From 61a751d0acac1b7bb95c83f5c36fd96cdfb2ed56 Mon Sep 17 00:00:00 2001 From: Hirotaka Wakabayashi Date: Sat, 12 Mar 2022 23:38:05 +0900 Subject: [PATCH] Works around a failure to load openstack dashboard This hack enables to load dashboard correctly by using django based implementation that is used in xena. Ideally, we should use angular based implementation like horizon, but I propose this workaround firstly because the current problem is really painful for us to develop Trove server side without dashboard. Task: 44413 Story: 2009825 Change-Id: I7da457f3a4fccb251288ac8b51df40a25a7e6e4a --- .../_launch_instances_network_help.html | 4 ++ .../templates/databases/_update_networks.html | 37 ++++++++++++++ .../databases/workflows/create_instance.py | 48 +++++++++++++++++-- 3 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 trove_dashboard/content/databases/templates/databases/_launch_instances_network_help.html create mode 100644 trove_dashboard/content/databases/templates/databases/_update_networks.html diff --git a/trove_dashboard/content/databases/templates/databases/_launch_instances_network_help.html b/trove_dashboard/content/databases/templates/databases/_launch_instances_network_help.html new file mode 100644 index 0000000..82714e9 --- /dev/null +++ b/trove_dashboard/content/databases/templates/databases/_launch_instances_network_help.html @@ -0,0 +1,4 @@ +{% load i18n horizon %} + +

{% blocktrans %}Choose network from Available networks to Selected networks by push button or drag and drop, you may change NIC order by drag and drop as well. {% endblocktrans %}

+ diff --git a/trove_dashboard/content/databases/templates/databases/_update_networks.html b/trove_dashboard/content/databases/templates/databases/_update_networks.html new file mode 100644 index 0000000..585109e --- /dev/null +++ b/trove_dashboard/content/databases/templates/databases/_update_networks.html @@ -0,0 +1,37 @@ +{% load i18n %} + + +
+
+ +
    + +
      +
      +
      + {% include "project/databases/_launch_instances_network_help.html" %} +
      +
      + +
      +
      +
      + {% include "horizon/common/_form_fields.html" %} +
      +
      +
      + {{ step.get_help_text }} +
      +
      + + + + diff --git a/trove_dashboard/content/databases/workflows/create_instance.py b/trove_dashboard/content/databases/workflows/create_instance.py index 25470fd..86b0e20 100644 --- a/trove_dashboard/content/databases/workflows/create_instance.py +++ b/trove_dashboard/content/databases/workflows/create_instance.py @@ -23,17 +23,57 @@ from horizon import workflows from openstack_dashboard import api as dash_api from openstack_dashboard.dashboards.project.instances \ import utils as instance_utils -from openstack_dashboard.dashboards.project.instances.workflows \ - import create_instance as dash_create_instance from oslo_log import log as logging - from trove_dashboard import api from trove_dashboard.utils import common as common_utils LOG = logging.getLogger(__name__) +# NOTE(hiwkby): SetNetworkAction is migrated from horizon for compatibiity +class SetNetworkAction(workflows.Action): + network = forms.MultipleChoiceField( + label=_("Networks"), + widget=forms.ThemableCheckboxSelectMultiple(), + error_messages={'required': _("At least one network must be " + "specified.")}, + help_text=_("Launch instance with these networks")) + + def __init__(self, request, *args, **kwargs): + super().__init__(request, *args, **kwargs) + self.use_required_attribute = False + + network_list = self.fields["network"].choices + if len(network_list) == 1: + self.fields['network'].initial = [network_list[0][0]] + + class Meta(object): + name = _("Networking") + permissions = ('openstack.services.network',) + help_text = _("Select networks for your instance.") + + def populate_network_choices(self, request, context): + return instance_utils.network_field_data(request, for_launch=True) + + +# NOTE(hiwkby): SetNetwork is migrated from horizon for compatibiity +class SetNetwork(workflows.Step): + action_class = SetNetworkAction + template_name = "project/databases/_update_networks.html" + contributes = ("network_id",) + + def contribute(self, data, context): + if data: + networks = self.workflow.request.POST.getlist("network") + # If no networks are explicitly specified, network list + # contains an empty string, so remove it. + networks = [n for n in networks if n != ''] + if networks: + context['network_id'] = networks + return context + + def parse_datastore_and_version_text(datastore_and_version): if datastore_and_version: datastore, datastore_version = datastore_and_version.split('-', 1) @@ -540,7 +580,7 @@ class LaunchInstance(workflows.Workflow): failure_message = _('Unable to launch %(count)s named "%(name)s".') success_url = "horizon:project:databases:index" default_steps = (SetInstanceDetails, - dash_create_instance.SetNetwork, + SetNetwork, DatabaseAccess, InitializeDatabase, Advanced)