Simple tenant usage pagination

Add optional parameters 'limit' and 'marker' to the
os-simple-tenant-usage endpoints for pagaination.

  /os-simple-tenant-usage?limit={limit}&marker={instance_uuid}
  /os-simple-tenant-usage/{tenant}?limit={limit}&marker={instance_uuid}

The aggregate usage totals may no longer reflect all instances for a
tenant, but rather just the instances for a given page. API consumers
will need to stitch the aggregate data back together (add the totals)
if a tenant's instances span several pages.

Implements blueprint paginate-simple-tenant-usage
Change-Id: Ic8e9f869f1b855f968967bedbf77542f287f26c0
This commit is contained in:
Diana Clarke 2016-10-13 13:07:36 -04:00
parent 0280b36666
commit 2623fe2427
2 changed files with 16 additions and 3 deletions

View File

@ -765,7 +765,8 @@ def instance_get_all_by_filters_sort(context, filters, limit=None,
def instance_get_active_by_window_joined(context, begin, end=None,
project_id=None, host=None,
columns_to_join=None):
columns_to_join=None, limit=None,
marker=None):
"""Get instances and joins active during a certain time window.
Specifying a project_id will filter for a certain project.
@ -773,7 +774,8 @@ def instance_get_active_by_window_joined(context, begin, end=None,
"""
return IMPL.instance_get_active_by_window_joined(context, begin, end,
project_id, host,
columns_to_join=columns_to_join)
columns_to_join=columns_to_join,
limit=limit, marker=marker)
def instance_get_all_by_host(context, host, columns_to_join=None):

View File

@ -2513,7 +2513,8 @@ def process_sort_params(sort_keys, sort_dirs,
@pick_context_manager_reader_allow_async
def instance_get_active_by_window_joined(context, begin, end=None,
project_id=None, host=None,
columns_to_join=None):
columns_to_join=None, limit=None,
marker=None):
"""Return instances and joins that were active during window."""
query = context.session.query(models.Instance)
@ -2539,6 +2540,16 @@ def instance_get_active_by_window_joined(context, begin, end=None,
if host:
query = query.filter_by(host=host)
if marker is not None:
try:
marker = _instance_get_by_uuid(
context.elevated(read_deleted='yes'), marker)
except exception.InstanceNotFound:
raise exception.MarkerNotFound(marker=marker)
query = sqlalchemyutils.paginate_query(
query, models.Instance, limit, ['project_id', 'uuid'], marker=marker)
return _instances_fill_metadata(context, query.all(), manual_joins)