1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-22 13:33:52 +03:00

Bug #3168: process attributes in update --append

This commit is contained in:
Carlos Martín 2014-10-20 16:05:44 +02:00
parent 2669f57e98
commit 930c13ae76
8 changed files with 85 additions and 146 deletions

View File

@ -163,17 +163,6 @@ public:
VectorAttribute * disk,
const vector<string>& inherit_attrs);
/**
* Replace template for this object. Object should be updated
* after calling this method
* @param tmpl_str new contents
* @param keep_restricted If true, the restricted attributes of the
* current template will override the new template
* @param error string describing the error if any
* @return 0 on success
*/
int replace_template(const string& tmpl_str, bool keep_restricted, string& error);
/**
* Set monitor information for the Datastore
* @param total_mb
@ -336,6 +325,14 @@ private:
}
int set_tm_mad(string &tm_mad, string &error_str);
/**
* Child classes can process the new template set with replace_template or
* append_template with this method
* @param error string describing the error if any
* @return 0 on success
*/
int post_update_template(string& error);
};
#endif /*DATASTORE_H_*/

View File

@ -692,6 +692,17 @@ protected:
*/
virtual void set_template_error_message(const string& name, const string& message);
/**
* Child classes can process the new template set with replace_template or
* append_template with this method
* @param error string describing the error if any
* @return 0 on success
*/
virtual int post_update_template(string& error)
{
return 0;
};
/**
* The object's unique ID
*/

View File

@ -370,17 +370,6 @@ public:
string& to_xml_extended(string& xml, const vector<int>& vms,
const vector<int>& vnets) const;
/**
* Replace the template of the virtual network it also updates the BRIDGE,
* PHY_DEV, VLAN_ID and VLAN attributes.
* @param tmpl_str new contents
* @param keep_restricted If true, the restricted attributes of the
* current template will override the new template
* @param error string describing the error if any
* @return 0 on success
*/
int replace_template(const string& tmpl_str, bool keep_restricted, string& error);
/**
* Gets a string based attribute (single) from an address range. If the
* attribute is not found in the address range, the VNET template will be
@ -494,6 +483,13 @@ private:
*/
int from_xml(const string &xml_str);
/**
* Updates the BRIDGE, PHY_DEV, VLAN_ID and VLAN attributes.
* @param error string describing the error if any
* @return 0 on success
*/
int post_update_template(string& error);
//**************************************************************************
// Constructor
//**************************************************************************

View File

@ -44,17 +44,6 @@ public:
*/
int from_xml(const string &xml_str);
/**
* Replace template for this object. Object should be updated
* after calling this method
* @param tmpl_str new contents
* @param keep_restricted If true, the restricted attributes of the
* current template will override the new template
* @param error string describing the error if any
* @return 0 on success
*/
int replace_template(const string& tmpl_str, bool keep_restricted, string& error);
private:
// -------------------------------------------------------------------------
@ -126,6 +115,14 @@ private:
{
return new Template;
}
/**
* Child classes can process the new template set with replace_template or
* append_template with this method
* @param error string describing the error if any
* @return 0 on success
*/
int post_update_template(string& error);
};
#endif /*ZONE_H_*/

View File

