WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] Implement VM_metrics Xen-API class.

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] Implement VM_metrics Xen-API class.
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Thu, 15 Mar 2007 05:30:10 -0700
Delivery-date: Thu, 15 Mar 2007 05:29:57 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Ewan Mellor <ewan@xxxxxxxxxxxxx>
# Date 1173904916 0
# Node ID 460dac5742cf0349f8968f5e9802e27d633f87ac
# Parent  192bee4b09a6a90f226b81e2cfc1356bf9df595e
Implement VM_metrics Xen-API class.

Signed-off-by: Tom Wilkie <tom.wilkie@xxxxxxxxx>
Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>
---
 tools/python/xen/xend/XendAPI.py        |   55 ++++++++++++++++++++-------
 tools/python/xen/xend/XendDomainInfo.py |   10 ++++
 tools/python/xen/xend/XendVMMetrics.py  |   65 ++++++++++++++++++++++++++++++++
 3 files changed, 117 insertions(+), 13 deletions(-)

diff -r 192bee4b09a6 -r 460dac5742cf tools/python/xen/xend/XendAPI.py
--- a/tools/python/xen/xend/XendAPI.py  Wed Mar 14 20:27:57 2007 +0000
+++ b/tools/python/xen/xend/XendAPI.py  Wed Mar 14 20:41:56 2007 +0000
@@ -31,6 +31,7 @@ from xen.xend.XendClient import ERROR_IN
 from xen.xend.XendClient import ERROR_INVALID_DOMAIN
 from xen.xend.XendLogging import log
 from xen.xend.XendTask import XendTask
+from xen.xend.XendVMMetrics import XendVMMetrics
 
 from xen.xend.XendAPIConstants import *
 from xen.util.xmlrpclib2 import stringify
@@ -192,6 +193,16 @@ def valid_vm(func):
            _check_ref(XendDomain.instance().is_valid_vm,
                       'VM', func, *args, **kwargs)
 
