Skip to main content

asterust_junos/interfaces/auto_configure/
ranges.rs

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