mirror of
https://github.com/threefoldtech/mycelium.git
synced 2026-05-25 09:54:05 +00:00
Add cli method to get no routes in myceliumd
Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
@@ -8,4 +8,6 @@ pub use inspect::inspect;
|
||||
#[cfg(feature = "message")]
|
||||
pub use message::{recv_msg, send_msg};
|
||||
pub use peer::{add_peers, list_peers, remove_peers};
|
||||
pub use routes::{list_fallback_routes, list_queried_subnets, list_selected_routes};
|
||||
pub use routes::{
|
||||
list_fallback_routes, list_no_route_entries, list_queried_subnets, list_selected_routes,
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use mycelium_api::{QueriedSubnet, Route};
|
||||
use mycelium_api::{NoRouteSubnet, QueriedSubnet, Route};
|
||||
use prettytable::{row, Table};
|
||||
use std::net::SocketAddr;
|
||||
|
||||
@@ -116,3 +116,37 @@ pub async fn list_queried_subnets(
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn list_no_route_entries(
|
||||
server_addr: SocketAddr,
|
||||
json_print: bool,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let request_url = format!("http://{server_addr}/api/v1/admin/routes/no_route");
|
||||
match reqwest::get(&request_url).await {
|
||||
Err(e) => {
|
||||
error!("Failed to retrieve subnets with no route entries");
|
||||
return Err(e.into());
|
||||
}
|
||||
Ok(resp) => {
|
||||
debug!("Listing no route entries");
|
||||
|
||||
if json_print {
|
||||
// API call returns routes in JSON format by default
|
||||
let nrs = resp.text().await?;
|
||||
println!("{nrs}");
|
||||
} else {
|
||||
// Print routes in table format
|
||||
let no_routes: Vec<NoRouteSubnet> = resp.json().await?;
|
||||
let mut table = Table::new();
|
||||
table.add_row(row!["Subnet", "Entry expiration"]);
|
||||
|
||||
for nrs in no_routes.iter() {
|
||||
table.add_row(row![nrs.subnet, nrs.expiration,]);
|
||||
}
|
||||
|
||||
table.printstd();
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
+10
-1
@@ -130,7 +130,7 @@ pub enum Command {
|
||||
command: PeersCommand,
|
||||
},
|
||||
|
||||
/// Actions related to routes (selected, fallback)
|
||||
/// Actions related to routes (selected, fallback, queried, no route)
|
||||
Routes {
|
||||
#[command(subcommand)]
|
||||
command: RoutesCommand,
|
||||
@@ -214,6 +214,12 @@ pub enum RoutesCommand {
|
||||
#[arg(long = "json", default_value_t = false)]
|
||||
json: bool,
|
||||
},
|
||||
/// Print all subnets which are explicitly marked as not having a route
|
||||
NoRoute {
|
||||
/// Print subnets in JSON format
|
||||
#[arg(long = "json", default_value_t = false)]
|
||||
json: bool,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
@@ -575,6 +581,9 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
RoutesCommand::Queried { json } => {
|
||||
return mycelium_cli::list_queried_subnets(cli.node_args.api_addr, json).await;
|
||||
}
|
||||
RoutesCommand::NoRoute { json } => {
|
||||
return mycelium_cli::list_no_route_entries(cli.node_args.api_addr, json).await;
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user