[pdm-devel] [PATCH proxmox-datacenter-manager v3 1/5] server: api: sdn: add ip-vrf endpoint

Stefan Hanreich s.hanreich at proxmox.com
Fri Nov 28 12:08:59 CET 2025


Calls the respective Proxmox VE endpoint to obtain status information
about the IP-VRF of an EVPN zone. Since the status is per-node, use
the existing nodes subdirectory instead of the general SDN
subdirectory, mirroring the API paths used in Proxmox VE. In order to
avoid having too many SDN-specific modules for a single API call,
introduce a submodule in the sdn module directly. If needed, this can
be easily factored out in the future.

Signed-off-by: Stefan Hanreich <s.hanreich at proxmox.com>
Tested-by: Hannes Dürr <h.duerr at proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner at proxmox.com>
---
 lib/pdm-client/src/lib.rs   | 12 ++++++++
 server/src/api/nodes/mod.rs |  2 ++
 server/src/api/nodes/sdn.rs | 58 +++++++++++++++++++++++++++++++++++++
 server/src/api/pve/node.rs  |  3 +-
 4 files changed, 74 insertions(+), 1 deletion(-)
 create mode 100644 server/src/api/nodes/sdn.rs

diff --git a/lib/pdm-client/src/lib.rs b/lib/pdm-client/src/lib.rs
index ddca395..83018ef 100644
--- a/lib/pdm-client/src/lib.rs
+++ b/lib/pdm-client/src/lib.rs
@@ -70,6 +70,8 @@ pub mod types {
     pub use pve_api_types::StorageStatus as PveStorageStatus;
 
     pub use pdm_api_types::subscription::{RemoteSubscriptionState, RemoteSubscriptions};
+
+    pub use pve_api_types::SdnZoneIpVrf;
 }
 
 pub struct PdmClient<T: HttpApiClient>(pub T);
@@ -1233,6 +1235,16 @@ impl<T: HttpApiClient> PdmClient<T> {
         Ok(self.0.post(path, &params).await?.expect_json()?.data)
     }
 
+    pub async fn pve_sdn_zone_get_ip_vrf(
+        &self,
+        remote: &str,
+        node: &str,
+        zone: &str,
+    ) -> Result<Vec<SdnZoneIpVrf>, Error> {
+        let path = format!("/api2/extjs/pve/remotes/{remote}/nodes/{node}/sdn/zones/{zone}/ip-vrf");
+        Ok(self.0.get(&path).await?.expect_json()?.data)
+    }
+
     /// uses /pbs/probe-tls to probe the tls connection to the given host
     pub async fn pbs_probe_tls(
         &self,
diff --git a/server/src/api/nodes/mod.rs b/server/src/api/nodes/mod.rs
index a0fe14a..d2a107a 100644
--- a/server/src/api/nodes/mod.rs
+++ b/server/src/api/nodes/mod.rs
@@ -10,6 +10,7 @@ pub mod dns;
 pub mod journal;
 pub mod network;
 pub mod rrddata;
+pub mod sdn;
 pub mod status;
 pub mod syslog;
 pub mod tasks;
@@ -45,6 +46,7 @@ pub const SUBDIRS: SubdirMap = &sorted!([
     ("journal", &journal::ROUTER),
     ("network", &network::ROUTER),
     ("rrdata", &rrddata::ROUTER),
+    ("sdn", &sdn::ROUTER),
     ("status", &status::ROUTER),
     ("syslog", &syslog::ROUTER),
     ("tasks", &tasks::ROUTER),
diff --git a/server/src/api/nodes/sdn.rs b/server/src/api/nodes/sdn.rs
new file mode 100644
index 0000000..9ca6130
--- /dev/null
+++ b/server/src/api/nodes/sdn.rs
@@ -0,0 +1,58 @@
+use anyhow::{anyhow, Error};
+use http::StatusCode;
+
+use pdm_api_types::{remotes::REMOTE_ID_SCHEMA, sdn::SDN_ID_SCHEMA, NODE_SCHEMA};
+use proxmox_router::{list_subdirs_api_method, Router, SubdirMap};
+use proxmox_schema::api;
+use pve_api_types::SdnZoneIpVrf;
+
+use crate::api::pve::{connect, get_remote};
+
+mod zones {
+    use super::*;
+
+    const ZONE_SUBDIRS: SubdirMap = &[("ip-vrf", &Router::new().get(&API_METHOD_GET_IP_VRF))];
+
+    const ZONE_ROUTER: Router = Router::new()
+        .get(&list_subdirs_api_method!(ZONE_SUBDIRS))
+        .subdirs(ZONE_SUBDIRS);
+
+    pub const ROUTER: Router = Router::new().match_all("zone", &ZONE_ROUTER);
+
+    #[api(
+        input: {
+            properties: {
+                remote: { schema: REMOTE_ID_SCHEMA },
+                node: { schema: NODE_SCHEMA },
+                zone: { schema: SDN_ID_SCHEMA },
+            },
+        },
+        returns: { type: SdnZoneIpVrf },
+    )]
+    /// Get the IP-VRF for an EVPN zone for a node on a given remote
+    async fn get_ip_vrf(
+        remote: String,
+        node: String,
+        zone: String,
+    ) -> Result<Vec<SdnZoneIpVrf>, Error> {
+        let (remote_config, _) = pdm_config::remotes::config()?;
+        let remote = get_remote(&remote_config, &remote)?;
+        let client = connect(remote)?;
+
+        client
+            .get_zone_ip_vrf(&node, &zone)
+            .await
+            .map_err(|err| match err {
+                proxmox_client::Error::Api(StatusCode::NOT_IMPLEMENTED, _msg) => {
+                    anyhow!("remote {} does not support the zone ip-vrf API call, please upgrade to the newest version!", remote.id)
+                }
+                _ => err.into()
+            })
+    }
+}
+
+const SUBDIRS: SubdirMap = &[("zone", &zones::ROUTER)];
+
+pub const ROUTER: Router = Router::new()
+    .get(&list_subdirs_api_method!(SUBDIRS))
+    .subdirs(SUBDIRS);
diff --git a/server/src/api/pve/node.rs b/server/src/api/pve/node.rs
index 47bd5b3..fe35cd3 100644
--- a/server/src/api/pve/node.rs
+++ b/server/src/api/pve/node.rs
@@ -7,7 +7,7 @@ use proxmox_sortable_macro::sortable;
 use pdm_api_types::{remotes::REMOTE_ID_SCHEMA, NODE_SCHEMA, PRIV_RESOURCE_AUDIT};
 use pve_api_types::StorageContent;
 
-use crate::api::pve::storage;
+use crate::api::{nodes::sdn, pve::storage};
 
 pub const ROUTER: Router = Router::new()
     .get(&list_subdirs_api_method!(SUBDIRS))
@@ -27,6 +27,7 @@ const SUBDIRS: SubdirMap = &sorted!([
         "vncwebsocket",
         &Router::new().upgrade(&crate::api::remote_shell::API_METHOD_SHELL_WEBSOCKET)
     ),
+    ("sdn", &sdn::ROUTER),
     ("storage", &STORAGE_ROUTER),
     ("status", &Router::new().get(&API_METHOD_GET_STATUS)),
 ]);
-- 
2.47.3




More information about the pdm-devel mailing list