quotas update form mostly working

This commit is contained in:
Jake Dahn
2011-07-08 22:59:24 -07:00
parent bc5ce1ba70
commit b562358c8e
6 changed files with 116 additions and 1 deletions

View File

@@ -45,7 +45,8 @@ urlpatterns += patterns('django_openstack.syspanel.views.services',
urlpatterns += patterns('django_openstack.syspanel.views.tenants',
url(r'^tenants/$', 'index', name='syspanel_tenants'),
url(r'^tenants/create$', 'create', name='syspanel_tenants_create'),
url(TENANTS % 'update', 'update', name='syspanel_tenant_update'),
url(TENANTS % 'users', 'users', name='syspanel_tenant_users'),
url(r'^tenants/create$', 'create', name='syspanel_tenants_create'),
url(TENANTS % 'quotas', 'quotas', name='syspanel_tenant_quotas'),
)

View File

@@ -92,6 +92,39 @@ class UpdateTenant(forms.SelfHandlingForm):
messages.error(request, 'Unable to update tenant: %s' % e.message)
return redirect('syspanel_tenants')
class UpdateQuotas(forms.SelfHandlingForm):
tenant_id = forms.CharField(label="ID (name)", widget=forms.TextInput(attrs={'readonly':'readonly'}))
metadata_items = forms.CharField(label="Metadata Items")
injected_files = forms.CharField(label="Injected Files")
injected_file_content_bytes = forms.CharField(label="Injected File Content Bytes")
cores = forms.CharField(label="VCPUs")
instances = forms.CharField(label="Instances")
volumes = forms.CharField(label="Volumes")
gigabytes = forms.CharField(label="Gigabytes")
ram = forms.CharField(label="RAM (in MB)")
floating_ips = forms.CharField(label="Floating IPs")
def handle(self, request, data):
try:
api.admin_api(request).quotas.update(request,
tenantId=data['tenant_id'],
metadata_items=data['metadata_items'],
injected_file_content_bytes=
data['injected_file_content_bytes'],
volumes=data['volumes'],
gigabytes=data['gigabytes'],
ram=int(data['ram']) * 100,
floating_ips=data['floating_ips'],
instances=data['instances'],
injected_files=data['injected_files'],
cores=data['cores'],
)
messages.success(request,
'Quotas for %s were successfully updated.'
% data['tenant_id'])
except api_exceptions.ApiException, e:
messages.error(request, 'Unable to update quotas: %s' % e.message)
return redirect('syspanel_tenants')
@login_required
def index(request):
@@ -161,3 +194,32 @@ def users(request, tenant_id):
'tenant_id': tenant_id,
'users': users,
}, context_instance = template.RequestContext(request))
@login_required
def quotas(request, tenant_id):
for f in (UpdateQuotas,):
_, handled = f.maybe_handle(request)
if handled:
return handled
quotas = api.admin_api(request).quotas.get(tenant_id)
quota_set = {
'tenant_id': quotas.tenantId,
'metadata_items': quotas.metadata_items,
'injected_file_content_bytes': quotas.injected_file_content_bytes,
'volumes': quotas.volumes,
'gigabytes': quotas.gigabytes,
'ram': int(quotas.ram) / 100,
'floating_ips': quotas.floating_ips,
'instances': quotas.instances,
'injected_files': quotas.injected_files,
'cores': quotas.cores,
}
form = UpdateQuotas(initial=quota_set)
return render_to_response(
'syspanel_tenant_quotas.html',{
'form': form,
'tenant_id': tenant_id,
'quotas': quotas,
}, context_instance = template.RequestContext(request))

View File

@@ -0,0 +1,6 @@
{% extends "_quotas_form.html" %}
{% block submit %}
<input type="submit" value="Update Quotas" class="large-rounded" />
{% endblock %}

View File

@@ -0,0 +1,12 @@
<form id="quotas_form" action="" method="post">
{% csrf_token %}
{% for hidden in form.hidden_fields %}{{ hidden }}{% endfor %}
{% for field in form.visible_fields %}
{{ field.label_tag }}
{{ field.errors }}
{{ field }}
{% endfor %}
{% block submit %}
{% endblock %}
</form>

View File

@@ -15,6 +15,7 @@
<li>{% include "_tenant_delete.html" with form=tenant_delete_form %}</li>
<li><a href="{% url syspanel_tenant_update tenant.id %}">Edit</a></li>
<li><a href="{% url syspanel_tenant_users tenant.id %}">View Members</a></li>
<li><a href="{% url syspanel_tenant_quotas tenant.id %}">Modify Quotas</a></li>
</ul>
</td>
</tr>

View File

@@ -0,0 +1,33 @@
{% extends 'syspanel_base.html' %}
{# list of tenants #}
{# standard nav, sidebar, list of instances in main #}
{% block sidebar %}
{% with current_sidebar="tenants" %}
{{block.super}}
{% endwith %}
{% endblock %}
{% block main %}
<div id='page_header'>
<h2><span>System Panel:</span> Tenants</h2>
<p class='desc'><span>&mdash;</span>Manage Tenants Quotas</p>
</div>
{% include "_messages.html" %}
<div class="main_content">
<div class="dash_block wide form">
<div class='title_block'>
<h3>Update Tenant Quotas</h3>
</div>
{% include 'django_openstack/syspanel/_update_quotas_form.html' with form=form %}
<div class="right">
<h3>Description:</h3>
<p>From here you can edit quotas (max limits) for the tenant {{tenant_id}}.</p>
</div>
</div>
</div>
{% endblock %}