public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Hanreich <s.hanreich@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH proxmox-datacenter-manager 1/5] server: api: sdn: add ip-vrf endpoint
Date: Fri,  7 Nov 2025 09:59:24 +0100	[thread overview]
Message-ID: <20251107085934.118815-5-s.hanreich@proxmox.com> (raw)
In-Reply-To: <20251107085934.118815-1-s.hanreich@proxmox.com>

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@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 0cab769..e22d139 100644
--- a/lib/pdm-client/src/lib.rs
+++ b/lib/pdm-client/src/lib.rs
@@ -66,6 +66,8 @@ pub mod types {
     pub use pve_api_types::{ListControllersType, ListZonesType, SdnObjectState};
 
     pub use pve_api_types::StorageStatus as PveStorageStatus;
+
+    pub use pve_api_types::SdnZoneIpVrf;
 }
 
 pub struct PdmClient<T: HttpApiClient>(pub T);
@@ -1051,6 +1053,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 6f30ba7..66f88f3 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 syslog;
 pub mod tasks;
 pub mod termproxy;
@@ -45,6 +46,7 @@ pub const SUBDIRS: SubdirMap = &sorted!([
     ("journal", &journal::ROUTER),
     ("network", &network::ROUTER),
     ("rrdata", &rrddata::ROUTER),
+    ("sdn", &sdn::ROUTER),
     ("syslog", &syslog::ROUTER),
     ("tasks", &tasks::ROUTER),
     ("termproxy", &termproxy::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 301c0b1..dae890e 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))
@@ -18,6 +18,7 @@ const SUBDIRS: SubdirMap = &sorted!([
     ("apt", &crate::api::remote_updates::APT_ROUTER),
     ("rrddata", &super::rrddata::NODE_RRD_ROUTER),
     ("network", &Router::new().get(&API_METHOD_GET_NETWORK)),
+    ("sdn", &sdn::ROUTER),
     ("storage", &STORAGE_ROUTER),
     ("status", &Router::new().get(&API_METHOD_GET_STATUS)),
 ]);
-- 
2.47.3


_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel


  parent reply	other threads:[~2025-11-07  8:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-07  8:59 [pdm-devel] [PATCH proxmox{, -datacenter-manager} 0/8] Integration of IP-VRF and MAC-VRF status to EVPN panel Stefan Hanreich
2025-11-07  8:59 ` [pdm-devel] [PATCH proxmox 1/3] pve-api-types: add zone / vnet status reporting endpoints Stefan Hanreich
2025-11-07  8:59 ` [pdm-devel] [PATCH proxmox 2/3] pve-api-types: generate ip-vrf / mac-vrf endpoints Stefan Hanreich
2025-11-07  8:59 ` [pdm-devel] [PATCH proxmox 3/3] pve-api-types: regenerate Stefan Hanreich
2025-11-07  8:59 ` Stefan Hanreich [this message]
2025-11-07  8:59 ` [pdm-devel] [PATCH proxmox-datacenter-manager 2/5] server: api: sdn: add mac-vrf endpoint Stefan Hanreich
2025-11-07  8:59 ` [pdm-devel] [PATCH proxmox-datacenter-manager 3/5] ui: sdn: evpn: add zone status panel Stefan Hanreich
2025-11-07  8:59 ` [pdm-devel] [PATCH proxmox-datacenter-manager 4/5] ui: sdn: evpn: add vnet " Stefan Hanreich
2025-11-07  8:59 ` [pdm-devel] [PATCH proxmox-datacenter-manager 5/5] sdn: evpn: add detail panel to the evpn panel 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=20251107085934.118815-5-s.hanreich@proxmox.com \
    --to=s.hanreich@proxmox.com \
    --cc=pdm-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal