189 lines
		
	
	
		
			6.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			189 lines
		
	
	
		
			6.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| # vim: tabstop=4 shiftwidth=4 softtabstop=4
 | |
| 
 | |
| # Copyright 2012 United States Government as represented by the
 | |
| # Administrator of the National Aeronautics and Space Administration.
 | |
| # All Rights Reserved.
 | |
| #
 | |
| # Copyright 2012 Nebula, Inc.
 | |
| #
 | |
| #    Licensed under the Apache License, Version 2.0 (the "License"); you may
 | |
| #    not use this file except in compliance with the License. You may obtain
 | |
| #    a copy of the License at
 | |
| #
 | |
| #         http://www.apache.org/licenses/LICENSE-2.0
 | |
| #
 | |
| #    Unless required by applicable law or agreed to in writing, software
 | |
| #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 | |
| #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 | |
| #    License for the specific language governing permissions and limitations
 | |
| #    under the License.
 | |
| 
 | |
| import json
 | |
| import logging
 | |
| 
 | |
| from django.utils.text import normalize_newlines
 | |
| from django.utils.translation import ugettext as _
 | |
| 
 | |
| from horizon import exceptions
 | |
| from horizon import forms
 | |
| from horizon import workflows
 | |
| 
 | |
| from openstack_dashboard import api
 | |
| 
 | |
| 
 | |
| LOG = logging.getLogger(__name__)
 | |
| 
 | |
| 
 | |
| class SelectProjectUserAction(workflows.Action):
 | |
|     project_id = forms.ChoiceField(label=_("Project"))
 | |
|     user_id = forms.ChoiceField(label=_("User"))
 | |
| 
 | |
|     def __init__(self, request, *args, **kwargs):
 | |
|         super(SelectProjectUserAction, self).__init__(request, *args, **kwargs)
 | |
|         # Set our project choices
 | |
|         projects = [(tenant.id, tenant.name)
 | |
|                     for tenant in request.user.authorized_tenants]
 | |
|         self.fields['project_id'].choices = projects
 | |
| 
 | |
|         # Set our user options
 | |
|         users = [(request.user.id, request.user.username)]
 | |
|         self.fields['user_id'].choices = users
 | |
| 
 | |
|     class Meta:
 | |
|         name = _("Project & User")
 | |
|         # Unusable permission so this is always hidden. However, we
 | |
|         # keep this step in the workflow for validation/verification purposes.
 | |
|         permissions = ("!",)
 | |
| 
 | |
| 
 | |
| class SelectProjectUser(workflows.Step):
 | |
|     action_class = SelectProjectUserAction
 | |
| 
 | |
| 
 | |
| class ConfigureDCAction(workflows.Action):
 | |
|     name = forms.CharField(label=_("Data Center Name"),
 | |
|                               required=True)
 | |
| 
 | |
|     class Meta:
 | |
|         name = _("Data Center")
 | |
|         help_text_template = ("project/windc/_data_center_help.html")
 | |
| 
 | |
| 
 | |
| class ConfigureDC(workflows.Step):
 | |
|     action_class = ConfigureDCAction
 | |
|     contibutes = ("name",)
 | |
| 
 | |
|     def contribute(self, data, context):
 | |
|         if data:
 | |
|             context['name'] = data.get("name", "")
 | |
|         return context
 | |
| 
 | |
| 
 | |
| class ConfigureWinDCAction(workflows.Action):
 | |
|     dc_name = forms.CharField(label=_("Domain Name"),
 | |
|                               required=False)
 | |
| 
 | |
|     dc_net_name = forms.CharField(label=_("Domain NetBIOS Name"),
 | |
|                                   required=False,
 | |
|                                   help_text=_("A NetBIOS name of new domain."))
 | |
| 
 | |
|     dc_count = forms.IntegerField(label=_("Domain Controllers Count"),
 | |
|                                   required=True,
 | |
|                                   min_value=1,
 | |
|                                   max_value=100,
 | |
|                                   initial=1)
 | |
