work on tenants

This commit is contained in:
Anthony Young
2011-06-19 12:13:53 -07:00
parent cf15c32b30
commit f20e6f3b06
11 changed files with 273 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ from django.conf import settings
INSTANCES = r'^instances/(?P<instance_id>[^/]+)/%s$'
USERS = r'^users/(?P<user_id>[^/]+)/%s$'
TENANTS = r'^tenants/(?P<tenant_id>[^/]+)/%s$'
urlpatterns = patterns('django_openstack.syspanel.views.instances',
@@ -40,3 +41,10 @@ urlpatterns += patterns('django_openstack.syspanel.views.users',
urlpatterns += patterns('django_openstack.syspanel.views.services',
url(r'^services/$', 'index', name='syspanel_services'),
)
urlpatterns += patterns('django_openstack.syspanel.views.tenants',
url(r'^tenants/$', 'index', name='syspanel_tenants'),
url(TENANTS % 'update', 'update', name='syspanel_tenant_update'),
url(r'^tenants/create$', 'create', name='syspanel_tenants_create'),
)

View File

@@ -0,0 +1,112 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
from django import template
from django import http
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.shortcuts import render_to_response
from django.shortcuts import redirect
from django.utils.translation import ugettext as _
import datetime
import json
import logging
from django.contrib import messages
from django_openstack import api
from django_openstack import forms
from django_openstack.dash.views import instances as dash_instances
from openstackx.api import exceptions as api_exceptions
class CreateTenant(forms.SelfHandlingForm):
id = forms.CharField(label="ID (name)")
description = forms.CharField(widget=forms.widgets.Textarea(), label="Description")
enabled = forms.BooleanField(label="Enabled", required=False)
def handle(self, request, data):
try:
api.account_api(request).tenants.create(data['id'],
data['description'], data['enabled'])
messages.success(request,
'%s was successfully created.'
% data['id'])
except api_exceptions.ApiException, e:
messages.error(request, 'Unable to create tenant: %s' %
(e.message))
return redirect('syspanel_tenants')
class UpdateTenant(forms.SelfHandlingForm):
id = forms.CharField(label="ID (name)", widget=forms.TextInput(attrs={'readonly':'readonly'}))
description = forms.CharField(widget=forms.widgets.Textarea(), label="Description")
enabled = forms.BooleanField(label="Enabled", required=False)
def handle(self, request, data):
try:
api.account_api(request).tenants.update(data['id'],
data['description'], data['enabled'])
messages.success(request,
'%s was successfully updated.'
% data['id'])
except api_exceptions.ApiException, e:
messages.error(request, 'Unable to update tenant: %s' % e.message)
return redirect('syspanel_tenants')
class ToggleTenant(forms.SelfHandlingForm):
id = forms.CharField(label="ID (name)")
enabled = forms.BooleanField(label="Enabled", required=False)
@login_required
def index(request):
tenants = []
try:
tenants = api.account_api(request).tenants.list()
except api_exceptions.ApiException, e:
messages.error(request, 'Unable to get tenant info: %s' % e.message)
tenants.sort(key=lambda x: x.id, reverse=True)
return render_to_response('syspanel_tenants.html',{
'tenants': tenants,
}, context_instance = template.RequestContext(request))
@login_required
def create(request):
form, handled = CreateTenant.maybe_handle(request)
if handled:
return handled
return render_to_response(
'syspanel_tenant_create.html',{
'form': form,
}, context_instance = template.RequestContext(request))
@login_required
def update(request, tenant_id):
form, handled = UpdateTenant.maybe_handle(request)
if handled:
return handled
if request.POST:
return render_to_response(
'syspanel_tenant_update.html',{
'form': form,
}, context_instance = template.RequestContext(request))
else:
try:
tenant = api.account_api(request).tenants.get(tenant_id)
form = UpdateTenant(initial={'id': tenant.id,
'description': tenant.description,
'enabled': tenant.enabled})
return render_to_response(
'syspanel_tenant_update.html',{
'form': form,
}, context_instance = template.RequestContext(request))
except api_exceptions.ApiException, e:
messages.error(request, 'Unable to update tenant: %s' % e.message)
return redirect('syspanel_tenants')

View File

@@ -7,5 +7,6 @@
<li><a {% if current_sidebar == "flavors" %} class="active" {% endif %} href="{% url syspanel_flavors %}">Flavors</a></li>
<li><a {% if current_sidebar == "users" %} class="active" {% endif %} href="{% url syspanel_users %}">Users</a></li>
<li><a {% if current_sidebar == "services" %} class="active" {% endif %} href="{% url syspanel_services %}">Services</a></li>
<li><a {% if current_sidebar == "tenants" %} class="active" {% endif %} href="{% url syspanel_tenants %}">Tenants</a></li>
</ul>
</div>

View File

@@ -0,0 +1,21 @@
<table class="wide">
<tr>
<th>Name</th>
<th>Description</th>
<th>Enabled</th>
<th>Options</th>
</tr>
{% for tenant in tenants %}
<tr class="{% cycle 'odd' 'even' %}">
<td>{{tenant.id}}</td>
<td>{{tenant.description}}</td>
<td>{{tenant.enabled}}</td>
<td id="actions">
<ul>
<li>{% include "_tenant_delete.html" with form=tenant_delete_form %}</li>
<li><a href="{% url syspanel_tenant_update tenant.id %}">Update</a></li>
</ul>
</td>
</tr>
{% endfor %}
</table>

View File

@@ -0,0 +1,9 @@
<form id="form_tenant_delete{{tenant.id}}" class="form-tenant-delete" method="post">
{% csrf_token %}
{% for hidden in form.hidden_fields %}
{{hidden}}
{% endfor %}
<input name="tenant" type="hidden" value="{{tenant.id}}" />
<input id="enable_{{tenant.id}}" class="enable" type="submit" value="Delete" />
</form>

View File

@@ -0,0 +1,10 @@
<form id="tenant_form" 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 %}
<input type="submit" value="Submit" class="large-rounded" />
</form>

View File

@@ -1,5 +1,5 @@
{% extends 'syspanel_base.html' %}
{# list of user's instances #}
{# list of system instances #}
{# standard nav, sidebar, list of instances in main #}
{% block sidebar %}

View File

@@ -0,0 +1,36 @@
{% 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</p>
</div>
{% include "_messages.html" %}
<div class="main_content">
<div class="dash_block wide form">
<div class='title_block'>
<h3>Create Tenant</h3>
</div>
{% include '_tenant_form.html' %}
<div class="right">
<h3>Description:</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus vitae est urna. Phasellus sagittis, sem posuere hendrerit mattis, velit risus viverra enim, tempus dapibus sem turpis ac erat.</p>
<p>Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed mollis ligula nec lacus mollis eu laoreet lectus porta. </p>
<p>Sed iaculis mauris et est consectetur egestas. Praesent dolor libero, semper sed aliquet</p>
</div>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,36 @@
{% 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</p>
</div>
{% include "_messages.html" %}
<div class="main_content">
<div class="dash_block wide form">
<div class='title_block'>
<h3>Update Tenant</h3>
</div>
{% include '_tenant_form.html' %}
<div class="right">
<h3>Description:</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus vitae est urna. Phasellus sagittis, sem posuere hendrerit mattis, velit risus viverra enim, tempus dapibus sem turpis ac erat.</p>
<p>Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed mollis ligula nec lacus mollis eu laoreet lectus porta. </p>
<p>Sed iaculis mauris et est consectetur egestas. Praesent dolor libero, semper sed aliquet</p>
</div>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,34 @@
{% 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</p>
</div>
{% include "_messages.html" %}
<div class="main_content">
<div class='table_title wide'>
<h3>Tenants</h3>
<div class='search'>
<form action='' method='post'>
<fieldset>
<label for='table_search'>Search</label>
<input id='table_search' name='search' type='text' value='' />
</fieldset>
</form>
</div>
</div>
{% include "_syspanel_tenant_list.html" %}
<a id="tenant_create_link" href="{% url syspanel_tenants_create %}">Create New Tenant >></a>
</div>
{% endblock %}

View File

@@ -230,6 +230,11 @@ border: 1px solid #cbe0e8;
float: left;
}
input[readonly="readonly"] {
background: #eee;
color: #999;
}
#login input[type="text"] {
width: 325px;
height: 25px;