From 4f719a0d28715484ee29875b049c44968dc5375c Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Thu, 27 Sep 2012 20:28:32 -0400 Subject: [PATCH] update added aggregate fields --- PLC/Persons.py | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/PLC/Persons.py b/PLC/Persons.py index c220aeb9..e088025a 100644 --- a/PLC/Persons.py +++ b/PLC/Persons.py @@ -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) -- 2.47.0