Skip to content

Commit

Permalink
F OpenNebula#2427: Added possibility to select SCHED_REQUIREMENTS fro…
Browse files Browse the repository at this point in the history
…m vnet datatable
  • Loading branch information
juanmont committed Oct 19, 2018
1 parent a6b8f48 commit 7c14ab1
Show file tree
Hide file tree
Showing 4 changed files with 256 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ define(function(require) {
var UniqueId = require('utils/unique-id');
var CreateUtils = require('../utils');
var Notifier = require('utils/notifier');
var TemplateUtils = require('utils/template-utils');

/*
TEMPLATES
Expand All @@ -46,6 +47,14 @@ define(function(require) {
that = this;
this.nicTabId = 'nicTab' + nicTabId + UniqueId.id();

var options = {
'select': true,
'selectOptions': {
'multiple_choice': true
}
}
this.vnetsTableAuto = new VNetsTable(this.nicTabId + 'TableAuto', options);

this.vnetsTable = new VNetsTable(this.nicTabId + 'Table', {'select': true});

var secgroupSelectOptions = {
Expand All @@ -68,6 +77,7 @@ define(function(require) {
NicTab.prototype.onShow = _onShow;
NicTab.prototype.retrieve = _retrieve;
NicTab.prototype.fill = _fill;
NicTab.prototype.generateRequirements = _generateRequirements;

return NicTab;

Expand All @@ -79,12 +89,14 @@ define(function(require) {
return TemplateHTML({
'nicTabId': this.nicTabId,
'vnetsTableSelectHTML': this.vnetsTable.dataTableHTML,
'vnetsTableAutoSelectHTML': this.vnetsTableAuto.dataTableHTML,
'secgroupsTableSelectHTML': this.secgroupsTable.dataTableHTML
});
}

function _onShow(context, panelForm) {
this.vnetsTable.refreshResourceTableSelect();
this.vnetsTableAuto.refreshResourceTableSelect();
}

/**
Expand Down Expand Up @@ -134,6 +146,20 @@ define(function(require) {
that.secgroupsTable.refreshResourceTableSelect();
that.vnetsTable.refreshResourceTableSelect();

var selectOptions = {
'selectOptions': {
'select_callback': function(aData, options) {
that.generateRequirements(context)
},
'unselect_callback': function(aData, options) {
that.generateRequirements(context)
}
}
}

that.vnetsTableAuto.initialize(selectOptions);
that.vnetsTableAuto.refreshResourceTableSelect();

$("input.pci-type-nic", context).on("change", function(){
var tbody = $(".pci-row tbody", context);

Expand Down Expand Up @@ -175,6 +201,18 @@ define(function(require) {
});

$(".auto", context).hide();

context.on("change", "input[name='" + that.nicTabId + "_req_select']", function() {
if ($("input[name='" + that.nicTabId + "_req_select']:checked").val() == "vnet_select") {
$("#"+ that.nicTabId +"_vnetTable",context).show();
} else {
$("#"+ that.nicTabId +"_vnetTable",context).hide();
}
});

context.on("change", "input[name='" + that.nicTabId + "_rank_select']", function() {
$("input#"+that.nicTabId+"_SCHED_RANK", context).val(this.value);
});
}

function _retrieve(context) {
Expand Down Expand Up @@ -292,8 +330,50 @@ define(function(require) {
if ( templateJSON["SCHED_RANK"] ) {
$("input#"+this.nicTabId+"_SCHED_RANK", context).val(templateJSON["SCHED_RANK"]);
}

var reqJSON = templateJSON['SCHED_REQUIREMENTS'];
if (reqJSON) {
var req = TemplateUtils.escapeDoubleQuotes(reqJSON);

var net_id_regexp = /(\s|\||\b)ID=\\"([0-9]+)\\"/g;

var nets = [];
while (match = net_id_regexp.exec(req)) {
nets.push(match[2])
}

var selectedResources = {
ids : nets
}

this.vnetsTableAuto.selectResourceTableSelect(selectedResources);
}

var rankJSON = templateJSON["SCHED_RANK"];
if (rankJSON) {
var striping_regexp = /^-USED_LEASES$/;
var packing_regexp = /^USED_LEASES$/;

if (striping_regexp.test(rankJSON)) {
$("input[name='" + this.nicTabId + "_rank_select']#stripingRadio", context).click();
}
else if (packing_regexp.test(rankJSON)) {
$("input[name='" + this.nicTabId + "_rank_select']#packingRadio", context).click();
}
}
}

WizardFields.fill(context, templateJSON);
}

function _generateRequirements(context) {
var req_string=[];
var selected_vnets = this.vnetsTableAuto.retrieveResourceTableSelect();

$.each(selected_vnets, function(index, netID) {
req_string.push('ID=\\"'+netID+'\\"');
});

$("input#"+this.nicTabId+"_SCHED_REQUIREMENTS", context).val(req_string.join(" | "));
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,56 @@
</div>
</div>
<div class="auto">
<fieldset>
<legend>{{tr "Network Requirements"}}</legend>
<div class="row">
<div class="large-12 columns text-center">
<input type="radio" id="vnet_req" name="{{nicTabId}}_req_select" value="vnet_select">
<label for="vnet_req">{{tr "Select Vnets "}}</label>
<input type="radio" id="custom_req" name="{{nicTabId}}_req_select" value="custom" checked>
<label for="custom_req">{{tr "Custom expression "}}</label>
</div>
</div>
<br>
<div id="{{nicTabId}}_vnetTable" class="net_select" hidden>{{{vnetsTableAutoSelectHTML}}}</div>
<div class="row">
<div class="large-12 columns">
<label for="{{nicTabId}}_SCHED_REQUIREMENTS">
{{tr "Expression"}}
{{{tip (tr "Boolean expression that rules out entries from the pool of datastores suitable to run this VM.")}}}
</label>
<input type="text" id="{{nicTabId}}_SCHED_REQUIREMENTS" name="requirements" />
</div>
</div>
</fieldset>
<div class="row autoContainer">
<div class="large-12 large-centered columns">
<label for="{{nicTabId}}_SCHED_REQUIREMENTS">
{{tr "Requirements"}}
</label>
<input type="text" id="{{nicTabId}}_SCHED_REQUIREMENTS" name="SCHED_REQUIREMENTS"/>
</div>
</div>
<div class="row autoContainer">
<div class="large-12 large-centered columns">
<label for="{{nicTabId}}_SCHED_RANK">
{{tr "Rank"}}
</label>
<input type="text" id="{{nicTabId}}_SCHED_RANK" name="SCHED_RANK"/>
</div>
<fieldset class="nic_rank">
<legend>{{tr "Network Rank"}}</legend>
<div class="row">
<div class="large-12 columns text-center">
<input type="radio" id="packingRadio" name="{{nicTabId}}_rank_select" value="USED_LEASES">
<label for="packingRadio">
{{tr "Packing"}}
{{{tip (tr "Pack the VMs in the vnet to reduce VM fragmentation")}}}
</label>
<input type="radio" id="stripingRadio" name="{{nicTabId}}_rank_select" value="-USED_LEASES">
<label for="stripingRadio">
{{tr "Stripping"}}
{{{tip (tr "Spread the VMs in the vnets")}}}
</label>
</div>
</div>
<br>
<div class="row">
<div class="large-12 columns">
<label for="{{nicTabId}}_SCHED_RANK">
{{tr "Expression"}}
{{{tip (tr "This field sets which attribute will be used to sort the suitable vnets for this VM")}}}
</label>
<input type="text" id="{{nicTabId}}_SCHED_RANK" name="RANK" />
</div>
</div>
</fieldset>
</div>
</div>
</div>
Expand Down
84 changes: 82 additions & 2 deletions src/sunstone/public/app/utils/nics-section.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ define(function(require) {
var TemplateDD = require('hbs!./nics-section/dd');
var SecurityGroupsTable = require('tabs/secgroups-tab/datatable');
var VNetsTable = require('tabs/vnets-tab/datatable');
var TemplateUtils = require('utils/template-utils');

var provision_nic_accordion_dd_id = 0;

Expand Down Expand Up @@ -120,11 +121,11 @@ define(function(require) {
var req = $("input#"+that.id+"_SCHED_REQUIREMENTS", $(this)).val();
var rank = $("input#"+that.id+"_SCHED_RANK", $(this)).val();

if ( req !== "" ){
if ( req && req !== "" ){
nic["SCHED_REQUIREMENTS"] = req;
}

if ( rank !== "" ){
if ( rank && rank !== "" ){
nic["SCHED_RANK"] = rank;
}
}
Expand Down Expand Up @@ -219,6 +220,14 @@ define(function(require) {
options = {};
}

var vnetsTableAuto = new VNetsTable('vnet_nics_section_auto_'+provision_nic_accordion_dd_id,
{
'select': true,
'selectOptions': {
'multiple_choice': true
}
});

var vnetsTable = new VNetsTable(
'vnet_nics_section_'+provision_nic_accordion_dd_id,
{ 'select': true });
Expand All @@ -238,11 +247,38 @@ define(function(require) {

var dd_context = $(TemplateDD({
vnetsTableHTML: vnetsTable.dataTableHTML,
vnetsTableAutoHTML: vnetsTableAuto.dataTableHTML,
securityGroupsTableHTML: sgHtml,
provision_nic_accordion_dd_id: provision_nic_accordion_dd_id,
options: options
})).appendTo(context);

var selectOptions = {
'selectOptions': {
'select_callback': function(aData, options) {
var req_string=[];
var selected_vnets = vnetsTableAuto.retrieveResourceTableSelect();

$.each(selected_vnets, function(index, netID) {
req_string.push('ID=\\"'+netID+'\\"');
});
$(".SCHED_REQUIREMENTS", dd_context).val(req_string.join(" | "));
},
'unselect_callback': function(aData, options) {
var req_string=[];
var selected_vnets = vnetsTableAuto.retrieveResourceTableSelect();

$.each(selected_vnets, function(index, netID) {
req_string.push('ID="'+netID+'"');
});
$(".SCHED_REQUIREMENTS", dd_context).val(req_string.join(" | "));
}
}
}

vnetsTableAuto.initialize(selectOptions);
vnetsTableAuto.refreshResourceTableSelect();

$(".nic-section-entry", dd_context).data("template_nic", options.nic);
$(".nic-section-entry", dd_context).data("vnetsTable", vnetsTable);
$(".nic-section-entry", dd_context).data("sgTable", sgTable);
Expand All @@ -265,7 +301,20 @@ define(function(require) {
}
});

$("input[name='provision_accordion_dd_"+provision_nic_accordion_dd_id+"_req_select']", dd_context).on("change", function() {
if (this.value == "vnet_select") {
$(".net_select",dd_context).show();
} else {
$(".net_select",dd_context).hide();
}
});

$("input[name='provision_accordion_dd_"+provision_nic_accordion_dd_id+"_rank_select']", dd_context).on("change", function() {
$(".SCHED_RANK", dd_context).val(this.value);
});

if ( options.nic && options.nic["NETWORK_MODE"] && options.nic["NETWORK_MODE"] === "auto" ) {

$("input#provision_accordion_dd_"+provision_nic_accordion_dd_id+"_network_mode", dd_context).prop("checked", true);
$(".no_auto", dd_context).hide();
$(".auto", dd_context).show();
Expand All @@ -277,6 +326,37 @@ define(function(require) {
if ( options.nic["SCHED_RANK"] ) {
$("input#provision_accordion_dd_"+provision_nic_accordion_dd_id+"_SCHED_RANK", dd_context).val(options.nic["SCHED_RANK"]);
}

var reqJSON = options.nic['SCHED_REQUIREMENTS'];
if (reqJSON) {
var req = TemplateUtils.escapeDoubleQuotes(reqJSON);

var net_id_regexp = /(\s|\||\b)ID=\\"([0-9]+)\\"/g;

var nets = [];
while (match = net_id_regexp.exec(req)) {
nets.push(match[2])
}

var selectedResourcesAuto = {
ids : nets
}

vnetsTableAuto.selectResourceTableSelect(selectedResourcesAuto);
}

var rankJSON = options.nic["SCHED_RANK"];
if (rankJSON) {
var striping_regexp = /^-USED_LEASES$/;
var packing_regexp = /^USED_LEASES$/;

if (striping_regexp.test(rankJSON)) {
$("input[name='provision_accordion_dd_"+provision_nic_accordion_dd_id+"_rank_select']#stripingRadio", context).click();
}
else if (packing_regexp.test(rankJSON)) {
$("input[name='provision_accordion_dd_"+provision_nic_accordion_dd_id+"_rank_select']#packingRadio", context).click();
}
}
}

Tips.setup(dd_context);
Expand Down
Loading

0 comments on commit 7c14ab1

Please sign in to comment.