From 14cdfc43531c31f3a7e2c71fab24fc4b58868cdf Mon Sep 17 00:00:00 2001 From: Mark Huang Date: Thu, 11 Jan 2007 06:23:26 +0000 Subject: [PATCH] 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. See the implementation of RefreshPeer for how this data is used. --- PLC/Methods/GetPeerData.py | 90 ++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 52 deletions(-) diff --git a/PLC/Methods/GetPeerData.py b/PLC/Methods/GetPeerData.py index dd073de..08ed4bc 100644 --- a/PLC/Methods/GetPeerData.py +++ b/PLC/Methods/GetPeerData.py @@ -16,71 +16,57 @@ 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 +from PLC.Slices import Slice, Slices -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', 'peer'] - accepts = [ - Auth(), - Mixed(Peer.fields['peer_id'], - Peer.fields['peername']), - ] + accepts = [Auth()] - # for RefreshPeer returns = { - 'Sites-local': Parameter([dict], "List of local sites"), - 'Sites-peer': Parameter([dict], "List of foreign sites"), - 'Keys-local': Parameter([dict], "List of local keys"), - 'Keys-peer': Parameter([dict], "List of foreign keys"), - 'Nodes-local': Parameter([dict], "List of local nodes"), - 'Nodes-peer': Parameter([dict], "List of foreign nodes"), - 'Persons-local': Parameter([dict], "List of local users"), - 'Persons-peer': Parameter([dict], "List of foreign users"), - 'SliceAttibuteTypes-local': Parameter([dict], "List of local slice attribute types"), - 'SliceAttibuteTypes-peer': Parameter([dict], "List of foreign slice attribute types"), - 'Slices-local': Parameter([dict], "List of local slices"), - 'Slices-peer': Parameter([dict], "List of foreign slices"), - 'SliceAttributes-local': Parameter([dict], "List of local slice attributes"), - 'SliceAttributes-peer': Parameter([dict], "List of foreign slice attributes"), + '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, peer_id_or_peername): + 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) - # checking the argument - try: - peer_id = Peers(self.api,[peer_id_or_peername])[0]['peer_id'] - except: - raise PLCInvalidArgument,'GetPeerData: no such peer %r'%peer_id_or_peername - - t_start = time.time() + 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-local' : Sites (self.api,{'peer_id':None}), - 'Sites-peer' : Sites (self.api,{'peer_id':peer_id}), - 'Keys-local' : Keys (self.api,{'peer_id':None}), - 'Keys-peer' : Keys (self.api,{'peer_id':peer_id}), - 'Nodes-local' : Nodes (self.api,{'peer_id':None}), - 'Nodes-peer' : Nodes (self.api,{'peer_id':peer_id}), - 'Persons-local' : Persons (self.api,{'peer_id':None}), - 'Persons-peer' : Persons (self.api,{'peer_id':peer_id}), - 'SliceAttibuteTypes-local' : SliceAttributeTypes (self.api,{'peer_id':None}), - 'SliceAttibuteTypes-peer' : SliceAttributeTypes (self.api,{'peer_id':peer_id}), - 'Slices-local' : Slices (self.api,{'peer_id':None}), - 'Slices-peer' : Slices (self.api,{'peer_id':peer_id}), - 'SliceAttributes-local': SliceAttributes (self.api,{'peer_id':None}), - 'SliceAttributes-peer': SliceAttributes (self.api,{'peer_id':peer_id}), + '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}), } - t_end = time.time() - result['ellapsed'] = t_end-t_start + + if isinstance(self.caller, Peer): + result['PeerNodes'] = Nodes(self.api, {'peer_id': self.caller['peer_id']}) + + result['db_time'] = time.time() - start + return result - -- 2.43.0