X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Futil%2Frecord.py;h=bfa166fef1b347c63bf5a6999fe683d25f3af02f;hb=53cfd89c9fa5735ffd22b265d18e0dcf1d2cf106;hp=8575f018275f6eaaef601246a3183edb339a4e85;hpb=f13173726f8382eef380f1e754f24dd2b126a77b;p=sfa.git diff --git a/sfa/util/record.py b/sfa/util/record.py index 8575f018..bfa166fe 100644 --- a/sfa/util/record.py +++ b/sfa/util/record.py @@ -18,9 +18,9 @@ from sfa.util.parameter import * class GeniRecord(dict): """ The GeniRecord class implements a Geni Record. A GeniRecord is a tuple - (Name, GID, Type, Info). + (Hrn, GID, Type, Info). - Name specifies the HRN of the object + Hrn specifies the Human Readable Name of the object GID is the GID of the object Type is user | authority | slice | component @@ -35,16 +35,13 @@ class GeniRecord(dict): of different types. """ + ### the wsdl generator assumes this is named 'fields' fields = { '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'), - } - - internal_fields = { - 'pointer': Parameter(int, "Internal ID") + 'last_updated': Parameter(int, 'Date and time of last update'), + 'date_created': Parameter(int, 'Date and time this record was created'), } ## @@ -56,14 +53,14 @@ class GeniRecord(dict): # @param pointer is a pointer to a PLC record # @param dict if !=None, then fill in this record from the dictionary - def __init__(self, name=None, gid=None, type=None, pointer=None, dict=None, string=None): + def __init__(self, hrn=None, gid=None, type=None, pointer=None, dict=None, string=None): self.dirty = True - self.name = None + self.hrn = None self.gid = None self.type = None self.pointer = None - if name: - self.set_name(name) + if hrn: + self.set_name(hrn) if gid: self.set_gid(gid) if type: @@ -92,13 +89,13 @@ class GeniRecord(dict): ## # Set the name of the record # - # @param name is a string containing the HRN + # @param hrn is a string containing the HRN - def set_name(self, name): + def set_name(self, hrn): """ Set the name of the record """ - self.name = name + self.hrn = hrn self.dirty = True ## @@ -148,7 +145,7 @@ class GeniRecord(dict): """ Return the name (HRN) of the record """ - return self.name + return self.hrn ## # Return the type of the record @@ -194,7 +191,7 @@ class GeniRecord(dict): Geni. This key is used to uniquely identify the record in the Geni database. """ - return self.name + "#" + self.type + return self.hrn + "#" + self.type ## # Returns a list of field names in this record. @@ -203,16 +200,16 @@ class GeniRecord(dict): """ Returns a list of field names in this record. """ - return ["name", "gid", "type", "pointer"] + return self.fields.keys() ## - # Given a field name ("name", "gid", ...) return the value of that field. + # Given a field name ("hrn", "gid", ...) return the value of that field. # - # @param name is the name of field to be returned + # @param fieldname is the name of field to be returned def get_field_value_string(self, fieldname): """ - Given a field name ("name", "gid", ...) return the value of that field. + Given a field name ("hrn", "gid", ...) return the value of that field. """ if fieldname == "key": val = self.get_key() @@ -224,18 +221,15 @@ class GeniRecord(dict): return str(val) ## - # Given a list of field names, return a list of values for those fields. + # Given a list of field names, return a list of values for those public. # # @param fieldnames is a list of field names def get_field_value_strings(self, fieldnames): """ - Given a list of field names, return a list of values for those fields. + Given a list of field names, return a list of values for those public. """ - strs = [] - for fieldname in fieldnames: - strs.append(self.get_field_value_string(fieldname)) - return strs + return [ self.get_field_value_string (fieldname) for fieldname in fieldnames ] ## # Return the record in the form of a dictionary @@ -249,13 +243,13 @@ class GeniRecord(dict): ## # Load the record from a dictionary # - # @param dict dictionary to load record fields from + # @param dict dictionary to load record public from def load_from_dict(self, dict): """ Load the record from a dictionary """ - self.set_name(dict['name']) + self.set_name(dict['hrn']) gidstr = dict.get("gid", None) if gidstr: self.set_gid(dict['gid']) @@ -264,7 +258,6 @@ class GeniRecord(dict): self.set_pointer(dict['pointer']) self.set_type(dict['type']) - self['hrn'] = dict['name'] self.update(dict) ## @@ -276,9 +269,10 @@ class GeniRecord(dict): Save the record to a string. The string contains an XML representation of the record. """ - dict = self.as_dict() + recorddict = self.as_dict() + filteredDict = dict([(key, val) for (key, val) in recorddict.iteritems() if key in self.fields.keys()]) record = RecordSpec() - record.parseDict(dict) + record.parseDict(filteredDict) str = record.toxml() #str = xmlrpclib.dumps((dict,), allow_none=True) return str @@ -344,17 +338,9 @@ class UserRecord(GeniRecord): 'last_name': Parameter(str, 'Last name'), 'phone': Parameter(str, 'Phone Number'), 'key': Parameter(str, 'Public key'), - 'slice': Parameter([str], 'List of slices this user belongs to'), + 'slices': Parameter([str], 'List of slices this user belongs to'), } fields.update(GeniRecord.fields) - - internal_fields = { - 'roles': Parameter([str], 'List of roles'), - 'title': Parameter(str, 'Title'), - 'sites': Parameter([str], 'List of sites this user belongs to'), - 'enabled': Parameter(bool, 'Is this person enabled'), - } - internal_fields.update(GeniRecord.internal_fields) class SliceRecord(GeniRecord): fields = { @@ -366,13 +352,6 @@ class SliceRecord(GeniRecord): } fields.update(GeniRecord.fields) - internal_fields = { - 'site': Parameter(str, 'Site this slice belongs to'), - 'instantiation': Parameter(str, 'Slice instantiation'), - 'nodes': Parameter([str], 'List of nodes this slice is instantiated on'), - 'max_nodes': Parameter(int, 'Maximum number of nodes this slice is allowed on') - } - internal_fields.update(GeniRecord.internal_fields) class NodeRecord(GeniRecord): fields = { @@ -384,23 +363,6 @@ class NodeRecord(GeniRecord): } fields.update(GeniRecord.fields) - internal_fields = { - 'slice_ids_whitelist': Parameter([str], 'List of allowed slices on this node'), - 'site': Parameter(str, 'Site this node belongs to'), - 'slices': Parameter([str], 'List of instantiated slices on this node'), - 'boot_state': Parameter(str, 'This nodes boot state'), - 'session': Parameter(str, 'This nodes session key'), - 'ssh_rsa_key': Parameter(str, 'Last known ssh host key'), - 'verified': Parameter(str, 'Whether the node configuration is verified correct'), - 'last_contact': Parameter(int, 'Date and time this node last phoned home'), - 'run_level': Parameter(str, 'Run level'), - 'version': Parameter(str, 'Node software version'), - 'key': Parameter(str, 'Node key'), - 'boot_noonce': Parameter(str, 'Random value generate at nodes last boot'), - 'model': Parameter(str, 'Model of node'), - 'ports': Parameter([int], 'List of pcu ports this node is connected to') - } - internal_fields.update(GeniRecord.internal_fields) class AuthorityRecord(GeniRecord): fields = { @@ -415,15 +377,4 @@ class AuthorityRecord(GeniRecord): } fields.update(GeniRecord.fields) - internal_fields = { - 'nodes': Parameter([str], 'List of nodes at this site'), - 'slices': Parameter([str], 'List of slices instantiated by this site'), - 'abbreviated_name': Parameter(str, 'Abbreviated name'), - 'owners': Parameter([str], 'List of owners'), - 'max_slices': Parameter(int, 'Maximum number of slices this site can instantiate'), - 'max_slivers': Parameter(int, 'Maximum number of slivers this site can instantiate'), - 'pi': Parameter([str], 'List of pis'), - 'is_public': Parameter(bool, 'Is this site public'), - - } - internal_fields.update(GeniRecord.internal_fields) +