From 961820cf332df1bba3ad47eb95d3995528f3dd10 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Mon, 11 Apr 2011 00:59:59 +0200 Subject: [PATCH] feature #487: Get rid of merge method for VirtualMachineTemplates --- include/VirtualMachineTemplate.h | 56 -------------------------------- src/rm/RequestManagerAllocate.cc | 32 ++++++++++++------ 2 files changed, 22 insertions(+), 66 deletions(-) diff --git a/include/VirtualMachineTemplate.h b/include/VirtualMachineTemplate.h index dec8d84852..c19fbdf171 100644 --- a/include/VirtualMachineTemplate.h +++ b/include/VirtualMachineTemplate.h @@ -36,64 +36,8 @@ public: VirtualMachineTemplate(VirtualMachineTemplate& vmt):Template(vmt){}; - /** - * Copies the attributes of the original template into this one. - * @param original Original template - * @param error_msg error string, must be freed by the calling funtion. - * This string is null if no error occurred. - */ - int merge(const VirtualMachineTemplate * original, char **error_msg) - { - int rc; - - *error_msg = 0; - - rc = merge_att(original, "TEMPLATE_ID"); - - if( rc != 0 ) - { - goto error_tid; - } - - merge_att(original, "NAME"); - return 0; - - error_tid: - *error_msg = strdup("TEMPLATE_ID attribute not found"); - return -1; - }; - private: friend class VirtualMachine; - - int merge_att(const VirtualMachineTemplate * original, const char * name) - { - vector attrs; - SingleAttribute * sattr; - const SingleAttribute * original_attr; - int number; - - string att_name = name; - - number = original->get(att_name,attrs); - - if( number == 0 ) - { - return -1; - } - - original_attr = dynamic_cast(attrs[0]); - - if ( original_attr != 0 ) - { - erase(att_name); - - sattr = new SingleAttribute(*original_attr); - set(sattr); - } - - return 0; - }; }; /* -------------------------------------------------------------------------- */ diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index b0cdf9c80c..2de7a853ac 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -30,7 +30,7 @@ void RequestManager::VirtualMachineAllocate::execute( string str_template; string error_str; string user_name; - string att_name; + string template_id_str = "TEMPLATE_ID";; const string method_name = "VirtualMachineAllocate"; @@ -87,12 +87,14 @@ void RequestManager::VirtualMachineAllocate::execute( //-------------------------------------------------------------------------- // Look for a template id //-------------------------------------------------------------------------- - att_name = "TEMPLATE_ID"; - using_template_pool = vm_template->get(att_name, tid); + using_template_pool = vm_template->get(template_id_str, tid); if( using_template_pool ) { - // Get the registered template + string name_str = "NAME"; + string name_val; + ostringstream template_id_val; + registered_template = VirtualMachineAllocate::tpool->get(tid, true); if( registered_template == 0 ) @@ -107,15 +109,25 @@ void RequestManager::VirtualMachineAllocate::execute( registered_template->unlock(); - rc = vm_template_aux->merge(vm_template, &error_msg); + // Set NAME & TEMPLATE_ID for the new template + vm_template->get(name_str,name_val); + + if ( !name_val.empty() ) + { + vm_template_aux->erase(name_str); + vm_template_aux->set(new SingleAttribute(name_str,name_val)); + } + + vm_template_aux->erase(template_id_str); + + template_id_val << tid; + + vm_template_aux->set(new + SingleAttribute(template_id_str,template_id_val.str())); delete vm_template; - vm_template = vm_template_aux; - if ( rc != 0 ) - { - goto error_parse; - } + vm_template = vm_template_aux; } if ( uid != 0 )