From 34c7d1fbb51ea5f53a4713e6ae8fad0f54f94f31 Mon Sep 17 00:00:00 2001 From: Sergio Betanzos Date: Thu, 28 Jan 2021 19:46:07 +0100 Subject: [PATCH] F #5159: Add attach external nic alias (#718) --- .../form-panels/create/wizard-tabs/network.js | 2 +- .../create/wizard-tabs/network/nic-tab.js | 20 ++++++++-- .../wizard-tabs/network/nic-tab/html.hbs | 40 +++++++++++++------ .../app/tabs/vms-tab/dialogs/attach-nic.js | 6 +++ .../tabs/vms-tab/dialogs/attach-nic/html.hbs | 8 +++- src/sunstone/public/app/utils/nics-section.js | 25 +++++++++--- .../public/app/utils/nics-section/dd.hbs | 40 +++++++++++++------ 7 files changed, 104 insertions(+), 37 deletions(-) diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/network.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/network.js index 725b51da06..f97bc4834f 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/network.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/network.js @@ -205,7 +205,7 @@ define(function(require) { nicTab.fill(nicContext, nicJSON); if (nicJSON.PARENT) { - nicTab.fill_alias(nicJSON.PARENT); + nicTab.fill_alias(nicJSON.PARENT, nicJSON.EXTERNAL); } }); diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/network/nic-tab.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/network/nic-tab.js index 4b83e69263..37dfd58dcd 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/network/nic-tab.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/network/nic-tab.js @@ -218,7 +218,6 @@ define(function(require) { $("input#" + this.nicTabId + "_interface_type", context).on("change", function(){ var alias_on = $(this).prop("checked"); var alias; - var found = false; $.each(that.nics, function(index, value) { if (value.ALIAS === ("NIC" + that.nicId)) { @@ -233,17 +232,20 @@ define(function(require) { if (that.nics.length == 1 && alias_on) { $("#" + that.nicTabId + "_alias_parent", context).hide(); + $("#" + that.nicTabId + "_alias_external_wrapper", context).hide(); $(".network_selection", context).hide(); $("#" + that.nicTabId + "_no_alias", context).html("No NIC available"); $("#" + that.nicTabId + "_no_alias").show(); } else { if(alias_on && !alias) { $("#" + that.nicTabId + "_alias_parent", context).show(); + $("#" + that.nicTabId + "_alias_external_wrapper", context).show(); $("#" + that.nicTabId + "_alias_parent", context).click(); $(".network_selection", context).hide(); $("#" + that.nicTabId + "_no_alias").hide(); } else if (alias_on && alias) { $("#" + that.nicTabId + "_alias_parent", context).hide(); + $("#" + that.nicTabId + "_alias_external_wrapper", context).hide(); $(".network_selection", context).hide(); $("#" + that.nicTabId + "_no_alias").show(); } else { @@ -257,6 +259,7 @@ define(function(require) { _hide_remove(that.nics); $("#" + that.nicTabId + "_alias_parent", context).hide(); + $("#" + that.nicTabId + "_alias_external_wrapper", context).hide(); $(".network_selection", context).show(); $("#" + that.nicTabId + "_no_alias").hide(); } @@ -302,6 +305,7 @@ define(function(require) { }); $("#" + this.nicTabId + "_alias_parent", context).hide(); + $("#" + that.nicTabId + "_alias_external_wrapper", context).hide(); context.on("change", "input[name='" + that.nicTabId + "_req_select']", function() { if ($("input[name='" + that.nicTabId + "_req_select']:checked").val() == "vnet_select") { @@ -371,6 +375,10 @@ define(function(require) { delete nicJSON["PARENT"]; } else { nicJSON["PARENT"] = $("#" + this.nicTabId + "_alias_parent", context).val(); + + if ($("#" + this.nicTabId + "_alias_external", context).is(':checked')) { + nicJSON["EXTERNAL"] = 'YES'; + } } if($("input#" + this.nicTabId + "_rdp", context).prop("checked")) { @@ -519,10 +527,10 @@ define(function(require) { $("input#"+this.nicTabId+"_SCHED_REQUIREMENTS", context).val(req_string.join(" | ")); }; - function _fill_alias(nicname) { + function _fill_alias(nicParentName, isExternal) { $.each(this.nics, function(index, value) { if (value.NAME == ("NIC" + that.nicId)) { - value.ALIAS = nicname; + value.ALIAS = nicParentName; } }); @@ -530,7 +538,11 @@ define(function(require) { $("#" + this.nicTabId + "_alias_parent", this.context).show(); $("#" + this.nicTabId + "_alias_parent", this.context).click(); $("#" + this.nicTabId + "_interface_type", this.context).click(); - $("#" + this.nicTabId + "_alias_parent", this.context).val(nicname); + $("#" + this.nicTabId + "_alias_parent", this.context).val(nicParentName); + + if (isExternal && String(isExternal).toLowerCase() === 'yes') { + $("#" + this.nicTabId + "_alias_external", this.context).prop('checked', 'checked'); + } } function _hide_remove(nics) { diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/network/nic-tab/html.hbs b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/network/nic-tab/html.hbs index 058acc24b9..ac84d76d6d 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/network/nic-tab/html.hbs +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/network/nic-tab/html.hbs @@ -18,21 +18,35 @@
{{tr "Interface type"}} -
- -
{{tr "Network selection"}} diff --git a/src/sunstone/public/app/tabs/vms-tab/dialogs/attach-nic.js b/src/sunstone/public/app/tabs/vms-tab/dialogs/attach-nic.js index b044d5418a..9672f4b25d 100644 --- a/src/sunstone/public/app/tabs/vms-tab/dialogs/attach-nic.js +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/attach-nic.js @@ -79,9 +79,11 @@ define(function(require) { Tips.setup(context); $("#parent", context).hide(); + $(".attach_external", context).hide(); $("#cb_attach_alias", context).change(function() { $("#parent", context).toggle(this.checked); + $(".attach_external", context).toggle(this.checked); }); $("#" + DIALOG_ID + "Form", context).submit(function() { @@ -95,6 +97,10 @@ define(function(require) { if($("#cb_attach_alias", context).prop("checked")) { templateJSON.PARENT = $("#parent").val(); + if ($('#cb_external').is(':checked')) { + templateJSON.EXTERNAL = 'YES' + } + var obj = { "NIC_ALIAS": templateJSON }; diff --git a/src/sunstone/public/app/tabs/vms-tab/dialogs/attach-nic/html.hbs b/src/sunstone/public/app/tabs/vms-tab/dialogs/attach-nic/html.hbs index 306d7417c3..b6d2a26665 100644 --- a/src/sunstone/public/app/tabs/vms-tab/dialogs/attach-nic/html.hbs +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/attach-nic/html.hbs @@ -32,7 +32,13 @@ -
+ +
+
+
+
{{{nicTabHTML}}}