All checks were successful
Run Check Script / check (pull_request) Successful in 1m5s
* Expose a high-level `brocade::init()` function to connect to a Brocade switch and automatically pick the best implementation based on its OS and version * Implement a client for Brocade switches running on Network Operating System (NOS) * Implement a client for older Brocade switches running on FastIron (partial implementation) The architecture for the library is based on 3 layers: 1. The `BrocadeClient` trait to describe the available capabilities to interact with a Brocade switch. It is partly opinionated in order to offer higher level features to group multiple commands into a single function (e.g. create a port channel). Its implementations are basically just the commands to run on the switch and the functions to parse the output. 2. The `BrocadeShell` struct to make it easier to authenticate, send commands, and interact with the switch. 3. The `ssh` module to actually connect to the switch over SSH and execute the commands. With time, we will add support for more Brocade switches and their various OS/versions. If needed, shared behavior could be extracted into a separate module to make it easier to add new implementations.
71 lines
2.1 KiB
Rust
71 lines
2.1 KiB
Rust
use std::net::{IpAddr, Ipv4Addr};
|
|
|
|
use brocade::BrocadeOptions;
|
|
use harmony_secret::{Secret, SecretManager};
|
|
use harmony_types::switch::PortLocation;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Secret, Clone, Debug, Serialize, Deserialize)]
|
|
struct BrocadeSwitchAuth {
|
|
username: String,
|
|
password: String,
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
|
|
|
|
// let ip = IpAddr::V4(Ipv4Addr::new(10, 0, 0, 250)); // old brocade @ ianlet
|
|
let ip = IpAddr::V4(Ipv4Addr::new(192, 168, 55, 101)); // brocade @ sto1
|
|
// let ip = IpAddr::V4(Ipv4Addr::new(192, 168, 4, 11)); // brocade @ st
|
|
let switch_addresses = vec![ip];
|
|
|
|
let config = SecretManager::get_or_prompt::<BrocadeSwitchAuth>()
|
|
.await
|
|
.unwrap();
|
|
|
|
let brocade = brocade::init(
|
|
&switch_addresses,
|
|
22,
|
|
&config.username,
|
|
&config.password,
|
|
Some(BrocadeOptions {
|
|
dry_run: true,
|
|
..Default::default()
|
|
}),
|
|
)
|
|
.await
|
|
.expect("Brocade client failed to connect");
|
|
|
|
let entries = brocade.get_stack_topology().await.unwrap();
|
|
println!("Stack topology: {entries:#?}");
|
|
|
|
let entries = brocade.get_interfaces().await.unwrap();
|
|
println!("Interfaces: {entries:#?}");
|
|
|
|
let version = brocade.version().await.unwrap();
|
|
println!("Version: {version:?}");
|
|
|
|
println!("--------------");
|
|
let mac_adddresses = brocade.get_mac_address_table().await.unwrap();
|
|
println!("VLAN\tMAC\t\t\tPORT");
|
|
for mac in mac_adddresses {
|
|
println!("{}\t{}\t{}", mac.vlan, mac.mac_address, mac.port);
|
|
}
|
|
|
|
println!("--------------");
|
|
let channel_name = "1";
|
|
brocade.clear_port_channel(channel_name).await.unwrap();
|
|
|
|
println!("--------------");
|
|
let channel_id = brocade.find_available_channel_id().await.unwrap();
|
|
|
|
println!("--------------");
|
|
let channel_name = "HARMONY_LAG";
|
|
let ports = [PortLocation(2, 0, 35)];
|
|
brocade
|
|
.create_port_channel(channel_id, channel_name, &ports)
|
|
.await
|
|
.unwrap();
|
|
}
|