first draft for the federica driver
[sfa.git] / sfa / federica / fdshell.py
1 import xmlrpclib
2
3 from sfa.util.sfalogging import logger
4
5 class FdShell:
6     """
7     A simple xmlrpc shell to a federica API server
8     This class can receive the XMLRPC calls to the federica testbed
9     For safety this is limited to a set of hard-coded calls
10     """
11     
12     direct_calls = [ 'listAvailableResources',
13                      'listSliceResources',
14                      'createSlice',
15                      'deleteSlice',
16                     ]
17
18     def __init__ ( self, config ) :
19         # xxx to be configurable
20         SFA_FEDERICA_URL = "http://%s:%s@%s:%s/"%\
21             (config.SFA_FEDERICA_USER,config.SFA_FEDERICA_PASSWORD,
22              config.SFA_FEDERICA_HOSTNAME,config.SFA_FEDERICA_PORT)
23         url=SFA_FEDERICA_URL
24         # xxx not sure if java xmlrpc has support for None
25         # self.proxy = xmlrpclib.Server(url, verbose = False, allow_none = True)
26         # xxx turn on verbosity
27         self.proxy = xmlrpclib.Server(url, verbose = True)
28
29     def __getattr__(self, name):
30         def func(*args, **kwds):
31             if name not in FdShell.direct_calls:
32                 raise Exception, "Illegal method call %s for FEDERICA driver"%(name)
33             # xxx get credentials from the config ?
34             # right now basic auth data goes into the URL
35             # the API still provides for a first credential arg though
36             credential='xxx-unused-xxx'
37             logger.info("Issuing %s args=%s kwds=%s to federica"%\
38                             (name,args,kwds))
39             result=getattr(self.proxy, "AggregateManager.%s"%name)(credential, *args, **kwds)
40             logger.debug('FdShell %s (%s) returned ... '%(name,name))
41             return result
42         return func
43