diff --git a/include/RequestManagerVirtualMachine.h b/include/RequestManagerVirtualMachine.h index bb1e849090..33f606d50e 100644 --- a/include/RequestManagerVirtualMachine.h +++ b/include/RequestManagerVirtualMachine.h @@ -170,15 +170,15 @@ public: /* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */ -class VirtualMachineSaveDisk : public RequestManagerVirtualMachine +class VirtualMachineDiskExport : public RequestManagerVirtualMachine { public: - VirtualMachineSaveDisk(): - RequestManagerVirtualMachine("VirtualMachineSaveDisk", - "Saves a disk from virtual machine as a new image", - "A:siissb"){}; + VirtualMachineDiskExport(): + RequestManagerVirtualMachine("VirtualMachineDiskExport", + "Exports a disk from virtual machine as a new image", + "A:siiss"){}; - ~VirtualMachineSaveDisk(){}; + ~VirtualMachineDiskExport(){}; void request_execute(xmlrpc_c::paramList const& _paramList, RequestAttributes& att); diff --git a/src/cli/onevm b/src/cli/onevm index 4ae4f74cb6..e97023ea3b 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -298,19 +298,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do end end - disk_snapshot_desc = <<-EOT.unindent - Sets the specified VM disk to be saved in a new Image. The Image is - created immediately, but the contents are saved only after the VM is - shut down gracefully (i.e., using 'onevm shutdown' and not - 'onevm delete') - - If '--live' is specified, the Image will be saved immediately. + disk_export_desc = <<-EOT.unindent + Exports the specified VM disk to a new Image. The Image is + created immediately, and the contents of the VM disk will be saved to + it. States: ANY EOT - command :"disk-snapshot", disk_snapshot_desc, :vmid, :diskid, :img_name, - :options=>[TYPE, OneVMHelper::LIVE] do + command :"disk-export", disk_export_desc, :vmid, :diskid, :img_name, + :options=>[TYPE] do disk_id = args[1].to_i image_name = args[2] image_type = options[:type] || "" @@ -319,8 +316,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do "the image #{image_name}" helper.perform_action(args[0],options,verbose) do |vm| - res = vm.disk_snapshot(disk_id, image_name, image_type, - options[:live]==true) + res = vm.disk_export(disk_id, image_name, image_type) if !OpenNebula.is_error?(res) puts "Image ID: #{res}" @@ -330,19 +326,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do end end - disk_snapshot_cancel_desc = <<-EOT.unindent - Cancels a deferred disk snapshot that has been set by disk-snapshot. - The target image is also deleted. - - States: ANY - EOT - - command :"disk-snapshot-cancel", disk_snapshot_cancel_desc, :vmid, :diskid do - helper.perform_action(args[0],options,"disk snapshot canceled") do |vm| - vm.disk_snapshot_cancel(args[1].to_i) - end - end - shutdown_desc = <<-EOT.unindent Shuts down the given VM. The VM life cycle will end. diff --git a/src/cloud/ec2/lib/EC2QueryServer.rb b/src/cloud/ec2/lib/EC2QueryServer.rb index c5c5ed0519..5381e4443c 100644 --- a/src/cloud/ec2/lib/EC2QueryServer.rb +++ b/src/cloud/ec2/lib/EC2QueryServer.rb @@ -218,10 +218,9 @@ class EC2QueryServer < CloudServer return rc end - image_id = vm.disk_snapshot(1, - params["Name"], - OpenNebula::Image::IMAGE_TYPES[0], - true) + image_id = vm.disk_export(1, + params["Name"], + OpenNebula::Image::IMAGE_TYPES[0]) # TODO Add AMI Tags # TODO A new persistent image should be created for each instance diff --git a/src/cloud/ec2/lib/ebs.rb b/src/cloud/ec2/lib/ebs.rb index c09e7ccc5c..9f6807ff87 100644 --- a/src/cloud/ec2/lib/ebs.rb +++ b/src/cloud/ec2/lib/ebs.rb @@ -302,10 +302,9 @@ module EBS disk_id = vm["TEMPLATE/DISK[IMAGE_ID=#{image_id}]/DISK_ID"] if !disk_id.nil? - snapshot_id = vm.disk_snapshot(disk_id.to_i, + snapshot_id = vm.disk_export(disk_id.to_i, params["Description"]||ImageEC2.generate_uuid, - OpenNebula::Image::IMAGE_TYPES[image["TYPE"].to_i], - true) + OpenNebula::Image::IMAGE_TYPES[image["TYPE"].to_i]) if OpenNebula::is_error?(snapshot_id) return snapshot_id diff --git a/src/image/ImageManagerActions.cc b/src/image/ImageManagerActions.cc index eefc7f52fc..6846353ac8 100644 --- a/src/image/ImageManagerActions.cc +++ b/src/image/ImageManagerActions.cc @@ -160,7 +160,7 @@ int ImageManager::acquire_image(int vm_id, Image *img, string& error) void ImageManager::release_image(int vm_id, int iid, bool failed) { - ostringstream disk_file, oss; + ostringstream oss; Image * img = ipool->get(iid,true); @@ -245,11 +245,7 @@ void ImageManager::release_image(int vm_id, int iid, bool failed) void ImageManager::release_cloning_image(int iid, int clone_img_id) { - Image * img; - - ostringstream disk_file; - - img = ipool->get(iid,true); + Image * img = ipool->get(iid,true); if ( img == 0 ) { @@ -276,15 +272,13 @@ void ImageManager::release_cloning_image(int iid, int clone_img_id) { case Image::USED: case Image::CLONE: - if (img->dec_cloning(clone_img_id) == 0 && img->get_running() == 0) { img->set_state(Image::READY); } ipool->update(img); - - break; + break; case Image::DELETE: case Image::INIT: @@ -293,14 +287,13 @@ void ImageManager::release_cloning_image(int iid, int clone_img_id) case Image::ERROR: case Image::USED_PERS: case Image::LOCKED: + ostringstream oss; - ostringstream oss; - oss << "Releasing image in wrong state: " - << Image::state_to_str(img->get_state()); + oss << "Releasing image in wrong state: " + << Image::state_to_str(img->get_state()); - NebulaLog::log("ImM", Log::ERROR, oss.str()); - - break; + NebulaLog::log("ImM", Log::ERROR, oss.str()); + break; } img->unlock(); diff --git a/src/lcm/LifeCycleStates.cc b/src/lcm/LifeCycleStates.cc index 5b958b1f11..7c350351d2 100644 --- a/src/lcm/LifeCycleStates.cc +++ b/src/lcm/LifeCycleStates.cc @@ -1623,16 +1623,19 @@ void LifeCycleManager::saveas_hot_success_action(int vid) vm->clear_saveas_disk(); - vmpool->update(vm); - if (vm->clear_saveas_state() == -1) { vm->log("LCM",Log::ERROR, "saveas_success_action, VM in a wrong state"); + + vmpool->update(vm); + vm->unlock(); return; } + vmpool->update(vm); + vm->unlock(); if ( rc != 0 ) @@ -1676,16 +1679,19 @@ void LifeCycleManager::saveas_hot_failure_action(int vid) vm->clear_saveas_disk(); - vmpool->update(vm); - if (vm->clear_saveas_state() == -1) { vm->log("LCM",Log::ERROR, "saveas_failure_action, VM in a wrong state"); + + vmpool->update(vm); + vm->unlock(); return; } + vmpool->update(vm); + vm->unlock(); if ( rc != 0 ) diff --git a/src/oca/ruby/opennebula/virtual_machine.rb b/src/oca/ruby/opennebula/virtual_machine.rb index 0b1d91a839..71dfda1ca7 100644 --- a/src/oca/ruby/opennebula/virtual_machine.rb +++ b/src/oca/ruby/opennebula/virtual_machine.rb @@ -29,8 +29,6 @@ module OpenNebula :action => "vm.action", :migrate => "vm.migrate", :deploy => "vm.deploy", - :savedisk => "vm.savedisk", - :savediskcancel => "vm.savediskcancel", :chown => "vm.chown", :chmod => "vm.chmod", :monitoring => "vm.monitoring", @@ -45,6 +43,7 @@ module OpenNebula :attachnic => "vm.attachnic", :detachnic => "vm.detachnic", :recover => "vm.recover", + :diskexport => "vm.diskexport", :disksnapshotcreate => "vm.disksnapshotcreate", :disksnapshotrevert => "vm.disksnapshotrevert", :disksnapshotdelete => "vm.disksnapshotdelete" @@ -468,36 +467,20 @@ module OpenNebula # disk will be saved # @param image_type [String] Type of the new image. Set to empty string # to use the default type - # @param hot [true|false] True to save the disk immediately, false will - # perform the operation when the VM shuts down # # @return [Integer, OpenNebula::Error] the new Image ID in case of # success, error otherwise - def disk_snapshot(disk_id, image_name, image_type="", hot=false) + def disk_export(disk_id, image_name, image_type="") return Error.new('ID not defined') if !@pe_id - rc = @client.call(VM_METHODS[:savedisk], + rc = @client.call(VM_METHODS[:diskexport], @pe_id, disk_id, image_name, - image_type, - hot) + image_type) return rc end - # @deprecated use {#disk_snapshot} - def save_as(disk_id, image_name, image_type="", hot=false) - return disk_snapshot(disk_id, image_name, image_type, hot) - end - - # Cancels a deferred snapshot that has been set by disk_snapshot. - # The target image is also deleted. - def disk_snapshot_cancel(disk_id) - return call(VM_METHODS[:savediskcancel], - @pe_id, - disk_id) - end - # Resize the VM # # @param capacity_template [String] Template containing the new capacity @@ -784,8 +767,7 @@ module OpenNebula image_id = disk["IMAGE_ID"] if !image_id.nil? && !image_id.empty? - rc = disk_snapshot(disk_id.to_i, "#{name}-disk-#{disk_id}", - "", true) + rc = disk_export(disk_id.to_i,"#{name}-disk-#{disk_id}","") return rc if OpenNebula.is_error?(rc) diff --git a/src/rm/RequestManager.cc b/src/rm/RequestManager.cc index 91dc6fe9df..72a29c3d91 100644 --- a/src/rm/RequestManager.cc +++ b/src/rm/RequestManager.cc @@ -293,7 +293,6 @@ void RequestManager::register_xml_methods() xmlrpc_c::methodPtr vm_deploy(new VirtualMachineDeploy()); xmlrpc_c::methodPtr vm_migrate(new VirtualMachineMigrate()); xmlrpc_c::methodPtr vm_action(new VirtualMachineAction()); - xmlrpc_c::methodPtr vm_savedisk(new VirtualMachineSaveDisk()); xmlrpc_c::methodPtr vm_monitoring(new VirtualMachineMonitoring()); xmlrpc_c::methodPtr vm_attach(new VirtualMachineAttach()); xmlrpc_c::methodPtr vm_detach(new VirtualMachineDetach()); @@ -303,6 +302,7 @@ void RequestManager::register_xml_methods() xmlrpc_c::methodPtr vm_snap_create(new VirtualMachineSnapshotCreate()); xmlrpc_c::methodPtr vm_snap_revert(new VirtualMachineSnapshotRevert()); xmlrpc_c::methodPtr vm_snap_delete(new VirtualMachineSnapshotDelete()); + xmlrpc_c::methodPtr vm_dexport(new VirtualMachineDiskExport()); xmlrpc_c::methodPtr vm_dsnap_create(new VirtualMachineDiskSnapshotCreate()); xmlrpc_c::methodPtr vm_dsnap_revert(new VirtualMachineDiskSnapshotRevert()); xmlrpc_c::methodPtr vm_dsnap_delete(new VirtualMachineDiskSnapshotDelete()); @@ -448,7 +448,6 @@ void RequestManager::register_xml_methods() RequestManagerRegistry.addMethod("one.vm.deploy", vm_deploy); RequestManagerRegistry.addMethod("one.vm.action", vm_action); RequestManagerRegistry.addMethod("one.vm.migrate", vm_migrate); - RequestManagerRegistry.addMethod("one.vm.savedisk", vm_savedisk); RequestManagerRegistry.addMethod("one.vm.allocate", vm_allocate); RequestManagerRegistry.addMethod("one.vm.info", vm_info); RequestManagerRegistry.addMethod("one.vm.chown", vm_chown); @@ -464,6 +463,7 @@ void RequestManager::register_xml_methods() RequestManagerRegistry.addMethod("one.vm.snapshotcreate", vm_snap_create); RequestManagerRegistry.addMethod("one.vm.snapshotrevert", vm_snap_revert); RequestManagerRegistry.addMethod("one.vm.snapshotdelete", vm_snap_delete); + RequestManagerRegistry.addMethod("one.vm.diskexport", vm_dexport); RequestManagerRegistry.addMethod("one.vm.disksnapshotcreate", vm_dsnap_create); RequestManagerRegistry.addMethod("one.vm.disksnapshotrevert", vm_dsnap_revert); RequestManagerRegistry.addMethod("one.vm.disksnapshotdelete", vm_dsnap_delete); diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index c812424844..6bb1d5cc3b 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -1176,7 +1176,7 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramList, +void VirtualMachineDiskExport::request_execute(xmlrpc_c::paramList const& paramList, RequestAttributes& att) { Nebula& nd = Nebula::instance(); @@ -1398,6 +1398,8 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis success_response(iid, att); + return; + error_state: vm->unlock(); diff --git a/src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb b/src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb index 987d780f78..b181f4ddd3 100644 --- a/src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb @@ -55,7 +55,6 @@ module OpenNebulaJSON when "suspend" then self.suspend when "reset" then self.reset when "saveas" then self.save_as(action_hash['params']) - when "disk_snapshot_cancel" then self.disk_snapshot_cancel(action_hash['params']) when "snapshot_create" then self.snapshot_create(action_hash['params']) when "snapshot_revert" then self.snapshot_revert(action_hash['params']) when "snapshot_delete" then self.snapshot_delete(action_hash['params']) @@ -105,14 +104,7 @@ module OpenNebulaJSON end def save_as(params=Hash.new) - clone = params['clonetemplate'] - clone = false if clone.nil? - - disk_snapshot(params['disk_id'].to_i, params['image_name'], params['type'], params['hot'], clone) - end - - def disk_snapshot_cancel(params=Hash.new) - super(params['disk_id'].to_i) + disk_export(params['disk_id'].to_i, params['image_name'], params['type']) end def snapshot_create(params=Hash.new)