update added aggregate fields
authorTony Mack <tmack@paris.CS.Princeton.EDU>
Fri, 28 Sep 2012 00:28:32 +0000 (20:28 -0400)
committerTony Mack <tmack@paris.CS.Princeton.EDU>
Fri, 28 Sep 2012 00:28:32 +0000 (20:28 -0400)
PLC/Persons.py

index c220aeb..e088025 100644 (file)
@@ -34,12 +34,12 @@ class Person(NovaObject):
         'email': Parameter(str, "Primary e-mail address", max = 254),
         'enabled': Parameter(bool, "Has been enabled"),
         'password': Parameter(str, "Account password in crypt() form", max = 254),
-        'tenant_id': Parameter(str, "Tenant identifier"),
-        'last_updated': Parameter(int, "Date and time of last update", ro = True),
-        'date_created': Parameter(int, "Date and time when account was created", ro = True),
-        'roles': Parameter([str], "List of roles"),
-        'keys': Parameter([int], "List of key identifiers"),
-        'slices': Parameter([int], "List of slice identifiers"),
+        'tenant_ids': Parameter(str, "Site identifier"),
+        #'last_updated': Parameter(int, "Date and time of last update"),
+        #'date_created': Parameter(int, "Date and time when account was created"),
+        'roles': Parameter([str], "List of roles", ro=True),
+        'key_ids': Parameter([str], "List of key identifiers", ro=True),
+        'slice_ids': Parameter([int], "List of slice identifiers", ro=True),
         }
 
     def validate_email(self, email):
@@ -106,16 +106,25 @@ class Person(NovaObject):
 
         return False
 
-    add_role = Row.add_object(Role, 'person_role')
-    remove_role = Row.remove_object(Role, 'person_role')
+    #add_role = Row.add_object(Role, 'person_role')
+    #remove_role = Row.remove_object(Role, 'person_role')
 
-    add_key = Row.add_object(Key, 'person_key')
-    remove_key = Row.remove_object(Key, 'person_key')
+    #add_key = Row.add_object(Key, 'person_key')
+    #remove_key = Row.remove_object(Key, 'person_key')
 
     def sync(self, insert=False, validate=True):
         NovaObject.sync(self, insert, validate)
         if insert == True or id not in self:
             self.object = self.api.client_shell.keystone.users.create(**self)
+
+    def delete(self):
+        # delete relationships
+        SlicePerson().delete.filter({'person_id': self['id']})
+
+        # delete nova object
+        user = self.api.client_shell.keystone.users.find(**self)
+        self.api.client_shell.keystone.users.delete(user)
+
  
     def get_roles(self):
         roles = []
@@ -123,12 +132,15 @@ class Person(NovaObject):
             roles = self.api.client_shell.keystone.roles.roles_for_user(self.object, self.tenant)
         return [role.name for role in roles] 
 
-    def get_tenants(self):
+    def get_tenants_ids(self):
         tenants = []
         if self.tenantId:
             tenants = [self.tenantId]
         return tenants
 
+    def get_key_ids(self):
+        return []
+
 class Persons(NovaTable):
     """
     Representation of row(s) from the persons table in the
@@ -155,6 +167,13 @@ class Persons(NovaTable):
             person.tenant=None
             if person.tenantId:
                 person.tenant = self.api.client_shell.keystone.tenants.find(id=person.tenantId)
-            person['roles'] = person.get_roles()
-            person['tenants'] = person.get_tenants() 
+            if not columns or 'roles' in columns:
+                person['roles'] = person.get_roles()
+            if not columns or 'tenant_ids' in columns:
+                person['tenant_ids'] = person.get_tenants_ids() 
+            if not columns or 'key_ids' in columns:
+                person['key_ids'] = person.get_keys_ids() 
+            if not columns or 'slice_ids' in columns:
+                person_slices = SlicePerson().select(filter={'person_id': person.person_id})
+                person['slice_ids'] = [rec.slice_id for rec in person_slices]
             self.append(person)