public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Hannes Laimer <h.laimer@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH proxmox-datacenter-manager 1/4] pdm-api-types: add firewall status types
Date: Thu, 30 Oct 2025 15:34:03 +0100	[thread overview]
Message-ID: <20251030143406.193744-11-h.laimer@proxmox.com> (raw)
In-Reply-To: <20251030143406.193744-1-h.laimer@proxmox.com>

These types are returned by all the `../firewall/status` endpoints. The
UI also uses them.

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
 lib/pdm-api-types/src/firewall.rs | 171 ++++++++++++++++++++++++++++++
 lib/pdm-api-types/src/lib.rs      |   2 +
 2 files changed, 173 insertions(+)
 create mode 100644 lib/pdm-api-types/src/firewall.rs

diff --git a/lib/pdm-api-types/src/firewall.rs b/lib/pdm-api-types/src/firewall.rs
new file mode 100644
index 0000000..10357ad
--- /dev/null
+++ b/lib/pdm-api-types/src/firewall.rs
@@ -0,0 +1,171 @@
+use proxmox_schema::{api, Schema};
+use serde::{Deserialize, Serialize};
+
+use crate::remotes::REMOTE_ID_SCHEMA;
+use crate::{NODE_SCHEMA, VMID_SCHEMA};
+
+const FIREWALL_RULES_COUNT: Schema =
+    proxmox_schema::IntegerSchema::new("The total amount of rules present")
+        .minimum(0)
+        .schema();
+
+const FIREWALL_ACTIVE_RULES_COUNT: Schema =
+    proxmox_schema::IntegerSchema::new("The amount of enabled rules")
+        .minimum(0)
+        .schema();
+
+#[api(
+    properties: {
+        all: {
+            schema: FIREWALL_RULES_COUNT,
+        },
+        active: {
+            schema: FIREWALL_ACTIVE_RULES_COUNT,
+        }
+    }
+)]
+/// Count of all rules present and count of all enabled firewall rules.
+#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
+pub struct RuleStat {
+    pub all: usize,
+    pub active: usize,
+}
+
+#[api(
+    properties: {
+        enabled: {
+            type: bool,
+            description: "True if the firewall is enabled",
+        },
+        rules: {
+            type: RuleStat,
+            flatten: true,
+        },
+    }
+)]
+/// Firewall status.
+#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
+#[serde(rename_all = "kebab-case")]
+pub struct FirewallStatus {
+    pub enabled: bool,
+    #[serde(flatten)]
+    pub rules: RuleStat,
+}
+
+#[api(
+    properties: {
+        remote: {
+            schema: REMOTE_ID_SCHEMA,
+        },
+        status: {
+            type: FirewallStatus,
+            optional: true,
+        },
+        nodes: {
+            description: "Nodes in the cluster",
+            items: {
+                type: NodeFirewallStatus
+            },
+            type: Array,
+        },
+    }
+)]
+/// Firewall status of a PVE remote.
+#[derive(Serialize, Deserialize, Clone, PartialEq)]
+#[serde(rename_all = "kebab-case")]
+pub struct RemoteFirewallStatus {
+    pub remote: String,
+    pub status: Option<FirewallStatus>,
+    pub nodes: Vec<NodeFirewallStatus>,
+}
+
+#[api(
+    properties: {
+        node: {
+            schema: NODE_SCHEMA,
+        },
+        status: {
+            type: FirewallStatus,
+            optional: true,
+        },
+        guests: {
+            description: "Guests on a node",
+            items: {
+                type: GuestFirewallStatus
+            },
+            type: Array,
+        },
+    }
+)]
+/// Firewall status of a node
+#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
+pub struct NodeFirewallStatus {
+    pub node: String,
+    pub status: Option<FirewallStatus>,
+    pub guests: Vec<GuestFirewallStatus>,
+}
+
+#[api]
+#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq)]
+#[serde(rename_all = "lowercase")]
+/// The type of the guest
+pub enum GuestKind {
+    /// Guest is a LXC
+    Lxc,
+    /// Guets is a QEMU
+    Qemu,
+}
+
+impl GuestKind {
+    pub const fn as_str(&self) -> &'static str {
+        match self {
+            GuestKind::Lxc => "lxc",
+            GuestKind::Qemu => "qemu",
+        }
+    }
+}
+
+impl AsRef<str> for GuestKind {
+    fn as_ref(&self) -> &str {
+        self.as_str()
+    }
+}
+
+impl From<GuestKind> for &'static str {
+    fn from(kind: GuestKind) -> Self {
+        kind.as_str()
+    }
+}
+
+impl From<&GuestKind> for &'static str {
+    fn from(kind: &GuestKind) -> Self {
+        kind.as_str()
+    }
+}
+
+#[api(
+    properties: {
+        vmid: {
+            schema: VMID_SCHEMA,
+        },
+        name: {
+            type: String,
+            description: "Name of the guest.",
+        },
+        status: {
+            type: FirewallStatus,
+            optional: true,
+        },
+        kind: {
+            type: GuestKind,
+        }
+    }
+)]
+/// Firewall status of a guest
+#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
+pub struct GuestFirewallStatus {
+    pub vmid: u32,
+    pub name: String,
+    pub status: Option<FirewallStatus>,
+    pub kind: GuestKind,
+}
diff --git a/lib/pdm-api-types/src/lib.rs b/lib/pdm-api-types/src/lib.rs
index 2fb61ef..40f2381 100644
--- a/lib/pdm-api-types/src/lib.rs
+++ b/lib/pdm-api-types/src/lib.rs
@@ -94,6 +94,8 @@ pub use proxmox_schema::upid::*;
 mod openid;
 pub use openid::*;
 
