From 41c039e1435b6757fd72d76531e3b3fe93553b75 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Mon, 21 Jan 2019 18:58:14 +0100 Subject: [PATCH] bin/proxmox-backup-client.rs: implement list command --- src/bin/proxmox-backup-client.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/bin/proxmox-backup-client.rs b/src/bin/proxmox-backup-client.rs index bc9e9b76..7ee5d0e3 100644 --- a/src/bin/proxmox-backup-client.rs +++ b/src/bin/proxmox-backup-client.rs @@ -65,6 +65,19 @@ fn backup_image(datastore: &DataStore, file: &std::fs::File, size: usize, target } */ +fn list_backups(param: Value, _info: &ApiMethod) -> Result { + + let store = tools::required_string_param(¶m, "store")?; + + let client = HttpClient::new("localhost"); + + let path = format!("api3/json/admin/datastore/{}/backups", store); + + let result = client.get(&path)?; + + Ok(result) +} + fn create_backup(param: Value, _info: &ApiMethod) -> Result { let filename = tools::required_string_param(¶m, "filename")?; @@ -121,7 +134,7 @@ fn create_backup(param: Value, _info: &ApiMethod) -> Result { fn main() { - let cmd_def = CliCommand::new( + let create_cmd_def = CliCommand::new( ApiMethod::new( create_backup, ObjectSchema::new("Create backup.") @@ -140,6 +153,19 @@ fn main() { .completion_cb("filename", tools::complete_file_name) .completion_cb("store", proxmox_backup::config::datastore::complete_datastore_name); + let list_cmd_def = CliCommand::new( + ApiMethod::new( + list_backups, + ObjectSchema::new("List backups.") + .required("store", StringSchema::new("Datastore name.")) + )) + .arg_param(vec!["store"]) + .completion_cb("store", proxmox_backup::config::datastore::complete_datastore_name); + + + let cmd_def = CliCommandMap::new() + .insert("create".to_owned(), create_cmd_def.into()) + .insert("list".to_owned(), list_cmd_def.into()); if let Err(err) = run_cli_command(&cmd_def.into()) { eprintln!("Error: {}", err);