2 # Thierry Parmentelat - INRIA
7 from PLC.Faults import *
8 from PLC.Method import Method
9 from PLC.Parameter import Parameter, Mixed
10 from PLC.Auth import Auth
12 from PLC.Peers import Peer, Peers
13 from PLC.Persons import Person, Persons
16 class RefreshPeer(Method):
18 Query a peer PLC for its list of nodes, and refreshes
19 the local database accordingly
21 Returns a dict containing
22 (*) 'plcname' : the peer name
23 (*) 'new_nodes' : the number of new nodes from that peer - may be negative
24 (*) 'new_slices': the number of new slices from that peer - may be negative
30 Parameter (int, "Peer id") ]
32 returns = Parameter(dict, "plcname, new_nodes, new_slices")
34 def call (self, auth, peer_id):
36 ### retrieve peer info
37 peers = Peers (self.api,[peer_id])
41 raise PLCInvalidArgument,'no such peer_id:%d'%peer_id
43 ### retrieve account info
44 person_id = peer['person_id']
45 persons = Persons (self.api,[person_id])
49 raise PLCInvalidArgument,'no such person_id:%d'%person_id
51 ### build up foreign auth
52 auth={ 'Username': person['email'],
53 'AuthMethod' : 'password',
54 'AuthString' : person['password'],
57 ## connect to the peer's API
59 apiserver = xmlrpclib.ServerProxy (url,allow_none=True)
61 peer_local_nodes = apiserver.GetNodes(auth,None,None,'local')
62 nb_new_nodes = peer.refresh_nodes(peer_local_nodes)
65 peer_foreign_nodes = apiserver.GetNodes(auth,None,None,'foreign')
66 peer_local_slices = apiserver.GetSlices(auth,{'peer_id':None})
67 nb_new_slices = peer.refresh_slices(peer_local_slices,peer_foreign_nodes)
69 return {'plcname':self.api.config.PLC_NAME,
70 'new_nodes':nb_new_nodes,
71 'new_slices':nb_new_slices}