From bb7c3577dcb9d90a24ff9061f3de10fa9b3538bb Mon Sep 17 00:00:00 2001 From: Timur Nurlygayanov Date: Tue, 12 Mar 2013 19:18:08 +0400 Subject: [PATCH] Added progress bar to Web UI. Fixed pep8 errors. --- dashboard/api/windc.py | 63 ++++++++++++------ dashboard/windc/forms.py | 34 +++++----- dashboard/windc/tables.py | 61 ++++++++++-------- .../windc/templates/windc/_services_tabs.html | 7 +- dashboard/windc/urls.py | 2 +- dashboard/windc/views.py | 64 ++++++++++++------- 6 files changed, 139 insertions(+), 92 deletions(-) diff --git a/dashboard/api/windc.py b/dashboard/api/windc.py index 98b777d4..2f136968 100644 --- a/dashboard/api/windc.py +++ b/dashboard/api/windc.py @@ -51,43 +51,66 @@ def datacenters_get(request, datacenter_id): def datacenters_list(request): return windcclient(request).environments.list() + def datacenters_deploy(request, datacenter_id): - session_id = windcclient(request).sessions.list(datacenter_id)[0].id + sessions = windcclient(request).sessions.list(datacenter_id) + for session in sessions: + if session.state == 'open': + session_id = session.id + if not session_id: + return "Sorry, nothing to deploy." return windcclient(request).sessions.deploy(datacenter_id, session_id) -def services_create(request, datacenter, parameters): - LOG.critical("////////////////////////////////") - LOG.critical(parameters) - LOG.critical("////////////////////////////////") - session_id = windcclient(request).sessions.list(datacenter)[0].id - if parameters['service_type'] == 'active directory': - res = windcclient(request).activeDirectories.create(datacenter, session_id, parameters) + +def datacenters_get_status(request, datacenter_id): + sessions = windcclient(request).sessions.list(datacenter_id) + for session in sessions: + if session.state == 'deployed': + windcclient(request).sessions.delete(datacenter_id, session.id) + sessions = windcclient(request).sessions.list(datacenter_id) + if sessions: + session = sessions[0] else: - res = windcclient(request).webServers.create(datacenter, session_id, parameters) - + session = windcclient(request).sessions.configure(datacenter_id) + + return session.state + + +def services_create(request, datacenter, parameters): + session_id = windcclient(request).sessions.list(datacenter)[0].id + if parameters['service_type'] == 'Active Directory': + res = windcclient(request).activeDirectories.create(datacenter, + session_id, + parameters) + else: + res = windcclient(request).webServers.create(datacenter, + session_id, + parameters) + return res def services_list(request, datacenter_id): session_id = request.user.token.token['id'] services = [] - + + session_id = None sessions = windcclient(request).sessions.list(datacenter_id) for s in sessions: - if s.state == 'open': - windcclient(request).sessions.delete(datacenter_id, s.id) - - session_id = windcclient(request).sessions.configure(datacenter_id).id - services = windcclient(request).activeDirectories.list(datacenter_id, session_id) + if s.state in ['open', 'deployed', 'deploying']: + session_id = s.id + + if session_id is None: + session_id = windcclient(request).sessions.configure(datacenter_id).id + + services = windcclient(request).activeDirectories.list(datacenter_id, + session_id) services += windcclient(request).webServers.list(datacenter_id, session_id) - + return services def services_get(request, datacenter, service_id): - LOG.critical("********************************") - LOG.debug(parameters) - LOG.critical("********************************") return windcclient(request).services.get(datacenter, service_id) diff --git a/dashboard/windc/forms.py b/dashboard/windc/forms.py index 37e17518..f4a2f7ac 100644 --- a/dashboard/windc/forms.py +++ b/dashboard/windc/forms.py @@ -38,9 +38,9 @@ LOG = logging.getLogger(__name__) class WizardFormServiceType(forms.Form): service = forms.ChoiceField(label=_("Service Type"), choices=[ - ('active directory', 'Active Directory'), - ('iis', 'Internet Information Services') - ]) + ('Active Directory', 'Active Directory'), + ('IIS', 'Internet Information Services') + ]) class WizardFormConfiguration(forms.Form): @@ -59,34 +59,32 @@ class WizardFormADConfiguration(forms.Form): initial=1) adm_password = forms.CharField(widget=forms.PasswordInput, - label=_("Administrator password"), required=False) + label=_("Administrator password"), + required=False) recovery_password = forms.CharField(widget=forms.PasswordInput, - label=_("Recovery password"), required=False) - + label=_("Recovery password"), + required=False) + class WizardFormIISConfiguration(forms.Form): iis_name = forms.CharField(label=_("IIS Server Name"), required=False) - - adm_password = forms.CharField(widget=forms.PasswordInput, - label=_("Administrator password"), required=False) - iis_count = forms.IntegerField(label=_("IIS Servers Count"), - required=True, - min_value=1, - max_value=100, - initial=1) + adm_password = forms.CharField(widget=forms.PasswordInput, + label=_("Administrator password"), + required=False) iis_domain = forms.CharField(label=_("Member of the Domain"), required=False) - + domain_user_name = forms.CharField(label=_("Domain User Name"), required=False) - + domain_user_password = forms.CharField(widget=forms.PasswordInput, - label=_("Domain User Password"), required=False) - + label=_("Domain User Password"), + required=False) + class UpdateWinDC(forms.SelfHandlingForm): tenant_id = forms.CharField(widget=forms.HiddenInput) diff --git a/dashboard/windc/tables.py b/dashboard/windc/tables.py index e9564e40..f61714c5 100644 --- a/dashboard/windc/tables.py +++ b/dashboard/windc/tables.py @@ -102,8 +102,8 @@ class DeleteService(tables.BatchAction): ############## api.windc.services_delete(request, datacenter_id, service_id) - - + + class DeployDataCenter(tables.BatchAction): name = "deploy" action_present = _("Deploy") @@ -143,53 +143,62 @@ class ShowDataCenterServices(tables.LinkAction): class UpdateRow(tables.Row): ajax = True - def get_data(self, request, instance_id): - instance = api.nova.server_get(request, instance_id) - instance.full_flavor = api.nova.flavor_get(request, - instance.flavor["id"]) - return instance + def get_data(self, request, datacenter_id): + datacenter = api.windc.datacenters_get(request, datacenter_id) + datacenter.status = api.windc.datacenters_get_status(request, + datacenter_id) + return datacenter + + +STATUS_DISPLAY_CHOICES = ( + ('deploying', 'Deploy in progress'), + ('open', 'Ready to deploy') +) + + +def get_datacenter_status(datacenter): + return datacenter.status class WinDCTable(tables.DataTable): + + STATUS_CHOICES = ( + (None, True), + ("Ready to deploy", False), + ("deploying", True), + ("deployed", True), + ("ready", True), + ("error", False), + ) + name = tables.Column("name", link=("horizon:project:windc:services"), verbose_name=_("Name")) + status = tables.Column(get_datacenter_status, verbose_name=_('Status'), + status=True, + status_choices=STATUS_CHOICES, + display_choices=STATUS_DISPLAY_CHOICES) + class Meta: name = "windc" verbose_name = _("Windows Data Centers") row_class = UpdateRow table_actions = (CreateDataCenter,) + status_columns = ['status'] row_actions = (ShowDataCenterServices, DeleteDataCenter, DeployDataCenter) -STATUS_DISPLAY_CHOICES = ( - ("create", "Deploy"), -) - - class WinServicesTable(tables.DataTable): - STATUS_CHOICES = ( - (None, True), - ("deployed", True), - ("active", True), - ("error", False), - ) - - name = tables.Column('dc_name', verbose_name=_('Name'), + name = tables.Column('name', verbose_name=_('Name'), link=("horizon:project:windc:service_details"),) - _type = tables.Column('type', verbose_name=_('Type')) - status = tables.Column('status', verbose_name=_('Status'), - status=True, - status_choices=STATUS_CHOICES, - display_choices=STATUS_DISPLAY_CHOICES) + _type = tables.Column('service_type', verbose_name=_('Type')) class Meta: name = "services" verbose_name = _("Services") row_class = UpdateRow - status_columns = ['status'] table_actions = (CreateService,) row_actions = (EditService, DeleteService) diff --git a/dashboard/windc/templates/windc/_services_tabs.html b/dashboard/windc/templates/windc/_services_tabs.html index 11737033..86542bb1 100644 --- a/dashboard/windc/templates/windc/_services_tabs.html +++ b/dashboard/windc/templates/windc/_services_tabs.html @@ -27,15 +27,14 @@
{% if wizard.steps.prev %} - {% if service_type == 'active directory' %} -

