From a787f45c99f207f4ec4178ebfd8ae625e325af90 Mon Sep 17 00:00:00 2001 From: Jorge Lobo Date: Tue, 7 May 2019 13:09:53 +0200 Subject: [PATCH] B #3101 multiple entries for a VF nic Signed-off-by: Jorge Lobo --- src/sunstone/public/app/opennebula/vm.js | 8 +- .../public/app/tabs/vms-tab/panels/network.js | 297 +++++++++--------- src/sunstone/routes/support.rb | 6 +- 3 files changed, 157 insertions(+), 154 deletions(-) diff --git a/src/sunstone/public/app/opennebula/vm.js b/src/sunstone/public/app/opennebula/vm.js index 5480deaf750..b3d77e56cc3 100644 --- a/src/sunstone/public/app/opennebula/vm.js +++ b/src/sunstone/public/app/opennebula/vm.js @@ -756,7 +756,6 @@ define(function(require) { var nic = element.TEMPLATE.NIC; var pci = element.TEMPLATE.PCI; var ips = []; - var monitoring = element.MONITORING; if (monitoring) { var externalIP; @@ -805,12 +804,13 @@ define(function(require) { }); }); } - + r=null; if (ips.length > 0) { - return ips.join(divider); + r = ips.join(divider); } else { - return "--"; + r = "--"; } + return r; }; // Return the Alias or several Aliases of a VM diff --git a/src/sunstone/public/app/tabs/vms-tab/panels/network.js b/src/sunstone/public/app/tabs/vms-tab/panels/network.js index dab8d2bf016..554153ac4df 100644 --- a/src/sunstone/public/app/tabs/vms-tab/panels/network.js +++ b/src/sunstone/public/app/tabs/vms-tab/panels/network.js @@ -19,29 +19,29 @@ define(function(require) { DEPENDENCIES */ - var Locale = require('utils/locale'); - var Config = require('sunstone-config'); - var Sunstone = require('sunstone'); - var Humanize = require('utils/humanize'); - var Notifier = require('utils/notifier'); - var Graphs = require('utils/graphs'); - require('flot.navigate'); - require('flot.canvas'); - var StateActions = require('../utils/state-actions'); - var OpenNebulaVM = require('opennebula/vm'); - var SecGroupsCommon = require('tabs/secgroups-tab/utils/common'); - var Navigation = require('utils/navigation'); + var Locale = require("utils/locale"); + var Config = require("sunstone-config"); + var Sunstone = require("sunstone"); + var Humanize = require("utils/humanize"); + var Notifier = require("utils/notifier"); + var Graphs = require("utils/graphs"); + require("flot.navigate"); + require("flot.canvas"); + var StateActions = require("../utils/state-actions"); + var OpenNebulaVM = require("opennebula/vm"); + var SecGroupsCommon = require("tabs/secgroups-tab/utils/common"); + var Navigation = require("utils/navigation"); /* CONSTANTS */ - var TAB_ID = require('../tabId'); - var PANEL_ID = require('./network/panelId'); - var ATTACH_NIC_DIALOG_ID = require('../dialogs/attach-nic/dialogId'); - var CONFIRM_DIALOG_ID = require('utils/dialogs/generic-confirm/dialogId'); - var RESOURCE = "VM" - var XML_ROOT = "VM" + var TAB_ID = require("../tabId"); + var PANEL_ID = require("./network/panelId"); + var ATTACH_NIC_DIALOG_ID = require("../dialogs/attach-nic/dialogId"); + var CONFIRM_DIALOG_ID = require("utils/dialogs/generic-confirm/dialogId"); + var RESOURCE = "VM"; + var XML_ROOT = "VM"; /* CONSTRUCTOR @@ -72,140 +72,140 @@ define(function(require) { function _html() { var that = this; - var html = '
\ -
\ -
\ - \ + var html = "\ +
\ +
\ +
\ \ \ \ - \ - \ - \ - \ - \ - \ - \ - \ - \ + \ + \ + \ + \ + \ + \ + \ + \ + html += "\ \ \ \ \
' + Locale.tr("ID") + '' + Locale.tr("Network") + '' + Locale.tr("IP") + '' + Locale.tr("MAC") + '' + Locale.tr("PCI address") + '' + Locale.tr("IPv6 ULA") + '' + Locale.tr("IPv6 Global") + '' + Locale.tr("Actions") + '' ; + " + Locale.tr("ID") + "" + Locale.tr("Network") + "" + Locale.tr("IP") + "" + Locale.tr("MAC") + "" + Locale.tr("PCI address") + "" + Locale.tr("IPv6 ULA") + "" + Locale.tr("IPv6 Global") + "" + Locale.tr("Actions") + "" ; if (Config.isTabActionEnabled("vms-tab", "VM.attachnic")) { if (StateActions.enabledStateAction("VM.attachnic", that.element.STATE, that.element.LCM_STATE) && OpenNebulaVM.isNICAttachSupported(that.element)) { - html += '\ - ' + html += "\ + "; } else { - html += '\ - ' + html += "\ + "; } } - html += '
\
\ -
' ; + " ; var externalNetworkAttrs = OpenNebulaVM.retrieveExternalNetworkAttrs(that.element); if (!$.isEmptyObject(externalNetworkAttrs)) { - html += '
' + - '
' + - '' + - '' + - '' + - '' + - '' + - '' + - ''; + html += "
" + + "
" + + "
' + Locale.tr("Network Monitoring Attributes") + '
" + + "" + + "" + + "" + + "" + + "" + + ""; $.each(externalNetworkAttrs, function(key, value) { - html += '' + - '' + - '' + - ''; + html += "" + + "" + + "" + + ""; }); - html += '' + - '
" + Locale.tr("Network Monitoring Attributes") + "
' + key + '' + value + '
" + key + "" + value + "
' + - '
' + - '
'; + html += "" + + "" + + "" + + ""; } // Do not show statistics for not hypervisors that do not gather net data if (OpenNebulaVM.isNICGraphsSupported(that.element)) { - html += '\ -
\ -
\ -
\ - ' + Locale.tr("NET RX") + '\ + html += "\ +
\ +
\ +
\ + " + Locale.tr("NET RX") + "\
\ -
\ -
\ - \ - \ +
\ +
\ + \ + \ \
\
\ -
\ -
\ +
\ +
\
\
\
\ -
\ -
\ - ' + Locale.tr("NET TX") + '\ +
\ +
\ + " + Locale.tr("NET TX") + "\
\ -
\ -
\ - \ - \ +
\ +
\ + \ + \ \
\
\ -
\ -
\ +
\ +
\
\
\
\ -
\ -
\ - ' + Locale.tr("NET DOWNLOAD SPEED") + '\ +
\ +
\ + " + Locale.tr("NET DOWNLOAD SPEED") + "\
\ -
\ -
\ - \ - \ +
\ +
\ + \ + \ \
\
\ -
\ -
\ +
\ +
\
\
\
\ -
\ -
\ - ' + Locale.tr("NET UPLOAD SPEED") + '\ +
\ +
\ + " + Locale.tr("NET UPLOAD SPEED") + "\
\ -
\ -
\ - \ - \ +
\ +
\ + \ + \ \
\
\ -
\ -
\ +
\ +
\
\
\
\
\ - '; + "; } return html; @@ -228,9 +228,12 @@ define(function(require) { function _setup(context) { var that = this; - var nics = [] - var nics_names = [] - var alias = [] + var nics = []; + var nics_names = []; + var alias = []; + var distinct = function(value, index, self){ + return self.indexOf(value)===index; + }; if ($.isArray(that.element.TEMPLATE.NIC)){ nics = that.element.TEMPLATE.NIC; @@ -238,6 +241,7 @@ define(function(require) { nics = [that.element.TEMPLATE.NIC]; } + if ($.isArray(that.element.TEMPLATE.NIC_ALIAS)){ alias = that.element.TEMPLATE.NIC_ALIAS; } else if (!$.isEmptyObject(that.element.TEMPLATE.NIC_ALIAS)){ @@ -259,9 +263,8 @@ define(function(require) { }); var nic_dt_data = []; + nics = nics.filter(distinct); if (nics.length) { - var nic_dt_data = []; - for (var i = 0; i < nics.length; i++) { var nic = nics[i]; @@ -269,16 +272,16 @@ define(function(require) { var is_pci = (nic.PCI_ID != undefined); - var actions = ''; + var actions = ""; // Attach / Detach if (!is_pci){ if ( (that.element.STATE == OpenNebulaVM.STATES.ACTIVE) && (that.element.LCM_STATE == OpenNebulaVM.LCM_STATES.HOTPLUG_NIC)) { - actions = Locale.tr("attach/detach in progress") + actions = Locale.tr("attach/detach in progress"); } else { if ( (Config.isTabActionEnabled("vms-tab", "VM.detachnic")) && (StateActions.enabledStateAction("VM.detachnic", that.element.STATE, that.element.LCM_STATE))) { - actions += '' + actions += ""; } } } @@ -306,11 +309,11 @@ define(function(require) { }); } - var pci_address = is_pci ? nic.ADDRESS : ''; + var pci_address = is_pci ? nic.ADDRESS : ""; var ipStr = "IP"; if (nic.IP6 !== undefined){ - ipStr = "IP6" + ipStr = "IP6"; } var nic_alias = []; @@ -348,10 +351,10 @@ define(function(require) { "data": nic_dt_data, "columns": [ { - "class": 'open-control', + "class": "open-control", "orderable": false, "data": null, - "defaultContent": '' + "defaultContent": "" }, {"data": "NIC_ID", "defaultContent": ""}, {"data": "NETWORK", "defaultContent": ""}, @@ -369,79 +372,79 @@ define(function(require) { if (aData.SECURITY_GROUP_RULES == undefined || aData.SECURITY_GROUP_RULES.length == 0) { - $("td.open-control", nRow).html("").removeClass('open-control'); + $("td.open-control", nRow).html("").removeClass("open-control"); } $(nRow).attr("nic_id", aData.NIC_ID); } }); - $("#tab_network_form .nics_table", context).dataTable().fnSort([[1, 'asc']]); + $("#tab_network_form .nics_table", context).dataTable().fnSort([[1, "asc"]]); // Add event listener for opening and closing each NIC row details - context.off('click', '#tab_network_form .nics_table td.open-control') - context.on('click', '#tab_network_form .nics_table td.open-control', function () { - var row = $(this).closest('table').DataTable().row($(this).closest('tr')); + context.off("click", "#tab_network_form .nics_table td.open-control"); + context.on("click", "#tab_network_form .nics_table td.open-control", function () { + var row = $(this).closest("table").DataTable().row($(this).closest("tr")); if (row.child.isShown()) { row.child.hide(); - $(this).children("span").addClass('fa-chevron-down'); - $(this).children("span").removeClass('fa-chevron-up'); + $(this).children("span").addClass("fa-chevron-down"); + $(this).children("span").removeClass("fa-chevron-up"); } else { if(row.data().NIC_ALIAS.length > 0) { - var html = ''; + var html = ""; $.each(row.data().NIC_ALIAS, function(index, elem) { - var new_div = '
' + - '' + "- Alias-" + this.ALIAS_ID + ":" + '' + + var new_div = "
" + + "" + "- Alias-" + this.ALIAS_ID + ":" + "" + "   " + this.IP + "   " + this.MAC + - "   " + this.ACTIONS + '
'; + "   " + this.ACTIONS + "
"; html += new_div; if (Config.isTabActionEnabled("vms-tab", "VM.detachnic")) { - context.off('click', '.detachnic'); - context.on('click', '.detachnic', {element_id: that.element.ID}, detach_alias); + context.off("click", ".detachnic"); + context.on("click", ".detachnic", {element_id: that.element.ID}, detach_alias); } }); } else { - html = ''; + html = ""; } - html += '
\ - \ + html += "
\ +
\ \ \ - \ - \ - \ - \ - \ - \ + \ + \ + \ + \ + \ + \ \ \ - ' ; + " ; $.each(row.data().SECURITY_GROUP_RULES, function(index, elem) { var rule_st = SecGroupsCommon.sgRuleToSt(this); - var new_tr = '\ - \ - \ - \ - \ - \ - \ - \ - ' + var new_tr = "\ + \ + \ + \ + \ + \ + \ + \ + "; html += new_tr; }); row.child(html).show(); - $(this).children("span").removeClass('fa-chevron-down'); - $(this).children("span").addClass('fa-chevron-up'); + $(this).children("span").removeClass("fa-chevron-down"); + $(this).children("span").addClass("fa-chevron-up"); $.each(row.data().NIC_ALIAS, function(index, elem) { $("#alias_" + this.NIC_ID).attr("nic_id", this.NIC_ID); }); @@ -449,8 +452,8 @@ define(function(require) { }); if (Config.isTabActionEnabled("vms-tab", "VM.attachnic")) { - context.off('click', '#attach_nic'); - context.on('click', '#attach_nic', function() { + context.off("click", "#attach_nic"); + context.on("click", "#attach_nic", function() { var dialog = Sunstone.getDialog(ATTACH_NIC_DIALOG_ID); dialog.setElement(that.element); dialog.setNicsNames(nics_names); @@ -460,9 +463,9 @@ define(function(require) { } if (Config.isTabActionEnabled("vms-tab", "VM.detachnic")) { - context.off('click', '.detachnic'); - context.on('click', '.detachnic', function() { - var nic_id = $(this).parents('tr').attr('nic_id'); + context.off("click", ".detachnic"); + context.on("click", ".detachnic", function() { + var nic_id = $(this).parents("tr").attr("nic_id"); Sunstone.getDialog(CONFIRM_DIALOG_ID).setParams({ //header : @@ -470,7 +473,7 @@ define(function(require) { body : Locale.tr("This will detach the nic immediately"), //question : submit : function(){ - Sunstone.runAction('VM.detachnic', that.element.ID, nic_id); + Sunstone.runAction("VM.detachnic", that.element.ID, nic_id); return false; } }); @@ -493,7 +496,7 @@ define(function(require) { body : Locale.tr("This will detach the alias immediately"), //question : submit : function(){ - Sunstone.runAction('VM.detachnic', element_id, nic_id); + Sunstone.runAction("VM.detachnic", element_id, nic_id); return false; } }); @@ -575,7 +578,7 @@ define(function(require) { var that = this; $.each(state["openNicsDetails"], function(){ - $('#tab_network_form .nics_table tr[nic_id="'+this+'"] td.open-control', context).click(); + $("#tab_network_form .nics_table tr[nic_id=\""+this+"\"] td.open-control", context).click(); }); } }); diff --git a/src/sunstone/routes/support.rb b/src/sunstone/routes/support.rb index 41cbbc791f1..579acba6607 100644 --- a/src/sunstone/routes/support.rb +++ b/src/sunstone/routes/support.rb @@ -229,17 +229,17 @@ def check_zendesk_api_gem 'OpenNebula Subscription Validation' end rescue StandardError - [400, JSON.pretty_generate(:pass => false)] + [400, JSON.pretty_generate({:pass => false, :error=> 'error curl'})] end if !http.nil? && http.response_code < 400 $conf[:one_support_time] = Time.now.to_i [200, JSON.pretty_generate(:pass => true)] else - [400, JSON.pretty_generate(:pass => false)] + [400, JSON.pretty_generate({:pass => false, :error=> 'http code' + http})] end else - [400, JSON.pretty_generate(:pass => false)] + [400, JSON.pretty_generate({:pass => false, :error=> 'empty or nil version or token'})] end end
' + Locale.tr("Security Group") + '' + Locale.tr("Protocol") + '' + Locale.tr("Type") + '' + Locale.tr("Range") + '' + Locale.tr("Network") + '' + Locale.tr("ICMP Type") + '" + Locale.tr("Security Group") + "" + Locale.tr("Protocol") + "" + Locale.tr("Type") + "" + Locale.tr("Range") + "" + Locale.tr("Network") + "" + Locale.tr("ICMP Type") + "
' + this.SECURITY_GROUP_ID + '' + Navigation.link(this.SECURITY_GROUP_NAME, "secgroups-tab", this.SECURITY_GROUP_ID) + '' + rule_st.PROTOCOL + '' + rule_st.RULE_TYPE + '' + rule_st.RANGE + '' + rule_st.NETWORK + '' + rule_st.ICMP_TYPE + '
" + this.SECURITY_GROUP_ID + "" + Navigation.link(this.SECURITY_GROUP_NAME, "secgroups-tab", this.SECURITY_GROUP_ID) + "" + rule_st.PROTOCOL + "" + rule_st.RULE_TYPE + "" + rule_st.RANGE + "" + rule_st.NETWORK + "" + rule_st.ICMP_TYPE + "