From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 3FB191FF0AF for ; Fri, 20 Nov 2026 16:28:24 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 3519821753; Fri, 20 Nov 2026 16:28:23 +0100 (CET) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox-ve-rs 1/4] sdn: config: read the nodes of zones from the running config Date: Fri, 20 Nov 2026 16:28:06 +0100 Message-ID: <20261120152811.473269-2-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261120152811.473269-1-s.hanreich@proxmox.com> References: <20261120152811.473269-1-s.hanreich@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795188499505 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.218 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: WS73I5FQJ252ETYLZZC5PDA63PWNS5YJ X-Message-ID-Hash: WS73I5FQJ252ETYLZZC5PDA63PWNS5YJ X-MailFrom: s.hanreich@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: A zone can be restricted to a set of nodes. Read the nodes of a zone, so that users of the SDN config can tell if a zone exists on a node. Signed-off-by: Stefan Hanreich --- proxmox-ve-config/src/sdn/config.rs | 18 +++++++++++++++++ proxmox-ve-config/tests/sdn/main.rs | 30 +++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/proxmox-ve-config/src/sdn/config.rs b/proxmox-ve-config/src/sdn/config.rs index 6a65ee11..d5b3926a 100644 --- a/proxmox-ve-config/src/sdn/config.rs +++ b/proxmox-ve-config/src/sdn/config.rs @@ -148,8 +148,15 @@ pub struct ZoneRunningConfig { deserialize_with = "proxmox_serde::perl::deserialize_u16" )] ct_zone: Option, + /// pve-network stores the nodes as object with the node names as keys + #[serde(default)] + nodes: Option>, } +/// A boolean as stored by perl, which can also be a number or a string. +#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, Hash, PartialOrd, Ord)] +struct PerlBool(#[serde(deserialize_with = "proxmox_serde::perl::deserialize_bool")] bool); + /// Struct for deserializing the zones of the SDN running config #[derive(Clone, Debug, Deserialize, PartialEq, Eq, Default)] pub struct ZonesRunningConfig { @@ -399,6 +406,8 @@ pub struct ZoneConfig { vnets: BTreeMap, #[serde(default)] ct_zone: Option, + #[serde(default)] + nodes: Option>, } impl ZoneConfig { @@ -408,6 +417,7 @@ impl ZoneConfig { ty, vnets: BTreeMap::default(), ct_zone: None, + nodes: None, } } @@ -463,6 +473,13 @@ impl ZoneConfig { pub fn set_ct_zone(&mut self, ct_zone: Option) { self.ct_zone = ct_zone; } + + /// Whether the zone exists on the given node, a zone without nodes exists on all nodes. + pub fn is_on_node(&self, node: &str) -> bool { + self.nodes + .as_ref() + .is_none_or(|nodes| nodes.get(node).is_some_and(|enabled| enabled.0)) + } } /// Representation of a Proxmox VE SDN configuration @@ -677,6 +694,7 @@ impl TryFrom for SdnConfig { let mut zone = ZoneConfig::new(name, running_config.ty); zone.set_ct_zone(ct_zone); + zone.nodes = running_config.nodes; zone }))?; } diff --git a/proxmox-ve-config/tests/sdn/main.rs b/proxmox-ve-config/tests/sdn/main.rs index a58690e2..d1071771 100644 --- a/proxmox-ve-config/tests/sdn/main.rs +++ b/proxmox-ve-config/tests/sdn/main.rs @@ -184,6 +184,36 @@ fn parse_running_config_ct_zone() { ); } +#[test] +fn parse_running_config_nodes() { + let running_config: RunningConfig = serde_json::from_value(serde_json::json!({ + "zones": { + "ids": { + "zone0": { "type": "simple" }, + "zone1": { "type": "simple", "nodes": { "pve1": 1, "pve2": "1", "pve3": 0 } }, + "zone2": { "type": "simple", "nodes": {} }, + }, + }, + })) + .expect("valid running config"); + + let sdn_config = SdnConfig::try_from(running_config).expect("valid SDN config"); + + let is_on_node = |zone: &str, node: &str| { + sdn_config + .zone(&ZoneName::from_str(zone).unwrap()) + .expect("zone exists") + .is_on_node(node) + }; + + assert!(is_on_node("zone0", "pve1")); + assert!(is_on_node("zone1", "pve1")); + assert!(is_on_node("zone1", "pve2")); + assert!(!is_on_node("zone1", "pve3")); + assert!(!is_on_node("zone1", "pve4")); + assert!(!is_on_node("zone2", "pve1")); +} + #[test] fn sdn_config() { let mut sdn_config = SdnConfig::new(); -- 2.47.3