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

feature #3383: Clean RequestManager code

This commit is contained in:
Ruben S. Montero 2015-02-05 22:49:33 +01:00
parent 943ae3d8b7
commit 093f95524e
3 changed files with 66 additions and 14 deletions

View File

@ -94,6 +94,15 @@ public:
int deploy (
VirtualMachine * vm);
/**
* Sets an imported VM to RUNNING state, a history record MUST be added,
* and the VM MUST be locked.
* @param vm pointer to a VirtualMachine with its mutex locked.
* @return 0 on success
*/
int import (
VirtualMachine * vm);
/**
* Migrates a VM. The following actions must be performed before calling
* this function:

View File

@ -74,6 +74,62 @@ error:
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int DispatchManager::import (
VirtualMachine * vm)
{
ostringstream oss;
int vid;
if ( vm == 0 )
{
return -1;
}
vid = vm->get_oid();
if ( vm->get_state() != VirtualMachine::PENDING &&
vm->get_state() != VirtualMachine::HOLD )
{
return -1;
}
Nebula& nd = Nebula::instance();
HostPool * hpool = nd.get_hpool();
time_t the_time = time(0);
int cpu, mem, disk;
vm->get_requirements(cpu, mem, disk);
hpool->add_capacity(vm->get_hid(), vm->get_oid(), cpu, mem, disk);
vm->set_state(VirtualMachine::ACTIVE);
vm->set_state(VirtualMachine::RUNNING);
vmpool->update(vm);
vm->set_stime(the_time);
vm->set_prolog_stime(the_time);
vm->set_prolog_etime(the_time);
vm->set_running_stime(the_time);
vm->set_last_poll(0);
vmpool->update_history(vm);
vm->log("LCM", Log::INFO, "New VM state is RUNNING");
vm->unlock();
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int DispatchManager::migrate(
VirtualMachine * vm)
{

View File

@ -806,20 +806,7 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList,
}
else
{
LifeCycleManager * lcm = nd.get_lcm();
VirtualMachinePool * vmpool = nd.get_vmpool();
HostPool * hpool = nd.get_hpool();
int cpu,mem,disk;
vm->get_requirements(cpu,mem,disk);
hpool->add_capacity(vm->get_hid(), id, cpu, mem, disk);
vm->set_state(VirtualMachine::ACTIVE);
vm->set_state(VirtualMachine::BOOT);
vmpool->update(vm);
lcm->trigger(LifeCycleManager::DEPLOY_SUCCESS, id);
dm->import(vm);
}
vm->unlock();