VM-side agent for Murano
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 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # Copyright (c) 2013 Mirantis Inc.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain 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,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  12. # implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import json
  16. import logging
  17. import re
  18. from django.utils.text import normalize_newlines
  19. from django.utils.translation import ugettext as _
  20. from horizon import exceptions
  21. from horizon import forms
  22. from horizon import workflows
  23. from glazierdashboard.tabula import api
  24. LOG = logging.getLogger(__name__)
  25. class SelectProjectUserAction(workflows.Action):
  26. project_id = forms.ChoiceField(label=_("Project"))
  27. user_id = forms.ChoiceField(label=_("User"))
  28. def __init__(self, request, *args, **kwargs):
  29. super(SelectProjectUserAction, self).__init__(request, *args, **kwargs)
  30. # Set our project choices
  31. projects = [(tenant.id, tenant.name)
  32. for tenant in request.user.authorized_tenants]
  33. self.fields['project_id'].choices = projects
  34. # Set our user options
  35. users = [(request.user.id, request.user.username)]
  36. self.fields['user_id'].choices = users
  37. class Meta:
  38. name = _("Project & User")
  39. # Unusable permission so this is always hidden. However, we
  40. # keep this step in the workflow for validation/verification purposes.
  41. permissions = ("!",)
  42. class SelectProjectUser(workflows.Step):
  43. action_class = SelectProjectUserAction
  44. class ConfigureDCAction(workflows.Action):
  45. name = forms.CharField(label=_("Environment Name"), required=True)
  46. class Meta:
  47. name = _("Environment")
  48. help_text_template = "_data_center_help.html"
  49. class ConfigureDC(workflows.Step):
  50. action_class = ConfigureDCAction
  51. contibutes = ('name',)
  52. def contribute(self, data, context):
  53. if data:
  54. context['name'] = data.get('name', '')
  55. return context
  56. class CreateDC(workflows.Workflow):
  57. slug = "create"
  58. name = _("Create Environment")
  59. finalize_button_name = _("Create")
  60. success_message = _('Created environment "%s".')
  61. failure_message = _('Unable to create environment "%s".')
  62. success_url = "horizon:project:tabula:index"
  63. default_steps = (SelectProjectUser, ConfigureDC)
  64. def format_status_message(self, message):
  65. name = self.context.get('name', 'noname')
  66. return message % name
  67. def handle(self, request, context):
  68. try:
  69. api.environment_create(request, context)
  70. return True
  71. except:
  72. exceptions.handle(request)
  73. return False