Skip to content

Commit 5f54b63

Browse files
internet-digletthawkw
authored andcommitted
Improve usability of switch port settings (#7966)
This PR aims to improve the usability of the switch port settings API by returning data of similar shape and content as what users provide when the create the switch port settings. Issues resolved: * Before this PR, you only need one call to create a complete switch port settings object, but you have to perform several lookups to get the complete switch port configuration. We were already returning the object ids of the nested objects, so it makes a lot of sense to just return the actual object (especially since the user supplied the entire object when they configured it) * The `HashMap<String_of_link_name, T>` pattern also did not give the expected behavior in our go client generation. Changing this to a `Vec<T_with_link_name_inside>` matches what the user provides during creation and also resolves this behavior. * Some of our `Vec<T>` fields can be empty but must be present. In the Go client, an empty array is omitted from the json object. We needed to add a `default` annotation to these fields so Serde handles this situation correctly. ## Related - oxidecomputer/oxide.go#278 - oxidecomputer/terraform-provider-oxide#426 Closes #5780
1 parent 48884d4 commit 5f54b63

File tree

13 files changed

+973
-458
lines changed

13 files changed

+973
-458
lines changed

common/src/api/external/mod.rs

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2466,7 +2466,7 @@ pub struct SwitchPort {
24662466
#[derive(
24672467
ObjectIdentity, Clone, Debug, Deserialize, JsonSchema, Serialize, PartialEq,
24682468
)]
2469-
pub struct SwitchPortSettings {
2469+
pub struct SwitchPortSettingsIdentity {
24702470
#[serde(flatten)]
24712471
pub identity: IdentityMetadata,
24722472
}
@@ -2475,9 +2475,9 @@ pub struct SwitchPortSettings {
24752475
/// convenience data structure for getting a complete view of a particular
24762476
/// port's settings.
24772477
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize, PartialEq)]
2478-
pub struct SwitchPortSettingsView {
2479-
/// The primary switch port settings handle.
2480-
pub settings: SwitchPortSettings,
2478+
pub struct SwitchPortSettings {
2479+
#[serde(flatten)]
2480+
pub identity: IdentityMetadata,
24812481

24822482
/// Switch port settings included from other switch port settings groups.
24832483
pub groups: Vec<SwitchPortSettingsGroups>,
@@ -2488,13 +2488,6 @@ pub struct SwitchPortSettingsView {
24882488
/// Layer 2 link settings.
24892489
pub links: Vec<SwitchPortLinkConfig>,
24902490

2491-
/// Link-layer discovery protocol (LLDP) settings.
2492-
pub link_lldp: Vec<LldpLinkConfig>,
2493-
2494-
/// TX equalization settings. These are optional, and most links will not
2495-
/// need them.
2496-
pub tx_eq: Vec<Option<TxEqConfig>>,
2497-
24982491
/// Layer 3 interface settings.
24992492
pub interfaces: Vec<SwitchInterfaceConfig>,
25002493

@@ -2508,7 +2501,7 @@ pub struct SwitchPortSettingsView {
25082501
pub bgp_peers: Vec<BgpPeer>,
25092502

25102503
/// Layer 3 IP address settings.
2511-
pub addresses: Vec<SwitchPortAddressConfig>,
2504+
pub addresses: Vec<SwitchPortAddressView>,
25122505
}
25132506

25142507
/// This structure maps a port settings object to a port settings groups. Port
@@ -2633,13 +2626,6 @@ pub struct SwitchPortLinkConfig {
26332626
/// The port settings this link configuration belongs to.
26342627
pub port_settings_id: Uuid,
26352628

2636-
/// The link-layer discovery protocol service configuration id for this
2637-
/// link.
2638-
pub lldp_link_config_id: Option<Uuid>,
2639-
2640-
/// The tx_eq configuration id for this link.
2641-
pub tx_eq_config_id: Option<Uuid>,
2642-
26432629
/// The name of this link.
26442630
pub link_name: String,
26452631

@@ -2656,6 +2642,13 @@ pub struct SwitchPortLinkConfig {
26562642

26572643
/// Whether or not the link has autonegotiation enabled.
26582644
pub autoneg: bool,
2645+
2646+
/// The link-layer discovery protocol service configuration for this
2647+
/// link.
2648+
pub lldp_link_config: Option<LldpLinkConfig>,
2649+
2650+
/// The tx_eq configuration for this link.
2651+
pub tx_eq_config: Option<TxEqConfig>,
26592652
}
26602653

26612654
/// A link layer discovery protocol (LLDP) service configuration.
@@ -2683,7 +2676,7 @@ pub struct LldpLinkConfig {
26832676
pub system_description: Option<String>,
26842677

26852678
/// The LLDP management IP TLV.
2686-
pub management_ip: Option<oxnet::IpNet>,
2679+
pub management_ip: Option<IpAddr>,
26872680
}
26882681

26892682
/// Information about LLDP advertisements from other network entities directly
@@ -2746,18 +2739,6 @@ pub struct TxEqConfig {
27462739
pub post1: Option<i32>,
27472740
}
27482741

2749-
impl From<crate::api::internal::shared::TxEqConfig> for TxEqConfig {
2750-
fn from(x: crate::api::internal::shared::TxEqConfig) -> TxEqConfig {
2751-
TxEqConfig {
2752-
pre1: x.pre1,
2753-
pre2: x.pre2,
2754-
main: x.main,
2755-
post2: x.post2,
2756-
post1: x.post1,
2757-
}
2758-
}
2759-
}
2760-
27612742
/// Describes the kind of an switch interface.
27622743
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize, PartialEq)]
27632744
#[serde(rename_all = "snake_case")]
@@ -2825,7 +2806,7 @@ pub struct SwitchPortRouteConfig {
28252806
pub dst: oxnet::IpNet,
28262807

28272808
/// The route's gateway address.
2828-
pub gw: oxnet::IpNet,
2809+
pub gw: IpAddr,
28292810

28302811
/// The VLAN identifier for the route. Use this if the gateway is reachable
28312812
/// over an 802.1Q tagged L2 segment.
@@ -2981,6 +2962,33 @@ pub struct SwitchPortAddressConfig {
29812962
pub interface_name: String,
29822963
}
29832964

2965+
/// An IP address configuration for a port settings object.
2966+
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize, PartialEq)]
2967+
pub struct SwitchPortAddressView {
2968+
/// The port settings object this address configuration belongs to.
2969+
pub port_settings_id: Uuid,
2970+
2971+
/// The id of the address lot this address is drawn from.
2972+
pub address_lot_id: Uuid,
2973+
2974+
/// The name of the address lot this address is drawn from.
2975+
pub address_lot_name: Name,
2976+
2977+
/// The id of the address lot block this address is drawn from.
2978+
pub address_lot_block_id: Uuid,
2979+
2980+
/// The IP address and prefix.
2981+
pub address: oxnet::IpNet,
2982+
2983+
/// An optional VLAN ID
2984+
pub vlan_id: Option<u16>,
2985+
2986+
/// The interface name this address belongs to.
2987+
// TODO: https://github.com/oxidecomputer/omicron/issues/3050
2988+
// Use `Name` instead of `String` for `interface_name` type
2989+
pub interface_name: String,
2990+
}
2991+
29842992
/// The current state of a BGP peer.
29852993
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize, PartialEq)]
29862994
#[serde(rename_all = "snake_case")]

