X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FRefreshPeer.py;h=21ebf0a23a7017fb8f5c05bdb5e5a9089d5a32a1;hb=d316abf4bdb070ea1acf6be4b262c86a055b6ac2;hp=4a5abd043b0527381e365573a0e919d471b76413;hpb=a1911156c062834ada3dd945c97e45563a980f56;p=plcapi.git diff --git a/PLC/Methods/RefreshPeer.py b/PLC/Methods/RefreshPeer.py index 4a5abd0..21ebf0a 100644 --- a/PLC/Methods/RefreshPeer.py +++ b/PLC/Methods/RefreshPeer.py @@ -11,26 +11,30 @@ from PLC.Auth import Auth from PLC.Peers import Peer, Peers from PLC.Persons import Person, Persons -##from PLC.ForeignNodes import ForeignNode, ForeignNodes +from PLC.Cache import Cache class RefreshPeer(Method): """ Query a peer PLC for its list of nodes, and refreshes the local database accordingly - Returns a tuple containing - (*) the peer name - (*) the number of new nodes from that peer - may be negative - (*) the number of new slices from that peer - may be negative + Returns a dict containing + (*) 'plcname' : the peer name + (*) 'new_sites': the number of new sites from that peer - may be negative + (*) 'new_keys': + (*) 'new_nodes': + (*) 'new_persons': + (*) 'new_slices': """ roles = ['admin'] accepts = [ Auth(), - Parameter (int, "Peer id") ] + Parameter (int, "Peer id"), + ] - returns = Parameter(int, "Delta in number of foreign nodes attached to that peer") + returns = Parameter(dict, "plcname, new_sites, new_keys, new_nodes, new_persons, new_slices") def call (self, auth, peer_id): @@ -49,22 +53,15 @@ class RefreshPeer(Method): except: raise PLCInvalidArgument,'no such person_id:%d'%person_id + ## connect to the peer's API + url=peer['peer_url'] + apiserver = xmlrpclib.ServerProxy (url,allow_none=True) + ### build up foreign auth auth={ 'Username': person['email'], 'AuthMethod' : 'password', 'AuthString' : person['password'], 'Role' : 'admin' } - ## connect to the peer's API - url=peer['peer_url'] - print 'url=',url - apiserver = xmlrpclib.Server (url) - print 'auth=',auth - - peer_get_nodes = apiserver.GetNodes(auth) - nb_new_nodes = peer.refresh_nodes(peer_get_nodes) - - peer_get_slices = apiserver.GetSlices(auth) - nb_new_slices = peer.refresh_slices(peer_get_slices) - - return (self.api.config.PLC_NAME,nb_new_nodes,nb_new_slices) + cache = Cache (self.api, peer_id, apiserver, auth) + return cache.refresh_peer ()