src/bin/proxmox-backup-client.rs - status: use format_and_print_result_full
This commit is contained in:
parent
03ac286c80
commit
390c5bdde4
@ -1470,24 +1470,28 @@ async fn status(param: Value) -> Result<Value, Error> {
|
|||||||
let path = format!("api2/json/admin/datastore/{}/status", repo.store());
|
let path = format!("api2/json/admin/datastore/{}/status", repo.store());
|
||||||
|
|
||||||
let mut result = client.get(&path, None).await?;
|
let mut result = client.get(&path, None).await?;
|
||||||
|
let mut data = result["data"].take();
|
||||||
|
|
||||||
record_repository(&repo);
|
record_repository(&repo);
|
||||||
|
|
||||||
if output_format == "text" {
|
let render_total_percentage = |v: &Value, record: &Value| -> Result<String, Error> {
|
||||||
let result: StorageStatus = serde_json::from_value(result["data"].take())?;
|
let v = v.as_u64().unwrap();
|
||||||
|
let total = record["total"].as_u64().unwrap();
|
||||||
|
let roundup = total/200;
|
||||||
|
let per = ((v+roundup)*100)/total;
|
||||||
|
Ok(format!("{} ({} %)", v, per))
|
||||||
|
};
|
||||||
|
|
||||||
let roundup = result.total/200;
|
let options = TableFormatOptions::new()
|
||||||
|
.noborder(false)
|
||||||
|
.noheader(false)
|
||||||
|
.column(ColumnConfig::new("total"))
|
||||||
|
.column(ColumnConfig::new("used").renderer(render_total_percentage))
|
||||||
|
.column(ColumnConfig::new("avail").renderer(render_total_percentage));
|
||||||
|
|
||||||
println!(
|
let schema = &proxmox_backup::api2::types::StorageStatus::API_SCHEMA;
|
||||||
"total: {} used: {} ({} %) available: {}",
|
|
||||||
result.total,
|
format_and_print_result_full(&mut data, schema, &output_format, &options);
|
||||||
result.used,
|
|
||||||
((result.used+roundup)*100)/result.total,
|
|
||||||
result.avail,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
format_and_print_result(&result["data"], &output_format);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(Value::Null)
|
Ok(Value::Null)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user