Implement blueprint ec2-id-compatibilty.
Instance ids are used by the ec2 layer to create ec2-ids. This currently uses the id column in the instances table. This patch creates a new mapping table for ec2-ids. This decouples the ec2 layer from needing direct access to the instances table so that it can eventually be pulled out if necessary. It also matches the way that the ec2 layer maps image, volume, and snaphsot ids. Finally, it allows us to eventually remove the id column from the instances table and only have one canonical id (uuid) to refer to instances. Change-Id: I02ad9fad37e6a04675543398f686351634bc1bb9
This commit is contained in:
parent
b0f674fe9e
commit
47da6647da
@ -1930,3 +1930,21 @@ def instance_fault_create(context, values):
|
||||
def instance_fault_get_by_instance_uuids(context, instance_uuids):
|
||||
"""Get all instance faults for the provided instance_uuids."""
|
||||
return IMPL.instance_fault_get_by_instance_uuids(context, instance_uuids)
|
||||
|
||||
|
||||
####################
|
||||
|
||||
|
||||
def get_ec2_instance_id_by_uuid(context, instance_id):
|
||||
"""Get ec2 id through uuid from instance_id_mappings table"""
|
||||
return IMPL.get_ec2_instance_id_by_uuid(context, instance_id)
|
||||
|
||||
|
||||
def get_instance_uuid_by_ec2_id(context, instance_id):
|
||||
"""Get uuid through ec2 id from instance_id_mappings table"""
|
||||
return IMPL.get_instance_uuid_by_ec2_id(context, instance_id)
|
||||
|
||||
|
||||
def ec2_instance_create(context, instance_ec2_id):
|
||||
"""Create the ec2 id to instance uuid mapping on demand"""
|
||||
return IMPL.ec2_instance_create(context, instance_ec2_id)
|
||||
|
@ -1367,6 +1367,9 @@ def instance_create(context, values):
|
||||
# exists in the ref when we return. Fixes lazy loading issues.
|
||||
instance_ref.instance_type
|
||||
|
||||
# create the instance uuid to ec2_id mapping entry for instance
|
||||
ec2_instance_create(context, instance_ref['uuid'])
|
||||
|
||||
return instance_ref
|
||||
|
||||
|
||||
@ -5163,3 +5166,50 @@ def instance_fault_get_by_instance_uuids(context, instance_uuids):
|
||||
output[row['instance_uuid']].append(data)
|
||||
|
||||
return output
|
||||
|
||||
|
||||
##################
|
||||
|
||||
|
||||
@require_context
|
||||
def ec2_instance_create(context, instance_uuid, id=None):
|
||||
"""Create ec2 compatable instance by provided uuid"""
|
||||
ec2_instance_ref = models.InstanceIdMapping()
|
||||
ec2_instance_ref.update({'uuid': instance_uuid})
|
||||
if id is not None:
|
||||
ec2_instance_ref.update({'id': id})
|
||||
|
||||
ec2_instance_ref.save()
|
||||
|
||||
return ec2_instance_ref
|
||||
|
||||
|
||||
@require_context
|
||||
def get_ec2_instance_id_by_uuid(context, instance_id, session=None):
|
||||
result = _ec2_instance_get_query(context,
|
||||
session=session).\
|
||||
filter_by(uuid=instance_id).\
|
||||
first()
|
||||
|
||||
if not result:
|
||||
raise exception.InstanceNotFound(uuid=instance_id)
|
||||
|
||||
return result['id']
|
||||
|
||||
|
||||
@require_context
|
||||
def get_instance_uuid_by_ec2_id(context, instance_id, session=None):
|
||||
result = _ec2_instance_get_query(context,
|
||||
session=session).\
|
||||
filter_by(id=instance_id).\
|
||||
first()
|
||||
|
||||
if not result:
|
||||
raise exception.InstanceNotFound(id=instance_id)
|
||||
|
||||
return result['uuid']
|
||||
|
||||
|
||||
@require_context
|
||||
def _ec2_instance_get_query(context, session=None):
|
||||
return model_query(context, models.InstanceIdMapping, session=session)
|
||||
|
Loading…
x
Reference in New Issue
Block a user