mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-22 13:33:52 +03:00
Adding the ability to CANCEL a virtual machine
Added it in the Dispatch Manager (lcm already prepared), the Request Manager and the ruby CLI git-svn-id: http://svn.opennebula.org/trunk@88 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
parent
04f78575b4
commit
27664b123d
@ -166,6 +166,15 @@ public:
|
||||
int stop(
|
||||
int vid);
|
||||
|
||||
/**
|
||||
* Cancels a VM.
|
||||
* @param vid VirtualMachine identification
|
||||
* @return 0 on success, -1 if the VM does not exits or -2 if the VM is
|
||||
* in a wrong a state
|
||||
*/
|
||||
int cancel(
|
||||
int vid);
|
||||
|
||||
/**
|
||||
* Suspends a VM.
|
||||
* @param vid VirtualMachine identification
|
||||
|
@ -245,6 +245,29 @@ private:
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
class VirtualMachineCancel: public xmlrpc_c::method
|
||||
{
|
||||
public:
|
||||
VirtualMachineCancel(
|
||||
VirtualMachinePool * _vmpool):
|
||||
vmpool(_vmpool)
|
||||
{
|
||||
_signature="A:si";
|
||||
_help="Cancels a virtual machine";
|
||||
};
|
||||
|
||||
~VirtualMachineCancel(){};
|
||||
|
||||
void execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retval);
|
||||
|
||||
private:
|
||||
VirtualMachinePool * vmpool;
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
class VirtualMachineInfo: public xmlrpc_c::method
|
||||
{
|
||||
public:
|
||||
|
@ -229,7 +229,8 @@ module ONE
|
||||
"deploy" => [:to_i, :to_i],
|
||||
"action" => [:to_s, :to_i],
|
||||
"migrate_" => [:to_i, :to_i, nil],
|
||||
"get_info" => [:to_i]
|
||||
"get_info" => [:to_i],
|
||||
"cancel" => [:to_i]
|
||||
}
|
||||
end
|
||||
|
||||
@ -273,6 +274,10 @@ module ONE
|
||||
self.action("stop", args[0])
|
||||
end
|
||||
|
||||
def cancel(*args)
|
||||
self.action("cancel", args[0])
|
||||
end
|
||||
|
||||
def suspend(*args)
|
||||
self.action("suspend", args[0])
|
||||
end
|
||||
|
@ -317,6 +317,9 @@ Commands:
|
||||
* stop (Stops a running VM)
|
||||
onevm stop <vm_id>
|
||||
|
||||
* cancel (Cancels a running VM)
|
||||
onevm cancel <vm_id>
|
||||
|
||||
* suspend (Saves a running VM)
|
||||
onevm suspend <vm_id>
|
||||
|
||||
@ -444,6 +447,14 @@ when "stop"
|
||||
exit 0
|
||||
end
|
||||
|
||||
when "cancel"
|
||||
check_parameters("cancel", 1)
|
||||
result=vm.cancel(*ARGV)
|
||||
if result[0]
|
||||
puts "Cancelling VM"
|
||||
exit 0
|
||||
end
|
||||
|
||||
when "suspend"
|
||||
check_parameters("suspend", 1)
|
||||
vm_id=get_vm_id(vm, ARGV[0])
|
||||
|
@ -357,6 +357,51 @@ error:
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int DispatchManager::cancel(
|
||||
int vid)
|
||||
{
|
||||
VirtualMachine * vm;
|
||||
ostringstream oss;
|
||||
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
oss << "Cancelling VM " << vid;
|
||||
Nebula::log("DiM",Log::DEBUG,oss);
|
||||
|
||||
if (vm->get_state() == VirtualMachine::ACTIVE &&
|
||||
vm->get_lcm_state() == VirtualMachine::RUNNING )
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
LifeCycleManager * lcm = nd.get_lcm();
|
||||
|
||||
vm->unlock();
|
||||
|
||||
lcm->trigger(LifeCycleManager::CANCEL,vid);
|
||||
}
|
||||
else
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
oss.str("");
|
||||
oss << "Could not cancel VM " << vid << ", wrong state.";
|
||||
Nebula::log("DiM",Log::ERROR,oss);
|
||||
|
||||
vm->unlock();
|
||||
return -2;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int DispatchManager::suspend(
|
||||
int vid)
|
||||
{
|
||||
|
@ -224,6 +224,9 @@ void RequestManager::register_xml_methods()
|
||||
xmlrpc_c::methodPtr vm_action(new
|
||||
RequestManager::VirtualMachineAction);
|
||||
|
||||
xmlrpc_c::methodPtr vm_cancel(new
|
||||
RequestManager::VirtualMachineCancel(vmpool));
|
||||
|
||||
xmlrpc_c::methodPtr vm_info(new
|
||||
RequestManager::VirtualMachineInfo(vmpool));
|
||||
|
||||
@ -245,6 +248,7 @@ void RequestManager::register_xml_methods()
|
||||
RequestManagerRegistry.addMethod("one.vmdeploy", vm_deploy);
|
||||
RequestManagerRegistry.addMethod("one.vmaction", vm_action);
|
||||
RequestManagerRegistry.addMethod("one.vmmigrate", vm_migrate);
|
||||
RequestManagerRegistry.addMethod("one.vmcancel", vm_cancel);
|
||||
RequestManagerRegistry.addMethod("one.vmget_info", vm_info);
|
||||
|
||||
/* Host related methods*/
|
||||
|
@ -58,6 +58,10 @@ void RequestManager::VirtualMachineAction::execute(
|
||||
{
|
||||
rc = dm->stop(vid);
|
||||
}
|
||||
else if (action == "cancel")
|
||||
{
|
||||
rc = dm->cancel(vid);
|
||||
}
|
||||
else if (action == "suspend")
|
||||
{
|
||||
rc = dm->suspend(vid);
|
||||
|
@ -45,7 +45,7 @@ void RequestManager::VirtualMachineInfo::execute(
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
vid = xmlrpc_c::value_int (paramList.getInt(1));
|
||||
|
||||
// Perform the allocation in the hostpool
|
||||
// Perform the allocation in the vmpool
|
||||
vm = VirtualMachineInfo::vmpool->get(vid,true);
|
||||
|
||||
|
||||
|
@ -11,6 +11,7 @@ source_files=[
|
||||
'RequestManagerAllocate.cc',
|
||||
'RequestManagerDeploy.cc',
|
||||
'RequestManagerMigrate.cc',
|
||||
'RequestManagerCancel.cc',
|
||||
'RequestManagerInfo.cc',
|
||||
'RequestManagerHostAllocate.cc',
|
||||
'RequestManagerHostDelete.cc',
|
||||
|
Loading…
Reference in New Issue
Block a user