4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.Filter import Filter
7 from PLC.Auth import Auth
8 from PLC.Persons import Persons
9 from PLC.Sites import Sites
10 from PLC.Nodes import Nodes
11 from PLC.Slices import Slices
12 from PLC.Keys import Keys
13 from PLC.Peers import Peers
14 from PLC.Faults import *
16 class BindObjectToPeer(Method):
18 This method is a hopefully temporary hack to let the sfa correctly
19 attach the objects it creates to a remote peer object. This is
20 needed so that the sfa federation link can work in parallel with
21 RefreshPeer, as RefreshPeer depends on remote objects being
24 BindRemoteObjectToPeer is allowed to admins only.
29 known_types = ['site','person','slice','node','key']
30 types_doc = ",".join(["'%s'"%type for type in known_types])
34 Parameter(str,"Object type, among "+types_doc),
35 Parameter(int,"object_id"),
36 Parameter(str,"peer shortname"),
37 Parameter(int,"remote object_id, set to 0 if unknown"),
40 returns = Parameter (int, '1 if successful')
42 def locate_object (self, object_type, object_id):
43 # locate e.g. the Nodes symbol
44 class_obj = globals()[object_type.capitalize()+'s']
45 id_name=object_type+'_id'
46 # invoke e.g. Nodes ({'node_id':node_id})
47 objs=class_obj(self.api,{id_name:object_id})
49 raise PLCInvalidArgument,"Cannot locate object, type=%s id=%d"%\
54 def call(self, auth, object_type, object_id, shortname,remote_object_id):
56 object_type = object_type.lower()
57 if object_type not in self.known_types:
58 raise PLCInvalidArgument, 'Unrecognized object type %s'%object_type
60 peers=Peers(self.api,{'shortname':shortname.upper()})
62 raise PLCInvalidArgument, 'No such peer with shortname %s'%shortname
65 object = self.locate_object (object_type, object_id)
67 # There is no need to continue if the object is already bound to this peer
68 if object['peer_id'] in [peer['peer_id']]:
71 adder_name = 'add_'+object_type
72 add_function = getattr(type(peer),adder_name)
73 add_function(peer,object,remote_object_id)