diff --git a/src/cli/one_helper/onemarketapp_helper.rb b/src/cli/one_helper/onemarketapp_helper.rb index f456d32082..2aed43bc1d 100644 --- a/src/cli/one_helper/onemarketapp_helper.rb +++ b/src/cli/one_helper/onemarketapp_helper.rb @@ -43,6 +43,13 @@ class OneMarketPlaceAppHelper < OpenNebulaHelper::OneHelper OpenNebulaHelper::DRY ] + VMNAME = { + :name => "vmname", + :large => "--vmname name" , + :description => "Selects the name for the new VM Template, if the App contains one", + :format => String + } + def self.rname "MARKETPLACEAPP" end diff --git a/src/cli/onemarketapp b/src/cli/onemarketapp index 74188d0514..3baf424532 100755 --- a/src/cli/onemarketapp +++ b/src/cli/onemarketapp @@ -55,7 +55,7 @@ CommandParser::CmdParser.new(ARGV) do list_options << OpenNebulaHelper::DESCRIBE CREATE_OPTIONS = [OneMarketPlaceHelper::MARKETPLACE] - EXPORT_OPTIONS = [OneDatastoreHelper::DATASTORE] + EXPORT_OPTIONS = [OneDatastoreHelper::DATASTORE, OneMarketPlaceAppHelper::VMNAME] ######################################################################## # Formatters for arguments @@ -138,7 +138,11 @@ CommandParser::CmdParser.new(ARGV) do command :export, export_desc, :appid, :name, :options=>EXPORT_OPTIONS do helper.perform_action(args[0], options, "exported") do |obj| - rc = obj.export(:dsid=>options[:datastore], :name=>args[1]) + rc = obj.export({ + :dsid=>options[:datastore], + :name=>args[1], + :vmtemplate_name=>options[:vmname] + }) next rc if OpenNebula.is_error?(rc) diff --git a/src/oca/ruby/opennebula/marketplaceapp.rb b/src/oca/ruby/opennebula/marketplaceapp.rb index 1b0dd11c02..8bd6250784 100644 --- a/src/oca/ruby/opennebula/marketplaceapp.rb +++ b/src/oca/ruby/opennebula/marketplaceapp.rb @@ -158,6 +158,7 @@ module OpenNebula # @param options [Hash] to control the export behavior # dsid [Integer] datastore to save images # name [String] of the new object + # vmtemplate_name [String] name for the VM Template, if the App has one # # @return [Hash, OpenNebula::Error] with the ID and type of the created # objects. Instead of an ID, the array may contain OpenNebula::Error with @@ -198,7 +199,9 @@ module OpenNebula if !self['TEMPLATE/VMTEMPLATE64'].nil? tmpl=Base64::decode64(self['TEMPLATE/VMTEMPLATE64']) - tmpl << "\nNAME=\"#{name}\"\n" + tmpl_name = options[:vmtemplate_name] || name + + tmpl << "\nNAME=\"#{tmpl_name}\"\n" tmpl << "DISK=[ IMAGE_ID = #{image.id} ]\n" vmtpl = Template.new(Template.build_xml, @client) diff --git a/src/sunstone/models/OpenNebulaJSON/MarketPlaceAppJSON.rb b/src/sunstone/models/OpenNebulaJSON/MarketPlaceAppJSON.rb index 57d6121985..50051e2e4e 100644 --- a/src/sunstone/models/OpenNebulaJSON/MarketPlaceAppJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/MarketPlaceAppJSON.rb @@ -72,7 +72,13 @@ module OpenNebulaJSON def export(params=Hash.new) dsid = params['dsid'] ? params['dsid'].to_i : params['dsid'] name = params['name'] - rc = super({:dsid => dsid, :name => name}) + vmtemplate_name = params['vmtemplate_name'] + rc = super({ + :dsid => dsid, + :name => name, + :vmtemplate_name => vmtemplate_name + }) + if OpenNebula.is_error?(rc) return rc else diff --git a/src/sunstone/public/app/tabs/marketplaceapps-tab/form-panels/export.js b/src/sunstone/public/app/tabs/marketplaceapps-tab/form-panels/export.js index eef0f9c8bc..245de8a53f 100644 --- a/src/sunstone/public/app/tabs/marketplaceapps-tab/form-panels/export.js +++ b/src/sunstone/public/app/tabs/marketplaceapps-tab/form-panels/export.js @@ -27,8 +27,8 @@ define(function(require) { var DataStoresTable = require('tabs/datastores-tab/datatable'); var DataStore = require('opennebula/datastore'); var Config = require('sunstone-config'); - var WizardFields = require('utils/wizard-fields'); var OpenNebula = require('opennebula'); + var TemplateUtils = require('utils/template-utils'); /* TEMPLATES @@ -92,6 +92,8 @@ define(function(require) { } function _onShow(context) { + Sunstone.disableFormPanelSubmit(TAB_ID); + this.datastoresTable.resetResourceTableSelect(); $("#NAME", context).focus(); @@ -105,17 +107,42 @@ define(function(require) { this.datastoresTable.initialize(); this.datastoresTable.idInput().attr('required', ''); + + $('input#NAME', context).on('input', function(){ + var vmname = $("#VMNAME", context).val(); + + if (vmname == "" || vmname == $(this).data("prev")){ + $("#VMNAME", context).val($(this).val()); + } + + $(this).data("prev", $(this).val()); + }); } function _setResourceId(context, resourceId) { this.resourceId = resourceId; - $('input#NAME', context).val(OpenNebula.MarketPlaceApp.getName(resourceId)); + OpenNebula.MarketPlaceApp.show({ + data : { + id: resourceId + }, + success: function(request,app_json){ + $('input#NAME', context).val(app_json.MARKETPLACEAPP.NAME).trigger('input'); + + if (app_json.MARKETPLACEAPP.TEMPLATE.VMTEMPLATE64 != undefined){ + $(".vmname", context).show(); + } + + Sunstone.enableFormPanelSubmit(TAB_ID); + }, + error: Notifier.onError + }); } function _submitWizard(context) { var marketPlaceAppObj = { "name" : $("#NAME", context).val(), + "vmtemplate_name" : $("#VMNAME", context).val(), "dsid" : this.datastoresTable.idInput().val() }; diff --git a/src/sunstone/public/app/tabs/marketplaceapps-tab/form-panels/export/wizard.hbs b/src/sunstone/public/app/tabs/marketplaceapps-tab/form-panels/export/wizard.hbs index 3e06f92298..3325e53ff3 100644 --- a/src/sunstone/public/app/tabs/marketplaceapps-tab/form-panels/export/wizard.hbs +++ b/src/sunstone/public/app/tabs/marketplaceapps-tab/form-panels/export/wizard.hbs @@ -25,6 +25,17 @@ +
{{tr "Select the Datastore to store the resource"}} {{{datastoresTableHTML}}}