api: make expensive parts of datastore status opt-in

used in the PBS GUI, but also for PVE usage queries which don't need all
the extra expensive information..

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler
2020-11-12 11:30:31 +01:00
committed by Wolfgang Bumiller
parent 0d08fceeb9
commit 98afc7b152
3 changed files with 27 additions and 7 deletions

View File

@ -525,7 +525,14 @@ fn get_snapshots_count(store: &DataStore) -> Result<Counts, Error> {
store: {
schema: DATASTORE_SCHEMA,
},
verbose: {
type: bool,
default: false,
optional: true,
description: "Include additional information like snapshot counts and GC status.",
},
},
},
returns: {
type: DataStoreStatus,
@ -537,13 +544,18 @@ fn get_snapshots_count(store: &DataStore) -> Result<Counts, Error> {
/// Get datastore status.
pub fn status(
store: String,
verbose: bool,
_info: &ApiMethod,
_rpcenv: &mut dyn RpcEnvironment,
) -> Result<DataStoreStatus, Error> {
let datastore = DataStore::lookup_datastore(&store)?;
let storage = crate::tools::disks::disk_usage(&datastore.base_path())?;
let counts = get_snapshots_count(&datastore)?;
let gc_status = datastore.last_gc_status();
let (counts, gc_status) = match verbose {
true => {
(Some(get_snapshots_count(&datastore)?), Some(datastore.last_gc_status()))
},
false => (None, None),
};
Ok(DataStoreStatus {
total: storage.total,