diff --git a/include/ScheduledAction.h b/include/ScheduledAction.h index cc6d69db30..0738170a77 100644 --- a/include/ScheduledAction.h +++ b/include/ScheduledAction.h @@ -93,9 +93,10 @@ public: * This function parse and checks the sched action attributes: REPEAT, DAYS * , END_TYPE, END_DATE. It also removed DONE and MESSAGE. * @param error + * @param clean indicates if the user wants to remove DONE and MESSAGE * @return 0 if success -1 otherwise */ - int parse(std::string& error); + int parse(std::string& error, bool clean); /** * @return true if the action needs to be executed. @@ -139,13 +140,14 @@ public: /** * Parse the ScheduleActions of a template * @param error + * @param clean indicates if the user wants to remove DONE and MESSAGE * @return -1 in case of error 0 otherwise */ - int parse(std::string& error) + int parse(std::string& error, bool clean) { for ( schedaction_iterator action = begin(); action != end(); ++action) { - if ( (*action)->parse(error) == -1 ) + if ( (*action)->parse(error, clean) == -1 ) { return -1; } diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index c3883c1df9..965e027fff 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -2052,6 +2052,19 @@ private: */ int parse_public_clouds(const char *name, string& error); + /** + * Child classes can process the new template set with replace_template or + * append_template with this method + * @param error string describing the error if any + * @return 0 on success + */ + int post_update_template(string& error); + + /** + * This method removes sched_action DONE/MESSAGE attributes + */ + int parse_sched_action(string& error_str); + protected: //************************************************************************** diff --git a/src/scheduler/src/sched/Scheduler.cc b/src/scheduler/src/sched/Scheduler.cc index 6b58e31cb4..ea91508674 100644 --- a/src/scheduler/src/sched/Scheduler.cc +++ b/src/scheduler/src/sched/Scheduler.cc @@ -1444,7 +1444,7 @@ int Scheduler::do_scheduled_actions() NebulaLog::log("VM", Log::INFO, oss); } - if ( sas->empty() != 0 ) //Do not update VMs without SCHED_ACTION + if ( !sas->empty() ) //Do not update VMs without SCHED_ACTION { vmpool->update(vm); } diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index a7c26e3806..7a0ed2442e 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -31,6 +31,7 @@ #include "NebulaLog.h" #include "NebulaUtil.h" #include "Snapshots.h" +#include "ScheduledAction.h" #include "Nebula.h" @@ -2302,6 +2303,13 @@ int VirtualMachine::replace_template( return -1; } + if (post_update_template(error) == -1) + { + delete user_obj_template; + + return -1; + } + delete user_obj_template; user_obj_template = new_tmpl; @@ -2356,6 +2364,13 @@ int VirtualMachine::append_template( user_obj_template = new_tmpl; } + if (post_update_template(error) == -1) + { + delete user_obj_template; + + return -1; + } + return 0; } @@ -3079,3 +3094,24 @@ void VirtualMachine::release_vmgroup() vmgrouppool->del_vm(thegroup, get_oid()); } +int VirtualMachine::parse_sched_action(string& error_str) +{ + SchedActions sactions(user_obj_template); + + return sactions.parse(error_str, false); +} + +/* ------------------------------------------------------------------------ */ +/* ------------------------------------------------------------------------ */ + +int VirtualMachine::post_update_template(string& error) +{ + int rc = parse_sched_action(error); + if (rc == -1) + { + return rc; + } + + return 0; +} + diff --git a/src/vm_template/ScheduledAction.cc b/src/vm_template/ScheduledAction.cc index 29d04b067e..a85f653b83 100644 --- a/src/vm_template/ScheduledAction.cc +++ b/src/vm_template/ScheduledAction.cc @@ -201,7 +201,7 @@ bool SchedAction::ends_in_range(EndOn eo, std::string& error) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int SchedAction::parse(std::string& error) +int SchedAction::parse(std::string& error, bool clean) { Repeat r; EndOn eo; @@ -228,8 +228,11 @@ int SchedAction::parse(std::string& error) return -1; } - remove("DONE"); - remove("MESSAGE"); + if (clean) + { + remove("DONE"); + remove("MESSAGE"); + } return 0; } diff --git a/src/vm_template/VMTemplate.cc b/src/vm_template/VMTemplate.cc index 52880cc47f..50c0867a75 100644 --- a/src/vm_template/VMTemplate.cc +++ b/src/vm_template/VMTemplate.cc @@ -175,7 +175,7 @@ int VMTemplate::parse_sched_action(string& error_str) { SchedActions sactions(obj_template); - return sactions.parse(error_str); + return sactions.parse(error_str, true); } /* ------------------------------------------------------------------------ */