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

Stefan Hanreich s.hanreich at proxmox.com
Thu Nov 20 12:06:35 CET 2025


Calls the respective Proxmox VE endpoint to obtain status information
about the MAC-VRF of an EVPN vnet. Since the status is per-node, use
the existing nodes subdirectory instead of the general SDN
subdirectory, mirroring the API path from Proxmox VE.

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   | 13 +++++++++-
 server/src/api/nodes/sdn.rs | 47 +++++++++++++++++++++++++++++++++++--
 2 files changed, 57 insertions(+), 3 deletions(-)

diff --git a/lib/pdm-client/src/lib.rs b/lib/pdm-client/src/lib.rs
index 00d980c..225e043 100644
--- a/lib/pdm-client/src/lib.rs
+++ b/lib/pdm-client/src/lib.rs
@@ -69,7 +69,7 @@ pub mod types {
 
     pub use pve_api_types::StorageStatus as PveStorageStatus;
 
-    pub use pve_api_types::SdnZoneIpVrf;
+    pub use pve_api_types::{SdnVnetMacVrf, SdnZoneIpVrf};
 }
 
 pub struct PdmClient<T: HttpApiClient>(pub T);
@@ -1076,6 +1076,17 @@ impl<T: HttpApiClient> PdmClient<T> {
         Ok(self.0.get(&path).await?.expect_json()?.data)
     }
 
+    pub async fn pve_sdn_vnet_get_mac_vrf(
+        &self,
+        remote: &str,
+        node: &str,
+        vnet: &str,
+    ) -> Result<Vec<SdnVnetMacVrf>, Error> {
+        let path =
+            format!("/api2/extjs/pve/remotes/{remote}/nodes/{node}/sdn/vnets/{vnet}/mac-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/sdn.rs b/server/src/api/nodes/sdn.rs
index 9ca6130..065ebe0 100644
--- a/server/src/api/nodes/sdn.rs
+++ b/server/src/api/nodes/sdn.rs
@@ -4,7 +4,7 @@ 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 pve_api_types::{SdnVnetMacVrf, SdnZoneIpVrf};
 
 use crate::api::pve::{connect, get_remote};
 
@@ -51,7 +51,50 @@ mod zones {
     }
 }
 
-const SUBDIRS: SubdirMap = &[("zone", &zones::ROUTER)];
+mod vnets {
+    use super::*;
+
+    const VNET_SUBDIRS: SubdirMap = &[("mac-vrf", &Router::new().get(&API_METHOD_GET_MAC_VRF))];
+
+    const VNET_ROUTER: Router = Router::new()
+        .get(&list_subdirs_api_method!(VNET_SUBDIRS))
+        .subdirs(VNET_SUBDIRS);
+
+    pub const ROUTER: Router = Router::new().match_all("vnet", &VNET_ROUTER);
+
+    #[api(
+        input: {
+            properties: {
+                remote: { schema: REMOTE_ID_SCHEMA },
+                node: { schema: NODE_SCHEMA },
+                vnet: { schema: SDN_ID_SCHEMA },
+            },
+        },
+        returns: { type: SdnVnetMacVrf },
+    )]
+    /// Get the MAC-VRF for an EVPN vnet for a node on a given remote
+    async fn get_mac_vrf(
+        remote: String,
+        node: String,
+        vnet: String,
+    ) -> Result<Vec<SdnVnetMacVrf>, Error> {
+        let (remote_config, _) = pdm_config::remotes::config()?;
+        let remote = get_remote(&remote_config, &remote)?;
+        let client = connect(&remote)?;
+
+        client
+            .get_vnet_mac_vrf(&node, &vnet)
+            .await
+            .map_err(|err| match err {
+                proxmox_client::Error::Api(StatusCode::NOT_IMPLEMENTED, _msg) => {
+                    anyhow!("remote {} does not support the vnet mac-vrf API call, please upgrade to the newest version!", remote.id)
+                }
+                _ => err.into()
+            })
+    }
+}
+
+const SUBDIRS: SubdirMap = &[("vnets", &vnets::ROUTER), ("zones", &zones::ROUTER)];
 
 pub const ROUTER: Router = Router::new()
     .get(&list_subdirs_api_method!(SUBDIRS))
-- 
2.47.3




More information about the pdm-devel mailing list