+def valid_vm_metrics(func):
+    """Decorator to verify if vm_metrics_ref is valid before calling method.
+
+    @param func: function with params: (self, session, vm_metrics_ref, ...)
+    @rtype: callable object
+    """    
+    return lambda *args, **kwargs: \
+           _check_ref(XendVMMetrics.is_valid_vm_metrics,
+                      'VM_metrics', func, *args, **kwargs)
+
 def valid_network(func):
     """Decorator to verify if network_ref is valid before calling method.
 
@@ -400,6 +411,7 @@ class XendAPI(object):
             'host_metrics' : valid_host_metrics,
             'network'      : valid_network,
             'VM'           : valid_vm,
+            'VM_metrics'   : valid_vm_metrics,
             'VBD'          : valid_vbd,
             'VBD_metrics'  : valid_vbd_metrics,
             'VIF'          : valid_vif,
@@ -990,11 +1002,9 @@ class XendAPI(object):
 
     VM_attr_ro = ['power_state',
                   'resident_on',
-                  'memory_actual',
                   'memory_static_max',                  
                   'memory_static_min',
                   'VCPUs_number',
-                  'VCPUs_utilisation',
                   'consoles',
                   'VIFs',
                   'VBDs',
@@ -1002,6 +1012,7 @@ class XendAPI(object):
                   'tools_version',
                   'domid',
                   'is_control_domain',
+                  'metrics'
                   ]
                   
     VM_attr_rw = ['name_label',
@@ -1098,11 +1109,7 @@ class XendAPI(object):
     
     def VM_get_resident_on(self, session, vm_ref):
         return xen_api_success(XendNode.instance().uuid)
-    
-    def VM_get_memory_actual(self, session, vm_ref):
-        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
-        return xen_api_todo() # unsupported by xc
-    
+       
     def VM_get_memory_static_max(self, session, vm_ref):
         dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
         return xen_api_success(dom.get_memory_static_max())
@@ -1115,10 +1122,6 @@ class XendAPI(object):
         dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
         return xen_api_success(dom.getVCpuCount())
     
-    def VM_get_VCPUs_utilisation(self, session, vm_ref):
-        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
-        return xen_api_success(dom.get_vcpus_util())
-    
     def VM_get_VIFs(self, session, vm_ref):
         dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
         return xen_api_success(dom.get_vifs())
@@ -1138,6 +1141,10 @@ class XendAPI(object):
     def VM_get_tools_version(self, session, vm_ref):
         dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
         return dom.get_tools_version()
+
+    def VM_get_metrics(self, _, vm_ref):
+        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
+        return xen_api_success(dom.get_metrics())
 
     # attributes (rw)
     def VM_get_name_label(self, session, vm_ref):
@@ -1418,11 +1425,9 @@ class XendAPI(object):
             'memory_static_max': xeninfo.get_memory_static_max(),
             'memory_dynamic_min': xeninfo.get_memory_dynamic_min(),
             'memory_dynamic_max': xeninfo.get_memory_dynamic_max(),
-            'memory_actual': xeninfo.get_memory_static_min(),
             'VCPUs_policy': xeninfo.get_vcpus_policy(),
             'VCPUs_params': xeninfo.get_vcpus_params(),
             'VCPUs_number': xeninfo.getVCpuCount(),
-            'VCPUs_utilisation': xeninfo.get_vcpus_util(),
             'actions_after_shutdown': xeninfo.get_on_shutdown(),
             'actions_after_reboot': xeninfo.get_on_reboot(),
             'actions_after_suspend': xeninfo.get_on_suspend(),
@@ -1497,6 +1502,30 @@ class XendAPI(object):
         return XendTask.log_progress(0, 100, do_vm_func,
                                      "domain_unpause", vm_ref)
 
+    # Xen API: Class VM_metrics
+    # ----------------------------------------------------------------
+
+    VM_metrics_attr_ro = ['memory_actual',
+                           'vcpus_number',
+                           'vcpus_utilisation']
+    VM_metrics_attr_rw = []
+    VM_metrics_methods = []
+
+    def _VM_metrics_get(self, ref):
+        return XendVMMetrics.get_by_uuid(ref)
+
+    def VM_metrics_get_record(self, _, ref):
+        return xen_api_success(self._VM_metrics_get(ref).get_record())
+
+    def VM_metrics_get_memory_actual(self, _, ref):
+        return xen_api_success(self._VM_metrics_get(ref).get_memory_actual())
+
+    def VM_metrics_get_vcpus_number(self, _, ref):
+        return xen_api_success(self._VM_metrics_get(ref).get_vcpus_number())
+
+    def VM_metrics_get_vcpus_utilisation(self, _, ref):
+        return 
xen_api_success(self._VM_metrics_get(ref).get_metrics_get_vcpus_utilisation())
+
     # Xen API: Class VBD
     # ----------------------------------------------------------------
 
diff -r 192bee4b09a6 -r 460dac5742cf tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py   Wed Mar 14 20:27:57 2007 +0000
+++ b/tools/python/xen/xend/XendDomainInfo.py   Wed Mar 14 20:41:56 2007 +0000
@@ -50,6 +50,8 @@ from xen.xend.xenstore.xswatch import xs
 from xen.xend.xenstore.xswatch import xswatch
 from xen.xend.XendConstants import *
 from xen.xend.XendAPIConstants import *
+
+from xen.xend.XendVMMetrics import XendVMMetrics
 
 MIGRATE_TIMEOUT = 30.0
 BOOTLOADER_LOOPBACK_DEVICE = '/dev/xvdp'
@@ -369,6 +371,8 @@ class XendDomainInfo:
             self._augmentInfo(priv)
 
         self._checkName(self.info['name_label'])
+
+        self.metrics = XendVMMetrics(uuid.createString(), self)
             
 
     #
@@ -626,6 +630,10 @@ class XendDomainInfo:
 
         except RuntimeError, exn:
             raise XendError(str(exn))
+
+
+    def getDomInfo(self):
+        return dom_get(self.domid)
 
     #
     # internal functions ... TODO: re-categorised
@@ -2060,6 +2068,8 @@ class XendDomainInfo:
         return self.info.get('pci_bus', '')
     def get_tools_version(self):
         return self.info.get('tools_version', {})
+    def get_metrics(self):
+        return self.metrics.get_uuid();
     
     def get_on_shutdown(self):
         after_shutdown = self.info.get('actions_after_shutdown')
diff -r 192bee4b09a6 -r 460dac5742cf tools/python/xen/xend/XendVMMetrics.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/python/xen/xend/XendVMMetrics.py    Wed Mar 14 20:41:56 2007 +0000
@@ -0,0 +1,65 @@
+#============================================================================
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of version 2.1 of the GNU Lesser General Public
+# License as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#============================================================================
+# Copyright (c) 2006-2007 Xensource Inc.
+#============================================================================
+
+from xen.xend.XendLogging import log
+
+instances = {}
+
+class XendVMMetrics:
+    """VM Metrics."""
+
+    def get_by_uuid(_, uuid):
+        return instances[uuid]
+
+    get_by_uuid = classmethod(get_by_uuid)
+
+    def is_valid_vm_metrics(_, uuid):
+        return uuid in instances
+
+    is_valid_vm_metrics = classmethod(is_valid_vm_metrics)
+   
+    def __init__(self, uuid, xend_domain_instance):
+        self.uuid = uuid
+        self.xend_domain_instance = xend_domain_instance
+        instances[uuid] = self
+
+    def get_uuid(self):
+        return self.uuid
+
+    def get_memory_actual(self):
+        return self.get_record()["memory_actual"]
+
+    def get_vcpus_number(self):
+        return self.get_record()["vcpus_number"]
+    
+    def get_vcpus_utilisation(self):
+        return self.xend_domain_instance.get_vcpus_util()
+
+    def get_record(self):
+        domInfo = self.xend_domain_instance.getDomInfo()
+        if domInfo:
+            return { 'uuid'              : self.uuid,
+                     'memory_actual'     : domInfo["mem_kb"] * 1024,
+                     'vcpus_number'      : domInfo["online_vcpus"],
+                     'vcpus_utilisation' : self.get_vcpus_utilisation()
+                   }
+        else:
+            return { 'uuid'              : self.uuid,
+                     'memory_actual'     : 0,
+                     'vcpus_number'      : 0,
+                     'vcpus_utilisation' : {}
+                   }

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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] Implement VM_metrics Xen-API class., Xen patchbot-unstable <=