from nova.compute.manager import ComputeManager
from nova.network.manager import NetworkManager
from nova.scheduler.manager import SchedulerManager
+ from nova.image.glance import GlanceImageService
has_nova = True
except:
has_nova = False
-def wrap_context(wrapped, context):
+class InjectContext:
"""
- 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 module and injects the context when executing methods
+ """
+ def __init__(self, proxy, context):
+ self.proxy = proxy
+ self.context = context
+
+ def __getattr__(self, name):
+ def func(*args, **kwds):
+ result=getattr(self.proxy, name)(self.context, *args, **kwds)
+ return result
+ return func
+
class NovaShell:
"""
A simple xmlrpc shell to a myplc instance
def __init__ ( self, config ) :
url = config.SFA_PLC_URL
# try to figure if the url is local
+ is_local=False
hostname=urlparse(url).hostname
if hostname == 'localhost': is_local=True
# otherwise compare IP addresses;
if is_local and has_nova:
logger.debug('nova access - native')
# load the config
+ flags.FLAGS(['foo', '--flagfile=/etc/nova/nova.conf', 'foo', 'foo'])
+ # instantiate managers
self.auth_manager = AuthManager()
self.compute_manager = ComputeManager()
self.network_manager = NetworkManager()
self.scheduler_manager = SchedulerManager()
- flags.FLAGS(['foo', '--flagfile=/etc/nova/nova.conf', 'foo', 'foo'])
- self.context = context.get_admin_context()
- self.db = wrap_context(db, self.context)
+ self.db = InjectContext(db, context.get_admin_context())
+ self.image_manager = InjectContext(GlanceImageService(), context.get_admin_context())
else:
self.auth = None
self.proxy = None
logger.debug('nova access - REST')
raise SfaNotImplemented('nova access - Rest')
-
- def __getattr__(self, name):
- def func(*args, **kwds):
- result=getattr(self.proxy, name)(self.auth, *args, **kwds)
- return result
- return func