'Helper method for pulling an instance object from a database.
During the transition to cellsv2 there is some complexity around
retrieving an instance from the database which this method hides. If
there is an instance mapping then query the cell for the instance, if
no mapping exists then query the configured nova database.
Once we are past the point that all deployments can be assumed to be
migrated to cellsv2 this method can go away.'

def _lookup_instance(self, context, uuid):

    inst_map = None
    try:
        inst_map = objects.InstanceMapping.get_by_instance_uuid(context, uuid)
    except exception.InstanceMappingNotFound:
        pass
    if ((inst_map is None) or (inst_map.cell_mapping is None) or CONF.cells.enable):
        cell = None
        try:
            instance = objects.Instance.get_by_uuid(context, uuid)
        except exception.InstanceNotFound:
            return (None, None)
    else:
        cell = inst_map.cell_mapping
        with nova_context.target_cell(context, cell) as cctxt:
            try:
                instance = objects.Instance.get_by_uuid(cctxt, uuid)
            except exception.InstanceNotFound:
                return (None, None)
    return (cell, instance)
