X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fopenstack%2Fnova_shell.py;h=b9ae13c76982261973e45fda0c2dbd9c67c085ee;hb=a65ff4e27632a4ccb873c6f50c6c466a11ee7bcb;hp=333a5207337b4ee5416aa33b756796180600d95e;hpb=fba711afe4fa0aeda50ef9cc5279090f08bdd1bf;p=sfa.git diff --git a/sfa/openstack/nova_shell.py b/sfa/openstack/nova_shell.py index 333a5207..b9ae13c7 100644 --- a/sfa/openstack/nova_shell.py +++ b/sfa/openstack/nova_shell.py @@ -11,29 +11,30 @@ try: 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 -class NovaDB: +class InjectContext: """ - Wraps the nova.db library and injects the context when executing methods + Wraps the module and injects the context when executing methods """ - def __init__(self, db, context): - self.db = db + def __init__(self, proxy, context): + self.proxy = proxy self.context = context def __getattr__(self, name): def func(*args, **kwds): - result=getattr(self.db, name)(self.context, *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 - This class can receive all Openstack calls to the underlying testbed + A simple native shell to a nova backend. + This class can receive all nova calls to the underlying testbed """ # dont care about limiting calls yet @@ -43,23 +44,14 @@ class NovaShell: # use the 'capability' auth mechanism for higher performance when the PLC db is local def __init__ ( self, config ) : - url = config.SFA_PLC_URL - # try to figure if the url is local - hostname=urlparse(url).hostname - if hostname == 'localhost': is_local=True - # otherwise compare IP addresses; - # this might fail for any number of reasons, so let's harden that - try: - # xxx todo this seems to result in a DNS request for each incoming request to the AM - # should be cached or improved - url_ip=socket.gethostbyname(hostname) - local_ip=socket.gethostbyname(socket.gethostname()) - if url_ip==local_ip: is_local=True - except: - pass - + self.auth_manager = None + self.compute_manager = None + self.network_manager = None + self.scheduler_manager = None + self.db = None + self.image_manager = None - if is_local and has_nova: + if has_nova: logger.debug('nova access - native') # load the config flags.FLAGS(['foo', '--flagfile=/etc/nova/nova.conf', 'foo', 'foo']) @@ -68,15 +60,8 @@ class NovaShell: self.compute_manager = ComputeManager() self.network_manager = NetworkManager() self.scheduler_manager = SchedulerManager() - self.db = NovaDB(db, context.get_admin_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