asterust-junos 0.5.14

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
//! `next-hop-tunnel`
//! `interfaces { <name> { unit <n> { family <name> { next-hop-tunnel <gateway> ipsec-vpn <vpn>; } } } }`.
//!
//! # See also
//!
//! - [next-hop-tunnel](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/interfaces-edit-next-hop-tunnel.html)

use crate::{active_children, value_after};
use asterust::config::ConfigLine;

/// A `next-hop-tunnel` of a family: an IPsec VPN tunnel to a gateway.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct NextHopTunnel {
    pub gateway_address: String,
    pub ipsec_vpn: String,
}

pub(super) fn parse_next_hop_tunnels(family: &ConfigLine) -> Vec<NextHopTunnel> {
    active_children(family)
        .filter_map(|c| {
            let words: Vec<&str> = c.arg("next-hop-tunnel")?.split_whitespace().collect();
            Some(NextHopTunnel {
                gateway_address: words.first()?.to_string(),
                ipsec_vpn: value_after(&words, "ipsec-vpn")?,
            })
        })
        .collect()
}