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

Wolfgang Bumiller w.bumiller at proxmox.com
Wed Jul 6 13:40:37 CEST 2022


On Tue, Jul 05, 2022 at 01:08:14PM +0000, Hannes Laimer wrote:
> 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

Instead of using the `API_SCHEMA` *here*, this should be a helper method
in `MaintenanceMode`.
And I don't think it should be able to fail. Given that
`MaintenanceMode` currently is just a mode with a reason string, the
stringification (& potential string quoting) could be done there without
a fully generic `print_property_string` helper way more easily ;-)

> +            .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