updated fields
authorTony Mack <tmack@paris.CS.Princeton.EDU>
Fri, 28 Sep 2012 19:13:57 +0000 (15:13 -0400)
committerTony Mack <tmack@paris.CS.Princeton.EDU>
Fri, 28 Sep 2012 19:13:57 +0000 (15:13 -0400)
PLC/Persons.py
PLC/Sites.py
PLC/Slices.py

index e088025..85f13c1 100644 (file)
@@ -29,7 +29,7 @@ class Person(NovaObject):
     """
 
     fields = {
-        'id': Parameter(str, "User identifier"),
+        'person_id': Parameter(str, "User identifier"),
         'name': Parameter(str, "Given name", max = 128),
         'email': Parameter(str, "Primary e-mail address", max = 254),
         'enabled': Parameter(bool, "Has been enabled"),
@@ -37,9 +37,9 @@ class Person(NovaObject):
         '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),
+        'roles': Parameter([str], "List of roles", joined=True),
+        'key_ids': Parameter([str], "List of key identifiers", joined=True),
+        'slice_ids': Parameter([int], "List of slice identifiers", joined=True),
         }
 
     def validate_email(self, email):
@@ -71,7 +71,7 @@ class Person(NovaObject):
 
         assert isinstance(person, Person)
 
-        if self.id == person.id:
+        if self.person_id == person.person_id:
             return True
 
         if 'admin' in self['roles']:
@@ -114,12 +114,12 @@ class Person(NovaObject):
 
     def sync(self, insert=False, validate=True):
         NovaObject.sync(self, insert, validate)
-        if insert == True or id not in self:
+        if insert == True or 'person_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']})
+        SlicePerson().delete.filter({'person_id': self['person_id']})
 
         # delete nova object
         user = self.api.client_shell.keystone.users.find(**self)
index beec765..873ebe6 100644 (file)
@@ -24,7 +24,7 @@ class Site(AlchemyObj):
 
     fields = {
         'enabled': Parameter(bool, "Has been enabled"),
-        'id': Parameter(str, "Site identifier"),
+        'site_id': Parameter(str, "Site identifier"),
         'tenant_id': Parameter(str, "Tenant identifier"),
         'abbreviated_name': Parameter(str, "Abbreviated site name", max = 50),
         'login_base': Parameter(str, "Site slice prefix", max = 20),
@@ -38,12 +38,12 @@ class Site(AlchemyObj):
         'last_updated': Parameter(int, "Date and time when site entry was last updated, in seconds since UNIX epoch", ro = True),
         'max_slices': Parameter(int, "Maximum number of slices that the site is able to create"),
         'max_slivers': Parameter(int, "Maximum number of slivers that the site is able to create"),
-        'person_ids': Parameter([int], "List of account identifiers", ro=True),
-        'slice_ids': Parameter([int], "List of slice identifiers", ro=True),
-        'address_ids': Parameter([int], "List of address identifiers"),
-        'pcu_ids': Parameter([int], "List of PCU identifiers", ro=True),
-        'node_ids': Parameter([int], "List of site node identifiers", ro=True),
-        'site_tag_ids' : Parameter ([int], "List of tags attached to this site", ro=True),
+        'person_ids': Parameter([int], "List of account identifiers", joined=True),
+        'slice_ids': Parameter([int], "List of slice identifiers", joined=True),
+        'address_ids': Parameter([int], "List of address identifiers", joined=True),
+        'pcu_ids': Parameter([int], "List of PCU identifiers", joined=True),
+        'node_ids': Parameter([int], "List of site node identifiers", joined=True),
+        'site_tag_ids' : Parameter ([int], "List of tags attached to this site", joined=True),
         'peer_id': Parameter(int, "Peer to which this site belongs", nullok = True),
         'peer_site_id': Parameter(int, "Foreign site identifier at peer", nullok = True),
         'ext_consortium_id': Parameter(int, "external consortium id", nullok = True) 
@@ -55,7 +55,7 @@ class Site(AlchemyObj):
         nova_can_update = lambda (field, value): field in nova_fields
         nova_site = dict(filter(nova_can_update, self.items()))
         AlchemyObj.sync(self, insert, validate)     
-        if insert == True or 'id' not in self:
+        if insert == True or 'site_id' not in self:
             self.object = self.api.client_shell.keystone.tenants.create(**nova_site)
             self['tenant_id'] = self.object.id
             AlchemyObj.insert(self, dict(self)) 
@@ -63,25 +63,25 @@ class Site(AlchemyObj):
             self.object = self.api.client_shell.keystone.tenants.update(self['tenant_id'], **nova_site)
             AlchemyObj.update(self, dict(self))
 
-    def delete(self):
+    def delete(self, commit=True):
         # delete nova object
         tenant = self.api.client_shell.keystone.tenants.find(id=self['tenant_id'])
         self.api.client_shell.keystone.tenants.delete(tenant)
         
         # delete relationships
-        SitePerson().delete(filter={'site_id': self['id']}) 
-        Slice().delete(filter={'site_id': self['id']}) 
-        PCU().delete(filter={'site_id': self['id']}) 
-        Node().delete(filter={'site_id': self['id']}) 
-        Address().delete(filter={'site_id': self['id']}) 
-        SiteTag().delete(filter={'site_id': self['id']}) 
+        SitePerson().delete(filter={'site_id': self['site_id']}) 
+        Slice().delete(filter={'site_id': self['site_id']}) 
+        PCU().delete(filter={'site_id': self['site_id']}) 
+        Node().delete(filter={'site_id': self['site_id']}) 
+        Address().delete(filter={'site_id': self['site_id']}) 
+        SiteTag().delete(filter={'site_id': self['site_id']}) 
         
         # delete site
         AlchemyObj.delete(self, dict(self))        
         
                
 
-class Sites(NovaTable):
+class Sites(list):
     """
     Representation of row(s) from the sites table in the
     database.
