prevents side-effect on foreign objects when appropriate
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 7 Dec 2006 09:13:55 +0000 (09:13 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 7 Dec 2006 09:13:55 +0000 (09:13 +0000)
31 files changed:
PLC/Faults.py
PLC/Methods/AddConfFileToNode.py
PLC/Methods/AddNodeToNodeGroup.py
PLC/Methods/AddNodeToPCU.py
PLC/Methods/AddPersonKey.py
PLC/Methods/AddPersonToSite.py
PLC/Methods/AddPersonToSlice.py
PLC/Methods/AddRoleToPerson.py
PLC/Methods/AddSliceToNodes.py
PLC/Methods/AdmDeletePersonKeys.py
PLC/Methods/AdmGenerateNodeConfFile.py
PLC/Methods/BlacklistKey.py
PLC/Methods/DeleteKey.py
PLC/Methods/DeleteNode.py
PLC/Methods/DeletePerson.py
PLC/Methods/DeletePersonFromSite.py
PLC/Methods/DeletePersonFromSlice.py
PLC/Methods/DeleteRoleFromPerson.py
PLC/Methods/DeleteSite.py
PLC/Methods/DeleteSlice.py
PLC/Methods/DeleteSliceAttribute.py
PLC/Methods/DeleteSliceAttributeType.py
PLC/Methods/DeleteSliceFromNodes.py
PLC/Methods/SetPersonPrimarySite.py
PLC/Methods/UpdateKey.py
PLC/Methods/UpdateNode.py
PLC/Methods/UpdatePerson.py
PLC/Methods/UpdateSite.py
PLC/Methods/UpdateSlice.py
PLC/Methods/UpdateSliceAttribute.py
PLC/Methods/UpdateSliceAttributeType.py

index 1b2cdd3..b2db117 100644 (file)
@@ -5,7 +5,7 @@
 # Mark Huang <mlhuang@cs.princeton.edu>
 #
 # Copyright (C) 2004-2006 The Trustees of Princeton University
-# $Id$
+# $Id: Faults.py,v 1.1 2006/09/06 15:36:06 mlhuang Exp $
 #
 
 import xmlrpclib
@@ -46,10 +46,13 @@ class PLCAuthenticationFailure(PLCFault):
         faultString = "Failed to authenticate call"
         PLCFault.__init__(self, 103, faultString, extra)
 
-class PLCNotImplemented(PLCFault):
-    def __init__(self, extra = None):
-        faultString = "Not fully implemented"
-        PLCFault.__init__(self, 109, faultString, extra)
+class PLCLocalObjectRequired(PLCFault):
+    def __init__(self,method_name="anonymous",obj_name="anonymous",
+                peer_id=None,extra=None):
+       faultString = "Method: <%s> - Object <%s> must be local"%(method_name,obj_name)
+       if peer_id is not None:
+           faultString += " (authoritative plc has peer_id %d)"%peer_id
+        PLCFault.__init__(self, 104, faultString, extra)
 
 class PLCDBError(PLCFault):
     def __init__(self, extra = None):
@@ -61,7 +64,44 @@ class PLCPermissionDenied(PLCFault):
         faultString = "Permission denied"
         PLCFault.__init__(self, 108, faultString, extra)
 
+class PLCNotImplemented(PLCFault):
+    def __init__(self, extra = None):
+        faultString = "Not fully implemented"
+        PLCFault.__init__(self, 109, faultString, extra)
+
 class PLCAPIError(PLCFault):
     def __init__(self, extra = None):
         faultString = "Internal API error"
         PLCFault.__init__(self, 111, faultString, extra)
+
+####################
+# shorthands to check various types of objects for localness (are we authoritative)
+def PLCCheckLocalNode (node,method_name):
+    if node['peer_id'] is not None:
+       raise PLCLocalObjectRequired(method_name,node['hostname'],node['peer_id'])
+
+def PLCCheckLocalPerson (person,method_name):
+    if person['peer_id'] is not None:
+       raise PLCLocalObjectRequired(method_name,person['email'],person['peer_id'])
+
+def PLCCheckLocalSite (site,method_name):
+    if site['peer_id'] is not None:
+       raise PLCLocalObjectRequired(method_name,site['name'],site['peer_id'])
+
+def PLCCheckLocalSlice (slice,method_name):
+    if slice['peer_id'] is not None:
+       raise PLCLocalObjectRequired(method_name,slice['name'],slice['peer_id'])
+
+def PLCCheckLocalKey (key,method_name):
+    if key['peer_id'] is not None:
+       raise PLCLocalObjectRequired(method_name,key['key_id'],key['peer_id'])
+
+def PLCCheckLocalSliceAttributeType (sliceAttributeType,method_name):
+    if sliceAttributeType['peer_id'] is not None:
+       raise PLCLocalObjectRequired(method_name,sliceAttributeType['name'],sliceAttributeType['peer_id'])
+
+def PLCCheckLocalSliceAttribute (sliceAttribute,method_name):
+    if sliceAttribute['peer_id'] is not None:
+       raise PLCLocalObjectRequired(method_name,sliceAttribute['name'],sliceAttribute['peer_id'])
+
+
index 7bcdcc0..0c4899e 100644 (file)
@@ -37,6 +37,7 @@ class AddConfFileToNode(Method):
        if not nodes:
                raise PLCInvalidArgument, "No such node"
        node = nodes[0]
+       PLCCheckLocalNode (node,"AddConfFileToNode")
        
        # Link configuration file to node
         if node['node_id'] not in conf_file['node_ids']:
index 1720dfb..336387b 100644 (file)
@@ -32,6 +32,7 @@ class AddNodeToNodeGroup(Method):
        if not nodes:
                raise PLCInvalidArgument, "No such node"
        node = nodes[0]
+       PLCCheckLocalNode (node,"AddNodeToNodeGroup")
 
        # Get nodegroup info
         nodegroups = NodeGroups(self.api, [nodegroup_id_or_name])
index 4314a67..e57e168 100644 (file)
@@ -34,6 +34,7 @@ class AddNodeToPCU(Method):
             raise PLCInvalidArgument, "No such node"
 
         node = nodes[0]
+       PLCCheckLocalNode(node,"AddNodeToPCU")
 
         # Get PCU
         pcus = PCUs(self.api, [pcu_id])
index c404d05..a06ea06 100644 (file)
@@ -38,6 +38,7 @@ class AddPersonKey(Method):
         if not persons:
             raise PLCInvalidArgument, "No such account"
         person = persons[0]
+       PLCCheckLocalPerson (person,"AddPersonKey")
 
        # If we are not admin, make sure caller is adding a key to their account
         if 'admin' not in self.caller['roles']:
index 5ada731..0753e9a 100644 (file)
@@ -33,6 +33,7 @@ class AddPersonToSite(Method):
             raise PLCInvalidArgument, "No such account"
 
         person = persons[0]
+       PLCCheckLocalPerson(person,"AddPersonToSite")
 
         # Get site information
         sites = Sites(self.api, [site_id_or_login_base])
@@ -40,6 +41,7 @@ class AddPersonToSite(Method):
             raise PLCInvalidArgument, "No such site"
 
         site = sites[0]
+       PLCCheckLocalSite(site,"AddPersonToSite")
 
         if site['site_id'] not in person['site_ids']:
             site.add_person(person)
index bd16e04..a5b8072 100644 (file)
@@ -32,6 +32,8 @@ class AddPersonToSlice(Method):
             raise PLCInvalidArgument, "No such account"
 
         person = persons[0]
+       # Let's be open-minded as a start
+       #PLCCheckLocalPerson(person,"AddPersonToSlice")
 
         # Get slice information
         slices = Slices(self.api, [slice_id_or_name])
@@ -39,6 +41,7 @@ class AddPersonToSlice(Method):
             raise PLCInvalidArgument, "No such slice"
 
         slice = slices[0]
+       PLCCheckLocalSlice(slice,"AddPersonToSlice")
 
         # If we are not admin, make sure the caller is a PI
         # of the site associated with the slice
index 08f183e..100bb66 100644 (file)
@@ -49,6 +49,7 @@ class AddRoleToPerson(Method):
             raise PLCInvalidArgument, "No such account"
 
         person = persons[0]
+       PLCCheckLocalPerson(person,"AddRoleToPerson")
 
         # Authenticated function
         assert self.caller is not None
index e1950f5..f2b042f 100644 (file)
@@ -36,6 +36,7 @@ class AddSliceToNodes(Method):
             raise PLCInvalidArgument, "No such slice"
 
         slice = slices[0]
+       PLCCheckLocalSlice(slice,"AddSliceToNodes")
 
         if 'admin' not in self.caller['roles']:
             if self.caller['person_id'] in slice['person_ids']:
index 01d4055..57c63f0 100644 (file)
@@ -36,6 +36,7 @@ class AdmDeletePersonKeys(Method):
             raise PLCInvalidArgument, "No such account"
 
         person = persons[0]
+       PLCCheckLocalPerson(person,"AdmDeletePersonKeys")
 
         if 'admin' not in self.caller['roles']:
             if self.caller['person_id'] != person['person_id']:
index ed968f9..8781e55 100644 (file)
@@ -41,6 +41,7 @@ class AdmGenerateNodeConfFile(Method):
         if not nodes:
             raise PLCInvalidArgument, "No such node"
         node = nodes[0]
+       PLCCheckLocalNode(node,"AdmGenerateNodeConfFile")
 
         # If we are not an admin, make sure that the caller is a
         # member of the site at which the node is located.
index 17a0418..a412865 100644 (file)
@@ -34,6 +34,7 @@ class BlacklistKey(Method):
         if not keys:
             raise PLCInvalidArgument, "No such key"
         key = keys[0]
+       PLCCheckLocalKey(key,"BlackListKey")
 
         key.blacklist()
        self.object_ids = [key['key_id']]
index bdd3397..d3eb68d 100644 (file)
@@ -29,6 +29,7 @@ class DeleteKey(Method):
         if not keys:
             raise PLCInvalidArgument, "No such key"
         key = keys[0]
+       PLCCheckLocalKey(key,"DeleteKey")
 
         if 'admin' not in self.caller['roles']:
             if key['key_id'] not in self.caller['key_ids']:
index 64f149a..c8dc2d8 100644 (file)
@@ -32,6 +32,8 @@ class DeleteNode(Method):
             raise PLCInvalidArgument, "No such node"
 
         node = nodes[0]
+       ### xxx here xxx
+       PLCCheckLocalNode(node,"DeleteNode")
 
         # If we are not an admin, make sure that the caller is a
         # member of the site at which the node is located.
index 38534c7..fd930a1 100644 (file)
@@ -33,6 +33,7 @@ class DeletePerson(Method):
             raise PLCInvalidArgument, "No such account"
 
         person = persons[0]
+       PLCCheckLocalPerson(person,"DeletePerson")
 
         # Authenticated function
         assert self.caller is not None
index c17384d..2c48127 100644 (file)
@@ -41,6 +41,7 @@ class DeletePersonFromSite(Method):
             raise PLCInvalidArgument, "No such site"
 
         site = sites[0]
+       PLCCheckLocalSite(site,"DeletePersonFromSite")
 
         if site['site_id'] in person['site_ids']:
             site.remove_person(person)
index bca374c..22e4be3 100644 (file)
@@ -40,6 +40,7 @@ class DeletePersonFromSlice(Method):
             raise PLCInvalidArgument, "No such slice"
 
         slice = slices[0]
+       PLCCheckLocalSlice(slice,"DeletePersonFromSlice")
 
         # If we are not admin, make sure the caller is a pi
         # of the site associated with the slice
index 1119ad4..f2106a7 100644 (file)
@@ -49,6 +49,7 @@ class DeleteRoleFromPerson(Method):
             raise PLCInvalidArgument, "No such account"
 
         person = persons[0]
+       PLCCheckLocalPerson(person,"DeleteRoleFromPerson")
 
         # Authenticated function
         assert self.caller is not None
index 743e228..2f5b54d 100644 (file)
@@ -35,6 +35,8 @@ class DeleteSite(Method):
             raise PLCInvalidArgument, "No such site"
 
         site = sites[0]
+       PLCCheckLocalSite(site,"DeleteSite")
+
         site.delete()
        self.object_ids = [site['site_id']]
 
index 888f6e0..e635b0d 100644 (file)
@@ -31,6 +31,7 @@ class DeleteSlice(Method):
         if not slices:
             raise PLCInvalidArgument, "No such slice"
         slice = slices[0]
+       PLCCheckLocalSlice(slice,"DeleteSlice")
 
         if 'admin' not in self.caller['roles']:
             if self.caller['person_id'] in slice['person_ids']:
index 989b112..c283c45 100644 (file)
@@ -34,11 +34,13 @@ class DeleteSliceAttribute(Method):
         if not slice_attributes:
             raise PLCInvalidArgument, "No such slice attribute"
         slice_attribute = slice_attributes[0]
+       PLCCheckLocalSliceAttribute(slice_attribute,"DeleteSliceAttribute")
 
         slices = Slices(self.api, [slice_attribute['slice_id']])
         if not slices:
             raise PLCInvalidArgument, "No such slice"
         slice = slices[0]
+       PLCCheckLocalSlice(slice,"DeleteSliceAttribute")
 
         assert slice_attribute['slice_attribute_id'] in slice['slice_attribute_ids']
 
index 922b6ac..ab10911 100644 (file)
@@ -27,6 +27,7 @@ class DeleteSliceAttributeType(Method):
         if not attribute_types:
             raise PLCInvalidArgument, "No such slice attribute type"
         attribute_type = attribute_types[0]
+       PLCCheckLocalSliceAttributeType(attribute_type,"DeleteSliceAttributeType")
 
         attribute_type.delete()
        self.object_ids = [attribute_type['attribute_type_id']]
index 2945d31..321169e 100644 (file)
@@ -33,6 +33,7 @@ class DeleteSliceFromNodes(Method):
             raise PLCInvalidArgument, "No such slice"
 
         slice = slices[0]
+       PLCCheckLocalSlice(slice,"DeleteSliceFromNodes")
 
         if 'admin' not in self.caller['roles']:
             if self.caller['person_id'] in slice['person_ids']:
index 61ab287..e2e913f 100644 (file)
@@ -32,6 +32,7 @@ class SetPersonPrimarySite(Method):
             raise PLCInvalidArgument, "No such account"
 
         person = persons[0]
+       PLCCheckLocalPerson(person,"SetPersonPrimarySite")
 
         # Authenticated function
         assert self.caller is not None
@@ -47,6 +48,7 @@ class SetPersonPrimarySite(Method):
             raise PLCInvalidArgument, "No such site"
 
         site = sites[0]
+       PLCCheckLocalSite(site,"SetPersonPrimarySite")
 
         if site['site_id'] not in person['site_ids']:
             raise PLCInvalidArgument, "Not a member of the specified site"
index 5e14b9a..14e521e 100644 (file)
@@ -37,6 +37,7 @@ class UpdateKey(Method):
         if not keys:
             raise PLCInvalidArgument, "No such key"
         key = keys[0]
+       PLCCheckLocalKey(key,"UpdateKey")
 
         if 'admin' not in self.caller['roles']:
             if key['key_id'] not in self.caller['key_ids']:
index 0e40564..5530874 100644 (file)
@@ -46,6 +46,7 @@ class UpdateNode(Method):
             raise PLCInvalidArgument, "No such node"
 
         node = nodes[0]
+       PLCCheckLocalNode(node,"UpdateNode")
 
         # Authenticated function
         assert self.caller is not None
index 5d0161c..65a490f 100644 (file)
@@ -42,6 +42,7 @@ class UpdatePerson(Method):
             raise PLCInvalidArgument, "No such account"
 
         person = persons[0]
+       PLCCheckLocalPerson(person,"UpdatePerson")
 
         # Authenticated function
         assert self.caller is not None
index 0e570f2..d09a21b 100644 (file)
@@ -42,6 +42,7 @@ class UpdateSite(Method):
             raise PLCInvalidArgument, "No such site"
 
         site = sites[0]
+       PLCCheckLocalSite(site,"UpdateSite")
 
         # Authenticated function
         assert self.caller is not None
index a9d6cb2..ac454af 100644 (file)
@@ -46,6 +46,7 @@ class UpdateSlice(Method):
         if not slices:
             raise PLCInvalidArgument, "No such slice"
         slice = slices[0]
+       PLCCheckLocalSlice(slice,"UpdateSlice")
 
         if 'admin' not in self.caller['roles']:
             if self.caller['person_id'] in slice['person_ids']:
index a9f26ec..81096a4 100644 (file)
@@ -32,11 +32,13 @@ class UpdateSliceAttribute(Method):
         if not slice_attributes:
             raise PLCInvalidArgument, "No such slice attribute"
         slice_attribute = slice_attributes[0]
+       PLCCheckLocalSliceAttribute(slice_attribute,"UpdateSliceAttribute")
 
         slices = Slices(self.api, [slice_attribute['slice_id']])
         if not slices:
             raise PLCInvalidArgument, "No such slice"
         slice = slices[0]
+       PLCCheckLocalSlice(slice,"UpdateSliceAttribute")
 
         assert slice_attribute['slice_attribute_id'] in slice['slice_attribute_ids']
 
index a6c7701..4dc852f 100644 (file)
@@ -35,6 +35,7 @@ class UpdateSliceAttributeType(Method):
         if not attribute_types:
             raise PLCInvalidArgument, "No such attribute"
         attribute_type = attribute_types[0]
+       PLCCheckLocalSliceAttributeType(attribute_type,"UpdateSliceAttributeType")
 
         attribute_type.update(attribute_type_fields)
         attribute_type.sync()