From 6bbe71a386d2c08a7d0ba4e367ce723ca274e5d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 17 Nov 2015 13:15:14 +0100 Subject: [PATCH] Bug #4108: Add option to create persistent images in onevm save-as-template (cherry picked from commit 45b33cabc5440e73051db06056388a7f732a7cdb) --- src/cli/onevm | 10 +++++-- src/oca/ruby/opennebula/virtual_machine.rb | 8 +++++- .../OpenNebulaJSON/VirtualMachineJSON.rb | 2 +- .../public/app/tabs/provision-tab/vms/list.js | 28 +++++++++++++++++-- .../tabs/vms-tab/dialogs/saveas-template.js | 4 ++- .../vms-tab/dialogs/saveas-template/html.hbs | 6 ++++ 6 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/cli/onevm b/src/cli/onevm index 5abc6210c4..270311d217 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -127,6 +127,12 @@ cmd=CommandParser::CmdParser.new(ARGV) do :description => "ID of the Snapshot to save." } + PERSISTENT={ + :name => "persistent", + :large => "--persistent", + :description => "Make the new images persistent" + } + ######################################################################## # Global Options ######################################################################## @@ -916,9 +922,9 @@ cmd=CommandParser::CmdParser.new(ARGV) do States: POWEROFF EOT - command :save, save_desc, :vmid, :name do + command :save, save_desc, :vmid, :name, :options=>[PERSISTENT] do helper.perform_action(args[0],options,"Saving VM") do |vm| - res = vm.save_as_template(args[1]) + res = vm.save_as_template(args[1], options[:persistent] ) if !OpenNebula.is_error?(res) puts "Template ID: #{res}" diff --git a/src/oca/ruby/opennebula/virtual_machine.rb b/src/oca/ruby/opennebula/virtual_machine.rb index 84a3ef1874..7cbee40926 100644 --- a/src/oca/ruby/opennebula/virtual_machine.rb +++ b/src/oca/ruby/opennebula/virtual_machine.rb @@ -712,10 +712,12 @@ module OpenNebula # of the current disks. The VM capacity and NICs are also preserved # # @param name [String] Name for the new Template + # @param name [true,false,nil] Optional, true to make the saved images + # persistent, false make them non-persistent # # @return [Integer, OpenNebula::Error] the new Template ID in case of # success, error otherwise - def save_as_template(name) + def save_as_template(name, persistent=nil) img_ids = [] new_tid = nil @@ -797,6 +799,10 @@ module OpenNebula raise if OpenNebula.is_error?(rc) + if persistent == true + OpenNebula::Image.new_with_id(rc.to_i, @client).persistent() + end + img_ids << rc.to_i replace << "DISK = [ IMAGE_ID = #{rc} ]\n" diff --git a/src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb b/src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb index d4bde1ecd2..1cce24e2af 100644 --- a/src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb @@ -187,7 +187,7 @@ module OpenNebulaJSON def save_as_template(params=Hash.new) vm_new = VirtualMachine.new(VirtualMachine.build_xml(@pe_id), @client) - vm_new.save_as_template(params['name']) + vm_new.save_as_template(params['name'], params['persistent']) end end end diff --git a/src/sunstone/public/app/tabs/provision-tab/vms/list.js b/src/sunstone/public/app/tabs/provision-tab/vms/list.js index d6387e8cf3..983c948c3f 100644 --- a/src/sunstone/public/app/tabs/provision-tab/vms/list.js +++ b/src/sunstone/public/app/tabs/provision-tab/vms/list.js @@ -503,7 +503,7 @@ define(function(require) { '
'+ '
'+ ''+ - Locale.tr("This Virtual Machine will be saved in a new Template. Only the main disk will be preserved!")+ + Locale.tr("This Virtual Machine will be saved in a new Template.")+ '
'+ Locale.tr("You can then create a new Virtual Machine using this Template.")+ '
'+ @@ -516,6 +516,27 @@ define(function(require) { '
'+ '
'+ '
'+ + '
'+ + '
'+ + ''+ + Locale.tr("The new Virtual Machine's disks can be made persistent. In a persistent Virtual Machine the changes made survive after it is destroyed. On the other hand, you cannot create more than one simultaneous Virtual Machine from a Template with persistent disks.")+ + ''+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + ''+ + ''+ + '
'+ + '
'+ + '
'+ '
'+ '
'+ ''+Locale.tr("Save Virtual Machine to Template")+''+ @@ -532,12 +553,15 @@ define(function(require) { var vm_id = context.attr("vm_id"); var template_name = $('.provision_snapshot_name', context).val(); + var persistent = + ($('input[name=provision_snapshot_radio]:checked').val() == "persistent"); OpenNebula.VM.save_as_template({ data : { id: vm_id, extra_param: { - name : template_name + name : template_name, + persistent : persistent } }, timeout: false, diff --git a/src/sunstone/public/app/tabs/vms-tab/dialogs/saveas-template.js b/src/sunstone/public/app/tabs/vms-tab/dialogs/saveas-template.js index 475e9794d1..0d117dd932 100644 --- a/src/sunstone/public/app/tabs/vms-tab/dialogs/saveas-template.js +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/saveas-template.js @@ -70,13 +70,15 @@ define(function(require) { $('#' + DIALOG_ID + 'Form', context).submit(function() { var template_name = $('#template_name', this).val(); + var persistent = $('#saveas_persistency', this).is(":checked") ? true : false; var vm_id = $("#vm_id", context).val(); OpenNebula.VM.save_as_template({ data : { id: vm_id, extra_param: { - name : template_name + name : template_name, + persistent : persistent } }, success: function(request, response){ diff --git a/src/sunstone/public/app/tabs/vms-tab/dialogs/saveas-template/html.hbs b/src/sunstone/public/app/tabs/vms-tab/dialogs/saveas-template/html.hbs index 070f1c3f85..f06410b8c0 100644 --- a/src/sunstone/public/app/tabs/vms-tab/dialogs/saveas-template/html.hbs +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/saveas-template/html.hbs @@ -34,6 +34,12 @@
+
+
+ + +
+