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

feature #1055: Added Reset action to OpenNebula core

This commit is contained in:
Ruben S. Montero 2012-05-08 22:33:59 +02:00
parent a427520272
commit 740f821a59
10 changed files with 229 additions and 186 deletions

View File

@ -219,6 +219,15 @@ public:
int reboot( int reboot(
int vid); int vid);
/**
* Resets 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 reset(
int vid);
/** /**
* Set the re-scheduling flag for the VM (must be in RUNNING state) * Set the re-scheduling flag for the VM (must be in RUNNING state)
* @param vid VirtualMachine identification * @param vid VirtualMachine identification

View File

@ -67,7 +67,6 @@ public:
LIVE_MIGRATE, /**< Sent by the DM to live-migrate a VM */ LIVE_MIGRATE, /**< Sent by the DM to live-migrate a VM */
SHUTDOWN, /**< Sent by the DM to shutdown a running VM */ SHUTDOWN, /**< Sent by the DM to shutdown a running VM */
RESTART, /**< Sent by the DM to restart a deployed 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 */ DELETE, /**< Sent by the DM to delete a VM */
CLEAN, /**< Sent by the DM to cleanup a VM for resubmission*/ CLEAN, /**< Sent by the DM to cleanup a VM for resubmission*/
FINALIZE FINALIZE
@ -195,8 +194,6 @@ private:
void restart_action(int vid); void restart_action(int vid);
void reboot_action(int vid);
void delete_action(int vid); void delete_action(int vid);
void clean_action(int vid); void clean_action(int vid);

View File

@ -52,6 +52,7 @@ public:
MIGRATE, MIGRATE,
RESTORE, RESTORE,
REBOOT, REBOOT,
RESET,
POLL, POLL,
TIMER, TIMER,
DRIVER_CANCEL, DRIVER_CANCEL,
@ -269,6 +270,13 @@ private:
*/ */
void reboot_action( void reboot_action(
int vid); int vid);
/**
* Resets a running VM.
* @param vid the id of the VM.
*/
void reset_action(
int vid);
/** /**
* Polls a VM. * Polls a VM.

View File

@ -116,7 +116,10 @@ private:
*/ */
void deploy ( void deploy (
const int oid, const int oid,
const string& drv_msg) const; const string& drv_msg) const
{
write_drv("DEPLOY", oid, drv_msg);
}
/** /**
* Sends a shutdown request to the MAD: "SHUTDOWN ID XML_DRV_MSG" * Sends a shutdown request to the MAD: "SHUTDOWN ID XML_DRV_MSG"
@ -125,7 +128,22 @@ private:
*/ */
void shutdown ( void shutdown (
const int oid, const int oid,
const string& drv_msg) const; const string& drv_msg) const
{
write_drv("SHUTDOWN", oid, drv_msg);
}
/**
* Sends a reset request to the MAD: "RESET ID XML_DRV_MSG"
* @param oid the virtual machine id.
* @param drv_msg xml data for the mad operation
*/
void reset (
const int oid,
const string& drv_msg) const
{
write_drv("RESET", oid, drv_msg);
}
/** /**
* Sends a reboot request to the MAD: "REBOOT ID XML_DRV_MSG" * Sends a reboot request to the MAD: "REBOOT ID XML_DRV_MSG"
@ -134,7 +152,10 @@ private:
*/ */
void reboot ( void reboot (
const int oid, const int oid,
const string& drv_msg) const; const string& drv_msg) const
{
write_drv("REBOOT", oid, drv_msg);
}
/** /**
* Sends a cancel request to the MAD: "CANCEL ID XML_DRV_MSG" * Sends a cancel request to the MAD: "CANCEL ID XML_DRV_MSG"
@ -143,7 +164,10 @@ private:
*/ */
void cancel ( void cancel (
const int oid, const int oid,
const string& drv_msg) const; const string& drv_msg) const
{
write_drv("CANCEL", oid, drv_msg);
}
/** /**
* Sends a checkpoint request to the MAD: "CHECKPOINT ID XML_DRV_MSG" * Sends a checkpoint request to the MAD: "CHECKPOINT ID XML_DRV_MSG"
@ -152,7 +176,10 @@ private:
*/ */
void checkpoint ( void checkpoint (
const int oid, const int oid,
const string& drv_msg) const; const string& drv_msg) const
{
write_drv("CHECKPOINT", oid, drv_msg);
}
/** /**
* Sends a save request to the MAD: "SAVE ID XML_DRV_MSG" * Sends a save request to the MAD: "SAVE ID XML_DRV_MSG"
@ -161,7 +188,11 @@ private:
*/ */
void save ( void save (
const int oid, const int oid,
const string& drv_msg) const; const string& drv_msg) const
{
write_drv("SAVE", oid, drv_msg);
}
/** /**
* Sends a save request to the MAD: "RESTORE ID XML_DRV_MSG" * Sends a save request to the MAD: "RESTORE ID XML_DRV_MSG"
@ -170,7 +201,11 @@ private:
*/ */
void restore ( void restore (
const int oid, const int oid,
const string& drv_msg) const; const string& drv_msg) const
{
write_drv("RESTORE", oid, drv_msg);
}
/** /**
* Sends a migrate request to the MAD: "MIGRATE ID XML_DRV_MSG" * Sends a migrate request to the MAD: "MIGRATE ID XML_DRV_MSG"
@ -179,7 +214,10 @@ private:
*/ */
void migrate ( void migrate (
const int oid, const int oid,
const string& drv_msg) const; const string& drv_msg) const
{
write_drv("MIGRATE", oid, drv_msg);
}
/** /**
* Sends a poll request to the MAD: "POLL ID XML_DRV_MSG" * Sends a poll request to the MAD: "POLL ID XML_DRV_MSG"
@ -188,7 +226,22 @@ private:
*/ */
void poll ( void poll (
const int oid, const int oid,
const string& drv_msg) const; const string& drv_msg) const
{
write_drv("POLL", oid, drv_msg);
}
private:
void write_drv(const char * aname, const int oid, const string& msg) const
{
ostringstream os;
os << aname << " " << oid << " " << msg << endl;
write(os);
}
}; };
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */

