Feature #4217: Add option to set VM Template name in export

This commit is contained in:
Carlos Martín committed 2016-04-04 15:28:04 +02:00
1 parent ff7acca61a
commit f37e2eac98
6 files changed
+64 -6

No files matched your search

@@ -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
+6 -2
View File
@@ -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)
+4 -1
View File
@@ -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)
@@ -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
@@ -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()
};
@@ -25,6 +25,17 @@
<input id="NAME" type="text" wizard_field="NAME"/>
</div>
</div>
<div class="row vmname" style="display:none">
<div class="medium-6 columns">
<label for="VMNAME">
{{tr "VM Template Name"}}:
<span class="tip">
{{tr "The following template will be created in OpenNebula and the previous images will be referenced in the disks."}}
</span>
</label>
<input id="VMNAME" type="text" wizard_field="VMNAME"/>
</div>
</div>
<fieldset>
<legend>{{tr "Select the Datastore to store the resource"}}</legend>
{{{datastoresTableHTML}}}