[pdm-devel] [PATCH proxmox-api-types 2/2] add cluster status api call
Dominik Csapak
d.csapak at proxmox.com
Mon Jan 13 16:45:41 CET 2025
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
pve-api-types/generate.pl | 7 ++
pve-api-types/src/generated/code.rs | 12 ++-
pve-api-types/src/generated/types.rs | 114 +++++++++++++++++++++++++++
3 files changed, 132 insertions(+), 1 deletion(-)
diff --git a/pve-api-types/generate.pl b/pve-api-types/generate.pl
index 4c8e164..8be737b 100644
--- a/pve-api-types/generate.pl
+++ b/pve-api-types/generate.pl
@@ -279,6 +279,13 @@ Schema2Rust::register_api_extensions('ClusterJoinInfo', {
});
api(GET => '/cluster/config/join', 'cluster_config_join', 'return-name' => 'ClusterJoinInfo');
+# cluster status info
+Schema2Rust::register_api_extensions('ClusterNodeStatus', {
+ '/properties/id' => { description => sq("FIXME: Missing description in PVE.") },
+ '/properties/name' => { description => sq("FIXME: Missing description in PVE.") },
+});
+api(GET => '/cluster/status', 'cluster_status', 'return-name' => 'ClusterNodeStatus');
+
# api(GET => '/storage', 'list_storages', 'return-name' => 'StorageList');
Schema2Rust::register_api_extensions('ListRealm', {
'/properties/realm' => { description => sq("FIXME: Missing description in PVE.") },
diff --git a/pve-api-types/src/generated/code.rs b/pve-api-types/src/generated/code.rs
index dc17cd9..d05b519 100644
--- a/pve-api-types/src/generated/code.rs
+++ b/pve-api-types/src/generated/code.rs
@@ -127,7 +127,6 @@
/// - /cluster/sdn/vnets/{vnet}/subnets/{subnet}
/// - /cluster/sdn/zones
/// - /cluster/sdn/zones/{zone}
-/// - /cluster/status
/// - /cluster/tasks
/// - /nodes/{node}
/// - /nodes/{node}/aplinfo
@@ -395,6 +394,11 @@ pub trait PveClient {
Err(Error::Other("cluster_resources not implemented"))
}
+ /// Get cluster status information.
+ async fn cluster_status(&self) -> Result<Vec<ClusterNodeStatus>, Error> {
+ Err(Error::Other("cluster_status not implemented"))
+ }
+
/// Generate a new API token for a specific user. NOTE: returns API token
/// value, which needs to be stored as it cannot be retrieved afterwards!
async fn create_token(
@@ -688,6 +692,12 @@ where
Ok(self.0.get(&url).await?.expect_json()?.data)
}
+ /// Get cluster status information.
+ async fn cluster_status(&self) -> Result<Vec<ClusterNodeStatus>, Error> {
+ let url = format!("/api2/extjs/cluster/status");
+ Ok(self.0.get(&url).await?.expect_json()?.data)
+ }
+
/// Generate a new API token for a specific user. NOTE: returns API token
/// value, which needs to be stored as it cannot be retrieved afterwards!
async fn create_token(
diff --git a/pve-api-types/src/generated/types.rs b/pve-api-types/src/generated/types.rs
index ebbb4a0..b6a3d20 100644
--- a/pve-api-types/src/generated/types.rs
+++ b/pve-api-types/src/generated/types.rs
@@ -405,6 +405,120 @@ pub enum ClusterNodeIndexResponseStatus {
serde_plain::derive_display_from_serialize!(ClusterNodeIndexResponseStatus);
serde_plain::derive_fromstr_from_deserialize!(ClusterNodeIndexResponseStatus);
+#[api(
+ properties: {
+ id: {
+ type: String,
+ description: "FIXME: Missing description in PVE.",
+ },
+ ip: {
+ optional: true,
+ type: String,
+ },
+ level: {
+ optional: true,
+ type: String,
+ },
+ local: {
+ default: false,
+ optional: true,
+ },
+ name: {
+ type: String,
+ description: "FIXME: Missing description in PVE.",
+ },
+ nodeid: {
+ optional: true,
+ type: Integer,
+ },
+ nodes: {
+ optional: true,
+ type: Integer,
+ },
+ online: {
+ default: false,
+ optional: true,
+ },
+ quorate: {
+ default: false,
+ optional: true,
+ },
+ type: {
+ type: ClusterNodeStatusType,
+ },
+ version: {
+ optional: true,
+ type: Integer,
+ },
+ },
+)]
+/// Object.
+#[derive(Debug, serde::Deserialize, serde::Serialize)]
+pub struct ClusterNodeStatus {
+ pub id: String,
+
+ /// [node] IP of the resolved nodename.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub ip: Option<String>,
+
+ /// [node] Proxmox VE Subscription level, indicates if eligible for
+ /// enterprise support as well as access to the stable Proxmox VE Enterprise
+ /// Repository.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub level: Option<String>,
+
+ /// [node] Indicates if this is the responding node.
+ #[serde(deserialize_with = "proxmox_login::parse::deserialize_bool")]
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub local: Option<bool>,
+
+ pub name: String,
+
+ /// [node] ID of the node from the corosync configuration.
+ #[serde(deserialize_with = "proxmox_login::parse::deserialize_i64")]
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub nodeid: Option<i64>,
+
+ /// [cluster] Nodes count, including offline nodes.
+ #[serde(deserialize_with = "proxmox_login::parse::deserialize_i64")]
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub nodes: Option<i64>,
+
+ /// [node] Indicates if the node is online or offline.
+ #[serde(deserialize_with = "proxmox_login::parse::deserialize_bool")]
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub online: Option<bool>,
+
+ /// [cluster] Indicates if there is a majority of nodes online to make
+ /// decisions
+ #[serde(deserialize_with = "proxmox_login::parse::deserialize_bool")]
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub quorate: Option<bool>,
+
+ #[serde(rename = "type")]
+ pub ty: ClusterNodeStatusType,
+
+ /// [cluster] Current version of the corosync configuration file.
+ #[serde(deserialize_with = "proxmox_login::parse::deserialize_i64")]
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub version: Option<i64>,
+}
+
+#[api]
+/// Indicates the type, either cluster or node. The type defines the object
+/// properties e.g. quorate available for type cluster.
+#[derive(Clone, Copy, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
+pub enum ClusterNodeStatusType {
+ #[serde(rename = "cluster")]
+ /// cluster.
+ Cluster,
+ #[serde(rename = "node")]
+ /// node.
+ Node,
+}
+serde_plain::derive_display_from_serialize!(ClusterNodeStatusType);
+serde_plain::derive_fromstr_from_deserialize!(ClusterNodeStatusType);
+
const_regex! {
CLUSTER_RESOURCE_NODE_RE = r##"^(?i:[a-z0-9](?i:[a-z0-9\-]*[a-z0-9])?)$"##;
--
2.39.5
More information about the pdm-devel
mailing list