ia64/xen-unstable

changeset 13196:6f8d650f3ab1

Tidy up bindings for VDI class.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Wed Dec 27 00:35:27 2006 +0000 (2006-12-27)
parents d752d8ccd282
children a9a43705f26b
files tools/python/xen/xend/XendAPI.py
line diff
     1.1 --- a/tools/python/xen/xend/XendAPI.py	Tue Dec 26 19:49:11 2006 +0000
     1.2 +++ b/tools/python/xen/xend/XendAPI.py	Wed Dec 27 00:35:27 2006 +0000
     1.3 @@ -1192,74 +1192,54 @@ class XendAPI:
     1.4  
     1.5      VDI_methods = ['snapshot']
     1.6      VDI_funcs = ['get_by_name_label']
     1.7 +
     1.8 +    def _get_VDI(self, ref):
     1.9 +        return XendNode.instance().get_sr().xen_api_get_by_uuid(ref)
    1.10      
    1.11      def VDI_get_VBDs(self, session, vdi_ref):
    1.12          return xen_api_todo()
    1.13      
    1.14      def VDI_get_physical_utilisation(self, session, vdi_ref):
    1.15 -        sr = XendNode.instance().get_sr()
    1.16 -        image = sr.xen_api_get_by_uuid(vdi_ref)
    1.17 -        return xen_api_success(image.get_physical_utilisation())        
    1.18 +        return xen_api_success(self._get_VDI(vdi_ref).
    1.19 +                               get_physical_utilisation())        
    1.20      
    1.21      def VDI_get_sector_size(self, session, vdi_ref):
    1.22 -        sr = XendNode.instance().get_sr()
    1.23 -        image = sr.xen_api_get_by_uuid(vdi_ref)
    1.24 -        return xen_api_success(image.sector_size)        
    1.25 +        return xen_api_success(self._get_VDI(vdi_ref).sector_size)        
    1.26      
    1.27      def VDI_get_type(self, session, vdi_ref):
    1.28 -        sr = XendNode.instance().get_sr()
    1.29 -        image = sr.xen_api_get_by_uuid(vdi_ref)
    1.30 -        return xen_api_success(image.type)
    1.31 +        return xen_api_success(self._get_VDI(vdi_ref).type)
    1.32      
    1.33      def VDI_get_parent(self, session, vdi_ref):
    1.34 -        sr = XendNode.instance().get_sr()
    1.35 -        image = sr.xen_api_get_by_uuid(vdi_ref)
    1.36 -        return xen_api_success(image.parent)        
    1.37 +        return xen_api_success(self._get_VDI(vdi_ref).parent)        
    1.38      
    1.39      def VDI_get_children(self, session, vdi_ref):
    1.40 -        sr = XendNode.instance().get_sr()
    1.41 -        image = sr.xen_api_get_by_uuid(vdi_ref)
    1.42 -        return xen_api_success(image.children)        
    1.43 +        return xen_api_success(self._get_VDI(vdi_ref).children)        
    1.44      
    1.45      def VDI_get_name_label(self, session, vdi_ref):
    1.46 -        sr = XendNode.instance().get_sr()
    1.47 -        image = sr.xen_api_get_by_uuid(vdi_ref)
    1.48 -        return xen_api_success(image.name_label)
    1.49 +        return xen_api_success(self._get_VDI(vdi_ref).name_label)
    1.50  
    1.51      def VDI_get_name_description(self, session, vdi_ref):
    1.52 -        sr = XendNode.instance().get_sr()
    1.53 -        image = sr.xen_api_get_by_uuid(vdi_ref)
    1.54 -        return xen_api_success(image.name_description)
    1.55 +        return xen_api_success(self._get_VDI(vdi_ref).name_description)
    1.56  
    1.57      def VDI_get_SR(self, session, vdi_ref):
    1.58          sr = XendNode.instance().get_sr()
    1.59          return xen_api_success(sr.uuid)
    1.60  
    1.61      def VDI_get_virtual_size(self, session, vdi_ref):
    1.62 -        sr = XendNode.instance().get_sr()
    1.63 -        image = sr.xen_api_get_by_uuid(vdi_ref)
    1.64 -        return xen_api_success(image.virtual_size)
    1.65 +        return xen_api_success(self._get_VDI(vdi_ref).virtual_size)
    1.66  
    1.67      def VDI_get_sharable(self, session, vdi_ref):
    1.68 -        sr = XendNode.instance().get_sr()
    1.69 -        image = sr.xen_api_get_by_uuid(vdi_ref)
    1.70 -        return xen_api_success(image.sharable)
    1.71 +        return xen_api_success(self._get_VDI(vdi_ref).sharable)
    1.72  
    1.73      def VDI_get_read_only(self, session, vdi_ref):
    1.74 -        sr = XendNode.instance().get_sr()
    1.75 -        image = sr.xen_api_get_by_uuid(vdi_ref)
    1.76 -        return xen_api_success(image.sharable)        
    1.77 +        return xen_api_success(self._get_VDI(vdi_ref).read_only)        
    1.78  
    1.79      def VDI_set_name_label(self, session, vdi_ref, value):
    1.80 -        sr = XendNode.instance().get_sr()
    1.81 -        image = sr.xen_api_get_by_uuid(vdi_ref)
    1.82 -        image.name_label = value
    1.83 +        self._get_VDI(vdi_ref).name_label = value
    1.84          return xen_api_success_void()
    1.85  
    1.86      def VDI_set_name_description(self, session, vdi_ref, value):
    1.87 -        sr = XendNode.instance().get_sr()
    1.88 -        image = sr.xen_api_get_by_uuid(vdi_ref)
    1.89 -        image.name_description = value
    1.90 +        self._get_VDI(vdi_ref).name_description = value
    1.91          return xen_api_success_void()
    1.92  
    1.93      def VDI_set_SR(self, session, vdi_ref, value):
    1.94 @@ -1269,15 +1249,11 @@ class XendAPI:
    1.95          return xen_api_error(XEND_ERROR_UNSUPPORTED)
    1.96  
    1.97      def VDI_set_sharable(self, session, vdi_ref, value):
    1.98 -        sr = XendNode.instance().get_sr()
    1.99 -        image = sr.xen_api_get_by_uuid(vdi_ref)
   1.100 -        image.sharable = bool(value)
   1.101 +        self._get_VDI(vdi_ref).sharable = bool(value)
   1.102          return xen_api_success_void()
   1.103      
   1.104      def VDI_set_read_only(self, session, vdi_ref, value):
   1.105 -        sr = XendNode.instance().get_sr()
   1.106 -        image = sr.xen_api_get_by_uuid(vdi_ref)
   1.107 -        image.read_only = bool(value)
   1.108 +        self._get_VDI(vdi_ref).read_only = bool(value)
   1.109          return xen_api_success_void()
   1.110  
   1.111      # Object Methods
   1.112 @@ -1292,24 +1268,21 @@ class XendAPI:
   1.113      def VDI_get_record(self, session, vdi_ref):
   1.114          sr = XendNode.instance().get_sr()
   1.115          image = sr.xen_api_get_by_uuid(vdi_ref)
   1.116 -        if image:
   1.117 -            return xen_api_success({
   1.118 -                'uuid': vdi_ref,
   1.119 -                'name_label': image.name_label,
   1.120 -                'name_description': image.name_description,
   1.121 -                'SR': sr.uuid,
   1.122 -                'VBDs': [], # TODO
   1.123 -                'virtual_size': image.virtual_size,
   1.124 -                'physical_utilisation': image.physical_utilisation,
   1.125 -                'sector_size': image.sector_size,
   1.126 -                'type': image.type,
   1.127 -                'parent': image.parent,
   1.128 -                'children': image.children,
   1.129 -                'sharable': image.sharable,
   1.130 -                'read_only': image.read_only,
   1.131 -                })
   1.132 -
   1.133 -        return xen_api_error(['VDI_HANDLE_INVALID', vdi_ref])
   1.134 +        return xen_api_success({
   1.135 +            'uuid': vdi_ref,
   1.136 +            'name_label': image.name_label,
   1.137 +            'name_description': image.name_description,
   1.138 +            'SR': sr.uuid,
   1.139 +            'VBDs': [], # TODO
   1.140 +            'virtual_size': image.virtual_size,
   1.141 +            'physical_utilisation': image.physical_utilisation,
   1.142 +            'sector_size': image.sector_size,
   1.143 +            'type': image.type,
   1.144 +            'parent': image.parent,
   1.145 +            'children': image.children,
   1.146 +            'sharable': image.sharable,
   1.147 +            'read_only': image.read_only,
   1.148 +            })
   1.149  
   1.150      # Class Functions    
   1.151      def VDI_create(self, session, vdi_struct):