[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] Fix state in xm list; add state to VM_metrics class.



# HG changeset patch
# User Ewan Mellor <ewan@xxxxxxxxxxxxx>
# Date 1174647891 0
# Node ID a34ab3f899c4150099697858b81b85d7684ba0f7
# Parent  5dfa9b09b07cd2e9c515f9dff0dc3a90af8dc80a
Fix state in xm list; add state to VM_metrics class.

Signed-off-by: Tom Wilkie <tom.wilkie@xxxxxxxxx>
---
 tools/python/xen/xend/XendAPI.py       |    4 ++++
 tools/python/xen/xend/XendVMMetrics.py |   25 +++++++++++++++++++++++++
 tools/python/xen/xm/main.py            |   13 ++++++++++++-
 3 files changed, 41 insertions(+), 1 deletion(-)

diff -r 5dfa9b09b07c -r a34ab3f899c4 tools/python/xen/xend/XendAPI.py
--- a/tools/python/xen/xend/XendAPI.py  Fri Mar 23 11:00:08 2007 +0000
+++ b/tools/python/xen/xend/XendAPI.py  Fri Mar 23 11:04:51 2007 +0000
@@ -1608,6 +1608,7 @@ class XendAPI(object):
                           'VCPUs_CPU',
                           'VCPUs_flags',
                           'VCPUs_params',
+                          'state',
                           'start_time']
     VM_metrics_attr_rw = []
     VM_metrics_methods = []
@@ -1641,6 +1642,9 @@ class XendAPI(object):
 
     def VM_metrics_get_start_time(self, _, ref):
         return xen_api_success(self._VM_metrics_get(ref).get_start_time())
+
+    def VM_metrics_get_state(self, _, ref):
+        return xen_api_success(self._VM_metrics_get(ref).get_state())
 
 
     # Xen API: Class VBD
diff -r 5dfa9b09b07c -r a34ab3f899c4 tools/python/xen/xend/XendVMMetrics.py
--- a/tools/python/xen/xend/XendVMMetrics.py    Fri Mar 23 11:00:08 2007 +0000
+++ b/tools/python/xen/xend/XendVMMetrics.py    Fri Mar 23 11:04:51 2007 +0000
@@ -97,6 +97,30 @@ class XendVMMetrics:
         else:
             return {}
 
+    def get_state(self):
+        try:
+            domid = self.xend_domain_instance.getDomid()
+            domlist = xc.domain_getinfo(domid, 1)
+            if domlist and domid == domlist[0]['domid']:
+                dominfo = domlist[0]
+
+                states = []
+                def addState(key):
+                    if dominfo[key] == 1:
+                        states.append(key)
+
+                addState("running")
+                addState("blocked")
+                addState("paused")
+                addState("dying")
+                addState("crashed")
+                addState("shutdown")
+                return ",".join(states)
+        except Exception, err:
+            # ignore missing domain
+            log.trace("domain_getinfo(%d) failed, ignoring: %s", domid, 
str(err))
+        return ""
+
     def get_VCPUs_params(self):
         domid = self.xend_domain_instance.getDomid()
         if domid is not None:
@@ -125,4 +149,5 @@ class XendVMMetrics:
                  'VCPUs_flags'       : self.get_VCPUs_flags(),
                  'VCPUs_params'      : self.get_VCPUs_params(),
                  'start_time'        : self.get_start_time(),
+                 'state'             : self.get_state(),
                }
diff -r 5dfa9b09b07c -r a34ab3f899c4 tools/python/xen/xm/main.py
--- a/tools/python/xen/xm/main.py       Fri Mar 23 11:00:08 2007 +0000
+++ b/tools/python/xen/xm/main.py       Fri Mar 23 11:04:51 2007 +0000
@@ -715,10 +715,21 @@ def getDomains(domain_names, state, full
             dom_rec = server.xenapi.VM.get_record(dom_ref)
             dom_metrics_ref = server.xenapi.VM.get_metrics(dom_ref)
             dom_metrics = server.xenapi.VM_metrics.get_record(dom_metrics_ref)
+
+            states = ('running', 'blocked', 'paused', 'shutdown',
+                      'crashed', 'dying')
+            def state_on_off(state):
+                if dom_metrics['state'].find(state) > -1:
+                    return state[0]
+                else:
+                    return "-"
+            state_str = "".join([state_on_off(state)
+                                 for state in states])
+            
             dom_rec.update({'name':     dom_rec['name_label'],
                             'memory_actual': 
int(dom_metrics['memory_actual'])/1024,
                             'vcpus':    dom_metrics['VCPUs_number'],
-                            'state':    '-----',
+                            'state':    state_str,
                             'cpu_time': dom_metrics['VCPUs_utilisation'],
                             'start_time': dom_metrics['start_time']})
                        

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.