ia64/xen-unstable

changeset 12110:c0d9f8b9c0e5

[XENAPI] Add missing function names. Proper sub command help messages.

Signed-off-by: Alastair Tse <atse@xensource.com>
author Alastair Tse <atse@xensource.com>
date Fri Oct 06 12:46:46 2006 +0100 (2006-10-06)
parents 19ab41db7fd2
children c88a78f8bed9
files tools/python/scripts/xapi.py
line diff
     1.1 --- a/tools/python/scripts/xapi.py	Fri Oct 06 12:31:24 2006 +0100
     1.2 +++ b/tools/python/scripts/xapi.py	Fri Oct 06 12:46:46 2006 +0100
     1.3 @@ -29,16 +29,18 @@ LOGIN = ('atse', 'passwd')
     1.4  
     1.5  COMMANDS = {
     1.6      'host-info': ('', 'Get Xen Host Info'),
     1.7 -    'vm-list':   ('', 'List all domains.'),
     1.8 -    'vm-uuid':   ('<name>', 'UUID of a domain by name.'),
     1.9 -    'vm-name':   ('<uuid>', 'Name of UUID.'),
    1.10 -    'vm-start':  ('<name>', 'Start VM with name'),
    1.11 -    'vm-shutdown': ('<name>', 'Shutdown VM with name'),
    1.12 -    'vm-create': ('<pycfg>', 'Create VM with python config'),
    1.13      'vbd-create': ('<domname> <pycfg>', 'Create VBD attached to domname'),
    1.14      'vif-create': ('<domname> <pycfg>', 'Create VIF attached to domname'),
    1.15 +
    1.16 +    'vm-create': ('<pycfg>', 'Create VM with python config'),
    1.17      'vm-delete': ('<domname>', 'Delete VM'),
    1.18 +    
    1.19      'vm-destroy': ('<name>', 'Hard shutdown a VM with name'),
    1.20 +    'vm-list':   ('', 'List all domains.'),
    1.21 +    'vm-name':   ('<uuid>', 'Name of UUID.'),
    1.22 +    'vm-shutdown': ('<name>', 'Shutdown VM with name'),
    1.23 +    'vm-start':  ('<name>', 'Start VM with name'),
    1.24 +    'vm-uuid':   ('<name>', 'UUID of a domain by name.'),    
    1.25  }
    1.26  
    1.27  OPTIONS = {
    1.28 @@ -107,6 +109,22 @@ def xapi_host_info(*args):
    1.29          print HOST_INFO_FORMAT % ('VMs', len(hostinfo['resident_VMs']))
    1.30          print HOST_INFO_FORMAT % ('UUID', host)        
    1.31  
    1.32 +def xapi_vm_uuid(*args):
    1.33 +    if len(args) < 1:
    1.34 +        raise OptionError("No domain name specified")
    1.35 +    
    1.36 +    server, session = _connect()
    1.37 +    vm_uuid = execute(server.VM.get_by_label, session, args[0])
    1.38 +    print vm_uuid
    1.39 +
    1.40 +def xapi_vm_name(*args):
    1.41 +    if len(args) < 1:
    1.42 +        raise OptionError("No UUID specified")
    1.43 +    
    1.44 +    server, session = _connect()
    1.45 +    vm_name = execute(server.VM.get_name_label, session, args[0])
    1.46 +    print vm_name
    1.47 +
    1.48  def xapi_vm_list(*args):
    1.49      opts, args = parse_args('vm-list', args)
    1.50      is_long = opts and opts.long
    1.51 @@ -209,6 +227,8 @@ def xapi_vif_create(*args):
    1.52      vif_uuid = execute(server.VIF.create, session, cfg)
    1.53      print 'Done. (%s)' % vif_uuid
    1.54  
    1.55 +    
    1.56 +
    1.57  #
    1.58  # Command Line Utils
    1.59  #
    1.60 @@ -237,13 +257,17 @@ def main(args):
    1.61      if not subcmd_func or not callable(subcmd_func):
    1.62          print 'Error: Unable to find subcommand \'%s\'' % subcmd
    1.63          usage()
    1.64 -        sys.exit(-1)
    1.65 -                  
    1.66 +        sys.exit(1)
    1.67 +
    1.68 +    if '-h' in args[1:] or '--help' in args[1:]:
    1.69 +        usage(subcmd)
    1.70 +        sys.exit(1)
    1.71 +        
    1.72      try:
    1.73          subcmd_func(*args[1:])
    1.74      except XenAPIError, e:
    1.75          print 'Error: %s' % str(e.args[1])
    1.76 -        sys.exit(-1)
    1.77 +        sys.exit(1)
    1.78  
    1.79      sys.exit(0)
    1.80