From f9bd6ad260f217e1a6b08ae296c5ddfedc32ba99 Mon Sep 17 00:00:00 2001 From: Jean-Gabriel Gill-Couture Date: Mon, 16 Feb 2026 21:08:56 -0500 Subject: [PATCH] reafactor: brocade switch slight improvements --- brocade/src/lib.rs | 2 +- brocade/src/shell.rs | 2 +- brocade/src/ssh.rs | 2 +- examples/okd_installation/src/topology.rs | 16 ++++++------ examples/okd_pxe/src/topology.rs | 11 ++++---- harmony/src/infra/brocade.rs | 28 +++++++++++++-------- harmony/src/modules/brocade/brocade.rs | 11 +++----- harmony/src/modules/brocade/brocade_snmp.rs | 12 ++++----- 8 files changed, 43 insertions(+), 41 deletions(-) diff --git a/brocade/src/lib.rs b/brocade/src/lib.rs index f51056ed..5fc3ac95 100644 --- a/brocade/src/lib.rs +++ b/brocade/src/lib.rs @@ -144,7 +144,7 @@ pub async fn init( ip_addresses: &[IpAddr], username: &str, password: &str, - options: BrocadeOptions, + options: &BrocadeOptions, ) -> Result, Error> { let shell = BrocadeShell::init(ip_addresses, username, password, options).await?; diff --git a/brocade/src/shell.rs b/brocade/src/shell.rs index f72c31b9..a44c5fda 100644 --- a/brocade/src/shell.rs +++ b/brocade/src/shell.rs @@ -28,7 +28,7 @@ impl BrocadeShell { ip_addresses: &[IpAddr], username: &str, password: &str, - options: BrocadeOptions, + options: &BrocadeOptions, ) -> Result { let ip = ip_addresses .first() diff --git a/brocade/src/ssh.rs b/brocade/src/ssh.rs index cb804c7c..89cfae3b 100644 --- a/brocade/src/ssh.rs +++ b/brocade/src/ssh.rs @@ -70,7 +70,7 @@ pub async fn try_init_client( username: &str, password: &str, ip: &std::net::IpAddr, - base_options: BrocadeOptions, + base_options: &BrocadeOptions, ) -> Result { let mut default = SshOptions::default(); default.port = base_options.ssh.port; diff --git a/examples/okd_installation/src/topology.rs b/examples/okd_installation/src/topology.rs index 37478683..71621757 100644 --- a/examples/okd_installation/src/topology.rs +++ b/examples/okd_installation/src/topology.rs @@ -2,7 +2,10 @@ use brocade::BrocadeOptions; use cidr::Ipv4Cidr; use harmony::{ hardware::{Location, SwitchGroup}, - infra::{brocade::BrocadeSwitchClient, opnsense::OPNSenseManagementInterface}, + infra::{ + brocade::{BrocadeSwitchClient, BrocadeSwitchConfig}, + opnsense::OPNSenseManagementInterface, + }, inventory::Inventory, topology::{HAClusterTopology, LogicalHost, UnmanagedRouter}, }; @@ -36,12 +39,11 @@ pub async fn get_topology() -> HAClusterTopology { dry_run: *harmony::config::DRY_RUN, ..Default::default() }; - let switch_client = BrocadeSwitchClient::init( - &switches, - &switch_auth.username, - &switch_auth.password, - brocade_options, - ) + let switch_client = BrocadeSwitchClient::init(BrocadeSwitchConfig { + ips: switches, + auth: switch_auth, + options: brocade_options, + }) .await .expect("Failed to connect to switch"); diff --git a/examples/okd_pxe/src/topology.rs b/examples/okd_pxe/src/topology.rs index 0cc4e2a1..58a54905 100644 --- a/examples/okd_pxe/src/topology.rs +++ b/examples/okd_pxe/src/topology.rs @@ -31,12 +31,11 @@ pub async fn get_topology() -> HAClusterTopology { dry_run: *harmony::config::DRY_RUN, ..Default::default() }; - let switch_client = BrocadeSwitchClient::init( - &switches, - &switch_auth.username, - &switch_auth.password, - brocade_options, - ) + let switch_client = BrocadeSwitchClient::init(BrocadeSwitchConfig { + ips: switches, + auth: switch_auth, + options: brocade_options, + }) .await .expect("Failed to connect to switch"); diff --git a/harmony/src/infra/brocade.rs b/harmony/src/infra/brocade.rs index 26935afb..8627c26d 100644 --- a/harmony/src/infra/brocade.rs +++ b/harmony/src/infra/brocade.rs @@ -5,15 +5,18 @@ use harmony_types::{ net::{IpAddress, MacAddress}, switch::{PortDeclaration, PortLocation}, }; +use log::info; use option_ext::OptionExt; -use crate::topology::{PortConfig, SwitchClient, SwitchError}; +use crate::{ + modules::brocade::BrocadeSwitchAuth, + topology::{PortConfig, SwitchClient, SwitchError}, +}; #[derive(Debug, Clone)] pub struct BrocadeSwitchConfig { pub ips: Vec, - pub username: String, - pub password: String, + pub auth: BrocadeSwitchAuth, pub options: BrocadeOptions, } @@ -23,13 +26,11 @@ pub struct BrocadeSwitchClient { } impl BrocadeSwitchClient { - pub async fn init( - ip_addresses: &[IpAddress], - username: &str, - password: &str, - options: BrocadeOptions, - ) -> Result { - let brocade = brocade::init(ip_addresses, username, password, options).await?; + pub async fn init(config: BrocadeSwitchConfig) -> Result { + let auth = &config.auth; + let options = &config.options; + + let brocade = brocade::init(&config.ips, &auth.username, &auth.password, options).await?; Ok(Self { brocade }) } } @@ -60,13 +61,18 @@ impl SwitchClient for BrocadeSwitchClient { || link.remote_port.contains(&interface.port_location) }) }) - .map(|interface| (interface.name.clone(), PortOperatingMode::Access)) + .map(|interface| (interface.name.clone(), PortOperatingMode::Trunk)) .collect(); if interfaces.is_empty() { return Ok(()); } + info!("About to configure interfaces {interfaces:?}"); + inquire::Confirm::new("Do you wish to configures interfaces now?") + .prompt() + .map_err(|e| SwitchError::new(e.to_string()))?; + self.brocade .configure_interfaces(&interfaces) .await diff --git a/harmony/src/modules/brocade/brocade.rs b/harmony/src/modules/brocade/brocade.rs index b1331e53..67e94e51 100644 --- a/harmony/src/modules/brocade/brocade.rs +++ b/harmony/src/modules/brocade/brocade.rs @@ -104,14 +104,9 @@ impl Topology for SwitchTopology { impl SwitchTopology { pub async fn new(config: BrocadeSwitchConfig) -> Self { - let client = BrocadeSwitchClient::init( - &config.ips, - &config.username, - &config.password, - config.options, - ) - .await - .expect("Failed to connect to switch"); + let client = BrocadeSwitchClient::init(config) + .await + .expect("Failed to connect to switch"); let client = Box::new(client); Self { client } diff --git a/harmony/src/modules/brocade/brocade_snmp.rs b/harmony/src/modules/brocade/brocade_snmp.rs index 47ef38c9..0e75c865 100644 --- a/harmony/src/modules/brocade/brocade_snmp.rs +++ b/harmony/src/modules/brocade/brocade_snmp.rs @@ -40,15 +40,15 @@ pub struct BrocadeEnableSnmpInterpret { #[derive(Secret, Clone, Debug, JsonSchema, Serialize, Deserialize)] pub struct BrocadeSwitchAuth { - username: String, - password: String, + pub username: String, + pub password: String, } #[derive(Secret, Clone, Debug, JsonSchema, Serialize, Deserialize)] pub struct BrocadeSnmpAuth { - username: String, - auth_password: String, - des_password: String, + pub username: String, + pub auth_password: String, + pub des_password: String, } #[async_trait] @@ -72,7 +72,7 @@ impl Interpret for BrocadeEnableSnmpInterpret { &switch_addresses, &config.username, &config.password, - BrocadeOptions { + &BrocadeOptions { dry_run: self.score.dry_run, ..Default::default() }, -- 2.39.5