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 4BFA71FF14F for ; Fri, 08 May 2026 18:31:53 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 84B711DDB0; Fri, 8 May 2026 18:31:48 +0200 (CEST) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox-perl-rs v6 03/24] sdn: prefix lists: refactor existing API endpoint Date: Fri, 8 May 2026 18:31:12 +0200 Message-ID: <20260508163134.481912-4-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260508163134.481912-1-s.hanreich@proxmox.com> References: <20260508163134.481912-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: 1778257794462 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.365 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_MAILER 2 Automated Mailer Tag Left in Email 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: SKYWE76QT2UFAJELUFCBNSMX33TUDB7R X-Message-ID-Hash: SKYWE76QT2UFAJELUFCBNSMX33TUDB7R 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: proxmox-ve-config now uses dedicated API types for the prefix list entries. This was necessary, because the sequence number in the prefix list entries is now required in the section config - but not when submitting values via the API. The existing API type for prefix lists, now uses the prefix list entry API type as well, to handle this change. List and get endpoints will always return the config type, since they return the values from the configuration - while the create and update endpoints will utilize the API types, since they contain the proper format for values submitted by users. Additionally, change the return type of the list and get endpoints since they're infallible. The updater method has been moved into proxmox-ve-config. This allows for leaving the field private, easier validation and automatic numbering of entries. Signed-off-by: Stefan Hanreich --- pve-rs/src/bindings/sdn/prefix_lists.rs | 57 +++++++++---------------- 1 file changed, 19 insertions(+), 38 deletions(-) diff --git a/pve-rs/src/bindings/sdn/prefix_lists.rs b/pve-rs/src/bindings/sdn/prefix_lists.rs index eafb70d..4ca6999 100644 --- a/pve-rs/src/bindings/sdn/prefix_lists.rs +++ b/pve-rs/src/bindings/sdn/prefix_lists.rs @@ -18,9 +18,13 @@ pub mod pve_rs_sdn_prefix_lists { use perlmod::Value; use proxmox_section_config::typed::{ApiSectionDataEntry, SectionConfigData}; use proxmox_ve_config::sdn::prefix_list::api::{ - PrefixList as ApiPrefixList, PrefixListDeletableProperties, PrefixListUpdater, + PrefixList as ApiPrefixList, PrefixListDeletableProperties, + PrefixListEntry as ApiPrefixListEntry, PrefixListEntryDeletableProperties, + PrefixListEntryUpdater, PrefixListUpdater, + }; + use proxmox_ve_config::sdn::prefix_list::{ + PrefixList as ConfigPrefixList, PrefixListEntry as ConfigPrefixListEntry, PrefixListId, }; - use proxmox_ve_config::sdn::prefix_list::{PrefixList as ConfigPrefixList, PrefixListId}; /// A SDN PrefixList config instance. #[derive(Serialize, Deserialize)] @@ -93,19 +97,13 @@ pub mod pve_rs_sdn_prefix_lists { /// Method: Returns all prefix lists as a hash indexed with the IDs of the prefix lists. #[export] - pub fn list( - #[try_from_ref] this: &PerlPrefixListConfig, - ) -> Result, Error> { - Ok(this - .prefix_lists + pub fn list(#[try_from_ref] this: &PerlPrefixListConfig) -> HashMap { + this.prefix_lists .lock() .unwrap() .iter() - .map(|(id, prefix_list)| { - let ConfigPrefixList::PrefixList(prefix_list) = prefix_list; - (id.clone(), prefix_list.clone()) - }) - .collect()) + .map(|(id, prefix_list)| (id.clone(), prefix_list.clone())) + .collect() } /// Method: Create a new PrefixList. @@ -121,7 +119,9 @@ pub mod pve_rs_sdn_prefix_lists { "prefix list already exists in configuration: {}", prefix_list.id() ), - Entry::Vacant(vacancy) => vacancy.insert(ConfigPrefixList::PrefixList(prefix_list)), + Entry::Vacant(vacancy) => { + vacancy.insert(ConfigPrefixList::PrefixList(prefix_list.try_into()?)) + } }; Ok(()) @@ -132,16 +132,12 @@ pub mod pve_rs_sdn_prefix_lists { pub fn get( #[try_from_ref] this: &PerlPrefixListConfig, id: PrefixListId, - ) -> Result, Error> { - Ok(this - .prefix_lists + ) -> Option { + this.prefix_lists .lock() .unwrap() .get(&id.to_string()) - .map(|prefix_list| { - let ConfigPrefixList::PrefixList(prefix_list) = prefix_list; - prefix_list.clone() - })) + .cloned() } /// Method: Update a PrefixList. @@ -158,21 +154,7 @@ pub mod pve_rs_sdn_prefix_lists { .get_mut(id.as_str()) .ok_or_else(|| anyhow!("Could not find prefix list with id: {}", id))?; - let PrefixListUpdater { entries } = updater; - - if let Some(entries) = entries { - prefix_list.entries = entries; - } - - for deletable_property in delete.unwrap_or_default() { - match deletable_property { - PrefixListDeletableProperties::Entries => { - prefix_list.entries = Vec::new(); - } - } - } - - Ok(()) + prefix_list.try_update(updater, delete) } /// Method: Delete a PrefixList. @@ -185,8 +167,7 @@ pub mod pve_rs_sdn_prefix_lists { .lock() .unwrap() .remove(&id.to_string()) - .ok_or_else(|| anyhow!("could not find prefix list with id: {id}"))?; - - Ok(()) + .map(|_| ()) + .ok_or_else(|| anyhow!("could not find prefix list with id: {id}")) } } -- 2.47.3