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.

workflows.py 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # Copyright 2012 NEC Corporation
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  4. # not use this file except in compliance with the License. You may obtain
  5. # a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. # License for the specific language governing permissions and limitations
  13. # under the License.
  14. from django.core.urlresolvers import reverse
  15. from openstack_dashboard.dashboards.admin.networks import forms \
  16. as networks_forms
  17. from openstack_dashboard.dashboards.project.networks \
  18. import workflows as network_workflows
  19. class CreateNetworkInfoAction(network_workflows.CreateNetworkInfoAction):
  20. def __init__(self, request, context, *args, **kwargs):
  21. self.create_network_form = context.get('create_network_form')
  22. self.base_fields = self.create_network_form.base_fields
  23. super(CreateNetworkInfoAction, self).__init__(
  24. request, context, *args, **kwargs)
  25. self.fields = self.create_network_form.fields
  26. def clean(self):
  27. self.create_network_form.cleaned_data = super(
  28. CreateNetworkInfoAction, self).clean()
  29. self.create_network_form._changed_data = self.changed_data
  30. self.create_network_form._errors = self.errors
  31. return self.create_network_form.clean()
  32. class Meta(object):
  33. name = network_workflows.CreateNetworkInfoAction.name
  34. help_text = network_workflows.CreateNetworkInfoAction.help_text
  35. class CreateNetworkInfo(network_workflows.CreateNetworkInfo):
  36. action_class = CreateNetworkInfoAction
  37. contributes = ("net_name", "admin_state", "with_subnet", "az_hints")
  38. def __init__(self, workflow):
  39. self.contributes = tuple(workflow.create_network_form.fields.keys())
  40. super(CreateNetworkInfo, self).__init__(workflow)
  41. def prepare_action_context(self, request, context):
  42. context = super(CreateNetworkInfo, self).prepare_action_context(
  43. request, context)
  44. context['create_network_form'] = self.workflow.create_network_form
  45. return context
  46. class CreateNetwork(network_workflows.CreateNetwork):
  47. default_steps = (CreateNetworkInfo,
  48. network_workflows.CreateSubnetInfo,
  49. network_workflows.CreateSubnetDetail)
  50. def __init__(self, request=None, context_seed=None, entry_point=None,
  51. *args, **kwargs):
  52. self.create_network_form = networks_forms.CreateNetwork(
  53. request, *args, **kwargs)
  54. super(CreateNetwork, self).__init__(
  55. request=request,
  56. context_seed=context_seed,
  57. entry_point=entry_point,
  58. *args, **kwargs)
  59. def get_success_url(self):
  60. return reverse("horizon:admin:networks:index")
  61. def get_failure_url(self):
  62. return reverse("horizon:admin:networks:index")
  63. def _create_network(self, request, data):
  64. network = self.create_network_form.handle(request, data)
  65. # Replicate logic from parent CreateNetwork._create_network
  66. if network:
  67. self.context['net_id'] = network.id
  68. self.context['net_name'] = network.name
  69. return network