nexus/db-model/src/switch_port.rs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,28 @@ impl_enum_type!(
4747
Sfp28x4 => b"Sfp28x4"
4848
);
4949

50+
impl PartialEq<params::SwitchPortGeometry> for SwitchPortGeometry {
51+
fn eq(&self, other: &params::SwitchPortGeometry) -> bool {
52+
match self {
53+
Self::Qsfp28x1 => {
54+
return matches!(other, params::SwitchPortGeometry::Qsfp28x1);
55+
}
56+
Self::Qsfp28x2 => {
57+
return matches!(other, params::SwitchPortGeometry::Qsfp28x2);
58+
}
59+
Self::Sfp28x4 => {
60+
return matches!(other, params::SwitchPortGeometry::Sfp28x4);
61+
}
62+
}
63+
}
64+
}
65+
66+
impl PartialEq<SwitchPortGeometry> for params::SwitchPortGeometry {
67+
fn eq(&self, other: &SwitchPortGeometry) -> bool {
68+
other.eq(self)
69+
}
70+
}
71+
5072
impl_enum_type!(
5173
SwitchLinkFecEnum:
5274

@@ -286,9 +308,9 @@ impl SwitchPortSettings {
286308
}
287309
}
288310

289-
impl Into<external::SwitchPortSettings> for SwitchPortSettings {
290-
fn into(self) -> external::SwitchPortSettings {
291-
external::SwitchPortSettings { identity: self.identity() }
311+
impl Into<external::SwitchPortSettingsIdentity> for SwitchPortSettings {
312+
fn into(self) -> external::SwitchPortSettingsIdentity {
313+
external::SwitchPortSettingsIdentity { identity: self.identity() }
292314
}
293315
}
294316

@@ -407,21 +429,6 @@ impl SwitchPortLinkConfig {
407429
}
408430
}
409431

410-
impl Into<external::SwitchPortLinkConfig> for SwitchPortLinkConfig {
411-
fn into(self) -> external::SwitchPortLinkConfig {
412-
external::SwitchPortLinkConfig {
413-
port_settings_id: self.port_settings_id,
414-
lldp_link_config_id: self.lldp_link_config_id,
415-
tx_eq_config_id: self.tx_eq_config_id,
416-
link_name: self.link_name.clone(),
417-
mtu: self.mtu.into(),
418-
fec: self.fec.map(|fec| fec.into()),
419-
speed: self.speed.into(),
420-
autoneg: self.autoneg,
421-
}
422-
}
423-
}
424-
425432
#[derive(
426433
Queryable,
427434
Insertable,
@@ -486,7 +493,7 @@ impl Into<external::LldpLinkConfig> for LldpLinkConfig {
486493
chassis_id: self.chassis_id.clone(),
487494
system_name: self.system_name.clone(),
488495
system_description: self.system_description.clone(),
489-
management_ip: self.management_ip.map(|a| a.into()),
496+
management_ip: self.management_ip.map(|a| a.ip()),
490497
}
491498
}
492499
}
@@ -625,7 +632,7 @@ impl Into<external::SwitchPortRouteConfig> for SwitchPortRouteConfig {
625632
port_settings_id: self.port_settings_id,
626633
interface_name: self.interface_name.clone(),
627634
dst: self.dst.into(),
628-
gw: self.gw.into(),
635+
gw: self.gw.ip(),
629636
vlan_id: self.vid.map(Into::into),
630637
rib_priority: self.rib_priority.map(Into::into),
631638
}

0 commit comments

Comments
 (0)