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
21 Wraps the nova.db library and injects the context when executing methods
23 def __init__(self, db, context):
25 self.context = context
27 def __getattr__(self, name):
28 def func(*args, **kwds):
29 result=getattr(self.db, name)(self.context, *args, **kwds)
35 A simple xmlrpc shell to a myplc instance
36 This class can receive all Openstack calls to the underlying testbed
39 # dont care about limiting calls yet
44 # use the 'capability' auth mechanism for higher performance when the PLC db is local
45 def __init__ ( self, config ) :
46 url = config.SFA_PLC_URL
47 # try to figure if the url is local
48 hostname=urlparse(url).hostname
49 if hostname == 'localhost': is_local=True
50 # otherwise compare IP addresses;
51 # this might fail for any number of reasons, so let's harden that
53 # xxx todo this seems to result in a DNS request for each incoming request to the AM
54 # should be cached or improved
55 url_ip=socket.gethostbyname(hostname)
56 local_ip=socket.gethostbyname(socket.gethostname())
57 if url_ip==local_ip: is_local=True
62 if is_local and has_nova:
63 logger.debug('nova access - native')
65 flags.FLAGS(['foo', '--flagfile=/etc/nova/nova.conf', 'foo', 'foo'])
66 # instantiate managers
67 self.auth_manager = AuthManager()
68 self.compute_manager = ComputeManager()
69 self.network_manager = NetworkManager()
70 self.scheduler_manager = SchedulerManager()
71 self.db = NovaDB(db, context.get_admin_context())
75 logger.debug('nova access - REST')
76 raise SfaNotImplemented('nova access - Rest')