enginefacade: 'dnsdomain' and 'ec2'
Use enginefacade in 'dnsdomain' and 'ec2' sections. Implements: blueprint new-oslodb-enginefacade Co-Authored-By: Sergey Nikitin <snikitin@mirantis.com> Change-Id: I0d754947ed0c34fe0ea997f039a8d6c19052007f
This commit is contained in:
@@ -1026,23 +1026,20 @@ def floating_ip_update(context, address, values):
|
||||
return float_ip_ref
|
||||
|
||||
|
||||
def _dnsdomain_get(context, session, fqdomain):
|
||||
return model_query(context, models.DNSDomain,
|
||||
session=session, read_deleted="no").\
|
||||
###################
|
||||
|
||||
|
||||
@require_context
|
||||
@main_context_manager.reader
|
||||
def dnsdomain_get(context, fqdomain):
|
||||
return model_query(context, models.DNSDomain, read_deleted="no").\
|
||||
filter_by(domain=fqdomain).\
|
||||
with_lockmode('update').\
|
||||
first()
|
||||
|
||||
|
||||
@require_context
|
||||
def dnsdomain_get(context, fqdomain):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
return _dnsdomain_get(context, session, fqdomain)
|
||||
|
||||
|
||||
def _dnsdomain_get_or_create(context, session, fqdomain):
|
||||
domain_ref = _dnsdomain_get(context, session, fqdomain)
|
||||
def _dnsdomain_get_or_create(context, fqdomain):
|
||||
domain_ref = dnsdomain_get(context, fqdomain)
|
||||
if not domain_ref:
|
||||
dns_ref = models.DNSDomain()
|
||||
dns_ref.update({'domain': fqdomain,
|
||||
@@ -1053,30 +1050,30 @@ def _dnsdomain_get_or_create(context, session, fqdomain):
|
||||
return domain_ref
|
||||
|
||||
|
||||
@main_context_manager.writer
|
||||
def dnsdomain_register_for_zone(context, fqdomain, zone):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
domain_ref = _dnsdomain_get_or_create(context, session, fqdomain)
|
||||
domain_ref.scope = 'private'
|
||||
domain_ref.availability_zone = zone
|
||||
session.add(domain_ref)
|
||||
domain_ref = _dnsdomain_get_or_create(context, fqdomain)
|
||||
domain_ref.scope = 'private'
|
||||
domain_ref.availability_zone = zone
|
||||
context.session.add(domain_ref)
|
||||
|
||||
|
||||
@main_context_manager.writer
|
||||
def dnsdomain_register_for_project(context, fqdomain, project):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
domain_ref = _dnsdomain_get_or_create(context, session, fqdomain)
|
||||
domain_ref.scope = 'public'
|
||||
domain_ref.project_id = project
|
||||
session.add(domain_ref)
|
||||
domain_ref = _dnsdomain_get_or_create(context, fqdomain)
|
||||
domain_ref.scope = 'public'
|
||||
domain_ref.project_id = project
|
||||
context.session.add(domain_ref)
|
||||
|
||||
|
||||
@main_context_manager.writer
|
||||
def dnsdomain_unregister(context, fqdomain):
|
||||
model_query(context, models.DNSDomain).\
|
||||
filter_by(domain=fqdomain).\
|
||||
delete()
|
||||
|
||||
|
||||
@main_context_manager.reader
|
||||
def dnsdomain_get_all(context):
|
||||
return model_query(context, models.DNSDomain, read_deleted="no").all()
|
||||
|
||||
@@ -3779,17 +3776,16 @@ def reservation_expire(context):
|
||||
###################
|
||||
|
||||
|
||||
def _ec2_volume_get_query(context, session=None):
|
||||
return model_query(context, models.VolumeIdMapping,
|
||||
session=session, read_deleted='yes')
|
||||
def _ec2_volume_get_query(context):
|
||||
return model_query(context, models.VolumeIdMapping, read_deleted='yes')
|
||||
|
||||
|
||||
def _ec2_snapshot_get_query(context, session=None):
|
||||
return model_query(context, models.SnapshotIdMapping,
|
||||
session=session, read_deleted='yes')
|
||||
def _ec2_snapshot_get_query(context):
|
||||
return model_query(context, models.SnapshotIdMapping, read_deleted='yes')
|
||||
|
||||
|
||||
@require_context
|
||||
@main_context_manager.writer
|
||||
def ec2_volume_create(context, volume_uuid, id=None):
|
||||
"""Create ec2 compatible volume by provided uuid."""
|
||||
ec2_volume_ref = models.VolumeIdMapping()
|
||||
@@ -3797,12 +3793,13 @@ def ec2_volume_create(context, volume_uuid, id=None):
|
||||
if id is not None:
|
||||
ec2_volume_ref.update({'id': id})
|
||||
|
||||
ec2_volume_ref.save()
|
||||
ec2_volume_ref.save(context.session)
|
||||
|
||||
return ec2_volume_ref
|
||||
|
||||
|
||||
@require_context
|
||||
@main_context_manager.reader
|
||||
def ec2_volume_get_by_uuid(context, volume_uuid):
|
||||
result = _ec2_volume_get_query(context).\
|
||||
filter_by(uuid=volume_uuid).\
|
||||
@@ -3815,6 +3812,7 @@ def ec2_volume_get_by_uuid(context, volume_uuid):
|
||||
|
||||
|
||||
@require_context
|
||||
@main_context_manager.reader
|
||||
def ec2_volume_get_by_id(context, volume_id):
|
||||
result = _ec2_volume_get_query(context).\
|
||||
filter_by(id=volume_id).\
|
||||
@@ -3827,6 +3825,7 @@ def ec2_volume_get_by_id(context, volume_id):
|
||||
|
||||
|
||||
@require_context
|
||||
@main_context_manager.writer
|
||||
def ec2_snapshot_create(context, snapshot_uuid, id=None):
|
||||
"""Create ec2 compatible snapshot by provided uuid."""
|
||||
ec2_snapshot_ref = models.SnapshotIdMapping()
|
||||
@@ -3834,12 +3833,13 @@ def ec2_snapshot_create(context, snapshot_uuid, id=None):
|
||||
if id is not None:
|
||||
ec2_snapshot_ref.update({'id': id})
|
||||
|
||||
ec2_snapshot_ref.save()
|
||||
ec2_snapshot_ref.save(context.session)
|
||||
|
||||
return ec2_snapshot_ref
|
||||
|
||||
|
||||
@require_context
|
||||
@main_context_manager.reader
|
||||
def ec2_snapshot_get_by_ec2_id(context, ec2_id):
|
||||
result = _ec2_snapshot_get_query(context).\
|
||||
filter_by(id=ec2_id).\
|
||||
@@ -3852,6 +3852,7 @@ def ec2_snapshot_get_by_ec2_id(context, ec2_id):
|
||||
|
||||
|
||||
@require_context
|
||||
@main_context_manager.reader
|
||||
def ec2_snapshot_get_by_uuid(context, snapshot_uuid):
|
||||
result = _ec2_snapshot_get_query(context).\
|
||||
filter_by(uuid=snapshot_uuid).\
|
||||
|
Reference in New Issue
Block a user