status: use Option on avail/used datastore attrs

Instead of returning -1 if we can't get the attributes, we use an
Option which will not be serialized on `None`.

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
This commit is contained in:
Gabriel Goller 2023-12-11 09:59:02 +01:00 committed by Dietmar Maurer
parent 0cac699e0c
commit cbb478fa19
2 changed files with 14 additions and 11 deletions

View File

@ -1302,12 +1302,15 @@ pub struct DataStoreStatus {
/// Status of a Datastore
pub struct DataStoreStatusListItem {
pub store: String,
/// The Size of the underlying storage in bytes. (-1 on error)
pub total: i64,
/// The used bytes of the underlying storage. (-1 on error)
pub used: i64,
/// The Size of the underlying storage in bytes.
#[serde(skip_serializing_if = "Option::is_none")]
pub total: Option<u64>,
/// The used bytes of the underlying storage.
#[serde(skip_serializing_if = "Option::is_none")]
pub used: Option<u64>,
/// The available bytes of the underlying storage. (-1 on error)
pub avail: i64,
#[serde(skip_serializing_if = "Option::is_none")]
pub avail: Option<u64>,
/// A list of usages of the past (last Month).
#[serde(skip_serializing_if = "Option::is_none")]
pub history: Option<Vec<Option<f64>>>,
@ -1335,9 +1338,9 @@ impl DataStoreStatusListItem {
pub fn empty(store: &str, err: Option<String>) -> Self {
DataStoreStatusListItem {
store: store.to_owned(),
total: -1,
used: -1,
avail: -1,
total: None,
used: None,
avail: None,
history: None,
history_start: None,
history_delta: None,

View File

@ -68,9 +68,9 @@ pub async fn datastore_status(
let mut entry = DataStoreStatusListItem {
store: store.clone(),
total: status.total as i64,
used: status.used as i64,
avail: status.available as i64,
total: Some(status.total),
used: Some(status.used),
avail: Some(status.available),
history: None,
history_start: None,
history_delta: None,