Active Directory Service

+

{{ service_type }} Service

+ {% if service_type == 'Active Directory' %}

{% trans "Now you can set the parameters for Active Directory Service." %}

{% trans "You can create few Active Directory instances, in this case will be created one Main Active Directory server and few Secondary Active Directory servers." %}

{% trans "The DNS service will be automatically created on each Active Directory servers." %}

{% else %} -

Internet Information Services

{% trans "Now you can set parameters for IIS Service." %}

-

{% trans "The IIS Service - it is the server with complex IIS infrastructure, which included to the domain infrasructure." %}

+

{% trans "The IIS Service - it is the server with complex Internet Information Services infrastructure, which included to the domain infrasructure." %}

{% trans "Please, set the complex password for local administrator account." %}

{% trans "Also, you can add this IIS server to the existing domain and configure credentials for domain user." %}

{% endif %} diff --git a/dashboard/windc/urls.py b/dashboard/windc/urls.py index c8f81b0a..7b5f987c 100644 --- a/dashboard/windc/urls.py +++ b/dashboard/windc/urls.py @@ -28,7 +28,7 @@ VIEW_MOD = 'openstack_dashboard.dashboards.project.windc.views' urlpatterns = patterns(VIEW_MOD, url(r'^$', IndexView.as_view(), name='index'), - url(r'^create$', + url(r'^create$', Wizard.as_view([WizardFormServiceType, WizardFormConfiguration]), name='create'), url(r'^create_dc$', CreateWinDCView.as_view(), name='create_dc'), diff --git a/dashboard/windc/views.py b/dashboard/windc/views.py index 20a650d6..bf9ed7cc 100644 --- a/dashboard/windc/views.py +++ b/dashboard/windc/views.py @@ -58,35 +58,50 @@ class Wizard(ModalFormMixin, SessionWizardView, generic.FormView): link = self.request.__dict__['META']['HTTP_REFERER'] datacenter_id = re.search('windc/(\S+)', link).group(0)[6:-1] url = "/project/windc/%s/" % datacenter_id - + service_type = form_list[0].data.get('0-service', '') parameters = {'service_type': service_type} - - if service_type == 'active directory': + + if service_type == 'Active Directory': parameters['configuration'] = 'standalone' - parameters['name'] = str(form_list[1].data.get('1-dc_name', 'noname')) - parameters['adminPassword'] = str(form_list[1].data.get('1-adm_password', '')) + parameters['name'] = str(form_list[1].data.get('1-dc_name', + 'noname')) + parameters['adminPassword'] = \ + str(form_list[1].data.get('1-adm_password', '')) dc_count = int(form_list[1].data.get('1-dc_count', 1)) - recovery_password = str(form_list[1].data.get('1-recovery_password', '')) + recovery_password = \ + str(form_list[1].data.get('1-recovery_password', '')) parameters['units'] = [] - parameters['units'].append({'isMaster': True, 'recoveryPassword': recovery_password, + parameters['units'].append({'isMaster': True, + 'recoveryPassword': recovery_password, 'location': 'west-dc'}) - for dc in range(dc_count-1): - parameters['units'].append({'isMaster': False, 'recoveryPassword': recovery_password, - 'location': 'west-dc'}) - - elif service_type == 'iis': - parameters['name'] = str(form_list[1].data.get('1-iis_name', 'noname')) + for dc in range(dc_count - 1): + parameters['units'].append({'isMaster': False, + 'recoveryPassword': recovery_password, + 'location': 'west-dc'}) + + elif service_type == 'IIS': + password = form_list[1].data.get('1-adm_password', '') + domain = form_list[1].data.get('1-iis_domain', '') + dc_user = form_list[1].data.get('1-domain_user_name', '') + dc_pass = form_list[1].data.get('1-domain_user_password', '') + parameters['name'] = str(form_list[1].data.get('1-iis_name', + 'noname')) parameters['credentials'] = {'username': 'Administrator', - 'password': str(form_list[1].data.get('1-adm_password', ''))} - parameters['domain'] = {'name': str(form_list[1].data.get('1-iis_domain', '')), - 'username': str(form_list[1].data.get('1-domain_user_name', '')), - 'password': str(form_list[1].data.get('1-domain_user_password', ''))} + 'password': password} + parameters['domain'] = {'name': str(domain), + 'username': str(dc_user), + 'password': str(dc_pass)} parameters['location'] = 'west-dc' + parameters['units'] = [] + parameters['units'].append({'id': '1', + 'endpoint': [{'host': '10.0.0.1'}], + 'location': 'west-dc'}) + service = api.windc.services_create(self.request, datacenter_id, - parameters) + parameters) message = "The %s service successfully created." % service_type messages.success(self.request, message) @@ -98,17 +113,17 @@ class Wizard(ModalFormMixin, SessionWizardView, generic.FormView): if data: service_type = data.get('0-service', '') self.service_type = service_type - if service_type == 'active directory': + if service_type == 'Active Directory': self.form_list['1'] = WizardFormADConfiguration - elif service_type == 'iis': + elif service_type == 'IIS': self.form_list['1'] = WizardFormIISConfiguration return form - + def get_form_step_data(self, form): LOG.debug(form.data) return form.data - + def get_context_data(self, form, **kwargs): context = super(Wizard, self).get_context_data(form=form, **kwargs) if self.steps.index > 0: @@ -121,9 +136,12 @@ class IndexView(tables.DataTableView): template_name = 'project/windc/index.html' def get_data(self): - # Gather our datacenters try: data_centers = api.windc.datacenters_list(self.request) + for dc in data_centers: + # get the information about session status for each dc + dc.status = api.windc.datacenters_get_status(self.request, + dc.id) except: data_centers = [] exceptions.handle(self.request,