| 
 | |
|     adm_password = forms.CharField(widget=forms.PasswordInput,
 | |
|                                    label=_("Administrator password"),
 | |
|                                    required=False,
 | |
|                                    help_text=_("Password for "
 | |
|                                                "administrator account."))
 | |
| 
 | |
|     recovery_password = forms.CharField(widget=forms.PasswordInput,
 | |
|                                    label=_("Recovery password"),
 | |
|                                    required=False,
 | |
|                                    help_text=_("Password for "
 | |
|                                                "Active Directory "
 | |
|                                                "Recovery Mode."))
 | |
| 
 | |
|     class Meta:
 | |
|         name = _("Domain Controllers")
 | |
|         help_text_template = ("project/windc/_dc_help.html")
 | |
| 
 | |
| 
 | |
| class ConfigureWinDC(workflows.Step):
 | |
|     action_class = ConfigureWinDCAction
 | |
| 
 | |
| 
 | |
| class ConfigureWinIISAction(workflows.Action):
 | |
|     iis_name = forms.CharField(label=_("IIS Server Name"),
 | |
|                                required=False)
 | |
| 
 | |
|     iis_count = forms.IntegerField(label=_("IIS Servers Count"),
 | |
|                                    required=True,
 | |
|                                    min_value=1,
 | |
|                                    max_value=100,
 | |
|                                    initial=1)
 | |
| 
 | |
|     iis_domain = forms.CharField(label=_("Member of the Domain"),
 | |
|                                  required=False,
 | |
|                                  help_text=_("A name of domain for"
 | |
|                                              " IIS Server."))
 | |
| 
 | |
|     class Meta:
 | |
|         name = _("Internet Information Services")
 | |
|         help_text_template = ("project/windc/_iis_help.html")
 | |
| 
 | |
| 
 | |
| class ConfigureWinIIS(workflows.Step):
 | |
|     action_class = ConfigureWinIISAction
 | |
| 
 | |
| 
 | |
| class CreateWinService(workflows.Workflow):
 | |
|     slug = "create"
 | |
|     name = _("Create Service")
 | |
|     finalize_button_name = _("Deploy")
 | |
|     success_message = _('Created service "%s".')
 | |
|     failure_message = _('Unable to create service "%s".')
 | |
|     success_url = "horizon:project:windc:services"
 | |
|     default_steps = (SelectProjectUser,
 | |
|                      ConfigureWinDC,
 | |
|                      ConfigureWinIIS)
 | |
| 
 | |
|     def format_status_message(self, message):
 | |
|         name = self.context.get('name', 'noname')
 | |
|         return message % name
 | |
| 
 | |
|     def handle(self, request, context):
 | |
|         try:
 | |
|             datacenter = context.get('domain_controller_name', '')
 | |
|             service = api.windc.services_create(request, context)
 | |
|             return True
 | |
|         except:
 | |
|             exceptions.handle(request)
 | |
|             return False
 | |
| 
 | |
| 
 | |
| 
 | |
| class CreateWinDC(workflows.Workflow):
 | |
|     slug = "create"
 | |
|     name = _("Create Windows Data Center")
 | |
|     finalize_button_name = _("Create")
 | |
|     success_message = _('Created data center "%s".')
 | |
|     failure_message = _('Unable to create data center "%s".')
 | |
|     success_url = "horizon:project:windc:index"
 | |
|     default_steps = (SelectProjectUser,
 | |
|                      ConfigureDC)
 | |
| 
 | |
|     def format_status_message(self, message):
 | |
|         name = self.context.get('name', 'noname')
 | |
|         return message % name
 | |
| 
 | |
|     def handle(self, request, context):
 | |
|         try:
 | |
|             datacenter = api.windc.datacenters_create(request, context)
 | |
|             return True
 | |
|         except:
 | |
|             exceptions.handle(request)
 | |
|             return False
 | 
