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

View File

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