diff --git a/include/LifeCycleManager.h b/include/LifeCycleManager.h
index 5c280618aa..c8499e33c3 100644
--- a/include/LifeCycleManager.h
+++ b/include/LifeCycleManager.h
@@ -62,6 +62,8 @@ public:
ATTACH_FAILURE, /**< Sent by the VMM when an attach action fails */
DETACH_SUCCESS, /**< Sent by the VMM when a detach action succeeds */
DETACH_FAILURE, /**< Sent by the VMM when a detach action fails */
+ CLEANUP_SUCCESS, /**< Sent by the VMM when a cleanup action succeeds */
+ CLEANUP_FAILURE, /**< Sent by the VMM when a cleanup action fails */
DEPLOY, /**< Sent by the DM to deploy a VM on a host */
SUSPEND, /**< Sent by the DM to suspend an running VM */
RESTORE, /**< Sent by the DM to restore a suspended VM */
@@ -145,7 +147,7 @@ private:
* the history registers
* @param vm with the lock aquired
*/
- void clean_up_vm (VirtualMachine *vm);
+ void clean_up_vm (VirtualMachine *vm, bool dispose);
void save_success_action(int vid);
@@ -185,6 +187,8 @@ private:
void detach_failure_action(int vid);
+ void cleanup_callback_action(int vid);
+
void deploy_action(int vid);
void suspend_action(int vid);
diff --git a/include/TransferManager.h b/include/TransferManager.h
index 1b2b1265a6..6a66e4b1cc 100644
--- a/include/TransferManager.h
+++ b/include/TransferManager.h
@@ -54,6 +54,7 @@ public:
EPILOG_DELETE,
EPILOG_DELETE_PREVIOUS,
EPILOG_DELETE_STOP,
+ EPILOG_DELETE_BOTH,
CHECKPOINT,
DRIVER_CANCEL,
FINALIZE
@@ -138,6 +139,20 @@ public:
VirtualMachine * vm,
ostream& xfr);
+ /**
+ * This function generates the the epilog_delete sequence for current,
+ * front-end and previous hosts.
+ * @param vm pointer to VM, locked
+ * @param xfr stream to write the commands
+ * @param local true to delete the front-end
+ * @param previous true to delete the previous host
+ *
+ * @return 0 on success
+ */
+ int epilog_delete_commands(VirtualMachine *vm,
+ ostream& xfr,
+ bool local,
+ bool previous);
private:
/**
* Thread id for the Transfer Manager
@@ -247,7 +262,8 @@ private:
void epilog_stop_action(int vid);
/**
- * This function starts the epilog_delete sequence
+ * This function starts the epilog_delete sequence in the current host
+ * @param vid the Virtual Machine ID
*/
void epilog_delete_action(int vid)
{
@@ -256,22 +272,32 @@ private:
/**
* This function starts the epilog_delete_stop sequence on the local host
+ * i.e. the front-end (the VM is not running)
+ * @param vid the Virtual Machine ID
*/
void epilog_delete_stop_action(int vid)
{
epilog_delete_action(true, vid);
}
+ /**
+ * This function starts the epilog_delete sequence on the previous host
+ * @param vid the Virtual Machine ID
+ */
+ void epilog_delete_previous_action(int vid);
+
+ /**
+ * This function starts the epilog_delete sequence on the current and
+ * previous hosts
+ * @param vid the Virtual Machine ID
+ */
+ void epilog_delete_both_action(int vid);
+
/**
* This function starts the epilog_delete sequence
*/
void epilog_delete_action(bool local, int vid);
- /**
- * This function starts the epilog_delete sequence on the previous host
- */
- void epilog_delete_previous_action(int vid);
-
/**
* This function starts the epilog sequence
*/
diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h
index 08b02cf5ac..a6b32f0133 100644
--- a/include/VirtualMachine.h
+++ b/include/VirtualMachine.h
@@ -81,14 +81,15 @@ public:
SHUTDOWN = 12,
CANCEL = 13,
FAILURE = 14,
- CLEANUP = 15,
+ CLEANUP_RESUBMIT = 15,
UNKNOWN = 16,
HOTPLUG = 17,
SHUTDOWN_POWEROFF = 18,
BOOT_UNKNOWN = 19,
BOOT_POWEROFF = 20,
BOOT_SUSPENDED = 21,
- BOOT_STOPPED = 22
+ BOOT_STOPPED = 22,
+ CLEANUP_DELETE = 23
};
// -------------------------------------------------------------------------
diff --git a/include/VirtualMachineManager.h b/include/VirtualMachineManager.h
index 42d1525a46..4f6c6a58a6 100644
--- a/include/VirtualMachineManager.h
+++ b/include/VirtualMachineManager.h
@@ -49,6 +49,9 @@ public:
SHUTDOWN,
CANCEL,
CANCEL_PREVIOUS,
+ CLEANUP,
+ CLEANUP_BOTH,
+ CLEANUP_PREVIOUS,
MIGRATE,
RESTORE,
REBOOT,
@@ -257,6 +260,22 @@ private:
void cancel_previous_action(
int vid);
+ /**
+ * Cleanups a host (cancel VM + delete disk images).
+ * @param vid the id of the VM.
+ * @param cancel_previous if true the VM will be canceled in the previous
+ * host (only relevant to delete VM's in MIGRATE state)
+ */
+ void cleanup_action(
+ int vid, bool cancel_previous);
+
+ /**
+ * Cleanups the previous host (cancel VM + delete disk images).
+ * @param vid the id of the VM.
+ */
+ void cleanup_previous_action(
+ int vid);
+
/**
* Function to migrate (live) a VM (MIGRATE action).
* @param vid the id of the VM.
diff --git a/include/VirtualMachineManagerDriver.h b/include/VirtualMachineManagerDriver.h
index 6c7d55f826..11ef3ab386 100644
--- a/include/VirtualMachineManagerDriver.h
+++ b/include/VirtualMachineManagerDriver.h
@@ -30,7 +30,7 @@ using namespace std;
* VirtualMachineManagerDriver provides a base class to implement VM Manager
* Drivers. This class implements the protocol and recover functions
* from the Mad interface. Classes derived from the VirtualMachineManagerDriver
- * must implement the deployment function to generate specific VM
+ * must implement the deployment function to generate specific VM
* deployment information for the unerlying MAD.
*/
class VirtualMachineManagerDriver : public Mad
@@ -53,7 +53,7 @@ public:
string& message);
/**
- * TODO: What do we need here? just poll the active VMs to recover
+ * TODO: What do we need here? just poll the active VMs to recover
* connections? Or an specific recover action from the MAD?
*/
void recover();
@@ -67,25 +67,25 @@ public:
virtual int deployment_description(
const VirtualMachine * vm,
const string& file_name) const = 0;
-
-protected:
+
+protected:
/**
- * Gets a configuration attr from driver configuration file (single
+ * Gets a configuration attr from driver configuration file (single
* version)
* @param name of config attribute
* @param value of the attribute
*/
void get_default(
- const char * name,
+ const char * name,
string& value) const
{
string sn = name;
-
+
driver_conf.get(sn,value);
- }
+ }
/**
- * Gets a configuration attr from driver configuration file (vector
+ * Gets a configuration attr from driver configuration file (vector
* version)
* @param name of config vector attribute for the domain
* @param vname of the attribute
@@ -95,20 +95,20 @@ protected:
const char * name,
const char * vname,
string& value) const;
-
-private:
- /**
+
+private:
+ /**
* Configuration file for the driver
*/
Template driver_conf;
-
+
/**
* Pointer to the Virtual Machine Pool, to access VMs
*/
VirtualMachinePool * vmpool;
friend class VirtualMachineManager;
-
+
/**
* Sends a deploy request to the MAD: "DEPLOY ID XML_DRV_MSG"
* @param oid the virtual machine id.
@@ -169,6 +169,18 @@ private:
write_drv("CANCEL", oid, drv_msg);
}
+ /**
+ * Sends a cleanup request to the MAD: "CLEANUP ID XML_DRV_MSG"
+ * @param oid the virtual machine id.
+ * @param drv_msg xml data for the mad operation
+ */
+ void cleanup (
+ const int oid,
+ const string& drv_msg) const
+ {
+ write_drv("CLEANUP", oid, drv_msg);
+ }
+
/**
* Sends a checkpoint request to the MAD: "CHECKPOINT ID XML_DRV_MSG"
* @param oid the virtual machine id.
@@ -263,7 +275,7 @@ private:
ostringstream os;
os << aname << " " << oid << " " << msg << endl;
-
+
write(os);
}
};
diff --git a/share/doc/xsd/acct.xsd b/share/doc/xsd/acct.xsd
index 824bbc25a0..d9b435b817 100644
--- a/share/doc/xsd/acct.xsd
+++ b/share/doc/xsd/acct.xsd
@@ -83,29 +83,30 @@
diff --git a/share/doc/xsd/vm.xsd b/share/doc/xsd/vm.xsd
index a6f1b96bbe..38bbf943c7 100644
--- a/share/doc/xsd/vm.xsd
+++ b/share/doc/xsd/vm.xsd
@@ -45,29 +45,30 @@
diff --git a/src/dm/DispatchManagerActions.cc b/src/dm/DispatchManagerActions.cc
index c5f642d280..87fe90f1e4 100644
--- a/src/dm/DispatchManagerActions.cc
+++ b/src/dm/DispatchManagerActions.cc
@@ -868,7 +868,7 @@ int DispatchManager::resubmit(int vid)
case VirtualMachine::FAILED: //Cleanup VM host files
vm->log("DiM", Log::INFO, "New VM state is CLEANUP.");
- vm->set_state(VirtualMachine::CLEANUP);
+ vm->set_state(VirtualMachine::CLEANUP_RESUBMIT);
vm->set_state(VirtualMachine::ACTIVE);
vmpool->update(vm);
diff --git a/src/dm/DispatchManagerStates.cc b/src/dm/DispatchManagerStates.cc
index 98053f2565..2ce1c9903c 100644
--- a/src/dm/DispatchManagerStates.cc
+++ b/src/dm/DispatchManagerStates.cc
@@ -161,7 +161,7 @@ void DispatchManager::done_action(int vid)
if ((dm_state == VirtualMachine::ACTIVE) &&
(lcm_state == VirtualMachine::EPILOG ||
lcm_state == VirtualMachine::CANCEL ||
- lcm_state == VirtualMachine::CLEANUP ))
+ lcm_state == VirtualMachine::CLEANUP_DELETE))
{
vm->set_state(VirtualMachine::DONE);
@@ -180,11 +180,11 @@ void DispatchManager::done_action(int vid)
uid = vm->get_uid();
gid = vm->get_gid();
tmpl = vm->clone_template();
-
+
vm->unlock();
Quotas::vm_del(uid, gid, tmpl);
-
+
delete tmpl;
}
else
@@ -196,7 +196,7 @@ void DispatchManager::done_action(int vid)
vm->unlock();
}
-
+
return;
}
@@ -247,7 +247,7 @@ void DispatchManager::resubmit_action(int vid)
return;
}
- if (vm->get_lcm_state() == VirtualMachine::CLEANUP)
+ if (vm->get_lcm_state() == VirtualMachine::CLEANUP_RESUBMIT)
{
vm->set_state(VirtualMachine::LCM_INIT);
diff --git a/src/lcm/LifeCycleActions.cc b/src/lcm/LifeCycleActions.cc
index 3833945405..d3c189aa40 100644
--- a/src/lcm/LifeCycleActions.cc
+++ b/src/lcm/LifeCycleActions.cc
@@ -573,6 +573,7 @@ void LifeCycleManager::delete_action(int vid)
Nebula& nd = Nebula::instance();
DispatchManager * dm = nd.get_dm();
+ TransferManager * tm = nd.get_tm();
vm = vmpool->get(vid,true);
@@ -581,17 +582,41 @@ void LifeCycleManager::delete_action(int vid)
return;
}
- if ( vm->get_state() == VirtualMachine::ACTIVE &&
- (vm->get_lcm_state() != VirtualMachine::LCM_INIT &&
- vm->get_lcm_state() != VirtualMachine::CLEANUP))
- {
- clean_up_vm(vm);
- dm->trigger(DispatchManager::DONE,vid);
- }
- else
+ if ( vm->get_state() != VirtualMachine::ACTIVE )
{
- vm->log("LCM", Log::ERROR, "delete_action, VM in a wrong state.");
+ vm->log("LCM", Log::ERROR, "clean_action, VM in a wrong state.");
+ vm->unlock();
+
+ return;
+ }
+
+ switch(vm->get_lcm_state())
+ {
+ case VirtualMachine::LCM_INIT:
+ vm->log("LCM", Log::ERROR, "clean_action, VM in a wrong state.");
+ break;
+
+ case VirtualMachine::CLEANUP_RESUBMIT:
+ case VirtualMachine::CLEANUP_DELETE:
+ vm->set_state(VirtualMachine::CLEANUP_DELETE);
+ vmpool->update(vm);
+
+ dm->trigger(DispatchManager::DONE, vid);
+ break;
+
+ case VirtualMachine::FAILURE:
+ vm->set_state(VirtualMachine::CLEANUP_DELETE);
+ vmpool->update(vm);
+
+ tm->trigger(TransferManager::EPILOG_DELETE,vid);
+ dm->trigger(DispatchManager::DONE, vid);
+ break;
+
+ default:
+ clean_up_vm(vm, true);
+ dm->trigger(DispatchManager::DONE, vid);
+ break;
}
vm->unlock();
@@ -606,6 +631,10 @@ void LifeCycleManager::clean_action(int vid)
{
VirtualMachine * vm;
+ Nebula& nd = Nebula::instance();
+ DispatchManager * dm = nd.get_dm();
+ TransferManager * tm = nd.get_tm();
+
vm = vmpool->get(vid,true);
if ( vm == 0 )
@@ -613,16 +642,35 @@ void LifeCycleManager::clean_action(int vid)
return;
}
-
- if ( vm->get_state() == VirtualMachine::ACTIVE &&
- (vm->get_lcm_state() != VirtualMachine::LCM_INIT &&
- vm->get_lcm_state() != VirtualMachine::CLEANUP))
- {
- clean_up_vm(vm);
- }
- else
+ if ( vm->get_state() != VirtualMachine::ACTIVE )
{
vm->log("LCM", Log::ERROR, "clean_action, VM in a wrong state.");
+ vm->unlock();
+
+ return;
+ }
+
+ switch(vm->get_lcm_state())
+ {
+ case VirtualMachine::LCM_INIT:
+ case VirtualMachine::CLEANUP_DELETE:
+ vm->log("LCM", Log::ERROR, "clean_action, VM in a wrong state.");
+ break;
+
+ case VirtualMachine::CLEANUP_RESUBMIT:
+ dm->trigger(DispatchManager::RESUBMIT, vid);
+ break;
+
+ case VirtualMachine::FAILURE:
+ vm->set_state(VirtualMachine::CLEANUP_RESUBMIT);
+ vmpool->update(vm);
+
+ tm->trigger(TransferManager::EPILOG_DELETE,vid);
+ break;
+
+ default:
+ clean_up_vm(vm, false);
+ break;
}
vm->unlock();
@@ -631,7 +679,7 @@ void LifeCycleManager::clean_action(int vid)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
-void LifeCycleManager::clean_up_vm(VirtualMachine * vm)
+void LifeCycleManager::clean_up_vm(VirtualMachine * vm, bool dispose)
{
int cpu, mem, disk;
time_t the_time = time(0);
@@ -646,7 +694,15 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm)
vm->log("LCM", Log::INFO, "New VM state is CLEANUP.");
- vm->set_state(VirtualMachine::CLEANUP);
+ if (dispose)
+ {
+ vm->set_state(VirtualMachine::CLEANUP_DELETE);
+ }
+ else
+ {
+ vm->set_state(VirtualMachine::CLEANUP_RESUBMIT);
+ }
+
vm->set_resched(false);
vmpool->update(vm);
@@ -683,9 +739,7 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm)
vmpool->update_history(vm);
vmm->trigger(VirtualMachineManager::DRIVER_CANCEL,vid);
- vmm->trigger(VirtualMachineManager::CANCEL,vid);
-
- tm->trigger(TransferManager::EPILOG_DELETE,vid);
+ vmm->trigger(VirtualMachineManager::CLEANUP,vid);
break;
case VirtualMachine::MIGRATE:
@@ -701,11 +755,7 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm)
hpool->del_capacity(vm->get_previous_hid(), vm->get_oid(), cpu, mem, disk);
vmm->trigger(VirtualMachineManager::DRIVER_CANCEL,vid);
-
- vmm->trigger(VirtualMachineManager::CANCEL,vid);
- vmm->trigger(VirtualMachineManager::CANCEL_PREVIOUS,vid);
-
- tm->trigger(TransferManager::EPILOG_DELETE,vid);
+ vmm->trigger(VirtualMachineManager::CLEANUP_BOTH,vid);
break;
case VirtualMachine::SAVE_STOP:
@@ -714,9 +764,7 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm)
vmpool->update_history(vm);
vmm->trigger(VirtualMachineManager::DRIVER_CANCEL,vid);
- vmm->trigger(VirtualMachineManager::CANCEL,vid);
-
- tm->trigger(TransferManager::EPILOG_DELETE,vid);
+ vmm->trigger(VirtualMachineManager::CLEANUP,vid);
break;
case VirtualMachine::SAVE_MIGRATE:
@@ -732,9 +780,7 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm)
hpool->del_capacity(vm->get_previous_hid(), vm->get_oid(), cpu, mem, disk);
vmm->trigger(VirtualMachineManager::DRIVER_CANCEL,vid);
- vmm->trigger(VirtualMachineManager::CANCEL_PREVIOUS,vid);
-
- tm->trigger(TransferManager::EPILOG_DELETE_PREVIOUS,vid);
+ vmm->trigger(VirtualMachineManager::CLEANUP_PREVIOUS,vid);
break;
case VirtualMachine::PROLOG_MIGRATE:
@@ -742,8 +788,7 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm)
vmpool->update_history(vm);
tm->trigger(TransferManager::DRIVER_CANCEL,vid);
- tm->trigger(TransferManager::EPILOG_DELETE,vid);
- tm->trigger(TransferManager::EPILOG_DELETE_PREVIOUS,vid);
+ tm->trigger(TransferManager::EPILOG_DELETE_BOTH,vid);
break;
case VirtualMachine::EPILOG_STOP:
@@ -755,12 +800,7 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm)
tm->trigger(TransferManager::EPILOG_DELETE,vid);
break;
- case VirtualMachine::FAILURE:
- vmpool->update_history(vm);
- tm->trigger(TransferManager::EPILOG_DELETE,vid);
- break;
-
- default: //LCM_INIT,CLEANUP
+ default: //LCM_INIT,CLEANUP_RESUBMIT, CLEANUP_DELETE, FAILURE
break;
}
}
diff --git a/src/lcm/LifeCycleManager.cc b/src/lcm/LifeCycleManager.cc
index d763b5dac8..a22e565bab 100644
--- a/src/lcm/LifeCycleManager.cc
+++ b/src/lcm/LifeCycleManager.cc
@@ -145,6 +145,14 @@ void LifeCycleManager::trigger(Actions action, int _vid)
aname = "DETACH_FAILURE";
break;
+ case CLEANUP_SUCCESS:
+ aname = "CLEANUP_SUCCESS";
+ break;
+
+ case CLEANUP_FAILURE:
+ aname = "CLEANUP_FAILURE";
+ break;
+
case DEPLOY:
aname = "DEPLOY";
break;
@@ -298,6 +306,14 @@ void LifeCycleManager::do_action(const string &action, void * arg)
{
detach_failure_action(vid);
}
+ else if (action == "CLEANUP_SUCCESS")
+ {
+ cleanup_callback_action(vid);
+ }
+ else if (action == "CLEANUP_FAILURE")
+ {
+ cleanup_callback_action(vid);
+ }
else if (action == "DEPLOY")
{
deploy_action(vid);
diff --git a/src/lcm/LifeCycleStates.cc b/src/lcm/LifeCycleStates.cc
index f675572258..81735432ae 100644
--- a/src/lcm/LifeCycleStates.cc
+++ b/src/lcm/LifeCycleStates.cc
@@ -722,7 +722,7 @@ void LifeCycleManager::epilog_success_action(int vid)
{
action = DispatchManager::DONE;
}
- else if ( state == VirtualMachine::CLEANUP )
+ else if ( state == VirtualMachine::CLEANUP_RESUBMIT )
{
dm->trigger(DispatchManager::RESUBMIT, vid);
@@ -762,6 +762,42 @@ void LifeCycleManager::epilog_success_action(int vid)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
+void LifeCycleManager::cleanup_callback_action(int vid)
+{
+ Nebula& nd = Nebula::instance();
+ DispatchManager * dm = nd.get_dm();
+
+ VirtualMachine * vm;
+
+ VirtualMachine::LcmState state;
+
+ vm = vmpool->get(vid,true);
+
+ if ( vm == 0 )
+ {
+ return;
+ }
+
+ state = vm->get_lcm_state();
+
+ if ( state == VirtualMachine::CLEANUP_RESUBMIT )
+ {
+ dm->trigger(DispatchManager::RESUBMIT, vid);
+
+ }
+ else
+ {
+ vm->log("LCM",Log::ERROR,"cleanup_callback_action, VM in a wrong state");
+ }
+
+ vm->unlock();
+
+ return;
+}
+
+/* -------------------------------------------------------------------------- */
+/* -------------------------------------------------------------------------- */
+
void LifeCycleManager::epilog_failure_action(int vid)
{
VirtualMachine * vm;
@@ -774,7 +810,7 @@ void LifeCycleManager::epilog_failure_action(int vid)
return;
}
- if ( vm->get_lcm_state() == VirtualMachine::CLEANUP )
+ if ( vm->get_lcm_state() == VirtualMachine::CLEANUP_RESUBMIT )
{
Nebula& nd = Nebula::instance();
DispatchManager * dm = nd.get_dm();
diff --git a/src/mad/ruby/VirtualMachineDriver.rb b/src/mad/ruby/VirtualMachineDriver.rb
index 335b63a03a..4d2936817a 100644
--- a/src/mad/ruby/VirtualMachineDriver.rb
+++ b/src/mad/ruby/VirtualMachineDriver.rb
@@ -42,6 +42,7 @@ class VirtualMachineDriver < OpenNebulaDriver
:log => "LOG",
:attach_disk => "ATTACHDISK",
:detach_disk => "DETACHDISK",
+ :cleanup => "CLEANUP"
}
POLL_ATTRIBUTE = {
@@ -89,6 +90,7 @@ class VirtualMachineDriver < OpenNebulaDriver
register_action(ACTION[:poll].to_sym, method("poll"))
register_action(ACTION[:attach_disk].to_sym, method("attach_disk"))
register_action(ACTION[:detach_disk].to_sym, method("detach_disk"))
+ register_action(ACTION[:cleanup].to_sym, method("cleanup"))
end
# Decodes the encoded XML driver message received from the core
@@ -168,6 +170,11 @@ class VirtualMachineDriver < OpenNebulaDriver
send_message(ACTION[:detach_disk],RESULT[:failure],id,error)
end
+ def cleanup(id, drv_message)
+ error = "Action not implemented by driver #{self.class}"
+ send_message(ACTION[:cleanup],RESULT[:failure],id,error)
+ end
+
private
# Interface to handle the pending events from the ActionManager Interface
def delete_running_action(action_id)
diff --git a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java
index 6b1509c165..a6e5853bb9 100644
--- a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java
+++ b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java
@@ -83,14 +83,15 @@ public class VirtualMachine extends PoolElement{
"SHUTDOWN",
"CANCEL",
"FAILURE",
- "CLEANUP",
+ "CLEANUP_RESUBMIT",
"UNKNOWN",
"HOTPLUG",
"SHUTDOWN_POWEROFF",
"BOOT_UNKNOWN",
"BOOT_POWEROFF",
"BOOT_SUSPENDED",
- "BOOT_STOPPED" };
+ "BOOT_STOPPED",
+ "CLEANUP_DELETE" };
private static final String[] SHORT_LCM_STATES =
{
@@ -116,7 +117,8 @@ public class VirtualMachine extends PoolElement{
"boot",
"boot",
"boot",
- "boot" };
+ "boot",
+ "clea" };
/**
* Creates a new VM representation.
diff --git a/src/oca/ruby/opennebula/virtual_machine.rb b/src/oca/ruby/opennebula/virtual_machine.rb
index 4bc05ae717..37937ddada 100644
--- a/src/oca/ruby/opennebula/virtual_machine.rb
+++ b/src/oca/ruby/opennebula/virtual_machine.rb
@@ -45,8 +45,8 @@ module OpenNebula
LCM_STATE=%w{LCM_INIT PROLOG BOOT RUNNING MIGRATE SAVE_STOP SAVE_SUSPEND
SAVE_MIGRATE PROLOG_MIGRATE PROLOG_RESUME EPILOG_STOP EPILOG
- SHUTDOWN CANCEL FAILURE CLEANUP UNKNOWN HOTPLUG SHUTDOWN_POWEROFF
- BOOT_UNKNOWN BOOT_POWEROFF BOOT_SUSPENDED BOOT_STOPPED}
+ SHUTDOWN CANCEL FAILURE CLEANUP_RESUBMIT UNKNOWN HOTPLUG SHUTDOWN_POWEROFF
+ BOOT_UNKNOWN BOOT_POWEROFF BOOT_SUSPENDED BOOT_STOPPED CLEANUP_DELETE}
SHORT_VM_STATES={
"INIT" => "init",
@@ -61,28 +61,29 @@ module OpenNebula
}
SHORT_LCM_STATES={
- "PROLOG" => "prol",
- "BOOT" => "boot",
- "RUNNING" => "runn",
- "MIGRATE" => "migr",
- "SAVE_STOP" => "save",
- "SAVE_SUSPEND" => "save",
- "SAVE_MIGRATE" => "save",
- "PROLOG_MIGRATE"=> "migr",
- "PROLOG_RESUME" => "prol",
- "EPILOG_STOP" => "epil",
- "EPILOG" => "epil",
- "SHUTDOWN" => "shut",
- "CANCEL" => "shut",
- "FAILURE" => "fail",
- "CLEANUP" => "clea",
- "UNKNOWN" => "unkn",
- "HOTPLUG" => "hotp",
+ "PROLOG" => "prol",
+ "BOOT" => "boot",
+ "RUNNING" => "runn",
+ "MIGRATE" => "migr",
+ "SAVE_STOP" => "save",
+ "SAVE_SUSPEND" => "save",
+ "SAVE_MIGRATE" => "save",
+ "PROLOG_MIGRATE" => "migr",
+ "PROLOG_RESUME" => "prol",
+ "EPILOG_STOP" => "epil",
+ "EPILOG" => "epil",
+ "SHUTDOWN" => "shut",
+ "CANCEL" => "shut",
+ "FAILURE" => "fail",
+ "CLEANUP_RESUBMIT" => "clea",
+ "UNKNOWN" => "unkn",
+ "HOTPLUG" => "hotp",
"SHUTDOWN_POWEROFF" => "shut",
- "BOOT_UNKNOWN" => "boot",
- "BOOT_POWEROFF" => "boot",
- "BOOT_SUSPENDED" => "boot",
- "BOOT_STOPPED" => "boot"
+ "BOOT_UNKNOWN" => "boot",
+ "BOOT_POWEROFF" => "boot",
+ "BOOT_SUSPENDED" => "boot",
+ "BOOT_STOPPED" => "boot",
+ "CLEANUP_DELETE" => "clea"
}
MIGRATE_REASON=%w{NONE ERROR STOP_RESUME USER CANCEL}
diff --git a/src/ozones/Server/public/js/ozones.js b/src/ozones/Server/public/js/ozones.js
index 3a1d54501a..d564cb91b5 100644
--- a/src/ozones/Server/public/js/ozones.js
+++ b/src/ozones/Server/public/js/ozones.js
@@ -94,14 +94,15 @@ var oZones = {
"SHUTDOWN",
"CANCEL",
"FAILURE",
- "CLEANUP",
+ "CLEANUP_RESUBMIT",
"UNKNOWN",
"HOTPLUG",
"SHUTDOWN_POWEROFF",
"BOOT_UNKNOWN",
"BOOT_POWEROFF",
"BOOT_SUSPENDED",
- "BOOT_STOPPED"][value]);
+ "BOOT_STOPPED",
+ "CLEANUP_DELETE"][value]);
break;
case "IMAGE":
case "image":
diff --git a/src/sunstone/public/js/opennebula.js b/src/sunstone/public/js/opennebula.js
index 5c1f5d53c4..49a1de90ab 100644
--- a/src/sunstone/public/js/opennebula.js
+++ b/src/sunstone/public/js/opennebula.js
@@ -102,14 +102,15 @@ var OpenNebula = {
"SHUTDOWN",
"CANCEL",
"FAILURE",
- "CLEANUP",
+ "CLEANUP_RESUBMIT",
"UNKNOWN",
"HOTPLUG",
"SHUTDOWN_POWEROFF",
"BOOT_UNKNOWN",
"BOOT_POWEROFF",
"BOOT_SUSPENDED",
- "BOOT_STOPPED"][value]);
+ "BOOT_STOPPED",
+ "CLEANUP_DELETE"][value]);
break;
case "IMAGE":
case "image":
diff --git a/src/tm/TransferManager.cc b/src/tm/TransferManager.cc
index 712ded9e8c..d23c7fe2ee 100644
--- a/src/tm/TransferManager.cc
+++ b/src/tm/TransferManager.cc
@@ -115,6 +115,10 @@ void TransferManager::trigger(Actions action, int _vid)
aname = "EPILOG_DELETE_PREVIOUS";
break;
+ case EPILOG_DELETE_BOTH:
+ aname = "EPILOG_DELETE_BOTH";
+ break;
+
case CHECKPOINT:
aname = "CHECKPOINT";
break;
@@ -183,6 +187,10 @@ void TransferManager::do_action(const string &action, void * arg)
{
epilog_delete_previous_action(vid);
}
+ else if (action == "EPILOG_DELETE_BOTH")
+ {
+ epilog_delete_both_action(vid);
+ }
else if (action == "CHECKPOINT")
{
checkpoint_action(vid);
@@ -1195,61 +1203,74 @@ error_common:
return;
}
+
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
-void TransferManager::epilog_delete_action(bool local, int vid)
+int TransferManager::epilog_delete_commands(VirtualMachine *vm,
+ ostream& xfr,
+ bool local,
+ bool previous)
{
- ofstream xfr;
ostringstream os;
- string xfr_name;
string vm_tm_mad;
string tm_mad;
string vm_ds_id;
string ds_id;
+ string host;
+ string system_dir;
+
int disk_id;
- VirtualMachine * vm;
- Nebula& nd = Nebula::instance();
-
- const TransferManagerDriver * tm_md;
+ Nebula& nd = Nebula::instance();
const VectorAttribute * disk;
vector attrs;
int num;
// ------------------------------------------------------------------------
- // Setup & Transfer script
+ // Setup transfer
// ------------------------------------------------------------------------
- vm = vmpool->get(vid,true);
-
- if (vm == 0)
- {
- return;
- }
-
if (!vm->hasHistory())
{
goto error_history;
}
- vm_tm_mad = vm->get_tm_mad();
- vm_ds_id = vm->get_ds_id();
- tm_md = get();
-
- if ( tm_md == 0 || vm_tm_mad.empty() || vm_ds_id.empty())
+ if (local)
{
- goto error_drivers;
+ host = nd.get_nebula_hostname();
+ system_dir = vm->get_system_dir();
+
+ vm_tm_mad = vm->get_tm_mad();
+ vm_ds_id = vm->get_ds_id();
+ }
+ else if (previous)
+ {
+ if (!vm->hasPreviousHistory())
+ {
+ goto error_history;
+ }
+
+ host = vm->get_previous_hostname();
+ system_dir = vm->get_remote_system_dir();
+
+ vm_tm_mad = vm->get_previous_tm_mad();
+ vm_ds_id = vm->get_previous_ds_id();
+ }
+ else
+ {
+ host = vm->get_hostname();
+ system_dir = vm->get_remote_system_dir();
+
+ vm_tm_mad = vm->get_tm_mad();
+ vm_ds_id = vm->get_ds_id();
}
- xfr_name = vm->get_transfer_file() + ".delete";
- xfr.open(xfr_name.c_str(), ios::out | ios::trunc);
-
- if (xfr.fail() == true)
+ if ( vm_tm_mad.empty() || vm_ds_id.empty())
{
- goto error_file;
+ goto error_drivers;
}
// -------------------------------------------------------------------------
@@ -1284,103 +1305,57 @@ void TransferManager::epilog_delete_action(bool local, int vid)
}
}
- if ( local )
- {
- //DELETE tm_mad fe:system_dir/disk.i vmid dsid
- xfr << "DELETE "
- << tm_mad << " "
- << nd.get_nebula_hostname() << ":"
- << vm->get_system_dir() << "/disk." << disk_id << " "
- << vm->get_oid() << " "
- << ds_id << endl;
- }
- else
- {
- //DELETE tm_mad host:remote_system_dir/disk.i vmid dsid
- xfr << "DELETE "
- << tm_mad << " "
- << vm->get_hostname() << ":"
- << vm->get_remote_system_dir() << "/disk." << disk_id << " "
- << vm->get_oid() << " "
- << ds_id << endl;
- }
- }
-
- if ( local )
- {
- //DELETE vm_tm_mad fe:system_dir vmid dsid(=0)
+ //DELETE tm_mad host:remote_system_dir/disk.i vmid dsid
+ // *local* DELETE tm_mad fe:system_dir/disk.i vmid dsid
+ // *prev* DELETE tm_mad prev_host:remote_system_dir/disk.i vmid ds_id
xfr << "DELETE "
- << vm_tm_mad << " "
- << nd.get_nebula_hostname() <<":"<< vm->get_system_dir() << " "
+ << tm_mad << " "
+ << host << ":"
+ << system_dir << "/disk." << disk_id << " "
<< vm->get_oid() << " "
- << vm_ds_id;
- }
- else
- {
- //DELETE vm_tm_mad hostname:remote_system_dir vmid dsid(=0)
- xfr << "DELETE "
- << vm_tm_mad << " "
- << vm->get_hostname() <<":"<< vm->get_remote_system_dir() << " "
- << vm->get_oid() << " "
- << vm_ds_id;
+ << ds_id << endl;
}
- xfr.close();
+ //DELETE vm_tm_mad hostname:remote_system_dir vmid dsid
+ // *local* DELETE vm_tm_mad fe:system_dir vmid dsid
+ // *prev* DELTE vm_tm_mad prev_host:remote_system_dir vmid ds_id
+ xfr << "DELETE "
+ << vm_tm_mad << " "
+ << host <<":"<< system_dir << " "
+ << vm->get_oid() << " "
+ << vm_ds_id << endl;
- tm_md->transfer(vid,xfr_name);
-
- vm->unlock();
- return;
+ return 0;
error_history:
- os.str("");
- os << "epilog_delete, VM " << vid << " has no history";
+ os << "epilog_delete, VM " << vm->get_oid() << " missing history record";
goto error_common;
error_drivers:
- os.str("");
os << "epilog_delete, error getting drivers.";
goto error_common;
-error_file:
- os.str("");
- os << "epilog_delete, could not open file: " << xfr_name;
- os << ". You may need to manually clean " << vm->get_hostname()
- << ":" << vm->get_remote_system_dir();
- goto error_common;
-
error_common:
vm->log("TM", Log::ERROR, os);
- (nd.get_lcm())->trigger(LifeCycleManager::EPILOG_FAILURE,vid);
-
- vm->unlock();
- return;
+ return -1;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
-void TransferManager::epilog_delete_previous_action(int vid)
+void TransferManager::epilog_delete_action(bool local, int vid)
{
- ofstream xfr;
ostringstream os;
- string xfr_name;
- string vm_tm_mad;
- string tm_mad;
- string vm_ds_id;
- string ds_id;
-
- int disk_id;
+ ofstream xfr;
+ string xfr_name;
VirtualMachine * vm;
Nebula& nd = Nebula::instance();
const TransferManagerDriver * tm_md;
- const VectorAttribute * disk;
- vector attrs;
- int num;
+ int rc;
// ------------------------------------------------------------------------
// Setup & Transfer script
@@ -1392,18 +1367,84 @@ void TransferManager::epilog_delete_previous_action(int vid)
return;
}
- if (!vm->hasHistory() || !vm->hasPreviousHistory())
+ tm_md = get();
+
+ if ( tm_md == 0 )
{
- goto error_history;
+ goto error_driver;
}
- vm_tm_mad = vm->get_previous_tm_mad();
- vm_ds_id = vm->get_previous_ds_id();
- tm_md = get();
+ xfr_name = vm->get_transfer_file() + ".delete";
+ xfr.open(xfr_name.c_str(), ios::out | ios::trunc);
- if ( tm_md == 0 || vm_tm_mad.empty() || vm_ds_id.empty() )
+ if (xfr.fail() == true)
{
- goto error_drivers;
+ goto error_file;
+ }
+
+ rc = epilog_delete_commands(vm, xfr, local, false);
+
+ if ( rc != 0 )
+ {
+ goto error_common;
+ }
+
+ xfr.close();
+
+ tm_md->transfer(vid,xfr_name);
+
+ vm->unlock();
+ return;
+
+error_driver:
+ os << "epilog_delete, error getting TM driver.";
+ goto error_common;
+
+error_file:
+ os << "epilog_delete, could not open file: " << xfr_name;
+ os << ". You may need to manually clean the host (current)";
+ goto error_common;
+
+error_common:
+ vm->log("TM", Log::ERROR, os);
+ (nd.get_lcm())->trigger(LifeCycleManager::EPILOG_FAILURE, vid);
+
+ vm->unlock();
+ return;
+}
+
+/* -------------------------------------------------------------------------- */
+/* -------------------------------------------------------------------------- */
+
+void TransferManager::epilog_delete_previous_action(int vid)
+{
+ ostringstream os;
+
+ ofstream xfr;
+ string xfr_name;
+
+ VirtualMachine * vm;
+ Nebula& nd = Nebula::instance();
+
+ const TransferManagerDriver * tm_md;
+
+ int rc;
+
+ // ------------------------------------------------------------------------
+ // Setup & Transfer script
+ // ------------------------------------------------------------------------
+ vm = vmpool->get(vid,true);
+
+ if (vm == 0)
+ {
+ return;
+ }
+
+ tm_md = get();
+
+ if (tm_md == 0)
+ {
+ goto error_driver;
}
xfr_name = vm->get_transfer_file() + ".delete_prev";
@@ -1414,81 +1455,106 @@ void TransferManager::epilog_delete_previous_action(int vid)
goto error_file;
}
- // ------------------------------------------------------------------------
- // Delete the remote VM Directory
- // ------------------------------------------------------------------------
- num = vm->get_template_attribute("DISK",attrs);
+ rc = epilog_delete_commands(vm, xfr, false, true);
- for (int i=0 ; i < num ; i++)
+ if ( rc != 0 )
{
- disk = dynamic_cast(attrs[i]);
-
- if ( disk == 0 )
- {
- continue;
- }
-
- disk->vector_value_str("DISK_ID", disk_id);
-
- if ( isVolatile(disk) == true )
- {
- tm_mad = vm_tm_mad;
- ds_id = vm_ds_id;
- }
- else
- {
- tm_mad = disk->vector_value("TM_MAD");
- ds_id = disk->vector_value("DATASTORE_ID");
-
- if ( tm_mad.empty() || ds_id.empty() )
- {
- continue;
- }
- }
-
- //DELETE tm_mad prev_host:remote_system_dir/disk.i vmid ds_id
- xfr << "DELETE "
- << tm_mad << " "
- << vm->get_previous_hostname() << ":"
- << vm->get_remote_system_dir() << "/disk." << disk_id << " "
- << vm->get_oid() << " "
- << ds_id << endl;
+ goto error_common;
}
- //DELTE vm_tm_mad prev_host:remote_system_dir vmid ds_id(=0)
- xfr << "DELETE "
- << vm_tm_mad << " "
- << vm->get_previous_hostname() <<":"<< vm->get_remote_system_dir()
- << " " << vm->get_oid() << " "
- << vm_ds_id << endl;
-
xfr.close();
- tm_md->transfer(vid,xfr_name);
+ tm_md->transfer(vid, xfr_name);
vm->unlock();
return;
-error_history:
- os.str("");
- os << "epilog_delete_previous, VM " << vid << " has no history";
- goto error_common;
-
-error_drivers:
- os.str("");
- os << "epilog_delete_previous, error getting drivers.";
+error_driver:
+ os << "epilog_delete_previous, error getting TM driver.";
goto error_common;
error_file:
- os.str("");
os << "epilog_delete_previous, could not open file: " << xfr_name;
- os << ". You may need to manually clean " << vm->get_previous_hostname()
- << ":" << vm->get_remote_system_dir();
+ os << ". You may need to manually clean the host (previous)";
goto error_common;
error_common:
- (nd.get_lcm())->trigger(LifeCycleManager::EPILOG_FAILURE,vid);
vm->log("TM", Log::ERROR, os);
+ (nd.get_lcm())->trigger(LifeCycleManager::EPILOG_FAILURE, vid);
+
+ vm->unlock();
+ return;
+}
+
+/* -------------------------------------------------------------------------- */
+/* -------------------------------------------------------------------------- */
+
+void TransferManager::epilog_delete_both_action(int vid)
+{
+ ostringstream os;
+
+ ofstream xfr;
+ string xfr_name;
+
+ VirtualMachine * vm;
+ Nebula& nd = Nebula::instance();
+
+ const TransferManagerDriver * tm_md;
+
+ int rc;
+
+ // ------------------------------------------------------------------------
+ // Setup & Transfer script
+ // ------------------------------------------------------------------------
+ vm = vmpool->get(vid,true);
+
+ if (vm == 0)
+ {
+ return;
+ }
+
+ tm_md = get();
+
+ if (tm_md == 0)
+ {
+ goto error_driver;
+ }
+
+ xfr_name = vm->get_transfer_file() + ".delete_both";
+ xfr.open(xfr_name.c_str(),ios::out | ios::trunc);
+
+ if (xfr.fail() == true)
+ {
+ goto error_file;
+ }
+
+ rc = epilog_delete_commands(vm, xfr, false, false); //current
+ rc = epilog_delete_commands(vm, xfr, false, true); //previous
+
+ if ( rc != 0 )
+ {
+ goto error_common;
+ }
+
+ xfr.close();
+
+ tm_md->transfer(vid, xfr_name);
+
+ vm->unlock();
+ return;
+
+error_driver:
+ os << "epilog_delete_both, error getting TM driver.";
+ goto error_common;
+
+error_file:
+ os << "epilog_delete_both, could not open file: " << xfr_name;
+ os << ". You may need to manually clean hosts (previous & current)";
+ goto error_common;
+
+error_common:
+ vm->log("TM", Log::ERROR, os);
+ (nd.get_lcm())->trigger(LifeCycleManager::EPILOG_FAILURE, vid);
vm->unlock();
return;
diff --git a/src/tm/TransferManagerDriver.cc b/src/tm/TransferManagerDriver.cc
index dbabe4e9da..6d4faff184 100644
--- a/src/tm/TransferManagerDriver.cc
+++ b/src/tm/TransferManagerDriver.cc
@@ -127,7 +127,7 @@ void TransferManagerDriver::protocol(
case VirtualMachine::EPILOG:
case VirtualMachine::EPILOG_STOP:
- case VirtualMachine::CLEANUP:
+ case VirtualMachine::CLEANUP_RESUBMIT:
lcm_action = LifeCycleManager::EPILOG_SUCCESS;
break;
@@ -164,7 +164,7 @@ void TransferManagerDriver::protocol(
case VirtualMachine::EPILOG:
case VirtualMachine::EPILOG_STOP:
- case VirtualMachine::CLEANUP:
+ case VirtualMachine::CLEANUP_RESUBMIT:
lcm_action = LifeCycleManager::EPILOG_FAILURE;
break;
diff --git a/src/vmm/VirtualMachineManager.cc b/src/vmm/VirtualMachineManager.cc
index e656c91ad8..8d9fc2601a 100644
--- a/src/vmm/VirtualMachineManager.cc
+++ b/src/vmm/VirtualMachineManager.cc
@@ -146,6 +146,18 @@ void VirtualMachineManager::trigger(Actions action, int _vid)
aname = "CANCEL_PREVIOUS";
break;
+ case CLEANUP:
+ aname = "CLEANUP";
+ break;
+
+ case CLEANUP_BOTH:
+ aname = "CLEANUP_BOTH";
+ break;
+
+ case CLEANUP_PREVIOUS:
+ aname = "CLEANUP_PREVIOUS";
+ break;
+
case MIGRATE:
aname = "MIGRATE";
break;
@@ -234,6 +246,18 @@ void VirtualMachineManager::do_action(const string &action, void * arg)
{
cancel_previous_action(vid);
}
+ else if (action == "CLEANUP")
+ {
+ cleanup_action(vid, false);
+ }
+ else if (action == "CLEANUP_BOTH")
+ {
+ cleanup_action(vid, true);
+ }
+ else if (action == "CLEANUP_PREVIOUS")
+ {
+ cleanup_previous_action(vid);
+ }
else if (action == "MIGRATE")
{
migrate_action(vid);
@@ -925,6 +949,183 @@ error_common:
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
+void VirtualMachineManager::cleanup_action(
+ int vid, bool cancel_previous)
+{
+ int rc;
+
+ VirtualMachine * vm;
+ ostringstream os;
+
+ string vm_tmpl;
+ string * drv_msg;
+
+ string m_hostname = "";
+ string m_net_drv = "";
+
+ const VirtualMachineManagerDriver * vmd;
+
+ Nebula& nd = Nebula::instance();
+
+ // 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;
+ }
+
+ if ( cancel_previous && vm->hasPreviousHistory() )
+ {
+ m_hostname = vm->get_previous_hostname();
+ m_net_drv = vm->get_previous_vnm_mad();
+ }
+
+ rc = nd.get_tm()->epilog_delete_commands(vm, os, false, false);
+
+ if ( rc != 0 )
+ {
+ goto error_common;
+ }
+
+ // Invoke driver method
+ drv_msg = format_message(
+ vm->get_hostname(),
+ vm->get_vnm_mad(),
+ m_hostname,
+ m_net_drv,
+ vm->get_deploy_id(),
+ "",
+ "",
+ "",
+ os.str(),
+ "",
+ vm->to_xml(vm_tmpl));
+
+ vmd->cleanup(vid, *drv_msg);
+
+ delete drv_msg;
+
+ vm->unlock();
+
+ return;
+
+error_history:
+ os.str("");
+ os << "cleanup_action, VM has no history";
+ goto error_common;
+
+error_driver:
+ os.str("");
+ os << "cleanup_action, error getting driver " << vm->get_vmm_mad();
+
+error_common:
+ (nd.get_lcm())->trigger(LifeCycleManager::CLEANUP_FAILURE, vid);
+
+ vm->unlock();
+ return;
+}
+
+/* -------------------------------------------------------------------------- */
+/* -------------------------------------------------------------------------- */
+
+void VirtualMachineManager::cleanup_previous_action(
+ int vid)
+{
+ int rc;
+
+ VirtualMachine * vm;
+ ostringstream os;
+
+ string vm_tmpl;
+ string * drv_msg;
+
+ const VirtualMachineManagerDriver * vmd;
+
+ Nebula& nd = Nebula::instance();
+
+ // Get the VM from the pool
+ vm = vmpool->get(vid,true);
+
+ if (vm == 0)
+ {
+ return;
+ }
+
+ if (!vm->hasHistory() || !vm->hasPreviousHistory())
+ {
+ goto error_history;
+ }
+
+ // Get the driver for this VM
+ vmd = get(vm->get_vmm_mad());
+
+ if ( vmd == 0 )
+ {
+ goto error_driver;
+ }
+
+ rc = nd.get_tm()->epilog_delete_commands(vm, os, false, true);
+
+ if ( rc != 0 )
+ {
+ goto error_common;
+ }
+
+ // Invoke driver method
+ drv_msg = format_message(
+ vm->get_previous_hostname(),
+ vm->get_previous_vnm_mad(),
+ "",
+ "",
+ vm->get_deploy_id(),
+ "",
+ "",
+ "",
+ os.str(),
+ "",
+ vm->to_xml(vm_tmpl));
+
+ vmd->cleanup(vid, *drv_msg);
+
+ delete drv_msg;
+
+ vm->unlock();
+
+ return;
+
+error_history:
+ os.str("");
+ os << "cleanup_previous_action, VM has no history";
+ goto error_common;
+
+error_driver:
+ os.str("");
+ os << "cleanup_previous_action, error getting driver " << vm->get_vmm_mad();
+
+error_common:
+ (nd.get_lcm())->trigger(LifeCycleManager::CLEANUP_FAILURE, vid);
+
+ vm->unlock();
+ return;
+}
+
+/* -------------------------------------------------------------------------- */
+/* -------------------------------------------------------------------------- */
+
void VirtualMachineManager::migrate_action(
int vid)
{
@@ -1366,7 +1567,7 @@ void VirtualMachineManager::attach_action(
vm_tm_mad = vm->get_tm_mad();
opennebula_hostname = nd.get_nebula_hostname();
- rc = Nebula::instance().get_tm()->prolog_transfer_command(
+ rc = nd.get_tm()->prolog_transfer_command(
vm,
disk,
vm_tm_mad,
diff --git a/src/vmm/VirtualMachineManagerDriver.cc b/src/vmm/VirtualMachineManagerDriver.cc
index 89cfd80b2d..e189f6506b 100644
--- a/src/vmm/VirtualMachineManagerDriver.cc
+++ b/src/vmm/VirtualMachineManagerDriver.cc
@@ -106,8 +106,8 @@ void VirtualMachineManagerDriver::get_default(
/* Helpers for the protocol function */
/* -------------------------------------------------------------------------- */
-static void log_error(VirtualMachine* vm,
- ostringstream& os,
+static void log_error(VirtualMachine* vm,
+ ostringstream& os,
istringstream& is,
const char * msg)
{
@@ -186,8 +186,7 @@ void VirtualMachineManagerDriver::protocol(
return;
}
- if ( vm->get_lcm_state() == VirtualMachine::CLEANUP ||
- vm->get_lcm_state() == VirtualMachine::FAILURE ||
+ if ( vm->get_lcm_state() == VirtualMachine::FAILURE ||
vm->get_lcm_state() == VirtualMachine::LCM_INIT )
{
os.str("");
@@ -373,6 +372,25 @@ void VirtualMachineManagerDriver::protocol(
lcm->trigger(LifeCycleManager::DETACH_FAILURE, id);
}
}
+ else if ( action == "CLEANUP" )
+ {
+ Nebula &ne = Nebula::instance();
+ LifeCycleManager *lcm = ne.get_lcm();
+
+ if ( result == "SUCCESS" )
+ {
+ vm->log("VMM", Log::ERROR, "Host Successfully cleaned.");
+
+ lcm->trigger(LifeCycleManager::CLEANUP_SUCCESS, id);
+ }
+ else
+ {
+ log_error(vm, os, is, "Error cleaning Host");
+ vmpool->update(vm);
+
+ lcm->trigger(LifeCycleManager::CLEANUP_FAILURE, id);
+ }
+ }
else if ( action == "POLL" )
{
if (result == "SUCCESS")
diff --git a/src/vmm_mad/dummy/one_vmm_dummy.rb b/src/vmm_mad/dummy/one_vmm_dummy.rb
index 6ada53fcfc..731186150d 100755
--- a/src/vmm_mad/dummy/one_vmm_dummy.rb
+++ b/src/vmm_mad/dummy/one_vmm_dummy.rb
@@ -128,6 +128,12 @@ class DummyDriver < VirtualMachineDriver
send_message(ACTION[:detach_disk],result,id)
end
+ def cleanup(id, drv_message)
+ result = retrieve_result("cleanup")
+
+ send_message(ACTION[:cleanup],result,id)
+ end
+
def poll(id, drv_message)
result = retrieve_result("poll")
@@ -159,13 +165,33 @@ class DummyDriver < VirtualMachineDriver
"#{POLL_ATTRIBUTE[:nettx]}=#{prev_nettx+(50*rand(3))} " \
"#{POLL_ATTRIBUTE[:netrx]}=#{prev_netrx+(100*rand(4))} " \
"#{POLL_ATTRIBUTE[:usedmemory]}=#{max_memory * (rand(80)+20)/100} " \
- "#{POLL_ATTRIBUTE[:usedcpu]}=#{max_cpu * (rand(95)+5)/100}"
+ "#{POLL_ATTRIBUTE[:usedcpu]}=#{max_cpu * (rand(95)+5)/100}"
send_message(ACTION[:poll],result,id,monitor_info)
end
private
+ # Retrives the result for a given action from the OpenNebula core. Each
+ # action has a defined set of responses in:
+ # /tmp/opennebula_dummy_actions/
+ #
+ # Each line of this file represents a response in the form:
+ # <"sucess|0" | "failure|1" | "-"> [sleep]
+ #
+ # - success or 1 returns SUCCESS
+ # - failure o 0 returns FAILURE
+ # - "-" returns nothing
+ # - sleep optional number of seconds to wait before answering
+ #
+ # Example: /tmp/opennebula_dummy_actions/deploy
+ # 0
+ # 0
+ # 1 120
+ # 1
+ # -
+ # 0
+ #
def retrieve_result(action)
begin
actions = File.read(DUMMY_ACTIONS_DIR+"/#{action}")
@@ -178,20 +204,28 @@ class DummyDriver < VirtualMachineDriver
action_id %= actions_array.size
if actions_array && actions_array[action_id]
- result = actions_array[action_id]
- if result == "success" || result == 0 || result == "0"
- return RESULT[:success]
- else
- return RESULT[:failure]
- end
@actions_counter[action] += 1
+
+ result = actions_array[action_id].split
+
+ case result[0]
+ when "success", 1, "1"
+ sleep result[1].to_i if result[1]
+ return RESULT[:success]
+ when "failure", 0, "0"
+ sleep result[1].to_i if result[1]
+ return RESULT[:failure]
+ when "-"
+ return nil
+ else
+ return RESULT[:success]
+ end
else
return RESULT[:success]
end
-
end
end
dd = DummyDriver.new
-dd.start_driver
\ No newline at end of file
+dd.start_driver
diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb
index 8c6f8ccacb..fae1a08c4f 100755
--- a/src/vmm_mad/exec/one_vmm_exec.rb
+++ b/src/vmm_mad/exec/one_vmm_exec.rb
@@ -185,7 +185,12 @@ class VmmAction
@vmm.log(@id,
"Failed to execute #{DRIVER_NAMES[step[:driver]]} " \
"operation: #{step[:action]}.")
- break
+
+ if step[:no_fail]
+ result = DriverExecHelper::RESULT[:success]
+ else
+ break
+ end
else
@vmm.log(@id,
"Successfully execute #{DRIVER_NAMES[step[:driver]]} " \
@@ -537,7 +542,7 @@ class ExecDriver < VirtualMachineDriver
# Bug #1355, argument character limitation in ESX
# Message not used in vmware anyway
if @hypervisor == "vmware"
- drv_message = "drv_message"
+ drv_message = "drv_message"
end
steps = [
@@ -603,6 +608,72 @@ class ExecDriver < VirtualMachineDriver
action.run(steps)
end
+ #
+ # CLEANUP action, frees resources allocated in a host: VM and disk images
+ #
+ def cleanup(id, drv_message)
+ aname = ACTION[:cleanup]
+ xml_data = decode(drv_message)
+
+ tm_command = xml_data.elements['TM_COMMAND'].text
+ mhost = xml_data.elements['MIGR_HOST'].text
+ deploy_id = xml_data.elements['DEPLOY_ID'].text
+
+ action = VmmAction.new(self, id, :cleanup, drv_message)
+ steps = Array.new
+
+ # Cancel the VM at host (only if we have a valid deploy-id)
+ if deploy_id && !deploy_id.empty?
+ steps <<
+ {
+ :driver => :vmm,
+ :action => :cancel,
+ :parameters => [:deploy_id, :host],
+ :no_fail => true
+ }
+ steps <<
+ {
+ :driver => :vnm,
+ :action => :clean,
+ :no_fail => true
+ }
+ end
+
+ # Cancel the VM at the previous host (in case of migration)
+ if mhost && !mhost.empty?
+ steps <<
+ {
+ :driver => :vmm,
+ :action => :cancel,
+ :parameters => [:deploy_id, :dest_host],
+ :destination => true,
+ :no_fail => true
+ }
+ steps <<
+ {
+ :driver => :vnm,
+ :action => :clean,
+ :destination => true,
+ :no_fail => true
+ }
+ end
+
+ # Cleans VM disk images and directory
+ tm_command.each_line { |tc|
+ tc.strip!
+
+ steps <<
+ {
+ :driver => :tm,
+ :action => :tm_delete,
+ :parameters => tc.split,
+ :no_fail => true
+ } if !tc.empty?
+ } if tm_command
+
+ action.run(steps)
+ end
+
private
def ensure_xpath(xml_data, id, action, xpath)