From aa79958aec0681b7403268d477966b2f36fa4b4c Mon Sep 17 00:00:00 2001 From: juanmont Date: Wed, 15 Nov 2017 17:31:40 +0100 Subject: [PATCH] B #5555: Fix conflict INHERIT vs RESTRICTED * bug-inherit-attr: Fixed bug with \n * bug-inherit-attr: Saved template_json_base within data attribute (cherry picked from commit 607cde3dafe89f77480aed4e0442a965d91eaa71) --- src/rm/RequestManagerVMTemplate.cc | 11 +++--- src/sunstone/public/app/tabs/provision-tab.js | 15 ++++++++ .../templates-tab/form-panels/instantiate.js | 16 +++++++++ src/sunstone/public/app/utils/disks-resize.js | 36 +++++++++++++------ src/sunstone/sunstone-server.rb | 3 +- 5 files changed, 64 insertions(+), 17 deletions(-) diff --git a/src/rm/RequestManagerVMTemplate.cc b/src/rm/RequestManagerVMTemplate.cc index 68b854a8fb..6c49a2ea5e 100644 --- a/src/rm/RequestManagerVMTemplate.cc +++ b/src/rm/RequestManagerVMTemplate.cc @@ -255,10 +255,7 @@ Request::ErrorCode VMTemplateInstantiate::merge( const string &str_uattrs, RequestAttributes& att) { - if (str_uattrs.empty()) - { - return SUCCESS; - } + int rc; @@ -270,11 +267,15 @@ Request::ErrorCode VMTemplateInstantiate::merge( if ( rc != 0 ) { return INTERNAL; + } + else if (uattrs.empty()) + { + return SUCCESS; } if (att.uid!=UserPool::ONEADMIN_ID && att.gid!=GroupPool::ONEADMIN_ID) { - if (uattrs.check_restricted(aname, tmpl)) + if (uattrs.check_restricted(aname, tmpl)) { att.resp_msg ="User Template includes a restricted attribute " + aname; diff --git a/src/sunstone/public/app/tabs/provision-tab.js b/src/sunstone/public/app/tabs/provision-tab.js index 2e106a5b07..56e8033dcc 100644 --- a/src/sunstone/public/app/tabs/provision-tab.js +++ b/src/sunstone/public/app/tabs/provision-tab.js @@ -926,6 +926,9 @@ define(function(require) { tab.on("click", "#provision_create_vm .provision_select_template .provision-pricing-table.only-one" , function(){ var create_vm_context = $("#provision_create_vm"); + var that = this; + + that.template_base_json = {}; if ($(this).hasClass("selected")){ //$(".provision_disk_selector", create_vm_context).html(""); @@ -954,6 +957,17 @@ define(function(require) { $("#provision_create_vm .provision_vmgroup").show(); $("#provision_create_vm .provision_ds").show(); + OpenNebulaTemplate.show({ + data : { + id: template_id, + extended: false + }, + timeout: true, + success: function (request, template_json) { + that.template_base_json= template_json; + } + }); + OpenNebula.Template.show({ data : { id: template_id, @@ -975,6 +989,7 @@ define(function(require) { pers = false; } DisksResize.insert({ + template_base_json: that.template_base_json, template_json: template_json, disksContext: disksContext, force_persistent: pers, 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 4f065607d3..dbb44f3358 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 @@ -371,14 +371,29 @@ define(function(require) { this.selected_nodes = selected_nodes; this.template_objects = []; + this.template_base_objects = {}; var templatesContext = $(".list_of_templates", context); var idsLength = this.selected_nodes.length; var idsDone = 0; + $.each(this.selected_nodes, function(index, template_id) { + OpenNebulaTemplate.show({ + data : { + id: template_id, + extended: false + }, + timeout: true, + success: function (request, template_json) { + that.template_base_objects[template_json.VMTEMPLATE.ID] = template_json; + } + }); + }); + templatesContext.html(""); $.each(this.selected_nodes, function(index, template_id) { + OpenNebulaTemplate.show({ data : { id: template_id, @@ -463,6 +478,7 @@ define(function(require) { } DisksResize.insert({ + template_base_json: that.template_base_objects[template_json.VMTEMPLATE.ID], template_json: template_json, disksContext: $(".disksContext" + template_json.VMTEMPLATE.ID, context), force_persistent: $("input.instantiate_pers", context).prop("checked"), diff --git a/src/sunstone/public/app/utils/disks-resize.js b/src/sunstone/public/app/utils/disks-resize.js index 814dcc916d..e366009a5a 100644 --- a/src/sunstone/public/app/utils/disks-resize.js +++ b/src/sunstone/public/app/utils/disks-resize.js @@ -76,6 +76,16 @@ define(function(require){ disks = [template_disk] } + if (opts.template_base_json) { + var template_base_disk = opts.template_base_json.VMTEMPLATE.TEMPLATE.DISK + var disks_base = [] + if ($.isArray(template_base_disk)) { + disks_base = template_base_disk + } else if (!$.isEmptyObject(template_base_disk)) { + disks_base = [template_base_disk] + } + } + if (disks.length > 0) { disksContext.html(DisksResizeTemplate()); @@ -101,17 +111,23 @@ define(function(require){ var diskContext; $(".disksContainer", disksContext).html(""); - $.each(disks, function(disk_id, disk) { - diskContext = $( - '
'+ - '
'+ - ''+ - '
'+ - '
' + - '
' + - '
').appendTo($(".disksContainer", disksContext)); - diskContext.data('template_disk', disk); + if (disks_base) { + $.each(disks_base, function(disk_id, disk) { + diskContext = $( + '
'+ + '
'+ + ''+ + '
'+ + '
' + + '
' + + '
').appendTo($(".disksContainer", disksContext)); + + diskContext.data('template_disk', disk); + }); + } + + $.each(disks, function(disk_id, disk) { var disk_snapshot_total_size = 0; if (disk.DISK_SNAPSHOT_TOTAL_SIZE != undefined) { diff --git a/src/sunstone/sunstone-server.rb b/src/sunstone/sunstone-server.rb index 7f951a6b3f..1a774044df 100755 --- a/src/sunstone/sunstone-server.rb +++ b/src/sunstone/sunstone-server.rb @@ -715,13 +715,12 @@ end ############################################################################## # GET Resource information ############################################################################## - get '/:resource/:id/template' do @SunstoneServer.get_template(params[:resource], params[:id]) end get '/:resource/:id' do - if params[:extended] + if params[:extended] && params[:extended] != "false" @SunstoneServer.get_resource(params[:resource], params[:id], true) else @SunstoneServer.get_resource(params[:resource], params[:id])