1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-03 13:47:01 +03:00

F 6441: Introduce FLOATING_ONLY for Virtual Router

The new attribute does not allocate extra IPs on NICs with FLOATING_IP =
yes and FLOATING_ONLY = yes. The NIC will only containg a random MAC
address and VROUTER_IP/MAC.

This commit also checks that network mode auto is not used for NIC of a
VROUTER

(cherry picked from commit 18c781607428733cce55b3b42813f2fdc7d8004f)
This commit is contained in:
Ruben S. Montero 2023-12-22 19:41:08 +01:00
parent 5ae681d1ce
commit 0a7a03e098
No known key found for this signature in database
GPG Key ID: A0CEA6FA880A1D87
5 changed files with 54 additions and 1 deletions

View File

@ -178,6 +178,12 @@ public:
// Address allocation functions
// *************************************************************************
/**
* Generate a random L2 lease for a NIC, this address is not actually
* allocated in any AR
*/
static int allocate_random_addr(VectorAttribute *nic);
/**
* Returns an unused address, which becomes used and fills a NIC attribute
* with the configuration parameters from the address range.

View File

@ -129,6 +129,20 @@ public:
return name() == "PCI";
}
/**
* Check if NIC is from a Virtual Router and no other IP needs to be allocated
*/
bool is_floating_only() const
{
bool floating;
bool only;
int rc = vector_value("FLOATING_IP", floating);
rc += vector_value("FLOATING_ONLY", only);
return rc == 0 && floating && only;
}
/*
* Set nic NAME attribute if not empty, defaults to NAME = NIC${NIC_ID}
*/

View File

@ -1533,6 +1533,26 @@ void AddressRange::allocate_by_index(unsigned int index,
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int AddressRange::allocate_random_addr(VectorAttribute* nic)
{
unsigned int rmac[2];
rmac[1] = VirtualNetworkPool::mac_prefix();
rmac[0] = one_util::random<uint32_t>() & 0xFFFFFFFF;
nic->replace("MAC", mac_to_s(rmac));
nic->remove("IP");
nic->remove("IP6_LINK");
nic->remove("IP6_ULA");
nic->remove("IP6_GLOBAL");
return 0;
}
/* -------------------------------------------------------------------------- */
int AddressRange::allocate_addr(
PoolObjectSQL::ObjectType ot,
int obid,

View File

@ -1021,7 +1021,11 @@ int VirtualNetwork::nic_attribute(
return -1;
}
if (ip_ne == 1)
if (nic->is_floating_only())
{
rc = AddressRange::allocate_random_addr(nic->vector_attribute());
}
else if (ip_ne == 1)
{
rc = allocate_by_ip(PoolObjectSQL::VM, vid, ip, nic->vector_attribute(),
inherit_attrs);

View File

@ -204,6 +204,15 @@ int VirtualRouter::get_network_leases(string& estr) const
{
VirtualMachineNic nic(nics[i], i);
std::string net_mode = nic.vector_value("NETWORK_MODE");
one_util::toupper(net_mode);
if (net_mode == "AUTO")
{
estr = "Virtual Router is incompatible with auto mode";
return -1;
}
if (vnpool->nic_attribute(PoolObjectSQL::VROUTER, &nic, i, uid, oid,
estr) == -1)
{