[pbs-devel] [PATCH proxmox-backup 06/26] api-types: add set_maintenance_mode function to DataStoreConfig

Hannes Laimer h.laimer at proxmox.com
Tue Jul 5 15:08:14 CEST 2022


helper for updating the MaintenanceMode of a Datastore not through the
API

Signed-off-by: Hannes Laimer <h.laimer at proxmox.com>
---
 pbs-api-types/src/datastore.rs   | 9 +++++++++
 pbs-api-types/src/maintenance.rs | 6 +++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/pbs-api-types/src/datastore.rs b/pbs-api-types/src/datastore.rs
index 965e3795..ce77f47d 100644
--- a/pbs-api-types/src/datastore.rs
+++ b/pbs-api-types/src/datastore.rs
@@ -313,6 +313,15 @@ impl DataStoreConfig {
             .and_then(|str| MaintenanceMode::API_SCHEMA.parse_property_string(str).ok())
             .and_then(|value| MaintenanceMode::deserialize(value).ok())
     }
+
+    pub fn set_maintenance_mode(&mut self, mode: MaintenanceMode) {
+        if let Some(property_string) = MaintenanceMode::API_SCHEMA
+            .print_property_string(&mode)
+            .ok()
+        {
+            self.maintenance_mode = Some(property_string);
+        }
+    }
 }
 
 #[api(
diff --git a/pbs-api-types/src/maintenance.rs b/pbs-api-types/src/maintenance.rs
index 4f0dfc7f..ec34397f 100644
--- a/pbs-api-types/src/maintenance.rs
+++ b/pbs-api-types/src/maintenance.rs
@@ -67,7 +67,7 @@ pub enum MaintenanceType {
 pub struct MaintenanceMode {
     /// Type of maintenance ("read-only", "offline" or "unplugged").
     #[serde(rename = "type")]
-    ty: MaintenanceType,
+    pub ty: MaintenanceType,
 
     /// Reason for maintenance.
     #[serde(skip_serializing_if = "Option::is_none")]
@@ -75,6 +75,10 @@ pub struct MaintenanceMode {
 }
 
 impl MaintenanceMode {
+    pub fn new(ty: MaintenanceType, message: Option<String>) -> Self {
+        MaintenanceMode { ty, message }
+    }
+
     pub fn check(&self, operation: Option<Operation>) -> Result<(), Error> {
         let message = percent_encoding::percent_decode_str(self.message.as_deref().unwrap_or(""))
             .decode_utf8()
-- 
2.30.2






More information about the pbs-devel mailing list