From 567e12cc3da501fa6b5306e7b8a9cfc9d465eb1b Mon Sep 17 00:00:00 2001 From: Frederick Borges Date: Tue, 29 Jun 2021 12:06:38 +0200 Subject: [PATCH] B #5438: Fix IP shown on Sunstone (#1336) (cherry picked from commit 4a4fe2ab50f9d36303e8733768104505b19967ed) --- src/sunstone/public/app/opennebula/vm.js | 36 +++++++++++++----------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/sunstone/public/app/opennebula/vm.js b/src/sunstone/public/app/opennebula/vm.js index 1ee67b61ff..a09bc389bd 100644 --- a/src/sunstone/public/app/opennebula/vm.js +++ b/src/sunstone/public/app/opennebula/vm.js @@ -676,7 +676,7 @@ define(function(require) { ? monitoringPool.reduce(function(result, monitoringVM) { return $.extend(result, { [monitoringVM.ID]: monitoringVM }); }, {}) - : {}; + : monitoringPool; }; OpenNebulaAction.list(params, VM_MONITORING_CACHE_NAME, "vm/monitor", process, undefined, false); @@ -887,7 +887,7 @@ define(function(require) { monitoring = cache.data; } - if (!monitoring || $.isEmptyObject(monitoring)) { + if ($.isEmptyObject(monitoring)) { VM.pool_monitor({ success: function(response) { monitoring = response; @@ -996,7 +996,7 @@ define(function(require) { function getNicsFromMonitoring(element = {}) { let monitoringPool = _getMonitoringPool(); - let monitoringVM = monitoringPool[element.ID]; + let monitoringVM = monitoringPool[element.ID] || monitoringPool; if (!monitoringPool || $.isEmptyObject(monitoringPool) || !monitoringVM) return []; @@ -1043,7 +1043,7 @@ define(function(require) { }).join(options.divider) || options.defaultValue; }; - // Return a dropdown with all the IPs + // Return dropdown with all the IPs function ipsDropdown(element, divider) { var ipsHtml = this.ipsStr(element, { divider, groupStrFunction: groupByIpsDropdown, forceGroup: true }); var ips = []; @@ -1086,13 +1086,15 @@ define(function(require) { var non_external_nics = []; nics.forEach(function(nic, index){ - var copy_nic = Object.assign({}, nic); - if (nic.EXTERNAL_IP){ - external_nics.push(nic); - delete copy_nic.EXTERNAL_IP; - } + if (nic.EXTERNAL_IP || nic.IP || nic.IP6 || (nic.IP6_ULA && nic.IP6_GLOBAL) || nic.MAC){ + var copy_nic = Object.assign({}, nic); + if (nic.EXTERNAL_IP){ + external_nics.push(nic); + delete copy_nic.EXTERNAL_IP; + } - non_external_nics.push(copy_nic); + non_external_nics.push(copy_nic); + } }); return external_nics.concat(non_external_nics); @@ -1112,17 +1114,17 @@ define(function(require) { return copy_nics.reduce(function(column, nic) { if (first){ - if (nic.EXTERNAL_IP || nic.IP || nic.IP6 || (nic.IP6_ULA && nic.IP6_GLOBAL)) { - var ip = nic.EXTERNAL_IP || nic.IP || nic.IP6 || nic.IP6_ULA + " " + identation + nic.IP6_GLOBAL; + if (nic.EXTERNAL_IP || nic.IP || nic.IP6 || (nic.IP6_ULA && nic.IP6_GLOBAL) || nic.MAC) { + var ip = nic.EXTERNAL_IP || nic.IP || nic.IP6 || nic.MAC || nic.IP6_ULA + " " + identation + nic.IP6_GLOBAL; nic_and_ip = nic.NIC_ID + ": " + ip; if (nic.EXTERNAL_IP) nic_and_ip = "" + nic_and_ip + "" column.append(nic_and_ip + ""); + first=false; } - first=false; } else{ - if (nic.EXTERNAL_IP || nic.IP || nic.IP6 || (nic.IP6_ULA && nic.IP6_GLOBAL)) { + if (nic.EXTERNAL_IP || nic.IP || nic.IP6 || (nic.IP6_ULA && nic.IP6_GLOBAL) || nic.MAC) { var ip; var nicSection = $("").css("color", "gray"); @@ -1131,7 +1133,7 @@ define(function(require) { nicSection.css("font-weight", "bold"); } else{ - ip = nic.IP || nic.IP6 || nic.IP6_ULA + " " + identation + nic.IP6_GLOBAL; + ip = nic.IP || nic.IP6 || nic.MAC || nic.IP6_ULA + " " + identation + nic.IP6_GLOBAL; } nicSection.html(nic.NIC_ID + ": " + ip); @@ -1182,7 +1184,7 @@ define(function(require) { var identation = "    "; return all_nics.reduce(function(column, nic) { - if (nic.EXTERNAL_IP || nic.IP || nic.IP6 || (nic.IP6_ULA && nic.IP6_GLOBAL)) { + if (nic.EXTERNAL_IP || nic.IP || nic.IP6 || nic.MAC || (nic.IP6_ULA && nic.IP6_GLOBAL)) { var ip; var nicSection = $("

") @@ -1194,7 +1196,7 @@ define(function(require) { nicSection.css("font-weight","bold"); } else { - ip = nic.IP || nic.IP6 || nic.IP6_ULA + "
" + identation + nic.IP6_GLOBAL; + ip = nic.IP || nic.IP6 || nic.MAC || nic.IP6_ULA + "
" + identation + nic.IP6_GLOBAL; } nicSection.html(nic.NIC_ID + ": " + ip);