ia64/xen-unstable

changeset 14530:a34ab3f899c4

Fix state in xm list; add state to VM_metrics class.

Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
author Ewan Mellor <ewan@xensource.com>
date Fri Mar 23 11:04:51 2007 +0000 (2007-03-23)
parents 5dfa9b09b07c
children 7869f58ff551
files tools/python/xen/xend/XendAPI.py tools/python/xen/xend/XendVMMetrics.py tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/python/xen/xend/XendAPI.py	Fri Mar 23 11:00:08 2007 +0000
     1.2 +++ b/tools/python/xen/xend/XendAPI.py	Fri Mar 23 11:04:51 2007 +0000
     1.3 @@ -1608,6 +1608,7 @@ class XendAPI(object):
     1.4                            'VCPUs_CPU',
     1.5                            'VCPUs_flags',
     1.6                            'VCPUs_params',
     1.7 +                          'state',
     1.8                            'start_time']
     1.9      VM_metrics_attr_rw = []
    1.10      VM_metrics_methods = []
    1.11 @@ -1642,6 +1643,9 @@ class XendAPI(object):
    1.12      def VM_metrics_get_start_time(self, _, ref):
    1.13          return xen_api_success(self._VM_metrics_get(ref).get_start_time())
    1.14  
    1.15 +    def VM_metrics_get_state(self, _, ref):
    1.16 +        return xen_api_success(self._VM_metrics_get(ref).get_state())
    1.17 +
    1.18  
    1.19      # Xen API: Class VBD
    1.20      # ----------------------------------------------------------------
     2.1 --- a/tools/python/xen/xend/XendVMMetrics.py	Fri Mar 23 11:00:08 2007 +0000
     2.2 +++ b/tools/python/xen/xend/XendVMMetrics.py	Fri Mar 23 11:04:51 2007 +0000
     2.3 @@ -97,6 +97,30 @@ class XendVMMetrics:
     2.4          else:
     2.5              return {}
     2.6  
     2.7 +    def get_state(self):
     2.8 +        try:
     2.9 +            domid = self.xend_domain_instance.getDomid()
    2.10 +            domlist = xc.domain_getinfo(domid, 1)
    2.11 +            if domlist and domid == domlist[0]['domid']:
    2.12 +                dominfo = domlist[0]
    2.13 +
    2.14 +                states = []
    2.15 +                def addState(key):
    2.16 +                    if dominfo[key] == 1:
    2.17 +                        states.append(key)
    2.18 +
    2.19 +                addState("running")
    2.20 +                addState("blocked")
    2.21 +                addState("paused")
    2.22 +                addState("dying")
    2.23 +                addState("crashed")
    2.24 +                addState("shutdown")
    2.25 +                return ",".join(states)
    2.26 +        except Exception, err:
    2.27 +            # ignore missing domain
    2.28 +            log.trace("domain_getinfo(%d) failed, ignoring: %s", domid, str(err))
    2.29 +        return ""
    2.30 +
    2.31      def get_VCPUs_params(self):
    2.32          domid = self.xend_domain_instance.getDomid()
    2.33          if domid is not None:
    2.34 @@ -125,4 +149,5 @@ class XendVMMetrics:
    2.35                   'VCPUs_flags'       : self.get_VCPUs_flags(),
    2.36                   'VCPUs_params'      : self.get_VCPUs_params(),
    2.37                   'start_time'        : self.get_start_time(),
    2.38 +                 'state'             : self.get_state(),
    2.39                 }
     3.1 --- a/tools/python/xen/xm/main.py	Fri Mar 23 11:00:08 2007 +0000
     3.2 +++ b/tools/python/xen/xm/main.py	Fri Mar 23 11:04:51 2007 +0000
     3.3 @@ -715,10 +715,21 @@ def getDomains(domain_names, state, full
     3.4              dom_rec = server.xenapi.VM.get_record(dom_ref)
     3.5              dom_metrics_ref = server.xenapi.VM.get_metrics(dom_ref)
     3.6              dom_metrics = server.xenapi.VM_metrics.get_record(dom_metrics_ref)
     3.7 +
     3.8 +            states = ('running', 'blocked', 'paused', 'shutdown',
     3.9 +                      'crashed', 'dying')
    3.10 +            def state_on_off(state):
    3.11 +                if dom_metrics['state'].find(state) > -1:
    3.12 +                    return state[0]
    3.13 +                else:
    3.14 +                    return "-"
    3.15 +            state_str = "".join([state_on_off(state)
    3.16 +                                 for state in states])
    3.17 +            
    3.18              dom_rec.update({'name':     dom_rec['name_label'],
    3.19                              'memory_actual': int(dom_metrics['memory_actual'])/1024,
    3.20                              'vcpus':    dom_metrics['VCPUs_number'],
    3.21 -                            'state':    '-----',
    3.22 +                            'state':    state_str,
    3.23                              'cpu_time': dom_metrics['VCPUs_utilisation'],
    3.24                              'start_time': dom_metrics['start_time']})
    3.25