mirror of
https://github.com/OpenNebula/one.git
synced 2025-04-02 10:50:07 +03:00
feature #132: Support for reboot action in OpenNebula core
This commit is contained in:
parent
16a1b24b82
commit
7301def913
@ -210,6 +210,15 @@ public:
|
||||
int resubmit(
|
||||
int vid);
|
||||
|
||||
/**
|
||||
* Reboots a VM preserving any resource and RUNNING state
|
||||
* @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 reboot(
|
||||
int vid);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Thread id for the Dispatch Manager
|
||||
|
@ -67,6 +67,7 @@ public:
|
||||
LIVE_MIGRATE, /**< Sent by the DM to live-migrate a VM */
|
||||
SHUTDOWN, /**< Sent by the DM to shutdown a running VM */
|
||||
RESTART, /**< Sent by the DM to restart a deployed VM */
|
||||
REBOOT, /**< Sent by the DM to reboot a running VM */
|
||||
DELETE, /**< Sent by the DM to delete a VM */
|
||||
CLEAN, /**< Sent by the DM to cleanup a VM for resubmission*/
|
||||
FINALIZE
|
||||
@ -194,6 +195,8 @@ private:
|
||||
|
||||
void restart_action(int vid);
|
||||
|
||||
void reboot_action(int vid);
|
||||
|
||||
void delete_action(int vid);
|
||||
|
||||
void clean_action(int vid);
|
||||
|
@ -51,6 +51,7 @@ public:
|
||||
CANCEL_PREVIOUS,
|
||||
MIGRATE,
|
||||
RESTORE,
|
||||
REBOOT,
|
||||
POLL,
|
||||
TIMER,
|
||||
DRIVER_CANCEL,
|
||||
@ -262,6 +263,13 @@ private:
|
||||
void restore_action(
|
||||
int vid);
|
||||
|
||||
/**
|
||||
* Reboots a running VM.
|
||||
* @param vid the id of the VM.
|
||||
*/
|
||||
void reboot_action(
|
||||
int vid);
|
||||
|
||||
/**
|
||||
* Polls a VM.
|
||||
* @param vid the id of the VM.
|
||||
|
@ -127,6 +127,15 @@ private:
|
||||
const int oid,
|
||||
const string& drv_msg) const;
|
||||
|
||||
/**
|
||||
* Sends a reboot request to the MAD: "REBOOT ID XML_DRV_MSG"
|
||||
* @param oid the virtual machine id.
|
||||
* @param drv_msg xml data for the mad operation
|
||||
*/
|
||||
void reboot (
|
||||
const int oid,
|
||||
const string& drv_msg) const;
|
||||
|
||||
/**
|
||||
* Sends a cancel request to the MAD: "CANCEL ID XML_DRV_MSG"
|
||||
* @param oid the virtual machine id.
|
||||
|
@ -539,6 +539,50 @@ error:
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int DispatchManager::reboot(int vid)
|
||||
{
|
||||
VirtualMachine * vm;
|
||||
ostringstream oss;
|
||||
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
oss << "Rebooting VM " << vid;
|
||||
NebulaLog::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();
|
||||
|
||||
lcm->trigger(LifeCycleManager::REBOOT,vid);
|
||||
}
|
||||
else
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
vm->unlock();
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
oss.str("");
|
||||
oss << "Could not reboot VM " << vid << ", wrong state.";
|
||||
NebulaLog::log("DiM",Log::ERROR,oss);
|
||||
|
||||
vm->unlock();
|
||||
|
||||
return -2;
|
||||
}
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int DispatchManager::finalize(
|
||||
int vid)
|
||||
{
|
||||
|
@ -427,6 +427,37 @@ void LifeCycleManager::cancel_action(int vid)
|
||||
|
||||
return;
|
||||
}
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void LifeCycleManager::reboot_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();
|
||||
|
||||
vmm->trigger(VirtualMachineManager::REBOOT,vid);
|
||||
}
|
||||
else
|
||||
{
|
||||
vm->log("LCM", Log::ERROR, "reboot_action, VM in a wrong state.");
|
||||
}
|
||||
|
||||
vm->unlock();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -165,6 +165,10 @@ void LifeCycleManager::trigger(Actions action, int _vid)
|
||||
aname = "RESTART";
|
||||
break;
|
||||
|
||||
case REBOOT:
|
||||
aname = "REBOOT";
|
||||
break;
|
||||
|
||||
case DELETE:
|
||||
aname = "DELETE";
|
||||
break;
|
||||
@ -298,6 +302,10 @@ void LifeCycleManager::do_action(const string &action, void * arg)
|
||||
{
|
||||
restart_action(vid);
|
||||
}
|
||||
else if (action == "REBOOT")
|
||||
{
|
||||
reboot_action(vid);
|
||||
}
|
||||
else if (action == "DELETE")
|
||||
{
|
||||
delete_action(vid);
|
||||
|
@ -233,6 +233,10 @@ void VirtualMachineAction::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
{
|
||||
rc = dm->resubmit(id);
|
||||
}
|
||||
else if (action == "reboot")
|
||||
{
|
||||
rc = dm->reboot(id);
|
||||
}
|
||||
|
||||
switch (rc)
|
||||
{
|
||||
|
@ -126,6 +126,10 @@ void VirtualMachineManager::trigger(Actions action, int _vid)
|
||||
aname = "RESTORE";
|
||||
break;
|
||||
|
||||
case REBOOT:
|
||||
aname = "REBOOT";
|
||||
break;
|
||||
|
||||
case SHUTDOWN:
|
||||
aname = "SHUTDOWN";
|
||||
break;
|
||||
@ -198,6 +202,10 @@ void VirtualMachineManager::do_action(const string &action, void * arg)
|
||||
{
|
||||
restore_action(vid);
|
||||
}
|
||||
else if (action == "REBOOT")
|
||||
{
|
||||
reboot_action(vid);
|
||||
}
|
||||
else if (action == "SHUTDOWN")
|
||||
{
|
||||
shutdown_action(vid);
|
||||
@ -573,6 +581,75 @@ error_common:
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualMachineManager::reboot_action(
|
||||
int vid)
|
||||
{
|
||||
VirtualMachine * vm;
|
||||
const VirtualMachineManagerDriver * vmd;
|
||||
|
||||
string vm_tmpl;
|
||||
string * drv_msg;
|
||||
ostringstream os;
|
||||
|
||||
// Get the VM from the pool
|
||||
vm = vmpool->get(vid,true);
|
||||
|
||||
if (vm == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!vm->hasHistory())
|
||||
{
|
||||
goto error_history;
|
||||
}
|
||||
|
||||
// Get the driver for this VM
|
||||
vmd = get(vm->get_vmm_mad());
|
||||
|
||||
if ( vmd == 0 )
|
||||
{
|
||||
goto error_driver;
|
||||
}
|
||||
|
||||
// Invoke driver method
|
||||
drv_msg = format_message(
|
||||
vm->get_hostname(),
|
||||
vm->get_vnm_mad(),
|
||||
"",
|
||||
"",
|
||||
vm->get_deploy_id(),
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
vm->to_xml(vm_tmpl));
|
||||
|
||||
vmd->reboot(vid, *drv_msg);
|
||||
|
||||
delete drv_msg;
|
||||
|
||||
vm->unlock();
|
||||
|
||||
return;
|
||||
|
||||
error_history:
|
||||
os.str("");
|
||||
os << "reboot_action, VM has no history";
|
||||
goto error_common;
|
||||
|
||||
error_driver:
|
||||
os.str("");
|
||||
os << "reboot_action, error getting driver " << vm->get_vmm_mad();
|
||||
|
||||
error_common:
|
||||
vm->log("VMM", Log::ERROR, os);
|
||||
vm->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualMachineManager::cancel_action(
|
||||
int vid)
|
||||
{
|
||||
|
@ -211,6 +211,20 @@ void VirtualMachineManagerDriver::poll (
|
||||
write(os);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualMachineManagerDriver::reboot (
|
||||
const int oid,
|
||||
const string& drv_msg) const
|
||||
{
|
||||
ostringstream os;
|
||||
|
||||
os << "REBOOT " << oid << " " << drv_msg << endl;
|
||||
|
||||
write(os);
|
||||
};
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* MAD Interface */
|
||||
/* ************************************************************************** */
|
||||
@ -424,6 +438,18 @@ void VirtualMachineManagerDriver::protocol(
|
||||
lcm->trigger(LifeCycleManager::DEPLOY_FAILURE, id);
|
||||
}
|
||||
}
|
||||
else if ( action == "REBOOT" )
|
||||
{
|
||||
if (result == "SUCCESS")
|
||||
{
|
||||
vm->log("VMM",Log::ERROR,"VM Successfully rebooted.");
|
||||
}
|
||||
else
|
||||
{
|
||||
log_error(vm,os,is,"Error rebooting VM, assume it's still running");
|
||||
vmpool->update(vm);
|
||||
}
|
||||
}
|
||||
else if ( action == "POLL" )
|
||||
{
|
||||
if (result == "SUCCESS")
|
||||
|
Loading…
x
Reference in New Issue
Block a user