Skip to main content

asterust_junos/interfaces/
tca.rs

1//! `tca`
2//! `interfaces <name> { optics-options { tca ... } }` and `interfaces <name> { otn-options { tca ... } }`.
3//!
4//! # See also
5//!
6//! - [tca](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/tca-edit-interfaces-otn-options.html)
7
8use crate::split_keyword;
9
10/// A threshold crossing alert, `tca <identifier> (enable-tca | no-enable-tca) (threshold <n> | threshold-24hrs <n>)`.
11#[derive(Clone, Debug, PartialEq, Eq)]
12#[non_exhaustive]
13pub struct Tca {
14    /// The alert, e.g. `"odu-bbe"`.
15    pub identifier: String,
16    /// `Some(true)` for `enable-tca`, `Some(false)` for `no-enable-tca`.
17    pub enabled: Option<bool>,
18    pub threshold: Option<String>,
19    pub threshold_24hrs: Option<String>,
20}
21
22/// Parses the argument of a `tca` statement.
23pub(super) fn parse_tca(arg: &str) -> Tca {
24    let (identifier, rest) = split_keyword(arg);
25    let words: Vec<&str> = rest.split_whitespace().collect();
26    let enabled = if words.contains(&"enable-tca") {
27        Some(true)
28    } else if words.contains(&"no-enable-tca") {
29        Some(false)
30    } else {
31        None
32    };
33    Tca {
34        identifier: identifier.to_string(),
35        enabled,
36        threshold: crate::value_after(&words, "threshold"),
37        threshold_24hrs: crate::value_after(&words, "threshold-24hrs"),
38    }
39}