fix packaging for f37 (4/n)
[plcapi.git] / PLC / Methods / BindObjectToPeer.py
index c9cf4e4..a684809 100644 (file)
@@ -1,5 +1,3 @@
-# $Id: ResolveSlices.py 12217 2009-02-24 17:28:54Z thierry $
-
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
 from PLC.Filter import Filter
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
 from PLC.Filter import Filter
@@ -8,7 +6,9 @@ from PLC.Persons import Persons
 from PLC.Sites import Sites
 from PLC.Nodes import Nodes
 from PLC.Slices import Slices
 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.Peers import Peers
+from PLC.Faults import *
 
 class BindObjectToPeer(Method):
     """
 
 class BindObjectToPeer(Method):
     """
@@ -16,7 +16,7 @@ class BindObjectToPeer(Method):
     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
     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. 
+    correctly marked.
 
     BindRemoteObjectToPeer is allowed to admins only.
     """
 
     BindRemoteObjectToPeer is allowed to admins only.
     """
@@ -43,8 +43,8 @@ class BindObjectToPeer(Method):
         # invoke e.g. Nodes ({'node_id':node_id})
         objs=class_obj(self.api,{id_name:object_id})
         if len(objs) != 1:
         # 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)
+            raise PLCInvalidArgument("Cannot locate object, type=%s id=%d"%\
+                (type,object_id))
         return objs[0]
 
 
         return objs[0]
 
 
@@ -52,14 +52,19 @@ class BindObjectToPeer(Method):
 
         object_type = object_type.lower()
         if object_type not in self.known_types:
 
         object_type = object_type.lower()
         if object_type not in self.known_types:
-            raise PLCInvalidArgument, 'Unrecognized object type %s'%object_type
+            raise PLCInvalidArgument('Unrecognized object type %s'%object_type)
 
         peers=Peers(self.api,{'shortname':shortname.upper()})
         if len(peers) !=1:
 
         peers=Peers(self.api,{'shortname':shortname.upper()})
         if len(peers) !=1:
-            raise PLCInvalidArgument, 'No such peer with shortname %s'%shortname
+            raise PLCInvalidArgument('No such peer with shortname %s'%shortname)
 
         peer=peers[0]
         object = self.locate_object (object_type, object_id)
 
         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)
         adder_name = 'add_'+object_type
         add_function = getattr(type(peer),adder_name)
         add_function(peer,object,remote_object_id)