asterust-junos 0.5.2

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

asterust-junos

Typed views of common Juniper JunOS config statements, extracted from a config tree parsed by asterust (config::juniper, brace-format show configuration).

Module Block
interfaces interfaces
protocols::ospf protocols ospf
protocols::ospf3 protocols ospf3
protocols::bgp protocols bgp
protocols::evpn protocols evpn
protocols::igmp and protocols::mld protocols igmp and protocols mld
protocols::isis protocols isis
protocols::l2vpn routing-instances <name> protocols l2vpn
protocols::ldp protocols ldp
protocols::lldp protocols lldp
protocols::lldp_med protocols lldp-med
protocols::mpls protocols mpls
protocols::pcep protocols pcep
protocols::pim protocols pim
protocols::rsvp protocols rsvp
protocols::source_packet_routing protocols source-packet-routing
routing_instances routing-instances
routing_options routing-options
policy_options policy-options
class_of_service class-of-service
firewall firewall
services::rpm::twamp services rpm twamp
services::monitoring::twamp services monitoring twamp (Junos OS Evolved)
system system

The statements each module reads are listed in docs/modules.md.

The source tree mirrors the configuration hierarchy so a statement is easy to find: a folder per top-level block (system/, protocols/, policy_options/), a file per statement inside it (system/radius_server.rs, system/root_authentication.rs), and a folder instead of a file when that statement has many children of its own (system/services/ssh.rs, system/login/class.rs, system/syslog/host.rs). The types of each level are re-exported from its parent, e.g. system::RadiusServer.

use asterust_junos::JunosDevice;

let device = JunosDevice::parse(show_configuration_text);
for iface in &device.interfaces {
    println!("{}: {:?}", iface.name, iface.units);
}
if let Some(bgp) = &device.protocols.bgp {
    println!("{} BGP groups", bgp.groups.len());
}

Unlike the Cisco crates, JunosDevice reads every view once and exposes it as a field that mirrors the configuration hierarchy: device.protocols.bgp, device.protocols.ospf, device.system, device.routing_options, device.class_of_service. A protocol or block that is not configured is None, and the views read from named top-level blocks rather than one struct per block. JunosDevice also implements asterust::device::Device.

Secrets: passwords, keys and shared secrets are not read by default, only a has_* flag says whether one is configured. With the secrets feature (asterust-junos = { version = "...", features = ["secrets"] }) the matching Option<Secret> fields are filled with the value as written (usually the encrypted $9$... form). Secret prints as Secret(<redacted>) in Debug; read it with Secret::expose. Covered: BGP, OSPF, IS-IS, LDP, RSVP, VRRP, auto-configure, and in system the RADIUS and TACACS+ servers, NTP, login users, root and diag/PIC console authentication, archival, autoinstallation, license, outbound-ssh, static subscribers and subscriber-management. master-password has nothing to read, since the password is not part of the configuration.

Junos OS Evolved: it shares most of the hierarchy with Junos OS and is read by the same modules. Where it configures a feature in a different place or with different statements, it has its own module that follows its hierarchy, for example services::monitoring::twamp (services monitoring twamp) next to services::rpm::twamp (services rpm twamp). A few Evolved-only statements sit inside shared modules, such as validation-database-instance in policy_options.

Limitations: statements deactivated with inactive: are skipped; | display set output is not supported; protocols nested inside routing instances (other than bgp SRv6 and l2vpn), apply-groups expansion and BGP group-to-neighbor setting inheritance are not resolved.

Sources

Test fixtures marked DOC_* or reads_the_guide_* are adapted from the Juniper documentation pages listed in docs/sources.md, which also lists the fixtures that are not from documentation and so are unverified.