From dffe1f1c52b32582f28d96f1c516384448de2f40 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Tue, 21 Jul 2015 15:06:59 +0200 Subject: [PATCH] Feature #3748: Chmod in cloud view now applies to all the template images --- .../models/OpenNebulaJSON/TemplateJSON.rb | 20 +++++++++- .../public/app/opennebula/template.js | 4 ++ .../app/tabs/provision-tab/templates/list.js | 40 +++---------------- 3 files changed, 29 insertions(+), 35 deletions(-) diff --git a/src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb b/src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb index 5635c02f8c..80680e3837 100644 --- a/src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb @@ -52,6 +52,8 @@ module OpenNebulaJSON when "rename" then self.rename(action_hash['params']) when "delete_from_provision" then self.delete_from_provision(action_hash['params']) + when "chmod_from_provision" + then self.chmod_from_provision(action_hash['params']) else error_msg = "#{action_hash['perform']} action not " << " available for this resource" @@ -122,7 +124,7 @@ module OpenNebulaJSON # Delete associated images self.each("TEMPLATE/DISK/IMAGE_ID"){|image_id| img = OpenNebula::Image.new_with_id(image_id.text, @client) - rc = img.delete + rc = img.delete if OpenNebula::is_error?(rc) error_msg = "Some of the resources associated with " << "this template couldn't be deleted. Error: " << rc.message @@ -133,5 +135,21 @@ module OpenNebulaJSON # Delete template self.delete end + + def chmod_from_provision(params=Hash.new) + # Chmod associated images + self.each("TEMPLATE/DISK/IMAGE_ID"){|image_id| + img = OpenNebulaJSON::ImageJSON.new_with_id(image_id.text, @client) + rc = img.chmod_json(params) + if OpenNebula::is_error?(rc) + error_msg = "Some of the resources associated with " << + "this template couldn't be published. Error: " << rc.message + return OpenNebula::Error.new(error_msg) + end + } + + # Chmod template + self.chmod_json(params) + end end end diff --git a/src/sunstone/public/app/opennebula/template.js b/src/sunstone/public/app/opennebula/template.js index 8259776b8f..d2a8fb091a 100644 --- a/src/sunstone/public/app/opennebula/template.js +++ b/src/sunstone/public/app/opennebula/template.js @@ -30,6 +30,10 @@ define(function(require) { var action_obj = params.data.extra_param; OpenNebulaAction.simple_action(params, RESOURCE, "chmod", action_obj); }, + "chmod_from_provision": function(params) { + var action_obj = params.data.extra_param; + OpenNebulaAction.simple_action(params, RESOURCE, "chmod_from_provision", action_obj); + }, "update" : function(params) { var action_obj = params.data.extra_param; OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); diff --git a/src/sunstone/public/app/tabs/provision-tab/templates/list.js b/src/sunstone/public/app/tabs/provision-tab/templates/list.js index ce8c710bae..8e922156df 100644 --- a/src/sunstone/public/app/tabs/provision-tab/templates/list.js +++ b/src/sunstone/public/app/tabs/provision-tab/templates/list.js @@ -270,7 +270,6 @@ define(function(require) { context.on("click", ".provision_confirm_chmod_template_button", function(){ var ul_context = $(this).parents(".provision-pricing-table"); var template_id = ul_context.attr("opennebula_id"); - var image_id = ul_context.attr("saved_to_image_id"); var template_name = $(".provision-title", ul_context).text(); $(".provision_confirm_delete_template_div", context).html( @@ -284,7 +283,7 @@ define(function(require) { ''+ ''+ '
'+ - ''+Locale.tr("Share template")+''+ + ''+Locale.tr("Share template")+''+ '
'+ ''+ '×'+ @@ -292,16 +291,13 @@ define(function(require) { }); context.on("click", ".provision_chmod_template_button", function(){ - /* TODO SAVED_TO_IMAGE_ID does not exists anymore and now all the images of the template - are cloned instead of only the main disk, therefore all the images should be chmod now. - Probably this could be done in the core + var button = $(this); button.attr("disabled", "disabled"); var template_id = $(this).attr("template_id"); - var image_id = $(this).attr("image_id"); - OpenNebula.Template.chmod({ + OpenNebula.Template.chmod_from_provision({ timeout: true, data : { id : template_id, @@ -309,26 +305,14 @@ define(function(require) { }, success: function (){ $(".provision_templates_list_refresh_button", context).trigger("click"); - - OpenNebula.Image.chmod({ - timeout: true, - data : { - id : image_id, - extra_param: {'group_u': 1} - }, - success: function (){ - }, - error: Notifier.onError - }) }, error: Notifier.onError - })*/ + }) }); context.on("click", ".provision_confirm_unshare_template_button", function(){ var ul_context = $(this).parents(".provision-pricing-table"); var template_id = ul_context.attr("opennebula_id"); - var image_id = ul_context.attr("saved_to_image_id"); var template_name = $(".provision-title", ul_context).first().text(); $(".provision_confirm_delete_template_div", context).html( @@ -342,7 +326,7 @@ define(function(require) { ''+ ''+ '
'+ - ''+Locale.tr("Unshare template")+''+ + ''+Locale.tr("Unshare template")+''+ '
'+ ''+ '×'+ @@ -354,9 +338,8 @@ define(function(require) { button.attr("disabled", "disabled"); var template_id = $(this).attr("template_id"); - var image_id = $(this).attr("image_id"); - OpenNebula.Template.chmod({ + OpenNebula.Template.chmod_from_provision({ timeout: true, data : { id : template_id, @@ -364,17 +347,6 @@ define(function(require) { }, success: function (){ $(".provision_templates_list_refresh_button", context).trigger("click"); - - OpenNebula.Image.chmod({ - timeout: true, - data : { - id : image_id, - extra_param: {'group_u': 0} - }, - success: function (){ - }, - error: Notifier.onError - }) }, error: Notifier.onError })