Merge "'Create Volume Snapshot' form should show the quota for snapshot"

This commit is contained in:
Jenkins 2014-07-18 04:24:50 +00:00 committed by Gerrit Code Review
commit b04f020fc1
5 changed files with 55 additions and 10 deletions

View File

@ -37,10 +37,11 @@ class VolumeSnapshotsViewTests(test.TestCase):
volume = self.cinder_volumes.first()
cinder.volume_get(IsA(http.HttpRequest), volume.id) \
.AndReturn(volume)
snapshot_used = len(self.cinder_volume_snapshots.list())
usage_limit = {'maxTotalVolumeGigabytes': 250,
'gigabytesUsed': 20,
'volumesUsed': len(self.cinder_volumes.list()),
'maxTotalVolumes': 6}
'snapshotsUsed': snapshot_used,
'maxTotalSnapshots': 6}
quotas.tenant_limit_usages(IsA(http.HttpRequest)).\
AndReturn(usage_limit)
self.mox.ReplayAll()

View File

@ -15,7 +15,7 @@
</fieldset>
</div>
<div class="right quota-dynamic">
{% include "project/volumes/volumes/_limits.html" with usages=usages snapshot_quota=True %}
{% include "project/volumes/volumes/_snapshot_limits.html" with usages=usages snapshot_quota=True %}
</div>
{% endblock %}

View File

@ -2,24 +2,24 @@
<h3>{% trans "Description" %}:</h3>
<p>{% trans "Volumes are block devices that can be attached to instances." %}</p>
<p>{% block title %}{% trans "Volumes are block devices that can be attached to instances." %}{% endblock %}</p>
<h3>{% trans "Volume Limits" %}</h3>
<h3>{% block head %}{% trans "Volume Limits" %}{% endblock %}</h3>
<div class="quota_title clearfix">
<strong>{% trans "Total Gigabytes" %} <span>({{ usages.gigabytesUsed|intcomma }} {% trans "GB" %})</span></strong>
<strong>{% trans "Total Gigabytes" %} <span>({% block gigabytes_used %}{{ usages.gigabytesUsed|intcomma }}{% endblock %} {% trans "GB" %})</span></strong>
<p>{{ usages.maxTotalVolumeGigabytes|quota:_("GB")|intcomma }}</p>
</div>
<div id="quota_size" data-progress-indicator-for="id_size" data-quota-limit="{{ usages.maxTotalVolumeGigabytes }}" data-quota-used="{{ usages.gigabytesUsed }}" class="quota_bar">
<div id="quota_size" data-progress-indicator-for="id_size" data-quota-limit="{{ usages.maxTotalVolumeGigabytes }}" data-quota-used={% block gigabytes_used_progress %}"{{ usages.gigabytesUsed }}"{% endblock %} class="quota_bar">
</div>
<div class="quota_title clearfix">
<strong>{% trans "Number of Volumes" %} <span>({{ usages.volumesUsed|intcomma }})</span></strong>
<p>{{ usages.maxTotalVolumes|quota|intcomma }}</p>
<strong>{% block type_title %}{% trans "Number of Volumes" %}{% endblock %} <span>({% block used %}{{ usages.volumesUsed|intcomma }}{% endblock %})</span></strong>
<p>{% block total %}{{ usages.maxTotalVolumes|quota|intcomma }}{% endblock %}</p>
</div>
<div id="quota_volumes" data-progress-indicator-step-by="1" data-quota-limit="{{ usages.maxTotalVolumes}}" data-quota-used="{{ usages.volumesUsed }}" class="quota_bar">
<div id={% block type_id %}"quota_volumes"{% endblock %} data-progress-indicator-step-by="1" data-quota-limit={% block total_progress %}"{{ usages.maxTotalVolumes}}"{% endblock %} data-quota-used={% block used_progress %}"{{ usages.volumesUsed }}"{% endblock %} class="quota_bar">
</div>

View File

@ -0,0 +1,42 @@
{% extends "project/volumes/volumes/_limits.html" %}
{% load i18n horizon humanize %}
{% block title %}
{% trans "From here you can create a snapshot of a volume." %}
{% endblock %}
{% block head %}
{% trans "Snapshot Limits" %}
{% endblock %}
{% block gigabytes_used %}
{{ usages.totalGigabytesUsed|intcomma }}
{% endblock %}
{% block gigabytes_used_progress %}
"{{ usages.totalGigabytesUsed }}"
{% endblock %}
{% block type_title %}
{% trans "Number of Snapshots" %}
{% endblock %}
{% block used %}
{{ usages.snapshotsUsed|intcomma }}
{% endblock %}
{% block total %}
{{ usages.maxTotalSnapshots|quota|intcomma }}
{% endblock %}
{% block type_id %}
"quota_snapshots"
{% endblock %}
{% block total_progress %}
"{{ usages.maxTotalSnapshots}}"
{% endblock %}
{% block used_progress %}
"{{ usages.snapshotsUsed }}"
{% endblock %}

View File

@ -252,10 +252,12 @@ def tenant_limit_usages(request):
try:
limits.update(cinder.tenant_absolute_limits(request))
volumes = cinder.volume_list(request)
snapshots = cinder.volume_snapshot_list(request)
total_size = sum([getattr(volume, 'size', 0) for volume
in volumes])
limits['gigabytesUsed'] = total_size
limits['volumesUsed'] = len(volumes)
limits['snapshotsUsed'] = len(snapshots)
except Exception:
msg = _("Unable to retrieve volume limit information.")
exceptions.handle(request, msg)