def get_by_filters(cls, context, filters, sort_key='created_at', sort_dir='desc', limit=None, marker=None, expected_attrs=None, use_slave=False, sort_keys=None, sort_dirs=None): if sort_keys or sort_dirs: db_inst_list = db.instance_get_all_by_filters_sort( context, filters, limit=limit, marker=marker, columns_to_join=_expected_cols(expected_attrs), use_slave=use_slave, sort_keys=sort_keys, sort_dirs=sort_dirs) else: db_inst_list = db.instance_get_all_by_filters( context, filters, sort_key, sort_dir, limit=limit, marker=marker, columns_to_join=_expected_cols(expected_attrs), use_slave=use_slave) return _make_instance_list(context, cls(), db_inst_list, expected_attrs)
def get_by_filters(self, ctx, filters, limit, marker, **kwargs): return db.instance_get_all_by_filters_sort( ctx, filters, limit=limit, marker=marker, sort_keys=self.sort_ctx.sort_keys, sort_dirs=self.sort_ctx.sort_dirs, **kwargs)
def _get_by_filters_impl(cls, context, filters, sort_key='created_at', sort_dir='desc', limit=None, marker=None, expected_attrs=None, use_slave=False, sort_keys=None, sort_dirs=None): if sort_keys or sort_dirs: db_inst_list = db.instance_get_all_by_filters_sort( context, filters, limit=limit, marker=marker, columns_to_join=_expected_cols(expected_attrs), sort_keys=sort_keys, sort_dirs=sort_dirs) else: db_inst_list = db.instance_get_all_by_filters( context, filters, sort_key, sort_dir, limit=limit, marker=marker, columns_to_join=_expected_cols(expected_attrs)) return _make_instance_list(context, cls(), db_inst_list, expected_attrs)
def do_query(ctx): """Generate InstanceWrapper(Instance) objects from a cell. We do this inside the thread (created by scatter_gather_all_cells()) so that we return wrappers and avoid having to iterate the combined result list in the caller again. This is run against each cell by the scatter_gather routine. """ # The local marker is a uuid of an instance in a cell that is found # by the special method instance_get_by_sort_filters(). It should # be the next instance in order according to the sort provided, # but after the marker instance which may have been in another cell. local_marker = None # Since the regular DB query routines take a marker and assume that # the marked instance was the last entry of the previous page, we # may need to prefix it to our result query if we're not the cell # that had the actual marker instance. local_marker_prefix = [] if marker: # FIXME(danms): If we knew which cell we were in here, we could # avoid looking up the marker again. But, we don't currently. local_marker = db.instance_get_by_sort_filters( ctx, sort_keys, sort_dirs, global_marker_values) if local_marker: if local_marker != marker: # We did find a marker in our cell, but it wasn't # the global marker. Thus, we will use it as our # marker in the main query below, but we also need # to prefix that result with this marker instance # since the result below will not return it and it # has not been returned to the user yet. Note that # we do _not_ prefix the marker instance if our # marker was the global one since that has already # been sent to the user. local_marker_filters = copy.copy(filters) if 'uuid' not in local_marker_filters: # If a uuid filter was provided, it will # have included our marker already if this instance # is desired in the output set. If it wasn't, we # specifically query for it. If the other filters would # have excluded it, then we'll get an empty set here # and not include it in the output as expected. local_marker_filters['uuid'] = [local_marker] local_marker_prefix = db.instance_get_all_by_filters_sort( ctx, local_marker_filters, limit=1, marker=None, columns_to_join=columns_to_join, sort_keys=sort_keys, sort_dirs=sort_dirs) else: # There was a global marker but everything in our cell is # _before_ that marker, so we return nothing. If we didn't # have this clause, we'd pass marker=None to the query below # and return a full unpaginated set for our cell. return [] main_query_result = db.instance_get_all_by_filters_sort( ctx, filters, limit=limit, marker=local_marker, columns_to_join=columns_to_join, sort_keys=sort_keys, sort_dirs=sort_dirs) return (InstanceWrapper(sort_ctx, inst) for inst in itertools.chain( local_marker_prefix, main_query_result))