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_sites': the number of new sites from that peer - may be negative
34 Parameter (int, "Peer id"),
37 returns = Parameter(dict, "plcname, new_sites, new_keys, new_nodes, new_persons, new_slices")
39 def call (self, auth, peer_id):
41 ### retrieve peer info
42 peers = Peers (self.api,[peer_id])
46 raise PLCInvalidArgument,'no such peer_id:%d'%peer_id
48 ### retrieve account info
49 person_id = peer['person_id']
50 persons = Persons (self.api,[person_id])
54 raise PLCInvalidArgument,'no such person_id:%d'%person_id
56 ## connect to the peer's API
58 apiserver = xmlrpclib.ServerProxy (url,allow_none=True)
60 ### build up foreign auth
61 auth={ 'Username': person['email'],
62 'AuthMethod' : 'password',
63 'AuthString' : person['password'],
66 cache = Cache (self.api, peer_id, apiserver, auth)
67 return cache.refresh_peer ()