mod accounting;
mod addressing;
mod archival;
mod auth;
mod autoinstallation;
mod commit;
mod extensions;
mod flow_tap_dtcp;
mod internet;
mod license;
mod location;
mod login;
mod ntp;
mod pixel_tracing;
mod ports;
mod processes;
mod schema;
mod scripts;
mod service_deployment;
mod services;
mod subscriber;
mod syslog;
pub use accounting::{Accounting, AccountingDestination};
pub use addressing::{BackupRouter, NameServer, StaticHostMapping};
pub use archival::{Archival, ArchivalConfiguration};
pub use auth::{MasterPassword, RadiusServer, RootAuthentication, TacplusServer};
pub use autoinstallation::{Autoinstallation, AutoinstallationInterface};
pub use commit::Commit;
pub use extensions::{ExtensionApplication, ExtensionProvider, Extensions, ProviderLicense};
pub use flow_tap_dtcp::{FlowTapDtcp, FlowTapDtcpSsh};
pub use internet::{IcmpRateLimit, InternetOptions};
pub use license::{License, LicenseAutoupdate, LicenseRenew};
pub use location::Location;
pub use login::{Login, LoginClass, LoginPassword, LoginRetryOptions, LoginUser};
pub use ntp::{Ntp, NtpAuthenticationKey, NtpHost};
pub use pixel_tracing::PixelTracing;
pub use ports::{Auxiliary, Console, Ports};
pub use processes::Process;
pub use schema::Schema;
pub use scripts::Scripts;
pub use service_deployment::{ServiceDeployment, ServiceDeploymentServer};
pub use services::{
Netconf, NetconfSsh, OutboundSshClient, OutboundSshServer, Services, SshService, WebManagement, WebManagementHttp,
WebManagementHttps, XnmClearText, XnmSsl,
};
pub use subscriber::{
AaclStatisticsProfile, DhcpLocalServer, DhcpLocalServerGroup, DynamicProfileOptions, LocalPolicyDecisionFunction,
RedundancyInterface, StaticSubscriberGroup, StaticSubscriberProfile, StaticSubscribers, SubscriberManagement,
SubscriberRedundancy,
};
pub use syslog::{Syslog, SyslogArchive, SyslogHost, SyslogRule, SyslogStructuredData, SyslogTarget};
use crate::{arg_of, args_of, child_block, has_leaf, list_values, top_level};
use accounting::parse_accounting;
use addressing::{name_servers, parse_backup_router, static_host_mappings};
use archival::parse_archival;
use asterust::config::Config;
use auth::{parse_master_password, password_methods, radius_servers, root_authentication, tacplus_servers};
use autoinstallation::parse_autoinstallation;
use commit::parse_commit;
use extensions::parse_extensions;
use internet::parse_internet_options;
use license::parse_license;
use location::parse_location;
use login::parse_login;
use ntp::parse_ntp;
use pixel_tracing::parse_pixel_tracing;
use ports::parse_ports;
use processes::parse_processes;
use schema::parse_schema;
use scripts::parse_scripts;
use services::parse_services;
use subscriber::parse_dynamic_profile_options;
use syslog::parse_syslog;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct System {
pub host_name: Option<String>,
pub domain_name: Option<String>,
pub time_zone: Option<String>,
pub domain_search: Vec<String>,
pub static_host_mappings: Vec<StaticHostMapping>,
pub backup_router: Option<BackupRouter>,
pub inet6_backup_router: Option<BackupRouter>,
pub authentication_order: Vec<String>,
pub radius_servers: Vec<RadiusServer>,
pub tacplus_servers: Vec<TacplusServer>,
pub location: Option<Location>,
pub ports: Option<Ports>,
pub max_configurations_on_flash: Option<String>,
pub max_configuration_rollbacks: Option<String>,
pub no_redirects: bool,
pub default_address_selection: bool,
pub internet_options: Option<InternetOptions>,
pub commit: Option<Commit>,
pub processes: Vec<Process>,
pub dynamic_profile_options: Option<DynamicProfileOptions>,
pub extensions: Option<Extensions>,
pub autoinstallation: Option<Autoinstallation>,
pub schema: Option<Schema>,
pub pixel_tracing: Option<PixelTracing>,
pub scripts: Option<Scripts>,
pub no_multicast_echo: bool,
pub no_ping_record_route: bool,
pub no_ping_time_stamp: bool,
pub auto_snapshot: bool,
pub compress_configuration_files: bool,
pub mirror_flash_on_disk: bool,
pub switchover_on_routing_crash: bool,
pub use_imported_time_zones: bool,
pub archival: Option<Archival>,
pub accounting: Option<Accounting>,
pub root_authentication: Option<RootAuthentication>,
pub master_password: Option<MasterPassword>,
pub diag_port_authentication: Vec<String>,
pub pic_console_authentication: Vec<String>,
pub license: Option<License>,
pub name_servers: Vec<NameServer>,
pub ntp: Option<Ntp>,
pub syslog: Option<Syslog>,
pub login: Option<Login>,
pub services: Option<Services>,
}
pub fn system(config: &Config) -> Option<System> {
let system = top_level(config, "system")?;
Some(System {
host_name: arg_of(system, "host-name").map(str::to_string),
domain_name: arg_of(system, "domain-name").map(str::to_string),
time_zone: arg_of(system, "time-zone").map(str::to_string),
domain_search: args_of(system, "domain-search")
.into_iter()
.flat_map(list_values)
.collect(),
static_host_mappings: static_host_mappings(system),
backup_router: arg_of(system, "backup-router").map(parse_backup_router),
inet6_backup_router: arg_of(system, "inet6-backup-router").map(parse_backup_router),
authentication_order: args_of(system, "authentication-order")
.into_iter()
.flat_map(list_values)
.collect(),
radius_servers: radius_servers(system, "radius-server"),
tacplus_servers: tacplus_servers(system, "tacplus-server"),
location: child_block(system, "location").map(parse_location),
ports: child_block(system, "ports").map(parse_ports),
max_configurations_on_flash: arg_of(system, "max-configurations-on-flash").map(str::to_string),
max_configuration_rollbacks: arg_of(system, "max-configuration-rollbacks").map(str::to_string),
no_redirects: has_leaf(system, "no-redirects"),
default_address_selection: has_leaf(system, "default-address-selection"),
internet_options: child_block(system, "internet-options").map(parse_internet_options),
commit: child_block(system, "commit").map(parse_commit),
processes: child_block(system, "processes")
.map(parse_processes)
.unwrap_or_default(),
dynamic_profile_options: child_block(system, "dynamic-profile-options").map(parse_dynamic_profile_options),
extensions: child_block(system, "extensions").map(parse_extensions),
autoinstallation: child_block(system, "autoinstallation").map(parse_autoinstallation),
schema: child_block(system, "schema").map(parse_schema),
pixel_tracing: child_block(system, "pixel-tracing").map(parse_pixel_tracing),
scripts: child_block(system, "scripts").map(parse_scripts),
no_multicast_echo: has_leaf(system, "no-multicast-echo"),
no_ping_record_route: has_leaf(system, "no-ping-record-route"),
no_ping_time_stamp: has_leaf(system, "no-ping-time-stamp"),
auto_snapshot: has_leaf(system, "auto-snapshot"),
compress_configuration_files: has_leaf(system, "compress-configuration-files"),
mirror_flash_on_disk: has_leaf(system, "mirror-flash-on-disk"),
switchover_on_routing_crash: has_leaf(system, "switchover-on-routing-crash"),
use_imported_time_zones: has_leaf(system, "use-imported-time-zones"),
archival: child_block(system, "archival").map(parse_archival),
accounting: child_block(system, "accounting").map(parse_accounting),
root_authentication: root_authentication(system),
master_password: child_block(system, "master-password").map(parse_master_password),
diag_port_authentication: password_methods(system, "diag-port-authentication"),
pic_console_authentication: password_methods(system, "pic-console-authentication"),
license: child_block(system, "license").map(parse_license),
name_servers: name_servers(system),
ntp: child_block(system, "ntp").map(parse_ntp),
syslog: child_block(system, "syslog").map(parse_syslog),
login: child_block(system, "login").map(parse_login),
services: child_block(system, "services").map(parse_services),
})
}
#[cfg(test)]
mod tests {
use super::*;
use asterust::config::juniper;
#[test]
fn extracts_host_name() {
let system = system(&juniper::parse_braces("system {\n host-name pe1;\n}\n")).unwrap();
assert_eq!(system.host_name.as_deref(), Some("pe1"));
}
#[test]
fn host_name_is_optional() {
let system = system(&juniper::parse_braces("system {\n domain-name example.net;\n}\n")).unwrap();
assert_eq!(system.host_name, None);
}
#[test]
fn skips_inactive_host_name() {
let system = system(&juniper::parse_braces("system {\n inactive: host-name pe1;\n}\n")).unwrap();
assert_eq!(system.host_name, None);
}
#[test]
fn extracts_domain_name() {
let system = system(&juniper::parse_braces(
"system {\n host-name pe1;\n domain-name example.net;\n}\n",
))
.unwrap();
assert_eq!(system.domain_name.as_deref(), Some("example.net"));
}
#[test]
fn domain_name_is_optional() {
let system = system(&juniper::parse_braces("system {\n host-name pe1;\n}\n")).unwrap();
assert_eq!(system.domain_name, None);
}
#[test]
fn extracts_time_zone() {
let system = system(&juniper::parse_braces("system {\n time-zone America/New_York;\n}\n")).unwrap();
assert_eq!(system.time_zone.as_deref(), Some("America/New_York"));
}
#[test]
fn time_zone_is_optional() {
let system = system(&juniper::parse_braces("system {\n host-name pe1;\n}\n")).unwrap();
assert_eq!(system.time_zone, None);
}
#[test]
fn extracts_configuration_limits_and_no_redirects() {
let system = system(&juniper::parse_braces(
"system {\n max-configurations-on-flash 5;\n max-configuration-rollbacks 20;\n no-redirects;\n}\n",
))
.unwrap();
assert_eq!(system.max_configurations_on_flash.as_deref(), Some("5"));
assert_eq!(system.max_configuration_rollbacks.as_deref(), Some("20"));
assert!(system.no_redirects);
}
#[test]
fn configuration_limits_are_optional() {
let system = system(&juniper::parse_braces("system {\n host-name pe1;\n}\n")).unwrap();
assert_eq!(system.max_configurations_on_flash, None);
assert_eq!(system.max_configuration_rollbacks, None);
assert!(!system.no_redirects);
}
#[test]
fn extracts_system_flags() {
let system = system(&juniper::parse_braces(
"system {\n no-multicast-echo;\n no-ping-record-route;\n no-ping-time-stamp;\n auto-snapshot;\n compress-configuration-files;\n mirror-flash-on-disk;\n switchover-on-routing-crash;\n use-imported-time-zones;\n}\n",
))
.unwrap();
assert!(system.no_multicast_echo);
assert!(system.no_ping_record_route);
assert!(system.no_ping_time_stamp);
assert!(system.auto_snapshot);
assert!(system.compress_configuration_files);
assert!(system.mirror_flash_on_disk);
assert!(system.switchover_on_routing_crash);
assert!(system.use_imported_time_zones);
}
#[test]
fn system_flags_default_to_off() {
let system = system(&juniper::parse_braces("system {\n host-name pe1;\n}\n")).unwrap();
assert!(!system.no_multicast_echo);
assert!(!system.auto_snapshot);
assert!(!system.use_imported_time_zones);
}
#[test]
fn no_system_is_none() {
assert!(system(&juniper::parse_braces("interfaces {\n lo0;\n}\n")).is_none());
}
}