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

F #5743: Reformat to allow filter with host and cluster (#1818)

(cherry picked from commit 50242487dd7b778456812a3b1faaf9d4132f88e8)
This commit is contained in:
Sergio Betanzos 2022-02-28 16:03:45 +01:00 committed by Tino Vazquez
parent 234d825471
commit 54f3bfc5e0
No known key found for this signature in database
GPG Key ID: 14201E424D02047E
9 changed files with 171 additions and 114 deletions

View File

@ -32,8 +32,15 @@ define(function(require) {
var RESOURCE = "Cluster";
var XML_ROOT = "CLUSTER";
var TAB_NAME = require('./tabId');
var LABELS_COLUMN = 6;
var TEMPLATE_ATTR = 'TEMPLATE';
var COLUMNS = {
ID: 1,
NAME: 2,
HOSTS: 3,
VNETS: 4,
DATASTORES: 5,
LABELS: 6
}
/*
CONSTRUCTOR
@ -45,7 +52,7 @@ define(function(require) {
this.dataTableId = dataTableId;
this.resource = RESOURCE;
this.xmlRoot = XML_ROOT;
this.labelsColumn = LABELS_COLUMN;
this.labelsColumn = COLUMNS.LABELS;
this.dataTableOptions = {
"bAutoWidth": false,
@ -88,7 +95,7 @@ define(function(require) {
Table.prototype.elementArray = _elementArray;
Table.prototype.preUpdateView = _preUpdateView;
Table.prototype.postUpdateView = _postUpdateView;
Table.prototype.isOpenNebulaResourceInCluster = _isOpenNebulaResourceInCluster;
Table.prototype.columnsIndex = COLUMNS;
return Table;
@ -130,26 +137,4 @@ define(function(require) {
function _postUpdateView() {
$(".total_clusters").text(this.totalClusters);
}
/**
* Checks that a OpenNebula resource is in the selected clusters.
*
* @param {object} resource - OpenNebula resource: Datastore, VM, etc
* @param {function(object):string|string[]} [fnGetResourceCluster]
* - Function to get Clusters ids from resource
* @returns `true` if selected Clusters contain the resource
*/
function _isOpenNebulaResourceInCluster(resource, fnGetResourceCluster) {
var clusters = typeof fnGetResourceCluster === 'function'
? fnGetResourceCluster(resource)
: resource.CLUSTERS.ID
var ensuredClusters = Array.isArray(clusters) ? clusters : [clusters];
var selectedClusterIds = this.retrieveResourceTableSelect();
return selectedClusterIds.length === 0 ||
ensuredClusters.some(function (cluster) {
return selectedClusterIds.includes(cluster)
});
}
});

View File

@ -46,9 +46,20 @@ define(function(require) {
var RESOURCE = "Host";
var XML_ROOT = "HOST";
var TAB_NAME = require("./tabId");
var LABELS_COLUMN = 10;
var SEARCH_COLUMN = 11;
var TEMPLATE_ATTR = "TEMPLATE";
var COLUMNS = {
ID: 1,
NAME: 2,
CLUSTER: 3,
RVMS: 4,
ALLOCATED_CPU: 5,
ALLOCATED_MEM: 6,
STATUS: 7,
IM_MAD: 8,
VM_MAD: 9,
LABELS: 10,
SEARCH: 10,
}
/*
CONSTRUCTOR
@ -60,7 +71,7 @@ define(function(require) {
this.dataTableId = dataTableId;
this.resource = RESOURCE;
this.xmlRoot = XML_ROOT;
this.labelsColumn = LABELS_COLUMN;
this.labelsColumn = COLUMNS.LABELS;
this.dataTableOptions = {
"bAutoWidth": false,
@ -109,7 +120,7 @@ define(function(require) {
this.allocatedMemory = 0;
this.conf.searchDropdownHTML = SearchDropdown({tableId: this.dataTableId});
this.searchColumn = SEARCH_COLUMN;
this.searchColumn = COLUMNS.SEARCH;
TabDataTable.call(this);
};
@ -119,7 +130,7 @@ define(function(require) {
Table.prototype.elementArray = _elementArray;
Table.prototype.preUpdateView = _preUpdateView;
Table.prototype.postUpdateView = _postUpdateView;
Table.prototype.isOpenNebulaResourceInHost = _isOpenNebulaResourceInHost;
Table.prototype.columnsIndex = COLUMNS;
return Table;
@ -289,32 +300,4 @@ define(function(require) {
"</div>" +
"</div>";
}
/**
* Checks that a OpenNebula resource is in the selected hosts.
*
* @param {object} resource - OpenNebula resource: Datastore, VM, etc
* @param {function(object):string|string[]} [fnGetResourceCluster]
* - Function to get Clusters ids from resource
* @returns `true` if selected Hosts and the resource are in same cluster
*/
function _isOpenNebulaResourceInHost(resource, fnGetResourceCluster) {
var clusters = typeof fnGetResourceCluster === 'function'
? fnGetResourceCluster(resource)
: resource.CLUSTERS.ID
var ensuredClusters = Array.isArray(clusters) ? clusters : [clusters];
var selectedHostIds = this.retrieveResourceTableSelect();
var allHosts = this.dataTable.fnGetData();
var id_index = this.selectOptions.id_index;
var selectedClusters = !Array.isArray(allHosts) ? [] : allHosts
.filter(function(host) { return selectedHostIds.includes(host[id_index]) })
.map(function(host) { return host[3] }); // cluster column => 3
return selectedClusters.length === 0 ||
ensuredClusters.some(function (cluster) {
return selectedClusters.includes(cluster)
});
}
});

