4 from urlparse import urlparse
5 from sfa.util.sfalogging import logger
9 from nova import context
10 from nova.auth.manager import AuthManager
11 from nova.compute.manager import ComputeManager
12 from nova.network.manager import NetworkManager
13 from nova.scheduler.manager import SchedulerManager
14 from nova.image.glance import GlanceImageService
22 Wraps the module and injects the context when executing methods
24 def __init__(self, proxy, context):
26 self.context = context
28 def __getattr__(self, name):
29 def func(*args, **kwds):
30 result=getattr(self.proxy, name)(self.context, *args, **kwds)
36 A simple native shell to a nova backend.
37 This class can receive all nova calls to the underlying testbed
40 # dont care about limiting calls yet
45 # use the 'capability' auth mechanism for higher performance when the PLC db is local
46 def __init__ ( self, config ) :
47 url = config.SFA_PLC_URL
48 # try to figure if the url is local
50 hostname=urlparse(url).hostname
51 if hostname == 'localhost': is_local=True
52 # otherwise compare IP addresses;
53 # this might fail for any number of reasons, so let's harden that
55 # xxx todo this seems to result in a DNS request for each incoming request to the AM
56 # should be cached or improved
57 url_ip=socket.gethostbyname(hostname)
58 local_ip=socket.gethostbyname(socket.gethostname())
59 if url_ip==local_ip: is_local=True
64 if is_local and has_nova:
65 logger.debug('nova access - native')
67 flags.FLAGS(['foo', '--flagfile=/etc/nova/nova.conf', 'foo', 'foo'])
68 # instantiate managers
69 self.auth_manager = AuthManager()
70 self.compute_manager = ComputeManager()
71 self.network_manager = NetworkManager()
72 self.scheduler_manager = SchedulerManager()
73 self.db = InjectContext(db, context.get_admin_context())
74 self.image_manager = InjectContext(GlanceImageService(), context.get_admin_context())
78 logger.debug('nova access - REST')
79 raise SfaNotImplemented('nova access - Rest')