Skip to content

Commit

Permalink
F #911: IP(v6) alias(es) support
Browse files Browse the repository at this point in the history
    * Made changes in info tab.
    * Made changes in network tab, to attach/detach alias.
    * Made changes in VM template update/instantiate.
  • Loading branch information
Alejandro Huertas committed Dec 17, 2018
1 parent 969ddc0 commit 093ddd6
Show file tree
Hide file tree
Showing 14 changed files with 636 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def instantiate(params=Hash.new)

template = template_to_str(params['template'])

['NIC', 'SCHED_ACTION', 'SCHED_REQUIREMENTS', 'SCHED_DS_REQUIREMENTS'].each { |i|
['NIC', 'NIC_ALIAS', 'SCHED_ACTION', 'SCHED_REQUIREMENTS', 'SCHED_DS_REQUIREMENTS'].each { |i|
if params['template'][i] && params['template'][i].empty?
template << "\n#{i} = []"
end
Expand Down
43 changes: 43 additions & 0 deletions src/sunstone/public/app/opennebula/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,16 @@ define(function(require) {
"VROUTER_IP6_ULA"
];

var NIC_ALIAS_IP_ATTRS = [
"IP",
"IP6",
"IP6_GLOBAL",
"IP6_ULA",
"VROUTER_IP",
"VROUTER_IP6_GLOBAL",
"VROUTER_IP6_ULA"
];

var EXTERNAL_NETWORK_ATTRIBUTES = [
'GUEST_IP',
'GUEST_IP_ADDRESSES',
Expand Down Expand Up @@ -646,6 +656,7 @@ define(function(require) {
return MIGRATE_ACTION_STR[stateId];
},
"ipsStr": ipsStr,
"aliasStr": aliasStr,
"retrieveExternalIPs": retrieveExternalIPs,
"retrieveExternalNetworkAttrs": retrieveExternalNetworkAttrs,
"isNICGraphsSupported": isNICGraphsSupported,
Expand Down Expand Up @@ -794,6 +805,38 @@ define(function(require) {
}
};

// Return the Alias or several Aliases of a VM
function aliasStr(element, divider) {
var divider = divider || "<br>"
var nic_alias = element.TEMPLATE.NIC_ALIAS;
var ips = [];

if (nic_alias == undefined){
nic_alias = [];
}

if (!$.isArray(nic_alias)) {
nic_alias = [nic_alias];
}

if(ips.length==0)
{
$.each(nic_alias, function(index, value) {
$.each(NIC_ALIAS_IP_ATTRS, function(j, attr){
if (value[attr]) {
ips.push(value[attr]);
}
});
});
}

if (ips.length > 0) {
return ips.join(divider);
} else {
return '--';
}
};

// returns true if the vnc button should be enabled
function isVNCSupported(element) {
var graphics = element.TEMPLATE.GRAPHICS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ define(function(require) {
var templateJSON = {}
$.each(this.wizardTabs, function(index, wizardTab) {
$.extend(true, templateJSON, wizardTab.retrieve($('#' + wizardTab.wizardTabId, context)));

var a = templateJSON;
});

// vCenter PUBLIC_CLOUD is not defined in the hybrid tab. Because it is
Expand All @@ -174,6 +176,24 @@ define(function(require) {
// part of an array, and it is filled in different tabs, the $.extend deep
// merge can't work. We define an auxiliary attribute for it.

if (templateJSON["NIC_ALIAS"]) {
var alias = templateJSON["NIC_ALIAS"];

if (!(alias instanceof Array)) {
alias = [alias];
}

if (alias.length > 0) {
if (alias.length == 1) {
templateJSON["NIC_ALIAS"] = alias[0];
} else {
templateJSON["NIC_ALIAS"] = alias;
}
} else {
delete templateJSON["NIC_ALIAS"];
}
}

if (templateJSON["NIC_PCI"] != undefined) {
if (templateJSON['PCI'] == undefined) {
templateJSON['PCI'] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ define(function(require) {
this.icon = 'fa-globe';
this.title = Locale.tr("Network");
this.classes = "hypervisor only_kvm only_vcenter";
this.nics = [];

if(opts.listener != undefined){
this.listener = opts.listener;
Expand Down Expand Up @@ -115,6 +116,7 @@ define(function(require) {
var templateJSON = {}
var nicsJSON = [];
var pcisJSON = [];
var aliasJSON = [];

var tmpJSON;
$.each(this.nicTabObjects, function(id, nicTab) {
Expand All @@ -124,13 +126,16 @@ define(function(require) {
delete tmpJSON["NIC_PCI"];
tmpJSON["TYPE"] = "NIC";
pcisJSON.push(tmpJSON);
} else if (tmpJSON["PARENT"]) {
aliasJSON.push(tmpJSON);
} else {
nicsJSON.push(tmpJSON);
}
};
})

if (nicsJSON.length > 0) { templateJSON['NIC'] = nicsJSON; };
if (aliasJSON.length > 0) { templateJSON['NIC_ALIAS'] = aliasJSON; };
if (pcisJSON.length > 0) { templateJSON['NIC_PCI'] = pcisJSON; };

var nicDefault = WizardFields.retrieveInput($('#DEFAULT_MODEL', context));
Expand All @@ -146,6 +151,7 @@ define(function(require) {
function _fill(context, templateJSON) {
var that = this;
var nics = [];
var alias = [];

if (templateJSON.NIC != undefined){
nics = templateJSON.NIC;
Expand All @@ -155,6 +161,18 @@ define(function(require) {
nics = [nics];
}

if (templateJSON.NIC_ALIAS != undefined){
alias = templateJSON.NIC_ALIAS;
}

if (!(alias instanceof Array)) {
alias = [alias];
}

$.each(alias, function() {
nics.push(this);
});

if (templateJSON.PCI != undefined){
var pcis = templateJSON.PCI;

Expand All @@ -177,12 +195,22 @@ define(function(require) {
var nicTab = that.nicTabObjects[that.numberOfNics];
var nicContext = $('#' + nicTab.nicTabId, context);
nicTab.fill(nicContext, nicJSON);

if (nicJSON.PARENT) {
nicTab.fill_alias(nicJSON.PARENT);
}
});

that.renameTabLinks(context);

if (templateJSON.NIC) {
delete templateJSON.NIC;
}

if (templateJSON.NIC_ALIAS) {
delete templateJSON.NIC_ALIAS;
}

if (templateJSON.PCI != undefined) {
var pcis = templateJSON.PCI;

Expand Down Expand Up @@ -215,8 +243,13 @@ define(function(require) {

function _addNicTab(context) {
var that = this;

if (!that.nics.find(nic => nic.NAME === ("NIC" + that.numberOfNics))) {
that.nics.push({"NAME": "NIC" + that.numberOfNics, "ALIAS": false});
}

that.numberOfNics++;
var nicTab = new NicTab(that.numberOfNics);
var nicTab = new NicTab(that.numberOfNics, that.nics);

var content = $('<div id="' + nicTab.nicTabId + '" class="nic wizard_internal_tab tabs-panel">' +
nicTab.html() +
Expand All @@ -242,24 +275,34 @@ define(function(require) {
var li = $(this).closest('li');
var ul = $(this).closest('ul');
var content = $(target);
var nicId = content.attr("nicId");
var index = that.nics.findIndex(nic => nic.NAME === ("NIC" + (nicId - 1)));

that.nics.splice(index, 1);

li.remove();
content.remove();

var nicId = content.attr("nicId");
delete that.nicTabObjects[nicId];

if (li.hasClass('is-active')) {
$('a', ul.children('li').last()).click();
}

that.renameTabLinks(context);
that.numberOfNics --;
});
}

function _renameTabLinks(context) {
$("#" + LINKS_CONTAINER_ID + " li", context).each(function(index) {
$("a", this).html(Locale.tr("NIC") + ' ' + index + " <i class='fa fa-times-circle remove-tab'></i>");
$("a", this).html(Locale.tr("NIC") + ' ' + index + " <i id='remove_nic_" + index + "'class='fa fa-times-circle remove-tab'></i>");

if (!that.nics.find(nic => nic.ALIAS === ("NIC" + index))) {
$("#remove_nic_" + index).show();
} else {
$("#remove_nic_" + index).hide();
}
})

if(this.listener != undefined){
Expand Down
Loading

0 comments on commit 093ddd6

Please sign in to comment.