From db1e061dcb30c167f579c0ffb20f0842a50be87d Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 5 May 2020 06:45:37 +0200 Subject: [PATCH] src/bin/proxmox-backup-client.rs: correctly format prune result list. --- src/api2/admin/datastore.rs | 10 ++++++++-- src/api2/types.rs | 24 ++++++++++++++++++++++++ src/bin/proxmox-backup-client.rs | 22 ++++++++++++++++++++-- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index fa7aacd8..3203734c 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -455,6 +455,11 @@ macro_rules! add_common_prune_prameters { } } +pub const API_RETURN_SCHEMA_PRUNE: Schema = ArraySchema::new( + "Returns the list of snapshots and a flag indicating if there are kept or removed.", + PruneListItem::API_SCHEMA +).schema(); + const API_METHOD_PRUNE: ApiMethod = ApiMethod::new( &ApiHandler::Sync(&prune), &ObjectSchema::new( @@ -469,8 +474,9 @@ const API_METHOD_PRUNE: ApiMethod = ApiMethod::new( ],[ ("store", false, &DATASTORE_SCHEMA), ]) - ) -).access(None, &Permission::Privilege( + )) + .returns(&API_RETURN_SCHEMA_PRUNE) + .access(None, &Permission::Privilege( &["datastore", "{store}"], PRIV_DATASTORE_MODIFY | PRIV_DATASTORE_PRUNE, true) diff --git a/src/api2/types.rs b/src/api2/types.rs index bfd94601..62345d76 100644 --- a/src/api2/types.rs +++ b/src/api2/types.rs @@ -391,6 +391,30 @@ pub struct SnapshotListItem { pub size: Option, } +#[api( + properties: { + "backup-type": { + schema: BACKUP_TYPE_SCHEMA, + }, + "backup-id": { + schema: BACKUP_ID_SCHEMA, + }, + "backup-time": { + schema: BACKUP_TIME_SCHEMA, + }, + }, +)] +#[derive(Serialize, Deserialize)] +#[serde(rename_all="kebab-case")] +/// Prune result. +pub struct PruneListItem { + pub backup_type: String, // enum + pub backup_id: String, + pub backup_time: i64, + /// Keep snapshot + pub keep: bool, +} + #[api( properties: { "filename": { diff --git a/src/bin/proxmox-backup-client.rs b/src/bin/proxmox-backup-client.rs index 474a0ca5..5f45ebb9 100644 --- a/src/bin/proxmox-backup-client.rs +++ b/src/bin/proxmox-backup-client.rs @@ -1424,11 +1424,29 @@ async fn prune_async(mut param: Value) -> Result { param["backup-type"] = group.backup_type().into(); param["backup-id"] = group.backup_id().into(); - let result = client.post(&path, Some(param)).await?; + let mut result = client.post(&path, Some(param)).await?; record_repository(&repo); - view_task_result(client, result, &output_format).await?; + let render_snapshot_path = |_v: &Value, record: &Value| -> Result { + let item: PruneListItem = serde_json::from_value(record.to_owned())?; + let snapshot = BackupDir::new(item.backup_type, item.backup_id, item.backup_time); + Ok(snapshot.relative_path().to_str().unwrap().to_owned()) + }; + + let options = default_table_format_options() + .sortby("backup-type", false) + .sortby("backup-id", false) + .sortby("backup-time", false) + .column(ColumnConfig::new("backup-id").renderer(render_snapshot_path).header("snapshot")) + .column(ColumnConfig::new("keep")) + ; + + let info = &proxmox_backup::api2::admin::datastore::API_RETURN_SCHEMA_PRUNE; + + let mut data = result["data"].take(); + + format_and_print_result_full(&mut data, info, &output_format, &options); Ok(Value::Null) }