mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-19 03:12:55 +09:00
feature #2009: Implementation of recover XML-RPC method and Core functionality
(cherry picked from commit 051a575f1d8bbc8c78d96ccb426c2cd4de29bdb1)
This commit is contained in:
1 parent
f3e7dda923
commit
cdc97ce18a
5 files changed
+250
No files matched your search
@@ -121,6 +121,13 @@ public:
|
||||
return lcm_thread;
|
||||
};
|
||||
|
||||
/**
|
||||
* Recovers a VM by self-triggering the associated lost transition.
|
||||
* @param vm to be recovered
|
||||
* @param success trigger successful transition if true, fail otherwise
|
||||
*/
|
||||
void recover(VirtualMachine * vm, bool success);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Thread id for the Virtual Machine Manager
|
||||
|
||||
@@ -316,6 +316,26 @@ public:
|
||||
RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class VirtualMachineRecover: public RequestManagerVirtualMachine
|
||||
{
|
||||
public:
|
||||
VirtualMachineRecover():
|
||||
RequestManagerVirtualMachine("VirtualMachineRecover",
|
||||
"Recovers a virtual machine",
|
||||
"A:sib")
|
||||
{
|
||||
auth_op = AuthRequest::ADMIN;
|
||||
};
|
||||
|
||||
~VirtualMachineRecover(){};
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList,
|
||||
RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
@@ -993,3 +993,181 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm, bool dispose, int& imag
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void LifeCycleManager::recover(VirtualMachine * vm, bool success)
|
||||
{
|
||||
LifeCycleManager::Actions lcm_action = LifeCycleManager::FINALIZE;
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
DispatchManager * dm = nd.get_dm();
|
||||
|
||||
switch (vm->get_lcm_state())
|
||||
{
|
||||
//----------------------------------------------------------------------
|
||||
// Direct recovery states
|
||||
//----------------------------------------------------------------------
|
||||
case VirtualMachine::LCM_INIT:
|
||||
case VirtualMachine::RUNNING:
|
||||
return;
|
||||
|
||||
case VirtualMachine::CLEANUP_DELETE:
|
||||
dm->trigger(DispatchManager::DONE, vm->get_oid());
|
||||
return;
|
||||
|
||||
case VirtualMachine::CLEANUP_RESUBMIT:
|
||||
dm->trigger(DispatchManager::RESUBMIT, vm->get_oid());
|
||||
return;
|
||||
|
||||
case VirtualMachine::UNKNOWN:
|
||||
vm->set_state(VirtualMachine::RUNNING);
|
||||
vmpool->update(vm);
|
||||
return;
|
||||
|
||||
case VirtualMachine::FAILURE:
|
||||
dm->trigger(DispatchManager::FAILED,vm->get_oid());
|
||||
return;
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Recover through re-triggering LCM events
|
||||
//----------------------------------------------------------------------
|
||||
case VirtualMachine::PROLOG:
|
||||
case VirtualMachine::PROLOG_MIGRATE:
|
||||
case VirtualMachine::PROLOG_RESUME:
|
||||
case VirtualMachine::PROLOG_UNDEPLOY:
|
||||
if (success)
|
||||
{
|
||||
lcm_action = LifeCycleManager::PROLOG_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
lcm_action = LifeCycleManager::PROLOG_FAILURE;
|
||||
}
|
||||
break;
|
||||
|
||||
case VirtualMachine::EPILOG:
|
||||
case VirtualMachine::EPILOG_STOP:
|
||||
case VirtualMachine::EPILOG_UNDEPLOY:
|
||||
if (success)
|
||||
{
|
||||
lcm_action = LifeCycleManager::EPILOG_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
lcm_action = LifeCycleManager::EPILOG_FAILURE;
|
||||
}
|
||||
break;
|
||||
|
||||
case VirtualMachine::HOTPLUG_SAVEAS:
|
||||
case VirtualMachine::HOTPLUG_SAVEAS_POWEROFF:
|
||||
case VirtualMachine::HOTPLUG_SAVEAS_SUSPENDED:
|
||||
if (success)
|
||||
{
|
||||
lcm_action = LifeCycleManager::SAVEAS_HOT_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
lcm_action = LifeCycleManager::SAVEAS_HOT_FAILURE;
|
||||
}
|
||||
break;
|
||||
|
||||
case VirtualMachine::BOOT:
|
||||
case VirtualMachine::BOOT_UNKNOWN:
|
||||
case VirtualMachine::BOOT_POWEROFF:
|
||||
case VirtualMachine::BOOT_SUSPENDED:
|
||||
case VirtualMachine::BOOT_STOPPED:
|
||||
case VirtualMachine::BOOT_UNDEPLOY:
|
||||
case VirtualMachine::MIGRATE:
|
||||
if (success)
|
||||
{
|
||||
//Auto-generate deploy-id it'll work for Xen, KVM and VMware
|
||||
if (vm->get_deploy_id().empty())
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
oss << "one-" << vm->get_oid();
|
||||
|
||||
vm->update_info(oss.str());
|
||||
}
|
||||
|
||||
lcm_action = LifeCycleManager::DEPLOY_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
lcm_action = LifeCycleManager::DEPLOY_FAILURE;
|
||||
}
|
||||
break;
|
||||
|
||||
case VirtualMachine::SHUTDOWN:
|
||||
case VirtualMachine::SHUTDOWN_POWEROFF:
|
||||
case VirtualMachine::SHUTDOWN_UNDEPLOY:
|
||||
if (success)
|
||||
{
|
||||
lcm_action = LifeCycleManager::SHUTDOWN_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
lcm_action = LifeCycleManager::SHUTDOWN_FAILURE;
|
||||
}
|
||||
break;
|
||||
|
||||
case VirtualMachine::CANCEL:
|
||||
if (success)
|
||||
{
|
||||
lcm_action = LifeCycleManager::CANCEL_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
lcm_action = LifeCycleManager::CANCEL_FAILURE;
|
||||
}
|
||||
break;
|
||||
|
||||
case VirtualMachine::SAVE_STOP:
|
||||
case VirtualMachine::SAVE_SUSPEND:
|
||||
case VirtualMachine::SAVE_MIGRATE:
|
||||
if (success)
|
||||
{
|
||||
lcm_action = LifeCycleManager::SAVE_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
lcm_action = LifeCycleManager::SAVE_FAILURE;
|
||||
}
|
||||
break;
|
||||
|
||||
case VirtualMachine::HOTPLUG:
|
||||
if (success)
|
||||
{
|
||||
lcm_action = LifeCycleManager::ATTACH_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
lcm_action = LifeCycleManager::ATTACH_FAILURE;
|
||||
}
|
||||
break;
|
||||
|
||||
case VirtualMachine::HOTPLUG_NIC:
|
||||
if (success)
|
||||
{
|
||||
lcm_action = LifeCycleManager::ATTACH_NIC_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
lcm_action = LifeCycleManager::ATTACH_NIC_FAILURE;
|
||||
}
|
||||
break;
|
||||
|
||||
//This is for all snapshot actions (create, delete & revert)
|
||||
case VirtualMachine::HOTPLUG_SNAPSHOT:
|
||||
lcm_action = LifeCycleManager::SNAPSHOT_CREATE_FAILURE;
|
||||
break;
|
||||
}
|
||||
|
||||
if (lcm_action != LifeCycleManager::FINALIZE)
|
||||
{
|
||||
trigger(lcm_action, vm->get_oid());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,6 +260,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_recover(new VirtualMachineRecover());
|
||||
|
||||
xmlrpc_c::methodPtr vm_pool_acct(new VirtualMachinePoolAccounting());
|
||||
xmlrpc_c::methodPtr vm_pool_monitoring(new VirtualMachinePoolMonitoring());
|
||||
@@ -410,6 +411,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.recover", vm_recover);
|
||||
|
||||
RequestManagerRegistry.addMethod("one.vmpool.info", vm_pool_info);
|
||||
RequestManagerRegistry.addMethod("one.vmpool.accounting", vm_pool_acct);
|
||||
|
||||
@@ -1760,3 +1760,46 @@ void VirtualMachineDetachNic::request_execute(
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualMachineRecover::request_execute(
|
||||
xmlrpc_c::paramList const& paramList, RequestAttributes& att)
|
||||
{
|
||||
int id = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
bool success = xmlrpc_c::value_boolean(paramList.getBoolean(2));
|
||||
|
||||
VirtualMachine * vm;
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
LifeCycleManager* lcm = nd.get_lcm();
|
||||
|
||||
if ( vm_authorization(id, 0, 0, att, 0, 0, auth_op) == false )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ((vm = get_vm(id, att)) == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(vm->get_state() != VirtualMachine::ACTIVE)
|
||||
{
|
||||
failure_response(ACTION,
|
||||
request_error("Wrong state to perform action",""),
|
||||
att);
|
||||
|
||||
vm->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
lcm->recover(vm, success);
|
||||
|
||||
success_response(id, att);
|
||||
|
||||
vm->unlock();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
Reference in new issue
Block a user