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 First queries a remote PLC for its name and updates the local peers table
21 Then proceeds with fetching objects on the remote PLC, and updates the
22 local database accordingly
24 It requires the remote peer to be aware of our own name (as configured in PLC_NAME)
26 Returns a dict containing
27 (*) 'peername' : the peer's name
28 (*) 'new_xxx': the number of new objects from that peer - may be negative
29 (*) 'timers': various stats on performance for optimization
36 Mixed(Peer.fields['peer_id'],
37 Peer.fields['peername']),
40 returns = Parameter(dict,
45 'new_slice_attribute_types '
47 'new_slice_attributes '
50 def call (self, auth, peer_id_or_peername):
52 ### retrieve peer info
53 peers = Peers (self.api,[peer_id_or_peername])
57 raise PLCInvalidArgument,'RefreshPeer: no such peer:%r'%peer_id_or_peername
59 ### retrieve account info
60 auth_person_id = peer['auth_person_id']
61 persons = Persons (self.api,[auth_person_id])
65 raise PLCInvalidArgument,'RefreshPeer: no such person_id:%d'%auth_person_id
67 ## connect to the peer's API
69 apiserver = xmlrpclib.ServerProxy (url,allow_none=True)
71 ### build up foreign auth
72 auth={ 'Username': person['email'],
73 'AuthMethod' : 'password',
74 'AuthString' : person['password'],
79 # right now we *need* the remote peer to know our name
80 # (this is used in the GetPeerData that we issue)
81 # in general this will be true
82 # however if anyone decides to change its own plc name things can get wrong
83 # doing this should ensure things become right again after some iterations
85 # might wish to change this policy once we have peer authentication, maybe
87 # make sure we have the right name for that peer
88 peername = apiserver.GetPeerName (auth)
89 peer.update_name(peername)
91 # we need a peer_id from there on
92 peer_id = peer['peer_id']
94 print 'Got peer_id',peer_id
96 cache = Cache (self.api, peer_id, apiserver, auth)
97 result = cache.refresh_peer ()
98 result['peername']=peername