diff --git a/src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb b/src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb index 1ca880f37e..5635c02f8c 100644 --- a/src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb @@ -50,6 +50,8 @@ module OpenNebulaJSON when "instantiate" then self.instantiate(action_hash['params']) when "clone" then self.clone(action_hash['params']) when "rename" then self.rename(action_hash['params']) + when "delete_from_provision" + then self.delete_from_provision(action_hash['params']) else error_msg = "#{action_hash['perform']} action not " << " available for this resource" @@ -115,5 +117,21 @@ module OpenNebulaJSON def rename(params=Hash.new) super(params['name']) end + + def delete_from_provision(params=Hash.new) + # Delete associated images + self.each("TEMPLATE/DISK/IMAGE_ID"){|image_id| + img = OpenNebula::Image.new_with_id(image_id.text, @client) + 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 + return OpenNebula::Error.new(error_msg) + end + } + + # Delete template + self.delete + end end end diff --git a/src/sunstone/public/app/opennebula/template.js b/src/sunstone/public/app/opennebula/template.js index b202e0d114..8259776b8f 100644 --- a/src/sunstone/public/app/opennebula/template.js +++ b/src/sunstone/public/app/opennebula/template.js @@ -11,6 +11,9 @@ define(function(require) { "del" : function(params) { OpenNebulaAction.del(params, RESOURCE); }, + "delete_from_provision": function(params) { + OpenNebulaAction.simple_action(params, RESOURCE, "delete_from_provision"); + }, "list" : function(params) { OpenNebulaAction.list(params, RESOURCE); }, 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 d053b50591..ce8c710bae 100644 --- a/src/sunstone/public/app/tabs/provision-tab/templates/list.js +++ b/src/sunstone/public/app/tabs/provision-tab/templates/list.js @@ -222,7 +222,6 @@ define(function(require) { context.on("click", ".provision_confirm_delete_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( @@ -236,7 +235,7 @@ define(function(require) { ''+ ''+ '