7195b5650e562eb005d15fcef7dc105294d833bf
[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                      'getRSpecVersion',
17                      'listSlices',
18                     ]
19
20     def __init__ ( self, config ) :
21         # xxx to be configurable
22         SFA_FEDERICA_URL = "http://%s:%s@%s:%s/"%\
23             (config.SFA_FEDERICA_USER,config.SFA_FEDERICA_PASSWORD,
24              config.SFA_FEDERICA_HOSTNAME,config.SFA_FEDERICA_PORT)
25         url=SFA_FEDERICA_URL
26         # xxx not sure if java xmlrpc has support for None
27         # self.proxy = xmlrpclib.Server(url, verbose = False, allow_none = True)
28         # xxx turn on verbosity
29         self.proxy = xmlrpclib.Server(url, verbose = True)
30
31     def __getattr__(self, name):
32         def func(*args, **kwds):
33             if name not in FdShell.direct_calls:
34                 raise Exception, "Illegal method call %s for FEDERICA driver"%(name)
35             # xxx get credentials from the config ?
36             # right now basic auth data goes into the URL
37             # the API still provides for a first credential arg though
38             credential='xxx-unused-xxx'
39             logger.info("Issuing %s args=%s kwds=%s to federica"%\
40                             (name,args,kwds))
41             result=getattr(self.proxy, "AggregateManager.%s"%name)(credential, *args, **kwds)
42             logger.debug('FdShell %s (%s) returned ... '%(name,name))
43             return result
44         return func
45