View File

@ -557,10 +557,14 @@ int DispatchManager::reboot(int vid)
if (vm->get_state() == VirtualMachine::ACTIVE && if (vm->get_state() == VirtualMachine::ACTIVE &&
vm->get_lcm_state() == VirtualMachine::RUNNING ) vm->get_lcm_state() == VirtualMachine::RUNNING )
{ {
Nebula& nd = Nebula::instance(); Nebula& nd = Nebula::instance();
LifeCycleManager * lcm = nd.get_lcm(); VirtualMachineManager * vmm = nd.get_vmm();
lcm->trigger(LifeCycleManager::REBOOT,vid); vmm->trigger(VirtualMachineManager::REBOOT,vid);
vm->set_resched(false); //Rebooting cancels re-scheduling actions
vmpool->update(vm);
} }
else else
{ {
@ -584,6 +588,55 @@ error:
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int DispatchManager::reset(int vid)
{
VirtualMachine * vm;
ostringstream oss;
vm = vmpool->get(vid,true);
if ( vm == 0 )
{
return -1;
}
oss << "Resetting VM " << vid;
NebulaLog::log("DiM",Log::DEBUG,oss);
if (vm->get_state() == VirtualMachine::ACTIVE &&
vm->get_lcm_state() == VirtualMachine::RUNNING )
{
Nebula& nd = Nebula::instance();
VirtualMachineManager * vmm = nd.get_vmm();
vmm->trigger(VirtualMachineManager::RESET,vid);
vm->set_resched(false); //Resetting cancels re-scheduling actions
vmpool->update(vm);
}
else
{
goto error;
}
vm->unlock();
return 0;
error:
oss.str("");
oss << "Could not reset VM " << vid << ", wrong state.";
NebulaLog::log("DiM",Log::ERROR,oss);
vm->unlock();
return -2;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int DispatchManager::resched(int vid, bool do_resched) int DispatchManager::resched(int vid, bool do_resched)
{ {
VirtualMachine * vm; VirtualMachine * vm;

View File

@ -439,41 +439,6 @@ void LifeCycleManager::cancel_action(int vid)
return; 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);
vm->set_resched(false); //Rebooting cancel re-scheduling actions
vmpool->update(vm);
}
else
{
vm->log("LCM", Log::ERROR, "reboot_action, VM in a wrong state.");
}
vm->unlock();
return;
}
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */

View File

@ -165,10 +165,6 @@ void LifeCycleManager::trigger(Actions action, int _vid)
aname = "RESTART"; aname = "RESTART";
break; break;
case REBOOT:
aname = "REBOOT";
break;
case DELETE: case DELETE:
aname = "DELETE"; aname = "DELETE";
break; break;
@ -302,10 +298,6 @@ void LifeCycleManager::do_action(const string &action, void * arg)
{ {
restart_action(vid); restart_action(vid);
} }
else if (action == "REBOOT")
{
reboot_action(vid);
}
else if (action == "DELETE") else if (action == "DELETE")
{ {
delete_action(vid); delete_action(vid);

View File

@ -180,7 +180,7 @@ void VirtualMachineAction::request_execute(xmlrpc_c::paramList const& paramList,
string action = xmlrpc_c::value_string(paramList.getString(1)); string action = xmlrpc_c::value_string(paramList.getString(1));
int id = xmlrpc_c::value_int(paramList.getInt(2)); int id = xmlrpc_c::value_int(paramList.getInt(2));
int rc; int rc = -4;
Nebula& nd = Nebula::instance(); Nebula& nd = Nebula::instance();
DispatchManager * dm = nd.get_dm(); DispatchManager * dm = nd.get_dm();
@ -249,6 +249,10 @@ void VirtualMachineAction::request_execute(xmlrpc_c::paramList const& paramList,
{ {
rc = dm->resched(id, false); rc = dm->resched(id, false);
} }
else if (action == "reset")
{
rc = dm->reset(id);
}
switch (rc) switch (rc)
{ {

View File

@ -130,6 +130,10 @@ void VirtualMachineManager::trigger(Actions action, int _vid)
aname = "REBOOT"; aname = "REBOOT";
break; break;
case RESET:
aname = "RESET";
break;
case SHUTDOWN: case SHUTDOWN:
aname = "SHUTDOWN"; aname = "SHUTDOWN";
break; break;
@ -206,6 +210,10 @@ void VirtualMachineManager::do_action(const string &action, void * arg)
{ {
reboot_action(vid); reboot_action(vid);
} }
else if (action == "RESET")
{
reset_action(vid);
}
else if (action == "SHUTDOWN") else if (action == "SHUTDOWN")
{ {
shutdown_action(vid); shutdown_action(vid);
@ -650,6 +658,75 @@ error_common:
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
void VirtualMachineManager::reset_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->reset(vid, *drv_msg);
delete drv_msg;
vm->unlock();
return;
error_history:
os.str("");
os << "reset_action, VM has no history";
goto error_common;
error_driver:
os.str("");
os << "reset_action, error getting driver " << vm->get_vmm_mad();
error_common:
vm->log("VMM", Log::ERROR, os);
vm->unlock();
return;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachineManager::cancel_action( void VirtualMachineManager::cancel_action(
int vid) int vid)
{ {

View File

@ -98,133 +98,6 @@ void VirtualMachineManagerDriver::get_default(
} }
} }
/* ************************************************************************** */
/* Driver ASCII Protocol Implementation */
/* ************************************************************************** */
void VirtualMachineManagerDriver::deploy (
const int oid,
const string& drv_msg) const
{
ostringstream os;
os << "DEPLOY " << oid << " " << drv_msg << endl;
write(os);
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachineManagerDriver::shutdown (
const int oid,
const string& drv_msg) const
{
ostringstream os;
os << "SHUTDOWN " << oid << " " << drv_msg << endl;
write(os);
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachineManagerDriver::cancel (
const int oid,
const string& drv_msg) const
{
ostringstream os;
os << "CANCEL " << oid << " " << drv_msg << endl;
write(os);
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachineManagerDriver::checkpoint (
const int oid,
const string& drv_msg) const
{
ostringstream os;
os<< "CHECKPOINT " << oid << " " << drv_msg << endl;
write(os);
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachineManagerDriver::save (
const int oid,
const string& drv_msg) const
{
ostringstream os;
os<< "SAVE " << oid << " " << drv_msg << endl;
write(os);
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachineManagerDriver::restore (
const int oid,
const string& drv_msg) const
{
ostringstream os;
os << "RESTORE " << oid << " " << drv_msg << endl;
write(os);
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachineManagerDriver::migrate (
const int oid,
const string& drv_msg) const
{
ostringstream os;
os<< "MIGRATE " << oid << " " << drv_msg << endl;
write(os);
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachineManagerDriver::poll (
const int oid,
const string& drv_msg) const
{
ostringstream os;
os << "POLL " << oid << " " << drv_msg << endl;
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 */ /* MAD Interface */
/* ************************************************************************** */ /* ************************************************************************** */
@ -450,6 +323,18 @@ void VirtualMachineManagerDriver::protocol(
vmpool->update(vm); vmpool->update(vm);
} }
} }
else if ( action == "RESET" )
{
if (result == "SUCCESS")
{
vm->log("VMM",Log::ERROR,"VM Successfully reseted.");
}
else
{
log_error(vm,os,is,"Error resetting VM, assume it's still running");
vmpool->update(vm);
}
}
else if ( action == "POLL" ) else if ( action == "POLL" )
{ {
if (result == "SUCCESS") if (result == "SUCCESS")