~ubuntu-branches/ubuntu/precise/horizon/precise-updates

« back to all changes in this revision

Viewing changes to horizon/horizon/dashboards/nova/access_and_security/views.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-16 16:34:56 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20111216163456-ts9ldy8skhsg0scb
Tags: 2012.1~e2-0ubuntu1
* New upstream release (LP: #904039)
* debian/control: Update build-depends.
* debian/watch: Fix to fetch from Launchpad ad well.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright 2011 United States Government as represented by the
 
4
# Administrator of the National Aeronautics and Space Administration.
 
5
# All Rights Reserved.
 
6
#
 
7
# Copyright 2011 Nebula, Inc.
 
8
# Copyright 2011 OpenStack LLC
 
9
#
 
10
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
11
#    not use this file except in compliance with the License. You may obtain
 
12
#    a copy of the License at
 
13
#
 
14
#         http://www.apache.org/licenses/LICENSE-2.0
 
15
#
 
16
#    Unless required by applicable law or agreed to in writing, software
 
17
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
18
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
19
#    License for the specific language governing permissions and limitations
 
20
#    under the License.
 
21
 
 
22
"""
 
23
Views for Instances and Volumes.
 
24
"""
 
25
import datetime
 
26
import logging
 
27
 
 
28
from django import http
 
29
from django import shortcuts
 
30
from django.contrib import messages
 
31
from django.contrib.auth.decorators import login_required
 
32
from django.utils.translation import ugettext as _
 
33
from novaclient import exceptions as novaclient_exceptions
 
34
import openstackx.api.exceptions as api_exceptions
 
35
 
 
36
from horizon import api
 
37
from horizon import forms
 
38
from horizon import test
 
39
from horizon.dashboards.nova.access_and_security.keypairs.forms import \
 
40
                                                                (DeleteKeypair)
 
41
from horizon.dashboards.nova.access_and_security.security_groups.forms import \
 
42
                                                                  (CreateGroup,
 
43
                                                                   DeleteGroup)
 
44
from horizon.dashboards.nova.access_and_security.floating_ips.forms import \
 
45
                                                       (ReleaseFloatingIp,
 
46
                                                        FloatingIpDisassociate,
 
47
                                                        FloatingIpAllocate)
 
48
 
 
49
 
 
50
LOG = logging.getLogger(__name__)
 
51
 
 
52
 
 
53
@login_required
 
54
def index(request):
 
55
    tenant_id = request.user.tenant_id
 
56
    for f in (CreateGroup, DeleteGroup, DeleteKeypair, ReleaseFloatingIp,
 
57
              FloatingIpDisassociate, FloatingIpAllocate):
 
58
        _unused, handled = f.maybe_handle(request)
 
59
        if handled:
 
60
            return handled
 
61
 
 
62
    try:
 
63
        security_groups = api.security_group_list(request)
 
64
    except novaclient_exceptions.ClientException, e:
 
65
        security_groups = []
 
66
        LOG.exception("ClientException in security_groups index")
 
67
        messages.error(request, _('Error fetching security_groups: %s')
 
68
                                 % e.message)
 
69
    try:
 
70
        floating_ips = api.tenant_floating_ip_list(request)
 
71
    except novaclient_exceptions.ClientException, e:
 
72
        floating_ips = []
 
73
        LOG.exception("ClientException in floating ip index")
 
74
        messages.error(request,
 
75
                    _('Error fetching floating ips: %s') % e.message)
 
76
    try:
 
77
        keypairs = api.keypair_list(request)
 
78
    except novaclient_exceptions.ClientException, e:
 
79
        keypairs = []
 
80
        LOG.exception("ClientException in keypair index")
 
81
        messages.error(request, _('Error fetching keypairs: %s') % e.message)
 
82
 
 
83
    context = {'keypairs': keypairs,
 
84
               'floating_ips': floating_ips,
 
85
               'security_groups': security_groups,
 
86
               'keypair_delete_form': DeleteKeypair(),
 
87
               'disassociate_form': FloatingIpDisassociate(),
 
88
               'release_form': ReleaseFloatingIp(),
 
89
               'allocate_form': FloatingIpAllocate(initial={
 
90
                                        'tenant_id': request.user.tenant_id}),
 
91
               'sec_group_create_form': CreateGroup(
 
92
                                            initial={'tenant_id': tenant_id}),
 
93
               'sec_group_delete_form': DeleteGroup.maybe_handle(request,
 
94
                                            initial={'tenant_id': tenant_id})}
 
95
 
 
96
    if request.is_ajax():
 
97
        template = 'nova/access_and_security/index_ajax.html'
 
98
        context['hide'] = True
 
99
    else:
 
100
        template = 'nova/access_and_security/index.html'
 
101
 
 
102
    return shortcuts.render(request, template, context)