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
19 def wrap_context(wrapped, context):
21 Supplies the wrapped object with the specified context
22 when executing callables.
24 def wrapper(*args, **kwds):
25 return wrapped(context, *args, **kwds)
30 A simple xmlrpc shell to a myplc instance
31 This class can receive all Openstack calls to the underlying testbed
34 # dont care about limiting calls yet
39 # use the 'capability' auth mechanism for higher performance when the PLC db is local
40 def __init__ ( self, config ) :
41 url = config.SFA_PLC_URL
42 # try to figure if the url is local
43 hostname=urlparse(url).hostname
44 if hostname == 'localhost': is_local=True
45 # otherwise compare IP addresses;
46 # this might fail for any number of reasons, so let's harden that
48 # xxx todo this seems to result in a DNS request for each incoming request to the AM
49 # should be cached or improved
50 url_ip=socket.gethostbyname(hostname)
51 local_ip=socket.gethostbyname(socket.gethostname())
52 if url_ip==local_ip: is_local=True
57 if is_local and has_nova:
58 logger.debug('nova access - native')
60 self.auth_manager = AuthManager()
61 self.compute_manager = ComputeManager()
62 self.network_manager = NetworkManager()
63 self.scheduler_manager = SchedulerManager()
64 flags.FLAGS(['foo', '--flagfile=/etc/nova/nova.conf', 'foo', 'foo'])
65 self.context = context.get_admin_context()
66 self.db = wrap_context(db, self.context)
70 logger.debug('nova access - REST')
71 raise SfaNotImplemented('nova access - Rest')
73 def __getattr__(self, name):
74 def func(*args, **kwds):
75 result=getattr(self.proxy, name)(self.auth, *args, **kwds)