X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Futil%2Frecord.py;h=11f46952935ad1d0a7457bee54a5992270b70013;hb=9277a03fd5b813e866746eae78b633d5f614a375;hp=a59a9c7c09400e013e6000ef7d2b394ee54f5ee4;hpb=9e655fe7d9a7e2f5b0f10dcef052c1918cafb603;p=sfa.git diff --git a/sfa/util/record.py b/sfa/util/record.py index a59a9c7c..11f46952 100644 --- a/sfa/util/record.py +++ b/sfa/util/record.py @@ -1,5 +1,5 @@ ## -# Implements support for geni records +# Implements support for SFA records # # TODO: Use existing PLC database methods? or keep this separate? ## @@ -11,15 +11,13 @@ from types import StringTypes from sfa.trust.gid import * -import sfa.util.report -from sfa.util.rspec import * from sfa.util.parameter import * -from sfa.util.misc import * +from sfa.util.xrn import get_authority +from sfa.util.row import Row - -class GeniRecord(dict): +class SfaRecord(Row): """ - The GeniRecord class implements a Geni Record. A GeniRecord is a tuple + The SfaRecord class implements an SFA Record. A SfaRecord is a tuple (Hrn, GID, Type, Info). Hrn specifies the Human Readable Name of the object @@ -37,9 +35,13 @@ class GeniRecord(dict): of different types. """ + table_name = 'sfa' + + primary_key = 'record_id' + ### the wsdl generator assumes this is named 'fields' internal_fields = { - 'record_id': Parameter(int, 'An id that uniquely identifies this record'), + 'record_id': Parameter(int, 'An id that uniquely identifies this record', ro=True), 'pointer': Parameter(int, 'An id that uniquely identifies this record in an external database ') } @@ -49,12 +51,12 @@ class GeniRecord(dict): 'hrn': Parameter(str, "Human readable name of object"), 'gid': Parameter(str, "GID of the object"), 'type': Parameter(str, "Record type"), - 'last_updated': Parameter(int, 'Date and time of last update'), - 'date_created': Parameter(int, 'Date and time this record was created'), + 'last_updated': Parameter(int, 'Date and time of last update', ro=True), + 'date_created': Parameter(int, 'Date and time this record was created', ro=True), } all_fields = dict(fields.items() + internal_fields.items()) ## - # Create a Geni Record + # Create an SFA Record # # @param name if !=None, assign the name of the record # @param gid if !=None, assign the gid of the record @@ -81,6 +83,10 @@ class GeniRecord(dict): self.load_from_dict(dict) if string: self.load_from_string(string) + + + def validate_last_updated(self, last_updated): + return time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime()) def update(self, new_dict): if isinstance(new_dict, list): @@ -200,6 +206,22 @@ class GeniRecord(dict): """ return GID(string=self.gid) + ## + # Returns the value of a field + + def get_field(self, fieldname, default=None): + # sometimes records act like classes, and sometimes they act like dicts + try: + return getattr(self, fieldname) + except AttributeError: + try: + return self[fieldname] + except KeyError: + if default != None: + return default + else: + raise + ## # Returns a list of field names in this record. @@ -301,8 +323,8 @@ class GeniRecord(dict): record = RecordSpec() record.parseString(str) record_dict = record.toDict() - geni_dict = record_dict['record'] - self.load_from_dict(geni_dict) + sfa_dict = record_dict['record'] + self.load_from_dict(sfa_dict) ## # Dump the record to stdout @@ -323,7 +345,7 @@ class GeniRecord(dict): # self.get_gid_object().dump(8, dump_parents) #print " pointer:", self.pointer - order = GeniRecord.fields.keys() + order = SfaRecord.fields.keys() for key in self.keys(): if key not in order: order.append(key) @@ -340,30 +362,31 @@ class GeniRecord(dict): return dict(self) -class UserRecord(GeniRecord): +class UserRecord(SfaRecord): fields = { 'email': Parameter(str, 'email'), 'first_name': Parameter(str, 'First name'), 'last_name': Parameter(str, 'Last name'), 'phone': Parameter(str, 'Phone Number'), - 'key': Parameter(str, 'Public key'), + 'keys': Parameter(str, 'Public key'), 'slices': Parameter([str], 'List of slices this user belongs to'), } - fields.update(GeniRecord.fields) + fields.update(SfaRecord.fields) -class SliceRecord(GeniRecord): +class SliceRecord(SfaRecord): fields = { 'name': Parameter(str, 'Slice name'), 'url': Parameter(str, 'Slice url'), 'expires': Parameter(int, 'Date and time this slice exipres'), 'researcher': Parameter([str], 'List of users for this slice'), + 'PI': Parameter([str], 'List of PIs responsible for this slice'), 'description': Parameter([str], 'Description of this slice'), } - fields.update(GeniRecord.fields) + fields.update(SfaRecord.fields) -class NodeRecord(GeniRecord): +class NodeRecord(SfaRecord): fields = { 'hostname': Parameter(str, 'This nodes dns name'), 'node_type': Parameter(str, 'Type of node this is'), @@ -371,10 +394,10 @@ class NodeRecord(GeniRecord): 'latitude': Parameter(str, 'latitude'), 'longitude': Parameter(str, 'longitude'), } - fields.update(GeniRecord.fields) + fields.update(SfaRecord.fields) -class AuthorityRecord(GeniRecord): +class AuthorityRecord(SfaRecord): fields = { 'name': Parameter(str, 'Name'), 'login_base': Parameter(str, 'login base'), @@ -385,6 +408,6 @@ class AuthorityRecord(GeniRecord): 'researcher': Parameter([str], 'List of researchers'), 'PI': Parameter([str], 'List of Principal Investigators'), } - fields.update(GeniRecord.fields) + fields.update(SfaRecord.fields)