From f185426f9cca3cda6db57a50a64c0dba41ce91e6 Mon Sep 17 00:00:00 2001 From: David Pacheco Date: Thu, 4 Jan 2024 16:58:21 -0800 Subject: [PATCH] sled agent client could use some primitives from omicron_common (#4754) --- clients/sled-agent-client/src/lib.rs | 56 +++---------------- dev-tools/omdb/src/bin/omdb/db.rs | 2 +- nexus/db-model/src/bytecount.rs | 6 -- nexus/db-model/src/generation.rs | 6 -- nexus/db-model/src/inventory.rs | 12 ++-- .../src/db/datastore/network_interface.rs | 2 +- nexus/inventory/src/builder.rs | 5 +- nexus/inventory/src/collector.rs | 3 +- nexus/inventory/src/examples.rs | 7 +-- sled-agent/src/params.rs | 2 +- 10 files changed, 23 insertions(+), 78 deletions(-) diff --git a/clients/sled-agent-client/src/lib.rs b/clients/sled-agent-client/src/lib.rs index 89f41d10a6..ee2214c3c2 100644 --- a/clients/sled-agent-client/src/lib.rs +++ b/clients/sled-agent-client/src/lib.rs @@ -25,6 +25,9 @@ progenitor::generate_api!( //TODO trade the manual transformations later in this file for the // replace directives below? replace = { + ByteCount = omicron_common::api::external::ByteCount, + Generation = omicron_common::api::external::Generation, + Name = omicron_common::api::external::Name, SwitchLocation = omicron_common::api::external::SwitchLocation, Ipv6Network = ipnetwork::Ipv6Network, IpNetwork = ipnetwork::IpNetwork, @@ -80,7 +83,7 @@ impl From propolis_id: s.propolis_id, dst_propolis_id: s.dst_propolis_id, migration_id: s.migration_id, - gen: s.gen.into(), + gen: s.gen, time_updated: s.time_updated, } } @@ -114,18 +117,6 @@ impl From } } -impl From for types::ByteCount { - fn from(s: omicron_common::api::external::ByteCount) -> Self { - Self(s.to_bytes()) - } -} - -impl From for types::Generation { - fn from(s: omicron_common::api::external::Generation) -> Self { - Self(i64::from(&s) as u64) - } -} - impl From for omicron_common::api::internal::nexus::InstanceRuntimeState { @@ -134,7 +125,7 @@ impl From propolis_id: s.propolis_id, dst_propolis_id: s.dst_propolis_id, migration_id: s.migration_id, - gen: s.gen.into(), + gen: s.gen, time_updated: s.time_updated, } } @@ -144,11 +135,7 @@ impl From for omicron_common::api::internal::nexus::VmmRuntimeState { fn from(s: types::VmmRuntimeState) -> Self { - Self { - state: s.state.into(), - gen: s.gen.into(), - time_updated: s.time_updated, - } + Self { state: s.state.into(), gen: s.gen, time_updated: s.time_updated } } } @@ -192,25 +179,13 @@ impl From } } -impl From for omicron_common::api::external::ByteCount { - fn from(s: types::ByteCount) -> Self { - Self::try_from(s.0).unwrap_or_else(|e| panic!("{}: {}", s.0, e)) - } -} - -impl From for omicron_common::api::external::Generation { - fn from(s: types::Generation) -> Self { - Self::try_from(s.0 as i64).unwrap() - } -} - impl From for types::DiskRuntimeState { fn from(s: omicron_common::api::internal::nexus::DiskRuntimeState) -> Self { Self { disk_state: s.disk_state.into(), - gen: s.gen.into(), + gen: s.gen, time_updated: s.time_updated, } } @@ -242,7 +217,7 @@ impl From fn from(s: types::DiskRuntimeState) -> Self { Self { disk_state: s.disk_state.into(), - gen: s.gen.into(), + gen: s.gen, time_updated: s.time_updated, } } @@ -268,19 +243,6 @@ impl From for omicron_common::api::external::DiskState { } } -impl From<&omicron_common::api::external::Name> for types::Name { - fn from(s: &omicron_common::api::external::Name) -> Self { - Self::try_from(<&str>::from(s)) - .unwrap_or_else(|e| panic!("{}: {}", s, e)) - } -} - -impl From for omicron_common::api::external::Name { - fn from(s: types::Name) -> Self { - Self::try_from(s.as_str().to_owned()).unwrap() - } -} - impl From for types::Vni { fn from(v: omicron_common::api::external::Vni) -> Self { Self(u32::from(v)) @@ -541,7 +503,7 @@ impl From Self { id: s.id, kind: s.kind.into(), - name: (&s.name).into(), + name: s.name, ip: s.ip, mac: s.mac.into(), subnet: s.subnet.into(), diff --git a/dev-tools/omdb/src/bin/omdb/db.rs b/dev-tools/omdb/src/bin/omdb/db.rs index ad7ab35455..f58fd57b9d 100644 --- a/dev-tools/omdb/src/bin/omdb/db.rs +++ b/dev-tools/omdb/src/bin/omdb/db.rs @@ -2738,7 +2738,7 @@ fn inv_collection_print_sleds(collection: &Collection) { ); println!( " zones generation: {} (count: {})", - *zones.zones.generation, + zones.zones.generation, zones.zones.zones.len() ); diff --git a/nexus/db-model/src/bytecount.rs b/nexus/db-model/src/bytecount.rs index 9ea13956b7..92a01db43f 100644 --- a/nexus/db-model/src/bytecount.rs +++ b/nexus/db-model/src/bytecount.rs @@ -53,12 +53,6 @@ where } } -impl From for sled_agent_client::types::ByteCount { - fn from(b: ByteCount) -> Self { - Self(b.to_bytes()) - } -} - impl From for ByteCount { fn from(bs: BlockSize) -> Self { Self(bs.to_bytes().into()) diff --git a/nexus/db-model/src/generation.rs b/nexus/db-model/src/generation.rs index b7e3a2b954..751cb98f3c 100644 --- a/nexus/db-model/src/generation.rs +++ b/nexus/db-model/src/generation.rs @@ -60,9 +60,3 @@ where .map_err(|e| e.into()) } } - -impl From for sled_agent_client::types::Generation { - fn from(g: Generation) -> Self { - Self(i64::from(&g.0) as u64) - } -} diff --git a/nexus/db-model/src/inventory.rs b/nexus/db-model/src/inventory.rs index 47e2033718..4e3e5fad56 100644 --- a/nexus/db-model/src/inventory.rs +++ b/nexus/db-model/src/inventory.rs @@ -675,7 +675,7 @@ impl InvSledOmicronZones { time_collected: zones_found.time_collected, source: zones_found.source.clone(), sled_id: zones_found.sled_id, - generation: Generation(zones_found.zones.generation.clone().into()), + generation: Generation(zones_found.zones.generation), } } @@ -687,7 +687,7 @@ impl InvSledOmicronZones { source: self.source, sled_id: self.sled_id, zones: nexus_types::inventory::OmicronZonesConfig { - generation: self.generation.0.into(), + generation: *self.generation, zones: Vec::new(), }, } @@ -1123,11 +1123,7 @@ impl InvOmicronZoneNic { Ok(Some(InvOmicronZoneNic { inv_collection_id, id: nic.id, - name: Name::from( - omicron_common::api::external::Name::from( - nic.name.clone(), - ), - ), + name: Name::from(nic.name.clone()), ip: IpNetwork::from(nic.ip), mac: MacAddr::from( omicron_common::api::external::MacAddr::from( @@ -1155,7 +1151,7 @@ impl InvOmicronZoneNic { zone_id, ), mac: (*self.mac).into(), - name: (&(*self.name)).into(), + name: self.name.into(), primary: self.is_primary, slot: *self.slot, vni: nexus_types::inventory::Vni::from(*self.vni), diff --git a/nexus/db-queries/src/db/datastore/network_interface.rs b/nexus/db-queries/src/db/datastore/network_interface.rs index 4d4e43c9a7..be12ea5231 100644 --- a/nexus/db-queries/src/db/datastore/network_interface.rs +++ b/nexus/db-queries/src/db/datastore/network_interface.rs @@ -76,7 +76,7 @@ impl From for sled_client_types::NetworkInterface { sled_client_types::NetworkInterface { id: nic.id, kind, - name: sled_client_types::Name::from(&nic.name.0), + name: nic.name.into(), ip: nic.ip.ip(), mac: sled_client_types::MacAddr::from(nic.mac.0), subnet: sled_client_types::IpNet::from(ip_subnet), diff --git a/nexus/inventory/src/builder.rs b/nexus/inventory/src/builder.rs index 602655ef0b..62d338c1ee 100644 --- a/nexus/inventory/src/builder.rs +++ b/nexus/inventory/src/builder.rs @@ -26,7 +26,6 @@ use nexus_types::inventory::RotPageWhich; use nexus_types::inventory::RotState; use nexus_types::inventory::ServiceProcessor; use nexus_types::inventory::SledAgent; -use omicron_common::api::external::ByteCount; use std::collections::BTreeMap; use std::collections::BTreeSet; use std::sync::Arc; @@ -455,8 +454,8 @@ impl CollectionBuilder { sled_role: inventory.sled_role, baseboard_id, usable_hardware_threads: inventory.usable_hardware_threads, - usable_physical_ram: ByteCount::from(inventory.usable_physical_ram), - reservoir_size: ByteCount::from(inventory.reservoir_size), + usable_physical_ram: inventory.usable_physical_ram, + reservoir_size: inventory.reservoir_size, time_collected: now(), sled_id, }; diff --git a/nexus/inventory/src/collector.rs b/nexus/inventory/src/collector.rs index 9b335d3ee4..ab9af3f9e0 100644 --- a/nexus/inventory/src/collector.rs +++ b/nexus/inventory/src/collector.rs @@ -374,6 +374,7 @@ mod test { use crate::StaticSledAgentEnumerator; use gateway_messages::SpPort; use nexus_types::inventory::Collection; + use omicron_common::api::external::Generation; use omicron_sled_agent::sim; use std::fmt::Write; use std::net::Ipv6Addr; @@ -540,7 +541,7 @@ mod test { let zone_address = SocketAddrV6::new(Ipv6Addr::LOCALHOST, 123, 0, 0); client .omicron_zones_put(&sled_agent_client::types::OmicronZonesConfig { - generation: sled_agent_client::types::Generation::from(3), + generation: Generation::from(3), zones: vec![sled_agent_client::types::OmicronZoneConfig { id: zone_id, underlay_address: *zone_address.ip(), diff --git a/nexus/inventory/src/examples.rs b/nexus/inventory/src/examples.rs index 054be457f3..93ba139c85 100644 --- a/nexus/inventory/src/examples.rs +++ b/nexus/inventory/src/examples.rs @@ -16,6 +16,7 @@ use nexus_types::inventory::CabooseWhich; use nexus_types::inventory::OmicronZonesConfig; use nexus_types::inventory::RotPage; use nexus_types::inventory::RotPageWhich; +use omicron_common::api::external::ByteCount; use std::sync::Arc; use strum::IntoEnumIterator; use uuid::Uuid; @@ -441,13 +442,11 @@ pub fn sled_agent( ) -> sled_agent_client::types::Inventory { sled_agent_client::types::Inventory { baseboard, - reservoir_size: sled_agent_client::types::ByteCount::from(1024), + reservoir_size: ByteCount::from(1024), sled_role, sled_agent_address: "[::1]:56792".parse().unwrap(), sled_id, usable_hardware_threads: 10, - usable_physical_ram: sled_agent_client::types::ByteCount::from( - 1024 * 1024, - ), + usable_physical_ram: ByteCount::from(1024 * 1024), } } diff --git a/sled-agent/src/params.rs b/sled-agent/src/params.rs index 41fc84504e..8417546e3b 100644 --- a/sled-agent/src/params.rs +++ b/sled-agent/src/params.rs @@ -298,7 +298,7 @@ pub struct OmicronZonesConfig { impl From for sled_agent_client::types::OmicronZonesConfig { fn from(local: OmicronZonesConfig) -> Self { Self { - generation: local.generation.into(), + generation: local.generation, zones: local.zones.into_iter().map(|s| s.into()).collect(), } }