Merge "Refactor volumes summary"
This commit is contained in:
commit
867cc254ce
@ -296,14 +296,9 @@ def volume_get_all_by_project(context, project_id, marker, limit,
|
||||
offset=offset)
|
||||
|
||||
|
||||
def get_volume_summary_all(context):
|
||||
"""Get all volume summary."""
|
||||
return IMPL.get_volume_summary_all(context)
|
||||
|
||||
|
||||
def get_volume_summary_by_project(context, project_id):
|
||||
"""Get all volume summary belonging to a project."""
|
||||
return IMPL.get_volume_summary_by_project(context, project_id)
|
||||
def get_volume_summary(context, project_only):
|
||||
"""Get volume summary."""
|
||||
return IMPL.get_volume_summary(context, project_only)
|
||||
|
||||
|
||||
def volume_update(context, volume_id, values):
|
||||
|
@ -2036,15 +2036,19 @@ def volume_get_all(context, marker=None, limit=None, sort_keys=None,
|
||||
return query.all()
|
||||
|
||||
|
||||
@require_admin_context
|
||||
def get_volume_summary_all(context):
|
||||
@require_context
|
||||
def get_volume_summary(context, project_only):
|
||||
"""Retrieves all volumes summary.
|
||||
|
||||
:param context: context to query under
|
||||
:returns: volume summary of all projects
|
||||
:param project_only: limit summary to project volumes
|
||||
:returns: volume summary
|
||||
"""
|
||||
if not (project_only or is_admin_context(context)):
|
||||
raise exception.AdminRequired()
|
||||
query = model_query(context, func.count(models.Volume.id),
|
||||
func.sum(models.Volume.size), read_deleted="no")
|
||||
func.sum(models.Volume.size), read_deleted="no",
|
||||
project_only=project_only)
|
||||
|
||||
if query is None:
|
||||
return []
|
||||
@ -2385,25 +2389,6 @@ def process_sort_params(sort_keys, sort_dirs, default_keys=None,
|
||||
return result_keys, result_dirs
|
||||
|
||||
|
||||
@require_context
|
||||
def get_volume_summary_by_project(context, project_id):
|
||||
"""Retrieves all volumes summary in a project.
|
||||
|
||||
:param context: context to query under
|
||||
:param project_id: project for all volumes being retrieved
|
||||
:returns: volume summary of a project
|
||||
"""
|
||||
query = model_query(context, func.count(models.Volume.id),
|
||||
func.sum(models.Volume.size), read_deleted="no").\
|
||||
filter_by(project_id=project_id)
|
||||
|
||||
if query is None:
|
||||
return []
|
||||
|
||||
result = query.first()
|
||||
return (result[0] or 0, result[1] or 0)
|
||||
|
||||
|
||||
@handle_db_data_error
|
||||
@require_context
|
||||
def volume_update(context, volume_id, values):
|
||||
|
@ -628,13 +628,8 @@ class VolumeList(base.ObjectListBase, base.CinderObject):
|
||||
volumes, expected_attrs=expected_attrs)
|
||||
|
||||
@classmethod
|
||||
def get_volume_summary_all(cls, context):
|
||||
volumes = db.get_volume_summary_all(context)
|
||||
return volumes
|
||||
|
||||
@classmethod
|
||||
def get_volume_summary_by_project(cls, context, project_id):
|
||||
volumes = db.get_volume_summary_by_project(context, project_id)
|
||||
def get_volume_summary(cls, context, project_only):
|
||||
volumes = db.get_volume_summary(context, project_only)
|
||||
return volumes
|
||||
|
||||
@classmethod
|
||||
|
@ -574,14 +574,10 @@ class API(base.Base):
|
||||
if filters is None:
|
||||
filters = {}
|
||||
|
||||
allTenants = utils.get_bool_param('all_tenants', filters)
|
||||
|
||||
if context.is_admin and allTenants:
|
||||
del filters['all_tenants']
|
||||
volumes = objects.VolumeList.get_volume_summary_all(context)
|
||||
else:
|
||||
volumes = objects.VolumeList.get_volume_summary_by_project(
|
||||
context, context.project_id)
|
||||
all_tenants = utils.get_bool_param('all_tenants', filters)
|
||||
filters.pop('all_tenants', None)
|
||||
project_only = not (all_tenants and context.is_admin)
|
||||
volumes = objects.VolumeList.get_volume_summary(context, project_only)
|
||||
|
||||
LOG.info("Get summary completed successfully.")
|
||||
return volumes
|
||||
|
Loading…
x
Reference in New Issue
Block a user