mirror of
https://github.com/speatzle/nfsense.git
synced 2025-05-11 10:58:21 +00:00
implement list network links
This commit is contained in:
parent
1ff5a41033
commit
3e7889a207
1 changed files with 21 additions and 3 deletions
|
@ -8,6 +8,7 @@ use crate::{
|
||||||
update_thing_by_index, update_thing_by_name,
|
update_thing_by_index, update_thing_by_name,
|
||||||
};
|
};
|
||||||
use jsonrpsee::{types::Params, RpcModule};
|
use jsonrpsee::{types::Params, RpcModule};
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
pub fn register_methods(module: &mut RpcModule<RpcState>) {
|
pub fn register_methods(module: &mut RpcModule<RpcState>) {
|
||||||
module
|
module
|
||||||
|
@ -85,7 +86,24 @@ pub fn register_methods(module: &mut RpcModule<RpcState>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn list_network_links(_: Params, _state: &RpcState) -> Result<Vec<Link>, ApiError> {
|
pub fn list_network_links(_: Params, _state: &RpcState) -> Result<Vec<Link>, ApiError> {
|
||||||
Ok(vec![Link {
|
match Command::new("ls")
|
||||||
name: "test1".to_string(),
|
.arg("-w")
|
||||||
}])
|
.arg("1")
|
||||||
|
.arg("/sys/class/net")
|
||||||
|
.output()
|
||||||
|
{
|
||||||
|
Ok(out) => {
|
||||||
|
let mut links = vec![];
|
||||||
|
let output = String::from_utf8_lossy(&out.stdout).to_string();
|
||||||
|
|
||||||
|
for l in output.split("\n") {
|
||||||
|
links.push(Link {
|
||||||
|
name: l.to_string(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(links)
|
||||||
|
}
|
||||||
|
Err(err) => Err(ApiError::IOError(err)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue