Add traffic control configuration config with API
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
This commit is contained in:
@ -16,7 +16,7 @@ serde = { version = "1.0", features = ["derive"] }
|
||||
|
||||
proxmox = "0.15.0"
|
||||
proxmox-lang = "1.0.0"
|
||||
proxmox-schema = { version = "1.0.0", features = [ "api-macro" ] }
|
||||
proxmox-schema = { version = "1.0.1", features = [ "api-macro" ] }
|
||||
proxmox-time = "1.0.0"
|
||||
proxmox-uuid = { version = "1.0.0", features = [ "serde" ] }
|
||||
|
||||
|
@ -7,6 +7,7 @@ use proxmox_schema::{
|
||||
api, const_regex, ApiStringFormat, ApiType, ArraySchema, Schema, StringSchema, ReturnType,
|
||||
};
|
||||
use proxmox::{IPRE, IPRE_BRACKET, IPV4OCTET, IPV4RE, IPV6H16, IPV6LS32, IPV6RE};
|
||||
use proxmox_systemd::daily_duration::parse_daily_duration;
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[macro_export]
|
||||
@ -73,6 +74,9 @@ pub use remote::*;
|
||||
mod tape;
|
||||
pub use tape::*;
|
||||
|
||||
mod traffic_control;
|
||||
pub use traffic_control::*;
|
||||
|
||||
mod zfs;
|
||||
pub use zfs::*;
|
||||
|
||||
@ -152,6 +156,9 @@ pub const HOSTNAME_FORMAT: ApiStringFormat = ApiStringFormat::Pattern(&HOSTNAME_
|
||||
pub const DNS_ALIAS_FORMAT: ApiStringFormat =
|
||||
ApiStringFormat::Pattern(&DNS_ALIAS_REGEX);
|
||||
|
||||
pub const DAILY_DURATION_FORMAT: ApiStringFormat =
|
||||
ApiStringFormat::VerifyFn(|s| parse_daily_duration(s).map(drop));
|
||||
|
||||
pub const SEARCH_DOMAIN_SCHEMA: Schema =
|
||||
StringSchema::new("Search domain for host-name lookup.").schema();
|
||||
|
||||
|
96
pbs-api-types/src/traffic_control.rs
Normal file
96
pbs-api-types/src/traffic_control.rs
Normal file
@ -0,0 +1,96 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use proxmox_schema::{api, Schema, IntegerSchema, StringSchema, Updater};
|
||||
|
||||
use crate::{
|
||||
CIDR_SCHEMA, DAILY_DURATION_FORMAT,
|
||||
PROXMOX_SAFE_ID_FORMAT, SINGLE_LINE_COMMENT_SCHEMA,
|
||||
};
|
||||
|
||||
pub const TRAFFIC_CONTROL_TIMEFRAME_SCHEMA: Schema = StringSchema::new(
|
||||
"Timeframe to specify when the rule is actice.")
|
||||
.format(&DAILY_DURATION_FORMAT)
|
||||
.schema();
|
||||
|
||||
pub const TRAFFIC_CONTROL_ID_SCHEMA: Schema = StringSchema::new("Rule ID.")
|
||||
.format(&PROXMOX_SAFE_ID_FORMAT)
|
||||
.min_length(3)
|
||||
.max_length(32)
|
||||
.schema();
|
||||
|
||||
pub const TRAFFIC_CONTROL_RATE_SCHEMA: Schema = IntegerSchema::new(
|
||||
"Rate limit (for Token bucket filter) in bytes/second.")
|
||||
.minimum(100_000)
|
||||
.schema();
|
||||
|
||||
pub const TRAFFIC_CONTROL_BURST_SCHEMA: Schema = IntegerSchema::new(
|
||||
"Size of the token bucket (for Token bucket filter) in bytes.")
|
||||
.minimum(1000)
|
||||
.schema();
|
||||
|
||||
#[api(
|
||||
properties: {
|
||||
name: {
|
||||
schema: TRAFFIC_CONTROL_ID_SCHEMA,
|
||||
},
|
||||
comment: {
|
||||
optional: true,
|
||||
schema: SINGLE_LINE_COMMENT_SCHEMA,
|
||||
},
|
||||
"rate-in": {
|
||||
schema: TRAFFIC_CONTROL_RATE_SCHEMA,
|
||||
optional: true,
|
||||
},
|
||||
"burst-in": {
|
||||
schema: TRAFFIC_CONTROL_BURST_SCHEMA,
|
||||
optional: true,
|
||||
},
|
||||
"rate-out": {
|
||||
schema: TRAFFIC_CONTROL_RATE_SCHEMA,
|
||||
optional: true,
|
||||
},
|
||||
"burst-out": {
|
||||
schema: TRAFFIC_CONTROL_BURST_SCHEMA,
|
||||
optional: true,
|
||||
},
|
||||
network: {
|
||||
type: Array,
|
||||
items: {
|
||||
schema: CIDR_SCHEMA,
|
||||
},
|
||||
},
|
||||
timeframe: {
|
||||
type: Array,
|
||||
items: {
|
||||
schema: TRAFFIC_CONTROL_TIMEFRAME_SCHEMA,
|
||||
},
|
||||
optional: true,
|
||||
},
|
||||
},
|
||||
)]
|
||||
#[derive(Serialize,Deserialize, Updater)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
/// Traffic control rule
|
||||
pub struct TrafficControlRule {
|
||||
#[updater(skip)]
|
||||
pub name: String,
|
||||
#[serde(skip_serializing_if="Option::is_none")]
|
||||
pub comment: Option<String>,
|
||||
/// Rule applies to Source IPs within this networks
|
||||
pub network: Vec<String>,
|
||||
#[serde(skip_serializing_if="Option::is_none")]
|
||||
pub rate_in: Option<u64>,
|
||||
#[serde(skip_serializing_if="Option::is_none")]
|
||||
pub burst_in: Option<u64>,
|
||||
#[serde(skip_serializing_if="Option::is_none")]
|
||||
pub rate_out: Option<u64>,
|
||||
#[serde(skip_serializing_if="Option::is_none")]
|
||||
pub burst_out: Option<u64>,
|
||||
// fixme: expose this?
|
||||
// /// Bandwidth is shared accross all connections
|
||||
// #[serde(skip_serializing_if="Option::is_none")]
|
||||
// pub shared: Option<bool>,
|
||||
/// Enable the rule at specific times
|
||||
#[serde(skip_serializing_if="Option::is_none")]
|
||||
pub timeframe: Option<Vec<String>>,
|
||||
}
|
Reference in New Issue
Block a user