OpenStack Dashboard (Horizon)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

forms.py 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # vim: tabstop=4 shiftwidth=4 softtabstop=4
  2. # Copyright 2012 United States Government as represented by the
  3. # Administrator of the National Aeronautics and Space Administration.
  4. # All Rights Reserved.
  5. #
  6. # Copyright 2012 Nebula, Inc.
  7. #
  8. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  9. # not use this file except in compliance with the License. You may obtain
  10. # a copy of the License at
  11. #
  12. # http://www.apache.org/licenses/LICENSE-2.0
  13. #
  14. # Unless required by applicable law or agreed to in writing, software
  15. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  16. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  17. # License for the specific language governing permissions and limitations
  18. # under the License.
  19. import logging
  20. from django import shortcuts
  21. from django.core.urlresolvers import reverse
  22. from django.contrib import messages
  23. from django.utils.translation import ugettext as _
  24. from horizon import api
  25. from horizon import exceptions
  26. from horizon import forms
  27. LOG = logging.getLogger(__name__)
  28. class CreateSnapshot(forms.SelfHandlingForm):
  29. tenant_id = forms.CharField(widget=forms.HiddenInput())
  30. instance_id = forms.CharField(widget=forms.TextInput(
  31. attrs={'readonly': 'readonly'}))
  32. name = forms.CharField(max_length="20", label=_("Snapshot Name"))
  33. def handle(self, request, data):
  34. try:
  35. api.snapshot_create(request, data['instance_id'], data['name'])
  36. # NOTE(gabriel): This API call is only to display a pretty name.
  37. instance = api.server_get(request, data['instance_id'])
  38. vals = {"name": data['name'], "inst": instance.name}
  39. messages.success(request, _('Snapshot "%(name)s" created for '
  40. 'instance "%(inst)s"') % vals)
  41. return shortcuts.redirect('horizon:nova:images_and_snapshots:'
  42. 'index')
  43. except:
  44. redirect = reverse("horizon:nova:instances_and_volumes:index")
  45. exceptions.handle(request,
  46. _('Unable to create snapshot.'),
  47. redirect=redirect)