mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 18:50:05 +01:00
Added some more fields to host_cpu.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
This commit is contained in:
1 parent
b3c8af5814
commit
d8309d27a1
5 files changed
+209
-147
No files matched your search
@@ -753,27 +753,44 @@ class XendAPI(object):
|
||||
|
||||
host_cpu_attr_ro = ['host',
|
||||
'number',
|
||||
'vendor',
|
||||
'speed',
|
||||
'modelname',
|
||||
'stepping',
|
||||
'flags',
|
||||
'utilisation']
|
||||
|
||||
# attributes
|
||||
def host_cpu_get_host(self, session, host_cpu_ref):
|
||||
def _host_cpu_get(self, ref, field):
|
||||
return xen_api_success(
|
||||
XendNode.instance().get_host_cpu_field(ref, field))
|
||||
|
||||
def host_cpu_get_host(self, _, ref):
|
||||
return xen_api_success(XendNode.instance().uuid)
|
||||
def host_cpu_get_utilisation(self, session, host_cpu_ref):
|
||||
util = XendNode.instance().get_host_cpu_load(host_cpu_ref)
|
||||
return xen_api_success(util)
|
||||
def host_cpu_get_number(self, session, host_cpu_ref):
|
||||
num = XendNode.instance().get_host_cpu_number(host_cpu_ref)
|
||||
return xen_api_success(num)
|
||||
def host_cpu_get_number(self, _, ref):
|
||||
return self._host_cpu_get(ref, 'number')
|
||||
def host_cpu_get_vendor(self, _, ref):
|
||||
return self._host_cpu_get(ref, 'vendor')
|
||||
def host_cpu_get_speed(self, _, ref):
|
||||
return self._host_cpu_get(ref, 'speed')
|
||||
def host_cpu_get_modelname(self, _, ref):
|
||||
return self._host_cpu_get(ref, 'modelname')
|
||||
def host_cpu_get_stepping(self, _, ref):
|
||||
return self._host_cpu_get(ref, 'stepping')
|
||||
def host_cpu_get_flags(self, _, ref):
|
||||
return self._host_cpu_get(ref, 'flags')
|
||||
def host_cpu_get_utilisation(self, _, ref):
|
||||
return xen_api_success(XendNode.instance().get_host_cpu_load(ref))
|
||||
|
||||
# object methods
|
||||
def host_cpu_destroy(self, session, host_cpu_ref):
|
||||
return xen_api_error(XEND_ERROR_UNSUPPORTED)
|
||||
def host_cpu_get_record(self, session, host_cpu_ref):
|
||||
def host_cpu_get_record(self, _, ref):
|
||||
node = XendNode.instance()
|
||||
record = {'uuid': host_cpu_ref,
|
||||
'host': node.uuid,
|
||||
'number': node.get_host_cpu_number(host_cpu_ref),
|
||||
'utilisation': node.get_host_cpu_load(host_cpu_ref)}
|
||||
record = dict([(f, node.get_host_cpu_field(ref, f))
|
||||
for f in self.host_cpu_attr_ro
|
||||
if f not in ['uuid', 'host', 'utilisation']])
|
||||
record['uuid'] = ref
|
||||
record['host'] = node.uuid
|
||||
record['utilisation'] = node.get_host_cpu_load(ref)
|
||||
return xen_api_success(record)
|
||||
|
||||
# class methods
|
||||
|
||||
@@ -81,7 +81,7 @@ class XendNode:
|
||||
for cpu_uuid, cpu in saved_cpus.items():
|
||||
self.cpus[cpu_uuid] = cpu
|
||||
|
||||
# verify we have enough cpus here
|
||||
cpuinfo = parse_proc_cpuinfo()
|
||||
physinfo = self.physinfo_dict()
|
||||
cpu_count = physinfo['nr_cpus']
|
||||
cpu_features = physinfo['hw_caps']
|
||||
@@ -91,12 +91,23 @@ class XendNode:
|
||||
if cpu_count != len(self.cpus):
|
||||
self.cpus = {}
|
||||
for i in range(cpu_count):
|
||||
cpu_uuid = uuid.createString()
|
||||
cpu_info = {'uuid': cpu_uuid,
|
||||
'host': self.uuid,
|
||||
'number': i,
|
||||
'features': cpu_features}
|
||||
self.cpus[cpu_uuid] = cpu_info
|
||||
u = uuid.createString()
|
||||
self.cpus[u] = {'uuid': u, 'number': i }
|
||||
|
||||
for u in self.cpus.keys():
|
||||
log.error(self.cpus[u])
|
||||
number = self.cpus[u]['number']
|
||||
log.error(number)
|
||||
log.error(cpuinfo)
|
||||
self.cpus[u].update(
|
||||
{ 'host' : self.uuid,
|
||||
'features' : cpu_features,
|
||||
'speed' : int(float(cpuinfo[number]['cpu MHz'])),
|
||||
'vendor' : cpuinfo[number]['vendor_id'],
|
||||
'modelname': cpuinfo[number]['model name'],
|
||||
'stepping' : cpuinfo[number]['stepping'],
|
||||
'flags' : cpuinfo[number]['flags'],
|
||||
})
|
||||
|
||||
self.pifs = {}
|
||||
self.pif_metrics = {}
|
||||
@@ -368,18 +379,12 @@ class XendNode:
|
||||
else:
|
||||
raise XendError('Invalid CPU Reference')
|
||||
|
||||
def get_host_cpu_features(self, host_cpu_ref):
|
||||
def get_host_cpu_field(self, ref, field):
|
||||
try:
|
||||
return self.cpus[host_cpu_ref]['features']
|
||||
return self.cpus[ref][field]
|
||||
except KeyError:
|
||||
raise XendError('Invalid CPU Reference')
|
||||
|
||||
def get_host_cpu_number(self, host_cpu_ref):
|
||||
try:
|
||||
return self.cpus[host_cpu_ref]['number']
|
||||
except KeyError:
|
||||
raise XendError('Invalid CPU Reference')
|
||||
|
||||
def get_host_cpu_load(self, host_cpu_ref):
|
||||
host_cpu = self.cpus.get(host_cpu_ref)
|
||||
if not host_cpu:
|
||||
@@ -542,6 +547,31 @@ class XendNode:
|
||||
pif.refresh(Brctl.get_state())
|
||||
|
||||
|
||||
def parse_proc_cpuinfo():
|
||||
cpuinfo = {}
|
||||
f = file('/proc/cpuinfo', 'r')
|
||||
try:
|
||||
p = -1
|
||||
d = {}
|
||||
for line in f:
|
||||
keyvalue = line.split(':')
|
||||
if len(keyvalue) != 2:
|
||||
continue
|
||||
key = keyvalue[0].strip()
|
||||
val = keyvalue[1].strip()
|
||||
if key == 'processor':
|
||||
if p != -1:
|
||||
cpuinfo[p] = d
|
||||
p = int(val)
|
||||
d = {}
|
||||
else:
|
||||
d[key] = val
|
||||
cpuinfo[p] = d
|
||||
return cpuinfo
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
|
||||
def instance():
|
||||
global inst
|
||||
try:
|
||||
|
||||