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 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # vim: tabstop=4 shiftwidth=4 softtabstop=4
  2. # Copyright 2012, Nachi Ueno, NTT MCL, Inc.
  3. # All rights reserved.
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  5. # not use this file except in compliance with the License. You may obtain
  6. # a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. # License for the specific language governing permissions and limitations
  14. # under the License.
  15. """
  16. Views for managing Neutron Routers.
  17. """
  18. import logging
  19. from django.core.urlresolvers import reverse # noqa
  20. from django.utils.translation import ugettext_lazy as _ # noqa
  21. from horizon import exceptions
  22. from horizon import forms
  23. from horizon import messages
  24. from openstack_dashboard import api
  25. LOG = logging.getLogger(__name__)
  26. class CreateForm(forms.SelfHandlingForm):
  27. name = forms.CharField(max_length="255", label=_("Router Name"))
  28. failure_url = 'horizon:project:routers:index'
  29. def __init__(self, request, *args, **kwargs):
  30. super(CreateForm, self).__init__(request, *args, **kwargs)
  31. def handle(self, request, data):
  32. try:
  33. router = api.neutron.router_create(request,
  34. name=data['name'])
  35. message = _('Router %s was successfully created.') % data['name']
  36. messages.success(request, message)
  37. return router
  38. except Exception:
  39. msg = _('Failed to create router "%s".') % data['name']
  40. LOG.info(msg)
  41. redirect = reverse(self.failure_url)
  42. exceptions.handle(request, msg, redirect=redirect)
  43. return False