WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] Tidy and fix bindings for the SR class.

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] Tidy and fix bindings for the SR class.
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Fri, 29 Dec 2006 14:20:05 -0800
Delivery-date: Fri, 29 Dec 2006 14:20:50 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Ewan Mellor <ewan@xxxxxxxxxxxxx>
# Date 1167220199 0
# Node ID 11b9ccdc94175a468667fa9313dc6ddf3fe652b0
# Parent  a9a43705f26b0892f722da1b6db8e98db49bad35
Tidy and fix bindings for the SR class.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>
---
 tools/python/xen/xend/XendAPI.py               |   66 +++++++++++++------------
 tools/python/xen/xend/XendStorageRepository.py |   21 ++++++-
 2 files changed, 51 insertions(+), 36 deletions(-)

diff -r a9a43705f26b -r 11b9ccdc9417 tools/python/xen/xend/XendAPI.py
--- a/tools/python/xen/xend/XendAPI.py  Wed Dec 27 00:38:01 2006 +0000
+++ b/tools/python/xen/xend/XendAPI.py  Wed Dec 27 11:49:59 2006 +0000
@@ -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 SR_get_physical_utilisation(self, session, sr_ref):
-        sr = XendNode.instance().get_sr()        
-        return sr.used_space_bytes()
-
-    def SR_get_physical_size(self, session, sr_ref):
-        sr = XendNode.instance().get_sr()        
-        return sr.total_space_bytes()
-    
-    def SR_get_type(self, session, sr_ref):
-        sr = XendNode.instance().get_sr()
-        return xen_api_success(sr.type)
-
-    def SR_get_location(self, session, sr_ref):
-        sr = XendNode.instance().get_sr()
-        return xen_api_success(sr.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_description(self, session, sr_ref):
-        sr = XendNode.instance().get_sr()
-        return xen_api_success(sr.name_description)        
+
+    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 _get_SR_attr(self, _, attr):
+        return xen_api_success(str(getattr(XendNode.instance().get_sr(),
+                                           attr)))
+
+    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, _, ref):
+        return self._get_SR_attr(ref, 'type')
+
+    def SR_get_location(self, _, ref):
+        return self._get_SR_attr(ref, 'location')
+
+    def SR_get_name_label(self, _, ref):
+        return self._get_SR_attr(ref, 'name_label')
+    
+    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()
diff -r a9a43705f26b -r 11b9ccdc9417 
tools/python/xen/xend/XendStorageRepository.py
--- a/tools/python/xen/xend/XendStorageRepository.py    Wed Dec 27 00:38:01 
2006 +0000
+++ b/tools/python/xen/xend/XendStorageRepository.py    Wed Dec 27 11:49:59 
2006 +0000
@@ -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()
 

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] Tidy and fix bindings for the SR class., Xen patchbot-unstable <=