asterust_junos/system/
auto_sw_sync.rs1use crate::{args_of, value_after};
9use asterust::config::ConfigLine;
10
11#[derive(Clone, Debug, PartialEq, Eq)]
13#[non_exhaustive]
14pub struct AutoSwSync {
15 pub node: String,
16 pub enabled: Option<bool>,
18}
19
20pub(super) fn auto_sw_sync(system: &ConfigLine) -> Vec<AutoSwSync> {
21 args_of(system, "auto-sw-sync")
22 .into_iter()
23 .filter_map(|arg| {
24 let words: Vec<&str> = arg.split_whitespace().collect();
25 Some(AutoSwSync {
26 node: value_after(&words, "node")?,
27 enabled: if words.contains(&"enable") {
28 Some(true)
29 } else if words.contains(&"disable") {
30 Some(false)
31 } else {
32 None
33 },
34 })
35 })
36 .collect()
37}
38
39#[cfg(test)]
40mod tests {
41 use crate::system::system;
42 use asterust::config::juniper;
43
44 #[test]
46 fn extracts_auto_sw_sync_per_node() {
47 let nodes = system(&juniper::parse_braces(
48 "system {\n auto-sw-sync node re0 enable;\n auto-sw-sync node re1 disable;\n}\n",
49 ))
50 .unwrap()
51 .auto_sw_sync;
52 assert_eq!(nodes.len(), 2);
53 assert_eq!(nodes[0].node, "re0");
54 assert_eq!(nodes[0].enabled, Some(true));
55 assert_eq!(nodes[1].node, "re1");
56 assert_eq!(nodes[1].enabled, Some(false));
57 }
58
59 #[test]
60 fn no_auto_sw_sync_is_empty() {
61 let system = system(&juniper::parse_braces("system {\n host-name pe1;\n}\n")).unwrap();
62 assert!(system.auto_sw_sync.is_empty());
63 }
64}