From 259f989816ec6cd9beb1c0549dc08aa78205cc20 Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Mon, 1 Oct 2012 21:40:13 -0400 Subject: [PATCH] removing Peers --- PLC/Methods/AddNode.py | 2 - PLC/Methods/BindObjectToPeer.py | 72 ------------------------- PLC/Methods/GetPeerData.py | 84 ----------------------------- PLC/Methods/GetPeerName.py | 19 ------- PLC/Methods/UnBindObjectFromPeer.py | 67 ----------------------- 5 files changed, 244 deletions(-) delete mode 100644 PLC/Methods/BindObjectToPeer.py delete mode 100644 PLC/Methods/GetPeerData.py delete mode 100644 PLC/Methods/GetPeerName.py delete mode 100644 PLC/Methods/UnBindObjectFromPeer.py diff --git a/PLC/Methods/AddNode.py b/PLC/Methods/AddNode.py index 0ee13f5a..3a5ce903 100644 --- a/PLC/Methods/AddNode.py +++ b/PLC/Methods/AddNode.py @@ -2,9 +2,7 @@ from PLC.Faults import * from PLC.Auth import Auth from PLC.Method import Method from PLC.Parameter import Parameter, Mixed -from PLC.Table import Row from PLC.Namespace import hostname_to_hrn -from PLC.Peers import Peers from PLC.Sites import Site, Sites from PLC.Nodes import Node, Nodes from PLC.TagTypes import TagTypes diff --git a/PLC/Methods/BindObjectToPeer.py b/PLC/Methods/BindObjectToPeer.py deleted file mode 100644 index ea16536d..00000000 --- a/PLC/Methods/BindObjectToPeer.py +++ /dev/null @@ -1,72 +0,0 @@ -from PLC.Method import Method -from PLC.Parameter import Parameter, Mixed -from PLC.Filter import Filter -from PLC.Auth import Auth -from PLC.Persons import Persons -from PLC.Sites import Sites -from PLC.Nodes import Nodes -from PLC.Slices import Slices -from PLC.Keys import Keys -from PLC.Peers import Peers -from PLC.Faults import * - -class BindObjectToPeer(Method): - """ - This method is a hopefully temporary hack to let the sfa correctly - attach the objects it creates to a remote peer object. This is - needed so that the sfa federation link can work in parallel with - RefreshPeer, as RefreshPeer depends on remote objects being - correctly marked. - - BindRemoteObjectToPeer is allowed to admins only. - """ - - roles = ['admin'] - - known_types = ['site','person','slice','node','key'] - types_doc = ",".join(["'%s'"%type for type in known_types]) - - accepts = [ - Auth(), - Parameter(str,"Object type, among "+types_doc), - Parameter(int,"object_id"), - Parameter(str,"peer shortname"), - Parameter(int,"remote object_id, set to 0 if unknown"), - ] - - returns = Parameter (int, '1 if successful') - - def locate_object (self, object_type, object_id): - # locate e.g. the Nodes symbol - class_obj = globals()[object_type.capitalize()+'s'] - id_name=object_type+'_id' - # invoke e.g. Nodes ({'node_id':node_id}) - objs=class_obj(self.api,{id_name:object_id}) - if len(objs) != 1: - raise PLCInvalidArgument,"Cannot locate object, type=%s id=%d"%\ - (type,object_id) - return objs[0] - - - def call(self, auth, object_type, object_id, shortname,remote_object_id): - - object_type = object_type.lower() - if object_type not in self.known_types: - raise PLCInvalidArgument, 'Unrecognized object type %s'%object_type - - peers=Peers(self.api,{'shortname':shortname.upper()}) - if len(peers) !=1: - raise PLCInvalidArgument, 'No such peer with shortname %s'%shortname - - peer=peers[0] - object = self.locate_object (object_type, object_id) - - # There is no need to continue if the object is already bound to this peer - if object['peer_id'] in [peer['peer_id']]: - return 1 - - adder_name = 'add_'+object_type - add_function = getattr(type(peer),adder_name) - add_function(peer,object,remote_object_id) - - return 1 diff --git a/PLC/Methods/GetPeerData.py b/PLC/Methods/GetPeerData.py deleted file mode 100644 index b220f180..00000000 --- a/PLC/Methods/GetPeerData.py +++ /dev/null @@ -1,84 +0,0 @@ -# -# Thierry Parmentelat - INRIA -# - -import time - -from PLC.Faults import * -from PLC.Method import Method -from PLC.Parameter import Parameter, Mixed -from PLC.Auth import Auth - -from PLC.Peers import Peer, Peers - -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.Slices import Slice, Slices -from PLC.SliceTags import SliceTags - -class GetPeerData(Method): - """ - 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. - """ - - 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 = [ field for field in Node.fields if field \ - not in ['boot_nonce', 'key', 'session', 'root_person_ids']] - nodes = Nodes(self.api, {'peer_id': None}, node_fields); - # filter out whitelisted nodes - nodes = [ n for n in nodes if not n['slice_ids_whitelist']] - - - person_fields = [ field for field in Person.fields if field \ - not in ['password', 'verification_key', 'verification_expires']] - - # XXX Optimize to return only those Persons, Keys, and Slices - # necessary for slice creation on the calling peer's nodes. - - # filter out special person - persons = Persons(self.api, {'~email':[self.api.config.PLC_API_MAINTENANCE_USER, - self.api.config.PLC_ROOT_USER], - 'peer_id': None}, person_fields) - - # filter out system slices - system_slice_ids = SliceTags(self.api, {'name': 'system', 'value': '1'}).dict('slice_id') - slices = Slices(self.api, {'peer_id': None, - '~slice_id':system_slice_ids.keys()}) - - result = { - 'Sites': Sites(self.api, {'peer_id': None}), - 'Keys': Keys(self.api, {'peer_id': None}), - 'Nodes': nodes, - 'Persons': persons, - 'Slices': slices, - } - - if isinstance(self.caller, Peer): - result['PeerNodes'] = Nodes(self.api, {'peer_id': self.caller['peer_id']}) - - result['db_time'] = time.time() - start - - return result diff --git a/PLC/Methods/GetPeerName.py b/PLC/Methods/GetPeerName.py deleted file mode 100644 index 30fbd945..00000000 --- a/PLC/Methods/GetPeerName.py +++ /dev/null @@ -1,19 +0,0 @@ -from PLC.Method import Method -from PLC.Parameter import Parameter -from PLC.Auth import Auth - -from PLC.Peers import Peer, Peers - -class GetPeerName (Method): - """ - Returns this peer's name, as defined in the config as PLC_NAME - """ - - roles = ['admin', 'peer', 'node'] - - accepts = [Auth()] - - returns = Peer.fields['peername'] - - def call (self, auth): - return self.api.config.PLC_NAME diff --git a/PLC/Methods/UnBindObjectFromPeer.py b/PLC/Methods/UnBindObjectFromPeer.py deleted file mode 100644 index 156f9765..00000000 --- a/PLC/Methods/UnBindObjectFromPeer.py +++ /dev/null @@ -1,67 +0,0 @@ -from PLC.Method import Method -from PLC.Parameter import Parameter, Mixed -from PLC.Filter import Filter -from PLC.Auth import Auth -from PLC.Persons import Persons -from PLC.Sites import Sites -from PLC.Nodes import Nodes -from PLC.Slices import Slices -from PLC.Keys import Keys -from PLC.Peers import Peers -from PLC.Faults import * - -class UnBindObjectFromPeer(Method): - """ - This method is a hopefully temporary hack to let the sfa correctly - detach the objects it creates from a remote peer object. This is - needed so that the sfa federation link can work in parallel with - RefreshPeer, as RefreshPeer depends on remote objects being - correctly marked. - - UnBindObjectFromPeer is allowed to admins only. - """ - - roles = ['admin'] - - known_types = ['site','person','slice','node','key'] - types_doc = ",".join(["'%s'"%type for type in known_types]) - - accepts = [ - Auth(), - Parameter(str,"Object type, among "+types_doc), - Parameter(int,"object_id"), - Parameter(str,"peer shortname"), - Parameter(int,"remote object_id, set to 0 if unknown"), - ] - - returns = Parameter (int, '1 if successful') - - def locate_object (self, object_type, object_id): - # locate e.g. the Nodes symbol - class_obj = globals()[object_type.capitalize()+'s'] - id_name=object_type+'_id' - # invoke e.g. Nodes ({'node_id':node_id}) - objs=class_obj(self.api,{id_name:object_id}) - if len(objs) != 1: - raise PLCInvalidArgument,"Cannot locate object, type=%s id=%d"%\ - (type,object_id) - return objs[0] - - - def call(self, auth, object_type, object_id, shortname): - - object_type = object_type.lower() - if object_type not in self.known_types: - raise PLCInvalidArgument, 'Unrecognized object type %s'%object_type - - peers=Peers(self.api,{'shortname':shortname.upper()}) - if len(peers) !=1: - raise PLCInvalidArgument, 'No such peer with shortname %s'%shortname - - peer=peers[0] - object = self.locate_object (object_type, object_id) - remover_name = 'remove_'+object_type - remove_function = getattr(type(peer),remover_name) - remove_function(peer,object) - - return 1 -- 2.47.0