fix(types): Switch port location failed on port channel interfaces

This commit is contained in:
2025-11-11 09:53:59 -05:00
parent a0a8d5277c
commit d3634a6313
8 changed files with 56 additions and 30 deletions

30
Cargo.lock generated
View File

@@ -690,6 +690,23 @@ dependencies = [
"tokio", "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]] [[package]]
name = "brotli" name = "brotli"
version = "8.0.2" version = "8.0.2"
@@ -1853,18 +1870,6 @@ dependencies = [
"url", "url",
] ]
[[package]]
name = "example-penpot"
version = "0.1.0"
dependencies = [
"harmony",
"harmony_cli",
"harmony_macros",
"harmony_types",
"tokio",
"url",
]
[[package]] [[package]]
name = "example-pxe" name = "example-pxe"
version = "0.1.0" version = "0.1.0"
@@ -2569,6 +2574,7 @@ dependencies = [
name = "harmony_types" name = "harmony_types"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"log",
"rand 0.9.2", "rand 0.9.2",
"serde", "serde",
"url", "url",

View File

@@ -1,6 +1,6 @@
use std::net::{IpAddr, Ipv4Addr}; use std::net::{IpAddr, Ipv4Addr};
use brocade::BrocadeOptions; use brocade::{BrocadeOptions, ssh};
use harmony_secret::{Secret, SecretManager}; use harmony_secret::{Secret, SecretManager};
use harmony_types::switch::PortLocation; use harmony_types::switch::PortLocation;
use serde::{Deserialize, Serialize}; 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(); 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(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 ip = IpAddr::V4(Ipv4Addr::new(192, 168, 4, 11)); // brocade @ st
let switch_addresses = vec![ip]; let switch_addresses = vec![ip];
let config = SecretManager::get_or_prompt::<BrocadeSwitchAuth>() // let config = SecretManager::get_or_prompt::<BrocadeSwitchAuth>()
.await // .await
.unwrap(); // .unwrap();
let brocade = brocade::init( let brocade = brocade::init(
&switch_addresses, &switch_addresses,
&config.username, // &config.username,
&config.password, // &config.password,
"admin",
"password",
BrocadeOptions { BrocadeOptions {
dry_run: true, dry_run: true,
ssh: ssh::SshOptions {
port: 2222,
..Default::default()
},
..Default::default() ..Default::default()
}, },
) )
@@ -53,6 +59,7 @@ async fn main() {
} }
println!("--------------"); println!("--------------");
todo!();
let channel_name = "1"; let channel_name = "1";
brocade.clear_port_channel(channel_name).await.unwrap(); brocade.clear_port_channel(channel_name).await.unwrap();

View File

@@ -39,10 +39,10 @@ async fn main() {
.expect("Failed to get credentials"); .expect("Failed to get credentials");
let switches: Vec<IpAddr> = vec![ip!("192.168.33.101")]; let switches: Vec<IpAddr> = vec![ip!("192.168.33.101")];
let brocade_options = Some(BrocadeOptions { let brocade_options = BrocadeOptions {
dry_run: *harmony::config::DRY_RUN, dry_run: *harmony::config::DRY_RUN,
..Default::default() ..Default::default()
}); };
let switch_client = BrocadeSwitchClient::init( let switch_client = BrocadeSwitchClient::init(
&switches, &switches,
&switch_auth.username, &switch_auth.username,

View File

@@ -31,10 +31,10 @@ pub async fn get_topology() -> HAClusterTopology {
.expect("Failed to get credentials"); .expect("Failed to get credentials");
let switches: Vec<IpAddr> = vec![ip!("192.168.1.101")]; // TODO: Adjust me let switches: Vec<IpAddr> = vec![ip!("192.168.1.101")]; // TODO: Adjust me
let brocade_options = Some(BrocadeOptions { let brocade_options = BrocadeOptions {
dry_run: *harmony::config::DRY_RUN, dry_run: *harmony::config::DRY_RUN,
..Default::default() ..Default::default()
}); };
let switch_client = BrocadeSwitchClient::init( let switch_client = BrocadeSwitchClient::init(
&switches, &switches,
&switch_auth.username, &switch_auth.username,

View File

@@ -26,10 +26,10 @@ pub async fn get_topology() -> HAClusterTopology {
.expect("Failed to get credentials"); .expect("Failed to get credentials");
let switches: Vec<IpAddr> = vec![ip!("192.168.1.101")]; // TODO: Adjust me let switches: Vec<IpAddr> = vec![ip!("192.168.1.101")]; // TODO: Adjust me
let brocade_options = Some(BrocadeOptions { let brocade_options = BrocadeOptions {
dry_run: *harmony::config::DRY_RUN, dry_run: *harmony::config::DRY_RUN,
..Default::default() ..Default::default()
}); };
let switch_client = BrocadeSwitchClient::init( let switch_client = BrocadeSwitchClient::init(
&switches, &switches,
&switch_auth.username, &switch_auth.username,

View File

@@ -35,10 +35,10 @@ async fn main() {
.expect("Failed to get credentials"); .expect("Failed to get credentials");
let switches: Vec<IpAddr> = vec![ip!("192.168.5.101")]; // TODO: Adjust me let switches: Vec<IpAddr> = vec![ip!("192.168.5.101")]; // TODO: Adjust me
let brocade_options = Some(BrocadeOptions { let brocade_options = BrocadeOptions {
dry_run: *harmony::config::DRY_RUN, dry_run: *harmony::config::DRY_RUN,
..Default::default() ..Default::default()
}); };
let switch_client = BrocadeSwitchClient::init( let switch_client = BrocadeSwitchClient::init(
&switches, &switches,
&switch_auth.username, &switch_auth.username,

View File

@@ -9,3 +9,4 @@ license.workspace = true
serde.workspace = true serde.workspace = true
url.workspace = true url.workspace = true
rand.workspace = true rand.workspace = true
log.workspace = true

View File

@@ -1,5 +1,5 @@
use std::{fmt, str::FromStr}; use std::{fmt, str::FromStr};
use log::trace;
use serde::Serialize; use serde::Serialize;
/// Simple error type for port parsing failures. /// Simple error type for port parsing failures.
@@ -72,6 +72,11 @@ impl FromStr for PortLocation {
pub enum PortDeclaration { pub enum PortDeclaration {
/// A single switch port defined by its location. Example: `PortDeclaration::Single(1/1/1)` /// A single switch port defined by its location. Example: `PortDeclaration::Single(1/1/1)`
Single(PortLocation), 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 (`-`). /// A strictly sequential range defined by two endpoints using the hyphen separator (`-`).
/// All ports between the endpoints (inclusive) are implicitly included. /// All ports between the endpoints (inclusive) are implicitly included.
/// Example: `PortDeclaration::Range(1/1/1, 1/1/4)` /// Example: `PortDeclaration::Range(1/1/1, 1/1/4)`
@@ -132,8 +137,14 @@ impl PortDeclaration {
return Ok(PortDeclaration::Set(start_port, end_port)); return Ok(PortDeclaration::Set(start_port, end_port));
} }
let location = PortLocation::from_str(port_str)?; match PortLocation::from_str(port_str) {
Ok(PortDeclaration::Single(location)) 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::Single(port) => write!(f, "{port}"),
PortDeclaration::Range(start, end) => write!(f, "{start}-{end}"), PortDeclaration::Range(start, end) => write!(f, "{start}-{end}"),
PortDeclaration::Set(start, end) => write!(f, "{start}*{end}"), PortDeclaration::Set(start, end) => write!(f, "{start}*{end}"),
PortDeclaration::Named(name) => write!(f, "{name}"),
} }
} }
} }