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 08B936290A; Tue, 24 Nov 2020 10:52:41 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 061809D0C; Tue, 24 Nov 2020 10:52:41 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (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 5F0C49D02; Tue, 24 Nov 2020 10:52:40 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 2AFA64406C; Tue, 24 Nov 2020 10:52:40 +0100 (CET) Date: Tue, 24 Nov 2020 10:52:39 +0100 From: Wolfgang Bumiller To: Dominik Csapak Cc: pve-devel@lists.proxmox.com, pbs-devel@lists.proxmox.com Message-ID: <20201124095238.rcicp7q2cy7f4k3f@wobu-vie.proxmox.com> References: <20201124090936.21810-1-d.csapak@proxmox.com> <20201124090936.21810-2-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201124090936.21810-2-d.csapak@proxmox.com> User-Agent: NeoMutt/20180716 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.024 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [snapshot.rs, proxmox-backup-client.rs, mod.rs] Subject: Re: [pve-devel] [PATCH proxmox-backup v2 1/1] client: add 'snapshot notes show/update' command X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Nov 2020 09:52:41 -0000 On Tue, Nov 24, 2020 at 10:09:29AM +0100, Dominik Csapak wrote: > to show and update snapshot notes from the cli > > Signed-off-by: Dominik Csapak > --- > src/bin/proxmox-backup-client.rs | 1 + > src/bin/proxmox_backup_client/mod.rs | 2 + > src/bin/proxmox_backup_client/snapshot.rs | 126 ++++++++++++++++++++++ > 3 files changed, 129 insertions(+) > create mode 100644 src/bin/proxmox_backup_client/snapshot.rs > > diff --git a/src/bin/proxmox-backup-client.rs b/src/bin/proxmox-backup-client.rs > index c961e390..f8a3fe70 100644 > --- a/src/bin/proxmox-backup-client.rs > +++ b/src/bin/proxmox-backup-client.rs > @@ -2110,6 +2110,7 @@ fn main() { > .insert("prune", prune_cmd_def) > .insert("restore", restore_cmd_def) > .insert("snapshots", snapshots_cmd_def) > + .insert("snapshot", snapshot_mgtm_cli()) > .insert("files", files_cmd_def) > .insert("status", status_cmd_def) > .insert("key", key::cli()) > diff --git a/src/bin/proxmox_backup_client/mod.rs b/src/bin/proxmox_backup_client/mod.rs > index 0c4bffb9..a14b0dc1 100644 > --- a/src/bin/proxmox_backup_client/mod.rs > +++ b/src/bin/proxmox_backup_client/mod.rs > @@ -8,6 +8,8 @@ mod task; > pub use task::*; > mod catalog; > pub use catalog::*; > +mod snapshot; > +pub use snapshot::*; > > pub mod key; > > diff --git a/src/bin/proxmox_backup_client/snapshot.rs b/src/bin/proxmox_backup_client/snapshot.rs > new file mode 100644 > index 00000000..fd5f543b > --- /dev/null > +++ b/src/bin/proxmox_backup_client/snapshot.rs > @@ -0,0 +1,126 @@ > +use anyhow::Error; > +use serde_json::{json, Value}; > + > +use proxmox::api::{api, cli::*}; > +use proxmox_backup::tools; > + > +use crate::{ > + complete_backup_snapshot, connect, extract_repository_from_value, BackupDir, REPO_URL_SCHEMA, > +}; > + > +#[api( > + input: { > + properties: { > + repository: { > + schema: REPO_URL_SCHEMA, > + optional: true, > + }, > + snapshot: { > + type: String, > + description: "Snapshot path.", > + }, > + "output-format": { > + schema: OUTPUT_FORMAT, > + optional: true, > + }, > + } > + } > +)] > +/// Show notes > +async fn show_notes(param: Value) -> Result { > + let repo = extract_repository_from_value(¶m)?; > + let path = tools::required_string_param(¶m, "snapshot")?; ^ FYI a mix of regular params with a catch-all `param: Value` should also work with an `#[api]` fn. > + > + let snapshot: BackupDir = path.parse()?; > + let client = connect(&repo)?; > + > + let path = format!("api2/json/admin/datastore/{}/notes", repo.store()); > + > + let args = json!({ > + "backup-type": snapshot.group().backup_type(), > + "backup-id": snapshot.group().backup_id(), > + "backup-time": snapshot.backup_time(), > + }); > + > + let output_format = get_output_format(¶m); > + > + let mut result = client.get(&path, Some(args)).await?; > + > + let notes = result["data"].take(); > + > + if output_format == "text" { > + if let Some(notes) = notes.as_str() { > + println!("{}", notes); > + } > + } else { > + format_and_print_result( > + &json!({ > + "notes": notes, > + }), > + &output_format, > + ); > + } > + > + Ok(Value::Null) > +} > + > +#[api( > + input: { > + properties: { > + repository: { > + schema: REPO_URL_SCHEMA, > + optional: true, > + }, > + snapshot: { > + type: String, > + description: "Snapshot path.", > + }, > + notes: { > + type: String, > + description: "The Notes.", > + }, > + } > + } > +)] > +/// Update Notes > +async fn update_notes(param: Value) -> Result { > + let repo = extract_repository_from_value(¶m)?; > + let path = tools::required_string_param(¶m, "snapshot")?; > + let notes = tools::required_string_param(¶m, "notes")?; > + > + let snapshot: BackupDir = path.parse()?; > + let mut client = connect(&repo)?; > + > + let path = format!("api2/json/admin/datastore/{}/notes", repo.store()); > + > + let args = json!({ > + "backup-type": snapshot.group().backup_type(), > + "backup-id": snapshot.group().backup_id(), > + "backup-time": snapshot.backup_time(), > + "notes": notes, > + }); > + > + client.put(&path, Some(args)).await?; > + > + Ok(Value::Null) > +} > + > +fn notes_cli() -> CliCommandMap { > + CliCommandMap::new() > + .insert( > + "show", > + CliCommand::new(&API_METHOD_SHOW_NOTES) > + .arg_param(&["snapshot"]) > + .completion_cb("snapshot", complete_backup_snapshot), > + ) > + .insert( > + "update", > + CliCommand::new(&API_METHOD_UPDATE_NOTES) > + .arg_param(&["snapshot", "notes"]) > + .completion_cb("snapshot", complete_backup_snapshot), > + ) > +} > + > +pub fn snapshot_mgtm_cli() -> CliCommandMap { > + CliCommandMap::new().insert("notes", notes_cli()) > +} > -- > 2.20.1