mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 10:11:27 +01:00
[XEND] Make existing autoplug classes implement new XendBase
signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
This commit is contained in:
1 parent
de8d95c660
commit
0207b91bee
5 files changed
+118
-105
No files matched your search
@@ -18,62 +18,82 @@
|
||||
|
||||
import uuid
|
||||
from XendLogging import log
|
||||
from xen.xend.XendBase import XendBase
|
||||
from xen.xend import XendAPIStore
|
||||
|
||||
|
||||
attr_inst = ['uuid',
|
||||
'host',
|
||||
'SR',
|
||||
'device_config']
|
||||
attr_ro = attr_inst + ['currently_attached']
|
||||
|
||||
|
||||
_all = {}
|
||||
|
||||
|
||||
def get(ref):
|
||||
return _all[ref]
|
||||
|
||||
|
||||
def get_all():
|
||||
return _all.values()
|
||||
|
||||
|
||||
def get_all_refs():
|
||||
return _all.keys()
|
||||
|
||||
|
||||
def get_by_SR(sr_ref):
|
||||
return [k for (k, v) in _all.items() if v.get_SR() == sr_ref]
|
||||
|
||||
|
||||
class XendPBD:
|
||||
class XendPBD(XendBase):
|
||||
"""Physical block devices."""
|
||||
|
||||
def getClass(self):
|
||||
return "PBD"
|
||||
|
||||
def __init__(self, record):
|
||||
if 'uuid' not in record:
|
||||
record['uuid'] = uuid.createString()
|
||||
def getAttrRO(self):
|
||||
attrRO = ['host',
|
||||
'SR',
|
||||
'device_config',
|
||||
'currently_attached']
|
||||
return XendBase.getAttrRO() + attrRO
|
||||
|
||||
import XendAPI
|
||||
for v in attr_inst:
|
||||
setattr(self, v, record[v])
|
||||
self.currently_attached = True
|
||||
_all[record['uuid']] = self
|
||||
def getAttrRW(self):
|
||||
attrRW = []
|
||||
return XendBase.getAttrRW() + attrRW
|
||||
|
||||
def getAttrInst(self):
|
||||
return ['uuid',
|
||||
'host',
|
||||
'SR',
|
||||
'device_config']
|
||||
|
||||
def getMethods(self):
|
||||
methods = ['destroy']
|
||||
return XendBase.getMethods() + methods
|
||||
|
||||
def getFuncs(self):
|
||||
funcs = ['create',
|
||||
'get_by_SR']
|
||||
return XendBase.getFuncs() + funcs
|
||||
|
||||
getClass = classmethod(getClass)
|
||||
getAttrRO = classmethod(getAttrRO)
|
||||
getAttrRW = classmethod(getAttrRW)
|
||||
getAttrInst = classmethod(getAttrInst)
|
||||
getMethods = classmethod(getMethods)
|
||||
getFuncs = classmethod(getFuncs)
|
||||
|
||||
def recreate(uuid, record):
|
||||
pbd = XendPBD(uuid, record)
|
||||
return uuid
|
||||
|
||||
def create(cls, record):
|
||||
uuid = genuuid.createString()
|
||||
pbd = XendPBD(uuid, record)
|
||||
return uuid
|
||||
|
||||
create = classmethod(create)
|
||||
|
||||
def __init__(self, uuid, record):
|
||||
XendBase.__init__(self, uuid, record)
|
||||
this.currently_attached = True
|
||||
|
||||
def get_host(self):
|
||||
return this.host
|
||||
|
||||
def get_SR(self):
|
||||
return this.SR
|
||||
|
||||
def get_device_config(self):
|
||||
return this.device_config
|
||||
|
||||
def get_currently_attached(self):
|
||||
return this.currently_attached
|
||||
|
||||
def destroy(self):
|
||||
if self.uuid in _all:
|
||||
del _all[self.uuid]
|
||||
pass
|
||||
|
||||
def get_by_SR(cls, sr_ref):
|
||||
pbds = XendAPIStore.get_all("PBD")
|
||||
return [pbd.get_uuid()
|
||||
for pbd in pbds
|
||||
if pbd.get_SR() == sr_ref]
|
||||
|
||||
|
||||
def get_record(self):
|
||||
import XendAPI
|
||||
result = {}
|
||||
for v in attr_ro:
|
||||
result[v] = getattr(self, v)
|
||||
return result
|
||||
|
||||
|
||||
for v in attr_ro:
|
||||
def f(v_):
|
||||
setattr(XendPBD, 'get_' + v_, lambda s: getattr(s, v_))
|
||||
f(v)
|
||||
get_by_SR = classmethod(get_by_SR)
|
||||
@@ -15,15 +15,30 @@
|
||||
# Copyright (c) 2006-2007 Xensource Inc.
|
||||
#============================================================================
|
||||
|
||||
from XendBase import XendBase
|
||||
|
||||
class XendPIFMetrics:
|
||||
class XendPIFMetrics(XendBase):
|
||||
"""PIF Metrics."""
|
||||
|
||||
def __init__(self, uuid):
|
||||
self.uuid = uuid
|
||||
|
||||
def set_PIF(self, pif):
|
||||
self.pif = pif
|
||||
def getClass(self):
|
||||
return "PIF_metrics"
|
||||
|
||||
def getAttrRO(self):
|
||||
attrRO = ['io_read_kbs',
|
||||
'io_write_kbs',
|
||||
'last_updated',
|
||||
'pif']
|
||||
return XendBase.getAttrRO() + attrRO
|
||||
|
||||
getClass = classmethod(getClass)
|
||||
getAttrRO = classmethod(getAttrRO)
|
||||
|
||||
def __init__(self, uuid, pif_uuid):
|
||||
XendBase.__init__(self, uuid, {})
|
||||
self.pif_uuid = pif_uuid
|
||||
|
||||
def get_pif(self):
|
||||
return self.pif_uuid
|
||||
|
||||
def get_io_read_kbs(self):
|
||||
return self._get_stat(0)
|
||||
@@ -33,19 +48,12 @@ class XendPIFMetrics:
|
||||
|
||||
def _get_stat(self, n):
|
||||
from xen.xend.XendNode import instance as xennode
|
||||
pifname = self.pif.device
|
||||
pifs_util = xennode().monitor.get_pifs_util()
|
||||
if pifname in pifs_util:
|
||||
return pifs_util[pifname][n]
|
||||
#pifname = self.pif.device
|
||||
#pifs_util = xennode().monitor.get_pifs_util()
|
||||
#if pifname in pifs_util:
|
||||
# return pifs_util[pifname][n]
|
||||
return 0.0
|
||||
|
||||
def get_last_updated(self):
|
||||
import xen.xend.XendAPI as XendAPI
|
||||
return XendAPI.now()
|
||||
|
||||
def get_record(self):
|
||||
return {'uuid' : self.uuid,
|
||||
'io_read_kbs' : self.get_io_read_kbs(),
|
||||
'io_write_kbs' : self.get_io_write_kbs(),
|
||||
'last_updated' : self.get_last_updated(),
|
||||
}
|
||||
@@ -30,7 +30,7 @@ import struct
|
||||
|
||||
from xen.util import mkdir
|
||||
import uuid
|
||||
import XendPBD
|
||||
from XendPBD import XendPBD
|
||||
from XendError import XendError
|
||||
from XendVDI import *
|
||||
from XendTask import XendTask
|
||||
|
||||
@@ -24,7 +24,7 @@ import sys
|
||||
|
||||
from XendError import XendError
|
||||
from XendVDI import *
|
||||
import XendPBD
|
||||
from XendPBD import XendPBD
|
||||
|
||||
XEND_STORAGE_NO_MAXIMUM = sys.maxint
|
||||
|
||||
|
||||
@@ -17,38 +17,36 @@
|
||||
#============================================================================
|
||||
|
||||
from xen.xend.XendLogging import log
|
||||
from xen.xend.XendBase import XendBase
|
||||
import xen.lowlevel.xc
|
||||
|
||||
xc = xen.lowlevel.xc.xc()
|
||||
|
||||
instances = {}
|
||||
|
||||
class XendVMMetrics:
|
||||
class XendVMMetrics(XendBase):
|
||||
"""VM Metrics."""
|
||||
|
||||
def get_by_uuid(_, uuid):
|
||||
return instances[uuid]
|
||||
def getClass(self):
|
||||
return "VM_metrics"
|
||||
|
||||
def getAttrRO(self):
|
||||
attrRO = ['memory_actual',
|
||||
'VCPUs_number',
|
||||
'VCPUs_utilisation',
|
||||
'VCPUs_CPU',
|
||||
'VCPUs_flags',
|
||||
'VCPUs_params',
|
||||
'state',
|
||||
'start_time',
|
||||
'last_updated']
|
||||
return XendBase.getAttrRO() + attrRO
|
||||
|
||||
get_by_uuid = classmethod(get_by_uuid)
|
||||
getClass = classmethod(getClass)
|
||||
getAttrRO = classmethod(getAttrRO)
|
||||
|
||||
def is_valid_vm_metrics(_, uuid):
|
||||
return uuid in instances
|
||||
|
||||
is_valid_vm_metrics = classmethod(is_valid_vm_metrics)
|
||||
|
||||
def get_all(_):
|
||||
return instances.keys()
|
||||
|
||||
get_all = classmethod(get_all)
|
||||
|
||||
def __init__(self, uuid, xend_domain_instance):
|
||||
self.uuid = uuid
|
||||
XendBase.__init__(self, uuid, {})
|
||||
self.xend_domain_instance = xend_domain_instance
|
||||
instances[uuid] = self
|
||||
|
||||
def get_uuid(self):
|
||||
return self.uuid
|
||||
|
||||
|
||||
def get_memory_actual(self):
|
||||
domInfo = self.xend_domain_instance.getDomInfo()
|
||||
if domInfo:
|
||||
@@ -145,16 +143,3 @@ class XendVMMetrics:
|
||||
def get_last_updated(self):
|
||||
import xen.xend.XendAPI as XendAPI
|
||||
return XendAPI.now()
|
||||
|
||||
def get_record(self):
|
||||
return { 'uuid' : self.uuid,
|
||||
'memory_actual' : self.get_memory_actual(),
|
||||
'VCPUs_number' : self.get_VCPUs_number(),
|
||||
'VCPUs_utilisation' : self.get_VCPUs_utilisation(),
|
||||
'VCPUs_CPU' : self.get_VCPUs_CPU(),
|
||||
'VCPUs_flags' : self.get_VCPUs_flags(),
|
||||
'VCPUs_params' : self.get_VCPUs_params(),
|
||||
'start_time' : self.get_start_time(),
|
||||
'state' : self.get_state(),
|
||||
'last_updated' : self.get_last_updated(),
|
||||
}
|
||||