tape: media_pool: derive and use Updater

This commit is contained in:
Dietmar Maurer 2021-08-12 09:04:16 +02:00
parent c62a6acb2e
commit dbda1513c5
2 changed files with 13 additions and 36 deletions

View File

@ -14,12 +14,8 @@ use crate::{
api2::types::{ api2::types::{
Authid, Authid,
MEDIA_POOL_NAME_SCHEMA, MEDIA_POOL_NAME_SCHEMA,
MEDIA_SET_NAMING_TEMPLATE_SCHEMA,
MEDIA_SET_ALLOCATION_POLICY_SCHEMA,
MEDIA_RETENTION_POLICY_SCHEMA,
TAPE_ENCRYPTION_KEY_FINGERPRINT_SCHEMA,
SINGLE_LINE_COMMENT_SCHEMA,
MediaPoolConfig, MediaPoolConfig,
MediaPoolConfigUpdater,
}, },
config::{ config::{
self, self,
@ -151,25 +147,9 @@ pub enum DeletableProperty {
name: { name: {
schema: MEDIA_POOL_NAME_SCHEMA, schema: MEDIA_POOL_NAME_SCHEMA,
}, },
allocation: { update: {
schema: MEDIA_SET_ALLOCATION_POLICY_SCHEMA, type: MediaPoolConfigUpdater,
optional: true, flatten: true,
},
retention: {
schema: MEDIA_RETENTION_POLICY_SCHEMA,
optional: true,
},
template: {
schema: MEDIA_SET_NAMING_TEMPLATE_SCHEMA,
optional: true,
},
encrypt: {
schema: TAPE_ENCRYPTION_KEY_FINGERPRINT_SCHEMA,
optional: true,
},
comment: {
optional: true,
schema: SINGLE_LINE_COMMENT_SCHEMA,
}, },
delete: { delete: {
description: "List of properties to delete.", description: "List of properties to delete.",
@ -188,11 +168,7 @@ pub enum DeletableProperty {
/// Update media pool settings /// Update media pool settings
pub fn update_pool( pub fn update_pool(
name: String, name: String,
allocation: Option<String>, update: MediaPoolConfigUpdater,
retention: Option<String>,
template: Option<String>,
encrypt: Option<String>,
comment: Option<String>,
delete: Option<Vec<DeletableProperty>>, delete: Option<Vec<DeletableProperty>>,
) -> Result<(), Error> { ) -> Result<(), Error> {
@ -214,12 +190,12 @@ pub fn update_pool(
} }
} }
if allocation.is_some() { data.allocation = allocation; } if update.allocation.is_some() { data.allocation = update.allocation; }
if retention.is_some() { data.retention = retention; } if update.retention.is_some() { data.retention = update.retention; }
if template.is_some() { data.template = template; } if update.template.is_some() { data.template = update.template; }
if encrypt.is_some() { data.encrypt = encrypt; } if update.encrypt.is_some() { data.encrypt = update.encrypt; }
if let Some(comment) = comment { if let Some(comment) = update.comment {
let comment = comment.trim(); let comment = comment.trim();
if comment.is_empty() { if comment.is_empty() {
data.comment = None; data.comment = None;

View File

@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize};
use proxmox::api::{ use proxmox::api::{
api, api,
schema::{Schema, StringSchema, ApiStringFormat}, schema::{Schema, StringSchema, ApiStringFormat, Updater},
}; };
use crate::{ use crate::{
@ -138,10 +138,11 @@ impl std::str::FromStr for RetentionPolicy {
}, },
}, },
)] )]
#[derive(Serialize,Deserialize)] #[derive(Serialize,Deserialize,Updater)]
/// Media pool configuration /// Media pool configuration
pub struct MediaPoolConfig { pub struct MediaPoolConfig {
/// The pool name /// The pool name
#[updater(skip)]
pub name: String, pub name: String,
/// Media Set allocation policy /// Media Set allocation policy
#[serde(skip_serializing_if="Option::is_none")] #[serde(skip_serializing_if="Option::is_none")]