From 5f35e0d0abc166ad0d824f1045bc160767349fe3 Mon Sep 17 00:00:00 2001 From: Abel Coronado Date: Fri, 21 Jul 2017 13:06:41 +0200 Subject: [PATCH] F #5217 Added ds requirements instantiate VM (#407) * Added ds requirements instantiate VM * Solved bug in VMGroup datatable cloud view * F #5217 Added DS Requirements cloud view instantiate VM * F #5217 Added SYSTEM filter in DS datatable * F #5217 Made configurable ds and host datatables instantiate VM --- src/sunstone/etc/sunstone-views/admin.yaml | 6 ++ .../etc/sunstone-views/admin_vcenter.yaml | 6 ++ src/sunstone/etc/sunstone-views/cloud.yaml | 20 +++++- .../etc/sunstone-views/groupadmin.yaml | 6 ++ src/sunstone/etc/sunstone-views/user.yaml | 6 ++ src/sunstone/public/app/tabs/provision-tab.js | 57 ++++++++++++++- .../app/tabs/provision-tab/vms/create.hbs | 10 +++ .../create/wizard-tabs/scheduling.js | 1 + .../templates-tab/form-panels/instantiate.js | 71 ++++++++++++++++--- .../form-panels/instantiate/templateRow.hbs | 25 ++++++- 10 files changed, 195 insertions(+), 13 deletions(-) diff --git a/src/sunstone/etc/sunstone-views/admin.yaml b/src/sunstone/etc/sunstone-views/admin.yaml index 7bc5086441..c8ef6d0e79 100644 --- a/src/sunstone/etc/sunstone-views/admin.yaml +++ b/src/sunstone/etc/sunstone-views/admin.yaml @@ -56,6 +56,12 @@ features: # True to show the option to make an instance persistent instantiate_persistent: true + # True to show the datastore datatable to instantiate VM + show_ds_instantiate: true + + # True to show the host datatable to instantiate VM + show_host_instantiate: true + # True to show an input to specify the the VMs and Template path/folder where a vCenter VM will # deployed to vcenter_vm_folder: false diff --git a/src/sunstone/etc/sunstone-views/admin_vcenter.yaml b/src/sunstone/etc/sunstone-views/admin_vcenter.yaml index 5583046484..3c9b6ed7dc 100644 --- a/src/sunstone/etc/sunstone-views/admin_vcenter.yaml +++ b/src/sunstone/etc/sunstone-views/admin_vcenter.yaml @@ -56,6 +56,12 @@ features: # True to show the option to make an instance persistent instantiate_persistent: true + # True to show the datastore datatable to instantiate VM + show_ds_instantiate: false + + # True to show the host datatable to instantiate VM + show_host_instantiate: false + # True to show an input to specify the the VMs and Template path/folder where a vCenter VM will # deployed to vcenter_vm_folder: true diff --git a/src/sunstone/etc/sunstone-views/cloud.yaml b/src/sunstone/etc/sunstone-views/cloud.yaml index e0399756d4..428b71a36c 100644 --- a/src/sunstone/etc/sunstone-views/cloud.yaml +++ b/src/sunstone/etc/sunstone-views/cloud.yaml @@ -88,6 +88,8 @@ tabs: vmgroup_select: true # True to allow DISK size customization disk_resize: true + # True to allow datastore customization + datastore_select: true settings-tab: panel_tabs: settings_info_tab: false @@ -153,4 +155,20 @@ tabs: - 4 # Owner - 5 # Vms #- 6 # Labels - #- 7 # Search data \ No newline at end of file + #- 7 # Search data + datastores-tab: + table_columns: + - 0 # Checkbox + - 1 # ID + - 2 # Owner + - 3 # Group + - 4 # Name + #- 5 # Capacity + #- 6 # Cluster + #- 7 # Basepath + #- 8 # TM + #- 9 # DS + #- 10 # Type + - 11 # Status + #- 12 # Labels + #- 13 # Search data \ No newline at end of file diff --git a/src/sunstone/etc/sunstone-views/groupadmin.yaml b/src/sunstone/etc/sunstone-views/groupadmin.yaml index 230a0ccee8..1795a6e60d 100644 --- a/src/sunstone/etc/sunstone-views/groupadmin.yaml +++ b/src/sunstone/etc/sunstone-views/groupadmin.yaml @@ -56,6 +56,12 @@ features: # True to show the option to make an instance persistent instantiate_persistent: true + # True to show the datastore datatable to instantiate VM + show_ds_instantiate: false + + # True to show the host datatable to instantiate VM + show_host_instantiate: false + # True to show an input to specify the the VMs and Template path/folder where a vCenter VM will # deployed to vcenter_vm_folder: false diff --git a/src/sunstone/etc/sunstone-views/user.yaml b/src/sunstone/etc/sunstone-views/user.yaml index 219138323b..d7c8af53a0 100644 --- a/src/sunstone/etc/sunstone-views/user.yaml +++ b/src/sunstone/etc/sunstone-views/user.yaml @@ -56,6 +56,12 @@ features: # True to show the option to make an instance persistent instantiate_persistent: true + # True to show the datastore datatable to instantiate VM + show_ds_instantiate: false + + # True to show the host datatable to instantiate VM + show_host_instantiate: false + # True to show an input to specify the the VMs and Template path/folder where a vCenter VM will # deployed to vcenter_vm_folder: false diff --git a/src/sunstone/public/app/tabs/provision-tab.js b/src/sunstone/public/app/tabs/provision-tab.js index 30638bdd61..c418d787e8 100644 --- a/src/sunstone/public/app/tabs/provision-tab.js +++ b/src/sunstone/public/app/tabs/provision-tab.js @@ -40,6 +40,8 @@ define(function(require) { var UserInputs = require('utils/user-inputs'); var CapacityInputs = require('tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-inputs'); var LabelsUtils = require('utils/labels/utils'); + var DatastoresTable = require('tabs/datastores-tab/datatable'); + var UniqueId = require('utils/unique-id'); var ProvisionVmsList = require('./provision-tab/vms/list'); var ProvisionTemplatesList = require('./provision-tab/templates/list'); @@ -92,6 +94,7 @@ define(function(require) { $("#vm_name", context).val(''); $(".provision_selected_networks").html(""); $(".provision_vmgroup_selector").html(""); + $(".provision_ds_selector").html(""); $(".provision-pricing-table", context).removeClass("selected"); $(".alert-box-error", context).hide(); $(".total_cost_div", context).hide(); @@ -569,8 +572,10 @@ define(function(require) { $("#provision_create_vm .provision_disk_selector").removeData("template_json"); $("#provision_create_vm .provision_network_selector").html(""); $("#provision_create_vm .provision_vmgroup_selector").html(""); + $("#provision_create_vm .provision_ds_selector").html(""); $("#provision_create_vm .provision_add_vmgroup").show(); $("#provision_create_vm .provision_vmgroup").hide(); + $("#provision_create_vm .provision_ds").hide(); $("#provision_create_vm .provision_custom_attributes_selector").html("") @@ -595,12 +600,13 @@ define(function(require) { $(".provision_vmgroup_selector", context).html(""); $(".provision_add_vmgroup", context).show(); $(".provision_vmgroup", context).hide(); + //$(".provision_ds", context).hide(); $(".provision_custom_attributes_selector", context).html(""); $(".provision_accordion_flow_template .selected_template", context).hide(); $(".provision_accordion_flow_template .select_template", context).show(); - $("li:not(.is-active) a[href='#provision_dd_flow_template']", context).trigger("click") + $("li:not(.is-active) a[href='#provision_dd_flow_template']", context).trigger("click"); $(".total_cost_div", context).hide(); $(".alert-box-error", context).hide(); @@ -946,6 +952,7 @@ define(function(require) { $(".provision_accordion_template a").first().trigger("click"); $("#provision_create_vm .provision_vmgroup").show(); + $("#provision_create_vm .provision_ds").show(); OpenNebula.Template.show({ data : { id: template_id, @@ -983,11 +990,45 @@ define(function(require) { } if (Config.provision.create_vm.isEnabled("vmgroup_select")) { + $(".provision_vmgroup_selector", create_vm_context).html(""); + $("#provision_create_vm .provision_add_vmgroup").show(); VMGroupSection.insert(template_json, $(".vmgroupContext", create_vm_context)); } else { $(".provision_vmgroup_selector", create_vm_context).html(""); } + if (Config.provision.create_vm.isEnabled("datastore_select")) { + $(".provision_ds_selector", create_vm_context).html(""); + var options = { + 'select': true, + 'selectOptions': { + 'multiple_choice': true + } + } + this.datastoresTable = new DatastoresTable('DatastoresTable' + UniqueId.id(), options); + $(".provision_ds_selector", create_vm_context).html(this.datastoresTable.dataTableHTML); + this.datastoresTable.initialize(); + this.datastoresTable.filter("system", 10); + this.datastoresTable.refreshResourceTableSelect(); + if(template_json.VMTEMPLATE.TEMPLATE.SCHED_DS_REQUIREMENTS){ + var dsReqJSON = template_json.VMTEMPLATE.TEMPLATE.SCHED_DS_REQUIREMENTS; + var dsReq = TemplateUtils.escapeDoubleQuotes(dsReqJSON); + var ds_id_regexp = /(\s|\||\b)ID=\\"([0-9]+)\\"/g; + var ds = []; + while (match = ds_id_regexp.exec(dsReq)) { + ds.push(match[2]); + } + var selectedResources = { + ids : ds + } + this.datastoresTable.selectResourceTableSelect(selectedResources); + $(".provision_ds_selector", create_vm_context).data("dsTable", this.datastoresTable); + } + } else { + $(".provision_ds_selector", create_vm_context).html(""); + $(".provision_ds", create_vm_context).hide(); + } + if (template_json.VMTEMPLATE.TEMPLATE.USER_INPUTS) { UserInputs.vmTemplateInsert( $(".provision_custom_attributes_selector", create_vm_context), @@ -1044,6 +1085,20 @@ define(function(require) { $.extend(extra_info.template, vmgroup); } + var dsTable = $(".provision_ds_selector", context).data("dsTable"); + if(dsTable != undefined){ + var req_string = []; + var ds = dsTable.retrieveResourceTableSelect(); + if(ds){ + $.each(ds, function(index, dsId) { + req_string.push('ID="' + dsId + '"'); + }); + req_string = req_string.join(" | "); + req_string = TemplateUtils.escapeDoubleQuotes(req_string); + extra_info.template.SCHED_DS_REQUIREMENTS = req_string; + } + } + if (nics.length > 0) { extra_info.template.nic = nics; } diff --git a/src/sunstone/public/app/tabs/provision-tab/vms/create.hbs b/src/sunstone/public/app/tabs/provision-tab/vms/create.hbs index 7f2fd3ac8f..56544be5fe 100644 --- a/src/sunstone/public/app/tabs/provision-tab/vms/create.hbs +++ b/src/sunstone/public/app/tabs/provision-tab/vms/create.hbs @@ -140,4 +140,14 @@ + \ No newline at end of file diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/scheduling.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/scheduling.js index 88dbbfbe66..97f35bf12a 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/scheduling.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/scheduling.js @@ -129,6 +129,7 @@ define(function(require) { that.clustersTable.initialize(selectOptions); that.clustersTable.refreshResourceTableSelect(); that.datastoresTable.initialize(selectOptions); + that.datastoresTable.filter("system", 10); that.datastoresTable.refreshResourceTableSelect(); } diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js index 3dcb1d75aa..a07a6126ce 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js @@ -29,6 +29,7 @@ define(function(require) { var Tips = require('utils/tips'); var UserInputs = require('utils/user-inputs'); var WizardFields = require('utils/wizard-fields'); + var TemplateUtils = require('utils/template-utils'); var DisksResize = require('utils/disks-resize'); var NicsSection = require('utils/nics-section'); var VMGroupSection = require('utils/vmgroup-section'); @@ -36,6 +37,7 @@ define(function(require) { var CapacityInputs = require('tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-inputs'); var Config = require('sunstone-config'); var HostsTable = require('tabs/hosts-tab/datatable'); + var DatastoresTable = require('tabs/datastores-tab/datatable'); /* CONSTANTS @@ -182,6 +184,11 @@ define(function(require) { tmp_json.SCHED_REQUIREMENTS = sched; } + var sched_ds = WizardFields.retrieveInput($("#SCHED_DS_REQUIREMENTS" + template_id, context)); + if(sched_ds){ + tmp_json.SCHED_DS_REQUIREMENTS = sched_ds; + } + var nics = []; var pcis = []; @@ -266,6 +273,7 @@ define(function(require) { timeout: true, success: function (request, template_json) { that.template_objects.push(template_json); + var options = { 'select': true, 'selectOptions': { @@ -274,26 +282,68 @@ define(function(require) { } that.hostsTable = new HostsTable('HostsTable' + template_json.VMTEMPLATE.ID, options); + that.datastoresTable = new DatastoresTable('DatastoresTable' + template_json.VMTEMPLATE.ID, options); + templatesContext.append( TemplateRowHTML( { element: template_json.VMTEMPLATE, capacityInputsHTML: CapacityInputs.html(), - hostsDatatable: that.hostsTable.dataTableHTML + hostsDatatable: that.hostsTable.dataTableHTML, + dsDatatable: that.datastoresTable.dataTableHTML }) ); $(".provision_host_selector" + template_json.VMTEMPLATE.ID, context).data("hostsTable", that.hostsTable); + $(".provision_ds_selector" + template_json.VMTEMPLATE.ID, context).data("dsTable", that.datastoresTable); + var selectOptions = { 'selectOptions': { 'select_callback': function(aData, options) { - generateRequirements($(".provision_host_selector" + template_json.VMTEMPLATE.ID, context).data("hostsTable"), context, template_json.VMTEMPLATE.ID); + var hostTable = $(".provision_host_selector" + template_json.VMTEMPLATE.ID, context).data("hostsTable"); + var dsTable = $(".provision_ds_selector" + template_json.VMTEMPLATE.ID, context).data("dsTable"); + generateRequirements(hostTable, dsTable, context, template_json.VMTEMPLATE.ID); }, 'unselect_callback': function(aData, options) { - generateRequirements($(".provision_host_selector"+ template_json.VMTEMPLATE.ID, context).data("hostsTable"), context, template_json.VMTEMPLATE.ID); - } + var hostTable = $(".provision_host_selector" + template_json.VMTEMPLATE.ID, context).data("hostsTable"); + var dsTable = $(".provision_ds_selector" + template_json.VMTEMPLATE.ID, context).data("dsTable"); + generateRequirements(hostTable, dsTable, context, template_json.VMTEMPLATE.ID); + } } } that.hostsTable.initialize(selectOptions); that.hostsTable.refreshResourceTableSelect(); + that.datastoresTable.initialize(selectOptions); + that.datastoresTable.filter("system", 10); + that.datastoresTable.refreshResourceTableSelect(); + + var reqJSON = template_json.VMTEMPLATE.TEMPLATE.SCHED_REQUIREMENTS; + if (reqJSON) { + $('#SCHED_REQUIREMENTS' + template_json.VMTEMPLATE.ID, context).val(reqJSON); + var req = TemplateUtils.escapeDoubleQuotes(reqJSON); + var host_id_regexp = /(\s|\||\b)ID=\\"([0-9]+)\\"/g; + var hosts = []; + while (match = host_id_regexp.exec(req)) { + hosts.push(match[2]); + } + var selectedResources = { + ids : hosts + } + that.hostsTable.selectResourceTableSelect(selectedResources); + } + + var dsReqJSON = template_json.VMTEMPLATE.TEMPLATE.SCHED_DS_REQUIREMENTS; + if (dsReqJSON) { + $('#SCHED_DS_REQUIREMENTS' + template_json.VMTEMPLATE.ID, context).val(dsReqJSON); + var dsReq = TemplateUtils.escapeDoubleQuotes(dsReqJSON); + var ds_id_regexp = /(\s|\||\b)ID=\\"([0-9]+)\\"/g; + var ds = []; + while (match = ds_id_regexp.exec(dsReq)) { + ds.push(match[2]); + } + var selectedResources = { + ids : ds + } + that.datastoresTable.selectResourceTableSelect(selectedResources); + } DisksResize.insert({ template_json: template_json, @@ -383,21 +433,22 @@ define(function(require) { Tips.setup(context); return false; } - function generateRequirements(hosts_table, context, id) { + + function generateRequirements(hosts_table, ds_table, context, id) { var req_string=[]; - //var req_ds_string=[]; + var req_ds_string=[]; var selected_hosts = hosts_table.retrieveResourceTableSelect(); - //var selected_ds = this.datastoresTable.retrieveResourceTableSelect(); + var selected_ds = ds_table.retrieveResourceTableSelect(); $.each(selected_hosts, function(index, hostId) { req_string.push('ID="'+hostId+'"'); }); - /*$.each(selected_ds, function(index, dsId) { + $.each(selected_ds, function(index, dsId) { req_ds_string.push('ID="'+dsId+'"'); - });*/ + }); $('#SCHED_REQUIREMENTS' + id, context).val(req_string.join(" | ")); - //$('#SCHED_DS_REQUIREMENTS', context).val(req_ds_string.join(" | ")); + $('#SCHED_DS_REQUIREMENTS' + id, context).val(req_ds_string.join(" | ")); }; }); diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate/templateRow.hbs b/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate/templateRow.hbs index 9ea6dd7639..a41df9e6cf 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate/templateRow.hbs +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate/templateRow.hbs @@ -67,6 +67,7 @@ + {{#isFeatureEnabled "show_host_instantiate"}}
@@ -86,7 +87,29 @@
-
+ {{/isFeatureEnabled}} + {{#isFeatureEnabled "show_ds_instantiate"}} +
+
+
+ + {{tr "Datastore"}} + +
{{{dsDatatable}}}
+
+
+ + +
+
+
+
+
+ {{/isFeatureEnabled}} +