use crate::{arg_of, has_leaf};
use asterust::config::ConfigLine;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct Lacp {
pub mode: Option<String>,
pub periodic: Option<String>,
pub system_priority: Option<String>,
pub system_id: Option<String>,
pub admin_key: Option<String>,
pub force_up: bool,
pub fast_failover: bool,
pub accept_data: bool,
}
pub(super) fn parse_lacp(lacp: &ConfigLine) -> Lacp {
Lacp {
mode: ["active", "passive"]
.iter()
.find(|mode| has_leaf(lacp, mode))
.map(|mode| mode.to_string()),
periodic: arg_of(lacp, "periodic").map(str::to_string),
system_priority: arg_of(lacp, "system-priority").map(str::to_string),
system_id: arg_of(lacp, "system-id").map(str::to_string),
admin_key: arg_of(lacp, "admin-key").map(str::to_string),
force_up: has_leaf(lacp, "force-up"),
fast_failover: has_leaf(lacp, "fast-failover"),
accept_data: has_leaf(lacp, "accept-data"),
}
}