check in lost code for updating researchers in records
authorScott Baker <bakers@cs.arizona.edu>
Thu, 26 Feb 2009 04:07:58 +0000 (04:07 +0000)
committerScott Baker <bakers@cs.arizona.edu>
Thu, 26 Feb 2009 04:07:58 +0000 (04:07 +0000)
geni/registry.py
geni/util/remoteshell.py

index bafc2d7..c4de3e6 100644 (file)
@@ -320,6 +320,62 @@ class Registry(GeniServer):
         self.fill_record_pl_info(record)
         self.fill_record_geni_info(record)
 
+    def update_membership_list(self, oldRecord, record, listName, addFunc, delFunc):
+        # get a list of the HRNs tht are members of the old and new records\r
+        if oldRecord:\r
+            if oldRecord.pl_info == None:\r
+                oldRecord.pl_info = {}\r
+            oldList = oldRecord.get_geni_info().get(listName, [])\r
+        else:\r
+            oldList = []\r
+        newList = record.get_geni_info().get(listName, [])\r
+\r
+        # if the lists are the same, then we don't have to update anything\r
+        if (oldList == newList):\r
+            return\r
+\r
+        # build a list of the new person ids, by looking up each person to get\r
+        # their pointer\r
+        newIdList = []\r
+        for hrn in newList:\r
+            userRecord = self.resolve_raw("user", hrn)[0]\r
+            newIdList.append(userRecord.get_pointer())\r
+\r
+        # build a list of the old person ids from the person_ids field of the\r
+        # pl_info\r
+        if oldRecord:\r
+            oldIdList = oldRecord.pl_info.get("person_ids", [])\r
+            containerId = oldRecord.get_pointer()\r
+        else:\r
+            # if oldRecord==None, then we are doing a Register, instead of an\r
+            # update.\r
+            oldIdList = []\r
+            containerId = record.get_pointer()\r
+\r
+        # add people who are in the new list, but not the oldList\r
+        for personId in newIdList:\r
+            if not (personId in oldIdList):\r
+                print "adding id", personId, "to", record.get_name()\r
+                addFunc(self.pl_auth, personId, containerId)\r
+\r
+        # remove people who are in the old list, but not the new list\r
+        for personId in oldIdList:\r
+            if not (personId in newIdList):\r
+                print "removing id", personId, "from", record.get_name()\r
+                delFunc(self.pl_auth, personId, containerId)\r
+\r
+    def update_membership(self, oldRecord, record):\r
+        if record.type == "slice":\r
+            self.update_membership_list(oldRecord, record, 'researcher',\r
+                                        self.shell.AddPersonToSlice,\r
+                                        self.shell.DeletePersonFromSlice)\r
+        elif record.type == "sa":\r
+            # TODO\r
+            pass\r
+        elif record.type == "ma":\r
+            # TODO\r
+            pass
+
     ##
     # GENI API: register
     #
@@ -418,6 +474,9 @@ class Registry(GeniServer):
 
         table.insert(record)
 
+        # update membership for researchers, pis, owners, operators
+        self.update_membership(None, record)
+
         return record.get_gid_object().save_to_string(save_parents=True)
 
     ##
@@ -474,7 +533,7 @@ class Registry(GeniServer):
         return True
 
     ##
-    # GENI API: Register
+    # GENI API: Update
     #
     # Update an object in the registry. Currently, this only updates the
     # PLC information associated with the record. The Geni fields (name, type,
@@ -535,6 +594,9 @@ class Registry(GeniServer):
         else:
             raise UnknownGeniType(type)
 
+        # update membership for researchers, pis, owners, operators\r
+        self.update_membership(existing_record, record)
+
     ##
     # List the records in an authority. The objectGID in the supplied credential
     # should name the authority that will be listed.
index 9697ae2..db15083 100644 (file)
@@ -44,6 +44,9 @@ class RemoteShell:
     def AddPerson(self, pl_auth, *args):
         return self.call("AddPerson", pl_auth, *args)
 
+    def AddPersonToSlice(self, pl_auth, *args):
+        return self.call("AddPersonToSlice", pl_auth, *args)
+
     def AddSite(self, pl_auth, *args):
         return self.call("AddSite", pl_auth, *args)
 
@@ -56,6 +59,9 @@ class RemoteShell:
     def DeletePerson(self, pl_auth, *args):
         return self.call("DeletePerson", pl_auth, *args)
 
+    def DeletePersonFromSlice(self, pl_auth, *args):
+        return self.call("DeletePersonFromSlice", pl_auth, *args)
+
     def DeleteSite(self, pl_auth, *args):
         return self.call("DeleteSite", pl_auth, *args)