diff options
author | Alastair Tse <atse@xensource.com> | 2006-10-13 17:34:13 +0100 |
---|---|---|
committer | Alastair Tse <atse@xensource.com> | 2006-10-13 17:34:13 +0100 |
commit | 68784417dbb25cc37d848e99eb76926ba773033c (patch) | |
tree | c8e891c75c8ac24a1a9bd08272126f026c7cba91 /tools/python/scripts | |
parent | 819c18341597971e6af46b00a5b0138d93c42fba (diff) | |
download | xen-68784417dbb25cc37d848e99eb76926ba773033c.tar.gz xen-68784417dbb25cc37d848e99eb76926ba773033c.tar.bz2 xen-68784417dbb25cc37d848e99eb76926ba773033c.zip |
[XENAPI] Make vm-destroy consistent with API naming. Moved what is
known as xm destroy to vm-shutdown --force.
Signed-off-by: Alastair Tse <atse@xensource.com>
Diffstat (limited to 'tools/python/scripts')
-rw-r--r-- | tools/python/scripts/xapi.py | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/tools/python/scripts/xapi.py b/tools/python/scripts/xapi.py index 7875b8f077..8ba8659314 100644 --- a/tools/python/scripts/xapi.py +++ b/tools/python/scripts/xapi.py @@ -44,12 +44,11 @@ COMMANDS = { 'vif-create': ('<domname> <pycfg>', 'Create VIF attached to domname'), 'vm-create': ('<pycfg>', 'Create VM with python config'), - 'vm-delete': ('<domname>', 'Delete VM'), + 'vm-destroy': ('<domname>', 'Delete VM'), - 'vm-destroy': ('<name>', 'Hard shutdown a VM with name'), 'vm-list': ('[--long]', 'List all domains.'), 'vm-name': ('<uuid>', 'Name of UUID.'), - 'vm-shutdown': ('<name>', 'Shutdown VM with name'), + 'vm-shutdown': ('<name> [opts]', 'Shutdown VM with name'), 'vm-start': ('<name>', 'Start VM with name'), 'vm-uuid': ('<name>', 'UUID of a domain by name.'), } @@ -59,6 +58,8 @@ OPTIONS = { {'action':'store_true', 'help':'List all properties of VMs'}) ], + 'vm-shutdown': [(('-f', '--force'), {'help': 'Shutdown Forcefully', + 'action': 'store_true'})], 'vdi-create': [(('--label',), {'help': 'Name for VDI'}), (('--description',), {'help': 'Description for VDI'}), @@ -103,7 +104,7 @@ class IterableValues(Values): yield opt, val -def parse_args(cmd_name, args): +def parse_args(cmd_name, args, set_defaults = False): argstring, desc = COMMANDS[cmd_name] parser = OptionParser(usage = 'xapi %s %s' % (cmd_name, argstring), description = desc) @@ -111,8 +112,11 @@ def parse_args(cmd_name, args): for optargs, optkwds in OPTIONS[cmd_name]: parser.add_option(*optargs, **optkwds) - default_values = parser.get_default_values() - defaults = IterableValues(default_values.__dict__) + if set_defaults: + default_values = parser.get_default_values() + defaults = IterableValues(default_values.__dict__) + else: + defaults = IterableValues() (opts, extraargs) = parser.parse_args(args = list(args), values = defaults) return opts, extraargs @@ -180,7 +184,7 @@ def xapi_vm_name(*args): print vm_name def xapi_vm_list(*args): - opts, args = parse_args('vm-list', args) + opts, args = parse_args('vm-list', args, set_defaults = True) is_long = opts and opts.long server, session = _connect() @@ -224,7 +228,7 @@ def xapi_vm_create(*args): print 'Done. (%s)' % uuid print uuid -def xapi_vm_delete(*args): +def xapi_vm_destroy(*args): if len(args) < 1: raise OptionError("No domain name specified.") @@ -246,25 +250,21 @@ def xapi_vm_start(*args): print 'Done.' def xapi_vm_shutdown(*args): + opts, args = parse_args("vm-shutdown", args, set_defaults = True) + if len(args) < 1: raise OptionError("No Domain name specified.") server, session = _connect() vm_uuid = resolve_vm(server, session, args[0]) - print 'Shutting down VM %s (%s)' % (args[0], vm_uuid) - success = execute(server.VM.clean_shutdown, session, vm_uuid) + if opts.force: + print 'Forcefully shutting down VM %s (%s)' % (args[0], vm_uuid) + success = execute(server.VM.hard_shutdown, session, vm_uuid) + else: + print 'Shutting down VM %s (%s)' % (args[0], vm_uuid) + success = execute(server.VM.clean_shutdown, session, vm_uuid) print 'Done.' -def xapi_vm_destroy(*args): - if len(args) < 1: - raise OptionError("No Domain name specified.") - - server, session = _connect() - vm_uuid = resolve_vm(server, session, args[0]) - print 'Shutting down VM with force %s (%s)' % (args[0], vm_uuid) - success = execute(server.VM.hard_shutdown, session, vm_uuid) - print 'Done.' - def xapi_vbd_create(*args): if len(args) < 2: raise OptionError("Configuration file not specified") @@ -273,11 +273,9 @@ def xapi_vbd_create(*args): domname = args[0] filename = args[1] - cfg = {} + cfg = _read_python_cfg(filename) for opt, val in opts: cfg[opt] = val - cfg.update(_read_python_cfg(filename)) - print 'Creating VBD from %s ..' % filename server, session = _connect() @@ -332,10 +330,9 @@ def xapi_vdi_create(*args): if len(args) < 1: raise OptionError("Not enough arguments.") - cfg = {} + cfg = _read_python_cfg(args[0]) for opt, val in opts: cfg[opt] = val - cfg.update(_read_python_cfg(args[0])) server, session = _connect() srs = execute(server.SR.get_all, session) |