From fba711afe4fa0aeda50ef9cc5279090f08bdd1bf Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Fri, 3 Feb 2012 14:53:17 -0500 Subject: [PATCH] replace wrap_context with NovaDB class --- sfa/openstack/nova_shell.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) 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 -- 2.47.0