@@ -92,7 +92,7 @@ class Sites(NovaTable):
         if not site_filter:
             sites = Site().select() 
         elif isinstance(site_filter, int):
-            sites = Site().select(filter={'id': site_filter})
+            sites = Site().select(filter={'site_id': site_filter})
         elif isinstance(site_filter, StringTypes):
             sites = Site().select(filter={'login_base': site_filter})
         elif isinstance(site_filter, dict):
index ae40d80..b30ec37 100644 (file)
@@ -26,7 +26,7 @@ class Slice(AlchemyObj):
     tablename = 'slices'
  
     fields = {
-        'id': Parameter(int, "Slice identifier", primary_key=True),
+        'slice_id': Parameter(int, "Slice identifier", primary_key=True),
         'site_id': Parameter(int, "Identifier of the site to which this slice belongs"),
         'name': Parameter(str, "Slice name", max = 32),
         'instantiation': Parameter(str, "Slice instantiation state", nullok=True),
@@ -36,9 +36,9 @@ class Slice(AlchemyObj):
         'creator_person_id': Parameter(str, "Identifier of the account that created this slice"),
         'created': Parameter(datetime, "Date and time when slice was created, in seconds since UNIX epoch", ro = True),
         'expires': Parameter(datetime, "Date and time when slice expires, in seconds since UNIX epoch"),
-        'node_ids': Parameter([str], "List of nodes in this slice", ro = True),
-        'person_ids': Parameter([str], "List of accounts that can use this slice", ro = True),
-        'slice_tag_ids': Parameter([int], "List of slice attributes", ro = True),
+        'node_ids': Parameter([str], "List of nodes in this slice", joined = True),
+        'person_ids': Parameter([str], "List of accounts that can use this slice", joined = True),
+        'slice_tag_ids': Parameter([int], "List of slice attributes", joined = True),
         'peer_id': Parameter(int, "Peer to which this slice belongs", nullok = True),
         'peer_slice_id': Parameter(int, "Foreign slice identifier at peer", nullok = True),
         }
@@ -60,7 +60,7 @@ class Slice(AlchemyObj):
 
         conflicts = Slices(self.api, [name])
         for slice in conflicts:
-            if 'id' not in self or self['id'] != slice.id:
+            if 'slice_id' not in self or self['slice_id'] != slice.slice_id:
                 raise PLCInvalidArgument, "Slice name already in use, %s"%name
 
         return name
@@ -85,24 +85,24 @@ class Slice(AlchemyObj):
         Add or update a slice.
         """
         AlchemyObj.sync(self, commit, validate)
-        if 'id' not in self:
+        if 'slice_id' not in self:
             # Before a new slice is added, delete expired slices
             #expired = Slices(self.api, expires = -int(time.time()))
             #for slice in expired:
             #    slice.delete(commit)
             AlchemyObj.insert(self, dict(self))
         else:
-            AlchemyObj.update(self, self['id'], dict(self)) 
+            AlchemyObj.update(self, self['slice_id'], dict(self)) 
 
     def delete(self, commit = True):
         """
         Delete existing slice.
         """
-        assert 'id' in self
+        assert 'slice_id' in self
         # delete relationships
-        SlicePerson().delete(self, filter={'slice_id': self['id']}) 
-        SliceNode().delete(self, filter={'slice_id': self['id']}) 
-        SliceTag().delete(self, filter={'slice_id': self['id']}) 
+        SlicePerson().delete(self, filter={'slice_id': self['slice_id']}) 
+        SliceNode().delete(self, filter={'slice_id': self['slice_id']}) 
+        SliceTag().delete(self, filter={'slice_id': self['slice_id']}) 
         AlchemyObj.delete(self, dict(self))