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):
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 ()