Skip to main content

asterust_junos/interfaces/
multi_chassis_protection.rs

1//! `multi-chassis-protection`
2//! `interfaces { <name> { multi-chassis-protection <peer> { interface <name>; } } }`.
3//!
4//! # See also
5//!
6//! - [multi-chassis-protection (Interfaces)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/multi-chassis-protection.html)
7//! - [peer (Multichassis Link Protection)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/peer-edit-interfaces-multi-chassis-link-protection.html)
8
9use crate::{arg_of, child_block, named_children};
10use asterust::config::ConfigLine;
11
12/// The `multi-chassis-protection` peer of an interface.
13#[derive(Clone, Debug, PartialEq, Eq)]
14#[non_exhaustive]
15pub struct MultiChassisProtection {
16    /// The address of the peer.
17    pub peer: String,
18    /// The interface on the peer, from `interface`.
19    pub interface: Option<String>,
20}
21
22/// The peer, written `multi-chassis-protection <peer> { ... }` or `multi-chassis-protection { peer <peer> { ... } }`.
23pub(super) fn parse_multi_chassis_protection(interface: &ConfigLine) -> Option<MultiChassisProtection> {
24    let (peer, block) = named_children(interface, "multi-chassis-protection")
25        .next()
26        .or_else(|| {
27            let protection = child_block(interface, "multi-chassis-protection")?;
28            named_children(protection, "peer").next()
29        })?;
30    Some(MultiChassisProtection {
31        peer: peer.to_string(),
32        interface: arg_of(block, "interface").map(str::to_string),
33    })
34}