[XEND][XM] Fixes for xm list output
authorAlastair Tse <atse@xensource.com>
Thu, 2 Nov 2006 14:26:01 +0000 (14:26 +0000)
committerAlastair Tse <atse@xensource.com>
Thu, 2 Nov 2006 14:26:01 +0000 (14:26 +0000)
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>
tools/python/xen/xend/XendConfig.py
tools/python/xen/xm/main.py

index 7449ec54ebdbc9a1093dd6b4889b2e934eda1e23..6a9473744006b4eee8a6b36aed6682167b64a831 100644 (file)
@@ -24,6 +24,7 @@ from xen.xend.XendError import VmError
 from xen.xend.XendDevices import XendDevices
 from xen.xend.XendLogging import log
 from xen.xend.PrettyPrint import prettyprintstring
+from xen.xend.XendConstants import DOM_STATE_HALTED
 
 """
 XendConfig API
@@ -31,41 +32,6 @@ XendConfig API
   XendConfig will try to mirror as closely the Xen API VM Struct
   providing a backwards compatibility mode for SXP dumping, loading.
 
-XendConfig is a subclass of the python dict in order to emulate the
-previous behaviour of the XendDomainInfo.info dictionary. However,
-the new dictionary also exposes a set of attributes that implement
-the Xen API VM configuration interface.
-
-Example:
-
->>> cfg = XendConfig(cfg = dict_from_xc_domain_getinfo)
->>> cfg.name_label
-Domain-0
->>> cfg['name']
-Domain-0
->>> cfg.kernel_kernel
-/boot/vmlinuz-xen
->>> cfg.kernel_initrd
-/root/initrd
->>> cfg.kernel_args
-root=/dev/sda1 ro
->>> cfg['image']
-(linux
-  (kernel /boot/vmlinuz-xen)
-  (ramdisk /root/initrd)
-  (root '/dev/sda1 ro'))
->>>  
-
-Internally, XendConfig will make sure changes via the old 'dict'
-interface get reflected, if possible, to the attribute store.
-
-It does this by overriding __setitem__, __getitem__, __hasitem__,
-__getattr__, __setattr__, __hasattr__.
-
-What this means is that as code is moved from the SXP interface to
-the Xen API interface, we can spot unported code by tracing calls
-to  __getitem__ and __setitem__.
-
 """
 
 
@@ -665,9 +631,9 @@ class XendConfig(dict):
                 if self[cfg] != None:
                     sxpr.append([cfg, self[cfg]])
 
-        if 'image' in self:
+        if 'image' in self and self['image'] != None:
             sxpr.append(['image', self['image']])
-        if 'security' in self:
+        if 'security' in self and self['security']:
             sxpr.append(['security', self['security']])
         if 'shutdown_reason' in self:
             sxpr.append(['shutdown_reason', self['shutdown_reason']])
@@ -684,7 +650,17 @@ class XendConfig(dict):
         sxpr.append(['on_xend_start', self.get('on_xend_start', 'ignore')])
         sxpr.append(['on_xend_stop', self.get('on_xend_stop', 'ignore')])
 
-        sxpr.append(['status', domain.state])
+        if domain:
+            sxpr.append(['status', domain.state])
+        else:
+            sxpr.append(['status', DOM_STATE_HALTED])
+
+        # For save/restore migration
+        if domain:
+            if domain.store_mfn:
+                sxpr.append(['store_mfn', domain.store_mfn])
+            if domain.console_mfn:
+                sxpr.append(['console_mfn', domain.console_mfn])
 
         # Marshall devices (running or from configuration)
         if not ignore_devices:
index 3d6a4c95ea822eb022fdf7ccaab81edc24a2c154..cfa75460924a06a2e5b48007d603e0057b835eb0 100644 (file)
@@ -39,6 +39,7 @@ from xen.xend import PrettyPrint
 from xen.xend import sxp
 from xen.xend import XendClient
 from xen.xend.XendClient import server
+from xen.xend.XendConstants import *
 
 from xen.xm.opts import OptionError, Opts, wrap, set_true
 from xen.xm import console
@@ -532,13 +533,16 @@ def xm_list(args):
 def parse_doms_info(info):
     def get_info(n, t, d):
         return t(sxp.child_value(info, n, d))
+
+    def get_status(n, t, d):
+        return DOM_STATES[t(sxp.child_value(info, n, d))]
     
     return {
         'domid'    : get_info('domid',        int,   -1),
         'name'     : get_info('name',         str,   '??'),
         'mem'      : get_info('memory',       int,   0),
         'vcpus'    : get_info('online_vcpus', int,   0),
-        'state'    : get_info('state',        str,   '??'),
+        'status'   : get_status('status',     int,   DOM_STATE_HALTED),
         'cpu_time' : get_info('cpu_time',     float, 0),
         'up_time'  : get_info('up_time',      float, -1),
         'seclabel' : security.get_security_printlabel(info),
@@ -559,10 +563,10 @@ def parse_sedf_info(info):
         }
 
 def xm_brief_list(doms):
-    print '%-40s %3s %8s %5s %5s %9s' % \
-          ('Name', 'ID', 'Mem(MiB)', 'VCPUs', 'State', 'Time(s)')
+    print '%-40s %3s %5s %5s %10s %9s' % \
+          ('Name', 'ID', 'Mem', 'VCPUs', 'State', 'Time(s)')
     
-    format = "%(name)-40s %(domid)3d %(mem)8d %(vcpus)5d %(state)5s " \
+    format = "%(name)-40s %(domid)3d %(mem)5d %(vcpus)5d %(status)10s " \
              "%(cpu_time)8.1f"
     
     for dom in doms:
@@ -570,11 +574,11 @@ def xm_brief_list(doms):
         print format % d
 
 def xm_label_list(doms):
-    print '%-32s %3s %8s %5s %5s %9s %-8s' % \
-          ('Name', 'ID', 'Mem(MiB)', 'VCPUs', 'State', 'Time(s)', 'Label')
+    print '%-32s %3s %5s %5s %5s %9s %-8s' % \
+          ('Name', 'ID', 'Mem', 'VCPUs', 'State', 'Time(s)', 'Label')
     
     output = []
-    format = '%(name)-32s %(domid)3d %(mem)8d %(vcpus)5d %(state)5s ' \
+    format = '%(name)-32s %(domid)3d %(mem)5d %(vcpus)5d %(status)10s ' \
              '%(cpu_time)8.1f %(seclabel)9s'
     
     for dom in doms: