diff --git a/Cargo.lock b/Cargo.lock index f0504aa..321b2b1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -690,6 +690,23 @@ dependencies = [ "tokio", ] +[[package]] +name = "brocade-switch" +version = "0.1.0" +dependencies = [ + "async-trait", + "brocade", + "env_logger", + "harmony", + "harmony_cli", + "harmony_macros", + "harmony_types", + "log", + "serde", + "tokio", + "url", +] + [[package]] name = "brotli" version = "8.0.2" @@ -1853,18 +1870,6 @@ dependencies = [ "url", ] -[[package]] -name = "example-penpot" -version = "0.1.0" -dependencies = [ - "harmony", - "harmony_cli", - "harmony_macros", - "harmony_types", - "tokio", - "url", -] - [[package]] name = "example-pxe" version = "0.1.0" @@ -2569,6 +2574,7 @@ dependencies = [ name = "harmony_types" version = "0.1.0" dependencies = [ + "log", "rand 0.9.2", "serde", "url", diff --git a/brocade/examples/main.rs b/brocade/examples/main.rs index de8623d..47d4a63 100644 --- a/brocade/examples/main.rs +++ b/brocade/examples/main.rs @@ -1,6 +1,6 @@ use std::net::{IpAddr, Ipv4Addr}; -use brocade::BrocadeOptions; +use brocade::{BrocadeOptions, ssh}; use harmony_secret::{Secret, SecretManager}; use harmony_types::switch::PortLocation; use serde::{Deserialize, Serialize}; @@ -16,20 +16,26 @@ 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(127, 0, 0, 1)); // 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::() - .await - .unwrap(); + // let config = SecretManager::get_or_prompt::() + // .await + // .unwrap(); let brocade = brocade::init( &switch_addresses, - &config.username, - &config.password, + // &config.username, + // &config.password, + "admin", + "password", BrocadeOptions { dry_run: true, + ssh: ssh::SshOptions { + port: 2222, + ..Default::default() + }, ..Default::default() }, ) @@ -53,6 +59,7 @@ async fn main() { } println!("--------------"); + todo!(); let channel_name = "1"; brocade.clear_port_channel(channel_name).await.unwrap(); diff --git a/examples/nanodc/src/main.rs b/examples/nanodc/src/main.rs index e487fab..ee19074 100644 --- a/examples/nanodc/src/main.rs +++ b/examples/nanodc/src/main.rs @@ -39,10 +39,10 @@ async fn main() { .expect("Failed to get credentials"); let switches: Vec = vec![ip!("192.168.33.101")]; - let brocade_options = Some(BrocadeOptions { + let brocade_options = BrocadeOptions { dry_run: *harmony::config::DRY_RUN, ..Default::default() - }); + }; let switch_client = BrocadeSwitchClient::init( &switches, &switch_auth.username, diff --git a/examples/okd_installation/src/topology.rs b/examples/okd_installation/src/topology.rs index 2bc9fd2..6af30fd 100644 --- a/examples/okd_installation/src/topology.rs +++ b/examples/okd_installation/src/topology.rs @@ -31,10 +31,10 @@ pub async fn get_topology() -> HAClusterTopology { .expect("Failed to get credentials"); let switches: Vec = vec![ip!("192.168.1.101")]; // TODO: Adjust me - let brocade_options = Some(BrocadeOptions { + let brocade_options = BrocadeOptions { dry_run: *harmony::config::DRY_RUN, ..Default::default() - }); + }; let switch_client = BrocadeSwitchClient::init( &switches, &switch_auth.username, diff --git a/examples/okd_pxe/src/topology.rs b/examples/okd_pxe/src/topology.rs index 72695fa..c32bf16 100644 --- a/examples/okd_pxe/src/topology.rs +++ b/examples/okd_pxe/src/topology.rs @@ -26,10 +26,10 @@ pub async fn get_topology() -> HAClusterTopology { .expect("Failed to get credentials"); let switches: Vec = vec![ip!("192.168.1.101")]; // TODO: Adjust me - let brocade_options = Some(BrocadeOptions { + let brocade_options = BrocadeOptions { dry_run: *harmony::config::DRY_RUN, ..Default::default() - }); + }; let switch_client = BrocadeSwitchClient::init( &switches, &switch_auth.username, diff --git a/examples/opnsense/src/main.rs b/examples/opnsense/src/main.rs index e74f5da..9cfd4cf 100644 --- a/examples/opnsense/src/main.rs +++ b/examples/opnsense/src/main.rs @@ -35,10 +35,10 @@ async fn main() { .expect("Failed to get credentials"); let switches: Vec = vec![ip!("192.168.5.101")]; // TODO: Adjust me - let brocade_options = Some(BrocadeOptions { + let brocade_options = BrocadeOptions { dry_run: *harmony::config::DRY_RUN, ..Default::default() - }); + }; let switch_client = BrocadeSwitchClient::init( &switches, &switch_auth.username, diff --git a/harmony_types/Cargo.toml b/harmony_types/Cargo.toml index f02874e..d1ac556 100644 --- a/harmony_types/Cargo.toml +++ b/harmony_types/Cargo.toml @@ -9,3 +9,4 @@ license.workspace = true serde.workspace = true url.workspace = true rand.workspace = true +log.workspace = true diff --git a/harmony_types/src/switch.rs b/harmony_types/src/switch.rs index 359e776..611207d 100644 --- a/harmony_types/src/switch.rs +++ b/harmony_types/src/switch.rs @@ -1,5 +1,5 @@ use std::{fmt, str::FromStr}; - +use log::trace; use serde::Serialize; /// Simple error type for port parsing failures. @@ -72,6 +72,11 @@ impl FromStr for PortLocation { pub enum PortDeclaration { /// A single switch port defined by its location. Example: `PortDeclaration::Single(1/1/1)` Single(PortLocation), + /// A Named port, often used for virtual ports such as PortChannels. Example + /// ```rust + /// PortDeclaration::Named("1".to_string()) + /// ``` + Named(String), /// A strictly sequential range defined by two endpoints using the hyphen separator (`-`). /// All ports between the endpoints (inclusive) are implicitly included. /// Example: `PortDeclaration::Range(1/1/1, 1/1/4)` @@ -132,8 +137,14 @@ impl PortDeclaration { return Ok(PortDeclaration::Set(start_port, end_port)); } - let location = PortLocation::from_str(port_str)?; - Ok(PortDeclaration::Single(location)) + match PortLocation::from_str(port_str) { + Ok(loc) => Ok(PortDeclaration::Single(loc)), + Err(e) => { + trace!("Failed to parse PortLocation {port_str} : {e}"); + trace!("Falling back on named port"); + Ok(PortDeclaration::Named(port_str.to_string())) + } + } } } @@ -143,6 +154,7 @@ impl fmt::Display for PortDeclaration { PortDeclaration::Single(port) => write!(f, "{port}"), PortDeclaration::Range(start, end) => write!(f, "{start}-{end}"), PortDeclaration::Set(start, end) => write!(f, "{start}*{end}"), + PortDeclaration::Named(name) => write!(f, "{name}"), } } }