From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 39D2EB421 for ; Wed, 6 Apr 2022 15:09:05 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 307732B540 for ; Wed, 6 Apr 2022 15:08:35 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 954162B535 for ; Wed, 6 Apr 2022 15:08:31 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 6D1A141FCF for ; Wed, 6 Apr 2022 15:08:31 +0200 (CEST) Message-ID: <81a44a2f-4b21-0b78-ef69-071ad7cf2a19@proxmox.com> Date: Wed, 6 Apr 2022 15:08:13 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Content-Language: en-US To: Proxmox Backup Server development discussion , Hannes Laimer References: <20220217171457.72206-1-h.laimer@proxmox.com> <20220217171457.72206-2-h.laimer@proxmox.com> From: Dylan Whyte In-Reply-To: <20220217171457.72206-2-h.laimer@proxmox.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.645 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment NICE_REPLY_A -0.631 Looks like a legit reply (A) SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: Re: [pbs-devel] [PATCH proxmox-backup v9 1/6] api-types: add maintenance type X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Apr 2022 13:09:05 -0000 Minor comments inline: On 2/17/22 18:14, Hannes Laimer wrote: > + bump proxmox-schema dep to 1.2.1 (for quoted property string) > > Signed-off-by: Hannes Laimer > --- > 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, > + /// 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, > +} > + > +impl DataStoreConfig { > + pub fn get_maintenance_mode(&self) -> Option { > + 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(); Is 32 characters enough for the message? I would think this is somewhat limiting, but am open to other opinions. > + > +#[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. docstring: s/reading/read/ > + ReadOnly, > + /// Neither reading nor writing operations are allowed on the datastore. docstring: s/reading/read/ docstring: s/writing/write/ > + 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 docstring: Reword to 'Type of maintenance ("read-only" or "offline").' > + #[serde(rename = "type")] > + ty: MaintenanceType, > + > + /// Reason for the maintenance mode. docstring: Maybe reword to "Reason for maintenance." > + #[serde(skip_serializing_if = "Option::is_none")] > + message: Option, > +}