1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2012, Nachi Ueno, NTT MCL, Inc.
5
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6
# not use this file except in compliance with the License. You may obtain
7
# a copy of the License at
9
# http://www.apache.org/licenses/LICENSE-2.0
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
# License for the specific language governing permissions and limitations
18
Views for managing Quantum Routers.
22
from django.core.urlresolvers import reverse
23
from django.utils.translation import ugettext_lazy as _
25
from horizon import forms
26
from horizon import exceptions
27
from horizon import messages
28
from openstack_dashboard import api
30
LOG = logging.getLogger(__name__)
33
class CreateForm(forms.SelfHandlingForm):
34
name = forms.CharField(max_length="255",
35
label=_("Router Name"),
37
tenant_id = forms.ChoiceField(label=_("Project"))
38
failure_url = 'horizon:admin:routers:index'
40
def __init__(self, request, *args, **kwargs):
41
super(CreateForm, self).__init__(request, *args, **kwargs)
42
tenant_choices = [('', _("Select a project"))]
44
for tenant in api.keystone.tenant_list(request, admin=True):
46
tenant_choices.append((tenant.id, tenant.name))
48
msg = _('Failed to get tenants.')
50
redirect = reverse(self.failure_url)
51
exceptions.handle(request, msg, redirect=redirect)
54
self.fields['tenant_id'].choices = tenant_choices
56
def handle(self, request, data):
59
if data.get('tenant_id'):
60
params['tenant_id'] = data['tenant_id']
61
router = api.quantum.router_create(request,
62
name=data['name'], **params)
63
message = 'Creating router "%s"' % data['name']
64
messages.info(request, message)
67
msg = _('Failed to create router "%s".') % data['name']
69
redirect = reverse(self.failure_url)
70
exceptions.handle(request, msg, redirect=redirect)