import types
-from datetime import datetime
# for get_key_from_incoming_ip
import tempfile
import os
if full:
# in full mode we get as much info as we can, which involves contacting the
# testbed for getting implementation details about the record
- for record in local_dicts: logger.info("resolve augment %s"%record)
+ for record in local_dicts: logger.debug("resolve augment %s"%record)
self.driver.augment_records_with_testbed_info(local_dicts)
# # also we fill the 'url' field for known authorities
# # used to be in the driver code, sounds like a poorman thing though
if not api.auth.hierarchy.auth_exists(hrn):
raise MissingAuthority(hrn)
records = dbsession.query(RegRecord).filter_by(authority=hrn)
- record_dicts=[ record.__dict__ for record in records ]
+ record_dicts=[ record.todict() for record in records ]
return record_dicts
raise ExistingRecord(hrn)
assert ('type' in record_dict)
- record = RegRecord("undefined")
- record.set_from_dict(record_dict)
- now=datetime.now()
- record.date_created=now
- record.last_updated=now
+ record = RegRecord(dict=record_dict)
+ record.just_created()
record.authority = get_authority(record.hrn)
auth_info = api.auth.get_auth_info(record.authority)
pub_key = None
def Update(self, api, record_dict):
assert ('type' in record_dict)
- new_record=RegRecord(type="unknown")
- new_record.set_from_dict(record_dict)
+ new_record=RegRecord(dict=record_dict)
type = new_record.type
hrn = new_record.hrn
record = dbsession.query(RegRecord).filter_by(type=type,hrn=hrn).first()
if not record:
raise RecordNotFound(hrn)
- now=datetime.now()
- record.last_updated=now
+ record.just_updated()
# validate the type
# xxx might be simpler to just try to commit as this is a constraint in the db
# expecting an Xrn instance
def Remove(self, api, xrn, origin_hrn=None):
-
- table = SfaTable()
- filter = {'hrn': xrn.get_hrn()}
hrn=xrn.get_hrn()
type=xrn.get_type()
+ request=dbsession.query(RegRecord).filter_by(hrn=hrn)
if type and type not in ['all', '*']:
- filter['type'] = type
+ request=request.filter_by(type=type)
- records = table.find(filter)
- if not records: raise RecordNotFound(hrn)
- record = records[0]
- type = record['type']
-
- if type not in ['slice', 'user', 'node', 'authority'] :
- raise UnknownSfaType(type)
+ record = request.first()
+ if not record:
+ msg="Could not find hrn %s"%hrn
+ if type: msg += " type=%s"%type
+ raise RecordNotFound(msg)
+ type = record.type
credential = api.getCredential()
registries = api.registries
# call testbed callback first
# IIUC this is done on the local testbed TOO because of the refreshpeer link
- if not self.driver.remove(record):
+ if not self.driver.remove(record.__dict__):
logger.warning("driver.remove failed")
# delete from sfa db
- table.remove(record)
+ dbsession.delete(record)
+ dbsession.commit()
return 1
- # This is a PLC-specific thing...
+ # This is a PLC-specific thing, won't work with other platforms
def get_key_from_incoming_ip (self, api):
# verify that the callers's ip address exist in the db and is an interface
# for a node in the db
node = nodes[0]
# look up the sfa record
- table = SfaTable()
- records = table.findObjects({'type': 'node', 'pointer': node['node_id']})
- if not records:
- raise RecordNotFound("pointer:" + str(node['node_id']))
- record = records[0]
+ record=dbsession.query(RegRecord).filter_by(type='node',pointer=node['node_id']).first()
+ if not record:
+ raise RecordNotFound("node with pointer %s"%node['node_id'])
# generate a new keypair and gid
uuid = create_uuid()
pkey = Keypair(create=True)
- urn = hrn_to_urn(record['hrn'], record['type'])
+ urn = hrn_to_urn(record.hrn, record.type)
gid_object = api.auth.hierarchy.create_gid(urn, uuid, pkey)
gid = gid_object.save_to_string(save_parents=True)
- record['gid'] = gid
- record.set_gid(gid)
+ record.gid = gid
# update the record
- table.update(record)
+ dbsession.commit()
# attempt the scp the key
# and gid onto the node