ia64/xen-unstable

changeset 14938:7317e701f3e7

[XEND] Make existing autoplug classes implement new XendBase

signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
author Tom Wilkie <tom.wilkie@gmail.com>
date Wed Apr 25 16:14:20 2007 +0100 (2007-04-25)
parents 5d2e5d05e828
children 31f6f85778e5
files tools/python/xen/xend/XendPBD.py tools/python/xen/xend/XendPIFMetrics.py tools/python/xen/xend/XendQCoWStorageRepo.py tools/python/xen/xend/XendStorageRepository.py tools/python/xen/xend/XendVMMetrics.py
line diff
     1.1 --- a/tools/python/xen/xend/XendPBD.py	Wed Apr 25 16:12:41 2007 +0100
     1.2 +++ b/tools/python/xen/xend/XendPBD.py	Wed Apr 25 16:14:20 2007 +0100
     1.3 @@ -18,62 +18,82 @@
     1.4  
     1.5  import uuid
     1.6  from XendLogging import log
     1.7 -
     1.8 +from xen.xend.XendBase import XendBase
     1.9 +from xen.xend import XendAPIStore
    1.10  
    1.11 -attr_inst = ['uuid',
    1.12 -             'host',
    1.13 -             'SR',
    1.14 -             'device_config']
    1.15 -attr_ro = attr_inst + ['currently_attached']
    1.16 -
    1.17 +class XendPBD(XendBase):
    1.18 +    """Physical block devices."""
    1.19  
    1.20 -_all = {}
    1.21 -
    1.22 +    def getClass(self):
    1.23 +        return "PBD"
    1.24 +    
    1.25 +    def getAttrRO(self):
    1.26 +        attrRO = ['host',
    1.27 +                  'SR',
    1.28 +                  'device_config',
    1.29 +                  'currently_attached']
    1.30 +        return XendBase.getAttrRO() + attrRO
    1.31  
    1.32 -def get(ref):
    1.33 -    return _all[ref]
    1.34 -
    1.35 +    def getAttrRW(self):
    1.36 +        attrRW = []
    1.37 +        return XendBase.getAttrRW() + attrRW
    1.38  
    1.39 -def get_all():
    1.40 -    return _all.values()
    1.41 +    def getAttrInst(self):
    1.42 +        return ['uuid',
    1.43 +                'host',
    1.44 +                'SR',
    1.45 +                'device_config']
    1.46  
    1.47 +    def getMethods(self):
    1.48 +        methods = ['destroy']
    1.49 +        return XendBase.getMethods() + methods
    1.50  
    1.51 -def get_all_refs():
    1.52 -    return _all.keys()
    1.53 -
    1.54 +    def getFuncs(self):
    1.55 +        funcs = ['create',
    1.56 +                 'get_by_SR']
    1.57 +        return XendBase.getFuncs() + funcs
    1.58  
    1.59 -def get_by_SR(sr_ref):
    1.60 -    return [k for (k, v) in _all.items() if v.get_SR() == sr_ref]
    1.61 +    getClass    = classmethod(getClass)
    1.62 +    getAttrRO   = classmethod(getAttrRO)
    1.63 +    getAttrRW   = classmethod(getAttrRW)
    1.64 +    getAttrInst = classmethod(getAttrInst)
    1.65 +    getMethods  = classmethod(getMethods)
    1.66 +    getFuncs    = classmethod(getFuncs)
    1.67  
    1.68 -
    1.69 -class XendPBD:
    1.70 -    """Physical block devices."""
    1.71 +    def recreate(uuid, record):
    1.72 +        pbd = XendPBD(uuid, record)
    1.73 +        return uuid
    1.74      
    1.75 -    def __init__(self, record):
    1.76 -        if 'uuid' not in record:
    1.77 -            record['uuid'] = uuid.createString()
    1.78 +    def create(cls, record):
    1.79 +        uuid = genuuid.createString()
    1.80 +        pbd = XendPBD(uuid, record)
    1.81 +        return uuid       
    1.82 +
    1.83 +    create = classmethod(create)
    1.84 +    
    1.85 +    def __init__(self, uuid, record):
    1.86 +        XendBase.__init__(self, uuid, record)
    1.87 +        this.currently_attached = True
    1.88  
    1.89 -        import XendAPI
    1.90 -        for v in attr_inst:
    1.91 -            setattr(self, v, record[v])
    1.92 -        self.currently_attached = True
    1.93 -        _all[record['uuid']] = self
    1.94 +    def get_host(self):
    1.95 +        return this.host
    1.96 +    
    1.97 +    def get_SR(self):
    1.98 +        return this.SR
    1.99  
   1.100 +    def get_device_config(self):
   1.101 +        return this.device_config
   1.102 +
   1.103 +    def get_currently_attached(self):
   1.104 +        return this.currently_attached
   1.105  
   1.106      def destroy(self):
   1.107 -        if self.uuid in _all:
   1.108 -            del _all[self.uuid]
   1.109 -
   1.110 +        pass
   1.111 +    
   1.112 +    def get_by_SR(cls, sr_ref):
   1.113 +        pbds = XendAPIStore.get_all("PBD")
   1.114 +        return [pbd.get_uuid()
   1.115 +                for pbd in pbds
   1.116 +                if pbd.get_SR() == sr_ref]
   1.117  
   1.118 -    def get_record(self):
   1.119 -        import XendAPI
   1.120 -        result = {}
   1.121 -        for v in attr_ro:
   1.122 -            result[v] = getattr(self, v)
   1.123 -        return result
   1.124 -
   1.125 -
   1.126 -for v in attr_ro:
   1.127 -    def f(v_):
   1.128 -        setattr(XendPBD, 'get_' + v_, lambda s: getattr(s, v_))
   1.129 -    f(v)
   1.130 +    get_by_SR = classmethod(get_by_SR)
     2.1 --- a/tools/python/xen/xend/XendPIFMetrics.py	Wed Apr 25 16:12:41 2007 +0100
     2.2 +++ b/tools/python/xen/xend/XendPIFMetrics.py	Wed Apr 25 16:14:20 2007 +0100
     2.3 @@ -15,15 +15,30 @@
     2.4  # Copyright (c) 2006-2007 Xensource Inc.
     2.5  #============================================================================
     2.6  
     2.7 +from XendBase import XendBase
     2.8  
     2.9 -class XendPIFMetrics:
    2.10 +class XendPIFMetrics(XendBase):
    2.11      """PIF Metrics."""
    2.12 +
    2.13 +    def getClass(self):
    2.14 +        return "PIF_metrics"
    2.15      
    2.16 -    def __init__(self, uuid):
    2.17 -        self.uuid = uuid
    2.18 +    def getAttrRO(self):
    2.19 +        attrRO =  ['io_read_kbs',
    2.20 +                   'io_write_kbs',
    2.21 +                   'last_updated',
    2.22 +                   'pif']
    2.23 +        return XendBase.getAttrRO() + attrRO
    2.24  
    2.25 -    def set_PIF(self, pif):
    2.26 -        self.pif = pif
    2.27 +    getClass    = classmethod(getClass)
    2.28 +    getAttrRO   = classmethod(getAttrRO)
    2.29 +
    2.30 +    def __init__(self, uuid, pif_uuid):
    2.31 +        XendBase.__init__(self, uuid, {})
    2.32 +        self.pif_uuid = pif_uuid
    2.33 +
    2.34 +    def get_pif(self):
    2.35 +        return self.pif_uuid
    2.36  
    2.37      def get_io_read_kbs(self):
    2.38          return self._get_stat(0)
    2.39 @@ -33,19 +48,12 @@ class XendPIFMetrics:
    2.40  
    2.41      def _get_stat(self, n):
    2.42          from xen.xend.XendNode import instance as xennode
    2.43 -        pifname = self.pif.device
    2.44 -        pifs_util = xennode().monitor.get_pifs_util()
    2.45 -        if pifname in pifs_util:
    2.46 -            return pifs_util[pifname][n]
    2.47 +        #pifname = self.pif.device
    2.48 +        #pifs_util = xennode().monitor.get_pifs_util()
    2.49 +        #if pifname in pifs_util:
    2.50 +        #    return pifs_util[pifname][n]
    2.51          return 0.0
    2.52  
    2.53      def get_last_updated(self):
    2.54          import xen.xend.XendAPI as XendAPI
    2.55          return XendAPI.now()
    2.56 -
    2.57 -    def get_record(self):
    2.58 -        return {'uuid'         : self.uuid,
    2.59 -                'io_read_kbs'  : self.get_io_read_kbs(),
    2.60 -                'io_write_kbs' : self.get_io_write_kbs(),
    2.61 -                'last_updated' : self.get_last_updated(),
    2.62 -                }
     3.1 --- a/tools/python/xen/xend/XendQCoWStorageRepo.py	Wed Apr 25 16:12:41 2007 +0100
     3.2 +++ b/tools/python/xen/xend/XendQCoWStorageRepo.py	Wed Apr 25 16:14:20 2007 +0100
     3.3 @@ -30,7 +30,7 @@ import struct
     3.4  
     3.5  from xen.util import mkdir
     3.6  import uuid
     3.7 -import XendPBD
     3.8 +from XendPBD import XendPBD
     3.9  from XendError import XendError
    3.10  from XendVDI import *
    3.11  from XendTask import XendTask
     4.1 --- a/tools/python/xen/xend/XendStorageRepository.py	Wed Apr 25 16:12:41 2007 +0100
     4.2 +++ b/tools/python/xen/xend/XendStorageRepository.py	Wed Apr 25 16:14:20 2007 +0100
     4.3 @@ -24,7 +24,7 @@ import sys
     4.4  
     4.5  from XendError import XendError
     4.6  from XendVDI import *
     4.7 -import XendPBD
     4.8 +from XendPBD import XendPBD
     4.9  
    4.10  XEND_STORAGE_NO_MAXIMUM = sys.maxint
    4.11  
     5.1 --- a/tools/python/xen/xend/XendVMMetrics.py	Wed Apr 25 16:12:41 2007 +0100
     5.2 +++ b/tools/python/xen/xend/XendVMMetrics.py	Wed Apr 25 16:14:20 2007 +0100
     5.3 @@ -17,38 +17,36 @@
     5.4  #============================================================================
     5.5  
     5.6  from xen.xend.XendLogging import log
     5.7 +from xen.xend.XendBase import XendBase
     5.8  import xen.lowlevel.xc
     5.9  
    5.10  xc = xen.lowlevel.xc.xc()
    5.11  
    5.12 -instances = {}
    5.13 -
    5.14 -class XendVMMetrics:
    5.15 +class XendVMMetrics(XendBase):
    5.16      """VM Metrics."""
    5.17  
    5.18 -    def get_by_uuid(_, uuid):
    5.19 -        return instances[uuid]
    5.20 -
    5.21 -    get_by_uuid = classmethod(get_by_uuid)
    5.22 -
    5.23 -    def is_valid_vm_metrics(_, uuid):
    5.24 -        return uuid in instances
    5.25 -
    5.26 -    is_valid_vm_metrics = classmethod(is_valid_vm_metrics)
    5.27 +    def getClass(self):
    5.28 +        return "VM_metrics"
    5.29 +    
    5.30 +    def getAttrRO(self):
    5.31 +        attrRO = ['memory_actual',
    5.32 +                  'VCPUs_number',
    5.33 +                  'VCPUs_utilisation',
    5.34 +                  'VCPUs_CPU',
    5.35 +                  'VCPUs_flags',
    5.36 +                  'VCPUs_params',
    5.37 +                  'state',
    5.38 +                  'start_time',
    5.39 +                  'last_updated']
    5.40 +        return XendBase.getAttrRO() + attrRO
    5.41  
    5.42 -    def get_all(_):
    5.43 -        return instances.keys()
    5.44 +    getClass    = classmethod(getClass)
    5.45 +    getAttrRO   = classmethod(getAttrRO)
    5.46  
    5.47 -    get_all = classmethod(get_all)
    5.48 -   
    5.49      def __init__(self, uuid, xend_domain_instance):
    5.50 -        self.uuid = uuid
    5.51 +        XendBase.__init__(self, uuid, {})
    5.52          self.xend_domain_instance = xend_domain_instance
    5.53 -        instances[uuid] = self
    5.54 -
    5.55 -    def get_uuid(self):
    5.56 -        return self.uuid
    5.57 -
    5.58 +        
    5.59      def get_memory_actual(self):
    5.60          domInfo = self.xend_domain_instance.getDomInfo()
    5.61          if domInfo:
    5.62 @@ -145,16 +143,3 @@ class XendVMMetrics:
    5.63      def get_last_updated(self):
    5.64          import xen.xend.XendAPI as XendAPI
    5.65          return XendAPI.now()
    5.66 -    
    5.67 -    def get_record(self):
    5.68 -        return { 'uuid'              : self.uuid,
    5.69 -                 'memory_actual'     : self.get_memory_actual(),
    5.70 -                 'VCPUs_number'      : self.get_VCPUs_number(),
    5.71 -                 'VCPUs_utilisation' : self.get_VCPUs_utilisation(),
    5.72 -                 'VCPUs_CPU'         : self.get_VCPUs_CPU(),
    5.73 -                 'VCPUs_flags'       : self.get_VCPUs_flags(),
    5.74 -                 'VCPUs_params'      : self.get_VCPUs_params(),
    5.75 -                 'start_time'        : self.get_start_time(),
    5.76 -                 'state'             : self.get_state(),
    5.77 -                 'last_updated'      : self.get_last_updated(),
    5.78 -               }