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

« back to all changes in this revision

Viewing changes to .pc/git-2012.1~e2~20111201.1077.patch/horizon/horizon/dashboards/nova/security_groups/views.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-09 16:18:55 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20111209161855-nguyenpghx2o2lqy
Tags: 2012.1~e2~20111209.1104-0ubuntu1
* New upstream release.
* Refreshed patches.
* debian/docs: Removed README

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
 
#
9
 
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
10
 
#    not use this file except in compliance with the License. You may obtain
11
 
#    a copy of the License at
12
 
#
13
 
#         http://www.apache.org/licenses/LICENSE-2.0
14
 
#
15
 
#    Unless required by applicable law or agreed to in writing, software
16
 
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17
 
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18
 
#    License for the specific language governing permissions and limitations
19
 
#    under the License.
20
 
 
21
 
"""
22
 
Views for managing Nova instances.
23
 
"""
24
 
import logging
25
 
 
26
 
from django.contrib import messages
27
 
from django.contrib.auth.decorators import login_required
28
 
from django import shortcuts
29
 
from django.utils.translation import ugettext as _
30
 
from novaclient import exceptions as novaclient_exceptions
31
 
 
32
 
from horizon import api
33
 
from horizon.dashboards.nova.security_groups.forms import (CreateGroup,
34
 
        DeleteGroup, AddRule, DeleteRule)
35
 
 
36
 
 
37
 
LOG = logging.getLogger(__name__)
38
 
 
39
 
 
40
 
@login_required
41
 
def index(request):
42
 
    tenant_id = request.user.tenant_id
43
 
    delete_form, handled = DeleteGroup.maybe_handle(request,
44
 
                                initial={'tenant_id': tenant_id})
45
 
 
46
 
    if handled:
47
 
        return handled
48
 
 
49
 
    try:
50
 
        security_groups = api.security_group_list(request)
51
 
    except novaclient_exceptions.ClientException, e:
52
 
        security_groups = []
53
 
        LOG.exception("ClientException in security_groups index")
54
 
        messages.error(request, _('Error fetching security_groups: %s')
55
 
                                 % e.message)
56
 
 
57
 
    return shortcuts.render(request,
58
 
                            'nova/security_groups/index.html', {
59
 
                                'security_groups': security_groups,
60
 
                                'delete_form': delete_form})
61
 
 
62
 
 
63
 
@login_required
64
 
def edit_rules(request, security_group_id):
65
 
    tenant_id = request.user.tenant_id
66
 
    add_form, handled = AddRule.maybe_handle(request,
67
 
                           initial={'tenant_id': tenant_id,
68
 
                                      'security_group_id': security_group_id})
69
 
    if handled:
70
 
        return handled
71
 
 
72
 
    delete_form, handled = DeleteRule.maybe_handle(request,
73
 
                              initial={'tenant_id': tenant_id,
74
 
                                       'security_group_id': security_group_id})
75
 
    if handled:
76
 
        return handled
77
 
 
78
 
    try:
79
 
        security_group = api.security_group_get(request, security_group_id)
80
 
    except novaclient_exceptions.ClientException, e:
81
 
        LOG.exception("ClientException in security_groups rules edit")
82
 
        messages.error(request, _('Error getting security_group: %s')
83
 
                                  % e.message)
84
 
        return shortcuts.redirect('horizon:nova:security_groups:index')
85
 
 
86
 
    return shortcuts.render(request,
87
 
                            'nova/security_groups/edit_rules.html', {
88
 
                                'security_group': security_group,
89
 
                                'delete_form': delete_form,
90
 
                                'form': add_form})
91
 
 
92
 
 
93
 
@login_required
94
 
def create(request):
95
 
    tenant_id = request.user.tenant_id
96
 
    form, handled = CreateGroup.maybe_handle(request,
97
 
                                initial={'tenant_id': tenant_id})
98
 
    if handled:
99
 
        return handled
100
 
 
101
 
    return shortcuts.render(request,
102
 
                            'nova/security_groups/create.html', {
103
 
                                'form': form})