[pbs-devel] [PATCH v2 proxmox-backup 28/31] api types: implement api type for `BackupGroupDeleteStats`

Christian Ebner c.ebner at proxmox.com
Thu Aug 1 09:44:00 CEST 2024


Make the `BackupGroupDeleteStats` exposable via the API by implementing
the ApiTypes trait via the api macro invocation and add an additional
field to account for the number of deleted groups.
Further, add a method to add up the statistics.

Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
changes since version 1:
- not present in previous version

 pbs-api-types/src/datastore.rs | 36 +++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/pbs-api-types/src/datastore.rs b/pbs-api-types/src/datastore.rs
index 82998acd4..0843492ea 100644
--- a/pbs-api-types/src/datastore.rs
+++ b/pbs-api-types/src/datastore.rs
@@ -1570,8 +1570,28 @@ pub fn print_store_and_ns(store: &str, ns: &BackupNamespace) -> String {
     }
 }
 
-#[derive(Default)]
+pub const DELETE_STATS_COUNT_SCHEMA: Schema =
+    IntegerSchema::new("Number of entities").minimum(0).schema();
+
+#[api(
+    properties: {
+        "removed-groups": {
+            schema: DELETE_STATS_COUNT_SCHEMA,
+        },
+        "unremoved-protected": {
+            schema: DELETE_STATS_COUNT_SCHEMA,
+        },
+        "removed-snapshots": {
+            schema: DELETE_STATS_COUNT_SCHEMA,
+        },
+     },
+)]
+#[derive(Default, Deserialize, Serialize)]
+#[serde(rename_all = "kebab-case")]
+/// Statistics for removed backup groups
 pub struct BackupGroupDeleteStats {
+    // Count of removed groups
+    removed_groups: usize,
     // Count of protected snapshots, therefore not removed
     unremoved_protected: usize,
     // Count of deleted snapshots
@@ -1583,6 +1603,10 @@ impl BackupGroupDeleteStats {
         self.unremoved_protected == 0
     }
 
+    pub fn removed_groups(&self) -> usize {
+        self.removed_groups
+    }
+
     pub fn removed_snapshots(&self) -> usize {
         self.removed_snapshots
     }
@@ -1591,6 +1615,16 @@ impl BackupGroupDeleteStats {
         self.unremoved_protected
     }
 
+    pub fn add(&mut self, rhs: &Self) {
+        self.removed_groups += rhs.removed_groups;
+        self.unremoved_protected += rhs.unremoved_protected;
+        self.removed_snapshots += rhs.removed_snapshots;
+    }
+
+    pub fn increment_removed_groups(&mut self) {
+        self.removed_groups += 1;
+    }
+
     pub fn increment_removed_snapshots(&mut self) {
         self.removed_snapshots += 1;
     }
-- 
2.39.2





More information about the pbs-devel mailing list