From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH proxmox-offline-mirror 4/4] cli: allow listing snapshots of all mirrors
Date: Wed, 21 Sep 2022 10:12:42 +0200 [thread overview]
Message-ID: <20220921081242.1139249-5-f.gruenbichler@proxmox.com> (raw)
In-Reply-To: <20220921081242.1139249-1-f.gruenbichler@proxmox.com>
and slightly change the output format accordingly.
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
technically a breaking change -> the json is now a map mirror ID => list
of snapshots, instead of a plain list of snapshots..
src/bin/proxmox_offline_mirror_cmds/mirror.rs | 53 +++++++++++++++----
1 file changed, 43 insertions(+), 10 deletions(-)
diff --git a/src/bin/proxmox_offline_mirror_cmds/mirror.rs b/src/bin/proxmox_offline_mirror_cmds/mirror.rs
index 348392b..a3fb258 100644
--- a/src/bin/proxmox_offline_mirror_cmds/mirror.rs
+++ b/src/bin/proxmox_offline_mirror_cmds/mirror.rs
@@ -3,7 +3,10 @@ use anyhow::{bail, format_err, Error};
use proxmox_section_config::SectionConfigData;
use proxmox_subscription::SubscriptionStatus;
use serde_json::Value;
-use std::{collections::HashMap, path::PathBuf};
+use std::{
+ collections::{BTreeMap, HashMap},
+ path::PathBuf,
+};
use proxmox_router::cli::{
format_and_print_result, get_output_format, CliCommand, CliCommandMap, CommandLineInterface,
@@ -174,6 +177,7 @@ async fn create_snapshots(
},
id: {
schema: MIRROR_ID_SCHEMA,
+ optional: true,
},
"output-format": {
schema: OUTPUT_FORMAT,
@@ -183,25 +187,54 @@ async fn create_snapshots(
},
)]
/// List existing repository snapshots.
-async fn list_snapshots(config: Option<String>, id: String, param: Value) -> Result<(), Error> {
+async fn list_snapshots(
+ config: Option<String>,
+ id: Option<String>,
+ param: Value,
+) -> Result<(), Error> {
let output_format = get_output_format(¶m);
let config = config.unwrap_or_else(get_config_path);
let (config, _digest) = proxmox_offline_mirror::config::config(&config)?;
- let config: MirrorConfig = config.lookup("mirror", &id)?;
+ let res = if let Some(id) = id {
+ let config: MirrorConfig = config.lookup("mirror", &id)?;
- let list = mirror::list_snapshots(&config)?;
+ let list = mirror::list_snapshots(&config)?;
+ let mut map = BTreeMap::new();
+ map.insert(config.id, list);
+ map
+ } else {
+ let mirrors: Vec<MirrorConfig> = config.convert_to_typed_array("mirror")?;
+ mirrors
+ .into_iter()
+ .fold(BTreeMap::new(), |mut map, mirror| {
+ match mirror::list_snapshots(&mirror) {
+ Ok(list) => {
+ map.insert(mirror.id, list);
+ }
+ Err(err) => eprintln!("Failed to list snapshots for {} - {err}", mirror.id),
+ }
+ map
+ })
+ };
if output_format == "text" {
- println!("Found {} snapshots:", list.len());
- for snap in &list {
- println!("- {snap}");
+ let mut first = true;
+ for (mirror, list) in res {
+ if first {
+ first = false;
+ } else {
+ println!();
+ }
+ println!("{mirror} ({} snapshots):", list.len());
+ for snap in &list {
+ println!("- {snap}");
+ }
}
} else {
- let list = serde_json::json!(list);
- format_and_print_result(&list, &output_format);
+ let map = serde_json::json!(res);
+ format_and_print_result(&map, &output_format);
}
-
Ok(())
}
--
2.30.2
next prev parent reply other threads:[~2022-09-21 8:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-21 8:12 [pve-devel] [PATCH proxmox-offline-mirror 0/4] extend/add commands Fabian Grünbichler
2022-09-21 8:12 ` [pve-devel] [PATCH proxmox-offline-mirror 1/4] pool: add diff and list helpers Fabian Grünbichler
2022-09-21 8:12 ` [pve-devel] [PATCH proxmox-offline-mirror 2/4] snapshots: add diff command Fabian Grünbichler
2022-09-21 8:12 ` [pve-devel] [PATCH proxmox-offline-mirror 3/4] medium: " Fabian Grünbichler
2022-09-21 8:12 ` Fabian Grünbichler [this message]
2022-09-26 7:51 ` [pve-devel] applied-series: [PATCH proxmox-offline-mirror 0/4] extend/add commands Wolfgang Bumiller
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=20220921081242.1139249-5-f.gruenbichler@proxmox.com \
--to=f.gruenbichler@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