3 from sfa.util.sfalogging import logger
7 A simple xmlrpc shell to a myplc instance
8 This class can receive all PLCAPI calls to the underlying testbed
9 For safety this is limited to a set of hard-coded calls
12 direct_calls = ['AddNode', 'AddPerson', 'AddPersonKey', 'AddPersonToSite',
13 'AddPersonToSlice', 'AddRoleToPerson', 'AddSite', 'AddSiteTag', 'AddSlice',
14 'AddSliceTag', 'AddSliceToNodes', 'BindObjectToPeer', 'DeleteKey',
15 'DeleteNode', 'DeletePerson', 'DeletePersonFromSlice', 'DeleteSite',
16 'DeleteSlice', 'DeleteSliceFromNodes', 'DeleteSliceTag', 'GetInitScripts',
17 'GetInterfaces', 'GetKeys', 'GetNodeTags', 'GetPeers',
18 'GetPersons', 'GetSlices', 'GetSliceTags', 'GetTagTypes',
19 'UnBindObjectFromPeer', 'UpdateNode', 'UpdatePerson', 'UpdateSite',
20 'UpdateSlice', 'UpdateSliceTag',
21 # also used as-is in importer
22 'GetSites','GetNodes',
24 # support for other names - this is experimental
25 alias_calls = { 'get_authorities':'GetSites',
26 'get_nodes':'GetNodes',
29 def __init__ ( self, config ) :
30 self.url = config.SFA_PLC_URL
31 # xxx attempt to use the 'capability' auth mechanism for higher performance
32 # when the PLC db is local
38 plc_direct_access=True
40 plc_direct_access=False
41 if is_local and plc_direct_access:
42 logger.info('plshell - capability access')
43 self.plauth = { 'AuthMethod': 'capability',
44 'UserName': config.SFA_PLC_USER,
45 'AuthString': config.SFA_PLC_PASSWORD,
47 self.proxy = PLC.Shell.Shell ()
50 logger.info('plshell - xmlrpc access')
51 self.plauth = { 'AuthMethod': 'password',
52 'Username': config.SFA_PLC_USER,
53 'AuthString': config.SFA_PLC_PASSWORD,
55 self.proxy = xmlrpclib.Server(self.url, verbose = 0, allow_none = True)
57 def __getattr__(self, name):
58 def func(*args, **kwds):
60 if name in PlShell.direct_calls: actual_name=name
61 if name in PlShell.alias_calls: actual_name=PlShell.alias_calls[name]
63 raise Exception, "Illegal method call %s for PL driver"%(name)
64 result=getattr(self.proxy, actual_name)(self.plauth, *args, **kwds)
65 logger.info('%s (%s) returned ... %s'%(name,actual_name,result))