From d097340199bb07363d728b3cbe15d0d856579fd8 Mon Sep 17 00:00:00 2001 From: juanmont Date: Tue, 18 Jul 2017 11:04:27 +0200 Subject: [PATCH 1/2] F #5015 Added new parser for sched_action --- include/VMTemplate.h | 32 ++++++++++++++++++++++++++++++++ src/vm_template/VMTemplate.cc | 13 +++++++++++++ 2 files changed, 45 insertions(+) diff --git a/include/VMTemplate.h b/include/VMTemplate.h index 78962c439f..44e2e460bf 100644 --- a/include/VMTemplate.h +++ b/include/VMTemplate.h @@ -102,6 +102,31 @@ public: obj_template->set(disks); } + /** + * This method check if sched_action is malformed or not + * + * @return false if the attribute is malformed + */ + bool parse_sched_action() + { + bool malformed = false; + string action = ""; + VectorAttribute *attr = nullptr; + vector _sched_actions; + obj_template->get("SCHED_ACTION",_sched_actions); + + for (vector::const_iterator i = _sched_actions.begin(); + i != _sched_actions.end() && !malformed ; ++i) + { + attr = new VectorAttribute(*i); + if ( attr->vector_value("DONE") != "" || attr->vector_value("MESSAGE") != "" ) + { + malformed = true; + } + } + return !malformed; + } + // ------------------------------------------------------------------------ // Virtual Router // ------------------------------------------------------------------------ @@ -141,6 +166,13 @@ private: */ int insert_replace(SqlDB *db, bool replace, string& error_str); + /** + * Execute this method after update the template. + * @param error Returns the error reason, if any + * @return 0 one success + */ + int post_update_template(string& error); + /** * Bootstraps the database table(s) associated to the VMTemplate * @return 0 on success diff --git a/src/vm_template/VMTemplate.cc b/src/vm_template/VMTemplate.cc index e07821f653..7459eb4706 100644 --- a/src/vm_template/VMTemplate.cc +++ b/src/vm_template/VMTemplate.cc @@ -167,6 +167,19 @@ error_common: return -1; } +/* ------------------------------------------------------------------------ */ +/* ------------------------------------------------------------------------ */ + +int VMTemplate::post_update_template(string& error) +{ + if ( !parse_sched_action() ) + { + error = "Error parsing sched_action, malformed."; + return -1; + } + return 0; +} + /* ************************************************************************ */ /* VMTemplate :: Misc */ /* ************************************************************************ */ From 508112fbffdc22b622bba33fe2ac23d58b7f7886 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Wed, 19 Jul 2017 11:27:57 +0200 Subject: [PATCH 2/2] F #5015: Add sched_action parse to insert --- include/VMTemplate.h | 30 +++++------------------------- src/vm_template/VMTemplate.cc | 28 +++++++++++++++++++++------- 2 files changed, 26 insertions(+), 32 deletions(-) diff --git a/include/VMTemplate.h b/include/VMTemplate.h index 44e2e460bf..59bb387d33 100644 --- a/include/VMTemplate.h +++ b/include/VMTemplate.h @@ -102,31 +102,6 @@ public: obj_template->set(disks); } - /** - * This method check if sched_action is malformed or not - * - * @return false if the attribute is malformed - */ - bool parse_sched_action() - { - bool malformed = false; - string action = ""; - VectorAttribute *attr = nullptr; - vector _sched_actions; - obj_template->get("SCHED_ACTION",_sched_actions); - - for (vector::const_iterator i = _sched_actions.begin(); - i != _sched_actions.end() && !malformed ; ++i) - { - attr = new VectorAttribute(*i); - if ( attr->vector_value("DONE") != "" || attr->vector_value("MESSAGE") != "" ) - { - malformed = true; - } - } - return !malformed; - } - // ------------------------------------------------------------------------ // Virtual Router // ------------------------------------------------------------------------ @@ -192,6 +167,11 @@ private: */ int from_xml(const string &xml_str); + /** + * This method removes sched_action DONE/MESSAGE attributes + */ + void parse_sched_action(); + protected: // ************************************************************************* diff --git a/src/vm_template/VMTemplate.cc b/src/vm_template/VMTemplate.cc index 7459eb4706..23d9a7317d 100644 --- a/src/vm_template/VMTemplate.cc +++ b/src/vm_template/VMTemplate.cc @@ -74,13 +74,16 @@ int VMTemplate::insert(SqlDB *db, string& error_str) // --------------------------------------------------------------------- // Check default attributes // --------------------------------------------------------------------- - erase_template_attribute("NAME", name); + // --------------------------------------------------------------------- + // Remove DONE/MESSAGE from SCHED_ACTION + // --------------------------------------------------------------------- + parse_sched_action(); + // ------------------------------------------------------------------------ // Insert the Template // ------------------------------------------------------------------------ - return insert_replace(db, false, error_str); } @@ -167,16 +170,27 @@ error_common: return -1; } +void VMTemplate::parse_sched_action() +{ + vector _sched_actions; + vector::iterator i; + + get_template_attribute("SCHED_ACTION", _sched_actions); + + for ( i = _sched_actions.begin(); i != _sched_actions.end() ; ++i) + { + (*i)->remove("DONE"); + (*i)->remove("MESSAGE"); + } +} + /* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */ int VMTemplate::post_update_template(string& error) { - if ( !parse_sched_action() ) - { - error = "Error parsing sched_action, malformed."; - return -1; - } + parse_sched_action(); + return 0; }