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

Features #487: VMTemplate code refactor, now it uses base class PoolObjectSQL's obj_template

This commit is contained in:
Carlos Martín 2011-04-08 16:34:40 +02:00
parent fdcca8a0fc
commit 995159994d
2 changed files with 8 additions and 96 deletions

View File

@ -84,95 +84,12 @@ public:
string xml_str;
VirtualMachineTemplate * new_template = new VirtualMachineTemplate();
template_contents->to_xml(xml_str);
obj_template->to_xml(xml_str);
new_template->from_xml(xml_str);
return new_template;
};
/**
* Gets the values of a template attribute
* @param name of the attribute
* @param values of the attribute
* @return the number of values
*/
int get_template_attribute(
string& name,
vector<const Attribute*>& values) const
{
return template_contents->get(name,values);
};
/**
* Gets the values of a template attribute
* @param name of the attribute
* @param values of the attribute
* @return the number of values
*/
int get_template_attribute(
const char *name,
vector<const Attribute*>& values) const
{
string str=name;
return template_contents->get(str,values);
};
/**
* Gets a string based attribute
* @param name of the attribute
* @param value of the attribute (a string), will be "" if not defined
*/
void get_template_attribute(
const char * name,
string& value) const
{
string str=name;
template_contents->get(str,value);
};
/**
* Gets a string based attribute
* @param name of the attribute
* @param value of the attribute (an int), will be 0 if not defined
*/
void get_template_attribute(
const char * name,
int& value) const
{
string str=name;
template_contents->get(str,value);
};
/**
* Removes an attribute
* @param name of the attribute
*/
int remove_template_attribute(const string& name)
{
return template_contents->erase(name);
};
/**
* Adds a new attribute to the template (replacing it if
* already defined), the object's mutex SHOULD be locked
* @param name of the new attribute
* @param value of the new attribute
* @return 0 on success
*/
int replace_template_attribute(
const string& name,
const string& value)
{
SingleAttribute * sattr;
template_contents->erase(name);
sattr = new SingleAttribute(name,value);
template_contents->set(sattr);
return 0;
};
private:
// -------------------------------------------------------------------------
// Friends
@ -189,11 +106,6 @@ private:
*/
string user_name;
/**
* The Virtual Machine template, holds the VM attributes.
*/
VirtualMachineTemplate* template_contents;
/**
* Public scope of the VMTemplate
*/

View File

@ -33,11 +33,11 @@ VMTemplate::VMTemplate(int id,
{
if (_template_contents != 0)
{
template_contents = _template_contents;
obj_template = _template_contents;
}
else
{
template_contents = new VirtualMachineTemplate;
obj_template = new VirtualMachineTemplate;
}
}
@ -46,9 +46,9 @@ VMTemplate::VMTemplate(int id,
VMTemplate::~VMTemplate()
{
if ( template_contents != 0 )
if ( obj_template != 0 )
{
delete template_contents;
delete obj_template;
}
}
@ -91,7 +91,7 @@ int VMTemplate::insert(SqlDB *db, string& error_str)
// ------------ PUBLIC --------------------
get_template_attribute("PUBLIC", public_attr);
template_contents->erase("PUBLIC");
obj_template->erase("PUBLIC");
TO_UPPER(public_attr);
@ -199,7 +199,7 @@ string& VMTemplate::to_xml(string& xml) const
<< "<NAME>" << name << "</NAME>"
<< "<PUBLIC>" << public_template << "</PUBLIC>"
<< "<REGTIME>" << regtime << "</REGTIME>"
<< template_contents->to_xml(template_xml)
<< obj_template->to_xml(template_xml)
<< "</VMTEMPLATE>";
xml = oss.str();
@ -235,7 +235,7 @@ int VMTemplate::from_xml(const string& xml)
}
// Template contents
rc += template_contents->from_xml_node(content[0]);
rc += obj_template->from_xml_node(content[0]);
if (rc != 0)
{