asterust-junos 0.5.13

Typed Juniper JunOS config views (interfaces, protocols, routing instances and options, policy options, firewall filters, class of service, system, services) extracted from an asterust config tree.
Documentation
//! `multi-chassis-protection`
//! `interfaces { <name> { multi-chassis-protection <peer> { interface <name>; } } }`.
//!
//! # See also
//!
//! - [multi-chassis-protection (Interfaces)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/multi-chassis-protection.html)
//! - [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)

use crate::{arg_of, child_block, named_children};
use asterust::config::ConfigLine;

/// The `multi-chassis-protection` peer of an interface.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct MultiChassisProtection {
    /// The address of the peer.
    pub peer: String,
    /// The interface on the peer, from `interface`.
    pub interface: Option<String>,
}

/// The peer, written `multi-chassis-protection <peer> { ... }` or `multi-chassis-protection { peer <peer> { ... } }`.
pub(super) fn parse_multi_chassis_protection(interface: &ConfigLine) -> Option<MultiChassisProtection> {
    let (peer, block) = named_children(interface, "multi-chassis-protection")
        .next()
        .or_else(|| {
            let protection = child_block(interface, "multi-chassis-protection")?;
            named_children(protection, "peer").next()
        })?;
    Some(MultiChassisProtection {
        peer: peer.to_string(),
        interface: arg_of(block, "interface").map(str::to_string),
    })
}