Add a param to control is we include usage in quota data
Adjutant didn't have a way to control is usage was to be included with the quota data, and this caused perfomance issues when adjutant-ui would query for all regions but not need the usage data. Change-Id: I50b6c19792ccf1a264bd29174f7d3f95180e0564
This commit is contained in:
parent
e720a51152
commit
1a07c1ead2
|
@ -305,7 +305,7 @@ class UpdateProjectQuotasAction(BaseAction, QuotaMixin):
|
||||||
|
|
||||||
for region in self.regions:
|
for region in self.regions:
|
||||||
current_size = quota_manager.get_region_quota_data(
|
current_size = quota_manager.get_region_quota_data(
|
||||||
region)['current_quota_size']
|
region, include_usage=False)['current_quota_size']
|
||||||
region_sizes.append(current_size)
|
region_sizes.append(current_size)
|
||||||
self.add_note(
|
self.add_note(
|
||||||
"Project has size '%s' in region: '%s'" %
|
"Project has size '%s' in region: '%s'" %
|
||||||
|
|
|
@ -390,20 +390,6 @@ class UpdateProjectQuotas(tasks.TaskView):
|
||||||
|
|
||||||
_number_of_returned_tasks = 5
|
_number_of_returned_tasks = 5
|
||||||
|
|
||||||
def get_region_quota_data(self, region_id):
|
|
||||||
quota_manager = QuotaManager(self.project_id)
|
|
||||||
current_quota = quota_manager.get_current_region_quota(region_id)
|
|
||||||
current_quota_size = quota_manager.get_quota_size(current_quota)
|
|
||||||
change_options = quota_manager.get_quota_change_options(
|
|
||||||
current_quota_size)
|
|
||||||
current_usage = quota_manager.get_current_usage(region_id)
|
|
||||||
return {"region": region_id,
|
|
||||||
"current_quota": current_quota,
|
|
||||||
"current_quota_size": current_quota_size,
|
|
||||||
"quota_change_options": change_options,
|
|
||||||
"current_usage": current_usage
|
|
||||||
}
|
|
||||||
|
|
||||||
def get_active_quota_tasks(self):
|
def get_active_quota_tasks(self):
|
||||||
# Get the 5 last quota tasks.
|
# Get the 5 last quota tasks.
|
||||||
task_list = models.Task.objects.filter(
|
task_list = models.Task.objects.filter(
|
||||||
|
@ -456,6 +442,7 @@ class UpdateProjectQuotas(tasks.TaskView):
|
||||||
|
|
||||||
self.project_id = request.keystone_user['project_id']
|
self.project_id = request.keystone_user['project_id']
|
||||||
regions = request.query_params.get('regions', None)
|
regions = request.query_params.get('regions', None)
|
||||||
|
include_usage = request.query_params.get('include_usage', True)
|
||||||
|
|
||||||
if regions:
|
if regions:
|
||||||
regions = regions.split(",")
|
regions = regions.split(",")
|
||||||
|
@ -471,7 +458,7 @@ class UpdateProjectQuotas(tasks.TaskView):
|
||||||
for region in regions:
|
for region in regions:
|
||||||
if self.check_region_exists(region):
|
if self.check_region_exists(region):
|
||||||
region_quotas.append(quota_manager.get_region_quota_data(
|
region_quotas.append(quota_manager.get_region_quota_data(
|
||||||
region))
|
region, include_usage))
|
||||||
else:
|
else:
|
||||||
return Response(
|
return Response(
|
||||||
{"ERROR": ['Region: %s is not valid' % region]}, 400)
|
{"ERROR": ['Region: %s is not valid' % region]}, 400)
|
||||||
|
|
|
@ -275,17 +275,22 @@ class QuotaManager(object):
|
||||||
|
|
||||||
return quota_list[:list_position]
|
return quota_list[:list_position]
|
||||||
|
|
||||||
def get_region_quota_data(self, region_id):
|
def get_region_quota_data(self, region_id, include_usage=True):
|
||||||
current_quota = self.get_current_region_quota(region_id)
|
current_quota = self.get_current_region_quota(region_id)
|
||||||
current_quota_size = self.get_quota_size(current_quota)
|
current_quota_size = self.get_quota_size(current_quota)
|
||||||
change_options = self.get_quota_change_options(current_quota_size)
|
change_options = self.get_quota_change_options(current_quota_size)
|
||||||
current_usage = self.get_current_usage(region_id)
|
|
||||||
return {'region': region_id,
|
region_data = {
|
||||||
"current_quota": current_quota,
|
'region': region_id,
|
||||||
"current_quota_size": current_quota_size,
|
"current_quota": current_quota,
|
||||||
"quota_change_options": change_options,
|
"current_quota_size": current_quota_size,
|
||||||
"current_usage": current_usage
|
"quota_change_options": change_options,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if include_usage:
|
||||||
|
region_data['current_usage'] = self.get_current_usage(region_id)
|
||||||
|
|
||||||
|
return region_data
|
||||||
|
|
||||||
def get_current_usage(self, region_id):
|
def get_current_usage(self, region_id):
|
||||||
current_usage = {}
|
current_usage = {}
|
||||||
|
|
Loading…
Reference in New Issue