asterust-junos 0.5.9

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
//! `inband-ztp`
//! `system { services { inband-ztp { ... } } }`.
//!
//! # See also
//!
//! - [inband-ztp](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/inband-ztp-edit-system-services.html)

use crate::{arg_of, args_of, list_values};
use asterust::config::ConfigLine;

/// The `system services inband-ztp` settings.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct InbandZtp {
    pub management_vlan_id: Option<String>,
    pub name_servers: Vec<String>,
}

pub(super) fn parse_inband_ztp(ztp: &ConfigLine) -> InbandZtp {
    InbandZtp {
        management_vlan_id: arg_of(ztp, "management-vlan-id").map(str::to_string),
        name_servers: args_of(ztp, "name-server").into_iter().flat_map(list_values).collect(),
    }
}

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

    // Not from documentation: written from the CLI Reference syntax page. See the README "Sources".
    #[test]
    fn extracts_inband_ztp() {
        let ztp = system(&juniper::parse_braces(
            "system {\n    services {\n        inband-ztp {\n            management-vlan-id 100;\n            name-server [ 192.0.2.53 192.0.2.54 ];\n        }\n    }\n}\n",
        ))
        .unwrap()
        .services
        .unwrap()
        .inband_ztp
        .unwrap();
        assert_eq!(ztp.management_vlan_id.as_deref(), Some("100"));
        assert_eq!(ztp.name_servers, ["192.0.2.53", "192.0.2.54"]);
    }

    #[test]
    fn no_inband_ztp_is_none() {
        let services = system(&juniper::parse_braces(
            "system {\n    services {\n        telnet;\n    }\n}\n",
        ))
        .unwrap()
        .services
        .unwrap();
        assert!(services.inband_ztp.is_none());
    }
}