X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FGetPeerData.py;h=7258384251e88f7287f672b3afd8bc9b328fd3fa;hb=9538a99a4190a75414c5d3ad37b8ed928bb03e21;hp=4b0f06881da1f8d3fdbde141c7b0e0bdb5796f22;hpb=8e199f468aaf48ac1dad3090c149711f38aa6c38;p=plcapi.git diff --git a/PLC/Methods/GetPeerData.py b/PLC/Methods/GetPeerData.py index 4b0f068..7258384 100644 --- a/PLC/Methods/GetPeerData.py +++ b/PLC/Methods/GetPeerData.py @@ -2,6 +2,8 @@ # Thierry Parmentelat - INRIA # +import time + from PLC.Faults import * from PLC.Method import Method from PLC.Parameter import Parameter, Mixed @@ -13,41 +15,56 @@ from PLC.Sites import Site, Sites from PLC.Keys import Key, Keys from PLC.Nodes import Node, Nodes from PLC.Persons import Person, Persons -from PLC.SliceAttributeTypes import SliceAttributeType, SliceAttributeTypes from PLC.Slices import Slice, Slices -from PLC.SliceAttributes import SliceAttribute, SliceAttributes -class GetPeerData (Method): +class GetPeerData(Method): """ - Gather all data needed by RefreshPeer in a single xmlrpc request - - Expects a peer id or peer name, that identifies the requesting peer + Returns lists of local objects that a peer should cache in its + database as foreign objects. Also returns the list of foreign + nodes in this database, for which the calling peer is + authoritative, to assist in synchronization of slivers. - Returns a dict containing, for the various types of cached entities, - the local objects as well as the ones attached to that peer + See the implementation of RefreshPeer for how this data is used. """ - roles = ['admin'] - - accepts = [Auth(), - Parameter (int, "Peer id"), - ] - # for RefreshPeer - returns = Parameter (dict,"Sites, Keys, Nodes, Persons, Slices") - event_type = 'Get' - object_type = 'Peer' - - def call (self, auth, peer_id): - # xxx a peer cannot yet compute it's peer_id under another plc - # so we return evrything by now - - return { - 'Sites' : Sites (self.api), - 'Keys' : Keys (self.api), - 'Nodes' : Nodes (self.api), - 'Persons' : Persons (self.api), - 'SliceAttibuteTypes' : SliceAttributeTypes (self.api), - 'Slices' : Slices (self.api), - 'SliceAttributes': SliceAttributes (self.api) + roles = ['admin', 'peer'] + + accepts = [Auth()] + + returns = { + 'Sites': Parameter([dict], "List of local sites"), + 'Keys': Parameter([dict], "List of local keys"), + 'Nodes': Parameter([dict], "List of local nodes"), + 'Persons': Parameter([dict], "List of local users"), + 'Slices': Parameter([dict], "List of local slices"), + 'db_time': Parameter(float, "(Debug) Database fetch time"), + } + + def call (self, auth): + start = time.time() + + # Filter out various secrets + node_fields = filter(lambda field: field not in \ + ['boot_nonce', 'key', 'session', 'root_person_ids'], + Node.fields) + + person_fields = filter(lambda field: field not in \ + ['password', 'verification_key', 'verification_expires'], + Person.fields) + + # XXX Optimize to return only those Persons, Keys, and Slices + # necessary for slice creation on the calling peer's nodes. + result = { + 'Sites': Sites(self.api, {'peer_id': None}), + 'Keys': Keys(self.api, {'peer_id': None}), + 'Nodes': Nodes(self.api, {'peer_id': None}, node_fields), + 'Persons': Persons(self.api, {'peer_id': None}, person_fields), + 'Slices': Slices(self.api, {'peer_id': None}), } - + + if isinstance(self.caller, Peer): + result['PeerNodes'] = Nodes(self.api, {'peer_id': self.caller['peer_id']}) + + result['db_time'] = time.time() - start + + return result