- record.set_gid(gid.save_to_string(save_parents=True))
- pl_record = api.driver.sfa_fields_to_pl_fields(type, hrn, record)
- sites = api.driver.GetSites([pl_record['login_base']])
- if not sites:
- pointer = api.driver.AddSite(pl_record)
- else:
- pointer = sites[0]['site_id']
-
- record.set_pointer(pointer)
- record['pointer'] = pointer
-
- elif (type == "slice"):
- acceptable_fields=['url', 'instantiation', 'name', 'description']
- pl_record = api.driver.sfa_fields_to_pl_fields(type, hrn, record)
- for key in pl_record.keys():
- if key not in acceptable_fields:
- pl_record.pop(key)
- slices = api.driver.GetSlices([pl_record['name']])
- if not slices:
- pointer = api.driver.AddSlice(pl_record)
- else:
- pointer = slices[0]['slice_id']
- record.set_pointer(pointer)
- record['pointer'] = pointer
-
- elif (type == "user"):
- persons = api.driver.GetPersons([record['email']])
- if not persons:
- pointer = api.driver.AddPerson(dict(record))
- else:
- pointer = persons[0]['person_id']
-
- if 'enabled' in record and record['enabled']:
- api.driver.UpdatePerson(pointer, {'enabled': record['enabled']})
- # add this persons to the site only if he is being added for the first
- # time by sfa and doesont already exist in plc
- if not persons or not persons[0]['site_ids']:
- login_base = get_leaf(record['authority'])
- api.driver.AddPersonToSite(pointer, login_base)
-
- # What roles should this user have?
- api.driver.AddRoleToPerson('user', pointer)
- # Add the user's key
- if pub_key:
- api.driver.AddPersonKey(pointer, {'key_type' : 'ssh', 'key' : pub_key})
-
- elif (type == "node"):
- pl_record = api.driver.sfa_fields_to_pl_fields(type, hrn, record)
- login_base = hrn_to_pl_login_base(record['authority'])
- nodes = api.driver.GetNodes([pl_record['hostname']])
- if not nodes:
- pointer = api.driver.AddNode(login_base, pl_record)
- else:
- pointer = nodes[0]['node_id']
-
- record['pointer'] = pointer
- record.set_pointer(pointer)
- record_id = table.insert(record)
- record['record_id'] = record_id
+ record.gid=gid.save_to_string(save_parents=True)
+
+ elif isinstance (record, RegSlice):
+ # locate objects for relationships
+ if hasattr (record, 'researcher'):
+ # we get the list of researcher hrns as
+ researcher_hrns = record.researcher
+ # strip that in case we have <researcher> words </researcher>
+ researcher_hrns = [ x.strip() for x in researcher_hrns ]
+ logger.info ("incoming researchers %s"%researcher_hrns)
+ request = dbsession.query (RegUser).filter(RegUser.hrn.in_(researcher_hrns))
+ logger.info ("%d incoming hrns, %d matches found"%(len(researcher_hrns),request.count()))
+ researchers = dbsession.query (RegUser).filter(RegUser.hrn.in_(researcher_hrns)).all()
+ record.reg_researchers = researchers
+
+ elif isinstance (record, RegUser):
+ # create RegKey objects for incoming keys
+ if hasattr(record,'keys'):
+ logger.debug ("creating %d keys for user %s"%(len(record.keys),record.hrn))
+ record.reg_keys = [ RegKey (key) for key in record.keys ]
+
+ # update testbed-specific data if needed
+ pointer = self.driver.register (record.__dict__, hrn, pub_key)
+
+ record.pointer=pointer
+ dbsession.add(record)
+ dbsession.commit()