1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

B #5037: fix malformed VM IPs (#431)

Signed-off-by: Frederick Borges <fborges@opennebula.io>
(cherry picked from commit d2d7e546c611770bee27d6dc3abc5caea388fbda)
This commit is contained in:
Frederick Borges 2020-11-17 12:55:35 +01:00 committed by Tino Vazquez
parent 766f0f86fa
commit 76636eeae1
No known key found for this signature in database
GPG Key ID: 14201E424D02047E
2 changed files with 39 additions and 14 deletions

View File

@ -789,7 +789,7 @@ define(function(require) {
}
// Return the IP or several IPs of a VM
function ipsStr(element, divider, groupStrFuntion = groupByIpsStr) {
function ipsStr(element, divider, groupStrFunction = groupByIpsStr) {
var divider = divider || "<br>";
var nics = getNICs(element);
var ips = [];
@ -808,6 +808,7 @@ define(function(require) {
}
});
}
// infoextended: alias will be group by nic
return Config.isExtendedVmInfo
? groupStrFuntion(element, nics)
@ -816,11 +817,22 @@ define(function(require) {
if (nic["IP"]) {
return nic["IP"];
}
else{
var ipv6 = ""
if (nic["IP6_ULA"]){
ipv6 += nic["IP6_ULA"];
}
if (nic["IP6_GLOBAL"]){
ipv6 = (ipv6 == "") ? "" : ipv6 + "<br>";
ipv6 += nic["IP6_GLOBAL"];
}
return ipv6;
}
}).join(divider)
: "--";
};
// Return a dropdown with all the
// Return a dropdown with all the
function ipsDropdown(element, divider) {
var ipsStr = this.ipsStr(element,divider,groupByIpsDropdown);
var ips = ipsStr.split('<br>');
@ -828,18 +840,18 @@ define(function(require) {
// If its generated by groupByIpsDropdown
if (~ipsStr.indexOf("li")){
ips = []
ips = []
$.each($.parseHTML(ipsStr), function( index ) {
ips.push($( this ).text());
});
ipsStr = "<ul style='list-style-type:none;'>" + ipsStr + "</ul>";
}
// If it has less than "numIPs" IPs
var numIPs = 2;
if ((ips.length < numIPs)) return ipsStr;
// Take the first x
// Take the first x
insideHtml = "";
for (let i = 0; i < numIPs-1; i++) {
insideHtml += ips.shift();
@ -848,7 +860,7 @@ define(function(require) {
// Format the other IPs inside a dropdown
if (ips.length){
html += '<ul class="dropdown menu ips-dropdown" style=" text-align:left;" data-dropdown-menu><li><a style="padding-top:0em;padding-bottom:0em;padding-left:0em;color:gray">'+insideHtml+'</a><ul class="menu" style="max-height: 25em; overflow: scroll;">';
html += '<ul class="dropdown menu ips-dropdown" style=" text-align:left;" data-dropdown-menu><li><a style="padding-top:0em;padding-bottom:0em;padding-left:0em;color:gray">'+insideHtml+'</a><ul class="menu" style="max-height: 50em; overflow: scroll; width:250px;">';
$.each(ips, function(index, value){
html+='<li><a style="color:gray">' + value + '</a></li>';
});
@ -860,21 +872,29 @@ define(function(require) {
function groupByIpsDropdown(element = {}, nics = []) {
return nics.reduce(function(column, nic) {
var nicSection = $("<li/>").append($("<a/>").css("color", "gray").text(nic.IP));
// Show the first IP two times for the dropdown.
var copy_nics = Object.assign([], nics)
var first_nic = Object.assign({}, nics[0]);
delete first_nic["ALIAS_IDS"];
copy_nics.unshift(first_nic);
return copy_nics.reduce(function(column, nic) {
identation = '&nbsp;&nbsp;&nbsp;&nbsp;';
var ip = (nic.IP) ? nic.IP : nic.IP6_ULA + '&#10;&#13;' + identation + nic.IP6_GLOBAL;
var nicSection = $("<li/>").append($("<a/>").css("color", "gray").html(nic.NIC_ID + ": " + ip));
if (nic.ALIAS_IDS) {
nicSection.append("*");
nic.ALIAS_IDS.split(",").forEach(function(aliasId) {
var templateAlias = Array.isArray(element.TEMPLATE.NIC_ALIAS)
? element.TEMPLATE.NIC_ALIAS : [element.TEMPLATE.NIC_ALIAS];
var alias = templateAlias.find(function(alias) { return alias.NIC_ID === aliasId });
if (alias) {
var alias_ip = alias.IP ? alias.IP : alias.IP6_ULA + '&#10;&#13;' + identation + '> ' + alias.IP6_GLOBAL;
nicSection.append($("<li/>").append($("<a/>").css({
"color": "gray",
"font-style": "italic",
}).text("> " + alias.IP))) }
}).html(identation + '> ' + alias_ip))) }
});
}
@ -883,11 +903,12 @@ define(function(require) {
};
function groupByIpsStr(element = {}, nics = []) {
identation = '&nbsp;&nbsp;&nbsp;&nbsp;';
return nics.reduce(function(column, nic) {
var nicSection = $("<p>").css("margin-bottom", 0).text(nic.IP)
var ip = (nic.IP) ? nic.IP : nic.IP6_ULA + '<br>' + identation + nic.IP6_GLOBAL;
var nicSection = $("<p>").css("margin-bottom", 0).html(nic.NIC_ID + ": " + ip);
if (nic.ALIAS_IDS) {
nicSection.append("*");
nic.ALIAS_IDS.split(",").forEach(function(aliasId) {
var templateAlias = Array.isArray(element.TEMPLATE.NIC_ALIAS)
@ -895,10 +916,11 @@ define(function(require) {
var alias = templateAlias.find(function(alias) { return alias.NIC_ID === aliasId });
if (alias) {
var alias_ip = alias.IP ? alias.IP : alias.IP6_ULA + '<br>' + identation + '> ' + alias.IP6_GLOBAL;
nicSection.append($("<p/>").css({
"margin-bottom": 0,
"font-style": "italic",
}).text("> " + alias.IP)) }
}).html(identation + '> ' + alias_ip)) }
});
}

View File

@ -214,6 +214,7 @@ define(function(require) {
$('#' + this.dataTableId + 'Search').on('input', function() {
that.dataTable.fnFilter($(this).val());
$("ul.ips-dropdown").foundation();
return false;
});
@ -735,6 +736,8 @@ define(function(require) {
return false;
}
});
$("ul.ips-dropdown").foundation();
}
function _getElementData(id, resource_tag) {