ia64/xen-unstable

view tools/python/xen/xend/XendVMMetrics.py @ 14405:036e42d1c9bb

Added VM_metrics.get_all.

Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
author Ewan Mellor <ewan@xensource.com>
date Wed Mar 14 21:04:04 2007 +0000 (2007-03-14)
parents 460dac5742cf
children 4baae9f9fdbb
line source
1 #============================================================================
2 # This library is free software; you can redistribute it and/or
3 # modify it under the terms of version 2.1 of the GNU Lesser General Public
4 # License as published by the Free Software Foundation.
5 #
6 # This library is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 # Lesser General Public License for more details.
10 #
11 # You should have received a copy of the GNU Lesser General Public
12 # License along with this library; if not, write to the Free Software
13 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 #============================================================================
15 # Copyright (c) 2006-2007 Xensource Inc.
16 #============================================================================
18 from xen.xend.XendLogging import log
20 instances = {}
22 class XendVMMetrics:
23 """VM Metrics."""
25 def get_by_uuid(_, uuid):
26 return instances[uuid]
28 get_by_uuid = classmethod(get_by_uuid)
30 def is_valid_vm_metrics(_, uuid):
31 return uuid in instances
33 is_valid_vm_metrics = classmethod(is_valid_vm_metrics)
35 def get_all(_):
36 return instances.keys()
38 get_all = classmethod(get_all)
40 def __init__(self, uuid, xend_domain_instance):
41 self.uuid = uuid
42 self.xend_domain_instance = xend_domain_instance
43 instances[uuid] = self
45 def get_uuid(self):
46 return self.uuid
48 def get_memory_actual(self):
49 return self.get_record()["memory_actual"]
51 def get_vcpus_number(self):
52 return self.get_record()["vcpus_number"]
54 def get_vcpus_utilisation(self):
55 return self.xend_domain_instance.get_vcpus_util()
57 def get_record(self):
58 domInfo = self.xend_domain_instance.getDomInfo()
59 if domInfo:
60 return { 'uuid' : self.uuid,
61 'memory_actual' : domInfo["mem_kb"] * 1024,
62 'vcpus_number' : domInfo["online_vcpus"],
63 'vcpus_utilisation' : self.get_vcpus_utilisation()
64 }
65 else:
66 return { 'uuid' : self.uuid,
67 'memory_actual' : 0,
68 'vcpus_number' : 0,
69 'vcpus_utilisation' : {}
70 }