1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-30 22:50:10 +03:00

Bug #4376: Make vlan_id_automatic a top level attribute

and only allow modification of vlan_id if vlan_id_automatic
is set to false (the vlan_id has been specified manually)
This commit is contained in:
Jaime Melis 2016-04-19 15:22:17 +02:00
parent 5bd27d089d
commit f1b56ed322
4 changed files with 47 additions and 19 deletions

View File

@ -539,6 +539,11 @@ private:
*/
string vlan_id;
/**
* If the VLAN has been set automatically
*/
bool vlan_id_automatic;
/**
* Parent VNET ID if any
*/

View File

@ -77,9 +77,9 @@ public:
/**
* Drops a Virtual Network and the associated VLAN_ID if needed
*/
int drop(VirtualNetwork * vn, string& error_msg)
int drop(PoolObjectSQL * vn, string& error_msg)
{
release_vlan_id(vn);
release_vlan_id(static_cast<VirtualNetwork *>(vn));
return PoolSQL::drop(vn, error_msg);
};

View File

@ -45,6 +45,7 @@ VirtualNetwork::VirtualNetwork(int _uid,
PoolObjectSQL(-1,NET,"",_uid,_gid,_uname,_gname,table),
Clusterable(_cluster_ids),
bridge(""),
vlan_id_automatic(false),
parent_vid(_pvid),
vrouters("VROUTERS")
{
@ -146,6 +147,8 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str)
erase_template_attribute("VLAN_ID", vlan_id);
add_template_attribute("VLAN_ID", vlan_id);
vlan_id_automatic = false;
}
// ------------ BRIDGE --------------------
@ -276,9 +279,11 @@ int VirtualNetwork::post_update_template(string& error)
add_template_attribute("PHYDEV", phydev);
erase_template_attribute("VLAN_ID", vlan_id);
add_template_attribute("VLAN_ID", vlan_id);
if (!vlan_id_automatic)
{
erase_template_attribute("VLAN_ID", vlan_id);
add_template_attribute("VLAN_ID", vlan_id);
}
erase_template_attribute("BRIDGE",new_bridge);
@ -415,6 +420,8 @@ string& VirtualNetwork::to_xml_extended(string& xml, bool extended,
string leases_xml;
string perm_str;
int int_vlan_id_automatic = vlan_id_automatic ? 1 : 0;
os <<
"<VNET>" <<
"<ID>" << oid << "</ID>" <<
@ -457,10 +464,13 @@ string& VirtualNetwork::to_xml_extended(string& xml, bool extended,
if (!vlan_id.empty())
{
os << "<VLAN_ID>" << one_util::escape_xml(vlan_id) << "</VLAN_ID>";
os << "<VLAN_ID_AUTOMATIC>" << int_vlan_id_automatic
<<"</VLAN_ID_AUTOMATIC>";
}
else
{
os << "<VLAN_ID/>";
os << "<VLAN_ID_AUTOMATIC/>";
}
os << "<USED_LEASES>"<< ar_pool.get_used_addr() << "</USED_LEASES>";
@ -486,6 +496,7 @@ int VirtualNetwork::from_xml(const string &xml_str)
vector<xmlNodePtr> content;
int rc = 0;
int int_vlan_id_automatic;
// Initialize the internal XML object
update_from_str(xml_str);
@ -506,6 +517,9 @@ int VirtualNetwork::from_xml(const string &xml_str)
xpath(phydev, "/VNET/PHYDEV", "");
xpath(vlan_id,"/VNET/VLAN_ID","");
xpath(parent_vid,"/VNET/PARENT_NETWORK_ID",-1);
xpath(int_vlan_id_automatic,"/VNET/VLAN_ID_AUTOMATIC",0);
vlan_id_automatic = int_vlan_id_automatic;
// Set of cluster IDs
rc += Clusterable::from_xml(this, "/VNET/");

View File

@ -382,17 +382,19 @@ int VirtualNetworkPool::set_vlan_id(VirtualNetwork * vn)
unsigned int start_vlan, hint_vlan;
unsigned int vlan_id;
if ( vn->PoolObjectSQL::get_template_attribute("VLAN_ID", vlan_id) )
ostringstream oss;
if ( !vn->vlan_id.empty() )
{
return 0;
}
if ( !vn->PoolObjectSQL::get_template_attribute("VN_MAD", vn_mad) )
if ( vn->vn_mad.empty() )
{
return 0;
}
switch (VirtualNetwork::str_to_driver(vn_mad))
switch (VirtualNetwork::str_to_driver(vn->vn_mad))
{
case VirtualNetwork::VXLAN:
if (vxlan_conf.vector_value("START", start_vlan) != 0)
@ -401,8 +403,11 @@ int VirtualNetworkPool::set_vlan_id(VirtualNetwork * vn)
}
vlan_id = start_vlan + vn->get_oid();
oss << vlan_id;
vn->add_template_attribute("VLAN_ID", vlan_id);
vn->vlan_id = oss.str();
vn->vlan_id_automatic = true;
update(vn);
@ -411,15 +416,17 @@ int VirtualNetworkPool::set_vlan_id(VirtualNetwork * vn)
case VirtualNetwork::VLAN:
case VirtualNetwork::OVSWITCH:
start_vlan = vlan_id_bitmap.get_start_bit();
hint_vlan = start_vlan + (vn->get_oid() % (4095 -start_vlan ));
hint_vlan = start_vlan + (vn->get_oid() % (4095 - start_vlan ));
if ( vlan_id_bitmap.get(hint_vlan, vlan_id) != 0 )
{
return -1;
}
vn->add_template_attribute("VLAN_ID", vlan_id);
vn->add_template_attribute("VLAN_ID_AUTOMATIC", true);
oss << vlan_id;
vn->vlan_id = oss.str();
vn->vlan_id_automatic = true;
vlan_id_bitmap.update(db);
@ -439,27 +446,29 @@ int VirtualNetworkPool::set_vlan_id(VirtualNetwork * vn)
void VirtualNetworkPool::release_vlan_id(VirtualNetwork *vn)
{
string vn_mad;
istringstream is;
unsigned int vlan_id;
bool vlan_auto;
if ( !vn->PoolObjectSQL::get_template_attribute("VLAN_ID_AUTOMATIC",
vlan_auto) || vlan_auto == false )
if ( !vn->vlan_id_automatic )
{
return;
}
if ( !vn->PoolObjectSQL::get_template_attribute("VLAN_ID", vlan_id) )
if ( vn->vlan_id.empty() )
{
return;
}
if ( !vn->PoolObjectSQL::get_template_attribute("VN_MAD", vn_mad) )
if ( vn->vn_mad.empty() )
{
return;
}
switch (VirtualNetwork::str_to_driver(vn_mad))
is.str(vn->vlan_id);
is >> vlan_id;
switch (VirtualNetwork::str_to_driver(vn->vn_mad))
{
case VirtualNetwork::VLAN:
case VirtualNetwork::OVSWITCH: