From 997c96d6a355cbf012fede865ef988123046c894 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Thu, 26 May 2022 13:33:58 +0200 Subject: [PATCH] datastore status: impl empty-status constructor for item type we can now use it for the error case and will further use it for the can access namespace but not datastore case in a future patch Signed-off-by: Thomas Lamprecht --- pbs-api-types/src/datastore.rs | 17 +++++++++++++++++ src/api2/status.rs | 13 +------------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/pbs-api-types/src/datastore.rs b/pbs-api-types/src/datastore.rs index 88724c3e..c96521cb 100644 --- a/pbs-api-types/src/datastore.rs +++ b/pbs-api-types/src/datastore.rs @@ -1361,6 +1361,23 @@ pub struct DataStoreStatusListItem { pub gc_status: Option, } +impl DataStoreStatusListItem { + pub fn empty(store: &str, err: Option) -> Self { + DataStoreStatusListItem { + store: store.to_owned(), + total: -1, + used: -1, + avail: -1, + history: None, + history_start: None, + history_delta: None, + estimated_full_date: None, + error: err, + gc_status: None, + } + } +} + pub const ADMIN_DATASTORE_LIST_SNAPSHOTS_RETURN_TYPE: ReturnType = ReturnType { optional: false, schema: &ArraySchema::new( diff --git a/src/api2/status.rs b/src/api2/status.rs index 45aa7fd7..4d8c64e6 100644 --- a/src/api2/status.rs +++ b/src/api2/status.rs @@ -53,18 +53,7 @@ pub fn datastore_status( let datastore = match DataStore::lookup_datastore(&store, Some(Operation::Read)) { Ok(datastore) => datastore, Err(err) => { - list.push(DataStoreStatusListItem { - store: store.clone(), - total: -1, - used: -1, - avail: -1, - history: None, - history_start: None, - history_delta: None, - estimated_full_date: None, - error: Some(err.to_string()), - gc_status: None, - }); + list.push(DataStoreStatusListItem::empty(store, Some(err.to_string()))); continue; } };