Skip to main content

asterust_junos/interfaces/auto_configure/
ranges.rs

1//! `interfaces { <name> { auto-configure { vlan-ranges { ... } stacked-vlan-ranges { ... } } } }`.
2
3use crate::{arg_of, args_of, child_block, named_children};
4use asterust::config::ConfigLine;
5
6/// A `dynamic-profile <name>` of a VLAN range block.
7#[derive(Clone, Debug, PartialEq, Eq)]
8#[non_exhaustive]
9pub struct AutoConfigureProfile {
10    pub name: String,
11    /// Each `accept` statement, e.g. `"dhcp-v4"` or `"pppoe"`.
12    pub accept: Vec<String>,
13    pub access_profile: Option<String>,
14    /// e.g. `"100-200"`, or for stacked ranges `"any,100-200"`.
15    pub ranges: Option<String>,
16}
17
18/// A `vlan-ranges` or `stacked-vlan-ranges` block. The `authentication` password is not extracted.
19#[derive(Clone, Debug, PartialEq, Eq)]
20#[non_exhaustive]
21pub struct AutoConfigureRanges {
22    pub access_profile: Option<String>,
23    pub dynamic_profiles: Vec<AutoConfigureProfile>,
24    /// An `authentication` block is configured.
25    pub has_authentication: bool,
26}
27
28pub(super) fn parse_ranges(ranges: &ConfigLine) -> AutoConfigureRanges {
29    AutoConfigureRanges {
30        access_profile: arg_of(ranges, "access-profile").map(str::to_string),
31        dynamic_profiles: named_children(ranges, "dynamic-profile")
32            .map(|(name, profile)| AutoConfigureProfile {
33                name: name.to_string(),
34                accept: args_of(profile, "accept").into_iter().map(str::to_string).collect(),
35                access_profile: arg_of(profile, "access-profile").map(str::to_string),
36                ranges: arg_of(profile, "ranges").map(str::to_string),
37            })
38            .collect(),
39        has_authentication: child_block(ranges, "authentication").is_some(),
40    }
41}