add switch tenants
This commit is contained in:
parent
25db4f453c
commit
f0b8a00880
@ -7,6 +7,6 @@ from django.conf import settings
|
||||
urlpatterns = patterns('django_openstack.auth.views',
|
||||
url(r'login/$', 'login', name='auth_login'),
|
||||
url(r'logout/$', 'logout', name='auth_logout'),
|
||||
url(r'switch/(?P<tenant_id>[^/]+)/$', 'logout', name='auth_switch'),
|
||||
url(r'switch/(?P<tenant_id>[^/]+)/$', 'switch_tenants', name='auth_switch'),
|
||||
)
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
from django import http
|
||||
from django import template
|
||||
from django import shortcuts
|
||||
from django.contrib import messages
|
||||
|
||||
@ -46,24 +48,24 @@ def switch_tenants(request, tenant_id):
|
||||
request.session['user'] = userdata['username']
|
||||
request.session['tenant'] = tenant_id
|
||||
messages.error(request, token)
|
||||
return shortcuts.redirect('novaO_overview')
|
||||
return shortcuts.redirect('dash_overview')
|
||||
|
||||
except api_exceptions.Unauthorized as ex:
|
||||
messages.error(request, 'Error authenticating:')
|
||||
return shortcuts.redirect('novaO_overview')
|
||||
return shortcuts.redirect('dash_overview')
|
||||
|
||||
else:
|
||||
form = nova_forms.LoginWithoutTenant()
|
||||
|
||||
return render_to_response('switch_tenants.html', {
|
||||
return shortcuts.render_to_response('switch_tenants.html', {
|
||||
'to_tenant': tenant_id,
|
||||
'form': form,
|
||||
'tenant_id': tenant_id,
|
||||
},context_instance=template.RequestContext(request))
|
||||
}, context_instance=template.RequestContext(request))
|
||||
|
||||
|
||||
def logout(request):
|
||||
request.session.clear()
|
||||
return shortcuts.redirect('novaO_instances')
|
||||
return shortcuts.redirect('splash')
|
||||
|
||||
|
||||
|
||||
|
@ -4,6 +4,7 @@ from django.conf.urls.defaults import *
|
||||
from django.conf import settings
|
||||
|
||||
INSTANCES = r'^(?P<tenant_id>[^/]+)/instances/(?P<instance_id>[^/]+)/%s$'
|
||||
IMAGES = r'^(?P<tenant_id>[^/]+)/images/(?P<image_id>[^/]+)/%s$'
|
||||
|
||||
urlpatterns = patterns('django_openstack.dash.views.instances',
|
||||
url(r'^(?P<tenant_id>[^/]+)/instances/$', 'index', name='dash_instances'),
|
||||
@ -19,10 +20,9 @@ urlpatterns += patterns('django_openstack.dash.views.images',
|
||||
url(r'^(?P<tenant_id>[^/]+)/images/upload/$',
|
||||
'upload',
|
||||
name='dash_images_upload'),
|
||||
url(r'^(?P<tenant_id>[^/]+)/images/(?P<image_id>[^/]+)/launch/$',
|
||||
'launch',
|
||||
name='dash_images_launch'),
|
||||
url(r'^(?P<tenant_id>[^/]+)/images/(?P<image_id>[^/]+)/update$',
|
||||
'update',
|
||||
name='dash_images_update'),
|
||||
url(IMAGES % 'launch', 'launch', name='dash_images_launch'),
|
||||
|
||||
#url(r'^(?P<tenant_id>[^/]+)/images/(?P<image_id>[^/]+)/update$',
|
||||
# 'update',
|
||||
# name='dash_images_update'),
|
||||
)
|
||||
|
@ -19,7 +19,7 @@
|
||||
"""
|
||||
Views for managing Nova instances.
|
||||
"""
|
||||
|
||||
import datetime
|
||||
import logging
|
||||
|
||||
from django import http
|
||||
@ -52,6 +52,29 @@ def index(request, tenant_id):
|
||||
}, context_instance=template.RequestContext(request))
|
||||
|
||||
|
||||
@login_required
|
||||
def usage(request, tenant_id=None):
|
||||
today = datetime.date.today()
|
||||
date_start = datetime.date(today.year, today.month, 1)
|
||||
datetime_start = datetime.datetime.combine(date_start, datetime.time())
|
||||
datetime_end = datetime.datetime.utcnow()
|
||||
|
||||
usage = {}
|
||||
if not tenant_id:
|
||||
tenant_id = request.user.tenant
|
||||
|
||||
|
||||
try:
|
||||
usage = api.extras_api(request).usage.get(tenant_id,
|
||||
datetime_start, datetime_end)
|
||||
except api_exceptions.ApiException, e:
|
||||
messages.error(request, 'Unable to get usage info: %s' % e.message)
|
||||
|
||||
return render_to_response('dash_usage.html', {
|
||||
'usage': usage,
|
||||
}, context_instance=template.RequestContext(request))
|
||||
|
||||
|
||||
# TODO(termie): instance_id in two places
|
||||
@login_required
|
||||
def terminate(request, tenant_id, instance_id):
|
||||
|
@ -0,0 +1,16 @@
|
||||
<form action="{% url auth_login %}" method="post">
|
||||
{% csrf_token %}
|
||||
<fieldset>
|
||||
{% for hidden in form.hidden_fields %}
|
||||
{{hidden}}
|
||||
{% endfor %}
|
||||
{% for field in form.visible_fields %}
|
||||
{{field.label_tag}}
|
||||
{{field.errors}}
|
||||
{{field}}
|
||||
{% endfor %}
|
||||
{% block submit %}
|
||||
<input type="submit" value="Login" />
|
||||
{% endblock %}
|
||||
</fieldset>
|
||||
</form>
|
7
openstack-dashboard/dashboard/templates/_switch.html
Normal file
7
openstack-dashboard/dashboard/templates/_switch.html
Normal file
@ -0,0 +1,7 @@
|
||||
{% extends 'django_openstack/auth/_switch.html' %}
|
||||
{% block submit %}
|
||||
<input type="hidden" name="next" value="/" />
|
||||
<div class="button">
|
||||
<input id="home_login_btn" type="submit" value="Sign In">
|
||||
</div>
|
||||
{% endblock %}
|
26
openstack-dashboard/dashboard/templates/switch_tenants.html
Normal file
26
openstack-dashboard/dashboard/templates/switch_tenants.html
Normal file
@ -0,0 +1,26 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{# present form to log in as different tenant #}
|
||||
|
||||
{% block sidebar %}
|
||||
<div id="sidebar">
|
||||
EMPTY_SIDEBAR
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
<div id='page_header'>
|
||||
<h2><span>Compute:</span> Switch to Tenant {{to_tenant}}</h2>
|
||||
<p class='desc'><span>—</span> Login to OpenStack via Keystone auth.</p>
|
||||
</div>
|
||||
<div class='main_content'>
|
||||
|
||||
{% include "_messages.html" %}
|
||||
|
||||
<div class="dash_block" id="login_wrapper">
|
||||
<div class='table_title narrow'>
|
||||
<h3>Switch</h3>
|
||||
</div>
|
||||
{% include '_switch.html' %}
|
||||
</div>
|
||||
{% endblock %}
|
@ -31,7 +31,7 @@ from django_openstack import urls as django_openstack_urls
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url(r'^$', 'dashboard.views.splash', name='splash'),
|
||||
url(r'^dash/$', 'dashboard.views.user_overview', name='dash_overview'),
|
||||
url(r'^dash/$', 'django_openstack.dash.views.instances.usage', name='dash_overview'),
|
||||
)
|
||||
|
||||
# NOTE(termie): just append them since we want the routes at the root
|
||||
|
Loading…
x
Reference in New Issue
Block a user