ia64/xen-unstable

changeset 1579:4cf3ae77b2fe

bitkeeper revision 1.1010.1.5 (40dbfee81bMxq2pSAYIoYZMhqQUEtg)

Fix help message for xm shutdown.
Add long format for xm list.
author mjw@wray-m-3.hpl.hp.com
date Fri Jun 25 10:31:04 2004 +0000 (2004-06-25)
parents 15a31950e646
children e27e8d79cc6a
files tools/xenmgr/lib/XendDomainInfo.py 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/XendDomainInfo.py	Thu Jun 24 19:05:51 2004 +0000
     1.2 +++ b/tools/xenmgr/lib/XendDomainInfo.py	Fri Jun 25 10:31:04 2004 +0000
     1.3 @@ -364,6 +364,7 @@ class XendDomainInfo:
     1.4          """Update with  info from xc.domain_getinfo().
     1.5          """
     1.6          self.info = info
     1.7 +        self.memory = self.info['mem_kb'] / 1024
     1.8  
     1.9      def __str__(self):
    1.10          s = "domain"
     2.1 --- a/tools/xenmgr/lib/xm/create.py	Thu Jun 24 19:05:51 2004 +0000
     2.2 +++ b/tools/xenmgr/lib/xm/create.py	Fri Jun 25 10:31:04 2004 +0000
     2.3 @@ -28,7 +28,7 @@ gopts.opt('path', val='PATH',
     2.4           use="Search path for default scripts.")
     2.5  
     2.6  gopts.opt('defaults', short='f', val='FILE',
     2.7 -         fn=set_value, default='defaults',
     2.8 +         fn=set_value, default='xmdefaults',
     2.9           use="Use the given default script.")
    2.10  
    2.11  gopts.opt('config', short='F', val='FILE',
     3.1 --- a/tools/xenmgr/lib/xm/main.py	Thu Jun 24 19:05:51 2004 +0000
     3.2 +++ b/tools/xenmgr/lib/xm/main.py	Fri Jun 25 10:31:04 2004 +0000
     3.3 @@ -4,6 +4,7 @@
     3.4  import os
     3.5  import os.path
     3.6  import sys
     3.7 +from getopt import getopt
     3.8  
     3.9  from xenmgr import PrettyPrint
    3.10  from xenmgr import sxp
    3.11 @@ -196,20 +197,41 @@ class ProgList(Prog):
    3.12      name = "list"
    3.13      info = """List info about domains."""
    3.14  
    3.15 +    short_options = 'l'
    3.16 +    long_options = ['long']
    3.17 +
    3.18      def help(self, args):
    3.19          if help:
    3.20 -            print args[0], '[DOM...]'
    3.21 +            print args[0], '[options] [DOM...]'
    3.22              print """\nGet information about domains.
    3.23 -            Either all domains or the domains given."""
    3.24 +            Either all domains or the domains given.
    3.25 +
    3.26 +            -l, --long   Get more detailed information.
    3.27 +            """
    3.28              return
    3.29          
    3.30      def main(self, args):
    3.31 -        n = len(args)
    3.32 -        if n == 1:
    3.33 -            doms = server.xend_domains()
    3.34 +        use_long = 0
    3.35 +        (options, params) = getopt(args[1:],
    3.36 +                                   self.short_options,
    3.37 +                                   self.long_options)
    3.38 +        n = len(params)
    3.39 +        for (k, v) in options:
    3.40 +            if k in ['-l', '--long']:
    3.41 +                use_long = 1
    3.42 +                
    3.43 +        if n == 0:
    3.44 +            doms = map(int, server.xend_domains())
    3.45 +            doms.sort()
    3.46          else:
    3.47 -            doms = map(int, args[1:])
    3.48 -        doms.sort()
    3.49 +            doms = map(int, params)
    3.50 +            
    3.51 +        if use_long:
    3.52 +            self.long_list(doms)
    3.53 +        else:
    3.54 +            self.brief_list(doms)
    3.55 +
    3.56 +    def brief_list(self, doms):
    3.57          print 'Dom  Name             Mem(MB)  CPU  State  Time(s)'
    3.58          for dom in doms:
    3.59              info = server.xend_domain(dom)
    3.60 @@ -222,6 +244,12 @@ class ProgList(Prog):
    3.61              d['cpu_time'] = float(sxp.child_value(info, 'cpu_time', '0'))
    3.62              print ("%(dom)-4d %(name)-16s %(mem)7d  %(cpu)3d  %(state)5s  %(cpu_time)7.1f" % d)
    3.63  
    3.64 +    def long_list(self, doms):
    3.65 +        for dom in doms:
    3.66 +            info = server.xend_domain(dom)
    3.67 +            print '\nDomain %d' % dom
    3.68 +            PrettyPrint.prettyprint(info)
    3.69 +
    3.70  xm.prog(ProgList)
    3.71  
    3.72  class ProgDestroy(Prog):
    3.73 @@ -246,8 +274,7 @@ class ProgShutdown(Prog):
    3.74      info = """Shutdown a domain."""
    3.75  
    3.76      def help(self, args):
    3.77 -        print args[0], 'DOM'
    3.78 -        print '\nSignal domain DOM to shutdown.'
    3.79 +        shutdown.main([args[0], '-h'])
    3.80      
    3.81      def main(self, args):
    3.82          shutdown.main(args)
     4.1 --- a/tools/xenmgr/lib/xm/opts.py	Thu Jun 24 19:05:51 2004 +0000
     4.2 +++ b/tools/xenmgr/lib/xm/opts.py	Fri Jun 25 10:31:04 2004 +0000
     4.3 @@ -273,7 +273,7 @@ class Opts:
     4.4                  self.load(p)
     4.5                  break
     4.6          else:
     4.7 -            self.err("Cannot open defaults file %s" % self.defaults)
     4.8 +            self.err("Cannot open defaults file %s" % self.vals.defaults)
     4.9  
    4.10      def load(self, defaults, help=0):
    4.11          """Load a defaults file. Local variables in the file
     5.1 --- a/tools/xenmgr/lib/xm/shutdown.py	Thu Jun 24 19:05:51 2004 +0000
     5.2 +++ b/tools/xenmgr/lib/xm/shutdown.py	Fri Jun 25 10:31:04 2004 +0000
     5.3 @@ -50,7 +50,7 @@ def shutdown(opts, doms, wait):
     5.4          opts.info("All domains terminated")
     5.5  
     5.6  def main_all(opts, args):
     5.7 -    shutdown(opts, None, opts.wait)
     5.8 +    shutdown(opts, None, opts.vals.wait)
     5.9  
    5.10  def main_dom(opts, args):
    5.11      if len(args) < 1: opts.err('Missing domain')
    5.12 @@ -59,7 +59,7 @@ def main_dom(opts, args):
    5.13          domid = int(dom)
    5.14      except:
    5.15          opts.err('Invalid domain: ' + dom)
    5.16 -    shutdown(opts, [ domid ], opts.wait)
    5.17 +    shutdown(opts, [ domid ], opts.vals.wait)
    5.18      
    5.19  def main(argv):
    5.20      opts = gopts
    5.21 @@ -68,7 +68,7 @@ def main(argv):
    5.22          opts.usage()
    5.23          return
    5.24      print 'shutdown.main>', len(args), args
    5.25 -    if opts.all:
    5.26 +    if opts.vals.all:
    5.27          main_all(opts, args)
    5.28      else:
    5.29          main_dom(opts, args)