ia64/xen-unstable

changeset 14571:75c797744eb4

Convert XendVMMetrics into an autoplug class. Tidy up our destroy methods
on the way -- metrics classes cannot be destroyed.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Tue Mar 27 00:48:46 2007 +0100 (2007-03-27)
parents 03d0dda70a8f
children f6c38a084bef
files tools/python/xen/xend/XendAPI.py tools/python/xen/xend/XendVMMetrics.py
line diff
     1.1 --- a/tools/python/xen/xend/XendAPI.py	Tue Mar 27 00:19:20 2007 +0100
     1.2 +++ b/tools/python/xen/xend/XendAPI.py	Tue Mar 27 00:48:46 2007 +0100
     1.3 @@ -438,7 +438,8 @@ class XendAPI(object):
     1.4          }
     1.5  
     1.6          autoplug_classes = {
     1.7 -            'network' : XendNetwork
     1.8 +            'network'    : XendNetwork,
     1.9 +            'VM_metrics' : XendVMMetrics,
    1.10          }
    1.11  
    1.12          # Cheat methods
    1.13 @@ -469,9 +470,8 @@ class XendAPI(object):
    1.14          # class, and wrapped up to be compatible with the Xen-API.
    1.15          
    1.16          for api_cls, impl_cls in autoplug_classes.items():
    1.17 -            getter = getattr(cls, '_%s_get' % api_cls)
    1.18 -
    1.19              def doit(n):
    1.20 +                getter = getattr(cls, '_%s_get' % api_cls)
    1.21                  dot_n = '%s.%s' % (api_cls, n)
    1.22                  full_n = '%s_%s' % (api_cls, n)
    1.23                  if not hasattr(cls, full_n):
    1.24 @@ -557,7 +557,7 @@ class XendAPI(object):
    1.25  
    1.26      Base_attr_ro = ['uuid']
    1.27      Base_attr_rw = []
    1.28 -    Base_methods = [('destroy', None), ('get_record', 'Struct')]
    1.29 +    Base_methods = [('get_record', 'Struct')]
    1.30      Base_funcs   = [('get_all', 'Set'), ('get_by_uuid', None)]
    1.31  
    1.32      # Xen API: Class Session
    1.33 @@ -960,7 +960,8 @@ class XendAPI(object):
    1.34                         'name_description',
    1.35                         'other_config']
    1.36      network_methods = [('add_to_other_config', None),
    1.37 -                       ('remove_from_other_config', None)]
    1.38 +                       ('remove_from_other_config', None),
    1.39 +                       ('destroy', None)]
    1.40      network_funcs = [('create', None)]
    1.41      
    1.42      def _network_get(self, _, ref):
    1.43 @@ -989,7 +990,7 @@ class XendAPI(object):
    1.44  
    1.45      PIF_attr_inst = PIF_attr_rw
    1.46  
    1.47 -    PIF_methods = [('create_VLAN', 'int')]
    1.48 +    PIF_methods = [('create_VLAN', 'int'), ('destroy', None)]
    1.49  
    1.50      def _get_PIF(self, ref):
    1.51          return XendNode.instance().pifs[ref]
    1.52 @@ -1152,7 +1153,8 @@ class XendAPI(object):
    1.53                    ('save', None),
    1.54                    ('set_memory_dynamic_max_live', None),
    1.55                    ('set_memory_dynamic_min_live', None),
    1.56 -                  ('send_trigger', None)]
    1.57 +                  ('send_trigger', None),
    1.58 +                  ('destroy', None)]
    1.59      
    1.60      VM_funcs  = [('create', 'VM'),
    1.61                   ('restore', None),
    1.62 @@ -1696,42 +1698,12 @@ class XendAPI(object):
    1.63      VM_metrics_attr_rw = []
    1.64      VM_metrics_methods = []
    1.65  
    1.66 -    def _VM_metrics_get(self, ref):
    1.67 +    def _VM_metrics_get(self, _, ref):
    1.68          return XendVMMetrics.get_by_uuid(ref)
    1.69  
    1.70      def VM_metrics_get_all(self, _):
    1.71          return xen_api_success(XendVMMetrics.get_all())
    1.72  
    1.73 -    def VM_metrics_get_record(self, _, ref):
    1.74 -        return xen_api_success(self._VM_metrics_get(ref).get_record())
    1.75 -
    1.76 -    def VM_metrics_get_memory_actual(self, _, ref):
    1.77 -        return xen_api_success(self._VM_metrics_get(ref).get_memory_actual())
    1.78 -
    1.79 -    def VM_metrics_get_VCPUs_number(self, _, ref):
    1.80 -        return xen_api_success(self._VM_metrics_get(ref).get_VCPUs_number())
    1.81 -
    1.82 -    def VM_metrics_get_VCPUs_utilisation(self, _, ref):
    1.83 -        return xen_api_success(self._VM_metrics_get(ref).get_VCPUs_utilisation())
    1.84 -
    1.85 -    def VM_metrics_get_VCPUs_CPU(self, _, ref):
    1.86 -        return xen_api_success(self._VM_metrics_get(ref).get_VCPUs_CPU())
    1.87 -    
    1.88 -    def VM_metrics_get_VCPUs_flags(self, _, ref):
    1.89 -        return xen_api_success(self._VM_metrics_get(ref).get_VCPUs_flags())
    1.90 -
    1.91 -    def VM_metrics_get_VCPUs_params(self, _, ref):
    1.92 -        return xen_api_success(self._VM_metrics_get(ref).get_VCPUs_params())
    1.93 -
    1.94 -    def VM_metrics_get_start_time(self, _, ref):
    1.95 -        return xen_api_success(self._VM_metrics_get(ref).get_start_time())
    1.96 -
    1.97 -    def VM_metrics_get_state(self, _, ref):
    1.98 -        return xen_api_success(self._VM_metrics_get(ref).get_state())
    1.99 -
   1.100 -    def VM_metrics_get_last_updated(self, _1, _2):
   1.101 -        return xen_api_success(now())
   1.102 -
   1.103  
   1.104      # Xen API: Class VBD
   1.105      # ----------------------------------------------------------------
   1.106 @@ -1747,7 +1719,7 @@ class XendAPI(object):
   1.107  
   1.108      VBD_attr_inst = VBD_attr_rw
   1.109  
   1.110 -    VBD_methods = [('media_change', None)]
   1.111 +    VBD_methods = [('media_change', None), ('destroy', None)]
   1.112      VBD_funcs = [('create', 'VBD')]
   1.113      
   1.114      # object methods
   1.115 @@ -1924,6 +1896,7 @@ class XendAPI(object):
   1.116  
   1.117      VIF_attr_inst = VIF_attr_rw
   1.118  
   1.119 +    VIF_methods = [('destroy', None)]
   1.120      VIF_funcs = [('create', 'VIF')]
   1.121  
   1.122                   
   1.123 @@ -2065,7 +2038,7 @@ class XendAPI(object):
   1.124                     'other_config']
   1.125      VDI_attr_inst = VDI_attr_ro + VDI_attr_rw
   1.126  
   1.127 -    VDI_methods = [('snapshot', 'VDI')]
   1.128 +    VDI_methods = [('snapshot', 'VDI'), ('destroy', None)]
   1.129      VDI_funcs = [('create', 'VDI'),
   1.130                    ('get_by_name_label', 'Set(VDI)')]
   1.131  
   1.132 @@ -2182,6 +2155,7 @@ class XendAPI(object):
   1.133  
   1.134      VTPM_attr_inst = VTPM_attr_rw
   1.135  
   1.136 +    VTPM_methods = [('destroy', None)]
   1.137      VTPM_funcs = [('create', 'VTPM')]
   1.138      
   1.139      # object methods
   1.140 @@ -2340,7 +2314,7 @@ class XendAPI(object):
   1.141                      'name_label',
   1.142                      'name_description']
   1.143      
   1.144 -    SR_methods = [('clone', 'SR')]
   1.145 +    SR_methods = [('clone', 'SR'), ('destroy', None)]
   1.146      SR_funcs = [('get_by_name_label', 'Set(SR)'),
   1.147                  ('get_by_uuid', 'SR')]
   1.148  
     2.1 --- a/tools/python/xen/xend/XendVMMetrics.py	Tue Mar 27 00:19:20 2007 +0100
     2.2 +++ b/tools/python/xen/xend/XendVMMetrics.py	Tue Mar 27 00:48:46 2007 +0100
     2.3 @@ -140,8 +140,11 @@ class XendVMMetrics:
     2.4      def get_start_time(self):
     2.5          return self.xend_domain_instance.info.get("start_time", -1)
     2.6      
     2.7 +    def get_last_updated(self):
     2.8 +        import xen.xend.XendAPI as XendAPI
     2.9 +        return XendAPI.now()
    2.10 +    
    2.11      def get_record(self):
    2.12 -        import xen.xend.XendAPI as XendAPI
    2.13          return { 'uuid'              : self.uuid,
    2.14                   'memory_actual'     : self.get_memory_actual(),
    2.15                   'VCPUs_number'      : self.get_VCPUs_number(),
    2.16 @@ -151,5 +154,5 @@ class XendVMMetrics:
    2.17                   'VCPUs_params'      : self.get_VCPUs_params(),
    2.18                   'start_time'        : self.get_start_time(),
    2.19                   'state'             : self.get_state(),
    2.20 -                 'last_updated'      : XendAPI.now(),
    2.21 +                 'last_updated'      : self.get_last_updated(),
    2.22                 }