From af46a6123ef79d2609abbe74ecfaf895b90e9a17 Mon Sep 17 00:00:00 2001 From: Duk Loi Date: Mon, 2 May 2016 19:50:26 -0400 Subject: [PATCH] Delegate network panel to instance network panel The network panel in Trove's launch instance panel is a duplicate of the Nova launch instance panel. Delegate the call in the Trove panel to use the Nove network panel to avoid code skew. Change-Id: I623e67a062654cfd62aa627b0b7ee4517413bcd4 Closes-Bug: #1580527 --- .../databases/workflows/create_instance.py | 57 ++----------------- 1 file changed, 4 insertions(+), 53 deletions(-) diff --git a/trove_dashboard/content/databases/workflows/create_instance.py b/trove_dashboard/content/databases/workflows/create_instance.py index 1842858..7e9b8af 100644 --- a/trove_dashboard/content/databases/workflows/create_instance.py +++ b/trove_dashboard/content/databases/workflows/create_instance.py @@ -25,6 +25,9 @@ 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 trove_dashboard import api @@ -144,58 +147,6 @@ class SetInstanceDetails(workflows.Step): contributes = ("name", "volume", "volume_type", "flavor", "datastore") -class SetNetworkAction(workflows.Action): - network = forms.MultipleChoiceField(label=_("Networks"), - widget=forms.CheckboxSelectMultiple(), - error_messages={ - 'required': _( - "At least one network must" - " be specified.")}, - help_text=_("Launch instance with" - " these networks")) - - def __init__(self, request, *args, **kwargs): - super(SetNetworkAction, self).__init__(request, *args, **kwargs) - 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): - try: - tenant_id = self.request.user.tenant_id - networks = dash_api.neutron.network_list_for_tenant(request, - tenant_id) - network_list = [(network.id, network.name_or_id) - for network in networks] - except Exception: - network_list = [] - exceptions.handle(request, - _('Unable to retrieve networks.')) - return network_list - - -class SetNetwork(workflows.Step): - action_class = SetNetworkAction - template_name = "project/databases/_launch_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 - - class AddDatabasesAction(workflows.Action): """Initialize the database with users/databases. This tab will honor the settings which should be a list of permissions required: @@ -368,7 +319,7 @@ class LaunchInstance(workflows.Workflow): failure_message = _('Unable to launch %(count)s named "%(name)s".') success_url = "horizon:project:databases:index" default_steps = (SetInstanceDetails, - SetNetwork, + dash_create_instance.SetNetwork, InitializeDatabase, Advanced)