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

« back to all changes in this revision

Viewing changes to horizon/horizon/dashboards/nova/instances_and_volumes/instances/views.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-03-02 12:11:59 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20120302121159-65b88lcl4slve26i
Tags: 2012.1~e4-0ubuntu1
* New upstream version.
* debian/rules: Update due to upstream build changes.
* debian/control: Update standards-version.
* debian/patches/openstack-config-settings.patch: Dropped
* debian/patches/fix-dashboard-django-wsgi.patch: Refreshed
* debian/patches/fix-dashboard-manage.patch: Refreshed
* debian/openstack-dashboard.install: Update due to upstream build changes.
* debian/dashboard: Update to upstream build changes.
* debian/pydist-overrides: Dont try to install python-django-nose-selenium.
* debian/openstack-dashboard.install: Add missing config files.
* debian/rules: Fix broken settings.py
* debian/patches/pkg-setup.patch: Copy missing templates, shameously
  taken from debian
* debian/patches/fix-broken-tarbll.patch: Add missing files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
 
 
3
 
# Copyright 2012 United States Government as represented by the
4
 
# Administrator of the National Aeronautics and Space Administration.
5
 
# All Rights Reserved.
6
 
#
7
 
# Copyright 2012 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 import http
27
 
from django import shortcuts
28
 
from django.core.urlresolvers import reverse
29
 
from django.utils.datastructures import SortedDict
30
 
from django.utils.translation import ugettext as _
31
 
 
32
 
from horizon import api
33
 
from horizon import exceptions
34
 
from horizon import forms
35
 
from horizon import views
36
 
from .forms import UpdateInstance
37
 
 
38
 
 
39
 
LOG = logging.getLogger(__name__)
40
 
 
41
 
 
42
 
def console(request, instance_id):
43
 
    try:
44
 
        # TODO(jakedahn): clean this up once the api supports tailing.
45
 
        length = request.GET.get('length', None)
46
 
        console = api.server_console_output(request,
47
 
                                            instance_id,
48
 
                                            tail_length=length)
49
 
        response = http.HttpResponse(mimetype='text/plain')
50
 
        response.write(console)
51
 
        response.flush()
52
 
        return response
53
 
    except:
54
 
        msg = _('Unable to get log for instance "%s".') % instance_id
55
 
        redirect = reverse('horizon:nova:instances_and_volumes:index')
56
 
        exceptions.handle(request, msg, redirect=redirect)
57
 
 
58
 
 
59
 
def vnc(request, instance_id):
60
 
    try:
61
 
        console = api.server_vnc_console(request, instance_id)
62
 
        instance = api.server_get(request, instance_id)
63
 
        return shortcuts.redirect(console.url +
64
 
                ("&title=%s(%s)" % (instance.name, instance_id)))
65
 
    except:
66
 
        redirect = reverse("horizon:nova:instances_and_volumes:index")
67
 
        msg = _('Unable to get VNC console for instance "%s".') % instance_id
68
 
        exceptions.handle(request, msg, redirect=redirect)
69
 
 
70
 
 
71
 
class UpdateView(forms.ModalFormView):
72
 
    form_class = UpdateInstance
73
 
    template_name = 'nova/instances_and_volumes/instances/update.html'
74
 
    context_object_name = 'instance'
75
 
 
76
 
    def get_object(self, *args, **kwargs):
77
 
        if not hasattr(self, "object"):
78
 
            instance_id = self.kwargs['instance_id']
79
 
            try:
80
 
                self.object = api.server_get(self.request, instance_id)
81
 
            except:
82
 
                redirect = reverse("horizon:nova:instances_and_volumes:index")
83
 
                msg = _('Unable to retrieve instance details.')
84
 
                exceptions.handle(self.request, msg, redirect=redirect)
85
 
        return self.object
86
 
 
87
 
    def get_initial(self):
88
 
        return {'instance': self.kwargs['instance_id'],
89
 
                'tenant_id': self.request.user.tenant_id,
90
 
                'name': getattr(self.object, 'name', '')}
91
 
 
92
 
 
93
 
class DetailView(views.APIView):
94
 
    template_name = 'nova/instances_and_volumes/instances/detail.html'
95
 
 
96
 
    def get_data(self, request, context, *args, **kwargs):
97
 
        instance_id = kwargs['instance_id']
98
 
 
99
 
        if "show" in request.GET:
100
 
            show_tab = request.GET["show"]
101
 
        else:
102
 
            show_tab = "overview"
103
 
 
104
 
        try:
105
 
            instance = api.server_get(request, instance_id)
106
 
            volumes = api.volume_instance_list(request, instance_id)
107
 
 
108
 
            # Gather our flavors and images and correlate our instances to
109
 
            # them. Exception handling happens in the parent class.
110
 
            flavors = api.flavor_list(request)
111
 
            full_flavors = SortedDict([(str(flavor.id), flavor) for \
112
 
                                        flavor in flavors])
113
 
            instance.full_flavor = full_flavors[instance.flavor["id"]]
114
 
 
115
 
            context.update({'instance': instance, 'volumes': volumes})
116
 
        except:
117
 
            redirect = reverse('horizon:nova:instances_and_volumes:index')
118
 
            exceptions.handle(request,
119
 
                              _('Unable to retrieve details for '
120
 
                                'instance "%s".') % instance_id,
121
 
                                redirect=redirect)
122
 
        if show_tab == "vnc":
123
 
            try:
124
 
                console = api.server_vnc_console(request, instance_id)
125
 
                vnc_url = "%s&title=%s(%s)" % (console.url,
126
 
                                               getattr(instance, "name", ""),
127
 
                                               instance_id)
128
 
                context.update({'vnc_url': vnc_url})
129
 
            except:
130
 
                exceptions.handle(request,
131
 
                                  _('Unable to get vnc console for '
132
 
                                    'instance "%s".') % instance_id)
133
 
 
134
 
        context.update({'show_tab': show_tab})
135
 
 
136
 
        return context