From: Hannes Laimer <h.laimer@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup v9 1/6] api-types: add maintenance type
Date: Thu, 17 Feb 2022 17:14:52 +0000 [thread overview]
Message-ID: <20220217171457.72206-2-h.laimer@proxmox.com> (raw)
In-Reply-To: <20220217171457.72206-1-h.laimer@proxmox.com>
+ bump proxmox-schema dep to 1.2.1 (for quoted property string)
Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
debian/control | 6 ++--
pbs-api-types/Cargo.toml | 2 +-
pbs-api-types/src/datastore.rs | 24 ++++++++++---
pbs-api-types/src/lib.rs | 3 ++
pbs-api-types/src/maintenance.rs | 59 ++++++++++++++++++++++++++++++++
5 files changed, 86 insertions(+), 8 deletions(-)
create mode 100644 pbs-api-types/src/maintenance.rs
diff --git a/debian/control b/debian/control
index 02a32977..f869d32d 100644
--- a/debian/control
+++ b/debian/control
@@ -56,9 +56,9 @@ Build-Depends: debhelper (>= 12),
librust-proxmox-openid-0.9+default-dev,
librust-proxmox-router-1+cli-dev (>= 1.1-~~),
librust-proxmox-router-1+default-dev (>= 1.1-~~),
- librust-proxmox-schema-1+api-macro-dev (>= 1.1-~~),
- librust-proxmox-schema-1+default-dev (>= 1.1-~~),
- librust-proxmox-schema-1+upid-api-impl-dev (>= 1.1-~~),
+ librust-proxmox-schema-1+api-macro-dev (>= 1.2.1-~~),
+ librust-proxmox-schema-1+default-dev (>= 1.2.1-~~),
+ librust-proxmox-schema-1+upid-api-impl-dev (>= 1.2.1-~~),
librust-proxmox-section-config-1+default-dev,
librust-proxmox-serde-0.1+default-dev,
librust-proxmox-shared-memory-0.2+default-dev,
diff --git a/pbs-api-types/Cargo.toml b/pbs-api-types/Cargo.toml
index e77d8bc4..1a98b09d 100644
--- a/pbs-api-types/Cargo.toml
+++ b/pbs-api-types/Cargo.toml
@@ -14,7 +14,7 @@ regex = "1.2"
serde = { version = "1.0", features = ["derive"] }
proxmox-lang = "1.0.0"
-proxmox-schema = { version = "1.1", features = [ "api-macro" ] }
+proxmox-schema = { version = "1.2.1", features = [ "api-macro" ] }
proxmox-serde = "0.1"
proxmox-time = "1.1.1"
proxmox-uuid = { version = "1.0.0", features = [ "serde" ] }
diff --git a/pbs-api-types/src/datastore.rs b/pbs-api-types/src/datastore.rs
index 36279b3a..7a2d6ae2 100644
--- a/pbs-api-types/src/datastore.rs
+++ b/pbs-api-types/src/datastore.rs
@@ -6,10 +6,9 @@ use proxmox_schema::{
};
use crate::{
- PROXMOX_SAFE_ID_FORMAT, SHA256_HEX_REGEX, SINGLE_LINE_COMMENT_SCHEMA, CryptMode, UPID,
- Fingerprint, Userid, Authid,
- GC_SCHEDULE_SCHEMA, DATASTORE_NOTIFY_STRING_SCHEMA, PRUNE_SCHEDULE_SCHEMA,
-
+ Authid, CryptMode, Fingerprint, MaintenanceMode, Userid, DATASTORE_NOTIFY_STRING_SCHEMA,
+ GC_SCHEDULE_SCHEMA, PROXMOX_SAFE_ID_FORMAT, PRUNE_SCHEDULE_SCHEMA, SHA256_HEX_REGEX,
+ SINGLE_LINE_COMMENT_SCHEMA, UPID,
};
const_regex!{
@@ -224,6 +223,11 @@ pub struct PruneOptions {
optional: true,
type: bool,
},
+ "maintenance-mode": {
+ optional: true,
+ format: &ApiStringFormat::PropertyString(&MaintenanceMode::API_SCHEMA),
+ type: String,
+ },
}
)]
#[derive(Serialize,Deserialize,Updater)]
@@ -261,6 +265,18 @@ pub struct DataStoreConfig {
/// Send notification only for job errors
#[serde(skip_serializing_if="Option::is_none")]
pub notify: Option<String>,
+ /// Maintenance mode, type is either 'offline' or 'read-only', message should be enclosed in "
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub maintenance_mode: Option<String>,
+}
+
+impl DataStoreConfig {
+ pub fn get_maintenance_mode(&self) -> Option<MaintenanceMode> {
+ self.maintenance_mode
+ .as_ref()
+ .and_then(|str| MaintenanceMode::API_SCHEMA.parse_property_string(str).ok())
+ .and_then(|value| MaintenanceMode::deserialize(value).ok())
+ }
}
#[api(
diff --git a/pbs-api-types/src/lib.rs b/pbs-api-types/src/lib.rs
index 754e7b22..efb01c3e 100644
--- a/pbs-api-types/src/lib.rs
+++ b/pbs-api-types/src/lib.rs
@@ -49,6 +49,9 @@ pub use jobs::*;
mod key_derivation;
pub use key_derivation::{Kdf, KeyInfo};
+mod maintenance;
+pub use maintenance::*;
+
mod network;
pub use network::*;
diff --git a/pbs-api-types/src/maintenance.rs b/pbs-api-types/src/maintenance.rs
new file mode 100644
index 00000000..19883e46
--- /dev/null
+++ b/pbs-api-types/src/maintenance.rs
@@ -0,0 +1,59 @@
+use serde::{Deserialize, Serialize};
+
+use proxmox_schema::{api, ApiStringFormat, const_regex, Schema, StringSchema};
+
+const_regex!{
+ pub MAINTENANCE_MESSAGE_REGEX = r"^[[:^cntrl:]]*$";
+}
+
+pub const MAINTENANCE_MESSAGE_FORMAT: ApiStringFormat =
+ ApiStringFormat::Pattern(&MAINTENANCE_MESSAGE_REGEX);
+
+
+pub const MAINTENANCE_MESSAGE_SCHEMA: Schema =
+ StringSchema::new("Message describing the reason for the maintenance.")
+ .format(&MAINTENANCE_MESSAGE_FORMAT)
+ .max_length(32)
+ .schema();
+
+#[derive(Clone, Copy, Debug)]
+/// Operation requirements, used when checking for maintenance mode.
+pub enum Operation {
+ Read,
+ Write,
+}
+
+#[api]
+#[derive(Deserialize, Serialize)]
+#[serde(rename_all="kebab-case")]
+/// Maintenance type.
+pub enum MaintenanceType {
+ /// Only reading operations are allowed on the datastore.
+ ReadOnly,
+ /// Neither reading nor writing operations are allowed on the datastore.
+ Offline,
+}
+
+#[api(
+ properties: {
+ type: {
+ type: MaintenanceType,
+ },
+ message: {
+ optional: true,
+ schema: MAINTENANCE_MESSAGE_SCHEMA,
+ }
+ },
+ default_key: "type",
+)]
+#[derive(Deserialize, Serialize)]
+/// Maintenance mode
+pub struct MaintenanceMode {
+ /// Type of the maintenance
+ #[serde(rename = "type")]
+ ty: MaintenanceType,
+
+ /// Reason for the maintenance mode.
+ #[serde(skip_serializing_if = "Option::is_none")]
+ message: Option<String>,
+}
--
2.30.2
next prev parent reply other threads:[~2022-02-17 17:15 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-17 17:14 [pbs-devel] [PATCH proxmox-backup v9 0/6] closes #3071: maintenance mode for datastore Hannes Laimer
2022-02-17 17:14 ` Hannes Laimer [this message]
2022-04-06 13:08 ` [pbs-devel] [PATCH proxmox-backup v9 1/6] api-types: add maintenance type Dylan Whyte
2022-04-11 7:33 ` Thomas Lamprecht
2022-02-17 17:14 ` [pbs-devel] [PATCH proxmox-backup v9 2/6] datastore: add check for maintenance in lookup Hannes Laimer
2022-04-06 13:08 ` Dylan Whyte
2022-02-17 17:14 ` [pbs-devel] [PATCH proxmox-backup v9 3/6] pbs-datastore: add active operations tracking Hannes Laimer
2022-02-17 17:14 ` [pbs-devel] [PATCH proxmox-backup v9 4/6] api: make maintenance_type updatable Hannes Laimer
2022-02-17 17:14 ` [pbs-devel] [PATCH proxmox-backup v9 5/6] api: add get_active_operations endpoint Hannes Laimer
2022-02-17 17:14 ` [pbs-devel] [PATCH proxmox-backup v9 6/6] ui: add option to change the maintenance type Hannes Laimer
2022-04-06 13:08 ` [pbs-devel] [PATCH proxmox-backup v9 0/6] closes #3071: maintenance mode for datastore Dylan Whyte
2022-04-11 7:35 ` Thomas Lamprecht
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=20220217171457.72206-2-h.laimer@proxmox.com \
--to=h.laimer@proxmox.com \
--cc=pbs-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