From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com, pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup v2 1/1] client: add 'snapshot notes show/update' command
Date: Tue, 24 Nov 2020 10:09:29 +0100 [thread overview]
Message-ID: <20201124090936.21810-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20201124090936.21810-1-d.csapak@proxmox.com>
to show and update snapshot notes from the cli
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
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<Value, Error> {
+ let repo = extract_repository_from_value(¶m)?;
+ let path = tools::required_string_param(¶m, "snapshot")?;
+
+ 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<Value, Error> {
+ 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
next prev parent reply other threads:[~2020-11-24 9:09 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-24 9:09 [pbs-devel] [PATCH proxmox-backup/pve-storage/pve-manager v2] show/edit backup comments Dominik Csapak
2020-11-24 9:09 ` Dominik Csapak [this message]
2020-11-24 9:52 ` [pbs-devel] [pve-devel] [PATCH proxmox-backup v2 1/1] client: add 'snapshot notes show/update' command Wolfgang Bumiller
2020-11-24 12:28 ` [pbs-devel] applied: " Dietmar Maurer
2020-11-24 9:09 ` [pbs-devel] [PATCH storage v2 1/4] rename comment to notes Dominik Csapak
2020-11-24 9:09 ` [pbs-devel] [PATCH storage v2 2/4] api2/storage/content: change to volume_size_info and add return properties Dominik Csapak
2020-11-24 9:09 ` [pbs-devel] [PATCH storage v2 3/4] Storage/Plugin: add get/update_volume_comment and implement for dir Dominik Csapak
2020-11-24 9:09 ` [pbs-devel] [PATCH storage v2 4/4] Storage/PBSPlugin: implement get/update_volume_notes for pbs Dominik Csapak
2020-11-24 9:09 ` [pbs-devel] [PATCH manager v2 1/3] ui: change comment column to notes Dominik Csapak
2020-11-24 9:09 ` [pbs-devel] [PATCH manager v2 2/3] ui: add ability to show and edit comments for backups Dominik Csapak
2020-11-24 9:09 ` [pbs-devel] [PATCH manager v2 3/3] ui: enable notesedit for pbs Dominik Csapak
2021-03-25 8:22 ` [pbs-devel] applied: [pve-devel] " Thomas Lamprecht
2020-11-24 13:11 ` [pbs-devel] applied-partially: [pve-devel] [PATCH proxmox-backup/pve-storage/pve-manager v2] show/edit backup comments 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=20201124090936.21810-2-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
--cc=pve-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