mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-23 17:33:56 +03:00
(cherry picked from commit cdf1231f81
)
Conflicts:
src/cli/one_helper/onevnet_helper.rb
src/vnm/test/VirtualNetworkPoolTest.cc
This commit is contained in:
parent
7a11688738
commit
5f7cea8083
@ -208,6 +208,11 @@ private:
|
||||
*/
|
||||
string vlan_id;
|
||||
|
||||
/**
|
||||
* Whether or not to isolate this network with the vnm driver
|
||||
*/
|
||||
int vlan;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Virtual Network Description
|
||||
// -------------------------------------------------------------------------
|
||||
|
@ -56,6 +56,11 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
|
||||
puts str % ["USER", vn['UNAME']]
|
||||
puts str % ["GROUP", vn['GNAME']]
|
||||
puts str % ["PUBLIC", OpenNebulaHelper.boolean_to_str(vn['PUBLIC'])]
|
||||
puts str % ["TYPE", vn.type_str]
|
||||
puts str % ["BRIDGE", vn["BRIDGE"]]
|
||||
puts str % ["VLAN", OpenNebulaHelper.boolean_to_str(vn['VLAN'])]
|
||||
puts str % ["PHYSICAL DEVICE", vn["PHYDEV"]] if vn["PHYDEV"]
|
||||
puts str % ["VLAN ID", vn["VLAN_ID"]] if vn["VLAN_ID"]
|
||||
puts str % ["USED LEASES", vn['TOTAL_LEASES']]
|
||||
|
||||
puts
|
||||
|
@ -25,6 +25,8 @@
|
||||
|
||||
#include "AuthManager.h"
|
||||
|
||||
#define TO_UPPER(S) transform(S.begin(),S.end(),S.begin(),(int(*)(int))toupper)
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Virtual Network :: Constructor/Destructor */
|
||||
/* ************************************************************************** */
|
||||
@ -207,6 +209,7 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str)
|
||||
int rc;
|
||||
|
||||
string pub;
|
||||
string vlan_attr;
|
||||
string s_type;
|
||||
|
||||
unsigned int default_size = VirtualNetworkPool::default_size();
|
||||
@ -219,7 +222,7 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str)
|
||||
// ------------ TYPE ----------------------
|
||||
erase_template_attribute("TYPE",s_type);
|
||||
|
||||
transform(s_type.begin(),s_type.end(),s_type.begin(),(int(*)(int))toupper);
|
||||
TO_UPPER(s_type);
|
||||
|
||||
if (s_type == "RANGED")
|
||||
{
|
||||
@ -255,6 +258,14 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str)
|
||||
|
||||
erase_template_attribute("VLAN_ID",vlan_id);
|
||||
|
||||
// ------------ VLAN ----------------------
|
||||
|
||||
erase_template_attribute("VLAN", vlan_attr);
|
||||
|
||||
TO_UPPER(vlan_attr);
|
||||
|
||||
vlan = (vlan_attr == "YES");
|
||||
|
||||
// ------------ BRIDGE --------------------
|
||||
|
||||
erase_template_attribute("BRIDGE",bridge);
|
||||
@ -272,7 +283,6 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str)
|
||||
oss << "onebr" << oid;
|
||||
|
||||
bridge = oss.str();
|
||||
replace_template_attribute("BRIDGE",bridge);
|
||||
}
|
||||
}
|
||||
|
||||
@ -280,7 +290,7 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str)
|
||||
|
||||
erase_template_attribute("PUBLIC", pub);
|
||||
|
||||
transform (pub.begin(), pub.end(), pub.begin(), (int(*)(int))toupper);
|
||||
TO_UPPER(pub);
|
||||
|
||||
public_obj = (pub == "YES");
|
||||
|
||||
@ -515,7 +525,8 @@ string& VirtualNetwork::to_xml_extended(string& xml, bool extended) const
|
||||
"<GNAME>" << gname << "</GNAME>" <<
|
||||
"<NAME>" << name << "</NAME>" <<
|
||||
"<TYPE>" << type << "</TYPE>" <<
|
||||
"<BRIDGE>" << bridge << "</BRIDGE>";
|
||||
"<BRIDGE>" << bridge << "</BRIDGE>"<<
|
||||
"<VLAN>" << vlan << "</VLAN>";
|
||||
|
||||
if (!phydev.empty())
|
||||
{
|
||||
@ -566,6 +577,7 @@ int VirtualNetwork::from_xml(const string &xml_str)
|
||||
rc += xpath(int_type, "/VNET/TYPE", -1);
|
||||
rc += xpath(bridge, "/VNET/BRIDGE", "not_found");
|
||||
rc += xpath(public_obj, "/VNET/PUBLIC", 0);
|
||||
rc += xpath(vlan, "/VNET/VLAN", 0);
|
||||
|
||||
xpath(phydev, "/VNET/PHYDEV", "");
|
||||
xpath(vlan_id, "/VNET/VLAN_ID","");
|
||||
@ -636,6 +648,15 @@ int VirtualNetwork::nic_attribute(VectorAttribute *nic, int vid)
|
||||
nic->replace("MAC" ,mac);
|
||||
nic->replace("IP" ,ip);
|
||||
|
||||
if ( vlan == 1 )
|
||||
{
|
||||
nic->replace("VLAN", "YES");
|
||||
}
|
||||
else
|
||||
{
|
||||
nic->replace("VLAN", "NO");
|
||||
}
|
||||
|
||||
if (!phydev.empty())
|
||||
{
|
||||
nic->replace("PHYDEV", phydev);
|
||||
|
@ -71,18 +71,18 @@ const string templates[] =
|
||||
|
||||
const string xmls[] =
|
||||
{
|
||||
"<VNET><ID>0</ID><UID>123</UID><GID>0</GID><UNAME>the_user</UNAME><GNAME>oneadmin</GNAME><NAME>Net number one</NAME><TYPE>1</TYPE><BRIDGE>br1</BRIDGE><PUBLIC>0</PUBLIC><TOTAL_LEASES>0</TOTAL_LEASES><TEMPLATE></TEMPLATE><LEASES><LEASE><IP>130.10.0.1</IP><MAC>50:20:20:20:20:20</MAC><USED>0</USED><VID>-1</VID></LEASE></LEASES></VNET>",
|
||||
"<VNET><ID>0</ID><UID>123</UID><GID>0</GID><UNAME>the_user</UNAME><GNAME>oneadmin</GNAME><NAME>Net number one</NAME><TYPE>1</TYPE><BRIDGE>br1</BRIDGE><VLAN>0</VLAN><PUBLIC>0</PUBLIC><TOTAL_LEASES>0</TOTAL_LEASES><TEMPLATE></TEMPLATE><LEASES><LEASE><IP>130.10.0.1</IP><MAC>50:20:20:20:20:20</MAC><USED>0</USED><VID>-1</VID></LEASE></LEASES></VNET>",
|
||||
|
||||
"<VNET><ID>1</ID><UID>261</UID><GID>0</GID><UNAME>the_user</UNAME><GNAME>oneadmin</GNAME><NAME>A virtual network</NAME><TYPE>0</TYPE><BRIDGE>br0</BRIDGE><PUBLIC>1</PUBLIC><TOTAL_LEASES>0</TOTAL_LEASES><TEMPLATE><NETWORK_ADDRESS><![CDATA[192.168.0.0]]></NETWORK_ADDRESS><NETWORK_SIZE><![CDATA[C]]></NETWORK_SIZE></TEMPLATE><LEASES></LEASES></VNET>",
|
||||
"<VNET><ID>1</ID><UID>261</UID><GID>0</GID><UNAME>the_user</UNAME><GNAME>oneadmin</GNAME><NAME>A virtual network</NAME><TYPE>0</TYPE><BRIDGE>br0</BRIDGE><VLAN>0</VLAN><PUBLIC>1</PUBLIC><TOTAL_LEASES>0</TOTAL_LEASES><TEMPLATE><NETWORK_ADDRESS><![CDATA[192.168.0.0]]></NETWORK_ADDRESS><NETWORK_SIZE><![CDATA[C]]></NETWORK_SIZE></TEMPLATE><LEASES></LEASES></VNET>",
|
||||
|
||||
"<VNET><ID>0</ID><UID>133</UID><GID>0</GID><UNAME>the_user</UNAME><GNAME>oneadmin</GNAME><NAME>Net number two</NAME><TYPE>1</TYPE><BRIDGE>br1</BRIDGE><PUBLIC>0</PUBLIC><TOTAL_LEASES>0</TOTAL_LEASES><TEMPLATE></TEMPLATE><LEASES><LEASE><IP>130.10.2.1</IP><MAC>50:20:20:20:20:20</MAC><USED>0</USED><VID>-1</VID></LEASE></LEASES></VNET>",
|
||||
"<VNET><ID>0</ID><UID>133</UID><GID>0</GID><UNAME>the_user</UNAME><GNAME>oneadmin</GNAME><NAME>Net number two</NAME><TYPE>1</TYPE><BRIDGE>br1</BRIDGE><VLAN>0</VLAN><PUBLIC>0</PUBLIC><TOTAL_LEASES>0</TOTAL_LEASES><TEMPLATE></TEMPLATE><LEASES><LEASE><IP>130.10.2.1</IP><MAC>50:20:20:20:20:20</MAC><USED>0</USED><VID>-1</VID></LEASE></LEASES></VNET>",
|
||||
};
|
||||
|
||||
const string xml_dump =
|
||||
"<VNET_POOL><VNET><ID>0</ID><UID>1</UID><GID>0</GID><UNAME>the_user</UNAME><GNAME>oneadmin</GNAME><NAME>Net number one</NAME><TYPE>1</TYPE><BRIDGE>br1</BRIDGE><PUBLIC>0</PUBLIC><TOTAL_LEASES>0</TOTAL_LEASES><TEMPLATE></TEMPLATE></VNET><VNET><ID>1</ID><UID>2</UID><GID>0</GID><UNAME>the_user</UNAME><GNAME>oneadmin</GNAME><NAME>A virtual network</NAME><TYPE>0</TYPE><BRIDGE>br0</BRIDGE><PUBLIC>1</PUBLIC><TOTAL_LEASES>0</TOTAL_LEASES><TEMPLATE><NETWORK_ADDRESS><![CDATA[192.168.0.0]]></NETWORK_ADDRESS><NETWORK_SIZE><![CDATA[C]]></NETWORK_SIZE></TEMPLATE></VNET></VNET_POOL>";
|
||||
"<VNET_POOL><VNET><ID>0</ID><UID>1</UID><GID>0</GID><UNAME>the_user</UNAME><GNAME>oneadmin</GNAME><NAME>Net number one</NAME><TYPE>1</TYPE><BRIDGE>br1</BRIDGE><VLAN>0</VLAN><PUBLIC>0</PUBLIC><TOTAL_LEASES>0</TOTAL_LEASES><TEMPLATE></TEMPLATE></VNET><VNET><ID>1</ID><UID>2</UID><GID>0</GID><UNAME>the_user</UNAME><GNAME>oneadmin</GNAME><NAME>A virtual network</NAME><TYPE>0</TYPE><BRIDGE>br0</BRIDGE><VLAN>0</VLAN><PUBLIC>1</PUBLIC><TOTAL_LEASES>0</TOTAL_LEASES><TEMPLATE><NETWORK_ADDRESS><![CDATA[192.168.0.0]]></NETWORK_ADDRESS><NETWORK_SIZE><![CDATA[C]]></NETWORK_SIZE></TEMPLATE></VNET></VNET_POOL>";
|
||||
|
||||
const string xml_dump_where =
|
||||
"<VNET_POOL><VNET><ID>1</ID><UID>2</UID><GID>0</GID><UNAME>the_user</UNAME><GNAME>oneadmin</GNAME><NAME>A virtual network</NAME><TYPE>0</TYPE><BRIDGE>br0</BRIDGE><PUBLIC>1</PUBLIC><TOTAL_LEASES>0</TOTAL_LEASES><TEMPLATE><NETWORK_ADDRESS><![CDATA[192.168.0.0]]></NETWORK_ADDRESS><NETWORK_SIZE><![CDATA[C]]></NETWORK_SIZE></TEMPLATE></VNET></VNET_POOL>";
|
||||
"<VNET_POOL><VNET><ID>1</ID><UID>2</UID><GID>0</GID><UNAME>the_user</UNAME><GNAME>oneadmin</GNAME><NAME>A virtual network</NAME><TYPE>0</TYPE><BRIDGE>br0</BRIDGE><VLAN>0</VLAN><PUBLIC>1</PUBLIC><TOTAL_LEASES>0</TOTAL_LEASES><TEMPLATE><NETWORK_ADDRESS><![CDATA[192.168.0.0]]></NETWORK_ADDRESS><NETWORK_SIZE><![CDATA[C]]></NETWORK_SIZE></TEMPLATE></VNET></VNET_POOL>";
|
||||
|
||||
/* ************************************************************************* */
|
||||
/* ************************************************************************* */
|
||||
@ -310,8 +310,8 @@ public:
|
||||
};
|
||||
|
||||
string phydev_xml[] = {
|
||||
"<VNET><ID>0</ID><UID>0</UID><GID>0</GID><UNAME>the_user</UNAME><GNAME>oneadmin</GNAME><NAME>BRIDGE and PHYDEV</NAME><TYPE>1</TYPE><BRIDGE>br0</BRIDGE><PHYDEV>eth0</PHYDEV><PUBLIC>0</PUBLIC><TOTAL_LEASES>0</TOTAL_LEASES><TEMPLATE></TEMPLATE><LEASES><LEASE><IP>130.10.0.1</IP><MAC>50:20:20:20:20:20</MAC><USED>0</USED><VID>-1</VID></LEASE></LEASES></VNET>",
|
||||
"<VNET><ID>1</ID><UID>0</UID><GID>0</GID><UNAME>the_user</UNAME><GNAME>oneadmin</GNAME><NAME>No BRIDGE only PHYDEV</NAME><TYPE>1</TYPE><BRIDGE>onebr1</BRIDGE><PHYDEV>eth0</PHYDEV><PUBLIC>0</PUBLIC><TOTAL_LEASES>0</TOTAL_LEASES><TEMPLATE><BRIDGE><![CDATA[onebr1]]></BRIDGE></TEMPLATE><LEASES><LEASE><IP>130.10.0.1</IP><MAC>50:20:20:20:20:20</MAC><USED>0</USED><VID>-1</VID></LEASE></LEASES></VNET>"
|
||||
"<VNET><ID>0</ID><UID>0</UID><GID>0</GID><UNAME>the_user</UNAME><GNAME>oneadmin</GNAME><NAME>BRIDGE and PHYDEV</NAME><TYPE>1</TYPE><BRIDGE>br0</BRIDGE><VLAN>0</VLAN><PHYDEV>eth0</PHYDEV><PUBLIC>0</PUBLIC><TOTAL_LEASES>0</TOTAL_LEASES><TEMPLATE></TEMPLATE><LEASES><LEASE><IP>130.10.0.1</IP><MAC>50:20:20:20:20:20</MAC><USED>0</USED><VID>-1</VID></LEASE></LEASES></VNET>",
|
||||
"<VNET><ID>1</ID><UID>0</UID><GID>0</GID><UNAME>the_user</UNAME><GNAME>oneadmin</GNAME><NAME>No BRIDGE only PHYDEV</NAME><TYPE>1</TYPE><BRIDGE>onebr1</BRIDGE><VLAN>0</VLAN><PHYDEV>eth0</PHYDEV><PUBLIC>0</PUBLIC><TOTAL_LEASES>0</TOTAL_LEASES><TEMPLATE></TEMPLATE><LEASES><LEASE><IP>130.10.0.1</IP><MAC>50:20:20:20:20:20</MAC><USED>0</USED><VID>-1</VID></LEASE></LEASES></VNET>"
|
||||
};
|
||||
|
||||
// test vm with bridge and phydev
|
||||
|
Loading…
Reference in New Issue
Block a user