all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Hanreich <s.hanreich@proxmox.com>
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	[thread overview]
Message-ID: <20260508163134.481912-4-s.hanreich@proxmox.com> (raw)
In-Reply-To: <20260508163134.481912-1-s.hanreich@proxmox.com>

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 <s.hanreich@proxmox.com>
---
 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<HashMap<String, ApiPrefixList>, Error> {
-        Ok(this
-            .prefix_lists
+    pub fn list(#[try_from_ref] this: &PerlPrefixListConfig) -> HashMap<String, ConfigPrefixList> {
+        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<Option<ApiPrefixList>, Error> {
-        Ok(this
-            .prefix_lists
+    ) -> Option<ConfigPrefixList> {
+        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





  parent reply	other threads:[~2026-05-08 16:31 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-08 16:31 [PATCH manager/network/proxmox{-ve-rs,-perl-rs} v6 00/24] Add support for route maps / prefix lists to SDN Stefan Hanreich
2026-05-08 16:31 ` [PATCH proxmox-ve-rs v6 01/24] sdn: prefix lists: refactor section config and api format Stefan Hanreich
2026-05-08 16:31 ` [PATCH proxmox-ve-rs v6 02/24] prefix lists: implement validation for prefix lists Stefan Hanreich
2026-05-08 16:31 ` Stefan Hanreich [this message]
2026-05-08 16:31 ` [PATCH proxmox-perl-rs v6 04/24] sdn: prefix lists: add crud methods for prefix list entries Stefan Hanreich
2026-05-08 16:31 ` [PATCH proxmox-perl-rs v6 05/24] sdn: prefix lists: validate prefix lists Stefan Hanreich
2026-05-08 16:31 ` [PATCH proxmox-perl-rs v6 06/24] sdn: route maps: add route map list method Stefan Hanreich
2026-05-08 16:31 ` [PATCH pve-network v6 07/24] api: refactor route map api structure Stefan Hanreich
2026-05-08 16:31 ` [PATCH pve-network v6 08/24] api: refactor prefix list " Stefan Hanreich
2026-05-08 16:31 ` [PATCH pve-manager v6 09/24] ui: sdn: add route map selector Stefan Hanreich
2026-05-08 16:31 ` [PATCH pve-manager v6 10/24] ui: sdn: add prefix list selector Stefan Hanreich
2026-05-08 16:31 ` [PATCH pve-manager v6 11/24] ui: sdn: add panel for managing prefix lists Stefan Hanreich
2026-05-08 16:31 ` [PATCH pve-manager v6 12/24] ui: sdn: add panel for managing route map entries Stefan Hanreich
2026-05-08 16:31 ` [PATCH pve-manager v6 13/24] ui: sdn: bgp controller: allow configuring route maps Stefan Hanreich
2026-05-08 16:31 ` [PATCH pve-manager v6 14/24] ui: sdn: evpn " Stefan Hanreich
2026-05-08 16:31 ` [PATCH pve-manager v6 15/24] ui: sdn: openfabric: add route filter Stefan Hanreich
2026-05-08 16:31 ` [PATCH pve-manager v6 16/24] ui: sdn: ospf: add route filter setting Stefan Hanreich
2026-05-08 16:31 ` [PATCH pve-manager v6 17/24] ui: sdn: prefix list: add missing subjects Stefan Hanreich
2026-05-08 16:31 ` [PATCH pve-manager v6 18/24] sdn: do not fail rendering record data if pending property is missing Stefan Hanreich
2026-05-08 16:31 ` [PATCH pve-manager v6 19/24] ui: sdn: prefix list: adapt to changed api structure Stefan Hanreich
2026-05-08 16:31 ` [PATCH pve-manager v6 20/24] ui: sdn: route maps: adapt to new route map " Stefan Hanreich
2026-05-08 16:31 ` [PATCH pve-manager v6 21/24] ui: sdn: prefix lists: route maps: use integerfields for numbers Stefan Hanreich
2026-05-08 16:31 ` [PATCH pve-manager v6 22/24] ui: sdn: prefix list panel: reload data on deleting prefix list entry Stefan Hanreich
2026-05-08 16:31 ` [PATCH pve-manager v6 23/24] ui: prefix list panel: delete empty le and get properties Stefan Hanreich
2026-05-08 16:31 ` [PATCH pve-manager v6 24/24] ui: prefix list entry panel: make prefix required Stefan Hanreich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260508163134.481912-4-s.hanreich@proxmox.com \
    --to=s.hanreich@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal