ia64/xen-unstable

changeset 7048:ab1c362ba0d1

Merge the duplicated code for create, destroy, migrate, sysrq, and shutdown
into one handler that dynamically imports the correct subcommand handler.
Remove the fullhelp cruft, which was referencing something not actually present,
and was unused. Remove xm_network_attach and xm_network_detach, which were
providing code for unadvertised and unsupported functionality.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Fri Sep 23 16:56:46 2005 +0100 (2005-09-23)
parents 1f948a831fdc
children ad0270abc9b9
files tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/python/xen/xm/main.py	Fri Sep 23 16:53:57 2005 +0100
     1.2 +++ b/tools/python/xen/xm/main.py	Fri Sep 23 16:56:46 2005 +0100
     1.3 @@ -1,5 +1,6 @@
     1.4  # (C) Copyright IBM Corp. 2005
     1.5  # Copyright (C) 2004 Mike Wray
     1.6 +# Copyright (c) 2005 XenSource Ltd
     1.7  #
     1.8  # Authors:
     1.9  #     Sean Dague <sean at dague dot net>
    1.10 @@ -169,12 +170,6 @@ def handle_xend_error(cmd, dom, ex):
    1.11  #
    1.12  #########################################################################
    1.13  
    1.14 -def xm_create(args):
    1.15 -    from xen.xm import create
    1.16 -    # ugly hack because the opt parser apparently wants
    1.17 -    # the subcommand name just to throw it away!
    1.18 -    create.main(["bogus"] + args)
    1.19 -
    1.20  def xm_save(args):
    1.21      arg_check(args,2,"save")
    1.22  
    1.23 @@ -196,13 +191,6 @@ def xm_restore(args):
    1.24      if id is not None:
    1.25          server.xend_domain_unpause(domid)
    1.26  
    1.27 -def xm_migrate(args):
    1.28 -    # TODO: arg_check
    1.29 -    from xen.xm import migrate
    1.30 -    # ugly hack because the opt parser apparently wants
    1.31 -    # the subcommand name just to throw it away!
    1.32 -    migrate.main(["bogus"] + args)
    1.33 -
    1.34  def xm_list(args):
    1.35      use_long = 0
    1.36      show_vcpus = 0
    1.37 @@ -290,14 +278,6 @@ def xm_show_vcpus(domsinfo):
    1.38  def xm_vcpu_list(args):
    1.39      xm_list(["-v"] + args)
    1.40  
    1.41 -def xm_destroy(args):
    1.42 -    arg_check(args,1,"destroy")
    1.43 -
    1.44 -    from xen.xm import destroy
    1.45 -    # ugly hack because the opt parser apparently wants
    1.46 -    # the subcommand name just to throw it away!
    1.47 -    destroy.main(["bogus"] + args)
    1.48 -            
    1.49  def xm_reboot(args):
    1.50      arg_check(args,1,"reboot")
    1.51      from xen.xm import shutdown
    1.52 @@ -305,20 +285,6 @@ def xm_reboot(args):
    1.53      # the subcommand name just to throw it away!
    1.54      shutdown.main(["bogus", "-R"] + args)
    1.55  
    1.56 -def xm_shutdown(args):
    1.57 -    arg_check(args,1,"shutdown")
    1.58 -
    1.59 -    from xen.xm import shutdown
    1.60 -    # ugly hack because the opt parser apparently wants
    1.61 -    # the subcommand name just to throw it away!
    1.62 -    shutdown.main(["bogus"] + args)
    1.63 -
    1.64 -def xm_sysrq(args):
    1.65 -    from xen.xm import sysrq
    1.66 -    # ugly hack because the opt parser apparently wants
    1.67 -    # the subcommand name just to throw it away!
    1.68 -    sysrq.main(["bogus"] + args)
    1.69 -
    1.70  def xm_pause(args):
    1.71      arg_check(args, 1, "pause")
    1.72      dom = args[0]
    1.73 @@ -333,6 +299,11 @@ def xm_unpause(args):
    1.74      from xen.xend.XendClient import server
    1.75      server.xend_domain_unpause(dom)
    1.76  
    1.77 +def xm_subcommand(command, args):
    1.78 +    cmd = __import__(command, globals(), locals(), 'xen.xm')
    1.79 +    cmd.main(["bogus"] + args)
    1.80 +
    1.81 +
    1.82  #############################################################
    1.83  
    1.84  def cpu_make_map(cpulist):
    1.85 @@ -506,14 +477,6 @@ def xm_network_list(args):
    1.86          sxp.show(x)
    1.87          print
    1.88  
    1.89 -def xm_network_attach(args):
    1.90 -
    1.91 -    print "Not implemented"
    1.92 -
    1.93 -def xm_network_detach(args):
    1.94 -
    1.95 -    print "Not implemented"
    1.96 -    
    1.97  def xm_block_list(args):
    1.98      arg_check(args,1,"block-list")
    1.99      dom = args[0]
   1.100 @@ -609,11 +572,8 @@ commands = {
   1.101      # domain commands
   1.102      "domid": xm_domid,
   1.103      "domname": xm_domname,
   1.104 -    "create": xm_create,
   1.105 -    "destroy": xm_destroy,
   1.106      "restore": xm_restore,
   1.107      "save": xm_save,
   1.108 -    "shutdown": xm_shutdown,
   1.109      "reboot": xm_reboot,
   1.110      "list": xm_list,
   1.111      # memory commands
   1.112 @@ -625,10 +585,7 @@ commands = {
   1.113      "vcpu-enable": xm_vcpu_enable,
   1.114      "vcpu-disable": xm_vcpu_disable,
   1.115      "vcpu-list": xm_vcpu_list,
   1.116 -    # migration
   1.117 -    "migrate": xm_migrate,
   1.118      # special
   1.119 -    "sysrq": xm_sysrq,
   1.120      "pause": xm_pause,
   1.121      "unpause": xm_unpause,
   1.122      # host commands
   1.123 @@ -647,14 +604,24 @@ commands = {
   1.124      # network
   1.125      "network-limit": xm_network_limit,
   1.126      "network-list": xm_network_list,
   1.127 -    "network-attach": xm_network_attach,
   1.128 -    "network-detach": xm_network_detach,
   1.129      # vnet
   1.130      "vnet-list": xm_vnet_list,
   1.131      "vnet-create": xm_vnet_create,
   1.132      "vnet-delete": xm_vnet_delete,
   1.133      }
   1.134  
   1.135 +## The commands supported by a separate argument parser in xend.xm.
   1.136 +subcommands = [
   1.137 +    'create',
   1.138 +    'destroy',
   1.139 +    'migrate',
   1.140 +    'sysrq',
   1.141 +    'shutdown'
   1.142 +    ]
   1.143 +
   1.144 +for c in subcommands:
   1.145 +    commands[c] = eval('lambda args: xm_subcommand("%s", args)' % c)
   1.146 +
   1.147  aliases = {
   1.148      "balloon": "mem-set",
   1.149      "vif-list": "network-list",
   1.150 @@ -669,6 +636,7 @@ help = {
   1.151      "--long": longhelp
   1.152     }
   1.153  
   1.154 +
   1.155  def xm_lookup_cmd(cmd):
   1.156      if commands.has_key(cmd):
   1.157          return commands[cmd]
   1.158 @@ -688,9 +656,7 @@ def deprecated(old,new):
   1.159      err('Option %s is the new replacement, see "xm help %s" for more info' % (new, new))
   1.160  
   1.161  def usage(cmd=None):
   1.162 -    if cmd == "full":
   1.163 -        print fullhelp
   1.164 -    elif help.has_key(cmd):
   1.165 +    if help.has_key(cmd):
   1.166          print help[cmd]
   1.167      else:
   1.168          print shorthelp
   1.169 @@ -701,7 +667,7 @@ def main(argv=sys.argv):
   1.170          usage()
   1.171      
   1.172      if re.compile('-*help').match(argv[1]):
   1.173 -	if len(argv) > 2 and help.has_key(argv[2]):
   1.174 +	if len(argv) > 2:
   1.175  	    usage(argv[2])
   1.176  	else:
   1.177  	    usage()