From: Thierry Parmentelat Date: Sat, 26 Nov 2011 10:28:59 +0000 (+0100) Subject: trashed remoteshell and use plshell instead X-Git-Tag: sfa-2.0-1~6^2~17 X-Git-Url: http://git.onelab.eu/?p=sfa.git;a=commitdiff_plain;h=a772af7fc570de7a2c194f3b8ffe7d30350f950d trashed remoteshell and use plshell instead for now this always uses xmlrpc --- diff --git a/sfa/importer/sfa-import-plc.py b/sfa/importer/sfa-import-plc.py index 15a5bc6d..dad723b6 100755 --- a/sfa/importer/sfa-import-plc.py +++ b/sfa/importer/sfa-import-plc.py @@ -70,9 +70,9 @@ def main(): interface_hrn = config.SFA_INTERFACE_HRN keys_filename = config.config_path + os.sep + 'person_keys.py' sfaImporter = sfaImport() - if config.SFA_API_DEBUG: sfaImporter.logger.setLevelDebug() + logger=sfaImporter.logger + if config.SFA_API_DEBUG: logger.setLevelDebug() shell = sfaImporter.shell - plc_auth = sfaImporter.plc_auth # initialize registry db table table = SfaTable() @@ -86,11 +86,11 @@ def main(): sfaImporter.create_sm_client_record() # create interface records - sfaImporter.logger.info("Import: creating interface records") + logger.info("Import: creating interface records") sfaImporter.create_interface_records() # add local root authority's cert to trusted list - sfaImporter.logger.info("Import: adding " + interface_hrn + " to trusted list") + logger.info("Import: adding " + interface_hrn + " to trusted list") authority = sfaImporter.AuthHierarchy.get_auth_info(interface_hrn) sfaImporter.TrustedRoots.add_gid(authority.get_gid_object()) @@ -112,13 +112,13 @@ def main(): existing_hrns.append(result['hrn']) # Get all plc sites - sites = shell.GetSites(plc_auth, {'peer_id': None}) + sites = shell.GetSites({'peer_id': None}) sites_dict = {} for site in sites: sites_dict[site['login_base']] = site # Get all plc users - persons = shell.GetPersons(plc_auth, {'peer_id': None, 'enabled': True}, + persons = shell.GetPersons({'peer_id': None, 'enabled': True}, ['person_id', 'email', 'key_ids', 'site_ids']) persons_dict = {} for person in persons: @@ -126,7 +126,7 @@ def main(): key_ids.extend(person['key_ids']) # Get all public keys - keys = shell.GetKeys(plc_auth, {'peer_id': None, 'key_id': key_ids}) + keys = shell.GetKeys( {'peer_id': None, 'key_id': key_ids}) keys_dict = {} for key in keys: keys_dict[key['key_id']] = key['key'] @@ -140,20 +140,20 @@ def main(): person_keys[person['person_id']] = pubkeys # Get all plc nodes - nodes = shell.GetNodes(plc_auth, {'peer_id': None}, ['node_id', 'hostname', 'site_id']) + nodes = shell.GetNodes( {'peer_id': None}, ['node_id', 'hostname', 'site_id']) nodes_dict = {} for node in nodes: nodes_dict[node['node_id']] = node # Get all plc slices - slices = shell.GetSlices(plc_auth, {'peer_id': None}, ['slice_id', 'name']) + slices = shell.GetSlices( {'peer_id': None}, ['slice_id', 'name']) slices_dict = {} for slice in slices: slices_dict[slice['slice_id']] = slice # start importing for site in sites: site_hrn = _get_site_hrn(interface_hrn, site) - sfaImporter.logger.info("Importing site: %s" % site_hrn) + logger.info("Importing site: %s" % site_hrn) # import if hrn is not in list of existing hrns or if the hrn exists # but its not a site record @@ -272,7 +272,7 @@ def main(): sfaImporter.delete_record(record_hrn, type) # save pub keys - sfaImporter.logger.info('Import: saving current pub keys') + logger.info('Import: saving current pub keys') save_keys(keys_filename, person_keys) if __name__ == "__main__": diff --git a/sfa/importer/sfaImport.py b/sfa/importer/sfaImport.py index 568fce84..082d3ed3 100644 --- a/sfa/importer/sfaImport.py +++ b/sfa/importer/sfaImport.py @@ -52,17 +52,12 @@ class sfaImport: self.AuthHierarchy = Hierarchy() self.config = Config() self.TrustedRoots = TrustedRoots(Config.get_trustedroots_dir(self.config)) - self.plc_auth = self.config.get_plc_auth() self.root_auth = self.config.SFA_REGISTRY_ROOT_AUTH - # connect to planetlab - self.shell = None - if "Url" in self.plc_auth: - from sfa.plc.remoteshell import RemoteShell - self.shell = RemoteShell(self.logger) - else: - import PLC.Shell - self.shell = PLC.Shell.Shell(globals = globals()) + # should use a driver instead... + from sfa.plc.plshell import PlShell + # how to connect to planetlab + self.shell = PlShell (self.config) def create_top_level_auth_records(self, hrn): """ @@ -145,7 +140,7 @@ class sfaImport: key_ids = person["key_ids"] # get the user's private key from the SSH keys they have uploaded # to planetlab - keys = self.shell.GetKeys(self.plc_auth, key_ids) + keys = self.shell.GetKeys(key_ids) key = keys[0]['key'] pkey = None try: diff --git a/sfa/plc/plshell.py b/sfa/plc/plshell.py index 972a97ea..ef2abb0b 100644 --- a/sfa/plc/plshell.py +++ b/sfa/plc/plshell.py @@ -1,5 +1,7 @@ import xmlrpclib +from sfa.util.sfalogging import logger + class PlShell: """ A simple xmlrpc shell to a myplc instance @@ -25,15 +27,32 @@ class PlShell: } def __init__ ( self, config ) : - self.plauth = {'Username': config.SFA_PLC_USER, - 'AuthMethod': 'password', - 'AuthString': config.SFA_PLC_PASSWORD} - self.url = config.SFA_PLC_URL - #self.plauth = {'Username': 'root@test.onelab.eu', - # 'AuthMethod': 'password', - # 'AuthString': 'test++'} - self.proxy_server = xmlrpclib.Server(self.url, verbose = 0, allow_none = True) + # xxx attempt to use the 'capability' auth mechanism for higher performance + # when the PLC db is local + # xxx todo + is_local = False + if is_local: + try: + import PLC.Shell + plc_direct_access=True + except: + plc_direct_access=False + if is_local and plc_direct_access: + logger.info('plshell - capability access') + self.plauth = { 'AuthMethod': 'capability', + 'UserName': config.SFA_PLC_USER, + 'AuthString': config.SFA_PLC_PASSWORD, + } + self.proxy = PLC.Shell.Shell () + + else: + logger.info('plshell - xmlrpc access') + self.plauth = { 'AuthMethod': 'password', + 'Username': config.SFA_PLC_USER, + 'AuthString': config.SFA_PLC_PASSWORD, + } + self.proxy = xmlrpclib.Server(self.url, verbose = 0, allow_none = True) def __getattr__(self, name): def func(*args, **kwds): @@ -42,5 +61,7 @@ class PlShell: if name in PlShell.alias_calls: actual_name=PlShell.alias_calls[name] if not actual_name: raise Exception, "Illegal method call %s for PL driver"%(name) - return getattr(self.proxy_server, actual_name)(self.plauth, *args, **kwds) + result=getattr(self.proxy, actual_name)(self.plauth, *args, **kwds) + logger.info('%s (%s) returned ... %s'%(name,actual_name,result)) + return result return func diff --git a/sfa/plc/remoteshell.py b/sfa/plc/remoteshell.py deleted file mode 100644 index 9deceb65..00000000 --- a/sfa/plc/remoteshell.py +++ /dev/null @@ -1,106 +0,0 @@ -# remoteshell.py -# -# interface to the PLC api via xmlrpc -# -# RemoteShell() exports an API that looks identical to that exported by -# PLC.Shell.Shell(). It's meant to be a drop in replacement for running -# SFA on a different machine than PLC. - -import xmlrpclib - -class RemoteShell: - def __init__(self,logger): - self.servers = {} - self.logger=logger - - def call(self, name, pl_auth, *args): - - key = pl_auth["Url"] + "#" + pl_auth["Username"] - - if not (key in self.servers): - self.logger.info("Connecting to PLCAPI at url %s"%pl_auth['Url']) - server = xmlrpclib.Server(pl_auth["Url"], verbose = 0, allow_none=True) - #server.AdmAuthCheck(pl_auth) - server.AuthCheck(pl_auth) - self.servers[key] = server - - server = self.servers[key] - - arglist = ["pl_auth"] - for arg in args: - arglist.append(repr(arg)) - - str = "server." + name + "(" + ",".join(arglist) + ")" - result = eval(str) - - return result - - # TODO: there's probably an automatic way to import all these stubs - - def AddInitScript(self, pl_auth, *args): - return self.call("AddInitScript", pl_auth, *args) - - def AddNode(self, pl_auth, *args): - return self.call("AddNode", pl_auth, *args) - - def AddPerson(self, pl_auth, *args): - return self.call("AddPerson", pl_auth, *args) - - def AddPersonToSlice(self, pl_auth, *args): - return self.call("AddPersonToSlice", pl_auth, *args) - - def AddSite(self, pl_auth, *args): - return self.call("AddSite", pl_auth, *args) - - def AddSlice(self, pl_auth, *args): - return self.call("AddSlice", pl_auth, *args) - - def DeleteNode(self, pl_auth, *args): - return self.call("DeleteNode", pl_auth, *args) - - def DeletePerson(self, pl_auth, *args): - return self.call("DeletePerson", pl_auth, *args) - - def DeletePersonFromSlice(self, pl_auth, *args): - return self.call("DeletePersonFromSlice", pl_auth, *args) - - def DeleteSite(self, pl_auth, *args): - return self.call("DeleteSite", pl_auth, *args) - - def DeleteSlice(self, pl_auth, *args): - return self.call("DeleteSlice", pl_auth, *args) - - def GetInitScripts(self, pl_auth, *args): - return self.call("GetInitScripts", pl_auth, *args) - - def GetKeys(self, pl_auth, *args): - return self.call("GetKeys", pl_auth, *args) - - def GetNodes(self, pl_auth, *args): - return self.call("GetNodes", pl_auth, *args) - - def GetPersons(self, pl_auth, *args): - return self.call("GetPersons", pl_auth, *args) - - def GetSites(self, pl_auth, *args): - return self.call("GetSites", pl_auth, *args) - - def GetSliceAttributes(self, pl_auth, *args): - return self.call("GetSliceAttributes", pl_auth, *args) - - def GetSlices(self, pl_auth, *args): - return self.call("GetSlices", pl_auth, *args) - - def UpdateNode(self, pl_auth, *args): - return self.call("UpdateNode", pl_auth, *args) - - def UpdatePerson(self, pl_auth, *args): - return self.call("UpdatePerson", pl_auth, *args) - - def UpdateSite(self, pl_auth, *args): - return self.call("UpdateSite", pl_auth, *args) - - def UpdateSlice(self, pl_auth, *args): - return self.call("UpdateSlice", pl_auth, *args) - - diff --git a/sfa/util/config.py b/sfa/util/config.py index 2ad7f7b5..56b30215 100644 --- a/sfa/util/config.py +++ b/sfa/util/config.py @@ -125,20 +125,3 @@ class Config: return (am_apiclient_path,am_url) - ## - # SFA uses a PLCAPI connection to perform operations on the registry, - # such as creating and deleting slices. This connection requires an account - # on the PLC server with full administrator access. - # - # The Url parameter controls whether the connection uses PLCAPI directly (i.e. - # SFA is located on the same machine as PLC), or uses a XMLRPC connection - # to the PLC machine. If you wish to use the API directly, then remove the Url - # field from the dictionary. - - def get_plc_auth(self): - return { - 'AuthMethod': 'capability', - 'Username': self.SFA_PLC_USER, - 'AuthString': self.SFA_PLC_PASSWORD, - "Url": self.SFA_PLC_URL - }