Skip to main content

nmstate/policy/
iface.rs

1// SPDX-License-Identifier: Apache-2.0
2
3use super::json::{search_item, update_items};
4use crate::{Interface, Interfaces, NetworkState, NmstateError};
5
6pub(crate) fn get_iface_match(
7    prop_path: &[String],
8    value: &str,
9    state: &NetworkState,
10    line: &str,
11    pos: usize,
12) -> Result<Interfaces, NmstateError> {
13    let mut ret = Interfaces::new();
14    for iface in search_item(
15        "interface",
16        prop_path,
17        value,
18        state.interfaces.to_vec().as_slice(),
19        line,
20        pos,
21    )? {
22        ret.push(iface.clone());
23    }
24
25    Ok(ret)
26}
27
28pub(crate) fn update_ifaces(
29    prop_path: &[String],
30    value: Option<&str>,
31    state: &NetworkState,
32    line: &str,
33    pos: usize,
34) -> Result<Interfaces, NmstateError> {
35    let ifaces: Vec<Interface> = state
36        .interfaces
37        .to_vec()
38        .as_slice()
39        .iter()
40        .cloned()
41        .cloned()
42        .collect();
43
44    let mut ret = Interfaces::new();
45    for iface in
46        update_items("interface", prop_path, value, &ifaces, line, pos)?
47    {
48        ret.push(iface);
49    }
50    Ok(ret)
51}