From: Tony Mack <tmack@paris.CS.Princeton.EDU>
Date: Fri, 3 Feb 2012 19:53:17 +0000 (-0500)
Subject: replace wrap_context with NovaDB class
X-Git-Tag: merged-in-sfa-2.1-2~30
X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=fba711afe4fa0aeda50ef9cc5279090f08bdd1bf;p=sfa.git

replace wrap_context with NovaDB class
---

diff --git a/sfa/openstack/nova_shell.py b/sfa/openstack/nova_shell.py
index 3c8ae883..333a5207 100644
--- a/sfa/openstack/nova_shell.py
+++ b/sfa/openstack/nova_shell.py
@@ -16,14 +16,19 @@ except:
     has_nova = False
 
 
-def wrap_context(wrapped, context): 
+class NovaDB:
     """
-    Supplies the wrapped object with the specified context 
-    when executing callables. 
-    """ 
-    def wrapper(*args, **kwds):
-        return wrapped(context, *args, **kwds)
-    return wrap_context   
+    Wraps the nova.db library and injects the context when executing methods 
+    """     
+    def __init__(self, db, context):
+        self.db = db
+        self.context = context
+    
+    def __getattr__(self, name):
+        def func(*args, **kwds):
+            result=getattr(self.db, name)(self.context, *args, **kwds)
+            return result
+        return func
  
 class NovaShell:
     """
@@ -63,8 +68,7 @@ class NovaShell:
             self.compute_manager = ComputeManager()
             self.network_manager = NetworkManager()
             self.scheduler_manager = SchedulerManager()
-            self.context = context.get_admin_context()
-            self.db = wrap_context(db, self.context)
+            self.db = NovaDB(db, context.get_admin_context())
         else:
             self.auth = None
             self.proxy = None