mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-11 05:17:41 +03:00
feature #2465: virtualnetwork can update VLAN, VLAN_ID, BRIDGE and PHYDEV configuration attributes
This commit is contained in:
parent
253d75ef0b
commit
a759d95c59
@ -210,6 +210,13 @@ public:
|
||||
int vid,
|
||||
const vector<string>& inherit_attrs);
|
||||
|
||||
/**
|
||||
* Replace the template of the virtual network it also updates the BRIDGE,
|
||||
* PHY_DEV, VLAN_ID and VLAN attributes.
|
||||
* @param tmpl string representation of the template
|
||||
*/
|
||||
int replace_template(const string& tmpl_str, string& error);
|
||||
|
||||
private:
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
@ -183,10 +183,7 @@ int PoolObjectSQL::replace_template(const string& tmpl_str, string& error)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( obj_template != 0 )
|
||||
{
|
||||
delete obj_template;
|
||||
}
|
||||
delete obj_template;
|
||||
|
||||
obj_template = new_tmpl;
|
||||
|
||||
|
@ -184,7 +184,7 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str)
|
||||
ostringstream ose;
|
||||
int rc;
|
||||
|
||||
string vlan_attr;
|
||||
bool b_vlan;
|
||||
string s_type;
|
||||
string ranged_error_str;
|
||||
|
||||
@ -227,19 +227,30 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str)
|
||||
|
||||
// ------------ PHYDEV --------------------
|
||||
|
||||
erase_template_attribute("PHYDEV",phydev);
|
||||
erase_template_attribute("PHYDEV", phydev);
|
||||
|
||||
add_template_attribute("PHYDEV", phydev);
|
||||
|
||||
// ------------ VLAN_ID -------------------
|
||||
|
||||
erase_template_attribute("VLAN_ID",vlan_id);
|
||||
erase_template_attribute("VLAN_ID", vlan_id);
|
||||
|
||||
add_template_attribute("VLAN_ID", vlan_id);
|
||||
|
||||
// ------------ VLAN ----------------------
|
||||
|
||||
erase_template_attribute("VLAN", vlan_attr);
|
||||
erase_template_attribute("VLAN", b_vlan);
|
||||
|
||||
TO_UPPER(vlan_attr);
|
||||
|
||||
vlan = (vlan_attr == "YES") || (vlan_attr.empty() && !phydev.empty());
|
||||
if (b_vlan || !phydev.empty())
|
||||
{
|
||||
vlan = 1;
|
||||
add_template_attribute("VLAN", "YES");
|
||||
}
|
||||
else
|
||||
{
|
||||
vlan = 0;
|
||||
add_template_attribute("VLAN", "NO");
|
||||
}
|
||||
|
||||
// ------------ BRIDGE --------------------
|
||||
|
||||
@ -270,6 +281,8 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str)
|
||||
}
|
||||
}
|
||||
|
||||
add_template_attribute("BRIDGE", bridge);
|
||||
|
||||
// ------------ IP6 PREFIX ---------------
|
||||
|
||||
erase_template_attribute("GLOBAL_PREFIX", global);
|
||||
@ -389,6 +402,76 @@ error_common:
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualNetwork::replace_template(const string& tmpl_str, string& error_str)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
delete obj_template;
|
||||
|
||||
obj_template = new_tmpl;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Update Configuration Attributes (class & template) */
|
||||
/* - PHYDEV */
|
||||
/* - VLAN_ID */
|
||||
/* - VLAN */
|
||||
/* - BRIDGE */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
erase_template_attribute("PHYDEV", phydev);
|
||||
|
||||
add_template_attribute("PHYDEV", phydev);
|
||||
|
||||
erase_template_attribute("VLAN_ID", vlan_id);
|
||||
|
||||
add_template_attribute("VLAN_ID", vlan_id);
|
||||
|
||||
erase_template_attribute("VLAN", b_vlan);
|
||||
|
||||
if (b_vlan || !phydev.empty())
|
||||
{
|
||||
vlan = 1;
|
||||
add_template_attribute("VLAN", "YES");
|
||||
}
|
||||
else
|
||||
{
|
||||
vlan = 0;
|
||||
add_template_attribute("VLAN", "NO");
|
||||
}
|
||||
|
||||
erase_template_attribute("BRIDGE",new_bridge);
|
||||
|
||||
if (!new_bridge.empty())
|
||||
{
|
||||
bridge = new_bridge;
|
||||
}
|
||||
|
||||
add_template_attribute("BRIDGE", bridge);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualNetwork::insert_replace(SqlDB *db, bool replace, string& error_str)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
Loading…
Reference in New Issue
Block a user