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 28CAE941C1 for ; Wed, 21 Sep 2022 10:13:01 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 2688424D43 for ; Wed, 21 Sep 2022 10:13:01 +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 for ; Wed, 21 Sep 2022 10:13:00 +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 54F9D442A9 for ; Wed, 21 Sep 2022 10:13:00 +0200 (CEST) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pve-devel@lists.proxmox.com Date: Wed, 21 Sep 2022 10:12:42 +0200 Message-Id: <20220921081242.1139249-5-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220921081242.1139249-1-f.gruenbichler@proxmox.com> References: <20220921081242.1139249-1-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.148 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 SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH proxmox-offline-mirror 4/4] cli: allow listing snapshots of all mirrors 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: Wed, 21 Sep 2022 08:13:01 -0000 and slightly change the output format accordingly. Signed-off-by: Fabian Grünbichler --- 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, id: String, param: Value) -> Result<(), Error> { +async fn list_snapshots( + config: Option, + id: Option, + 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 = 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