1 # $Id: UnBindObjectFromPeer.py 14587 2009-07-19 13:18:50Z thierry $
2 # $URL: svn+ssh://svn.planet-lab.org/svn/PLCAPI/trunk/PLC/Methods/BindObjectToPeer.py $
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 UnBindObjectFromPeer(Method):
18 This method is a hopefully temporary hack to let the sfa correctly
19 detach the objects it creates from 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 UnBindObjectFromPeer 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):
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)
66 remover_name = 'remove_'+object_type
67 remove_function = getattr(type(peer),remover_name)
68 remove_function(peer,object)