def Update(self, api, record_dict): logger.debug("Update: entering with record_dict=%s"%printable(record_dict)) normalize_input_record (record_dict) logger.debug("Update: normalized record_dict=%s"%printable(record_dict)) dbsession=api.dbsession() assert ('type' in record_dict) new_record=make_record(dict=record_dict) (type,hrn) = (new_record.type, new_record.hrn) # make sure the record exists record = dbsession.query(RegRecord).filter_by(type=type,hrn=hrn).first() if not record: raise RecordNotFound("hrn=%s, type=%s"%(hrn,type)) record.just_updated() # Use the pointer from the existing record, not the one that the user # gave us. This prevents the user from inserting a forged pointer pointer = record.pointer # is there a change in keys ? new_key=None if type=='user': if getattr(new_record,'keys',None): new_key=new_record.keys if isinstance (new_key,types.ListType): new_key=new_key[0] # take new_key into account if new_key: # update the openssl key and gid pkey = convert_public_key(new_key) uuid = create_uuid() urn = hrn_to_urn(hrn,type) email=getattr(new_record,'email',None) if email is None: email=getattr(record,'email',None) gid_object = api.auth.hierarchy.create_gid(urn, uuid, pkey, email = email) gid = gid_object.save_to_string(save_parents=True) # xxx should do side effects from new_record to record # not too sure how to do that # not too big a deal with planetlab as the driver is authoritative, but... # update native relations if isinstance (record, RegSlice): researcher_hrns = getattr(new_record,'reg-researchers',None) if researcher_hrns is not None: record.update_researchers (researcher_hrns, dbsession) elif isinstance (record, RegAuthority): pi_hrns = getattr(new_record,'reg-pis',None) if pi_hrns is not None: record.update_pis (pi_hrns, dbsession) # update the PLC information that was specified with the record # xxx oddly enough, without this useless statement, # record.__dict__ as received by the driver seems to be off # anyway the driver should receive an object # (and then extract __dict__ itself if needed) print "DO NOT REMOVE ME before driver.update, record=%s"%record new_key_pointer = -1 try: (pointer, new_key_pointer) = api.driver.update (record.__dict__, new_record.__dict__, hrn, new_key) except: pass if new_key and new_key_pointer: record.reg_keys=[ RegKey (new_key, new_key_pointer)] record.gid = gid dbsession.commit() # update membership for researchers, pis, owners, operators self.update_driver_relations (api, record, new_record) return 1
def Update(self, api, record_dict): dbsession = api.dbsession() assert ('type' in record_dict) new_record = make_record(dict=record_dict) (type, hrn) = (new_record.type, new_record.hrn) # make sure the record exists record = dbsession.query(RegRecord).filter_by(type=type, hrn=hrn).first() if not record: raise RecordNotFound("hrn=%s, type=%s" % (hrn, type)) record.just_updated() # Use the pointer from the existing record, not the one that the user # gave us. This prevents the user from inserting a forged pointer pointer = record.pointer # is there a change in keys ? new_key = None if type == 'user': if getattr(new_record, 'keys', None): new_key = new_record.keys if isinstance(new_key, types.ListType): new_key = new_key[0] # take new_key into account if new_key: # update the openssl key and gid pkey = convert_public_key(new_key) uuid = create_uuid() urn = hrn_to_urn(hrn, type) gid_object = api.auth.hierarchy.create_gid(urn, uuid, pkey) gid = gid_object.save_to_string(save_parents=True) # xxx should do side effects from new_record to record # not too sure how to do that # not too big a deal with planetlab as the driver is authoritative, but... # update native relations if isinstance(record, RegSlice): researcher_hrns = getattr(new_record, 'researcher', None) if researcher_hrns is not None: record.update_researchers(researcher_hrns, dbsession) elif isinstance(record, RegAuthority): pi_hrns = getattr(new_record, 'pi', None) if pi_hrns is not None: record.update_pis(pi_hrns, dbsession) # update the PLC information that was specified with the record # xxx oddly enough, without this useless statement, # record.__dict__ as received by the driver seems to be off # anyway the driver should receive an object # (and then extract __dict__ itself if needed) print "DO NOT REMOVE ME before driver.update, record=%s" % record new_key_pointer = -1 try: (pointer, new_key_pointer) = api.driver.update(record.__dict__, new_record.__dict__, hrn, new_key) except: pass if new_key and new_key_pointer: record.reg_keys = [RegKey(new_key, new_key_pointer)] record.gid = gid dbsession.commit() # update membership for researchers, pis, owners, operators self.update_driver_relations(api, record, new_record) return 1
def Register(self, api, record_dict): logger.debug("Register: entering with record_dict=%s"%printable(record_dict)) normalize_input_record (record_dict) logger.debug("Register: normalized record_dict=%s"%printable(record_dict)) dbsession=api.dbsession() hrn, type = record_dict['hrn'], record_dict['type'] urn = hrn_to_urn(hrn,type) # validate the type if type not in ['authority', 'slice', 'node', 'user']: raise UnknownSfaType(type) # check if record_dict already exists existing_records = dbsession.query(RegRecord).filter_by(type=type,hrn=hrn).all() if existing_records: raise ExistingRecord(hrn) assert ('type' in record_dict) # returns the right type of RegRecord according to type in record record = make_record(dict=record_dict) record.just_created() record.authority = get_authority(record.hrn) auth_info = api.auth.get_auth_info(record.authority) pub_key = None # make sure record has a gid if not record.gid: uuid = create_uuid() pkey = Keypair(create=True) pub_key=getattr(record,'reg-keys',None) if pub_key is not None: # use only first key in record if pub_key and isinstance(pub_key, types.ListType): pub_key = pub_key[0] pkey = convert_public_key(pub_key) email=getattr(record,'email',None) gid_object = api.auth.hierarchy.create_gid(urn, uuid, pkey, email = email) gid = gid_object.save_to_string(save_parents=True) record.gid = gid if isinstance (record, RegAuthority): # update the tree if not api.auth.hierarchy.auth_exists(hrn): api.auth.hierarchy.create_auth(hrn_to_urn(hrn,'authority')) # get the GID from the newly created authority auth_info = api.auth.get_auth_info(hrn) gid = auth_info.get_gid_object() record.gid=gid.save_to_string(save_parents=True) # locate objects for relationships pi_hrns = getattr(record,'reg-pis',None) if pi_hrns is not None: record.update_pis (pi_hrns, dbsession) elif isinstance (record, RegSlice): researcher_hrns = getattr(record,'reg-researchers',None) if researcher_hrns is not None: record.update_researchers (researcher_hrns, dbsession) elif isinstance (record, RegUser): # create RegKey objects for incoming keys if hasattr(record,'reg-keys'): keys=getattr(record,'reg-keys') # some people send the key as a string instead of a list of strings if isinstance(keys,types.StringTypes): keys=[keys] logger.debug ("creating %d keys for user %s"%(len(keys),record.hrn)) record.reg_keys = [ RegKey (key) for key in keys ] # update testbed-specific data if needed pointer = api.driver.register (record.__dict__, hrn, pub_key) record.pointer=pointer dbsession.add(record) dbsession.commit() # update membership for researchers, pis, owners, operators self.update_driver_relations (api, record, record) return record.get_gid_object().save_to_string(save_parents=True)
def Register(self, api, record_dict): dbsession = api.dbsession() hrn, type = record_dict['hrn'], record_dict['type'] urn = hrn_to_urn(hrn, type) # validate the type if type not in ['authority', 'slice', 'node', 'user']: raise UnknownSfaType(type) # check if record_dict already exists existing_records = dbsession.query(RegRecord).filter_by(type=type, hrn=hrn).all() if existing_records: raise ExistingRecord(hrn) assert ('type' in record_dict) # returns the right type of RegRecord according to type in record record = make_record(dict=record_dict) record.just_created() record.authority = get_authority(record.hrn) auth_info = api.auth.get_auth_info(record.authority) pub_key = None # make sure record has a gid if not record.gid: uuid = create_uuid() pkey = Keypair(create=True) if getattr(record, 'keys', None): pub_key = record.keys # use only first key in record if isinstance(record.keys, types.ListType): pub_key = record.keys[0] pkey = convert_public_key(pub_key) gid_object = api.auth.hierarchy.create_gid(urn, uuid, pkey) gid = gid_object.save_to_string(save_parents=True) record.gid = gid if isinstance(record, RegAuthority): # update the tree if not api.auth.hierarchy.auth_exists(hrn): api.auth.hierarchy.create_auth(hrn_to_urn(hrn, 'authority')) # get the GID from the newly created authority auth_info = api.auth.get_auth_info(hrn) gid = auth_info.get_gid_object() record.gid = gid.save_to_string(save_parents=True) # locate objects for relationships pi_hrns = getattr(record, 'pi', None) if pi_hrns is not None: record.update_pis(pi_hrns, dbsession) elif isinstance(record, RegSlice): researcher_hrns = getattr(record, 'researcher', None) if researcher_hrns is not None: record.update_researchers(researcher_hrns, dbsession) 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 = api.driver.register(record.__dict__, hrn, pub_key) record.pointer = pointer dbsession.add(record) dbsession.commit() # update membership for researchers, pis, owners, operators self.update_driver_relations(api, record, record) return record.get_gid_object().save_to_string(save_parents=True)