From 0b90c67fb4e924c939823fd5b30424a42aefee2d Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 5 Mar 2021 12:43:39 +0100 Subject: [PATCH] tape: avoid Updatable for now --- src/api2/config/tape_backup_job.rs | 99 ++++++++++++++++++++++++++---- src/config/tape_job.rs | 5 +- 2 files changed, 88 insertions(+), 16 deletions(-) diff --git a/src/api2/config/tape_backup_job.rs b/src/api2/config/tape_backup_job.rs index fbd36a53..6b116af6 100644 --- a/src/api2/config/tape_backup_job.rs +++ b/src/api2/config/tape_backup_job.rs @@ -1,15 +1,20 @@ -use anyhow::{bail, format_err, Error}; +use anyhow::{bail, Error}; use serde_json::Value; use ::serde::{Deserialize, Serialize}; -use proxmox::api::{api, Router, RpcEnvironment, Permission, schema::Updatable}; +use proxmox::api::{api, Router, RpcEnvironment, Permission}; use proxmox::tools::fs::open_file_locked; use crate::{ api2::types::{ Authid, JOB_ID_SCHEMA, + DATASTORE_SCHEMA, + DRIVE_NAME_SCHEMA, PROXMOX_CONFIG_DIGEST_SCHEMA, + SINGLE_LINE_COMMENT_SCHEMA, + MEDIA_POOL_NAME_SCHEMA, + SYNC_SCHEDULE_SCHEMA, }, config::{ self, @@ -21,7 +26,6 @@ use crate::{ tape_job::{ TAPE_JOB_CFG_LOCKFILE, TapeBackupJobConfig, - TapeBackupJobConfigUpdater, } }, }; @@ -151,9 +155,43 @@ pub enum DeletableProperty { protected: true, input: { properties: { - update: { - flatten: true, - type: TapeBackupJobConfigUpdater, + id: { + schema: JOB_ID_SCHEMA, + }, + store: { + schema: DATASTORE_SCHEMA, + optional: true, + }, + pool: { + schema: MEDIA_POOL_NAME_SCHEMA, + optional: true, + }, + drive: { + schema: DRIVE_NAME_SCHEMA, + optional: true, + }, + "eject-media": { + description: "Eject media upon job completion.", + type: bool, + optional: true, + }, + "export-media-set": { + description: "Export media set upon job completion.", + type: bool, + optional: true, + }, + "latest-only": { + description: "Backup latest snapshots only.", + type: bool, + optional: true, + }, + comment: { + optional: true, + schema: SINGLE_LINE_COMMENT_SCHEMA, + }, + schedule: { + optional: true, + schema: SYNC_SCHEDULE_SCHEMA, }, delete: { description: "List of properties to delete.", @@ -175,26 +213,61 @@ pub enum DeletableProperty { )] /// Update the tape backup job pub fn update_tape_backup_job( - mut update: TapeBackupJobConfigUpdater, - delete: Option>, + id: String, + store: Option, + pool: Option, + drive: Option, + eject_media: Option, + export_media_set: Option, + latest_only: Option, + comment: Option, + schedule: Option, + delete: Option>, digest: Option, ) -> Result<(), Error> { let _lock = open_file_locked(TAPE_JOB_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?; - let id = update.id.take().ok_or_else(|| format_err!("no id given"))?; - let (mut config, expected_digest) = config::tape_job::config()?; - let mut job: TapeBackupJobConfig = config.lookup("backup", &id)?; + let mut data: TapeBackupJobConfig = config.lookup("backup", &id)?; if let Some(ref digest) = digest { let digest = proxmox::tools::hex_to_digest(digest)?; crate::tools::detect_modified_configuration_file(&digest, &expected_digest)?; } - job.update_from(update, &delete.unwrap_or(Vec::new()))?; + if let Some(delete) = delete { + for delete_prop in delete { + match delete_prop { + DeletableProperty::EjectMedia => { data.setup.eject_media = None; }, + DeletableProperty::ExportMediaSet => { data.setup.export_media_set = None; }, + DeletableProperty::LatestOnly => { data.setup.latest_only = None; }, + DeletableProperty::Schedule => { data.schedule = None; }, + DeletableProperty::Comment => { data.comment = None; }, + } + } + } - config.set_data(&job.id, "backup", &job)?; + if let Some(store) = store { data.setup.store = store; } + if let Some(pool) = pool { data.setup.pool = pool; } + if let Some(drive) = drive { data.setup.drive = drive; } + + if eject_media.is_some() { data.setup.eject_media = eject_media; }; + if export_media_set.is_some() { data.setup.export_media_set = export_media_set; } + if latest_only.is_some() { data.setup.latest_only = latest_only; } + + if schedule.is_some() { data.schedule = schedule; } + + if let Some(comment) = comment { + let comment = comment.trim(); + if comment.is_empty() { + data.comment = None; + } else { + data.comment = Some(comment.to_string()); + } + } + + config.set_data(&id, "backup", &data)?; config::tape_job::save_config(&config)?; diff --git a/src/config/tape_job.rs b/src/config/tape_job.rs index 7e1ad37d..5b250117 100644 --- a/src/config/tape_job.rs +++ b/src/config/tape_job.rs @@ -58,7 +58,7 @@ lazy_static! { } )] #[serde(rename_all="kebab-case")] -#[derive(Updater,Serialize,Deserialize,Clone)] +#[derive(Serialize,Deserialize,Clone)] /// Tape Backup Job Setup pub struct TapeBackupJobSetup { pub store: String, @@ -91,10 +91,9 @@ pub struct TapeBackupJobSetup { } )] #[serde(rename_all="kebab-case")] -#[derive(Updater,Serialize,Deserialize,Clone)] +#[derive(Serialize,Deserialize,Clone)] /// Tape Backup Job pub struct TapeBackupJobConfig { - #[updater(fixed)] pub id: String, #[serde(flatten)] pub setup: TapeBackupJobSetup,