From 6eb756bcabfe0b02b25b09a5fab5e0175c76f19c Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Sun, 21 Nov 2021 10:29:58 +0100 Subject: [PATCH] sync-job: add rate limit Signed-off-by: Dietmar Maurer --- pbs-api-types/src/jobs.rs | 8 +++++++- pbs-config/src/sync.rs | 2 +- src/api2/config/sync.rs | 28 ++++++++++++++++++++++++++ src/bin/proxmox_backup_manager/sync.rs | 1 + 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/pbs-api-types/src/jobs.rs b/pbs-api-types/src/jobs.rs index 2a7e201b..fe2383a5 100644 --- a/pbs-api-types/src/jobs.rs +++ b/pbs-api-types/src/jobs.rs @@ -7,7 +7,8 @@ use serde::{Deserialize, Serialize}; use proxmox_schema::*; use crate::{ - Userid, Authid, REMOTE_ID_SCHEMA, DRIVE_NAME_SCHEMA, MEDIA_POOL_NAME_SCHEMA, + Userid, Authid, RateLimitConfig, + REMOTE_ID_SCHEMA, DRIVE_NAME_SCHEMA, MEDIA_POOL_NAME_SCHEMA, SINGLE_LINE_COMMENT_SCHEMA, PROXMOX_SAFE_ID_FORMAT, DATASTORE_SCHEMA, BACKUP_GROUP_SCHEMA, BACKUP_TYPE_SCHEMA, }; @@ -405,6 +406,9 @@ pub const GROUP_FILTER_LIST_SCHEMA: Schema = ArraySchema::new("List of group fil optional: true, schema: SINGLE_LINE_COMMENT_SCHEMA, }, + limit: { + type: RateLimitConfig, + }, schedule: { optional: true, schema: SYNC_SCHEDULE_SCHEMA, @@ -434,6 +438,8 @@ pub struct SyncJobConfig { pub schedule: Option, #[serde(skip_serializing_if="Option::is_none")] pub group_filter: Option>, + #[serde(flatten)] + pub limit: RateLimitConfig, } #[api( diff --git a/pbs-config/src/sync.rs b/pbs-config/src/sync.rs index a9e3a0de..6331fa34 100644 --- a/pbs-config/src/sync.rs +++ b/pbs-config/src/sync.rs @@ -17,7 +17,7 @@ lazy_static! { fn init() -> SectionConfig { let obj_schema = match SyncJobConfig::API_SCHEMA { - Schema::Object(ref obj_schema) => obj_schema, + Schema::AllOf(ref allof_schema) => allof_schema, _ => unreachable!(), }; diff --git a/src/api2/config/sync.rs b/src/api2/config/sync.rs index 2028d038..bc4ad285 100644 --- a/src/api2/config/sync.rs +++ b/src/api2/config/sync.rs @@ -194,6 +194,14 @@ pub enum DeletableProperty { remove_vanished, /// Delete the group_filter property. group_filter, + /// Delete the rate_in property. + rate_in, + /// Delete the burst_in property. + burst_in, + /// Delete the rate_out property. + rate_out, + /// Delete the burst_out property. + burst_out, } #[api( @@ -257,6 +265,10 @@ pub fn update_sync_job( DeletableProperty::schedule => { data.schedule = None; }, DeletableProperty::remove_vanished => { data.remove_vanished = None; }, DeletableProperty::group_filter => { data.group_filter = None; }, + DeletableProperty::rate_in => { data.limit.rate_in = None; }, + DeletableProperty::rate_out => { data.limit.rate_out = None; }, + DeletableProperty::burst_in => { data.limit.burst_in = None; }, + DeletableProperty::burst_out => { data.limit.burst_out = None; }, } } } @@ -276,6 +288,22 @@ pub fn update_sync_job( if let Some(owner) = update.owner { data.owner = Some(owner); } if let Some(group_filter) = update.group_filter { data.group_filter = Some(group_filter); } + if update.limit.rate_in.is_some() { + data.limit.rate_in = update.limit.rate_in; + } + + if update.limit.rate_out.is_some() { + data.limit.rate_out = update.limit.rate_out; + } + + if update.limit.burst_in.is_some() { + data.limit.burst_in = update.limit.burst_in; + } + + if update.limit.burst_out.is_some() { + data.limit.burst_out = update.limit.burst_out; + } + let schedule_changed = data.schedule != update.schedule; if update.schedule.is_some() { data.schedule = update.schedule; } if update.remove_vanished.is_some() { data.remove_vanished = update.remove_vanished; } diff --git a/src/bin/proxmox_backup_manager/sync.rs b/src/bin/proxmox_backup_manager/sync.rs index f4fa9530..bfe141f8 100644 --- a/src/bin/proxmox_backup_manager/sync.rs +++ b/src/bin/proxmox_backup_manager/sync.rs @@ -48,6 +48,7 @@ fn list_sync_jobs(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result