View File

@ -39,24 +39,39 @@ define(function(require) {
CONSTANTS
*/
var general = require("./create/wizard-tabs/general")
var storage = require("./create/wizard-tabs/storage")
var network = require("./create/wizard-tabs/network")
var os = require("./create/wizard-tabs/os")
var io = require("./create/wizard-tabs/io")
var actions = require("./create/wizard-tabs/actions")
var context = require("./create/wizard-tabs/context")
var scheduling = require("./create/wizard-tabs/scheduling")
var hybrid = require("./create/wizard-tabs/hybrid")
var vmgroup = require("./create/wizard-tabs/vmgroup")
var other = require("./create/wizard-tabs/other")
var numa = require("./create/wizard-tabs/numa")
var WIZARD_TABS = [
require("./create/wizard-tabs/general"),
require("./create/wizard-tabs/storage"),
require("./create/wizard-tabs/network"),
require("./create/wizard-tabs/os"),
require("./create/wizard-tabs/io"),
require("./create/wizard-tabs/actions"),
require("./create/wizard-tabs/context"),
require("./create/wizard-tabs/scheduling"),
require("./create/wizard-tabs/hybrid"),
require("./create/wizard-tabs/vmgroup"),
require("./create/wizard-tabs/other"),
require("./create/wizard-tabs/numa")
general,
storage,
network,
os,
io,
actions,
context,
scheduling,
hybrid,
vmgroup,
other,
numa
];
var TEMPLATES_TAB_ID = require("tabs/templates-tab/tabId");
var VROUTER_TEMPLATES_TAB_ID = require("tabs/vrouter-templates-tab/tabId");
var in_progress = false
/*
CONSTRUCTOR
*/
@ -145,9 +160,17 @@ define(function(require) {
}
function _setup(context) {
$.each(this.wizardTabs, function(index, wizardTab) {
wizardTab.setup($("#" + wizardTab.wizardTabId, context));
});
$.each(
[].concat(this.wizardTabs).sort(function(a, b) {
var setupOrderA = a.setupOrder === undefined ? -1 : a.setupOrder
var setupOrderB = b.setupOrder === undefined ? -1 : b.setupOrder
return setupOrderB - setupOrderA
}),
function(index, wizardTab) {
wizardTab.setup($("#" + wizardTab.wizardTabId, context));
}
);
Foundation.reflow(context, "tabs");
Tips.setup(context);
@ -402,7 +425,16 @@ define(function(require) {
this.notify();
}
var in_progress = false;
function insertAt(array, index, element) {
array.splice(index, 0, element);
}
function insertAt2(array, index, element) {
return array
.slice(0, index)
.concat(element)
.concat(array.slice(index));
}
function _notify() {
var that = this;

View File

@ -106,6 +106,8 @@ define(function(require) {
return false;
});
that.addNicTab(context);
if(that.listener != undefined){
$(context).on("change", "input", function(){
that.listener.notify();
@ -194,19 +196,17 @@ define(function(require) {
});
}
nics.length === 0
? that.addNicTab(context)
: $.each(nics, function(nicId, nicJSON) {
that.addNicTab(context);
$.each(nics, function(nicId, nicJSON) {
nicId > 0 && that.addNicTab(context);
var nicTab = that.nicTabObjects[that.numberOfNics];
var nicContext = $('#' + nicTab.nicTabId, context);
nicTab.fill(nicContext, nicJSON);
var nicTab = that.nicTabObjects[that.numberOfNics];
var nicContext = $('#' + nicTab.nicTabId, context);
nicTab.fill(nicContext, nicJSON);
if (nicJSON.PARENT) {
nicTab.fill_alias(nicJSON.PARENT, nicJSON.EXTERNAL);
}
});
if (nicJSON.PARENT) {
nicTab.fill_alias(nicJSON.PARENT, nicJSON.EXTERNAL);
}
});
that.renameTabLinks(context);
that.enableRDP(context);

View File

@ -121,23 +121,37 @@ define(function(require) {
$(".only_create", context).hide();
}
var isInHostOrClusterTable = function(vnet){
if (!options.hostsTable || !options.clustersTable) return true;
var clusters = vnet.CLUSTERS.ID;
var ensuredClusters = Array.isArray(clusters) ? clusters : [clusters];
var hostClusterIndex = options.hostsTable.columnsIndex.CLUSTER
var hostClustersIds = options.hostsTable.getColumnDataInSelectedRows(hostClusterIndex)
var clustersIds = options.clustersTable.getColumnDataInSelectedRows()
return (
(hostClustersIds.length === 0 && clustersIds.length === 0) ||
hostClustersIds
.concat(clustersIds)
.some(function(id) { return ensuredClusters.includes(id) })
)
}
that.vnetsTable.initialize({
'selectOptions': {
filter_fn: function(vnet) {
if (!options.hostsTable || !options.clustersTable) return true;
const filterResource = isInHostOrClusterTable(vnet)
var inHostOrCluster = $("input[name='req_select']:checked").val() === "host_select"
? options.hostsTable.isOpenNebulaResourceInHost(vnet)
: options.clustersTable.isOpenNebulaResourceInCluster(vnet)
if (!inHostOrCluster && $('#NETWORK', context).val() === vnet.NAME) {
if (!filterResource && $('#NETWORK', context).val() === vnet.NAME) {
that.secgroupsTable.selectResourceTableSelect({ ids: [] });
$.each(['NETWORK_ID', 'NETWORK', 'NETWORK_UNAME', 'NETWORK_UID'], function() {
$('#' + this, context).val('');
})
}
return inHostOrCluster
return filterResource
},
select_callback: function(aData, options) {
// If the net is selected by Id, avoid overwriting it with name+uname
@ -177,11 +191,7 @@ define(function(require) {
that.vnetsTableAuto.initialize({
selectOptions: {
filter_fn: function(vnet) {
if (!options.hostsTable || !options.clustersTable) return true;
return $("input[name='req_select']:checked").val() === "host_select"
? options.hostsTable.isOpenNebulaResourceInHost(vnet)
: options.clustersTable.isOpenNebulaResourceInCluster(vnet)
return isInHostOrClusterTable(vnet)
},
select_callback: function(aData, options) {
that.generateRequirements(context)

View File

@ -69,6 +69,7 @@ define(function(require) {
WizardTab.prototype.constructor = WizardTab;
WizardTab.prototype.html = _html;
WizardTab.prototype.setup = _setup;
WizardTab.prototype.setupOrder = 1;
WizardTab.prototype.onShow = _onShow;
WizardTab.prototype.retrieve = _retrieve;
WizardTab.prototype.fill = _fill;
@ -143,9 +144,19 @@ define(function(require) {
filter_fn: function(ds) {
if (!that.hostsTable || !that.clustersTable) return true;
return $("input[name='req_select']:checked").val() === "host_select"
? that.hostsTable.isOpenNebulaResourceInHost(ds)
: that.clustersTable.isOpenNebulaResourceInCluster(ds)
var clusters = ds.CLUSTERS.ID;
var ensuredClusters = Array.isArray(clusters) ? clusters : [clusters];
var hostClusterIndex = that.hostsTable.columnsIndex.CLUSTER
var hostClustersIds = that.hostsTable.getColumnDataInSelectedRows(hostClusterIndex)
var clustersIds = that.clustersTable.getColumnDataInSelectedRows()
return (
(hostClustersIds.length === 0 && clustersIds.length === 0) ||
hostClustersIds
.concat(clustersIds)
.some(function(id) { return ensuredClusters.includes(id) })
)
}
})
});
@ -184,18 +195,11 @@ define(function(require) {
clusters.push(match[1])
}
var selectedResources = {
ids : hosts
}
this.hostsTable.selectResourceTableSelect({ ids: hosts });
this.clustersTable.selectResourceTableSelect({ ids: clusters });
this.hostsTable.selectResourceTableSelect(selectedResources);
var selectedResources = {
ids : clusters
}
this.clustersTable.selectResourceTableSelect(selectedResources);
this.datastoresTable.updateFn();
this.datastoresTable.deselectHiddenResources();
}
var dsReqJSON = templateJSON['SCHED_DS_REQUIREMENTS'];

View File

@ -530,7 +530,15 @@ define(function(require) {
filter_fn: function(ds) {
if (!that.hostsTable.dataTable) return true;
return that.hostsTable.isOpenNebulaResourceInHost(ds)
var clusters = ds.CLUSTERS.ID;
var ensuredClusters = Array.isArray(clusters) ? clusters : [clusters];
var hostClusterIndex = that.hostsTable.columnsIndex.CLUSTER
var hostClustersIds = that.hostsTable.getColumnDataInSelectedRows(hostClusterIndex)
return hostClustersIds.length === 0 ||
hostClustersIds.some(function(id) {
return ensuredClusters.includes(id)
})
},
select_callback: function(aData, options) {
var hostTable = $(".provision_host_selector" + template_json.VMTEMPLATE.ID, context).data("hostsTable");

View File

@ -345,7 +345,15 @@ define(function(require) {
filter_fn: function(vnet) {
if (!options.hostsTable) return true;
return options.hostsTable.isOpenNebulaResourceInHost(vnet)
var clusters = vnet.CLUSTERS.ID;
var ensuredClusters = Array.isArray(clusters) ? clusters : [clusters];
var hostClusterIndex = options.hostsTable.columnsIndex.CLUSTER
var hostClustersIds = options.hostsTable.getColumnDataInSelectedRows(hostClusterIndex)
return hostClustersIds.length === 0 ||
hostClustersIds.some(function(id) {
return ensuredClusters.includes(id)
})
},
"select_callback": function(aData, options) {
var req_string=[];
@ -585,7 +593,15 @@ define(function(require) {
filter_fn: function(vnet) {
if (!options.hostsTable) return true;
return options.hostsTable.isOpenNebulaResourceInHost(vnet)
var clusters = vnet.CLUSTERS.ID;
var ensuredClusters = Array.isArray(clusters) ? clusters : [clusters];
var hostClusterIndex = options.hostsTable.columnsIndex.CLUSTER
var hostClustersIds = options.hostsTable.getColumnDataInSelectedRows(hostClusterIndex)
return hostClustersIds.length === 0 ||
hostClustersIds.some(function(id) {
return ensuredClusters.includes(id)
})
},
}
});

View File

@ -170,6 +170,7 @@ define(function(require) {
"clearLabelsFilter": _clearLabelsFilter,
"getLabelsFilter": _getLabelsFilter,
"deselectHiddenResources": _deselectHiddenResources,
"getColumnDataInSelectedRows": _getColumnDataInSelectedRows,
};
return TabDatatable;
@ -1276,4 +1277,22 @@ define(function(require) {
return ids
}
/**
* Returns the selected data from a column by index.
*
* @param {number} columnIndex - Column index
* @returns {any[]} List of column data
*/
function _getColumnDataInSelectedRows(columnIndex) {
var selectedRowIds = this.retrieveResourceTableSelect();
var allRows = this.dataTable.fnGetData();
var id_index = this.selectOptions.id_index;
var columnData = !Array.isArray(allRows) ? [] : allRows
.filter(function(row) { return selectedRowIds.includes(row[id_index]) })
.map(function(row) { return row[(columnIndex || id_index)] });
return columnData;
}
});