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 C99341FF15F for ; Mon, 21 Oct 2024 14:55:05 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 48DC4344E0; Mon, 21 Oct 2024 14:55:43 +0200 (CEST) From: Christian Ebner To: pbs-devel@lists.proxmox.com Date: Mon, 21 Oct 2024 14:55:20 +0200 Message-Id: <20241021125522.237273-2-c.ebner@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241021125522.237273-1-c.ebner@proxmox.com> References: <20241021125522.237273-1-c.ebner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.027 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_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup 1/3] api-types: client: add type to specify progress log interval 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: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" Implements the `LogInterval` api type, which will be used to specify the log progress output interval for the proxmox backup client's backup command. Currently, 3 variants of progress log output are allowed: - none - time based - size based Further, implements the methods to parse the string given as API parameter into the corresponding variant and value. The time based variant allows to specify an interval given by a `TimeSpan` compatible value, the size based variant allows to specify `HumanByte` compatible interval. If no explicit variant is specified, the time based variant is used. Possible parameter values are therefore, e.g.: - `none` to set no interval (disable logging) - `1m 30s` to set a time based interval, alternatively the variant might be declared explicitly as `time:1m 30s`. - `size:512MiB` to set a size based log interval Signed-off-by: Christian Ebner --- pbs-api-types/src/client.rs | 73 +++++++++++++++++++++++++++++++++++++ pbs-api-types/src/lib.rs | 3 ++ 2 files changed, 76 insertions(+) create mode 100644 pbs-api-types/src/client.rs diff --git a/pbs-api-types/src/client.rs b/pbs-api-types/src/client.rs new file mode 100644 index 000000000..ecc4ad692 --- /dev/null +++ b/pbs-api-types/src/client.rs @@ -0,0 +1,73 @@ +use std::str::FromStr; + +use anyhow::{bail, Error}; + +use proxmox_human_byte::HumanByte; +use proxmox_schema::{const_regex, ApiStringFormat, ApiType, Schema, StringSchema}; +use proxmox_time::TimeSpan; + +const_regex! { + pub LOG_INTERVAL_REGEX = r"^((none|(size|time):)?[0-9a-z\.\s]*)$"; +} + +pub const LOG_INTERVAL_FORMAT: ApiStringFormat = ApiStringFormat::Pattern(&LOG_INTERVAL_REGEX); +pub const LOG_INTERVAL_SCHEMA: Schema = StringSchema::new("Log interval") + .format(&ApiStringFormat::VerifyFn(verify_log_interval)) + .type_text("(none|[(size|time):]value) (default 'time:60s')") + .schema(); + +#[derive(Clone)] +pub enum LogInterval { + None, + Size(HumanByte), + Time(TimeSpan), +} + +impl Default for LogInterval { + fn default() -> Self { + Self::Time(TimeSpan::from_str("60s").unwrap()) + } +} + +impl ApiType for LogInterval { + const API_SCHEMA: Schema = LOG_INTERVAL_SCHEMA; +} + +pub fn verify_log_interval(value: &str) -> Result<(), Error> { + let _: LogInterval = value.parse()?; + Ok(()) +} + +impl FromStr for LogInterval { + type Err = Error; + + fn from_str(v: &str) -> Result { + let mut split = v.split(':'); + let interval = match (split.next(), split.next()) { + (Some("none"), None) => LogInterval::None, + // Default to time if no explicit variant set + (Some(value), None) => LogInterval::Time(TimeSpan::from_str(value)?), + (Some(variant), Some(value)) => match variant { + "size" => LogInterval::Size(HumanByte::from_str(value)?), + "time" => LogInterval::Time(TimeSpan::from_str(value)?), + variant => bail!(format!("unexpected log interval variant '{variant}'")), + }, + _ => bail!("expected '(none|[variant:]value)'"), + }; + + Ok(interval) + } +} + +impl std::fmt::Display for LogInterval { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + LogInterval::None => write!(f, "none"), + LogInterval::Size(value) => write!(f, "size:{value}"), + LogInterval::Time(value) => write!(f, "time:{value}"), + } + } +} + +proxmox_serde::forward_serialize_to_display!(LogInterval); +proxmox_serde::forward_deserialize_to_from_str!(LogInterval); diff --git a/pbs-api-types/src/lib.rs b/pbs-api-types/src/lib.rs index 635292a54..e2eb2f5c6 100644 --- a/pbs-api-types/src/lib.rs +++ b/pbs-api-types/src/lib.rs @@ -93,6 +93,9 @@ pub const GROUP_OR_SNAPSHOT_PATH_REGEX_STR: &str = mod acl; pub use acl::*; +mod client; +pub use client::*; + mod datastore; pub use datastore::*; -- 2.39.5 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel