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 25C3B1FF165 for ; Thu, 22 May 2025 18:19:15 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 635CAA311; Thu, 22 May 2025 18:17:55 +0200 (CEST) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Date: Thu, 22 May 2025 18:16:45 +0200 Message-Id: <20250522161731.537011-30-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250522161731.537011-1-s.hanreich@proxmox.com> References: <20250522161731.537011-1-s.hanreich@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.228 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 v3 3/5] pve-rs: sdn: fabrics: add frr config generation 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" We use proxmox-ve-config to generate a FRR config and serialize it with the proxmox-frr crate in order to return it to perl in its internally used format (an array of strings). The Perl SDN module in turn merges it with the FRR configuration generated by Perl modules and persists it to the FRR configuration file. We also provide a method that returns a list of daemons, that are required to be enabled for the current FRR configuration. This is used by Perl to write the daemons configuration file of FRR. Co-authored-by: Gabriel Goller Signed-off-by: Stefan Hanreich --- pve-rs/src/bindings/sdn/fabrics.rs | 49 +++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/pve-rs/src/bindings/sdn/fabrics.rs b/pve-rs/src/bindings/sdn/fabrics.rs index 2efa1c6..a7a740f 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; + use std::collections::{BTreeMap, HashSet}; use std::ops::Deref; use std::sync::Mutex; @@ -14,6 +14,7 @@ pub mod pve_rs_sdn_fabrics { use serde::{Deserialize, Serialize}; use perlmod::Value; + use proxmox_frr::serializer::to_raw_config; use proxmox_section_config::typed::SectionConfigData; use proxmox_ve_config::common::valid::Validatable; @@ -31,6 +32,7 @@ pub mod pve_rs_sdn_fabrics { }, FabricConfig, FabricEntry, }; + use proxmox_ve_config::sdn::frr::FrrConfigBuilder; /// A SDN Fabric config instance. #[derive(Serialize, Deserialize)] @@ -302,4 +304,49 @@ pub mod pve_rs_sdn_fabrics { Ok(hex::encode(hash)) } + + /// Class method: Return all FRR daemons that need to be enabled for this fabric configuration + /// instance. + #[export] + pub fn enabled_daemons( + #[try_from_ref] this: &PerlFabricConfig, + node_id: NodeId, + ) -> Vec { + let config = this.fabric_config.lock().unwrap(); + + let node_fabrics = config + .values() + .filter(|fabric| fabric.get_node(&node_id).is_ok()); + + let mut daemons = HashSet::new(); + + for fabric in node_fabrics { + match fabric { + FabricEntry::Ospf(_) => { + daemons.insert("ospfd"); + } + FabricEntry::Openfabric(_) => { + daemons.insert("fabricd"); + } + }; + } + + daemons.into_iter().map(String::from).collect() + } + + /// Class method: Return the FRR configuration for this config instance, as an array of + /// strings, where each line represents a line in the FRR configuration. + #[export] + pub fn get_frr_raw_config( + #[try_from_ref] this: &PerlFabricConfig, + node_id: NodeId, + ) -> Result, Error> { + let config = this.fabric_config.lock().unwrap(); + + let frr_config = FrrConfigBuilder::default() + .add_fabrics(config.clone().into_valid()?) + .build(node_id)?; + + to_raw_config(&frr_config) + } } -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel