1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

feature #3782: Changes in OCA (Ruby) and CLI. Updated direct references

to OCA methods
This commit is contained in:
Ruben S. Montero 2015-06-10 01:30:22 +02:00
parent 9d20167c1c
commit ce85188042
10 changed files with 47 additions and 91 deletions

View File

@ -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);

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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();

View File

@ -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 )

View File

@ -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)

View File

@ -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);

View File

@ -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();

View File

@ -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)