Ejemplo n.º 1
0
def get_instance_objects_sorted(ctx, filters, limit, marker, expected_attrs,
                                sort_keys, sort_dirs):
    """Same as above, but return an InstanceList."""
    query_cell_subset = CONF.api.instance_list_per_project_cells
    # NOTE(danms): Replicated in part from instance_get_all_by_sort_filters(),
    # where if we're not admin we're restricted to our context's project
    if query_cell_subset and not ctx.is_admin:
        # We are not admin, and configured to only query the subset of cells
        # we could possibly have instances in.
        cell_mappings = objects.CellMappingList.get_by_project_id(
            ctx, ctx.project_id)
    else:
        # Either we are admin, or configured to always hit all cells,
        # so don't limit the list to a subset.
        cell_mappings = None
    columns_to_join = instance_obj._expected_cols(expected_attrs)
    instance_generator = get_instances_sorted(ctx, filters, limit, marker,
                                              columns_to_join, sort_keys,
                                              sort_dirs,
                                              cell_mappings=cell_mappings)

    if 'fault' in expected_attrs:
        # We join fault above, so we need to make sure we don't ask
        # make_instance_list to do it again for us
        expected_attrs = copy.copy(expected_attrs)
        expected_attrs.remove('fault')
    return instance_obj._make_instance_list(ctx, objects.InstanceList(),
                                            instance_generator,
                                            expected_attrs)
Ejemplo n.º 2
0
def get_instance_objects_sorted(ctx,
                                filters,
                                limit,
                                marker,
                                expected_attrs,
                                sort_keys,
                                sort_dirs,
                                cell_down_support=False):
    """Return a list of instances and information about down cells.

    This returns a tuple of (objects.InstanceList, list(of down cell
    uuids) for the requested operation. The instances returned are
    those that were collected from the cells that responded. The uuids
    of any cells that did not respond (or raised an error) are included
    in the list as the second element of the tuple. That list is empty
    if all cells responded.
    """
    query_cell_subset = CONF.api.instance_list_per_project_cells
    # NOTE(danms): Replicated in part from instance_get_all_by_sort_filters(),
    # where if we're not admin we're restricted to our context's project
    if query_cell_subset and not ctx.is_admin:
        # We are not admin, and configured to only query the subset of cells
        # we could possibly have instances in.
        cell_mappings = objects.CellMappingList.get_by_project_id(
            ctx, ctx.project_id)
    else:
        # Either we are admin, or configured to always hit all cells,
        # so don't limit the list to a subset.
        context.load_cells()
        cell_mappings = context.CELLS

    batch_size = get_instance_list_cells_batch_size(limit, cell_mappings)

    columns_to_join = instance_obj._expected_cols(expected_attrs)
    instance_lister, instance_generator = get_instances_sorted(
        ctx,
        filters,
        limit,
        marker,
        columns_to_join,
        sort_keys,
        sort_dirs,
        cell_mappings=cell_mappings,
        batch_size=batch_size,
        cell_down_support=cell_down_support)

    if 'fault' in expected_attrs:
        # We join fault above, so we need to make sure we don't ask
        # make_instance_list to do it again for us
        expected_attrs = copy.copy(expected_attrs)
        expected_attrs.remove('fault')

    instance_list = instance_obj._make_instance_list(ctx,
                                                     objects.InstanceList(),
                                                     instance_generator,
                                                     expected_attrs)
    down_cell_uuids = (instance_lister.cells_failed +
                       instance_lister.cells_timed_out)
    return instance_list, down_cell_uuids
Ejemplo n.º 3
0
def get_instance_objects_sorted(ctx, filters, limit, marker, expected_attrs,
                                sort_keys, sort_dirs):
    """Same as above, but return an InstanceList."""
    columns_to_join = instance_obj._expected_cols(expected_attrs)
    instance_generator = get_instances_sorted(ctx, filters, limit, marker,
                                              columns_to_join, sort_keys,
                                              sort_dirs)
    if 'fault' in expected_attrs:
        # We join fault above, so we need to make sure we don't ask
        # make_instance_list to do it again for us
        expected_attrs = copy.copy(expected_attrs)
        expected_attrs.remove('fault')
    return instance_obj._make_instance_list(ctx, objects.InstanceList(),
                                            instance_generator, expected_attrs)
