ia64/xen-unstable

changeset 12224:41ad2c673fdb

[XEND][XM] Fixes for xm list output

Do not output image, security if they are empty
Change xm list slightly to be more informative about state.
Add back store_mfn and console_mfn to the SXP so save/restore can work
again.


Signed-off-by: Alastair Tse <atse@xensource.com>
author Alastair Tse <atse@xensource.com>
date Thu Nov 02 14:26:01 2006 +0000 (2006-11-02)
parents 70687bcb82dd
children 722cc2390021
files tools/python/xen/xend/XendConfig.py tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/python/xen/xend/XendConfig.py	Thu Nov 02 07:46:06 2006 +0000
     1.2 +++ b/tools/python/xen/xend/XendConfig.py	Thu Nov 02 14:26:01 2006 +0000
     1.3 @@ -24,6 +24,7 @@ from xen.xend.XendError import VmError
     1.4  from xen.xend.XendDevices import XendDevices
     1.5  from xen.xend.XendLogging import log
     1.6  from xen.xend.PrettyPrint import prettyprintstring
     1.7 +from xen.xend.XendConstants import DOM_STATE_HALTED
     1.8  
     1.9  """
    1.10  XendConfig API
    1.11 @@ -31,41 +32,6 @@ XendConfig API
    1.12    XendConfig will try to mirror as closely the Xen API VM Struct
    1.13    providing a backwards compatibility mode for SXP dumping, loading.
    1.14  
    1.15 -XendConfig is a subclass of the python dict in order to emulate the
    1.16 -previous behaviour of the XendDomainInfo.info dictionary. However,
    1.17 -the new dictionary also exposes a set of attributes that implement
    1.18 -the Xen API VM configuration interface.
    1.19 -
    1.20 -Example:
    1.21 -
    1.22 ->>> cfg = XendConfig(cfg = dict_from_xc_domain_getinfo)
    1.23 ->>> cfg.name_label
    1.24 -Domain-0
    1.25 ->>> cfg['name']
    1.26 -Domain-0
    1.27 ->>> cfg.kernel_kernel
    1.28 -/boot/vmlinuz-xen
    1.29 ->>> cfg.kernel_initrd
    1.30 -/root/initrd
    1.31 ->>> cfg.kernel_args
    1.32 -root=/dev/sda1 ro
    1.33 ->>> cfg['image']
    1.34 -(linux
    1.35 -  (kernel /boot/vmlinuz-xen)
    1.36 -  (ramdisk /root/initrd)
    1.37 -  (root '/dev/sda1 ro'))
    1.38 ->>>  
    1.39 -
    1.40 -Internally, XendConfig will make sure changes via the old 'dict'
    1.41 -interface get reflected, if possible, to the attribute store.
    1.42 -
    1.43 -It does this by overriding __setitem__, __getitem__, __hasitem__,
    1.44 -__getattr__, __setattr__, __hasattr__.
    1.45 -
    1.46 -What this means is that as code is moved from the SXP interface to
    1.47 -the Xen API interface, we can spot unported code by tracing calls
    1.48 -to  __getitem__ and __setitem__.
    1.49 -
    1.50  """
    1.51  
    1.52  
    1.53 @@ -665,9 +631,9 @@ class XendConfig(dict):
    1.54                  if self[cfg] != None:
    1.55                      sxpr.append([cfg, self[cfg]])
    1.56  
    1.57 -        if 'image' in self:
    1.58 +        if 'image' in self and self['image'] != None:
    1.59              sxpr.append(['image', self['image']])
    1.60 -        if 'security' in self:
    1.61 +        if 'security' in self and self['security']:
    1.62              sxpr.append(['security', self['security']])
    1.63          if 'shutdown_reason' in self:
    1.64              sxpr.append(['shutdown_reason', self['shutdown_reason']])
    1.65 @@ -684,7 +650,17 @@ class XendConfig(dict):
    1.66          sxpr.append(['on_xend_start', self.get('on_xend_start', 'ignore')])
    1.67          sxpr.append(['on_xend_stop', self.get('on_xend_stop', 'ignore')])
    1.68  
    1.69 -        sxpr.append(['status', domain.state])
    1.70 +        if domain:
    1.71 +            sxpr.append(['status', domain.state])
    1.72 +        else:
    1.73 +            sxpr.append(['status', DOM_STATE_HALTED])
    1.74 +
    1.75 +        # For save/restore migration
    1.76 +        if domain:
    1.77 +            if domain.store_mfn:
    1.78 +                sxpr.append(['store_mfn', domain.store_mfn])
    1.79 +            if domain.console_mfn:
    1.80 +                sxpr.append(['console_mfn', domain.console_mfn])
    1.81  
    1.82          # Marshall devices (running or from configuration)
    1.83          if not ignore_devices:
     2.1 --- a/tools/python/xen/xm/main.py	Thu Nov 02 07:46:06 2006 +0000
     2.2 +++ b/tools/python/xen/xm/main.py	Thu Nov 02 14:26:01 2006 +0000
     2.3 @@ -39,6 +39,7 @@ from xen.xend import PrettyPrint
     2.4  from xen.xend import sxp
     2.5  from xen.xend import XendClient
     2.6  from xen.xend.XendClient import server
     2.7 +from xen.xend.XendConstants import *
     2.8  
     2.9  from xen.xm.opts import OptionError, Opts, wrap, set_true
    2.10  from xen.xm import console
    2.11 @@ -532,13 +533,16 @@ def xm_list(args):
    2.12  def parse_doms_info(info):
    2.13      def get_info(n, t, d):
    2.14          return t(sxp.child_value(info, n, d))
    2.15 +
    2.16 +    def get_status(n, t, d):
    2.17 +        return DOM_STATES[t(sxp.child_value(info, n, d))]
    2.18      
    2.19      return {
    2.20          'domid'    : get_info('domid',        int,   -1),
    2.21          'name'     : get_info('name',         str,   '??'),
    2.22          'mem'      : get_info('memory',       int,   0),
    2.23          'vcpus'    : get_info('online_vcpus', int,   0),
    2.24 -        'state'    : get_info('state',        str,   '??'),
    2.25 +        'status'   : get_status('status',     int,   DOM_STATE_HALTED),
    2.26          'cpu_time' : get_info('cpu_time',     float, 0),
    2.27          'up_time'  : get_info('up_time',      float, -1),
    2.28          'seclabel' : security.get_security_printlabel(info),
    2.29 @@ -559,10 +563,10 @@ def parse_sedf_info(info):
    2.30          }
    2.31  
    2.32  def xm_brief_list(doms):
    2.33 -    print '%-40s %3s %8s %5s %5s %9s' % \
    2.34 -          ('Name', 'ID', 'Mem(MiB)', 'VCPUs', 'State', 'Time(s)')
    2.35 +    print '%-40s %3s %5s %5s %10s %9s' % \
    2.36 +          ('Name', 'ID', 'Mem', 'VCPUs', 'State', 'Time(s)')
    2.37      
    2.38 -    format = "%(name)-40s %(domid)3d %(mem)8d %(vcpus)5d %(state)5s " \
    2.39 +    format = "%(name)-40s %(domid)3d %(mem)5d %(vcpus)5d %(status)10s " \
    2.40               "%(cpu_time)8.1f"
    2.41      
    2.42      for dom in doms:
    2.43 @@ -570,11 +574,11 @@ def xm_brief_list(doms):
    2.44          print format % d
    2.45  
    2.46  def xm_label_list(doms):
    2.47 -    print '%-32s %3s %8s %5s %5s %9s %-8s' % \
    2.48 -          ('Name', 'ID', 'Mem(MiB)', 'VCPUs', 'State', 'Time(s)', 'Label')
    2.49 +    print '%-32s %3s %5s %5s %5s %9s %-8s' % \
    2.50 +          ('Name', 'ID', 'Mem', 'VCPUs', 'State', 'Time(s)', 'Label')
    2.51      
    2.52      output = []
    2.53 -    format = '%(name)-32s %(domid)3d %(mem)8d %(vcpus)5d %(state)5s ' \
    2.54 +    format = '%(name)-32s %(domid)3d %(mem)5d %(vcpus)5d %(status)10s ' \
    2.55               '%(cpu_time)8.1f %(seclabel)9s'
    2.56      
    2.57      for dom in doms: