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

« back to all changes in this revision

Viewing changes to horizon/horizon/dashboards/nova/images_and_snapshots/snapshots/forms.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
#
 
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
import logging
 
22
 
 
23
from django import shortcuts
 
24
from django.contrib import messages
 
25
from django.utils.translation import ugettext as _
 
26
from openstackx.api import exceptions as api_exceptions
 
27
 
 
28
from horizon import api
 
29
from horizon import forms
 
30
 
 
31
 
 
32
LOG = logging.getLogger(__name__)
 
33
 
 
34
 
 
35
class CreateSnapshot(forms.SelfHandlingForm):
 
36
    tenant_id = forms.CharField(widget=forms.HiddenInput())
 
37
    instance_id = forms.CharField(widget=forms.TextInput(
 
38
        attrs={'readonly': 'readonly'}))
 
39
    name = forms.CharField(max_length="20", label=_("Snapshot Name"))
 
40
 
 
41
    def handle(self, request, data):
 
42
        try:
 
43
            LOG.info('Creating snapshot "%s"' % data['name'])
 
44
            snapshot = api.snapshot_create(request,
 
45
                    data['instance_id'],
 
46
                    data['name'])
 
47
            instance = api.server_get(request, data['instance_id'])
 
48
 
 
49
            messages.info(request,
 
50
                     _('Snapshot "%(name)s" created for instance "%(inst)s"') %
 
51
                    {"name": data['name'], "inst": instance.name})
 
52
            return shortcuts.redirect('horizon:nova:images_and_snapshots:snapshots:index')
 
53
        except api_exceptions.ApiException, e:
 
54
            msg = _('Error Creating Snapshot: %s') % e.message
 
55
            LOG.exception(msg)
 
56
            messages.error(request, msg)
 
57
            return shortcuts.redirect(request.build_absolute_uri())