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) { '