From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 3A4291FF165 for ; Thu, 17 Jul 2025 17:28:29 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 9CFAB3EDCD; Thu, 17 Jul 2025 17:29:17 +0200 (CEST) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Date: Thu, 17 Jul 2025 17:28:37 +0200 Message-Id: <20250717152841.397830-3-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250717152841.397830-1-s.hanreich@proxmox.com> References: <20250717152841.397830-1-s.hanreich@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.210 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 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: [pve-devel] [PATCH proxmox-perl-rs 1/1] pve-rs: fabrics: helper for mapping interface names X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" Add a helper method for proxmox-network-interface-pinning to rename all interfaces of a node in the fabric config according to the mapping generated by the pinning tool. This method renames all occurences of an interface name to the pinned version. The logic has been taken and reimplemented from the Perl helper itself. Signed-off-by: Stefan Hanreich --- pve-rs/src/bindings/sdn/fabrics.rs | 64 +++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/pve-rs/src/bindings/sdn/fabrics.rs b/pve-rs/src/bindings/sdn/fabrics.rs index fd81c77..587b1d6 100644 --- a/pve-rs/src/bindings/sdn/fabrics.rs +++ b/pve-rs/src/bindings/sdn/fabrics.rs @@ -5,7 +5,7 @@ pub mod pve_rs_sdn_fabrics { //! This provides the configuration for the SDN fabrics, as well as helper methods for reading //! / writing the configuration, as well as for generating ifupdown2 and FRR configuration. - use std::collections::{BTreeMap, HashSet}; + use std::collections::{BTreeMap, HashMap, HashSet}; use std::fmt::Write; use std::net::IpAddr; use std::ops::Deref; @@ -26,6 +26,7 @@ pub mod pve_rs_sdn_fabrics { Fabric as ConfigFabric, FabricId, api::{Fabric, FabricUpdater}, }; + use proxmox_ve_config::sdn::fabric::section_config::interface::InterfaceName; use proxmox_ve_config::sdn::fabric::section_config::node::{ Node as ConfigNode, NodeId, api::{Node, NodeUpdater}, @@ -304,6 +305,67 @@ pub mod pve_rs_sdn_fabrics { .map_err(anyhow::Error::from) } + fn map_name( + mapping: &HashMap, + name: &str, + ) -> Result, Error> { + match name.split_once('.') { + Some((interface_name, vlan_id)) + if !vlan_id.is_empty() && vlan_id.chars().all(char::is_numeric) => + { + mapping + .get(interface_name) + .map(|mapped_name| { + InterfaceName::from_string(format!("{mapped_name}.{vlan_id}")) + }) + .transpose() + } + _ => mapping + .get(name) + .cloned() + .map(InterfaceName::from_string) + .transpose(), + } + } + + /// Method: Map all interface names of a node to a different one, according to the given + /// mapping. + /// + /// Used by proxmox-network-interface-pinning + #[export] + pub fn map_interfaces( + #[try_from_ref] this: &PerlFabricConfig, + node_id: NodeId, + mapping: HashMap, + ) -> Result<(), Error> { + let mut config = this.fabric_config.lock().unwrap(); + + for entry in config.get_fabrics_mut() { + let Ok(node) = entry.get_node_mut(&node_id) else { + continue; + }; + + match node { + ConfigNode::Openfabric(node_section) => { + for interface in node_section.properties_mut().interfaces_mut() { + if let Some(mapped_name) = map_name(&mapping, &interface.name())? { + interface.set_name(mapped_name); + } + } + } + ConfigNode::Ospf(node_section) => { + for interface in node_section.properties_mut().interfaces_mut() { + if let Some(mapped_name) = map_name(&mapping, &interface.name())? { + interface.set_name(mapped_name); + } + } + } + } + } + + Ok(()) + } + /// Method: Convert the configuration into the section config sections. /// /// Used for writing the running configuration. -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel