use crate::connectors::types::{ListsNetworkInterfaces, NetworkInterface}; use crate::connectors::utils::call_exec; use serde::Deserialize; use serde_json; #[derive(Deserialize)] struct ENInterface { ifname: String, flags: Vec, } impl From for NetworkInterface { fn from(inf: ENInterface) -> Self { NetworkInterface { enabled: inf.flags.contains(&String::from("UP")), machine_name: inf.ifname.clone(), ..Default::default() } } } pub struct EtcNetConnector {} impl ListsNetworkInterfaces for EtcNetConnector { fn list_network_interfaces(&self) -> Result, String> { let output = call_exec("ip", "ip", vec!["--json", "address"]).expect("calling ip failed"); let ifaces: Vec = serde_json::from_slice(&output).expect("ip returned shit"); Ok(ifaces .into_iter() .map(|inf| NetworkInterface::from(inf)) .collect()) } }