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

« back to all changes in this revision

Viewing changes to horizon/horizon/dashboards/nova/images_and_snapshots/images/forms.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 images.
23
 
"""
24
 
 
25
 
import logging
26
 
 
27
 
from django import shortcuts
28
 
from django.contrib import messages
29
 
from django.core.urlresolvers import reverse
30
 
from django.utils.text import normalize_newlines
31
 
from django.utils.translation import ugettext as _
32
 
 
33
 
from horizon import api
34
 
from horizon import exceptions
35
 
from horizon import forms
36
 
 
37
 
LOG = logging.getLogger(__name__)
38
 
 
39
 
 
40
 
class UpdateImageForm(forms.SelfHandlingForm):
41
 
    image_id = forms.CharField(widget=forms.HiddenInput())
42
 
    name = forms.CharField(max_length="25", label=_("Name"))
43
 
    kernel = forms.CharField(max_length="25", label=_("Kernel ID"),
44
 
                             required=False)
45
 
    ramdisk = forms.CharField(max_length="25", label=_("Ramdisk ID"),
46
 
                              required=False)
47
 
    architecture = forms.CharField(label=_("Architecture"), required=False)
48
 
    container_format = forms.CharField(label=_("Container Format"),
49
 
                                       required=False)
50
 
    disk_format = forms.CharField(label=_("Disk Format"))
51
 
 
52
 
    def handle(self, request, data):
53
 
        # TODO add public flag to image meta properties
54
 
        image_id = data['image_id']
55
 
        error_updating = _('Unable to update image "%s".')
56
 
 
57
 
        meta = {'is_public': True,
58
 
                'disk_format': data['disk_format'],
59
 
                'container_format': data['container_format'],
60
 
                'name': data['name'],
61
 
                'properties': {}}
62
 
        if data['kernel']:
63
 
            meta['properties']['kernel_id'] = data['kernel']
64
 
        if data['ramdisk']:
65
 
            meta['properties']['ramdisk_id'] = data['ramdisk']
66
 
        if data['architecture']:
67
 
            meta['properties']['architecture'] = data['architecture']
68
 
 
69
 
        try:
70
 
            api.image_update(request, image_id, meta)
71
 
            messages.success(request, _('Image was successfully updated.'))
72
 
        except:
73
 
            exceptions.handle(request, error_updating % image_id)
74
 
        return shortcuts.redirect('horizon:nova:images_and_snapshots:index')
75
 
 
76
 
 
77
 
class LaunchForm(forms.SelfHandlingForm):
78
 
    name = forms.CharField(max_length=80, label=_("Server Name"))
79
 
    image_id = forms.CharField(widget=forms.HiddenInput())
80
 
    tenant_id = forms.CharField(widget=forms.HiddenInput())
81
 
    user_data = forms.CharField(widget=forms.Textarea,
82
 
                                label=_("User Data"),
83
 
                                required=False)
84
 
    flavor = forms.ChoiceField(label=_("Flavor"),
85
 
                               help_text=_("Size of image to launch."))
86
 
    keypair = forms.ChoiceField(label=_("Keypair"),
87
 
                                required=False,
88
 
                                help_text=_("Which keypair to use for "
89
 
                                            "authentication."))
90
 
    count = forms.CharField(label=_("Instance Count"),
91
 
                            required=True,
92
 
                            initial=1,
93
 
                            widget=forms.TextInput(),
94
 
                            help_text=_("Number of instances to launch."))
95
 
    security_groups = forms.MultipleChoiceField(
96
 
                                label=_("Security Groups"),
97
 
                                required=True,
98
 
                                initial=["default"],
99
 
                                widget=forms.CheckboxSelectMultiple(),
100
 
                                help_text=_("Launch instance in these "
101
 
                                            "security groups."))
102
 
    volume = forms.ChoiceField(label=_("Volume or Volume Snapshot"),
103
 
                               required=False,
104
 
                               help_text=_("Volume to boot from."))
105
 
    device_name = forms.CharField(label=_("Device Name"),
106
 
                                  required=False,
107
 
                                  initial="vda",
108
 
                                  help_text=_("Volume mount point (e.g. 'vda' "
109
 
                                              "mounts at '/dev/vda')."))
110
 
    delete_on_terminate = forms.BooleanField(
111
 
            label=_("Delete on Terminate"),
112
 
            initial=False,
113
 
            required=False,
114
 
            help_text=_("Delete volume on instance termiante"))
115
 
 
116
 
    def __init__(self, *args, **kwargs):
117
 
        flavor_list = kwargs.pop('flavor_list')
118
 
        keypair_list = kwargs.pop('keypair_list')
119
 
        security_group_list = kwargs.pop('security_group_list')
120
 
        volume_list = kwargs.pop('volume_list')
121
 
        super(LaunchForm, self).__init__(*args, **kwargs)
122
 
        self.fields['flavor'].choices = flavor_list
123
 
        self.fields['keypair'].choices = keypair_list
124
 
        self.fields['security_groups'].choices = security_group_list
125
 
        self.fields['volume'].choices = volume_list
126
 
 
127
 
    def handle(self, request, data):
128
 
        try:
129
 
            if(len(data['volume']) > 0):
130
 
                if(data['delete_on_terminate']):
131
 
                    delete_on_terminate = 1
132
 
                else:
133
 
                    delete_on_terminate = 0
134
 
                dev_mapping = {data['device_name']:
135
 
                        ("%s::%s" % (data['volume'], delete_on_terminate))}
136
 
            else:
137
 
                dev_mapping = None
138
 
 
139
 
            api.server_create(request,
140
 
                              data['name'],
141
 
                              data['image_id'],
142
 
                              data['flavor'],
143
 
                              data.get('keypair'),
144
 
                              normalize_newlines(data.get('user_data')),
145
 
                              data.get('security_groups'),
146
 
                              dev_mapping,
147
 
                              instance_count=int(data.get('count')))
148
 
            messages.success(request,
149
 
                         _('Instance "%s" launched.') % data["name"])
150
 
        except:
151
 
            redirect = reverse("horizon:nova:images_and_snapshots:index")
152
 
            exceptions.handle(request,
153
 
                              _('Unable to launch instance: %(exc)s'),
154
 
                              redirect=redirect)
155
 
        return shortcuts.redirect('horizon:nova:instances_and_volumes:index')