diff --git a/Cargo.lock b/Cargo.lock index 1b59329893..28bdb78e18 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11022,6 +11022,7 @@ dependencies = [ "chrono", "installinator-common", "ipnetwork", + "omicron-common", "omicron-workspace-hack", "progenitor", "regress", diff --git a/clients/wicketd-client/Cargo.toml b/clients/wicketd-client/Cargo.toml index 814309b975..d6f2ea0e54 100644 --- a/clients/wicketd-client/Cargo.toml +++ b/clients/wicketd-client/Cargo.toml @@ -8,6 +8,7 @@ license = "MPL-2.0" chrono.workspace = true installinator-common.workspace = true ipnetwork.workspace = true +omicron-common.workspace = true progenitor.workspace = true regress.workspace = true reqwest = { workspace = true, features = ["rustls-tls", "stream"] } diff --git a/clients/wicketd-client/src/lib.rs b/clients/wicketd-client/src/lib.rs index 09f9ca1418..a59f31ceca 100644 --- a/clients/wicketd-client/src/lib.rs +++ b/clients/wicketd-client/src/lib.rs @@ -44,33 +44,36 @@ progenitor::generate_api!( RackOperationStatus = { derives = [ PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize ] }, RackNetworkConfigV1 = { derives = [ PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize ] }, UplinkConfig = { derives = [ PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize ] }, - PortConfigV1 = { derives = [ PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize ] }, - BgpPeerConfig = { derives = [ PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize ] }, - BgpConfig = { derives = [ PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize ] }, - RouteConfig = { derives = [ PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize ] }, - CurrentRssUserConfigInsensitive = { derives = [ PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize ] }, + CurrentRssUserConfigInsensitive = { derives = [ PartialEq, Eq, Serialize, Deserialize ] }, CurrentRssUserConfigSensitive = { derives = [ PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize ] }, - CurrentRssUserConfig = { derives = [ PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize ] }, - UserSpecifiedRackNetworkConfig = { derives = [ PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize ] }, + CurrentRssUserConfig = { derives = [ PartialEq, Eq, Serialize, Deserialize ] }, GetLocationResponse = { derives = [ PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize ] }, }, replace = { + BgpConfig = omicron_common::api::internal::shared::BgpConfig, + BgpPeerConfig = omicron_common::api::internal::shared::BgpPeerConfig, + ClearUpdateStateResponse = wicket_common::rack_update::ClearUpdateStateResponse, Duration = std::time::Duration, + EventReportForWicketdEngineSpec = wicket_common::update_events::EventReport, + IpNetwork = ipnetwork::IpNetwork, Ipv4Network = ipnetwork::Ipv4Network, Ipv6Network = ipnetwork::Ipv6Network, - IpNetwork = ipnetwork::IpNetwork, + M2Slot = installinator_common::M2Slot, + PortConfigV1 = omicron_common::api::internal::shared::PortConfigV1, + PortFec = omicron_common::api::internal::shared::PortFec, + PortSpeed = omicron_common::api::internal::shared::PortSpeed, + ProgressEventForGenericSpec = update_engine::events::ProgressEvent, + ProgressEventForInstallinatorSpec = installinator_common::ProgressEvent, + ProgressEventForWicketdEngineSpec = wicket_common::update_events::ProgressEvent, PutRssUserConfigInsensitive = wicket_common::rack_setup::PutRssUserConfigInsensitive, - ClearUpdateStateResponse = wicket_common::rack_update::ClearUpdateStateResponse, + RouteConfig = omicron_common::api::internal::shared::RouteConfig, SpIdentifier = wicket_common::rack_update::SpIdentifier, SpType = wicket_common::rack_update::SpType, - EventReportForWicketdEngineSpec = wicket_common::update_events::EventReport, - StepEventForWicketdEngineSpec = wicket_common::update_events::StepEvent, - ProgressEventForWicketdEngineSpec = wicket_common::update_events::ProgressEvent, StepEventForGenericSpec = update_engine::events::StepEvent, - ProgressEventForGenericSpec = update_engine::events::ProgressEvent, StepEventForInstallinatorSpec = installinator_common::StepEvent, - ProgressEventForInstallinatorSpec = installinator_common::ProgressEvent, - M2Slot = installinator_common::M2Slot, + StepEventForWicketdEngineSpec = wicket_common::update_events::StepEvent, + SwitchLocation = omicron_common::api::internal::shared::SwitchLocation, + UserSpecifiedRackNetworkConfig = wicket_common::rack_setup::UserSpecifiedRackNetworkConfig, } ); diff --git a/common/src/api/internal/shared.rs b/common/src/api/internal/shared.rs index 6637dcb581..09c2e9b6ed 100644 --- a/common/src/api/internal/shared.rs +++ b/common/src/api/internal/shared.rs @@ -13,7 +13,7 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use std::{ collections::HashMap, - fmt::Display, + fmt, net::{IpAddr, Ipv4Addr, Ipv6Addr}, str::FromStr, }; @@ -174,7 +174,7 @@ pub struct RackNetworkConfigV1 { pub bfd: Vec, } -#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, JsonSchema)] +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, JsonSchema)] pub struct BgpConfig { /// The autonomous system number for the BGP configuration. pub asn: u32, @@ -182,7 +182,7 @@ pub struct BgpConfig { pub originate: Vec, } -#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, JsonSchema)] +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, JsonSchema)] pub struct BgpPeerConfig { /// The autonomous sysetm number of the router the peer belongs to. pub asn: u32, @@ -203,7 +203,7 @@ pub struct BgpPeerConfig { pub keepalive: Option, } -#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, JsonSchema)] +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, JsonSchema)] pub struct BfdPeerConfig { pub local: Option, pub remote: IpAddr, @@ -213,7 +213,7 @@ pub struct BfdPeerConfig { pub switch: SwitchLocation, } -#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, JsonSchema)] +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, JsonSchema)] pub struct RouteConfig { /// The destination of the route. pub destination: IpNetwork, @@ -221,7 +221,7 @@ pub struct RouteConfig { pub nexthop: IpAddr, } -#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, JsonSchema)] +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, JsonSchema)] pub struct PortConfigV1 { /// The set of routes associated with this port. pub routes: Vec, @@ -325,8 +325,8 @@ pub enum SwitchLocation { Switch1, } -impl Display for SwitchLocation { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Display for SwitchLocation { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { SwitchLocation::Switch0 => write!(f, "switch0"), SwitchLocation::Switch1 => write!(f, "switch1"), @@ -386,6 +386,22 @@ pub enum PortSpeed { Speed400G, } +impl fmt::Display for PortSpeed { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + PortSpeed::Speed0G => write!(f, "0G"), + PortSpeed::Speed1G => write!(f, "1G"), + PortSpeed::Speed10G => write!(f, "10G"), + PortSpeed::Speed25G => write!(f, "25G"), + PortSpeed::Speed40G => write!(f, "40G"), + PortSpeed::Speed50G => write!(f, "50G"), + PortSpeed::Speed100G => write!(f, "100G"), + PortSpeed::Speed200G => write!(f, "200G"), + PortSpeed::Speed400G => write!(f, "400G"), + } + } +} + /// Switchport FEC options #[derive( Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq, JsonSchema, Hash, @@ -396,3 +412,13 @@ pub enum PortFec { None, Rs, } + +impl fmt::Display for PortFec { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + PortFec::Firecode => write!(f, "Firecode R-FEC"), + PortFec::None => write!(f, "None"), + PortFec::Rs => write!(f, "RS-FEC"), + } + } +} diff --git a/wicket-common/src/rack_setup.rs b/wicket-common/src/rack_setup.rs index f28c0639a9..761877e9a4 100644 --- a/wicket-common/src/rack_setup.rs +++ b/wicket-common/src/rack_setup.rs @@ -16,7 +16,7 @@ use std::net::Ipv4Addr; /// User-specified parts of /// [`RackNetworkConfig`](omicron_common::api::internal::shared::RackNetworkConfig). -#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, JsonSchema)] pub struct UserSpecifiedRackNetworkConfig { pub infra_ip_first: Ipv4Addr, pub infra_ip_last: Ipv4Addr, diff --git a/wicket/src/cli/rack_setup/config_toml.rs b/wicket/src/cli/rack_setup/config_toml.rs index e0a519dc36..9b777a1726 100644 --- a/wicket/src/cli/rack_setup/config_toml.rs +++ b/wicket/src/cli/rack_setup/config_toml.rs @@ -15,11 +15,11 @@ use toml_edit::InlineTable; use toml_edit::Item; use toml_edit::Table; use toml_edit::Value; +use wicket_common::rack_setup::UserSpecifiedRackNetworkConfig; use wicket_common::rack_update::SpType; use wicketd_client::types::BootstrapSledDescription; use wicketd_client::types::CurrentRssUserConfigInsensitive; use wicketd_client::types::IpRange; -use wicketd_client::types::UserSpecifiedRackNetworkConfig; static TEMPLATE: &str = include_str!("config_template.toml"); @@ -349,31 +349,19 @@ fn populate_network_table( #[cfg(test)] mod tests { use super::*; + use omicron_common::api::external::SwitchLocation; + use omicron_common::api::internal::shared::{ + BgpConfig, BgpPeerConfig, PortConfigV1, PortFec, PortSpeed, RouteConfig, + }; use std::net::Ipv6Addr; use wicket_common::rack_setup::PutRssUserConfigInsensitive; use wicket_common::rack_update::SpIdentifier; use wicketd_client::types::Baseboard; - use wicketd_client::types::BgpConfig; - use wicketd_client::types::BgpPeerConfig; - use wicketd_client::types::PortConfigV1; - use wicketd_client::types::PortFec; - use wicketd_client::types::PortSpeed; - use wicketd_client::types::RouteConfig; - use wicketd_client::types::SwitchLocation; fn put_config_from_current_config( value: CurrentRssUserConfigInsensitive, ) -> PutRssUserConfigInsensitive { - use omicron_common::api::internal::shared::BgpConfig as InternalBgpConfig; - use omicron_common::api::internal::shared::BgpPeerConfig as InternalBgpPeerConfig; - use omicron_common::api::internal::shared::PortConfigV1 as InternalPortConfig; - use omicron_common::api::internal::shared::PortFec as InternalPortFec; - use omicron_common::api::internal::shared::PortSpeed as InternalPortSpeed; - use omicron_common::api::internal::shared::RouteConfig as InternalRouteConfig; - use omicron_common::api::internal::shared::SwitchLocation as InternalSwitchLocation; - use wicket_common::rack_setup::UserSpecifiedRackNetworkConfig as InternalUserSpecifiedRackNetworkConfig; - - let rnc = value.rack_network_config.unwrap(); + let rack_network_config = value.rack_network_config.unwrap(); PutRssUserConfigInsensitive { bootstrap_sleds: value @@ -400,79 +388,7 @@ mod tests { .collect(), external_dns_ips: value.external_dns_ips, ntp_servers: value.ntp_servers, - rack_network_config: InternalUserSpecifiedRackNetworkConfig { - infra_ip_first: rnc.infra_ip_first, - infra_ip_last: rnc.infra_ip_last, - ports: rnc - .ports - .iter() - .map(|config| InternalPortConfig { - routes: config - .routes - .iter() - .map(|r| InternalRouteConfig { - destination: r.destination, - nexthop: r.nexthop, - }) - .collect(), - addresses: config.addresses.clone(), - bgp_peers: config - .bgp_peers - .iter() - .map(|p| InternalBgpPeerConfig { - asn: p.asn, - port: p.port.clone(), - addr: p.addr, - hold_time: p.hold_time, - connect_retry: p.connect_retry, - delay_open: p.delay_open, - idle_hold_time: p.idle_hold_time, - keepalive: p.keepalive, - }) - .collect(), - port: config.port.clone(), - uplink_port_speed: match config.uplink_port_speed { - PortSpeed::Speed0G => InternalPortSpeed::Speed0G, - PortSpeed::Speed1G => InternalPortSpeed::Speed1G, - PortSpeed::Speed10G => InternalPortSpeed::Speed10G, - PortSpeed::Speed25G => InternalPortSpeed::Speed25G, - PortSpeed::Speed40G => InternalPortSpeed::Speed40G, - PortSpeed::Speed50G => InternalPortSpeed::Speed50G, - PortSpeed::Speed100G => { - InternalPortSpeed::Speed100G - } - PortSpeed::Speed200G => { - InternalPortSpeed::Speed200G - } - PortSpeed::Speed400G => { - InternalPortSpeed::Speed400G - } - }, - uplink_port_fec: match config.uplink_port_fec { - PortFec::Firecode => InternalPortFec::Firecode, - PortFec::None => InternalPortFec::None, - PortFec::Rs => InternalPortFec::Rs, - }, - autoneg: config.autoneg, - switch: match config.switch { - SwitchLocation::Switch0 => { - InternalSwitchLocation::Switch0 - } - SwitchLocation::Switch1 => { - InternalSwitchLocation::Switch1 - } - }, - }) - .collect(), - bgp: rnc - .bgp - .iter() - .map(|config| InternalBgpConfig { - asn: config.asn, - originate: config.originate.clone(), - }) - .collect(), - }, + rack_network_config, } }