mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 02:30:03 +01:00
Tidy and fix bindings for the SR class.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
This commit is contained in:
1 parent
866cc9cd43
commit
bbe21e102e
2 files changed
+44
-29
No files matched your search
@@ -100,6 +100,7 @@ def catch_typeerror(func):
|
||||
try:
|
||||
return func(self, *args, **kwargs)
|
||||
except TypeError, exn:
|
||||
#log.exception('catch_typeerror')
|
||||
if hasattr(func, 'api') and func.api in argcounts:
|
||||
# Assume that if the exception was thrown inside this
|
||||
# file, then it is due to an invalid call from the client,
|
||||
@@ -1446,37 +1447,40 @@ class XendAPI:
|
||||
return xen_api_success(sr.get_record())
|
||||
|
||||
# Attribute acceess
|
||||
def SR_get_VDIs(self, session, sr_ref):
|
||||
sr = XendNode.instance().get_sr()
|
||||
return xen_api_success(sr.list_images())
|
||||
|
||||
def SR_get_virtual_allocation(self, session, sr_ref):
|
||||
sr = XendNode.instance().get_sr()
|
||||
return sr.used_space_bytes()
|
||||
def _get_SR_func(self, _, func, conv = None):
|
||||
result = getattr(XendNode.instance().get_sr(), func)()
|
||||
if conv:
|
||||
result = conv(result)
|
||||
return xen_api_success(result)
|
||||
|
||||
def SR_get_physical_utilisation(self, session, sr_ref):
|
||||
sr = XendNode.instance().get_sr()
|
||||
return sr.used_space_bytes()
|
||||
def _get_SR_attr(self, _, attr):
|
||||
return xen_api_success(str(getattr(XendNode.instance().get_sr(),
|
||||
attr)))
|
||||
|
||||
def SR_get_physical_size(self, session, sr_ref):
|
||||
sr = XendNode.instance().get_sr()
|
||||
return sr.total_space_bytes()
|
||||
def SR_get_VDIs(self, _, ref):
|
||||
return self._get_SR_func(ref, 'list_images')
|
||||
|
||||
def SR_get_virtual_allocation(self, _, ref):
|
||||
return self._get_SR_func(ref, 'virtual_allocation', str)
|
||||
|
||||
def SR_get_physical_utilisation(self, _, ref):
|
||||
return self._get_SR_func(ref, 'used_space_bytes', str)
|
||||
|
||||
def SR_get_physical_size(self, _, ref):
|
||||
return self._get_SR_func(ref, 'total_space_bytes', str)
|
||||
|
||||
def SR_get_type(self, session, sr_ref):
|
||||
sr = XendNode.instance().get_sr()
|
||||
return xen_api_success(sr.type)
|
||||
def SR_get_type(self, _, ref):
|
||||
return self._get_SR_attr(ref, 'type')
|
||||
|
||||
def SR_get_location(self, session, sr_ref):
|
||||
sr = XendNode.instance().get_sr()
|
||||
return xen_api_success(sr.location)
|
||||
def SR_get_location(self, _, ref):
|
||||
return self._get_SR_attr(ref, 'location')
|
||||
|
||||
def SR_get_name_label(self, session, sr_ref):
|
||||
sr = XendNode.instance().get_sr()
|
||||
return xen_api_success(sr.name_label)
|
||||
def SR_get_name_label(self, _, ref):
|
||||
return self._get_SR_attr(ref, 'name_label')
|
||||
|
||||
def SR_get_name_description(self, session, sr_ref):
|
||||
sr = XendNode.instance().get_sr()
|
||||
return xen_api_success(sr.name_description)
|
||||
def SR_get_name_description(self, _, ref):
|
||||
return self._get_SR_attr(ref, 'name_description')
|
||||
|
||||
def SR_set_name_label(self, session, sr_ref, value):
|
||||
sr = XendNode.instance().get_sr()
|
||||
|
||||
@@ -294,7 +294,11 @@ class XendStorageRepository:
|
||||
"""
|
||||
self.lock.acquire()
|
||||
try:
|
||||
return self.storage_max
|
||||
if self.storage_max == XEND_STORAGE_NO_MAXIMUM:
|
||||
stfs = os.statvfs(self.location)
|
||||
return stfs.f_blocks * stfs.f_frsize
|
||||
else:
|
||||
return self.storage_max
|
||||
finally:
|
||||
self.lock.release()
|
||||
|
||||
@@ -304,10 +308,17 @@ class XendStorageRepository:
|
||||
"""
|
||||
self.lock.acquire()
|
||||
try:
|
||||
total_used = 0
|
||||
for val in self.images.values():
|
||||
total_used += val.physical_utilisation
|
||||
return total_used
|
||||
return self.storage_used
|
||||
finally:
|
||||
self.lock.release()
|
||||
|
||||
def virtual_allocation(self):
|
||||
"""Returns the total virtual space allocated within the storage repo.
|
||||
@rtype: int
|
||||
"""
|
||||
self.lock.acquire()
|
||||
try:
|
||||
return self.storage_alloc
|
||||
finally:
|
||||
self.lock.release()
|
||||
|
||||
|
||||