Skip to content

Commit

Permalink
F #1913: setuid/setgid for VM Templates (#2008)
Browse files Browse the repository at this point in the history
* F #1913: Modular advanced options

* F #1913: PCI -> Input/Output

* F #1913: Renamed 'Other' tab by 'Tags'

* F #1913: Added 'instantiate as user/group' into Template update
  • Loading branch information
Abel Coronado authored and tinova committed Apr 23, 2018
1 parent 9953620 commit 1535808
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ define(function(require) {
var UserInputs = require('utils/user-inputs');
var UniqueId = require('utils/unique-id');
var OpenNebula = require('opennebula');
var UsersTable = require("tabs/users-tab/datatable");
var GroupTable = require("tabs/groups-tab/datatable");

/*
TEMPLATES
Expand All @@ -53,9 +55,19 @@ define(function(require) {
this.icon = 'fa-laptop';
this.title = Locale.tr("General");

if(opts.listener != undefined){
if (opts.listener != undefined){
this.listener = opts.listener;
}

var opts = {
"select": true,
"selectOptions": {
"multiple_choice": false
}
};

this.usersTable = new UsersTable("UsersTable" + UniqueId.id(), opts);
this.groupTable = new GroupTable("GroupTable" + UniqueId.id(), opts);
}

WizardTab.prototype.constructor = WizardTab;
Expand All @@ -74,7 +86,9 @@ define(function(require) {
function _html() {
return TemplateHTML({
'capacityCreateHTML': CapacityCreate.html(),
'logos': Config.vmLogos
'logos': Config.vmLogos,
'usersDatatable': this.usersTable.dataTableHTML,
'groupDatatable': this.groupTable.dataTableHTML
});
}

Expand Down Expand Up @@ -121,6 +135,11 @@ define(function(require) {
function _setup(context) {
var that = this;

this.usersTable.initialize();
this.usersTable.refreshResourceTableSelect();
this.groupTable.initialize();
this.groupTable.refreshResourceTableSelect();

$(document).on('click', "[href='#" + this.wizardTabId + "']", function(){
//context.foundation('slider', 'reflow');
});
Expand Down Expand Up @@ -281,6 +300,16 @@ define(function(require) {
if (templateJSON['DISK_COST']) {
templateJSON['DISK_COST'] = templateJSON['DISK_COST']/1024;
}

var as_uid = this.usersTable.retrieveResourceTableSelect();
if (as_uid){
templateJSON["AS_UID"] = as_uid;
}

var as_gid = this.groupTable.retrieveResourceTableSelect();
if (as_gid){
templateJSON["AS_GID"] = as_gid;
}
return templateJSON;
}

Expand Down Expand Up @@ -350,31 +379,48 @@ define(function(require) {
}
}


if (templateJSON["VCENTER_RESOURCE_POOL"]) {
$('.modify_rp', context).val('fixed');
WizardFields.fillInput($('.initial_rp', context), templateJSON["VCENTER_RESOURCE_POOL"]);

delete templateJSON["VCENTER_RESOURCE_POOL"];
}

if(templateJSON["VCENTER_TEMPLATE_REF"]){
if (templateJSON["VCENTER_TEMPLATE_REF"]){
WizardFields.fillInput($("#vcenter_template_ref", context), templateJSON["VCENTER_TEMPLATE_REF"]);
delete templateJSON["VCENTER_TEMPLATE_REF"];
}

if(templateJSON["VCENTER_CCR_REF"]){
if (templateJSON["VCENTER_CCR_REF"]){
WizardFields.fillInput($("#vcenter_ccr_ref", context), templateJSON["VCENTER_CCR_REF"]);
delete templateJSON["VCENTER_CCR_REF"];
}

if(templateJSON["VCENTER_INSTANCE_ID"]){
if (templateJSON["VCENTER_INSTANCE_ID"]){
WizardFields.fillInput($("#vcenter_instance_id", context), templateJSON["VCENTER_INSTANCE_ID"]);
delete templateJSON["VCENTER_INSTANCE_ID"];
}

CapacityCreate.fill($("div.capacityCreate", context), templateJSON);

if (templateJSON["AS_UID"]){
var asuidJSON = templateJSON["AS_UID"];
var selectedResources = {
ids : asuidJSON
};
this.usersTable.selectResourceTableSelect(selectedResources);
delete templateJSON["AS_UID"];
}

if (templateJSON["AS_GID"]){
var asgidJSON = templateJSON["AS_GID"];
var selectedResources = {
ids : asgidJSON
};
this.groupTable.selectResourceTableSelect(selectedResources);
delete templateJSON["AS_GID"];
}

WizardFields.fill(context, templateJSON);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,30 @@
{{{tip (tr "Virtual Routers create Virtual Machines from a source Template. This checkbox makes this template available to be selected in the New Virtual Router wizard")}}}
</label>
</div>
</div><br><br>
{{#advancedSection (tr "User / Group") }}
{{#isFeatureEnabled "show_as_uid_instantiate"}}
<div class="row">
<div class="small-12 columns usersContext{{element.ID}}">
<fieldset>
<legend>
<i class="fas fa-user"></i> {{tr "Instantiate as a different user"}}
</legend>
<div class="provision_uid_selector{{element.ID}}">{{{usersDatatable}}}</div>
</fieldset>
</div>
</div>
{{/isFeatureEnabled}}
{{#isFeatureEnabled "show_as_gid_instantiate"}}
<div class="row">
<div class="small-12 columns groupContext{{element.ID}}">
<fieldset>
<legend>
<i class="fas fa-users"></i> {{tr "Instantiate as a different group"}}
</legend>
<div class="provision_gid_selector{{element.ID}}">{{{groupDatatable}}}</div>
</fieldset>
</div>
</div>
{{/isFeatureEnabled}}
{{/advancedSection}}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ define(function(require) {
var Tips = require('utils/tips');
var WizardFields = require('utils/wizard-fields');
var UniqueId = require('utils/unique-id');
var CreateUtils = require('./utils');

/*
TEMPLATES
Expand Down Expand Up @@ -115,6 +116,15 @@ define(function(require) {
context.on('click', "i.remove-tab", function() {
$(this).closest("tr").remove()
});

context.off("click", ".add_pci");
context.on("click", ".add_pci", function(){
var tr = $(CreateUtils.pciRowHTML()).appendTo( $(".pci_devices tbody", context) );

CreateUtils.fillPCIRow({tr: tr, remove: true});
});

CreateUtils.setupPCIRows($(".pci_devices", context));
}

function _retrieve(context) {
Expand All @@ -139,6 +149,18 @@ define(function(require) {

if (!$.isEmptyObject(inputsJSON)) { templateJSON['INPUT'] = inputsJSON; };

$('.pci_devices tbody tr', context).each(function(i,row){
var pci = WizardFields.retrieve(row);

if (!$.isEmptyObject(pci)){
if (templateJSON['PCI'] == undefined){
templateJSON['PCI'] = [];
}

templateJSON['PCI'].push(pci);
}
});

return templateJSON;
}

Expand Down Expand Up @@ -191,7 +213,28 @@ define(function(require) {
cell3.innerHTML = "<i class='fa fa-times-circle fa fa-lg remove-tab'></i>";
});

delete templateJSON['INPUT']
delete templateJSON['INPUT'];
}

$(".pci_devices i.remove-tab", context).trigger("click");

var pcis = templateJSON['PCI'];

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

if (!$.isArray(pcis)){ // If only 1 convert to array
pcis = [pcis];
}

$.each(pcis, function(i, pci){
$(".add_pci", context).trigger("click");
var tr = $('.pci_devices tbody tr', context).last();

WizardFields.fill(tr, pci);
});

delete templateJSON.PCI;
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,42 @@
</div>
</fieldset>
</div>
<div class="medium-12 columns hypervisor only_kvm">
<fieldset class="hypervisor only_kvm vm_updateconf_hide">
<legend>{{tr "PCI Devices"}}</legend>
<div class="row">
<div class="large-12 columns text-center">
<span class="radius secondary label">
<i class="fas fa-exclamation-triangle"/> {{tr "PCI passthrough of network devices is configured per NIC, in the \"Network\" tab. Do not add network devices here"}}
</span>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<table class="dataTable pci_devices">
<thead>
<tr>
<th style="width:50%">{{tr "Device name"}}</th>
<th>{{tr "Vendor"}}</th>
<th>{{tr "Device"}}</th>
<th>{{tr "Class"}}</th>
<th></th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td colspan="5">
<a type="button" class="add_pci button small small-12 secondary radius">
<i class="fas fa-lg fa-plus-circle"></i>
</a>
</td>
</tr>
</tfoot>
</table>
</div>
</div>
</fieldset>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ define(function(require) {
var CustomTagsTable = require('utils/custom-tags-table');
var OpenNebulaHost = require('opennebula/host');
var UniqueId = require('utils/unique-id');
var CreateUtils = require('./utils');

/*
TEMPLATES
Expand All @@ -51,8 +50,8 @@ define(function(require) {
}

this.wizardTabId = WIZARD_TAB_ID + UniqueId.id();
this.icon = 'fa-ellipsis-h';
this.title = Locale.tr("Other");
this.icon = 'fa-tag';
this.title = Locale.tr("Tags");
}

WizardTab.prototype.constructor = WizardTab;
Expand All @@ -79,21 +78,12 @@ define(function(require) {

function _setup(context) {
CustomTagsTable.setup(context);

context.off("click", ".add_pci");
context.on("click", ".add_pci", function(){
var tr = $(CreateUtils.pciRowHTML()).appendTo( $(".pci_devices tbody", context) );

CreateUtils.fillPCIRow({tr: tr, remove: true});
});

CreateUtils.setupPCIRows($(".pci_devices", context));
}

function _retrieve(context) {
var templateJSON = CustomTagsTable.retrieve(context);

var rawJSON = {}
var rawJSON = {};
var rawData = WizardFields.retrieveInput($('.raw_data', context));
if (rawData != "") {
rawJSON['DATA'] = rawData;
Expand All @@ -106,18 +96,6 @@ define(function(require) {

if (!$.isEmptyObject(rawJSON)) { templateJSON['RAW'] = rawJSON; };

$('.pci_devices tbody tr', context).each(function(i,row){
var pci = WizardFields.retrieve(row);

if (!$.isEmptyObject(pci)){
if (templateJSON['PCI'] == undefined){
templateJSON['PCI'] = [];
}

templateJSON['PCI'].push(pci);
}
});

return templateJSON;
}

Expand All @@ -128,30 +106,9 @@ define(function(require) {
$('.raw_type', context).change();
WizardFields.fillInput($('.raw_data', context), rawJSON['DATA']);

delete templateJSON.RAW
delete templateJSON.RAW;
}

$(".pci_devices i.remove-tab", context).trigger("click");

var pcis = templateJSON['PCI'];

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

if (!$.isArray(pcis)){ // If only 1 convert to array
pcis = [pcis];
}

$.each(pcis, function(i, pci){
$(".add_pci", context).trigger("click");
var tr = $('.pci_devices tbody tr', context).last();

WizardFields.fill(tr, pci);
});

delete templateJSON.PCI;

CustomTagsTable.fill(context, templateJSON);
}
});
Loading

0 comments on commit 1535808

Please sign in to comment.