+pub mod firewall;
+
 pub mod remotes;
 
 pub mod remote_updates;
-- 
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-10-30 14:33 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-30 14:33 [pdm-devel] [PATCH proxmox{, -yew-comp, -datacenter-manager} 00/13] add basic integration of PVE firewall Hannes Laimer
2025-10-30 14:33 ` [pdm-devel] [PATCH proxmox 1/5] pve-api-types: update pve-api.json Hannes Laimer
2025-10-30 14:33 ` [pdm-devel] [PATCH proxmox 2/5] pve-api-types: add get/update firewall options endpoints Hannes Laimer
2025-10-30 14:33 ` [pdm-devel] [PATCH proxmox 3/5] pve-api-types: schema2rust: handle `macro` keyword like we do `type` Hannes Laimer
2025-10-30 14:33 ` [pdm-devel] [PATCH proxmox 4/5] pve-api-types: add list firewall rules endpoints Hannes Laimer
2025-10-30 14:33 ` [pdm-devel] [PATCH proxmox 5/5] pve-api-types: regenerate Hannes Laimer
2025-10-30 14:33 ` [pdm-devel] [PATCH proxmox-yew-comp 1/4] form: add helpers for extractig data out of schemas Hannes Laimer
2025-10-30 14:34 ` [pdm-devel] [PATCH proxmox-yew-comp 2/4] firewall: add FirewallContext Hannes Laimer
2025-10-30 14:34 ` [pdm-devel] [PATCH proxmox-yew-comp 3/4] firewall: add options edit form Hannes Laimer
2025-10-30 14:34 ` [pdm-devel] [PATCH proxmox-yew-comp 4/4] firewall: add rules table Hannes Laimer
2025-10-30 14:34 ` Hannes Laimer [this message]
2025-10-30 14:34 ` [pdm-devel] [PATCH proxmox-datacenter-manager 2/4] api: firewall: add option, rules and status endpoints Hannes Laimer
2025-10-30 14:34 ` [pdm-devel] [PATCH proxmox-datacenter-manager 3/4] pdm-client: add api methods for firewall options, " Hannes Laimer
2025-10-30 14:34 ` [pdm-devel] [PATCH proxmox-datacenter-manager 4/4] ui: add firewall status tree Hannes Laimer

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=20251030143406.193744-11-h.laimer@proxmox.com \
    --to=h.laimer@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