From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 568AF1FF185 for ; Mon, 4 Aug 2025 18:23:26 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 6E24D3696A; Mon, 4 Aug 2025 18:24:53 +0200 (CEST) From: Stefan Hanreich To: pbs-devel@lists.proxmox.com Date: Mon, 4 Aug 2025 18:24:38 +0200 Message-ID: <20250804162448.607184-5-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250804162448.607184-1-s.hanreich@proxmox.com> References: <20250804162448.607184-1-s.hanreich@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -1.194 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods KAM_MAILER 2 Automated Mailer Tag Left in Email RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RDNS_NONE 0.793 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record Subject: [pbs-devel] [PATCH proxmox v5 3/3] network-api: add rename_interfaces method X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" Used for batch renaming interfaces in the /e/n/i configuration file by the proxmox-network-interface-pinning tool. Signed-off-by: Stefan Hanreich --- proxmox-network-api/src/config/mod.rs | 80 +++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/proxmox-network-api/src/config/mod.rs b/proxmox-network-api/src/config/mod.rs index e8cb81d1..bc80fb8d 100644 --- a/proxmox-network-api/src/config/mod.rs +++ b/proxmox-network-api/src/config/mod.rs @@ -267,6 +267,86 @@ impl NetworkConfig { Ok(interface) } + fn map_interface_name(iface_name: String, mapping: &HashMap) -> String { + if let Some(mapping) = mapping.get(&iface_name) { + return mapping.clone(); + } + + if let (Some(name), Some(id)) = ( + parse_vlan_raw_device_from_name(&iface_name), + parse_vlan_id_from_name(&iface_name), + ) { + if let Some(mapping) = mapping.get(name) { + return format!("{mapping}.{id}"); + } + } + + iface_name + } + + fn handle_interface(mut interface: Interface, mapping: &HashMap) -> Interface { + interface.bridge_ports = interface.bridge_ports.map(|bridge_ports| { + bridge_ports + .into_iter() + .map(|interface| Self::map_interface_name(interface, mapping)) + .collect::>() + }); + + interface.vlan_raw_device = interface + .vlan_raw_device + .map(|interface| Self::map_interface_name(interface, mapping)); + + interface.slaves = interface.slaves.map(|slaves| { + slaves + .into_iter() + .map(|interface| Self::map_interface_name(interface, mapping)) + .collect::>() + }); + + interface.bond_primary = interface + .bond_primary + .map(|interface| Self::map_interface_name(interface, mapping)); + + interface + } + + pub fn rename_interfaces( + mut self, + mapping: &HashMap, + ) -> Result { + let mut new_config = NetworkConfig::new(); + + for entry in self.order { + match entry { + NetworkOrderEntry::Iface(ref iface_name) => { + if let Some(mut interface) = self.interfaces.remove(iface_name) { + interface.name = Self::map_interface_name(interface.name, mapping); + + interface = Self::handle_interface(interface, mapping); + + new_config.order.push(entry); + new_config + .interfaces + .insert(interface.name.clone(), interface); + } + } + _ => new_config.order.push(entry), + } + } + + for (name, mut interface) in self.interfaces.into_iter() { + interface.name = Self::map_interface_name(name, mapping); + + interface = Self::handle_interface(interface, mapping); + + new_config + .interfaces + .insert(interface.name.clone(), interface); + } + + Ok(new_config) + } + /// Check that there is no other gateway. /// /// The gateway property is only allowed on passed 'iface'. This should be -- 2.47.2 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel