mirror of
https://git.proxmox.com/git/proxmox-offline-mirror
synced 2025-08-07 19:47:43 +00:00
cli: allow listing snapshots of all mirrors
and slightly change the output format accordingly. Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
parent
d056f823f0
commit
a0a1cae4b4
@ -3,7 +3,10 @@ use anyhow::{bail, format_err, Error};
|
|||||||
use proxmox_section_config::SectionConfigData;
|
use proxmox_section_config::SectionConfigData;
|
||||||
use proxmox_subscription::SubscriptionStatus;
|
use proxmox_subscription::SubscriptionStatus;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use std::{collections::HashMap, path::PathBuf};
|
use std::{
|
||||||
|
collections::{BTreeMap, HashMap},
|
||||||
|
path::PathBuf,
|
||||||
|
};
|
||||||
|
|
||||||
use proxmox_router::cli::{
|
use proxmox_router::cli::{
|
||||||
format_and_print_result, get_output_format, CliCommand, CliCommandMap, CommandLineInterface,
|
format_and_print_result, get_output_format, CliCommand, CliCommandMap, CommandLineInterface,
|
||||||
@ -174,6 +177,7 @@ async fn create_snapshots(
|
|||||||
},
|
},
|
||||||
id: {
|
id: {
|
||||||
schema: MIRROR_ID_SCHEMA,
|
schema: MIRROR_ID_SCHEMA,
|
||||||
|
optional: true,
|
||||||
},
|
},
|
||||||
"output-format": {
|
"output-format": {
|
||||||
schema: OUTPUT_FORMAT,
|
schema: OUTPUT_FORMAT,
|
||||||
@ -183,25 +187,54 @@ async fn create_snapshots(
|
|||||||
},
|
},
|
||||||
)]
|
)]
|
||||||
/// List existing repository 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 output_format = get_output_format(¶m);
|
||||||
let config = config.unwrap_or_else(get_config_path);
|
let config = config.unwrap_or_else(get_config_path);
|
||||||
|
|
||||||
let (config, _digest) = proxmox_offline_mirror::config::config(&config)?;
|
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" {
|
if output_format == "text" {
|
||||||
println!("Found {} snapshots:", list.len());
|
let mut first = true;
|
||||||
for snap in &list {
|
for (mirror, list) in res {
|
||||||
println!("- {snap}");
|
if first {
|
||||||
|
first = false;
|
||||||
|
} else {
|
||||||
|
println!();
|
||||||
|
}
|
||||||
|
println!("{mirror} ({} snapshots):", list.len());
|
||||||
|
for snap in &list {
|
||||||
|
println!("- {snap}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let list = serde_json::json!(list);
|
let map = serde_json::json!(res);
|
||||||
format_and_print_result(&list, &output_format);
|
format_and_print_result(&map, &output_format);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user