B #8214: Do not clear ETHx_* context variables on NIC detach if NETWORK is not YES

When a NIC is detached, its ETHx_* variables are removed from the VM CONTEXT
whatever the value of NETWORK is. With NETWORK=NO, OpenNebula does not generate
those variables: they are defined by the user, and nothing generates them back
when the NIC is attached again. Guests that read their network configuration
from the CONTEXT at every boot lose their network.

Only clear them when NETWORK=YES, the same condition generate_network_context()
uses to decide whether OpenNebula manages them.

Signed-off-by: Mickaël Canévet <mickael.canevet@proton.ch>
(cherry picked from commit 6e4694de9365e8275301249c20acdeef0e8d34fe)
This commit is contained in:
Mickaël Canévet authored and Ruben S. Montero committed 2026-11-02 12:41:42 +01:00
1 parent b199f51021
commit dfd6b3da7e
3 files changed
+31 -3

No files matched your search

+1 -1
View File
@@ -1460,7 +1460,7 @@ CommandParser::CmdParser.new(ARGV) do
RAW = ["DATA", "TYPE", "VALIDATE"]
CPU_MODEL = ["MODEL", "FEATURES"]
BACKUP_CONFIG = ["FS_FREEZE", "KEEP_LAST", "BACKUP_VOLATILE", "MODE", "INCREMENT_MODE", "INTERACTIVE"]
CONTEXT (any value, ETH* if CONTEXT_ALLOW_ETH_UPDATES set in oned.conf, **variable substitution will be made**)
CONTEXT (any value, ETH* if NETWORK is not YES or CONTEXT_ALLOW_ETH_UPDATES set in oned.conf, **variable substitution will be made**)
EOT
command :updateconf, updateconf_desc, :vmid, [:file, nil],
+15
View File
@@ -3281,6 +3281,21 @@ int VirtualMachine::updateconf(VirtualMachineTemplate* tmpl, string &err,
}
else if ( context_bck != 0 && context_new != 0 )
{
bool network_context;
// In append mode an omitted NETWORK retains its current value.
if (append && context_new->value().count("NETWORK") == 0)
{
context_bck->vector_value("NETWORK", network_context);
}
else
{
context_new->vector_value("NETWORK", network_context);
}
// ETH* values are user-managed when network context is disabled.
allow_eth_updates = allow_eth_updates || !network_context;
context_new = context_new->clone();
// Remove equal values from the new context
+15 -2
View File
@@ -888,11 +888,24 @@ static void clear_context_network(const std::vector<ContextVariable>& cvars,
/* -------------------------------------------------------------------------- */
// The ETHx_* variables are only generated (and so only owned) by OpenNebula when
// NETWORK=YES. Otherwise they are defined by the user and must not be removed.
static bool network_context_enabled(const VectorAttribute * context)
{
bool net_context;
context->vector_value("NETWORK", net_context);
return net_context;
}
/* -------------------------------------------------------------------------- */
void VirtualMachine::clear_nic_context(int nicid)
{
VectorAttribute * context = obj_template->get("CONTEXT");
if (context == 0)
if (context == 0 || !network_context_enabled(context))
{
return;
}
@@ -926,7 +939,7 @@ void VirtualMachine::clear_nic_alias_context(int nicid, int aliasidx)
{
VectorAttribute * context = obj_template->get("CONTEXT");
if (context == 0)
if (context == 0 || !network_context_enabled(context))
{
return;
}