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
15 from PLC.Cache import Cache
17 class RefreshPeer(Method):
19 Query a peer PLC for its list of nodes, and refreshes
20 the local database accordingly
22 Returns a dict containing
23 (*) 'plcname' : the peer name
24 (*) 'new_nodes' : the number of new nodes from that peer - may be negative
25 (*) 'new_slices': the number of new slices from that peer - may be negative
31 Parameter (int, "Peer id") ]
33 returns = Parameter(dict, "plcname, new_nodes, new_slices")
35 def call (self, auth, peer_id):
37 ### retrieve peer info
38 peers = Peers (self.api,[peer_id])
42 raise PLCInvalidArgument,'no such peer_id:%d'%peer_id
44 ### retrieve account info
45 person_id = peer['person_id']
46 persons = Persons (self.api,[person_id])
50 raise PLCInvalidArgument,'no such person_id:%d'%person_id
52 ## connect to the peer's API
54 apiserver = xmlrpclib.ServerProxy (url,allow_none=True)
56 ### build up foreign auth
57 auth={ 'Username': person['email'],
58 'AuthMethod' : 'password',
59 'AuthString' : person['password'],
62 cache = Cache (self.api, peer, apiserver, auth)
63 return cache.refresh_peer ()