From 03b7b77ce8dccdd673aa6bef5a00ab58aa9aa4d0 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Tue, 26 Apr 2016 15:35:07 +0200 Subject: [PATCH] Merge monitor information for the VM (instead of recreating). Update Template.merge interface --- include/Template.h | 5 +---- include/VirtualMachineMonitorInfo.h | 14 ++++++++------ src/host/Host.cc | 4 +--- src/pool/PoolObjectSQL.cc | 6 +++--- src/rm/RequestManagerVMTemplate.cc | 7 +------ src/template/Template.cc | 4 +--- src/vm/VirtualMachine.cc | 5 ++--- 7 files changed, 17 insertions(+), 28 deletions(-) diff --git a/include/Template.h b/include/Template.h index 575e1fa1d5..a33f0e6ca2 100644 --- a/include/Template.h +++ b/include/Template.h @@ -394,11 +394,8 @@ public: * replacing the existing ones * * @param from_tmpl the template to be merged - * @param error_str string describing the error - * - * @return 0 on success. */ - int merge(const Template * from_tmpl, string& error_str); + void merge(const Template * from_tmpl); /** * Deletes all restricted attributes diff --git a/include/VirtualMachineMonitorInfo.h b/include/VirtualMachineMonitorInfo.h index 96fde9c12f..e2eeb6b224 100644 --- a/include/VirtualMachineMonitorInfo.h +++ b/include/VirtualMachineMonitorInfo.h @@ -41,20 +41,22 @@ public: */ int update(const string& monitor_data, string& error) { + VirtualMachineMonitorInfo new_info; + char * error_c = 0; - clear(); - - int rc = parse(monitor_data, &error_c); - - if (rc != 0) + if (new_info.parse(monitor_data, &error_c) != 0) { error = error_c; free(error_c); + + return -1; } - return rc; + merge(&new_info); + + return 0; }; char remove_state() diff --git a/src/host/Host.cc b/src/host/Host.cc index 536509f79d..b773c3c3a1 100644 --- a/src/host/Host.cc +++ b/src/host/Host.cc @@ -248,8 +248,6 @@ int Host::update_info(Template &tmpl, int vmid; float val; - string error_st; - ostringstream zombie; ostringstream wild; @@ -286,7 +284,7 @@ int Host::update_info(Template &tmpl, // Copy monitor, extract share info & update last_monitored and state // ------------------------------------------------------------------------- - obj_template->merge(&tmpl, error_st); + obj_template->merge(&tmpl); touch(true); diff --git a/src/pool/PoolObjectSQL.cc b/src/pool/PoolObjectSQL.cc index a96b1c8f3c..0e374df47c 100644 --- a/src/pool/PoolObjectSQL.cc +++ b/src/pool/PoolObjectSQL.cc @@ -200,8 +200,7 @@ int PoolObjectSQL::replace_template( { obj_template->remove_all_except_restricted(); - string aux_error; - new_tmpl->merge(obj_template, aux_error); + new_tmpl->merge(obj_template); } } @@ -260,7 +259,8 @@ int PoolObjectSQL::append_template( { old_tmpl = new Template(*obj_template); - obj_template->merge(new_tmpl, error); + obj_template->merge(new_tmpl); + delete new_tmpl; } else diff --git a/src/rm/RequestManagerVMTemplate.cc b/src/rm/RequestManagerVMTemplate.cc index eaec333ffe..a5b2282e9d 100644 --- a/src/rm/RequestManagerVMTemplate.cc +++ b/src/rm/RequestManagerVMTemplate.cc @@ -271,12 +271,7 @@ Request::ErrorCode VMTemplateInstantiate::merge( } } - rc = tmpl->merge(&uattrs, att.resp_msg); - - if ( rc != 0 ) - { - return INTERNAL; - } + tmpl->merge(&uattrs); return SUCCESS; } diff --git a/src/template/Template.cc b/src/template/Template.cc index e5025a9e5f..95da05119f 100644 --- a/src/template/Template.cc +++ b/src/template/Template.cc @@ -587,7 +587,7 @@ int Template::from_xml_node(const xmlNodePtr node) /* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */ -int Template::merge(const Template * from_tmpl, string& error_str) +void Template::merge(const Template * from_tmpl) { multimap::const_iterator it; @@ -600,8 +600,6 @@ int Template::merge(const Template * from_tmpl, string& error_str) { this->set(it->second->clone()); } - - return 0; } /* ------------------------------------------------------------------------ */ diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index d2495816d2..04051b788d 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -4166,8 +4166,7 @@ int VirtualMachine::replace_template( { user_obj_template->remove_all_except_restricted(); - string aux_error; - new_tmpl->merge(user_obj_template, aux_error); + new_tmpl->merge(user_obj_template); } } @@ -4208,7 +4207,7 @@ int VirtualMachine::append_template( if (user_obj_template != 0) { - user_obj_template->merge(new_tmpl, error); + user_obj_template->merge(new_tmpl); delete new_tmpl; } else