mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-16 22:50:10 +03:00
feature #487: Get rid of merge method for VirtualMachineTemplates
This commit is contained in:
parent
e678b190ee
commit
961820cf33
@ -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<const Attribute *> 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<const SingleAttribute *>(attrs[0]);
|
||||
|
||||
if ( original_attr != 0 )
|
||||
{
|
||||
erase(att_name);
|
||||
|
||||
sattr = new SingleAttribute(*original_attr);
|
||||
set(sattr);
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -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 )
|
||||
|
Loading…
x
Reference in New Issue
Block a user