ia64/xen-unstable

view tools/python/xen/xm/new.py @ 12810:cf1ca0615414

Added support for configuration file for xm, and use that to specify
contact and authentication details for the Xen-API server.

The default behaviour is still to use the existing legacy XML-RPC server.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Wed Dec 06 11:02:32 2006 +0000 (2006-12-06)
parents 2773c39df9a6
children 6b2875302558
line source
1 #============================================================================
2 # This library is free software; you can redistribute it and/or
3 # modify it under the terms of version 2.1 of the GNU Lesser General Public
4 # License as published by the Free Software Foundation.
5 #
6 # This library is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 # Lesser General Public License for more details.
10 #
11 # You should have received a copy of the GNU Lesser General Public
12 # License along with this library; if not, write to the Free Software
13 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 #============================================================================
15 # Copyright (C) 2006 XenSource Ltd
16 #============================================================================
18 import os
19 import xmlrpclib
21 from xen.xend import PrettyPrint
22 from xen.xend import sxp
23 from xen.xend import XendClient
25 from opts import *
26 from create import *
28 def make_unstarted_domain(opts, config):
29 """Create an unstarted domain.
31 @param opts: options
32 @param config: configuration
33 """
34 try:
35 server.xend.domain.new(config)
36 except xmlrpclib.Fault, ex:
37 import signal
38 if vncpid:
39 os.kill(vncpid, signal.SIGKILL)
40 if ex.faultCode == XendClient.ERROR_INVALID_DOMAIN:
41 err("the domain '%s' does not exist." % ex.faultString)
42 else:
43 err("%s" % ex.faultString)
44 except Exception, ex:
45 import signal
46 if vncpid:
47 os.kill(vncpid, signal.SIGKILL)
48 err(str(ex))
51 def main(argv):
52 try:
53 (opts, config) = parseCommandLine(argv)
54 except StandardError, ex:
55 err(str(ex))
57 if not opts:
58 return
60 if type(config) == str:
61 try:
62 config = sxp.parse(file(config))[0]
63 except IOError, exn:
64 raise OptionError("Cannot read file %s: %s" % (config, exn[1]))
66 if opts.vals.dryrun:
67 PrettyPrint.prettyprint(config)
68 else:
69 make_unstarted_domain(opts, config)
71 if __name__ == '__main__':
72 main(sys.argv)