1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-31 17:17:40 +03:00

F #1548: Fixed bug and added post_update_template

This commit is contained in:
juanmont 2018-05-11 16:31:00 +02:00 committed by Ruben S. Montero
parent 00b3c96d68
commit ee0127327d
6 changed files with 62 additions and 8 deletions

View File

@ -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;
}

View File

@ -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:
//**************************************************************************

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);
}
/* ------------------------------------------------------------------------ */