2 # Thierry Parmentelat - INRIA
5 from PLC.Faults import *
6 from PLC.Method import Method
7 from PLC.Parameter import Parameter, Mixed
8 from PLC.Auth import Auth
10 from PLC.Peers import Peer, Peers
11 from PLC.Persons import Person, Persons
13 from PLC.Cache import Cache
15 class RefreshPeer(Method):
17 First queries a remote PLC for its name and updates the local peers table
19 Then proceeds with fetching objects on the remote PLC, and updates the
20 local database accordingly
22 It requires the remote peer to be aware of our own name (as configured in PLC_NAME)
24 Returns a dict containing
25 (*) 'peername' : the peer's name
26 (*) 'new_xxx': the number of new objects from that peer - may be negative
27 (*) 'timers': various stats on performance for optimization
34 Mixed(Peer.fields['peer_id'],
35 Peer.fields['peername']),
39 'new_sites': Parameter([dict], "List of new sites"),
40 'new_keys': Parameter([dict], "List of new keys"),
41 'new_nodes': Parameter([dict], "List of new nodes"),
42 'new_persons': Parameter([dict], "List of new users"),
43 'new_slice_attribute_types': Parameter([dict], "List of new slice attribute types"),
44 'new_slices': Parameter([dict], "List of new slices"),
45 'new_slice_attributes': Parameter([dict], "List of new slice attributes"),
46 'timers': Parameter(dict, "(Debug) Timing information"),
49 def call (self, auth, peer_id_or_peername):
50 peers = Peers(self.api, [peer_id_or_peername])
52 raise PLCInvalidArgument, "No such peer '%s'" % unicode(peer_id_or_peername)
59 peername = peer.GetPeerName()
60 if peer['peername'] != peername:
61 peer['peername'] = peername
64 cache = Cache(self.api, peer['peer_id'], peer)
65 result = cache.refresh_peer()
67 # Add peer name to result set
68 result['peername'] = peername