Ejemplo n.º 4
0
def get_instance_objects_sorted(ctx, filters, limit, marker, expected_attrs,
                                sort_keys, sort_dirs):
    """Return a list of instances and information about down cells.

    This returns a tuple of (objects.InstanceList, list(of down cell
    uuids) for the requested operation. The instances returned are
    those that were collected from the cells that responded. The uuids
    of any cells that did not respond (or raised an error) are included
    in the list as the second element of the tuple. That list is empty
    if all cells responded.
    """
    query_cell_subset = CONF.api.instance_list_per_project_cells
    # NOTE(danms): Replicated in part from instance_get_all_by_sort_filters(),
    # where if we're not admin we're restricted to our context's project
    if query_cell_subset and not ctx.is_admin:
        # We are not admin, and configured to only query the subset of cells
        # we could possibly have instances in.
        cell_mappings = objects.CellMappingList.get_by_project_id(
            ctx, ctx.project_id)
    else:
        # Either we are admin, or configured to always hit all cells,
        # so don't limit the list to a subset.
        context.load_cells()
        cell_mappings = context.CELLS

    batch_size = get_instance_list_cells_batch_size(limit, cell_mappings)

    columns_to_join = instance_obj._expected_cols(expected_attrs)
    instance_lister, instance_generator = get_instances_sorted(ctx, filters,
        limit, marker, columns_to_join, sort_keys, sort_dirs,
        cell_mappings=cell_mappings, batch_size=batch_size)

    if 'fault' in expected_attrs:
        # We join fault above, so we need to make sure we don't ask
        # make_instance_list to do it again for us
        expected_attrs = copy.copy(expected_attrs)
        expected_attrs.remove('fault')

    instance_list = instance_obj._make_instance_list(ctx,
        objects.InstanceList(), instance_generator, expected_attrs)
    down_cell_uuids = (instance_lister.cells_failed +
                       instance_lister.cells_timed_out)
    return instance_list, down_cell_uuids
Ejemplo n.º 5
0
 def __get_active_by_window_joined(
     self,
     context,
     begin, end=None,
     project_id=None,
     host=None,
     expected_attrs=None,
     use_slave=False,
     metadata=None
 ):
     """Second to bottom most database layer"""
     # NOTE(mriedem): We need to convert the begin/end timestamp strings
     # to timezone-aware datetime objects for the DB API call.
     begin = timeutils.parse_isotime(begin)
     end = timeutils.parse_isotime(end) if end else None
     db_inst_list = instance_get_active_by_window_joined(
         context, begin, end, project_id, host,
         columns_to_join=_expected_cols(expected_attrs), metadata=metadata)
     return db_inst_list
Ejemplo n.º 6
0
 def test_expected_cols(self):
     self.stubs.Set(instance, '_INSTANCE_OPTIONAL_JOINED_FIELDS', ['bar'])
     self.assertEqual(['bar'], instance._expected_cols(['foo', 'bar']))
     self.assertIsNone(instance._expected_cols(None))
Ejemplo n.º 7
0
 def test_expected_cols(self):
     self.stubs.Set(instance, '_INSTANCE_OPTIONAL_JOINED_FIELDS', ['bar'])
     self.assertEqual(['bar'], instance._expected_cols(['foo', 'bar']))
     self.assertIsNone(instance._expected_cols(None))
Ejemplo n.º 8
0
 def test_expected_cols(self):
     self.stubs.Set(instance, "_INSTANCE_OPTIONAL_JOINED_FIELDS", ["bar"])
     self.assertEqual(["bar"], instance._expected_cols(["foo", "bar"]))
     self.assertEqual(None, instance._expected_cols(None))