From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 570731FF17E for ; Thu, 30 Oct 2025 15:33:48 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 5395724287; Thu, 30 Oct 2025 15:34:17 +0100 (CET) From: Hannes Laimer To: pdm-devel@lists.proxmox.com Date: Thu, 30 Oct 2025 15:34:03 +0100 Message-ID: <20251030143406.193744-11-h.laimer@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251030143406.193744-1-h.laimer@proxmox.com> References: <20251030143406.193744-1-h.laimer@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1761834836262 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.042 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_MSPIKE_H2 0.001 Average reputation (+2) SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pdm-devel] [PATCH proxmox-datacenter-manager 1/4] pdm-api-types: add firewall status types X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Datacenter Manager development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" These types are returned by all the `../firewall/status` endpoints. The UI also uses them. Signed-off-by: Hannes Laimer --- 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, + pub nodes: Vec, +} + +#[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, + pub guests: Vec, +} + +#[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 for GuestKind { + fn as_ref(&self) -> &str { + self.as_str() + } +} + +impl From 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, + 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