deeper pass on xmlrpclib vs xmlrpc.client as well as configparser
[sfa.git] / sfa / federica / fdshell.py
1 from sfa.util.sfalogging import logger
2 from sfa.util.py23 import xmlrpc_client
3
4 class FdShell:
5     """
6     A simple xmlrpc shell to a federica API server
7     This class can receive the XMLRPC calls to the federica testbed
8     For safety this is limited to a set of hard-coded calls
9     """
10     
11     direct_calls = [ 'listAvailableResources',
12                      'listSliceResources',
13                      'createSlice',
14                      'deleteSlice',
15                      'getRSpecVersion',
16                      'listSlices',
17                     ]
18
19     def __init__ ( self, config ) :
20         url=config.SFA_FEDERICA_URL
21         # xxx not sure if java xmlrpc has support for None
22         # self.proxy = xmlrpc_client.ServerProxy(url, verbose = False, allow_none = True)
23         # xxx turn on verbosity
24         self.proxy = xmlrpc_client.ServerProxy(url, verbose = True)
25
26     # xxx get credentials from the config ?
27     # right now basic auth data goes into the URL
28     # so do *not* add any credential at that point
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             logger.info("Issuing %s args=%s kwds=%s to federica"%\
34                             (name,args,kwds))
35 #            result=getattr(self.proxy, "AggregateManager.%s"%name)(credential, *args, **kwds)
36             result=getattr(self.proxy, "AggregateManager.%s"%name)(*args, **kwds)
37             logger.debug('FdShell %s (%s) returned ... '%(name,name))
38             return result
39         return func
40