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
//! `aggregated-inline-services-options`
//! `interfaces { asi<n> { aggregated-inline-services-options { ... } } }`.
//!
//! # See also
//!
//! - [aggregated-inline-services-options](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/aggregated-inlinesvcs-options-edit-interfaces.html)

use crate::arg_of;
use asterust::config::ConfigLine;

/// The `aggregated-inline-services-options` of an `asi` interface.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct AggregatedInlineServicesOptions {
    pub primary_interface: Option<String>,
    pub secondary_interface: Option<String>,
}

pub(super) fn parse_aggregated_inline_services_options(options: &ConfigLine) -> AggregatedInlineServicesOptions {
    AggregatedInlineServicesOptions {
        primary_interface: arg_of(options, "primary-interface").map(str::to_string),
        secondary_interface: arg_of(options, "secondary-interface").map(str::to_string),
    }
}

#[cfg(test)]
mod tests {
    use crate::interfaces::interfaces;
    use asterust::config::juniper;

    // Not from documentation: written from the CLI Reference syntax pages. See the README "Sources".
    #[test]
    fn extracts_aggregated_inline_services_options() {
        let ifaces = interfaces(&juniper::parse_braces(
            "interfaces {\n    asi0 {\n        aggregated-inline-services-options {\n            primary-interface si-1/0/0;\n            secondary-interface si-2/0/0;\n        }\n    }\n}\n",
        ));
        let options = ifaces[0].aggregated_inline_services_options.as_ref().unwrap();
        assert_eq!(options.primary_interface.as_deref(), Some("si-1/0/0"));
        assert_eq!(options.secondary_interface.as_deref(), Some("si-2/0/0"));
    }
}