sync-job: add rate limit
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
This commit is contained in:
		@ -7,7 +7,8 @@ use serde::{Deserialize, Serialize};
 | 
				
			|||||||
use proxmox_schema::*;
 | 
					use proxmox_schema::*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::{
 | 
					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,
 | 
					    SINGLE_LINE_COMMENT_SCHEMA, PROXMOX_SAFE_ID_FORMAT, DATASTORE_SCHEMA,
 | 
				
			||||||
    BACKUP_GROUP_SCHEMA, BACKUP_TYPE_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,
 | 
					            optional: true,
 | 
				
			||||||
            schema: SINGLE_LINE_COMMENT_SCHEMA,
 | 
					            schema: SINGLE_LINE_COMMENT_SCHEMA,
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
 | 
					        limit: {
 | 
				
			||||||
 | 
					            type: RateLimitConfig,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
        schedule: {
 | 
					        schedule: {
 | 
				
			||||||
            optional: true,
 | 
					            optional: true,
 | 
				
			||||||
            schema: SYNC_SCHEDULE_SCHEMA,
 | 
					            schema: SYNC_SCHEDULE_SCHEMA,
 | 
				
			||||||
@ -434,6 +438,8 @@ pub struct SyncJobConfig {
 | 
				
			|||||||
    pub schedule: Option<String>,
 | 
					    pub schedule: Option<String>,
 | 
				
			||||||
    #[serde(skip_serializing_if="Option::is_none")]
 | 
					    #[serde(skip_serializing_if="Option::is_none")]
 | 
				
			||||||
    pub group_filter: Option<Vec<GroupFilter>>,
 | 
					    pub group_filter: Option<Vec<GroupFilter>>,
 | 
				
			||||||
 | 
					    #[serde(flatten)]
 | 
				
			||||||
 | 
					    pub limit: RateLimitConfig,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[api(
 | 
					#[api(
 | 
				
			||||||
 | 
				
			|||||||
@ -17,7 +17,7 @@ lazy_static! {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
fn init() -> SectionConfig {
 | 
					fn init() -> SectionConfig {
 | 
				
			||||||
    let obj_schema = match SyncJobConfig::API_SCHEMA {
 | 
					    let obj_schema = match SyncJobConfig::API_SCHEMA {
 | 
				
			||||||
        Schema::Object(ref obj_schema) => obj_schema,
 | 
					        Schema::AllOf(ref allof_schema) => allof_schema,
 | 
				
			||||||
        _ => unreachable!(),
 | 
					        _ => unreachable!(),
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -194,6 +194,14 @@ pub enum DeletableProperty {
 | 
				
			|||||||
    remove_vanished,
 | 
					    remove_vanished,
 | 
				
			||||||
    /// Delete the group_filter property.
 | 
					    /// Delete the group_filter property.
 | 
				
			||||||
    group_filter,
 | 
					    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(
 | 
					#[api(
 | 
				
			||||||
@ -257,6 +265,10 @@ pub fn update_sync_job(
 | 
				
			|||||||
                DeletableProperty::schedule => { data.schedule = None; },
 | 
					                DeletableProperty::schedule => { data.schedule = None; },
 | 
				
			||||||
                DeletableProperty::remove_vanished => { data.remove_vanished = None; },
 | 
					                DeletableProperty::remove_vanished => { data.remove_vanished = None; },
 | 
				
			||||||
                DeletableProperty::group_filter => { data.group_filter = 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(owner) = update.owner { data.owner = Some(owner); }
 | 
				
			||||||
    if let Some(group_filter) = update.group_filter { data.group_filter = Some(group_filter); }
 | 
					    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;
 | 
					    let schedule_changed = data.schedule != update.schedule;
 | 
				
			||||||
    if update.schedule.is_some() { 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; }
 | 
					    if update.remove_vanished.is_some() { data.remove_vanished = update.remove_vanished; }
 | 
				
			||||||
 | 
				
			|||||||
@ -48,6 +48,7 @@ fn list_sync_jobs(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value
 | 
				
			|||||||
        .column(ColumnConfig::new("remote-store"))
 | 
					        .column(ColumnConfig::new("remote-store"))
 | 
				
			||||||
        .column(ColumnConfig::new("schedule"))
 | 
					        .column(ColumnConfig::new("schedule"))
 | 
				
			||||||
        .column(ColumnConfig::new("group-filter").renderer(render_group_filter))
 | 
					        .column(ColumnConfig::new("group-filter").renderer(render_group_filter))
 | 
				
			||||||
 | 
					        .column(ColumnConfig::new("rate-in"))
 | 
				
			||||||
        .column(ColumnConfig::new("comment"));
 | 
					        .column(ColumnConfig::new("comment"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
 | 
					    format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user