ia64/xen-unstable

changeset 1522:abaa8727dcb1

bitkeeper revision 1.990.2.4 (40d6e58cfM0ifkkM2ZVDB4SR04_JmQ)

Change to using a different variable for the global opts.
Change some command names and options.
author mjw@wray-m-3.hpl.hp.com
date Mon Jun 21 13:41:32 2004 +0000 (2004-06-21)
parents e1ea789b5c8c
children b3df007a98da
files tools/xenmgr/lib/xm/create.py tools/xenmgr/lib/xm/main.py tools/xenmgr/lib/xm/opts.py tools/xenmgr/lib/xm/shutdown.py
line diff
     1.1 --- a/tools/xenmgr/lib/xm/create.py	Mon Jun 21 13:25:17 2004 +0000
     1.2 +++ b/tools/xenmgr/lib/xm/create.py	Mon Jun 21 13:41:32 2004 +0000
     1.3 @@ -7,28 +7,28 @@ from xenmgr.XendClient import server
     1.4  
     1.5  from xenmgr.xm.opts import *
     1.6  
     1.7 -opts = Opts(use="""[options]
     1.8 +gopts = Opts(use="""[options]
     1.9  
    1.10  Create a domain.
    1.11  """)
    1.12  
    1.13 -opts.opt('help', short='h',
    1.14 +gopts.opt('help', short='h',
    1.15           fn=set_value, default=0,
    1.16           use="Print this help.")
    1.17  
    1.18 -opts.opt('quiet', short='q',
    1.19 +gopts.opt('quiet', short='q',
    1.20           fn=set_true, default=0,
    1.21           use="Quiet.")
    1.22  
    1.23 -opts.opt('path', val='PATH',
    1.24 +gopts.opt('path', val='PATH',
    1.25           fn=set_value, default='.:/etc/xc',
    1.26           use="Search path for default scripts.")
    1.27  
    1.28 -opts.opt('defaults', short='f', val='FILE',
    1.29 +gopts.opt('defaults', short='f', val='FILE',
    1.30           fn=set_value, default='xmdefaults',
    1.31           use="Use the given default script.")
    1.32  
    1.33 -opts.opt('config', short='F', val='FILE',
    1.34 +gopts.opt('config', short='F', val='FILE',
    1.35           fn=set_value, default=None,
    1.36           use='Domain configuration to use.')
    1.37  
    1.38 @@ -38,102 +38,103 @@ def set_var(opt, k, v):
    1.39          (k, v) = string.split(d, '=')
    1.40          opt.opts.setvar(k, v)
    1.41  
    1.42 -opts.opt('define', short='D', val='VAR=VAL',
    1.43 +gopts.opt('define', short='D', val='VAR=VAL',
    1.44           fn=set_var, default=None,
    1.45           use="""Set variables before loading defaults, e.g. '-D vmid=3;ip=1.2.3.4'
    1.46           to set vmid and ip.""")
    1.47  
    1.48 -opts.opt('dryrun', short='n',
    1.49 +gopts.opt('dryrun', short='n',
    1.50           fn=set_true, default=0,
    1.51           use="Dry run - print the config but don't create the domain.")
    1.52  
    1.53 -opts.opt('console', short='c',
    1.54 +gopts.opt('console', short='c',
    1.55           fn=set_true, default=0,
    1.56           use="Connect to console after domain is created.")
    1.57  
    1.58 -opts.opt('kernel', short='k', val='FILE',
    1.59 +gopts.opt('kernel', short='k', val='FILE',
    1.60 +         fn=set_value, default=None,
    1.61           use="Path to kernel image.")
    1.62  
    1.63 -opts.opt('ramdisk', short='r', val='FILE',
    1.64 +gopts.opt('ramdisk', short='r', val='FILE',
    1.65           fn=set_value, default='',
    1.66           use="Path to ramdisk.")
    1.67  
    1.68 -opts.opt('builder', short='b', val='FUNCTION',
    1.69 +gopts.opt('builder', short='b', val='FUNCTION',
    1.70           fn=set_value, default='linux',
    1.71           use="Function to use to build the domain.")
    1.72  
    1.73 -opts.opt('memory', short='m', val='MEMORY',
    1.74 +gopts.opt('memory', short='m', val='MEMORY',
    1.75           fn=set_value, default=128,
    1.76           use="Domain memory in MB.")
    1.77  
    1.78 -opts.opt('disk', short='d', val='phy:DEV,VDEV,MODE',
    1.79 +gopts.opt('disk', short='d', val='phy:DEV,VDEV,MODE',
    1.80           fn=append_value, default=[],
    1.81           use="""Add a disk device to a domain. The physical device is DEV, which
    1.82           is exported to the domain as VDEV. The disk is read-only if MODE is r,
    1.83           read-write if mode is 'w'.""")
    1.84  
    1.85 -opts.opt('pci', val='BUS,DEV,FUNC',
    1.86 +gopts.opt('pci', val='BUS,DEV,FUNC',
    1.87           fn=append_value, default=[],
    1.88 -         use="""Add a PCI device to a domain.""")
    1.89 +         use="""Add a PCI device to a domain, using given params (in hex).""")
    1.90  
    1.91 -opts.opt('ipaddr', short='i', val="IPADDR",
    1.92 +gopts.opt('ipaddr', short='i', val="IPADDR",
    1.93           fn=append_value, default=[],
    1.94           use="Add an IP address to the domain.")
    1.95  
    1.96 -opts.opt('mac', short='M', val="MAC",
    1.97 +gopts.opt('mac', short='M', val="MAC",
    1.98           fn=append_value, default=[],
    1.99           use="""Add a network interface with the given mac address to the domain.
   1.100           More than one interface may be specified. Interfaces with unspecified MAC addresses
   1.101           are allocated a random address.""")
   1.102  
   1.103 -opts.opt('nics', val="N",
   1.104 +gopts.opt('nics', val="N",
   1.105           fn=set_int, default=1,
   1.106           use="Set the number of network interfaces.")
   1.107  
   1.108 -opts.opt('vnet', val='VNET',
   1.109 +gopts.opt('vnet', val='VNET',
   1.110           fn=append_value, default=[],
   1.111           use="""Define the vnets for the network interfaces.
   1.112           More than one vnet may be given, they are used in order.
   1.113           """)
   1.114  
   1.115 -opts.opt('root', short='R', val='DEVICE',
   1.116 +gopts.opt('root', short='R', val='DEVICE',
   1.117           fn=set_value, default='',
   1.118           use="""Set the root= parameter on the kernel command line.
   1.119           Use a device, e.g. /dev/sda1, or /dev/nfs for NFS root.""")
   1.120  
   1.121 -opts.opt('extra', short='E', val="ARGS",
   1.122 +gopts.opt('extra', short='E', val="ARGS",
   1.123           fn=set_value, default='',
   1.124           use="Set extra arguments to append to the kernel command line.")
   1.125  
   1.126 -opts.opt('ip', short='I', val='IPADDR',
   1.127 +gopts.opt('ip', short='I', val='IPADDR',
   1.128           fn=set_value, default='',
   1.129           use="Set the kernel IP interface address.")
   1.130  
   1.131 -opts.opt('gateway', val="IPADDR",
   1.132 +gopts.opt('gateway', val="IPADDR",
   1.133           fn=set_value, default='',
   1.134           use="Set kernel IP gateway.")
   1.135  
   1.136 -opts.opt('netmask', val="MASK",
   1.137 +gopts.opt('netmask', val="MASK",
   1.138           fn=set_value, default = '',
   1.139           use="Set kernel IP netmask.")
   1.140  
   1.141 -opts.opt('hostname', val="NAME",
   1.142 +gopts.opt('hostname', val="NAME",
   1.143           fn=set_value, default='',
   1.144           use="Set kernel IP hostname.")
   1.145  
   1.146 -opts.opt('interface', val="INTF",
   1.147 +gopts.opt('interface', val="INTF",
   1.148           fn=set_value, default="eth0",
   1.149           use="Set the kernel IP interface name.")
   1.150  
   1.151 -opts.opt('dhcp', val="off|dhcp",
   1.152 +gopts.opt('dhcp', val="off|dhcp",
   1.153           fn=set_value, default='off',
   1.154           use="Set kernel dhcp option.")
   1.155  
   1.156 -opts.opt('nfs_server', val="IPADDR",
   1.157 +gopts.opt('nfs_server', val="IPADDR",
   1.158           fn=set_value, default=None,
   1.159           use="Set the address of the NFS server for NFS root.")
   1.160  
   1.161 -opts.opt('nfs_root', val="PATH",
   1.162 +gopts.opt('nfs_root', val="PATH",
   1.163           fn=set_value, default=None,
   1.164           use="Set the path of the root NFS directory.")
   1.165  
   1.166 @@ -160,7 +161,7 @@ def make_config(opts):
   1.167          config_image.append(['ip', cmdline_ip])
   1.168      if opts.root:
   1.169          cmdline_root = strip('root=', opts.root)
   1.170 -        config_image.append(['root', opts.root])
   1.171 +        config_image.append(['root', cmdline_root])
   1.172      if opts.extra:
   1.173          config_image.append(['args', opts.extra])
   1.174      config.append(['image', config_image ])
   1.175 @@ -221,7 +222,9 @@ def preprocess_pci(opts):
   1.176          d = v.split(',')
   1.177          if len(d) != 3:
   1.178              opts.err('Invalid pci specifier: ' + v)
   1.179 -        pci.append(d)
   1.180 +        # Components are in hex: add hex specifier.
   1.181 +        hexd = map(lambda v: '0x'+v, d)
   1.182 +        pci.append(hexd)
   1.183      opts.pci = pci
   1.184  
   1.185  def preprocess_ip(opts):
   1.186 @@ -247,6 +250,8 @@ def preprocess_nfs(opts):
   1.187      opts.extra = nfs + ' ' + opts.extra
   1.188      
   1.189  def preprocess(opts):
   1.190 +    if not opts.kernel:
   1.191 +        opts.err("No kernel specified")
   1.192      preprocess_disk(opts)
   1.193      preprocess_pci(opts)
   1.194      preprocess_ip(opts)
   1.195 @@ -278,6 +283,7 @@ def make_domain(opts, config):
   1.196      return (dom, console_port)
   1.197  
   1.198  def main(argv):
   1.199 +    opts = gopts
   1.200      args = opts.parse(argv)
   1.201      if opts.config:
   1.202          pass
   1.203 @@ -285,6 +291,7 @@ def main(argv):
   1.204          opts.load_defaults()
   1.205      if opts.help:
   1.206          opts.usage()
   1.207 +        return
   1.208      preprocess(opts)
   1.209      config = make_config(opts)
   1.210      if opts.dryrun:
     2.1 --- a/tools/xenmgr/lib/xm/main.py	Mon Jun 21 13:25:17 2004 +0000
     2.2 +++ b/tools/xenmgr/lib/xm/main.py	Mon Jun 21 13:41:32 2004 +0000
     2.3 @@ -1,7 +1,7 @@
     2.4  #!/usr/bin/python
     2.5 -import string
     2.6  import sys
     2.7  
     2.8 +from xenmgr import PrettyPrint
     2.9  from xenmgr import sxp
    2.10  from xenmgr.XendClient import server
    2.11  from xenmgr.xm import create, shutdown
    2.12 @@ -39,7 +39,7 @@ class Xm:
    2.13      def help(self, meth, args):
    2.14          name = meth[3:]
    2.15          f = getattr(self, meth)
    2.16 -        print "%s\t%s" % (name, f.__doc__ or '')
    2.17 +        print "%-14s %s" % (name, f.__doc__ or '')
    2.18  
    2.19      def xm_help(self, help, args):
    2.20          """Print help."""
    2.21 @@ -69,11 +69,12 @@ class Xm:
    2.22              print args[0], "FILE"
    2.23              print "\nRestore a domain from FILE."
    2.24          if len(args) < 2: self.err("%s: Missing file" % args[0])
    2.25 -        server.xend_domain_restore(dom, None, filename)
    2.26 +        filename = args[1]
    2.27 +        server.xend_domain_restore(None, filename)
    2.28  
    2.29 -    def xm_ls(self, help, args):
    2.30 +    def xm_domains(self, help, args):
    2.31          """List domains."""
    2.32 -        if help: self.help('xm_' + args[0]); return
    2.33 +        if help: self.help('xm_' + args[0], args); return
    2.34          doms = server.xend_domains()
    2.35          print 'Dom  Name             Mem(MB)  CPU  State  Time(s)'
    2.36          for dom in doms:
    2.37 @@ -87,6 +88,18 @@ class Xm:
    2.38              d['cpu_time'] = float(sxp.child_value(info, 'cpu_time', '0'))
    2.39              print ("%(dom)-4d %(name)-16s %(mem)4d     %(cpu)3d %(state)5s %(cpu_time)10.2f" % d)
    2.40  
    2.41 +    def xm_domain(self, help, args):
    2.42 +        """Get information about a domain."""
    2.43 +        if help:
    2.44 +            print args[0], 'DOM'
    2.45 +            print '\nGet information about domain DOM.'
    2.46 +            return
    2.47 +        if len(args) < 2: self.err("%s: Missing domain" % args[0])
    2.48 +        dom = args[1]
    2.49 +        info = server.xend_domain(dom)
    2.50 +        PrettyPrint.prettyprint(info)
    2.51 +        print
    2.52 +
    2.53      def xm_halt(self, help, args):
    2.54          """Terminate a domain immediately."""
    2.55          if help:
    2.56 @@ -101,8 +114,8 @@ class Xm:
    2.57          """Shutdown a domain."""
    2.58          shutdown.main(args)
    2.59  
    2.60 -    def xm_stop(self, help, args):
    2.61 -        """Stop execution of a domain."""
    2.62 +    def xm_pause(self, help, args):
    2.63 +        """Pause execution of a domain."""
    2.64          if help:
    2.65              print args[0], 'DOM'
    2.66              print '\nStop execution of domain DOM.'
    2.67 @@ -111,11 +124,11 @@ class Xm:
    2.68          dom = args[1]
    2.69          server.xend_domain_stop(dom)
    2.70  
    2.71 -    def xm_start(self, help, args):
    2.72 -        """Start execution of a domain."""
    2.73 +    def xm_unpause(self, help, args):
    2.74 +        """Unpause a paused domain."""
    2.75          if help:
    2.76              print args[0], 'DOM'
    2.77 -            print '\nStart execution of domain DOM.'
    2.78 +            print '\nUnpause execution of domain DOM.'
    2.79              return
    2.80          if len(args) < 2: self.err("%s: Missing domain" % args[0])
    2.81          dom = args[1]
    2.82 @@ -131,31 +144,31 @@ class Xm:
    2.83          v = map(int, args[1:3])
    2.84          server.xend_domain_pincpu(*v)
    2.85  
    2.86 -    def xm_vif_stats(self, help, args):
    2.87 -        """Get stats for a virtual interface."""
    2.88 -        if help:
    2.89 -            print args[0], 'DOM VIF'
    2.90 -            print '\nGet stats for interface VIF on domain DOM.'
    2.91 -            return
    2.92 -        if len(args) != 3: self.err("%s: Invalid argument(s)" % args[0])
    2.93 -        v = map(int, args[1:3])
    2.94 -        print server.xend_domain_vif_stats(*v)
    2.95 +##     def xm_vif_stats(self, help, args):
    2.96 +##         """Get stats for a virtual interface."""
    2.97 +##         if help:
    2.98 +##             print args[0], 'DOM VIF'
    2.99 +##             print '\nGet stats for interface VIF on domain DOM.'
   2.100 +##             return
   2.101 +##         if len(args) != 3: self.err("%s: Invalid argument(s)" % args[0])
   2.102 +##         v = map(int, args[1:3])
   2.103 +##         print server.xend_domain_vif_stats(*v)
   2.104  
   2.105 -    def xm_vif_rate(self, help, args):
   2.106 -        """Set or get vif rate params."""
   2.107 -        if help:
   2.108 -            print args[0], "DOM VIF [BYTES USECS]"
   2.109 -            print '\nSet or get rate controls for interface VIF on domain DOM.'
   2.110 -            return
   2.111 -        n = len(args)
   2.112 -        if n == 3:
   2.113 -            v = map(int, args[1:n])
   2.114 -            print server.xend_domain_vif_scheduler_get(*v)
   2.115 -        elif n == 5:
   2.116 -            v = map(int, args[1:n])
   2.117 -            server.xend_domain_vif_scheduler_set(*v)
   2.118 -        else:
   2.119 -            self.err("%s: Invalid argument(s)" % args[0])
   2.120 +##     def xm_vif_rate(self, help, args):
   2.121 +##         """Set or get vif rate params."""
   2.122 +##         if help:
   2.123 +##             print args[0], "DOM VIF [BYTES USECS]"
   2.124 +##             print '\nSet or get rate controls for interface VIF on domain DOM.'
   2.125 +##             return
   2.126 +##         n = len(args)
   2.127 +##         if n == 3:
   2.128 +##             v = map(int, args[1:n])
   2.129 +##             print server.xend_domain_vif_scheduler_get(*v)
   2.130 +##         elif n == 5:
   2.131 +##             v = map(int, args[1:n])
   2.132 +##             server.xend_domain_vif_scheduler_set(*v)
   2.133 +##         else:
   2.134 +##             self.err("%s: Invalid argument(s)" % args[0])
   2.135  
   2.136      def xm_bvt(self, help, args):
   2.137          """Set BVT scheduler parameters."""
   2.138 @@ -193,16 +206,29 @@ class Xm:
   2.139              print "\nSet round robin scheduler slice."
   2.140              return
   2.141          if len(args) != 2: self.err("%s: Invalid argument(s)" % args[0])
   2.142 -        slice = int(args[1])
   2.143 -        server.xend_node_rrobin_set(slice)
   2.144 +        rrslice = int(args[1])
   2.145 +        server.xend_node_rrobin_set(rrslice)
   2.146  
   2.147      def xm_info(self, help, args):
   2.148          """Get information about the xen host."""
   2.149 -        if help: self.help('xm_info'); return
   2.150 +        if help: self.help('xm_' + args[0], args); return
   2.151          info = server.xend_node()
   2.152          for x in info[1:]:
   2.153              print "%-23s:" % x[0], x[1]
   2.154  
   2.155 +    def xm_consoles(self, help, args):
   2.156 +        """Get information about domain consoles."""
   2.157 +        if help: self.help('xm_' + args[0], args); return
   2.158 +        l = server.xend_consoles()
   2.159 +        print "Dom Port  Id"
   2.160 +        for x in l:
   2.161 +            info = server.xend_console(x)
   2.162 +            d = {}
   2.163 +            d['dom'] = sxp.child(info, 'dst', ['dst', '?', '?'])[1]
   2.164 +            d['port'] = sxp.child_value(info, 'port', '?')
   2.165 +            d['id'] = sxp.child_value(info, 'id', '?')
   2.166 +            print "%(dom)3s %(port)4s %(id)3s" % d
   2.167 +
   2.168      def xm_console(self, help, args):
   2.169          """Open a console to a domain."""
   2.170          if help:
     3.1 --- a/tools/xenmgr/lib/xm/opts.py	Mon Jun 21 13:25:17 2004 +0000
     3.2 +++ b/tools/xenmgr/lib/xm/opts.py	Mon Jun 21 13:41:32 2004 +0000
     3.3 @@ -91,6 +91,7 @@ class Opts:
     3.4          self._vals = {}
     3.5          self._globals = {}
     3.6          self._locals = {}
     3.7 +        self.quiet = 0
     3.8  
     3.9      def opt(self, name, **args):
    3.10          x = Opt(self, name, **args)
     4.1 --- a/tools/xenmgr/lib/xm/shutdown.py	Mon Jun 21 13:25:17 2004 +0000
     4.2 +++ b/tools/xenmgr/lib/xm/shutdown.py	Mon Jun 21 13:41:32 2004 +0000
     4.3 @@ -5,19 +5,19 @@ import time
     4.4  from xenmgr.XendClient import server
     4.5  from xenmgr.xm.opts import *
     4.6  
     4.7 -opts = Opts(use="""[options] [DOM]
     4.8 +gopts = Opts(use="""[options] [DOM]
     4.9  
    4.10  Shutdown one or more domains gracefully.""")
    4.11  
    4.12 -opts.opt('help', short='h',
    4.13 +gopts.opt('help', short='h',
    4.14           fn=set_value, default=0,
    4.15           use="Print this help.")
    4.16  
    4.17 -opts.opt('all', short='a',
    4.18 +gopts.opt('all', short='a',
    4.19           fn=set_true, default=0,
    4.20           use="Shutdown all domains.")
    4.21  
    4.22 -opts.opt('wait', short='w',
    4.23 +gopts.opt('wait', short='w',
    4.24           fn=set_true, default=0,
    4.25           use='Wait for shutdown to complete.')
    4.26  
    4.27 @@ -28,7 +28,7 @@ def shutdown(opts, doms, wait):
    4.28      if 0 in doms:
    4.29          doms.remove(0)
    4.30      for d in doms:
    4.31 -        server.xend_domain_shutdown(dom)
    4.32 +        server.xend_domain_shutdown(d)
    4.33      if wait:
    4.34          while doms:
    4.35              alive = domains()
    4.36 @@ -55,6 +55,7 @@ def main_dom(opts, args):
    4.37      shutdown(opts, [ domid ], opts.wait)
    4.38      
    4.39  def main(argv):
    4.40 +    opts = gopts
    4.41      args = opts.parse(argv)
    4.42      if opts.help:
    4.43          opts.usage()