diff --git a/src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb b/src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb index a5783979af..6b2957365d 100644 --- a/src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb @@ -46,6 +46,7 @@ module OpenNebulaJSON when "unpublish" then self.unpublish when "update" then self.update(action_hash['params']) when "chown" then self.chown(action_hash['params']) + when "instantiate" then self.instantiate(action_hash['params']) else error_msg = "#{action_hash['perform']} action not " << " available for this resource" @@ -60,5 +61,10 @@ module OpenNebulaJSON def chown(params=Hash.new) super(params['owner_id'].to_i,params['group_id'].to_i) end + + def instantiate(params=Hash.new) + super(params['vm_name']) + end + end end diff --git a/src/sunstone/public/js/opennebula.js b/src/sunstone/public/js/opennebula.js index dab77dd8a3..769bffab40 100644 --- a/src/sunstone/public/js/opennebula.js +++ b/src/sunstone/public/js/opennebula.js @@ -2333,6 +2333,39 @@ var OpenNebula = { }); }, + "instantiate" : function(params) { + var callback = params.success; + var callback_error = params.error; + var id = params.data.id; + var vm_name = params.data.extra_param ? params.data.extra_param : ""; + var vm_obj = { "vm_name" : vm_name } + + var method = "instantiate"; + var action = OpenNebula.Helper.action(method,vm_obj); + var resource = OpenNebula.Template.resource; + var request = OpenNebula.Helper.request(resource,method, [id,vm_obj]); + + $.ajax({ + url: "template/" + id + "/action", + type: "POST", + data: JSON.stringify(action), + success: function() + { + if (callback) + { + callback(request); + } + }, + error: function(response) + { + if(callback_error) + { + callback_error(request, OpenNebula.Error(response)); + } + } + }); + }, + "fetch_template" : function(params) { var callback = params.success; diff --git a/src/sunstone/public/js/plugins/templates-tab.js b/src/sunstone/public/js/plugins/templates-tab.js index 0b5b572cb4..2dfe909977 100644 --- a/src/sunstone/public/js/plugins/templates-tab.js +++ b/src/sunstone/public/js/plugins/templates-tab.js @@ -646,17 +646,22 @@ var template_actions = { notify: true }, - "Template.instantiate" : { + "Template.instantiate" : { + type: "single", + call: OpenNebula.Template.instantiate, + callback: function(){}, + error: onError, + notify: true + }, + + "Template.instantiate_vms" : { type: "custom", call: function(){ nodes = getSelectedNodes(dataTable_templates); $.each(nodes,function(){ - Sunstone.runAction("VM.create", - {vm : { - template_id: this - } - }); + Sunstone.runAction("Template.instantiate",this,""); }); + Sunstone.runAction("VM.refresh"); }, notify: false }, @@ -701,7 +706,7 @@ var template_buttons = { condition: True, alwaysActive: true }, - "Template.instantiate" : { + "Template.instantiate_vms" : { type: "action", text: "Instantiate", condition: True diff --git a/src/sunstone/public/js/plugins/vms-tab.js b/src/sunstone/public/js/plugins/vms-tab.js index 1ff74ae257..53c0afe8e5 100644 --- a/src/sunstone/public/js/plugins/vms-tab.js +++ b/src/sunstone/public/js/plugins/vms-tab.js @@ -96,11 +96,13 @@ var rfb; var vm_actions = { "VM.create" : { - type: "create", - call: OpenNebula.VM.create, + type: "custom", + call: function(id,name) { + Sunstone.runAction("Template.instantiate",id,name); + Sunstone.runAction("VM.list"); + }, callback: addVMachineElement, - error: onError, - notify: true + error: onError }, "VM.create_dialog" : { @@ -765,9 +767,8 @@ function setupCreateVMDialog(){ $('#create_vm_dialog #create_vm_proceed').click(function(){ var vm_name = $('#create_vm_form #vm_name').val(); var template_id = $('#create_vm_form #template_id').val(); - var vm_json = { vm: { vm_name: vm_name, template_id : template_id }}; - Sunstone.runAction("VM.create",vm_json); + Sunstone.runAction("VM.create",template_id,vm_name); $('#create_vm_dialog').dialog('close'); return false; });