ia64/xen-unstable

changeset 12129:41ca10996ce7

[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>
author Alastair Tse <atse@xensource.com>
date Fri Oct 13 17:34:13 2006 +0100 (2006-10-13)
parents e6162aeb0f89
children c4df5f0a41f3
files tools/python/scripts/xapi.py
line diff
     1.1 --- a/tools/python/scripts/xapi.py	Fri Oct 13 17:33:34 2006 +0100
     1.2 +++ b/tools/python/scripts/xapi.py	Fri Oct 13 17:34:13 2006 +0100
     1.3 @@ -44,12 +44,11 @@ COMMANDS = {
     1.4      'vif-create': ('<domname> <pycfg>', 'Create VIF attached to domname'),
     1.5  
     1.6      'vm-create': ('<pycfg>', 'Create VM with python config'),
     1.7 -    'vm-delete': ('<domname>', 'Delete VM'),
     1.8 +    'vm-destroy': ('<domname>', 'Delete VM'),
     1.9      
    1.10 -    'vm-destroy': ('<name>', 'Hard shutdown a VM with name'),
    1.11      'vm-list':   ('[--long]', 'List all domains.'),
    1.12      'vm-name':   ('<uuid>', 'Name of UUID.'),
    1.13 -    'vm-shutdown': ('<name>', 'Shutdown VM with name'),
    1.14 +    'vm-shutdown': ('<name> [opts]', 'Shutdown VM with name'),
    1.15      'vm-start':  ('<name>', 'Start VM with name'),
    1.16      'vm-uuid':   ('<name>', 'UUID of a domain by name.'),    
    1.17  }
    1.18 @@ -59,6 +58,8 @@ OPTIONS = {
    1.19                   {'action':'store_true',
    1.20                    'help':'List all properties of VMs'})
    1.21                 ],
    1.22 +    'vm-shutdown': [(('-f', '--force'), {'help': 'Shutdown Forcefully',
    1.23 +                                         'action': 'store_true'})],
    1.24      
    1.25      'vdi-create': [(('--label',), {'help': 'Name for VDI'}),
    1.26                     (('--description',), {'help': 'Description for VDI'}),
    1.27 @@ -103,7 +104,7 @@ class IterableValues(Values):
    1.28              yield opt, val        
    1.29  
    1.30  
    1.31 -def parse_args(cmd_name, args):
    1.32 +def parse_args(cmd_name, args, set_defaults = False):
    1.33      argstring, desc = COMMANDS[cmd_name]
    1.34      parser = OptionParser(usage = 'xapi %s %s' % (cmd_name, argstring),
    1.35                            description = desc)
    1.36 @@ -111,8 +112,11 @@ def parse_args(cmd_name, args):
    1.37          for optargs, optkwds in OPTIONS[cmd_name]:
    1.38              parser.add_option(*optargs, **optkwds)
    1.39  
    1.40 -    default_values = parser.get_default_values()
    1.41 -    defaults = IterableValues(default_values.__dict__)
    1.42 +    if set_defaults:
    1.43 +        default_values = parser.get_default_values()
    1.44 +        defaults = IterableValues(default_values.__dict__)
    1.45 +    else:
    1.46 +        defaults = IterableValues()
    1.47      (opts, extraargs) = parser.parse_args(args = list(args),
    1.48                                            values = defaults)
    1.49      return opts, extraargs
    1.50 @@ -180,7 +184,7 @@ def xapi_vm_name(*args):
    1.51      print vm_name
    1.52  
    1.53  def xapi_vm_list(*args):
    1.54 -    opts, args = parse_args('vm-list', args)
    1.55 +    opts, args = parse_args('vm-list', args, set_defaults = True)
    1.56      is_long = opts and opts.long
    1.57      
    1.58      server, session = _connect()
    1.59 @@ -224,7 +228,7 @@ def xapi_vm_create(*args):
    1.60      print 'Done. (%s)' % uuid
    1.61      print uuid
    1.62  
    1.63 -def xapi_vm_delete(*args):
    1.64 +def xapi_vm_destroy(*args):
    1.65      if len(args) < 1:
    1.66          raise OptionError("No domain name specified.")
    1.67      
    1.68 @@ -246,25 +250,21 @@ def xapi_vm_start(*args):
    1.69      print 'Done.'
    1.70  
    1.71  def xapi_vm_shutdown(*args):
    1.72 +    opts, args = parse_args("vm-shutdown", args, set_defaults = True)
    1.73 +    
    1.74      if len(args) < 1:
    1.75          raise OptionError("No Domain name specified.")
    1.76  
    1.77      server, session = _connect()
    1.78      vm_uuid = resolve_vm(server, session, args[0])
    1.79 -    print 'Shutting down VM %s (%s)' % (args[0], vm_uuid)
    1.80 -    success = execute(server.VM.clean_shutdown, session, vm_uuid)
    1.81 +    if opts.force:
    1.82 +        print 'Forcefully shutting down VM %s (%s)' % (args[0], vm_uuid)
    1.83 +        success = execute(server.VM.hard_shutdown, session, vm_uuid)
    1.84 +    else:
    1.85 +        print 'Shutting down VM %s (%s)' % (args[0], vm_uuid)
    1.86 +        success = execute(server.VM.clean_shutdown, session, vm_uuid)
    1.87      print 'Done.'
    1.88  
    1.89 -def xapi_vm_destroy(*args):
    1.90 -    if len(args) < 1:
    1.91 -        raise OptionError("No Domain name specified.")
    1.92 -
    1.93 -    server, session = _connect()
    1.94 -    vm_uuid = resolve_vm(server, session, args[0])
    1.95 -    print 'Shutting down VM with force %s (%s)' % (args[0], vm_uuid)
    1.96 -    success = execute(server.VM.hard_shutdown, session, vm_uuid)
    1.97 -    print 'Done.'    
    1.98 -
    1.99  def xapi_vbd_create(*args):
   1.100      if len(args) < 2:
   1.101          raise OptionError("Configuration file not specified")
   1.102 @@ -273,11 +273,9 @@ def xapi_vbd_create(*args):
   1.103      domname = args[0]
   1.104      filename = args[1]
   1.105  
   1.106 -    cfg = {}
   1.107 +    cfg = _read_python_cfg(filename)    
   1.108      for opt, val in opts:
   1.109          cfg[opt] = val
   1.110 -    cfg.update(_read_python_cfg(filename))
   1.111 -    
   1.112      
   1.113      print 'Creating VBD from %s ..' % filename
   1.114      server, session = _connect()
   1.115 @@ -332,10 +330,9 @@ def xapi_vdi_create(*args):
   1.116      if len(args) < 1:
   1.117          raise OptionError("Not enough arguments.")
   1.118  
   1.119 -    cfg = {}
   1.120 +    cfg = _read_python_cfg(args[0])
   1.121      for opt, val in opts:
   1.122          cfg[opt] = val
   1.123 -    cfg.update(_read_python_cfg(args[0]))
   1.124  
   1.125      server, session = _connect()
   1.126      srs = execute(server.SR.get_all, session)