@ -581,11 +581,10 @@ int Datastore::from_xml(const string& xml)
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
int Datastore::replace_template(
const string& tmpl_str, bool keep_restricted, string& error_str)
int Datastore::post_update_template(string& error_str)
{
string new_ds_mad;
string new_tm_mad;
@ -596,38 +595,12 @@ int Datastore::replace_template(
Image::DiskType new_disk_type;
DatastoreType new_ds_type;
Template * new_tmpl = new DatastoreTemplate;
if ( new_tmpl == 0 )
{
error_str = "Cannot allocate a new template";
return -1;
}
if ( new_tmpl->parse_str_or_xml(tmpl_str, error_str) != 0 )
{
delete new_tmpl;
return -1;
}
if (keep_restricted)
{
new_tmpl->remove_restricted();
if (obj_template != 0)
{
obj_template->remove_all_except_restricted();
string aux_error;
new_tmpl->merge(obj_template, aux_error);
}
}
/* ---------------------------------------------------------------------- */
/* Set the TYPE of the Datastore (class & template) */
/* ---------------------------------------------------------------------- */
new_tmpl->get("TYPE", s_ds_type);
get_template_attribute("TYPE", s_ds_type);
if (!s_ds_type.empty())
{
@ -638,12 +611,6 @@ int Datastore::replace_template(
new_ds_type = type;
}
/* --- Update the Datastore template --- */
delete obj_template;
obj_template = new_tmpl;
/* ---------------------------------------------------------------------- */
/* Set the TYPE of the Datastore (class & template) */
/* ---------------------------------------------------------------------- */

View File

@ -170,7 +170,8 @@ void PoolObjectSQL::clear_template_error_message()
int PoolObjectSQL::replace_template(
const string& tmpl_str, bool keep_restricted, string& error)
{
Template * new_tmpl = get_new_template();
Template * old_tmpl = 0;
Template * new_tmpl = get_new_template();
if ( new_tmpl == 0 )
{
@ -184,6 +185,11 @@ int PoolObjectSQL::replace_template(
return -1;
}
if (obj_template != 0)
{
old_tmpl = new Template(*obj_template);
}
if (keep_restricted && new_tmpl->has_restricted())
{
new_tmpl->remove_restricted();
@ -201,6 +207,22 @@ int PoolObjectSQL::replace_template(
obj_template = new_tmpl;
if (post_update_template(error) == -1)
{
delete obj_template;
if (old_tmpl != 0)
{
obj_template = old_tmpl;
}
else
{
obj_template = 0;
}
return -1;
}
return 0;
}
@ -210,7 +232,8 @@ int PoolObjectSQL::replace_template(
int PoolObjectSQL::append_template(
const string& tmpl_str, bool keep_restricted, string& error)
{
Template * new_tmpl = get_new_template();
Template * old_tmpl = 0;
Template * new_tmpl = get_new_template();
if ( new_tmpl == 0 )
{
@ -231,6 +254,8 @@ int PoolObjectSQL::append_template(
if ( obj_template != 0 )
{
old_tmpl = new Template(*obj_template);
obj_template->merge(new_tmpl, error);
delete new_tmpl;
}
@ -239,6 +264,22 @@ int PoolObjectSQL::append_template(
obj_template = new_tmpl;
}
if (post_update_template(error) == -1)
{
delete obj_template;
if (old_tmpl != 0)
{
obj_template = old_tmpl;
}
else
{
obj_template = 0;
}
return -1;
}
return 0;
}

View File

@ -221,47 +221,11 @@ error_common:
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int VirtualNetwork::replace_template(
const string& tmpl_str, bool keep_restricted, string& error_str)
int VirtualNetwork::post_update_template(string& error)
{
string new_bridge;
bool b_vlan;
/* ---------------------------------------------------------------------- */
/* Parse & Update VirtualNetwork Template */
/* ---------------------------------------------------------------------- */
Template * new_tmpl = new VirtualNetworkTemplate;
if ( new_tmpl == 0 )
{
error_str = "Cannot allocate a new template";
return -1;
}
if ( new_tmpl->parse_str_or_xml(tmpl_str, error_str) != 0 )
{
delete new_tmpl;
return -1;
}
if (keep_restricted && is_reservation())
{
new_tmpl->remove_restricted();
if (obj_template != 0)
{
obj_template->remove_all_except_restricted();
string aux_error;
new_tmpl->merge(obj_template, aux_error);
}
}
delete obj_template;
obj_template = new_tmpl;
/* ---------------------------------------------------------------------- */
/* Update Configuration Attributes (class & template) */
/* - PHYDEV */

View File

@ -251,50 +251,16 @@ int Zone::from_xml(const string& xml)
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
int Zone::replace_template(const string& tmpl_str, bool keep_restricted, string& error_str)
int Zone::post_update_template(string& error)
{
Template * new_tmpl = get_new_template();
if ( new_tmpl == 0 )
{
error_str = "Cannot allocate a new template";
return -1;
}
if ( new_tmpl->parse_str_or_xml(tmpl_str, error_str) != 0 )
{
delete new_tmpl;
return -1;
}
if (keep_restricted)
{
new_tmpl->remove_restricted();
if (obj_template != 0)
{
obj_template->remove_all_except_restricted();
string aux_error;
new_tmpl->merge(obj_template, aux_error);
}
}
string new_endpoint;
new_tmpl->get("ENDPOINT", new_endpoint);
get_template_attribute("ENDPOINT", new_endpoint);
if (new_endpoint.empty())
{
new_tmpl->replace("ENDPOINT", "-");
replace_template_attribute("ENDPOINT", "-");
}
if ( obj_template != 0 )
{
delete obj_template;
}
obj_template = new_tmpl;
return 0;
}