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.

views.py 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 logging
  16. import re
  17. from django.views import generic
  18. from django.core.urlresolvers import reverse
  19. from django.utils.translation import ugettext_lazy as _
  20. from django.contrib.formtools.wizard.views import SessionWizardView
  21. from horizon import exceptions
  22. from horizon import tabs
  23. from horizon import tables
  24. from horizon import workflows
  25. from horizon.forms.views import ModalFormMixin
  26. from glazierdashboard.tabula import api
  27. from .tables import EnvironmentsTable, ServicesTable
  28. from .workflows import CreateDC
  29. from .tabs import ServicesTabs
  30. from .forms import (WizardFormADConfiguration, WizardFormIISConfiguration)
  31. from horizon import messages
  32. from django.http import HttpResponseRedirect
  33. LOG = logging.getLogger(__name__)
  34. class Wizard(ModalFormMixin, SessionWizardView, generic.FormView):
  35. template_name = 'services_tabs.html'
  36. def done(self, form_list, **kwargs):
  37. link = self.request.__dict__['META']['HTTP_REFERER']
  38. environment_id = re.search('tabula/(\S+)', link).group(0)[6:-1]
  39. url = "/project/tabula/%s/" % environment_id
  40. service_type = form_list[0].data.get('0-service', '')
  41. parameters = {'service_type': service_type}
  42. data = form_list[1].data
  43. if service_type == 'Active Directory':
  44. parameters['configuration'] = 'standalone'
  45. parameters['name'] = str(data.get('1-dc_name', 'noname'))
  46. parameters['domain'] = parameters['name'] # Fix Me in orchestrator
  47. parameters['adminPassword'] = str(data.get('1-adm_password', ''))
  48. dc_count = int(data.get('1-dc_count', 1))
  49. recovery_password = str(data.get('1-recovery_password', ''))
  50. parameters['units'] = []
  51. parameters['units'].append({'isMaster': True,
  52. 'recoveryPassword': recovery_password,
  53. 'location': 'west-dc'})
  54. for dc in range(dc_count - 1):
  55. parameters['units'].append({
  56. 'isMaster': False,
  57. 'recoveryPassword': recovery_password,
  58. 'location': 'west-dc'
  59. })
  60. elif service_type == 'IIS':
  61. password = data.get('1-adm_password', '')
  62. parameters['name'] = str(data.get('1-iis_name', 'noname'))
  63. parameters['credentials'] = {'username': 'Administrator',
  64. 'password': password}
  65. parameters['domain'] = str(data.get('1-iis_domain', ''))
  66. password = form_list[1].data.get('1-adm_password', '')
  67. domain = form_list[1].data.get('1-iis_domain', '')
  68. dc_user = form_list[1].data.get('1-domain_user_name', '')
  69. dc_pass = form_list[1].data.get('1-domain_user_password', '')
  70. parameters['name'] = str(form_list[1].data.get('1-iis_name',
  71. 'noname'))
  72. parameters['domain'] = parameters['name']
  73. parameters['credentials'] = {'username': 'Administrator',
  74. 'password': password}
  75. parameters['domain'] = str(domain)
  76. parameters['location'] = 'west-dc'
  77. parameters['units'] = []
  78. parameters['units'].append({'id': '1',
  79. 'endpoint': [{'host': '10.0.0.1'}],
  80. 'location': 'west-dc'})
  81. service = api.services_create(self.request, environment_id, parameters)
  82. message = "The %s service successfully created." % service_type
  83. messages.success(self.request, message)
  84. return HttpResponseRedirect(url)
  85. def get_form(self, step=None, data=None, files=None):
  86. form = super(Wizard, self).get_form(step, data, files)
  87. if data:
  88. self.service_type = data.get('0-service', '')
  89. if self.service_type == 'Active Directory':
  90. self.form_list['1'] = WizardFormADConfiguration
  91. elif self.service_type == 'IIS':
  92. self.form_list['1'] = WizardFormIISConfiguration
  93. return form
  94. def get_form_kwargs(self, step=None):
  95. return {'request': self.request} if step == u'1' else {}
  96. def get_form_step_data(self, form):
  97. LOG.debug(form.data)
  98. return form.data
  99. def get_context_data(self, form, **kwargs):
  100. context = super(Wizard, self).get_context_data(form=form, **kwargs)
  101. if self.steps.index > 0:
  102. context.update({'service_type': self.service_type})
  103. return context
  104. class IndexView(tables.DataTableView):
  105. table_class = EnvironmentsTable
  106. template_name = 'index.html'
  107. def get_data(self):
  108. try:
  109. environments = api.environments_list(self.request)
  110. except:
  111. environments = []
  112. exceptions.handle(self.request,
  113. _('Unable to retrieve environments list.'))
  114. return environments
  115. class Services(tables.DataTableView):
  116. table_class = ServicesTable
  117. template_name = 'services.html'
  118. def get_context_data(self, **kwargs):
  119. context = super(Services, self).get_context_data(**kwargs)
  120. context['environment_name'] = self.environment_name
  121. return context
  122. def get_data(self):
  123. try:
  124. self.environment_id = self.kwargs['environment_id']
  125. environment = api.environment_get(self.request, self.environment_id)
  126. self.environment_name = environment.name
  127. services = api.services_list(self.request, environment_id)
  128. except:
  129. services = []
  130. exceptions.handle(self.request,
  131. _('Unable to retrieve list of services for '
  132. 'environment "%s".') % self.environment_name)
  133. self._services = services
  134. return self._services
  135. class DetailServiceView(tabs.TabView):
  136. tab_group_class = ServicesTabs
  137. template_name = 'service_details.html'
  138. def get_context_data(self, **kwargs):
  139. context = super(DetailServiceView, self).get_context_data(**kwargs)
  140. context["service"] = self.get_data()
  141. context["service_name"] = self.get_data().name
  142. return context
  143. def get_data(self):
  144. if not hasattr(self, "_service"):
  145. try:
  146. service_id = self.kwargs['service_id']
  147. service = api.get_service_datails(self.request, service_id)
  148. except:
  149. redirect = reverse('horizon:project:tabula:index')
  150. exceptions.handle(self.request,
  151. _('Unable to retrieve details for '
  152. 'service "%s".') % service_id,
  153. redirect=redirect)
  154. self._service = service
  155. return self._service
  156. def get_tabs(self, request, *args, **kwargs):
  157. service = self.get_data()
  158. return self.tab_group_class(request, service=service, **kwargs)
  159. class CreateDCView(workflows.WorkflowView):
  160. workflow_class = CreateDC
  161. template_name = 'create_dc.html'
  162. def get_initial(self):
  163. initial = super(CreateDCView, self).get_initial()
  164. initial['project_id'] = self.request.user.tenant_id
  165. initial['user_id'] = self.request.user.id
  166. return initial