~yolanda.robla/horizon/precise-security

« 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, Chuck Short, Robie Basak
  • Date: 2012-01-13 10:59:49 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20120113105949-s0ecs3a4atn08dqf
Tags: 2012.1~e3~20120113.1213-0ubuntu1
[Chuck Short]
* Removed python-django-horizon.postinst, let dh_python2 generate instead
  since python-support is not a dependency. 
* Dropped python-openstack-compute from debian/control.
* Clean up debian/control.
* Restart apache when installing the openstack dashboard.
  (LP: #905527)
* Dropped python-coverage not needed.
* Added transitional package for people updating from oneiric.
* Rediffed patches.
* More linitian fixes.

[Robie Basak]
* debian/control: put python-django-horizon in Python section.
* debian/control: lintian fixes (LP: #899427):
  - Put python-django-horizon in Python section
  - Remove definite article from Description
* debian/copyright: fix dep5 syntax.
* debian/python-django-horizon.lintian-overrides: override for template shell
  script.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
"""
23
23
Views for Instances and Volumes.
24
24
"""
25
 
import datetime
26
25
import logging
27
26
 
28
 
from django import http
29
 
from django import shortcuts
30
27
from django.contrib import messages
31
 
from django.contrib.auth.decorators import login_required
32
28
from django.utils.translation import ugettext as _
33
29
from novaclient import exceptions as novaclient_exceptions
34
 
import openstackx.api.exceptions as api_exceptions
35
30
 
36
31
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)
 
32
from horizon import tables
 
33
from .keypairs.tables import KeypairsTable
 
34
from .floating_ips.tables import FloatingIPsTable
 
35
from .security_groups.tables import SecurityGroupsTable
48
36
 
49
37
 
50
38
LOG = logging.getLogger(__name__)
51
39
 
52
40
 
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)
 
41
class IndexView(tables.MultiTableView):
 
42
    table_classes = (KeypairsTable, SecurityGroupsTable, FloatingIPsTable)
 
43
    template_name = 'nova/access_and_security/index.html'
 
44
 
 
45
    def get_keypairs_data(self):
 
46
        try:
 
47
            keypairs = api.nova.keypair_list(self.request)
 
48
        except Exception, e:
 
49
            keypairs = []
 
50
            LOG.exception("Exception in keypair index")
 
51
            messages.error(self.request,
 
52
                           _('Keypair list is currently unavailable.'))
 
53
        return keypairs
 
54
 
 
55
    def get_security_groups_data(self):
 
56
        try:
 
57
            security_groups = api.security_group_list(self.request)
 
58
        except novaclient_exceptions.ClientException, e:
 
59
            security_groups = []
 
60
            LOG.exception("ClientException in security_groups index")
 
61
            messages.error(self.request,
 
62
                           _('Error fetching security_groups: %s') % e)
 
63
        return security_groups
 
64
 
 
65
    def get_floating_ips_data(self):
 
66
        try:
 
67
            floating_ips = api.tenant_floating_ip_list(self.request)
 
68
        except novaclient_exceptions.ClientException, e:
 
69
            floating_ips = []
 
70
            LOG.exception("ClientException in floating ip index")
 
71
            messages.error(self.request,
 
72
                        _('Error fetching floating ips: %s') % e)
 
73
        return floating_ips