mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
Improve SQL queries for vm_pool. Updates last_seq
This commit is contained in:
parent
3df3652b82
commit
97eb669659
@ -23,29 +23,29 @@ void LifeCycleManager::deploy_action(int vid)
|
||||
ostringstream os;
|
||||
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if ( vm->get_state() == VirtualMachine::ACTIVE )
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
TransferManager * tm = nd.get_tm();
|
||||
time_t thetime = time(0);
|
||||
int cpu,mem,disk;
|
||||
|
||||
|
||||
VirtualMachine::LcmState vm_state;
|
||||
TransferManager::Actions tm_action;
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
// PROLOG STATE
|
||||
//----------------------------------------------------
|
||||
|
||||
|
||||
vm_state = VirtualMachine::PROLOG;
|
||||
tm_action = TransferManager::PROLOG;
|
||||
|
||||
|
||||
if (vm->hasPreviousHistory())
|
||||
{
|
||||
if (vm->get_previous_reason() == History::STOP_RESUME)
|
||||
@ -56,21 +56,21 @@ void LifeCycleManager::deploy_action(int vid)
|
||||
}
|
||||
|
||||
vm->set_state(vm_state);
|
||||
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
|
||||
vm->set_stime(thetime);
|
||||
|
||||
vm->set_prolog_stime(thetime);
|
||||
|
||||
|
||||
vm->set_prolog_stime(thetime);
|
||||
|
||||
vmpool->update_history(vm);
|
||||
|
||||
|
||||
vm->get_requirements(cpu,mem,disk);
|
||||
|
||||
|
||||
hpool->add_capacity(vm->get_hid(),cpu,mem,disk);
|
||||
|
||||
|
||||
vm->log("LCM", Log::INFO, "New VM state is PROLOG.");
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
tm->trigger(tm_action,vid);
|
||||
@ -79,9 +79,9 @@ void LifeCycleManager::deploy_action(int vid)
|
||||
{
|
||||
vm->log("LCM", Log::ERROR, "deploy_action, VM in a wrong state.");
|
||||
}
|
||||
|
||||
|
||||
vm->unlock();
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -91,14 +91,14 @@ void LifeCycleManager::deploy_action(int vid)
|
||||
void LifeCycleManager::suspend_action(int vid)
|
||||
{
|
||||
VirtualMachine * vm;
|
||||
|
||||
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (vm->get_state() == VirtualMachine::ACTIVE &&
|
||||
vm->get_lcm_state() == VirtualMachine::RUNNING)
|
||||
{
|
||||
@ -108,24 +108,24 @@ void LifeCycleManager::suspend_action(int vid)
|
||||
//----------------------------------------------------
|
||||
// SAVE_SUSPEND STATE
|
||||
//----------------------------------------------------
|
||||
|
||||
|
||||
vm->set_state(VirtualMachine::SAVE_SUSPEND);
|
||||
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
vm->log("LCM", Log::INFO, "New VM state is SAVE_SUSPEND");
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
vmm->trigger(VirtualMachineManager::SAVE,vid);
|
||||
|
||||
vmm->trigger(VirtualMachineManager::SAVE,vid);
|
||||
}
|
||||
else
|
||||
{
|
||||
vm->log("LCM", Log::ERROR, "suspend_action, VM in a wrong state.");
|
||||
}
|
||||
|
||||
|
||||
vm->unlock();
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -135,14 +135,14 @@ void LifeCycleManager::suspend_action(int vid)
|
||||
void LifeCycleManager::stop_action(int vid)
|
||||
{
|
||||
VirtualMachine * vm;
|
||||
|
||||
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (vm->get_state() == VirtualMachine::ACTIVE &&
|
||||
vm->get_lcm_state() == VirtualMachine::RUNNING)
|
||||
{
|
||||
@ -154,22 +154,22 @@ void LifeCycleManager::stop_action(int vid)
|
||||
//----------------------------------------------------
|
||||
|
||||
vm->set_state(VirtualMachine::SAVE_STOP);
|
||||
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
vm->log("LCM", Log::INFO, "New VM state is SAVE_STOP");
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
vmm->trigger(VirtualMachineManager::SAVE,vid);
|
||||
vmm->trigger(VirtualMachineManager::SAVE,vid);
|
||||
}
|
||||
else
|
||||
{
|
||||
vm->log("LCM", Log::ERROR, "stop_action, VM in a wrong state.");
|
||||
vm->log("LCM", Log::ERROR, "stop_action, VM in a wrong state.");
|
||||
}
|
||||
|
||||
|
||||
vm->unlock();
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -179,50 +179,50 @@ void LifeCycleManager::stop_action(int vid)
|
||||
void LifeCycleManager::migrate_action(int vid)
|
||||
{
|
||||
VirtualMachine * vm;
|
||||
|
||||
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (vm->get_state() == VirtualMachine::ACTIVE &&
|
||||
vm->get_lcm_state() == VirtualMachine::RUNNING)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
VirtualMachineManager * vmm = nd.get_vmm();
|
||||
int cpu,mem,disk;
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
// SAVE_MIGRATE STATE
|
||||
//----------------------------------------------------
|
||||
|
||||
vm->set_state(VirtualMachine::SAVE_MIGRATE);
|
||||
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
|
||||
vm->set_stime(time(0));
|
||||
|
||||
|
||||
vmpool->update_history(vm);
|
||||
|
||||
|
||||
vm->get_requirements(cpu,mem,disk);
|
||||
|
||||
|
||||
hpool->add_capacity(vm->get_hid(),cpu,mem,disk);
|
||||
|
||||
vm->log("LCM", Log::INFO, "New VM state is SAVE_MIGRATE");
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
vmm->trigger(VirtualMachineManager::SAVE,vid);
|
||||
vmm->trigger(VirtualMachineManager::SAVE,vid);
|
||||
}
|
||||
else
|
||||
{
|
||||
vm->log("LCM", Log::ERROR, "migrate_action, VM in a wrong state.");
|
||||
}
|
||||
|
||||
|
||||
vm->unlock();
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -233,21 +233,21 @@ void LifeCycleManager::live_migrate_action(int vid)
|
||||
{
|
||||
VirtualMachine * vm;
|
||||
ostringstream os;
|
||||
|
||||
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (vm->get_state() == VirtualMachine::ACTIVE &&
|
||||
vm->get_lcm_state() == VirtualMachine::RUNNING)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
VirtualMachineManager * vmm = nd.get_vmm();
|
||||
int cpu,mem,disk;
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
// MIGRATE STATE
|
||||
//----------------------------------------------------
|
||||
@ -257,26 +257,26 @@ void LifeCycleManager::live_migrate_action(int vid)
|
||||
vmpool->update(vm);
|
||||
|
||||
vm->set_stime(time(0));
|
||||
|
||||
|
||||
vmpool->update_history(vm);
|
||||
|
||||
|
||||
vm->get_requirements(cpu,mem,disk);
|
||||
|
||||
|
||||
hpool->add_capacity(vm->get_hid(),cpu,mem,disk);
|
||||
|
||||
|
||||
vm->log("LCM",Log::INFO,"New VM state is MIGRATE");
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
vmm->trigger(VirtualMachineManager::MIGRATE,vid);
|
||||
|
||||
vmm->trigger(VirtualMachineManager::MIGRATE,vid);
|
||||
}
|
||||
else
|
||||
{
|
||||
vm->log("LCM", Log::ERROR, "live_migrate_action, VM in a wrong state.");
|
||||
}
|
||||
|
||||
|
||||
vm->unlock();
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -286,14 +286,14 @@ void LifeCycleManager::live_migrate_action(int vid)
|
||||
void LifeCycleManager::shutdown_action(int vid)
|
||||
{
|
||||
VirtualMachine * vm;
|
||||
|
||||
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (vm->get_state() == VirtualMachine::ACTIVE &&
|
||||
vm->get_lcm_state() == VirtualMachine::RUNNING)
|
||||
{
|
||||
@ -307,20 +307,20 @@ void LifeCycleManager::shutdown_action(int vid)
|
||||
vm->set_state(VirtualMachine::SHUTDOWN);
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
|
||||
vm->log("LCM",Log::INFO,"New VM state is SHUTDOWN");
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
vmm->trigger(VirtualMachineManager::SHUTDOWN,vid);
|
||||
|
||||
vmm->trigger(VirtualMachineManager::SHUTDOWN,vid);
|
||||
}
|
||||
else
|
||||
{
|
||||
vm->log("LCM", Log::ERROR, "shutdown_action, VM in a wrong state.");
|
||||
}
|
||||
|
||||
|
||||
vm->unlock();
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -331,56 +331,56 @@ void LifeCycleManager::restore_action(int vid)
|
||||
{
|
||||
VirtualMachine * vm;
|
||||
ostringstream os;
|
||||
|
||||
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (vm->get_state() == VirtualMachine::ACTIVE)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
VirtualMachineManager * vmm = nd.get_vmm();
|
||||
int cpu,mem,disk;
|
||||
time_t the_time = time(0);
|
||||
|
||||
|
||||
vm->log("LCM", Log::INFO, "Restoring VM");
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
// BOOT STATE (FROM SUSPEND)
|
||||
//----------------------------------------------------
|
||||
//----------------------------------------------------
|
||||
|
||||
vm->set_state(VirtualMachine::BOOT);
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
vm->cp_history();
|
||||
|
||||
|
||||
vmpool->update(vm); //update last_seq & state
|
||||
|
||||
vm->set_stime(the_time);
|
||||
|
||||
|
||||
vm->set_running_stime(the_time);
|
||||
|
||||
|
||||
vmpool->update_history(vm);
|
||||
|
||||
|
||||
vm->get_requirements(cpu,mem,disk);
|
||||
|
||||
hpool->add_capacity(vm->get_hid(),cpu,mem,disk);
|
||||
|
||||
|
||||
hpool->add_capacity(vm->get_hid(),cpu,mem,disk);
|
||||
|
||||
vm->log("LCM", Log::INFO, "New state is BOOT");
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
vmm->trigger(VirtualMachineManager::RESTORE,vid);
|
||||
|
||||
vmm->trigger(VirtualMachineManager::RESTORE,vid);
|
||||
}
|
||||
else
|
||||
{
|
||||
vm->log("LCM", Log::ERROR, "restore_action, VM in a wrong state.");
|
||||
}
|
||||
|
||||
|
||||
vm->unlock();
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -390,14 +390,14 @@ void LifeCycleManager::restore_action(int vid)
|
||||
void LifeCycleManager::cancel_action(int vid)
|
||||
{
|
||||
VirtualMachine * vm;
|
||||
|
||||
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (vm->get_state() == VirtualMachine::ACTIVE &&
|
||||
vm->get_lcm_state() == VirtualMachine::RUNNING)
|
||||
{
|
||||
@ -409,22 +409,22 @@ void LifeCycleManager::cancel_action(int vid)
|
||||
//----------------------------------------------------
|
||||
|
||||
vm->set_state(VirtualMachine::CANCEL);
|
||||
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
vm->log("LCM", Log::INFO, "New state is CANCEL");
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
vmm->trigger(VirtualMachineManager::CANCEL,vid);
|
||||
|
||||
vmm->trigger(VirtualMachineManager::CANCEL,vid);
|
||||
}
|
||||
else
|
||||
{
|
||||
vm->log("LCM", Log::ERROR, "cancel_action, VM in a wrong state.");
|
||||
}
|
||||
|
||||
|
||||
vm->unlock();
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -434,14 +434,14 @@ void LifeCycleManager::cancel_action(int vid)
|
||||
void LifeCycleManager::restart_action(int vid)
|
||||
{
|
||||
VirtualMachine * vm;
|
||||
|
||||
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (vm->get_state() == VirtualMachine::ACTIVE &&
|
||||
(vm->get_lcm_state() == VirtualMachine::UNKNOWN ||
|
||||
vm->get_lcm_state() == VirtualMachine::BOOT))
|
||||
@ -452,7 +452,7 @@ void LifeCycleManager::restart_action(int vid)
|
||||
//----------------------------------------------------
|
||||
// RE-START THE VM IN THE SAME HOST
|
||||
//----------------------------------------------------
|
||||
|
||||
|
||||
if (vm->get_lcm_state() == VirtualMachine::BOOT)
|
||||
{
|
||||
vm->log("LCM", Log::INFO, "Sending BOOT command to VM again");
|
||||
@ -460,23 +460,23 @@ void LifeCycleManager::restart_action(int vid)
|
||||
else
|
||||
{
|
||||
vm->set_state(VirtualMachine::BOOT);
|
||||
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
vm->log("LCM", Log::INFO, "New VM state is BOOT");
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
vmm->trigger(VirtualMachineManager::DEPLOY,vid);
|
||||
|
||||
vmm->trigger(VirtualMachineManager::DEPLOY,vid);
|
||||
}
|
||||
else
|
||||
{
|
||||
vm->log("LCM", Log::ERROR, "restart_action, VM in a wrong state.");
|
||||
}
|
||||
|
||||
|
||||
vm->unlock();
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -489,7 +489,7 @@ void LifeCycleManager::delete_action(int vid)
|
||||
|
||||
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return;
|
||||
@ -548,7 +548,7 @@ void LifeCycleManager::delete_action(int vid)
|
||||
|
||||
tm->trigger(TransferManager::EPILOG_DELETE,vid);
|
||||
break;
|
||||
|
||||
|
||||
case VirtualMachine::MIGRATE:
|
||||
vm->set_running_etime(the_time);
|
||||
vmpool->update_history(vm);
|
||||
@ -557,8 +557,8 @@ void LifeCycleManager::delete_action(int vid)
|
||||
vm->set_previous_running_etime(the_time);
|
||||
vm->set_previous_reason(History::USER);
|
||||
vmpool->update_previous_history(vm);
|
||||
|
||||
hpool->del_capacity(vm->get_previous_hid(),cpu,mem,disk);
|
||||
|
||||
hpool->del_capacity(vm->get_previous_hid(),cpu,mem,disk);
|
||||
|
||||
vmm->trigger(VirtualMachineManager::DRIVER_CANCEL,vid);
|
||||
|
||||
@ -585,8 +585,8 @@ void LifeCycleManager::delete_action(int vid)
|
||||
vm->set_previous_running_etime(the_time);
|
||||
vm->set_previous_reason(History::USER);
|
||||
vmpool->update_previous_history(vm);
|
||||
|
||||
hpool->del_capacity(vm->get_previous_hid(),cpu,mem,disk);
|
||||
|
||||
hpool->del_capacity(vm->get_previous_hid(),cpu,mem,disk);
|
||||
|
||||
vmm->trigger(VirtualMachineManager::DRIVER_CANCEL,vid);
|
||||
vmm->trigger(VirtualMachineManager::CANCEL_PREVIOUS,vid);
|
||||
|
@ -24,49 +24,49 @@ void LifeCycleManager::save_success_action(int vid)
|
||||
{
|
||||
VirtualMachine * vm;
|
||||
ostringstream os;
|
||||
|
||||
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if ( vm->get_lcm_state() == VirtualMachine::SAVE_MIGRATE )
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
TransferManager * tm = nd.get_tm();
|
||||
int cpu,mem,disk;
|
||||
time_t the_time = time(0);
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
// PROLOG_MIGRATE STATE
|
||||
//----------------------------------------------------
|
||||
|
||||
|
||||
vm->set_state(VirtualMachine::PROLOG_MIGRATE);
|
||||
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
|
||||
vm->set_previous_etime(the_time);
|
||||
|
||||
|
||||
vm->set_previous_running_etime(the_time);
|
||||
|
||||
|
||||
vm->set_previous_reason(History::USER);
|
||||
|
||||
|
||||
vmpool->update_previous_history(vm);
|
||||
|
||||
|
||||
vm->set_prolog_stime(the_time);
|
||||
|
||||
vmpool->update_history(vm);
|
||||
|
||||
|
||||
vm->get_requirements(cpu,mem,disk);
|
||||
|
||||
|
||||
hpool->del_capacity(vm->get_previous_hid(),cpu,mem,disk);
|
||||
|
||||
|
||||
vm->log("LCM", Log::INFO, "New VM state is PROLOG_MIGRATE");
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
|
||||
tm->trigger(TransferManager::PROLOG_MIGR,vid);
|
||||
}
|
||||
else if ( vm->get_lcm_state() == VirtualMachine::SAVE_SUSPEND)
|
||||
@ -83,17 +83,17 @@ void LifeCycleManager::save_success_action(int vid)
|
||||
vm->set_running_etime(the_time);
|
||||
|
||||
vm->set_etime(the_time);
|
||||
|
||||
|
||||
vm->set_reason(History::STOP_RESUME);
|
||||
|
||||
vmpool->update_history(vm);
|
||||
|
||||
vm->get_requirements(cpu,mem,disk);
|
||||
|
||||
|
||||
hpool->del_capacity(vm->get_hid(),cpu,mem,disk);
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
|
||||
dm->trigger(DispatchManager::SUSPEND_SUCCESS,vid);
|
||||
}
|
||||
else if ( vm->get_lcm_state() == VirtualMachine::SAVE_STOP)
|
||||
@ -101,34 +101,34 @@ void LifeCycleManager::save_success_action(int vid)
|
||||
Nebula& nd = Nebula::instance();
|
||||
TransferManager * tm = nd.get_tm();
|
||||
time_t the_time = time(0);
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
// EPILOG_STOP STATE
|
||||
//----------------------------------------------------
|
||||
|
||||
|
||||
vm->set_state(VirtualMachine::EPILOG_STOP);
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
|
||||
vm->set_epilog_stime(the_time);
|
||||
|
||||
vm->set_running_etime(the_time);
|
||||
|
||||
vm->set_running_etime(the_time);
|
||||
|
||||
vm->set_reason(History::STOP_RESUME);
|
||||
|
||||
|
||||
vmpool->update_history(vm);
|
||||
|
||||
|
||||
vm->log("LCM", Log::INFO, "New VM state is EPILOG_STOP");
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
|
||||
tm->trigger(TransferManager::EPILOG_STOP,vid);
|
||||
}
|
||||
else
|
||||
{
|
||||
vm->log("LCM",Log::ERROR,"save_success_action, VM in a wrong state");
|
||||
}
|
||||
|
||||
|
||||
vm->unlock();
|
||||
}
|
||||
|
||||
@ -138,69 +138,69 @@ void LifeCycleManager::save_success_action(int vid)
|
||||
void LifeCycleManager::save_failure_action(int vid)
|
||||
{
|
||||
VirtualMachine * vm;
|
||||
|
||||
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if ( vm->get_lcm_state() == VirtualMachine::SAVE_MIGRATE )
|
||||
{
|
||||
int cpu,mem,disk;
|
||||
time_t the_time = time(0);
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
VirtualMachineManager * vmm = nd.get_vmm();
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
// RUNNING STATE FROM SAVE_MIGRATE
|
||||
//----------------------------------------------------
|
||||
|
||||
vm->set_state(VirtualMachine::RUNNING);
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
|
||||
vm->set_etime(the_time);
|
||||
|
||||
|
||||
vm->set_reason(History::ERROR);
|
||||
|
||||
|
||||
vmpool->update_history(vm);
|
||||
|
||||
|
||||
vm->get_requirements(cpu,mem,disk);
|
||||
|
||||
|
||||
hpool->del_capacity(vm->get_hid(),cpu,mem,disk);
|
||||
|
||||
vm->set_previous_etime(the_time);
|
||||
|
||||
vm->set_previous_running_etime(the_time);
|
||||
|
||||
vm->set_previous_reason(History::USER);
|
||||
|
||||
vmpool->update_previous_history(vm);
|
||||
|
||||
// --- Add new record by copying the previous one
|
||||
|
||||
|
||||
vm->set_previous_etime(the_time);
|
||||
|
||||
vm->set_previous_running_etime(the_time);
|
||||
|
||||
vm->set_previous_reason(History::USER);
|
||||
|
||||
vmpool->update_previous_history(vm);
|
||||
|
||||
// --- Add new record by copying the previous one
|
||||
|
||||
vm->cp_previous_history();
|
||||
|
||||
|
||||
vmpool->update(vm); //update last_seq & state
|
||||
|
||||
vm->set_stime(the_time);
|
||||
|
||||
|
||||
vm->set_running_stime(the_time);
|
||||
|
||||
|
||||
vmpool->update_history(vm);
|
||||
|
||||
|
||||
vm->log("LCM", Log::INFO, "Fail to save VM state while migrating."
|
||||
" Assuming that the VM is still RUNNING (will poll VM).");
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
vmm->trigger(VirtualMachineManager::POLL,vid);
|
||||
|
||||
vmm->trigger(VirtualMachineManager::POLL,vid);
|
||||
}
|
||||
else if ( vm->get_lcm_state() == VirtualMachine::SAVE_SUSPEND ||
|
||||
vm->get_lcm_state() == VirtualMachine::SAVE_STOP )
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
Nebula& nd = Nebula::instance();
|
||||
VirtualMachineManager * vmm = nd.get_vmm();
|
||||
|
||||
//----------------------------------------------------
|
||||
@ -208,14 +208,14 @@ void LifeCycleManager::save_failure_action(int vid)
|
||||
//----------------------------------------------------
|
||||
|
||||
vm->set_state(VirtualMachine::RUNNING);
|
||||
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
vm->log("LCM", Log::INFO, "Fail to save VM state."
|
||||
" Assuming that the VM is still RUNNING (will poll VM).");
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
|
||||
vmm->trigger(VirtualMachineManager::POLL,vid);
|
||||
}
|
||||
|
||||
@ -228,9 +228,9 @@ void LifeCycleManager::save_failure_action(int vid)
|
||||
void LifeCycleManager::deploy_success_action(int vid)
|
||||
{
|
||||
VirtualMachine * vm;
|
||||
|
||||
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return;
|
||||
@ -244,30 +244,30 @@ void LifeCycleManager::deploy_success_action(int vid)
|
||||
{
|
||||
int cpu,mem,disk;
|
||||
time_t the_time = time(0);
|
||||
|
||||
|
||||
vm->set_running_stime(the_time);
|
||||
|
||||
|
||||
vmpool->update_history(vm);
|
||||
|
||||
|
||||
vm->set_previous_etime(the_time);
|
||||
|
||||
|
||||
vm->set_previous_running_etime(the_time);
|
||||
|
||||
|
||||
vm->set_previous_reason(History::USER);
|
||||
|
||||
|
||||
vmpool->update_previous_history(vm);
|
||||
|
||||
|
||||
vm->get_requirements(cpu,mem,disk);
|
||||
|
||||
hpool->del_capacity(vm->get_previous_hid(),cpu,mem,disk);
|
||||
|
||||
hpool->del_capacity(vm->get_previous_hid(),cpu,mem,disk);
|
||||
}
|
||||
|
||||
|
||||
vm->set_state(VirtualMachine::RUNNING);
|
||||
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
vm->log("LCM", Log::INFO, "New VM state is RUNNING");
|
||||
|
||||
|
||||
vm->unlock();
|
||||
}
|
||||
|
||||
@ -276,11 +276,11 @@ void LifeCycleManager::deploy_success_action(int vid)
|
||||
|
||||
void LifeCycleManager::deploy_failure_action(int vid)
|
||||
{
|
||||
|
||||
|
||||
VirtualMachine * vm;
|
||||
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return;
|
||||
@ -290,52 +290,52 @@ void LifeCycleManager::deploy_failure_action(int vid)
|
||||
{
|
||||
int cpu,mem,disk;
|
||||
time_t the_time = time(0);
|
||||
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
VirtualMachineManager * vmm = nd.get_vmm();
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
// RUNNING STATE FROM MIGRATE
|
||||
//----------------------------------------------------
|
||||
|
||||
vm->set_state(VirtualMachine::RUNNING);
|
||||
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
vm->set_etime(the_time);
|
||||
|
||||
vm->set_reason(History::ERROR);
|
||||
|
||||
vmpool->update_history(vm);
|
||||
|
||||
vm->set_previous_etime(the_time);
|
||||
|
||||
vm->set_previous_running_etime(the_time);
|
||||
|
||||
vm->set_previous_reason(History::USER);
|
||||
|
||||
vmpool->update_previous_history(vm);
|
||||
|
||||
vm->get_requirements(cpu,mem,disk);
|
||||
|
||||
hpool->del_capacity(vm->get_hid(),cpu,mem,disk);
|
||||
|
||||
// --- Add new record by copying the previous one
|
||||
|
||||
vm->set_reason(History::ERROR);
|
||||
|
||||
vm->set_previous_etime(the_time);
|
||||
|
||||
vm->set_previous_running_etime(the_time);
|
||||
|
||||
vm->set_previous_reason(History::USER);
|
||||
|
||||
vmpool->update_previous_history(vm);
|
||||
|
||||
vm->get_requirements(cpu,mem,disk);
|
||||
|
||||
hpool->del_capacity(vm->get_hid(),cpu,mem,disk);
|
||||
|
||||
// --- Add new record by copying the previous one
|
||||
|
||||
vm->cp_previous_history();
|
||||
|
||||
|
||||
vmpool->update(vm); //update last_seq & state
|
||||
|
||||
vm->set_stime(the_time);
|
||||
|
||||
|
||||
vm->set_running_stime(the_time);
|
||||
|
||||
|
||||
vmpool->update_history(vm);
|
||||
|
||||
|
||||
vm->log("LCM", Log::INFO, "Fail to life migrate VM."
|
||||
" Assuming that the VM is still RUNNING (will poll VM).");
|
||||
|
||||
" Assuming that the VM is still RUNNING (will poll VM).");
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
vmm->trigger(VirtualMachineManager::POLL,vid);
|
||||
|
||||
vmm->trigger(VirtualMachineManager::POLL,vid);
|
||||
}
|
||||
else if (vm->get_lcm_state() == VirtualMachine::BOOT)
|
||||
{
|
||||
@ -345,7 +345,7 @@ void LifeCycleManager::deploy_failure_action(int vid)
|
||||
|
||||
failure_action(vm);
|
||||
}
|
||||
|
||||
|
||||
vm->unlock();
|
||||
}
|
||||
|
||||
@ -358,35 +358,35 @@ void LifeCycleManager::shutdown_success_action(int vid)
|
||||
TransferManager * tm = nd.get_tm();
|
||||
VirtualMachine * vm;
|
||||
time_t the_time = time(0);
|
||||
|
||||
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
// EPILOG STATE
|
||||
//----------------------------------------------------
|
||||
|
||||
|
||||
vm->set_state(VirtualMachine::EPILOG);
|
||||
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
|
||||
vm->set_epilog_stime(the_time);
|
||||
|
||||
|
||||
vm->set_running_etime(the_time);
|
||||
|
||||
|
||||
vmpool->update_history(vm);
|
||||
|
||||
|
||||
vm->log("LCM", Log::INFO, "New VM state is EPILOG");
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
|
||||
tm->trigger(TransferManager::EPILOG,vid);
|
||||
|
||||
vm->unlock();
|
||||
|
||||
vm->unlock();
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -395,33 +395,33 @@ void LifeCycleManager::shutdown_success_action(int vid)
|
||||
void LifeCycleManager::shutdown_failure_action(int vid)
|
||||
{
|
||||
VirtualMachine * vm;
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
VirtualMachineManager * vmm = nd.get_vmm();
|
||||
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
// RUNNING STATE FROM SHUTDOWN
|
||||
//----------------------------------------------------
|
||||
|
||||
vm->set_state(VirtualMachine::RUNNING);
|
||||
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
vm->log("LCM", Log::INFO, "Fail to shutdown VM."
|
||||
" Assuming that the VM is still RUNNING (will poll VM).");
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
|
||||
vmm->trigger(VirtualMachineManager::POLL,vid);
|
||||
|
||||
vm->unlock();
|
||||
|
||||
vm->unlock();
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -434,31 +434,31 @@ void LifeCycleManager::prolog_success_action(int vid)
|
||||
VirtualMachine * vm;
|
||||
time_t the_time = time(0);
|
||||
ostringstream os;
|
||||
|
||||
|
||||
VirtualMachineManager::Actions action;
|
||||
VirtualMachine::LcmState lcm_state;
|
||||
|
||||
|
||||
vm = vmpool->get(vid, true);
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lcm_state = vm->get_lcm_state();
|
||||
|
||||
|
||||
lcm_state = vm->get_lcm_state();
|
||||
|
||||
if (lcm_state == VirtualMachine::PROLOG)
|
||||
{
|
||||
action = VirtualMachineManager::DEPLOY;
|
||||
action = VirtualMachineManager::DEPLOY;
|
||||
}
|
||||
else if ( lcm_state == VirtualMachine::PROLOG_MIGRATE ||
|
||||
lcm_state == VirtualMachine::PROLOG_RESUME )
|
||||
{
|
||||
action = VirtualMachineManager::RESTORE;
|
||||
action = VirtualMachineManager::RESTORE;
|
||||
}
|
||||
else
|
||||
{
|
||||
vm->log("LCM",Log::ERROR,"prolog_success_action, VM in a wrong state");
|
||||
vm->log("LCM",Log::ERROR,"prolog_success_action, VM in a wrong state");
|
||||
vm->unlock();
|
||||
|
||||
return;
|
||||
@ -469,23 +469,23 @@ void LifeCycleManager::prolog_success_action(int vid)
|
||||
//----------------------------------------------------
|
||||
|
||||
vm->set_state(VirtualMachine::BOOT);
|
||||
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
|
||||
vm->set_prolog_etime(the_time);
|
||||
|
||||
|
||||
vm->set_running_stime(the_time);
|
||||
|
||||
|
||||
vmpool->update_history(vm);
|
||||
|
||||
vm->log("LCM", Log::INFO, "New VM state is BOOT");
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
|
||||
vmm->trigger(action,vid);
|
||||
|
||||
|
||||
vm->unlock();
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -498,19 +498,19 @@ void LifeCycleManager::prolog_failure_action(int vid)
|
||||
time_t the_time = time(0);
|
||||
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
vm->set_prolog_etime(the_time);
|
||||
|
||||
failure_action(vm);
|
||||
|
||||
vm->unlock();
|
||||
|
||||
return;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -520,20 +520,20 @@ void LifeCycleManager::epilog_success_action(int vid)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
DispatchManager * dm = nd.get_dm();
|
||||
|
||||
|
||||
VirtualMachine * vm;
|
||||
time_t the_time = time(0);
|
||||
int cpu,mem,disk;
|
||||
|
||||
|
||||
DispatchManager::Actions action;
|
||||
|
||||
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if ( vm->get_lcm_state() == VirtualMachine::EPILOG_STOP )
|
||||
{
|
||||
action = DispatchManager::STOP_SUCCESS;
|
||||
@ -549,23 +549,23 @@ void LifeCycleManager::epilog_success_action(int vid)
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
vm->set_epilog_etime(the_time);
|
||||
|
||||
|
||||
vm->set_etime(the_time);
|
||||
|
||||
|
||||
vmpool->update_history(vm);
|
||||
|
||||
vm->get_requirements(cpu,mem,disk);
|
||||
|
||||
|
||||
hpool->del_capacity(vm->get_hid(),cpu,mem,disk);
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
|
||||
dm->trigger(action,vid);
|
||||
|
||||
|
||||
vm->unlock();
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -576,21 +576,21 @@ void LifeCycleManager::epilog_failure_action(int vid)
|
||||
{
|
||||
VirtualMachine * vm;
|
||||
time_t the_time = time(0);
|
||||
|
||||
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vm->set_epilog_etime(the_time);
|
||||
|
||||
|
||||
failure_action(vm);
|
||||
|
||||
vm->unlock();
|
||||
|
||||
return;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -601,31 +601,31 @@ void LifeCycleManager::cancel_success_action(int vid)
|
||||
VirtualMachine * vm;
|
||||
time_t the_time = time(0);
|
||||
int cpu,mem,disk;
|
||||
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
DispatchManager * dm = nd.get_dm();
|
||||
|
||||
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vm->set_etime(the_time);
|
||||
|
||||
|
||||
vm->set_reason(History::CANCEL);
|
||||
|
||||
|
||||
vmpool->update_history(vm);
|
||||
|
||||
vm->get_requirements(cpu,mem,disk);
|
||||
|
||||
|
||||
hpool->del_capacity(vm->get_hid(),cpu,mem,disk);
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
|
||||
dm->trigger(DispatchManager::DONE,vid);
|
||||
|
||||
|
||||
vm->unlock();
|
||||
}
|
||||
|
||||
@ -636,32 +636,32 @@ void LifeCycleManager::cancel_failure_action(int vid)
|
||||
{
|
||||
VirtualMachine * vm;
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
Nebula& nd = Nebula::instance();
|
||||
VirtualMachineManager * vmm = nd.get_vmm();
|
||||
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
// RUNNING STATE FROM CANCEL
|
||||
//----------------------------------------------------
|
||||
|
||||
vm->set_state(VirtualMachine::RUNNING);
|
||||
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
vm->log("LCM", Log::INFO, "Fail to cancel VM."
|
||||
" Assuming that the VM is still RUNNING (will poll VM).");
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
|
||||
vmm->trigger(VirtualMachineManager::POLL,vid);
|
||||
|
||||
vm->unlock();
|
||||
|
||||
vm->unlock();
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -672,14 +672,14 @@ void LifeCycleManager::monitor_failure_action(int vid)
|
||||
VirtualMachine * vm;
|
||||
|
||||
time_t the_time = time(0);
|
||||
|
||||
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
vm->set_running_etime(the_time);
|
||||
|
||||
failure_action(vm);
|
||||
@ -699,24 +699,24 @@ void LifeCycleManager::monitor_suspend_action(int vid)
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
DispatchManager * dm = nd.get_dm();
|
||||
|
||||
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
vm->set_running_etime(the_time);
|
||||
|
||||
|
||||
vm->set_etime(the_time);
|
||||
|
||||
|
||||
vm->set_reason(History::STOP_RESUME);
|
||||
|
||||
vmpool->update_history(vm);
|
||||
|
||||
vm->get_requirements(cpu,mem,disk);
|
||||
|
||||
|
||||
hpool->del_capacity(vm->get_hid(),cpu,mem,disk);
|
||||
|
||||
vm->log("LCM", Log::INFO, "VM is suspended.");
|
||||
@ -735,27 +735,27 @@ void LifeCycleManager::monitor_suspend_action(int vid)
|
||||
void LifeCycleManager::monitor_done_action(int vid)
|
||||
{
|
||||
VirtualMachine * vm;
|
||||
|
||||
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
// EPILOG STATE
|
||||
//----------------------------------------------------
|
||||
|
||||
|
||||
vm->set_state(VirtualMachine::UNKNOWN);
|
||||
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
|
||||
vm->log("LCM", Log::INFO, "New VM state is UNKNOWN");
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
vm->unlock();
|
||||
|
||||
vm->unlock();
|
||||
}
|
||||
|
||||
|
||||
@ -767,10 +767,10 @@ void LifeCycleManager::failure_action(VirtualMachine * vm)
|
||||
Nebula& nd = Nebula::instance();
|
||||
TransferManager * tm = nd.get_tm();
|
||||
DispatchManager * dm = nd.get_dm();
|
||||
|
||||
|
||||
time_t the_time = time(0);
|
||||
int cpu,mem,disk;
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
// LCM FAILURE STATE
|
||||
//----------------------------------------------------
|
||||
@ -778,15 +778,15 @@ void LifeCycleManager::failure_action(VirtualMachine * vm)
|
||||
vm->set_state(VirtualMachine::FAILURE);
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
|
||||
vm->set_etime(the_time);
|
||||
|
||||
|
||||
vm->set_reason(History::ERROR);
|
||||
|
||||
vmpool->update_history(vm);
|
||||
|
||||
vm->get_requirements(cpu,mem,disk);
|
||||
|
||||
|
||||
hpool->del_capacity(vm->get_hid(),cpu,mem,disk);
|
||||
|
||||
//------------- Clean up remote files ----------------
|
||||
|
@ -36,96 +36,98 @@ void RequestManager::VirtualMachineDeploy::execute(
|
||||
string vmm_mad;
|
||||
string tm_mad;
|
||||
string vmdir;
|
||||
|
||||
|
||||
VirtualMachine * vm;
|
||||
Host * host;
|
||||
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
DispatchManager * dm = nd.get_dm();
|
||||
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
|
||||
NebulaLog::log("ReM",Log::DEBUG,"VirtualMachineDeploy invoked");
|
||||
|
||||
|
||||
//Parse Arguments
|
||||
|
||||
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
vid = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
hid = xmlrpc_c::value_int(paramList.getInt(2));
|
||||
|
||||
|
||||
//We also need the hsid
|
||||
|
||||
|
||||
//Get host info to deploy the VM
|
||||
|
||||
|
||||
host = VirtualMachineDeploy::hpool->get(hid,true);
|
||||
|
||||
|
||||
if ( host == 0 )
|
||||
{
|
||||
goto error_host_get;
|
||||
}
|
||||
|
||||
|
||||
hostname = host->get_hostname();
|
||||
vmm_mad = host->get_vmm_mad();
|
||||
tm_mad = host->get_tm_mad();
|
||||
|
||||
|
||||
nd.get_configuration_attribute("VM_DIR",vmdir);
|
||||
|
||||
host->unlock();
|
||||
|
||||
|
||||
//Get the VM
|
||||
|
||||
|
||||
vm = VirtualMachineDeploy::vmpool->get(vid,true);
|
||||
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
goto error_vm_get;
|
||||
}
|
||||
|
||||
uid = vm->get_uid();
|
||||
|
||||
|
||||
// Only oneadmin or the VM owner can perform operations upon the VM
|
||||
rc = VirtualMachineDeploy::upool->authenticate(session);
|
||||
|
||||
if ( rc != 0 && rc != uid)
|
||||
{
|
||||
goto error_authenticate;
|
||||
|
||||
if ( rc != 0 && rc != uid)
|
||||
{
|
||||
goto error_authenticate;
|
||||
}
|
||||
|
||||
if ( vm->get_state() != VirtualMachine::PENDING )
|
||||
{
|
||||
goto error_state;
|
||||
}
|
||||
|
||||
|
||||
//Update host info and share usage (cpu,mem....)
|
||||
|
||||
|
||||
vm->add_history(hid,hostname,vmdir,vmm_mad,tm_mad);
|
||||
|
||||
|
||||
rc = VirtualMachineDeploy::vmpool->update_history(vm);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
goto error_history;
|
||||
}
|
||||
|
||||
|
||||
vmpool->update(vm); //Insert last_seq in the DB
|
||||
|
||||
//Deploy the VM
|
||||
|
||||
|
||||
dm->deploy(vm);
|
||||
|
||||
|
||||
vm->unlock();
|
||||
|
||||
|
||||
// Send results to client
|
||||
|
||||
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(true));
|
||||
|
||||
|
||||
arrayresult = new xmlrpc_c::value_array(arrayData);
|
||||
|
||||
|
||||
*retval = *arrayresult;
|
||||
|
||||
|
||||
delete arrayresult;
|
||||
|
||||
|
||||
return;
|
||||
|
||||
error_authenticate:
|
||||
@ -136,20 +138,20 @@ error_authenticate:
|
||||
error_host_get:
|
||||
oss << "The host " << hid << " does not exists";
|
||||
goto error_common;
|
||||
|
||||
|
||||
error_vm_get:
|
||||
oss << "The virtual machine " << vid << " does not exists";
|
||||
goto error_common;
|
||||
|
||||
error_history:
|
||||
vm->unlock();
|
||||
|
||||
|
||||
oss << "Can not deploy VM " << vid << ", can not insert history";
|
||||
goto error_common;
|
||||
|
||||
error_state:
|
||||
vm->unlock();
|
||||
|
||||
|
||||
oss << "Can not deploy VM " << vid << ", wrong state";
|
||||
goto error_common;
|
||||
|
||||
@ -157,11 +159,11 @@ error_common:
|
||||
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false));
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
*retval = arrayresult_error;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -32,42 +32,41 @@ void RequestManager::VirtualMachineMigrate::execute(
|
||||
int uid;
|
||||
int rc;
|
||||
bool live;
|
||||
|
||||
|
||||
string hostname;
|
||||
string vmm_mad;
|
||||
string tm_mad;
|
||||
string vmdir;
|
||||
|
||||
|
||||
VirtualMachine * vm;
|
||||
Host * host;
|
||||
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
DispatchManager * dm = nd.get_dm();
|
||||
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
|
||||
ostringstream oss;
|
||||
time_t thetime;
|
||||
|
||||
|
||||
NebulaLog::log("ReM",Log::DEBUG,"VirtualMachineMigrate invoked");
|
||||
|
||||
|
||||
//Parse Arguments
|
||||
|
||||
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
vid = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
hid = xmlrpc_c::value_int(paramList.getInt(2));
|
||||
live = xmlrpc_c::value_boolean(paramList.getBoolean(3));
|
||||
|
||||
|
||||
//Get host info to deploy the VM
|
||||
|
||||
|
||||
host = VirtualMachineMigrate::hpool->get(hid,true);
|
||||
|
||||
|
||||
if ( host == 0 )
|
||||
{
|
||||
goto error_host_get;
|
||||
}
|
||||
|
||||
|
||||
hostname = host->get_hostname();
|
||||
vmm_mad = host->get_vmm_mad();
|
||||
tm_mad = host->get_tm_mad();
|
||||
@ -75,43 +74,43 @@ void RequestManager::VirtualMachineMigrate::execute(
|
||||
nd.get_configuration_attribute("VM_DIR",vmdir);
|
||||
|
||||
host->unlock();
|
||||
|
||||
|
||||
//Get the VM and migrate it
|
||||
|
||||
|
||||
vm = VirtualMachineMigrate::vmpool->get(vid,true);
|
||||
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
goto error_vm_get;
|
||||
}
|
||||
|
||||
uid = vm->get_uid();
|
||||
|
||||
uid = vm->get_uid();
|
||||
|
||||
// Only oneadmin or the VM owner can perform operations upon the VM
|
||||
rc = VirtualMachineMigrate::upool->authenticate(session);
|
||||
|
||||
|
||||
if ( rc != 0 && rc != uid)
|
||||
{
|
||||
goto error_authenticate;
|
||||
}
|
||||
|
||||
|
||||
if ((vm->get_state() != VirtualMachine::ACTIVE) ||
|
||||
(vm->get_lcm_state() != VirtualMachine::RUNNING))
|
||||
{
|
||||
goto error_state;
|
||||
}
|
||||
|
||||
thetime = time(0);
|
||||
|
||||
|
||||
vm->add_history(hid,hostname,vmdir,vmm_mad,tm_mad);
|
||||
|
||||
|
||||
rc = VirtualMachineMigrate::vmpool->update_history(vm);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
goto error_history;
|
||||
}
|
||||
|
||||
|
||||
vmpool->update(vm); //Insert last_seq in the DB
|
||||
|
||||
if ( live == true )
|
||||
{
|
||||
dm->live_migrate(vm);
|
||||
@ -120,19 +119,19 @@ void RequestManager::VirtualMachineMigrate::execute(
|
||||
{
|
||||
dm->migrate(vm);
|
||||
}
|
||||
|
||||
|
||||
vm->unlock();
|
||||
|
||||
|
||||
// Send results to client
|
||||
|
||||
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(true));
|
||||
|
||||
|
||||
arrayresult = new xmlrpc_c::value_array(arrayData);
|
||||
|
||||
|
||||
*retval = *arrayresult;
|
||||
|
||||
|
||||
delete arrayresult;
|
||||
|
||||
|
||||
return;
|
||||
|
||||
error_authenticate:
|
||||
@ -143,20 +142,20 @@ error_authenticate:
|
||||
error_host_get:
|
||||
oss << "The host " << hid << " does not exists";
|
||||
goto error_common;
|
||||
|
||||
|
||||
error_vm_get:
|
||||
oss << "The virtual machine " << vid << " does not exists";
|
||||
goto error_common;
|
||||
|
||||
error_history:
|
||||
vm->unlock();
|
||||
|
||||
oss << "Can not migrate VM " << vid << ", can not insert history";
|
||||
|
||||
oss << "Can not migrate VM " << vid << ", can not insert history";
|
||||
goto error_common;
|
||||
|
||||
error_state:
|
||||
vm->unlock();
|
||||
|
||||
|
||||
oss << "Can not migrate VM " << vid << ", wrong state";
|
||||
goto error_common;
|
||||
|
||||
@ -164,11 +163,11 @@ error_common:
|
||||
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false));
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
*retval = arrayresult_error;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -185,26 +185,21 @@ int VirtualMachine::select(SqlDB * db)
|
||||
|
||||
//Get the History Records
|
||||
|
||||
history = new History(oid);
|
||||
|
||||
rc = history->select(db);
|
||||
|
||||
if (rc != 0)
|
||||
if ( last_seq != -1 )
|
||||
{
|
||||
goto error_history;
|
||||
history = new History(oid, last_seq);
|
||||
|
||||
rc = history->select(db);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
goto error_history;
|
||||
}
|
||||
}
|
||||
|
||||
if ( history->seq == -1 )
|
||||
if ( last_seq > 0 )
|
||||
{
|
||||
delete history;
|
||||
|
||||
history = 0;
|
||||
}
|
||||
else if (history->seq > 0)
|
||||
{
|
||||
last_seq = history->seq;
|
||||
|
||||
previous_history = new History(oid,history->seq - 1);
|
||||
previous_history = new History(oid, last_seq - 1);
|
||||
|
||||
rc = previous_history->select(db);
|
||||
|
||||
@ -381,7 +376,7 @@ int VirtualMachine::insert_replace(SqlDB *db, bool replace)
|
||||
db->free_str(sql_deploy_id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if(replace)
|
||||
{
|
||||
oss << "REPLACE";
|
||||
@ -390,7 +385,7 @@ int VirtualMachine::insert_replace(SqlDB *db, bool replace)
|
||||
{
|
||||
oss << "INSERT";
|
||||
}
|
||||
|
||||
|
||||
oss << " INTO " << table << " "<< db_names <<" VALUES ("
|
||||
<< oid << ","
|
||||
<< uid << ","
|
||||
@ -421,8 +416,6 @@ int VirtualMachine::insert_replace(SqlDB *db, bool replace)
|
||||
|
||||
int VirtualMachine::dump(ostringstream& oss,int num,char **values,char **names)
|
||||
{
|
||||
int n = num;
|
||||
int j = ( LIMIT + History::LIMIT + 2 );
|
||||
if ((!values[OID])||
|
||||
(!values[UID])||
|
||||
(!values[NAME]) ||
|
||||
@ -437,7 +430,7 @@ int j = ( LIMIT + History::LIMIT + 2 );
|
||||
(!values[NET_TX])||
|
||||
(!values[NET_RX])||
|
||||
(!values[LAST_SEQ])||
|
||||
(num != LIMIT + History::LIMIT + 1 ))
|
||||
(num != (LIMIT + History::LIMIT + 1)))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@ -460,7 +453,7 @@ int j = ( LIMIT + History::LIMIT + 2 );
|
||||
"<NET_RX>" << values[NET_RX] << "</NET_RX>" <<
|
||||
"<LAST_SEQ>" << values[LAST_SEQ] << "</LAST_SEQ>";
|
||||
|
||||
History::dump(oss, num-LIMIT-2, values+LIMIT+1, names+LIMIT+1);
|
||||
History::dump(oss, num-LIMIT-1, values+LIMIT+1, names+LIMIT+1);
|
||||
|
||||
oss << "</VM>";
|
||||
|
||||
@ -963,6 +956,7 @@ string& VirtualMachine::to_str(string& str) const
|
||||
<< "STOP TIME : " << etime << endl
|
||||
<< "NET TX : " << net_tx << endl
|
||||
<< "NET RX : " << net_rx << endl
|
||||
<< "LAST SEQ : " << last_seq << endl
|
||||
<< "Template" << endl << vm_template.to_str(template_str) << endl;
|
||||
|
||||
if ( hasHistory() )
|
||||
|
@ -335,6 +335,9 @@ cout << endl << oss.str() << endl;
|
||||
// Add a history item
|
||||
vm->add_history(0, hostnames[0], vm_dirs[0], vmm_mads[0], tm_mads[0]);
|
||||
|
||||
rc = vmp->update(vm);
|
||||
CPPUNIT_ASSERT( rc == 0 );
|
||||
|
||||
rc = vmp->update_history(vm);
|
||||
CPPUNIT_ASSERT( rc == 0 );
|
||||
//----------------------------------------------------------------------
|
||||
@ -349,11 +352,19 @@ cout << endl << oss.str() << endl;
|
||||
|
||||
// Add a history item
|
||||
vm->add_history(1, hostnames[1], vm_dirs[1], vmm_mads[1], tm_mads[1]);
|
||||
|
||||
rc = vmp->update(vm);
|
||||
CPPUNIT_ASSERT( rc == 0 );
|
||||
|
||||
rc = vmp->update_history(vm);
|
||||
CPPUNIT_ASSERT( rc == 0 );
|
||||
|
||||
// Add another history item
|
||||
vm->add_history(2, hostnames[2], vm_dirs[2], vmm_mads[2], tm_mads[2]);
|
||||
|
||||
rc = vmp->update(vm);
|
||||
CPPUNIT_ASSERT( rc == 0 );
|
||||
|
||||
rc = vmp->update_history(vm);
|
||||
CPPUNIT_ASSERT( rc == 0 );
|
||||
//----------------------------------------------------------------------
|
||||
@ -412,11 +423,17 @@ cout << endl << oss.str() << endl;
|
||||
// Add a history item
|
||||
vm->add_history(0, hostname, vm_dir, vmm_mad, tm_mad);
|
||||
|
||||
rc = vmp->update(vm);
|
||||
CPPUNIT_ASSERT( rc == 0 );
|
||||
|
||||
rc = vmp->update_history(vm);
|
||||
CPPUNIT_ASSERT( rc == 0 );
|
||||
|
||||
vm->add_history(0, new_hostname, vm_dir, vmm_mad, tm_mad);
|
||||
|
||||
rc = vmp->update(vm);
|
||||
CPPUNIT_ASSERT( rc == 0 );
|
||||
|
||||
vm->set_reason(History::USER);
|
||||
vm->set_previous_reason(History::ERROR);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user