ia64/xen-unstable
changeset 13198:11b9ccdc9417
Tidy and fix bindings for the SR class.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
Signed-off-by: Ewan Mellor <ewan@xensource.com>
author | Ewan Mellor <ewan@xensource.com> |
---|---|
date | Wed Dec 27 11:49:59 2006 +0000 (2006-12-27) |
parents | a9a43705f26b |
children | 088752354770 |
files | tools/python/xen/xend/XendAPI.py tools/python/xen/xend/XendStorageRepository.py |
line diff
1.1 --- a/tools/python/xen/xend/XendAPI.py Wed Dec 27 00:38:01 2006 +0000 1.2 +++ b/tools/python/xen/xend/XendAPI.py Wed Dec 27 11:49:59 2006 +0000 1.3 @@ -100,6 +100,7 @@ def catch_typeerror(func): 1.4 try: 1.5 return func(self, *args, **kwargs) 1.6 except TypeError, exn: 1.7 + #log.exception('catch_typeerror') 1.8 if hasattr(func, 'api') and func.api in argcounts: 1.9 # Assume that if the exception was thrown inside this 1.10 # file, then it is due to an invalid call from the client, 1.11 @@ -1446,37 +1447,40 @@ class XendAPI: 1.12 return xen_api_success(sr.get_record()) 1.13 1.14 # Attribute acceess 1.15 - def SR_get_VDIs(self, session, sr_ref): 1.16 - sr = XendNode.instance().get_sr() 1.17 - return xen_api_success(sr.list_images()) 1.18 1.19 - def SR_get_virtual_allocation(self, session, sr_ref): 1.20 - sr = XendNode.instance().get_sr() 1.21 - return sr.used_space_bytes() 1.22 + def _get_SR_func(self, _, func, conv = None): 1.23 + result = getattr(XendNode.instance().get_sr(), func)() 1.24 + if conv: 1.25 + result = conv(result) 1.26 + return xen_api_success(result) 1.27 + 1.28 + def _get_SR_attr(self, _, attr): 1.29 + return xen_api_success(str(getattr(XendNode.instance().get_sr(), 1.30 + attr))) 1.31 1.32 - def SR_get_physical_utilisation(self, session, sr_ref): 1.33 - sr = XendNode.instance().get_sr() 1.34 - return sr.used_space_bytes() 1.35 + def SR_get_VDIs(self, _, ref): 1.36 + return self._get_SR_func(ref, 'list_images') 1.37 + 1.38 + def SR_get_virtual_allocation(self, _, ref): 1.39 + return self._get_SR_func(ref, 'virtual_allocation', str) 1.40 1.41 - def SR_get_physical_size(self, session, sr_ref): 1.42 - sr = XendNode.instance().get_sr() 1.43 - return sr.total_space_bytes() 1.44 + def SR_get_physical_utilisation(self, _, ref): 1.45 + return self._get_SR_func(ref, 'used_space_bytes', str) 1.46 + 1.47 + def SR_get_physical_size(self, _, ref): 1.48 + return self._get_SR_func(ref, 'total_space_bytes', str) 1.49 1.50 - def SR_get_type(self, session, sr_ref): 1.51 - sr = XendNode.instance().get_sr() 1.52 - return xen_api_success(sr.type) 1.53 + def SR_get_type(self, _, ref): 1.54 + return self._get_SR_attr(ref, 'type') 1.55 1.56 - def SR_get_location(self, session, sr_ref): 1.57 - sr = XendNode.instance().get_sr() 1.58 - return xen_api_success(sr.location) 1.59 + def SR_get_location(self, _, ref): 1.60 + return self._get_SR_attr(ref, 'location') 1.61 1.62 - def SR_get_name_label(self, session, sr_ref): 1.63 - sr = XendNode.instance().get_sr() 1.64 - return xen_api_success(sr.name_label) 1.65 + def SR_get_name_label(self, _, ref): 1.66 + return self._get_SR_attr(ref, 'name_label') 1.67 1.68 - def SR_get_name_description(self, session, sr_ref): 1.69 - sr = XendNode.instance().get_sr() 1.70 - return xen_api_success(sr.name_description) 1.71 + def SR_get_name_description(self, _, ref): 1.72 + return self._get_SR_attr(ref, 'name_description') 1.73 1.74 def SR_set_name_label(self, session, sr_ref, value): 1.75 sr = XendNode.instance().get_sr()
2.1 --- a/tools/python/xen/xend/XendStorageRepository.py Wed Dec 27 00:38:01 2006 +0000 2.2 +++ b/tools/python/xen/xend/XendStorageRepository.py Wed Dec 27 11:49:59 2006 +0000 2.3 @@ -294,7 +294,11 @@ class XendStorageRepository: 2.4 """ 2.5 self.lock.acquire() 2.6 try: 2.7 - return self.storage_max 2.8 + if self.storage_max == XEND_STORAGE_NO_MAXIMUM: 2.9 + stfs = os.statvfs(self.location) 2.10 + return stfs.f_blocks * stfs.f_frsize 2.11 + else: 2.12 + return self.storage_max 2.13 finally: 2.14 self.lock.release() 2.15 2.16 @@ -304,10 +308,17 @@ class XendStorageRepository: 2.17 """ 2.18 self.lock.acquire() 2.19 try: 2.20 - total_used = 0 2.21 - for val in self.images.values(): 2.22 - total_used += val.physical_utilisation 2.23 - return total_used 2.24 + return self.storage_used 2.25 + finally: 2.26 + self.lock.release() 2.27 + 2.28 + def virtual_allocation(self): 2.29 + """Returns the total virtual space allocated within the storage repo. 2.30 + @rtype: int 2.31 + """ 2.32 + self.lock.acquire() 2.33 + try: 2.34 + return self.storage_alloc 2.35 finally: 2.36 self.lock.release() 2.37