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
of different types.
"""
- public = {
+ ### 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'),
+ 'last_updated': Parameter(int, 'Date and time of last update'),
+ 'date_created': Parameter(int, 'Date and time this record was created'),
}
##
# @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:
##
# 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
##
"""
Return the name (HRN) of the record
"""
- return self.name
+ return self.hrn
##
# Return the type of the record
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.
"""
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()
else:
- val = getattr(self, fieldname)
+ try:
+ val = getattr(self, fieldname)
+ except:
+ val = self[fieldname]
if isinstance(val, str):
return "'" + str(val) + "'"
else:
"""
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
"""
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'])
self.set_pointer(dict['pointer'])
self.set_type(dict['type'])
- self['hrn'] = dict['name']
self.update(dict)
##
the record.
"""
recorddict = self.as_dict()
- filteredDict = dict([(key, val) for (key, val) in recorddict.iteritems() if key in self.public.keys()])
+ filteredDict = dict([(key, val) for (key, val) in recorddict.iteritems() if key in self.fields.keys()])
record = RecordSpec()
record.parseDict(filteredDict)
str = record.toxml()
# self.get_gid_object().dump(8, dump_parents)
#print " pointer:", self.pointer
- order = GeniRecord.public.keys()
+ order = GeniRecord.fields.keys()
for key in self.keys():
if key not in order:
order.append(key)
for key in order:
- if key in (self and self.public):
+ if key in self and key in self.fields:
if key in 'gid' and self[key]:
gid = GID(string=self[key])
print " %s:" % key
class UserRecord(GeniRecord):
- public = {
+ fields = {
'email': Parameter(str, 'email'),
'first_name': Parameter(str, 'First name'),
'last_name': Parameter(str, 'Last name'),
'key': Parameter(str, 'Public key'),
'slices': Parameter([str], 'List of slices this user belongs to'),
}
- public.update(GeniRecord.public)
+ fields.update(GeniRecord.fields)
class SliceRecord(GeniRecord):
- public = {
+ 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'),
'description': Parameter([str], 'Description of this slice'),
}
- public.update(GeniRecord.public)
+ fields.update(GeniRecord.fields)
class NodeRecord(GeniRecord):
- public = {
+ fields = {
'hostname': Parameter(str, 'This nodes dns name'),
'node_type': Parameter(str, 'Type of node this is'),
'node_type': Parameter(str, 'Type of node this is'),
'latitude': Parameter(str, 'latitude'),
'longitude': Parameter(str, 'longitude'),
}
- public.update(GeniRecord.public)
+ fields.update(GeniRecord.fields)
class AuthorityRecord(GeniRecord):
- public = {
+ fields = {
'name': Parameter(str, 'Name'),
'login_base': Parameter(str, 'login base'),
'enabled': Parameter(bool, 'Is this site enabled'),
'researcher': Parameter([str], 'List of researchers'),
'PI': Parameter([str], 'List of Principal Investigators'),
}
- public.update(GeniRecord.public)
+ fields.update(GeniRecord.fields)