4 from urlparse import urlparse
6 from sfa.util.sfalogging import logger
10 A simple xmlrpc shell to a myplc instance
11 This class can receive all Openstack calls to the underlying testbed
14 # dont care about limiting calls yet
19 # use the 'capability' auth mechanism for higher performance when the PLC db is local
20 def __init__ ( self, config ) :
21 url = config.SFA_PLC_URL
22 # try to figure if the url is local
23 hostname=urlparse(url).hostname
25 if hostname == 'localhost': is_local=True
26 # otherwise compare IP addresses;
27 # this might fail for any number of reasons, so let's harden that
29 # xxx todo this seems to result in a DNS request for each incoming request to the AM
30 # should be cached or improved
31 url_ip=socket.gethostbyname(hostname)
32 local_ip=socket.gethostbyname(socket.gethostname())
33 if url_ip==local_ip: is_local=True
38 # Openstack provides a RESTful api but it is very limited, so we will
39 # ignore it for now and always use the native openstack (nova) library.
40 # This of course will not work if sfa is not installed on the same machine
41 # as the openstack-compute package.
44 from nova.auth.manager import AuthManager, db, context
48 if is_local and direct_access:
50 logger.debug('openstack access - native')
51 self.auth = context.get_admin_context()
52 # AuthManager isnt' really useful for much yet but it's
53 # more convenient to use than the db reference which requires
54 # a context. Lets hold onto the AuthManager reference for now.
55 #self.proxy = AuthManager()
56 self.auth_manager = AuthManager()
62 logger.debug('openstack access - REST')
63 raise SfaNotImplemented('openstack access - Rest')
65 def __getattr__(self, name):
66 def func(*args, **kwds):
67 result=getattr(self.proxy, name)(self.auth, *args, **kwds)