~ubuntu-branches/ubuntu/raring/horizon/raring

« back to all changes in this revision

Viewing changes to openstack_dashboard/dashboards/admin/routers/forms.py

  • Committer: Package Import Robot
  • Author(s): James Page, James Page, Adam Gandelman
  • Date: 2013-03-20 11:20:17 UTC
  • mfrom: (1.1.25)
  • Revision ID: package-import@ubuntu.com-20130320112017-15h2zdnqy20lc089
Tags: 1:2013.1~rc1-0ubuntu1
[ James Page ]
* New upstream release candidate for Grizzly:
  - Recompress static JS and CSS and generate new manifest.json for
    offline compression.
* d/watch: Update uversionmangle to deal with upstream versioning
  changes, remove tarballs.openstack.org.
* d/control: Version python-compressor >= 1.2 (LP: #1130610).

[ Adam Gandelman ]
* debian/patches/ubuntu_local_settings.py: Refresh, specify memcache
  location as part of CACHES, as per upstream changes to example config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
 
 
3
 
# Copyright 2012,  Nachi Ueno,  NTT MCL,  Inc.
4
 
#
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
8
 
#
9
 
#         http://www.apache.org/licenses/LICENSE-2.0
10
 
#
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
15
 
#    under the License.
16
 
 
17
 
"""
18
 
Views for managing Quantum Routers.
19
 
"""
20
 
import logging
21
 
 
22
 
from django.core.urlresolvers import reverse
23
 
from django.utils.translation import ugettext_lazy as _
24
 
 
25
 
from horizon import forms
26
 
from horizon import exceptions
27
 
from horizon import messages
28
 
from openstack_dashboard import api
29
 
 
30
 
LOG = logging.getLogger(__name__)
31
 
 
32
 
 
33
 
class CreateForm(forms.SelfHandlingForm):
34
 
    name = forms.CharField(max_length="255",
35
 
                           label=_("Router Name"),
36
 
                           required=False)
37
 
    tenant_id = forms.ChoiceField(label=_("Project"))
38
 
    failure_url = 'horizon:admin:routers:index'
39
 
 
40
 
    def __init__(self, request, *args, **kwargs):
41
 
        super(CreateForm, self).__init__(request, *args, **kwargs)
42
 
        tenant_choices = [('', _("Select a project"))]
43
 
        try:
44
 
            for tenant in api.keystone.tenant_list(request, admin=True):
45
 
                if tenant.enabled:
46
 
                    tenant_choices.append((tenant.id, tenant.name))
47
 
        except:
48
 
            msg = _('Failed to get tenants.')
49
 
            LOG.warn(msg)
50
 
            redirect = reverse(self.failure_url)
51
 
            exceptions.handle(request, msg, redirect=redirect)
52
 
            return False
53
 
 
54
 
        self.fields['tenant_id'].choices = tenant_choices
55
 
 
56
 
    def handle(self, request, data):
57
 
        try:
58
 
            params = {}
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)
65
 
            return router
66
 
        except:
67
 
            msg = _('Failed to create router "%s".') % data['name']
68
 
            LOG.warn(msg)
69
 
            redirect = reverse(self.failure_url)
70
 
            exceptions.handle(request, msg, redirect=redirect)
71
 
            return False