From: Thierry Parmentelat Date: Thu, 7 Jul 2011 10:29:00 +0000 (+0200) Subject: much faster reset_xmpp_pubsub_nodes - one single API call X-Git-Tag: plcapi-5.0-34~5 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=0c7387b368077a7a4792a4be7bb4f8837230b0cb;p=plcapi.git much faster reset_xmpp_pubsub_nodes - one single API call to retrieve nodes --- diff --git a/omf/reset_xmpp_pubsub_nodes.py b/omf/reset_xmpp_pubsub_nodes.py old mode 100644 new mode 100755 index 81f50a4..d0bdfa1 --- a/omf/reset_xmpp_pubsub_nodes.py +++ b/omf/reset_xmpp_pubsub_nodes.py @@ -5,11 +5,11 @@ import xmlrpclib sys.path.append("/usr/bin/") from omf_slicemgr import * -xmlrpc = xmlrpclib.ServerProxy("http://localhost:5053") - xmppserver = config.PLC_OMF_XMPP_SERVER xmppuser = "@".join([config.PLC_OMF_XMPP_USER, xmppserver]) xmpppass = config.PLC_OMF_XMPP_PASSWORD +xmlrpc = xmlrpclib.ServerProxy(config.PLC_OMF_SLICEMGR_URL) + pubsub = PubSubClient(xmppuser, xmpppass, verbose=False) @@ -40,12 +40,24 @@ if __name__ == "__main__": print "Re-creating PubSub groups..." slices = GetSlices() + # optimizing the API calls + nodes = GetNodes ({},['node_id','hrn','peer_id']) + local_node_hash = dict ( [ (n['node_id'],n['hrn']) for n in nodes if n['peer_id'] is None ] ) + foreign_node_hash = dict ( [ (n['node_id'],n['hrn']) for n in nodes if n['peer_id'] is not None ] ) + total=len(slices) + counter=1 for slice in slices: + print 40*'x' + " slice %s (%d/%d)"%(slice['name'],counter,total) + counter +=1 xmlrpc.createSlice(slice['name']) for node_id in slice['node_ids']: - try: - hrn = GetNodeTags({'tagname':'hrn', 'node_id': node_id})[0]['value'] - xmlrpc.addResource(slice['name'], hrn) - except IndexError: - if is_local_node(node_id, slice['name']): + # silently ignore foreign nodes + if node_id in foreign_node_hash: continue + elif node_id in local_node_hash: + hrn=local_node_hash[node_id] + if hrn: + xmlrpc.addResource(slice['name'],hrn) + else: print "WARNING: missing hrn tag for node_id: %s" % node_id + else: + print "Cannot find node with node_id %d (in slice %s)"%(node_id,slice['name'])