From dfd6b3da7e53bb4ed67cd52ebed3f7b6cde1384b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Can=C3=A9vet?= Date: Wed, 21 Oct 2026 16:37:40 +0200 Subject: [PATCH] B #8214: Do not clear ETHx_* context variables on NIC detach if NETWORK is not YES MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 (cherry picked from commit 6e4694de9365e8275301249c20acdeef0e8d34fe) --- src/cli/onevm | 2 +- src/vm/VirtualMachine.cc | 15 +++++++++++++++ src/vm/VirtualMachineContext.cc | 17 +++++++++++++++-- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/cli/onevm b/src/cli/onevm index a29e3e53f1..c3161ffe72 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -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], diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 642c4792c4..9b2c5c4a80 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -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 diff --git a/src/vm/VirtualMachineContext.cc b/src/vm/VirtualMachineContext.cc index 4f3e67f2fe..c5aed4ffbd 100644 --- a/src/vm/VirtualMachineContext.cc +++ b/src/vm/VirtualMachineContext.cc @@ -888,11 +888,24 @@ static void clear_context_network(const std::vector& 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; }