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 read only with the `secrets`
26/// feature.
27#[derive(Clone, Debug, PartialEq, Eq)]
28#[non_exhaustive]
29pub struct AutoConfigureRanges {
30    pub access_profile: Option<String>,
31    pub dynamic_profiles: Vec<AutoConfigureProfile>,
32    /// An `authentication` block is configured.
33    pub has_authentication: bool,
34    /// The `authentication { password ...; }`; `None` unless the `secrets` feature is enabled.
35    pub authentication_password: Option<crate::Secret>,
36}
37
38pub(super) fn parse_ranges(ranges: &ConfigLine) -> AutoConfigureRanges {
39    AutoConfigureRanges {
40        access_profile: arg_of(ranges, "access-profile").map(str::to_string),
41        dynamic_profiles: named_children(ranges, "dynamic-profile")
42            .map(|(name, profile)| AutoConfigureProfile {
43                name: name.to_string(),
44                accept: args_of(profile, "accept").into_iter().map(str::to_string).collect(),
45                access_profile: arg_of(profile, "access-profile").map(str::to_string),
46                ranges: arg_of(profile, "ranges").map(str::to_string),
47            })
48            .collect(),
49        has_authentication: child_block(ranges, "authentication").is_some(),
50        authentication_password: crate::secret_value(
51            child_block(ranges, "authentication").and_then(|auth| arg_of(auth, "password")),
52        ),
53    }
54}