diff --git a/src/cli/onevm b/src/cli/onevm index 0c5716f38c..3cd90e80ec 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -36,6 +36,15 @@ cmd=CommandParser::CmdParser.new(ARGV) do helper = OneVMHelper.new + + TYPE={ + :name => "type", + :short => "-t type", + :large => "--type type", + :format => String, + :description => "Type of the new Image" + } + ######################################################################## # Global Options ######################################################################## @@ -142,14 +151,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do States: ANY EOT - command :saveas, saveas_desc, :vmid, :diskid, :img_name do + command :saveas, saveas_desc, :vmid, :diskid, :img_name, :options=>[TYPE] do disk_id = args[1].to_i image_name = args[2] + image_type = options[:type] || "" + verbose = "disk #{disk_id} prepared to be saved in " << "the image #{image_name}" helper.perform_action(args[0],options,verbose) do |vm| - res = vm.save_as(disk_id, image_name) + res = vm.save_as(disk_id, image_name, image_type) if !OpenNebula.is_error?(res) puts "Image ID: #{res}" diff --git a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java index b15db02bdb..ccb89f254d 100644 --- a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java +++ b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java @@ -292,7 +292,22 @@ public class VirtualMachine extends PoolElement{ */ public OneResponse savedisk(int diskId, String imageName) { - return client.call(SAVEDISK, id ,diskId, imageName); + return savedisk(diskId, imageName, ""); + } + + /** + * Sets the specified vm's disk to be saved in a new image when the + * VirtualMachine shutdowns. + * + * @param diskId ID of the disk to be saved. + * @param imageName Name of the new Image that will be created. + * @param imageType Type of the new image. Set to empty string to use + * the default type + * @return If an error occurs the error message contains the reason. + */ + public OneResponse savedisk(int diskId, String imageName, String imageType) + { + return client.call(SAVEDISK, id ,diskId, imageName, imageType); } /** diff --git a/src/oca/ruby/OpenNebula/VirtualMachine.rb b/src/oca/ruby/OpenNebula/VirtualMachine.rb index 7360be8ef0..ee98880a9e 100644 --- a/src/oca/ruby/OpenNebula/VirtualMachine.rb +++ b/src/oca/ruby/OpenNebula/VirtualMachine.rb @@ -217,13 +217,19 @@ module OpenNebula # @param disk_id [Integer] ID of the disk to be saved # @param image_name [String] Name for the new image where the # disk will be saved + # @param image_type [String] Type of the new image. Set to empty string + # to use the default type # # @return [Integer, OpenNebula::Error] the new Image ID in case of # success, error otherwise - def save_as(disk_id, image_name) + def save_as(disk_id, image_name, image_type="") return Error.new('ID not defined') if !@pe_id - rc = @client.call(VM_METHODS[:savedisk], @pe_id, disk_id, image_name) + rc = @client.call(VM_METHODS[:savedisk], + @pe_id, + disk_id, + image_name, + image_type) return rc end diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index cdbef2c83e..17dd537084 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -394,6 +394,7 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis int id = xmlrpc_c::value_int(paramList.getInt(1)); int disk_id = xmlrpc_c::value_int(paramList.getInt(2)); string img_name = xmlrpc_c::value_string(paramList.getString(3)); + string img_type = xmlrpc_c::value_string(paramList.getString(4)); VirtualMachine * vm; string vm_owner; @@ -412,6 +413,11 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis oss << "PUBLIC = NO " << endl; oss << "SOURCE = - " << endl; + if ( img_type != "" ) + { + oss << "TYPE = " << img_type << endl; + } + itemplate = new ImageTemplate; itemplate->parse(oss.str(), &error_char);