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
14 from PLC.Sites import Site, Sites
15 from PLC.Keys import Key, Keys
16 from PLC.Nodes import Node, Nodes
17 from PLC.Persons import Person, Persons
18 from PLC.SliceAttributeTypes import SliceAttributeType, SliceAttributeTypes
19 from PLC.SliceAttributes import SliceAttribute, SliceAttributes
20 from PLC.Slices import Slice, Slices
22 class GetPeerData(Method):
24 Returns lists of local objects that a peer should cache in its
25 database as foreign objects. Also returns the list of foreign
26 nodes in this database, for which the calling peer is
27 authoritative, to assist in synchronization of slivers.
29 See the implementation of RefreshPeer for how this data is used.
32 roles = ['admin', 'peer']
37 'Sites': Parameter([dict], "List of local sites"),
38 'Keys': Parameter([dict], "List of local keys"),
39 'Nodes': Parameter([dict], "List of local nodes"),
40 'Persons': Parameter([dict], "List of local users"),
41 'Slices': Parameter([dict], "List of local slices"),
42 'db_time': Parameter(float, "(Debug) Database fetch time"),
45 def call (self, auth):
48 # Filter out various secrets
49 node_fields = filter(lambda field: field not in \
50 ['boot_nonce', 'key', 'session', 'root_person_ids'],
53 person_fields = filter(lambda field: field not in \
54 ['password', 'verification_key', 'verification_expires'],
57 # XXX Optimize to return only those Persons, Keys, and Slices
58 # necessary for slice creation on the calling peer's nodes.
60 'Sites': Sites(self.api, {'peer_id': None}),
61 'Keys': Keys(self.api, {'peer_id': None}),
62 'Nodes': Nodes(self.api, {'peer_id': None}, node_fields),
63 'Persons': Persons(self.api, {'peer_id': None}, person_fields),
64 'Slices': Slices(self.api, {'peer_id': None}),
67 if isinstance(self.caller, Peer):
68 result['PeerNodes'] = Nodes(self.api, {'peer_id': self.caller['peer_id']})
70 result['db_time'] = time.time() - start