diff --git a/clients/nexus-client/src/lib.rs b/clients/nexus-client/src/lib.rs index 41ce658233..482f346b6b 100644 --- a/clients/nexus-client/src/lib.rs +++ b/clients/nexus-client/src/lib.rs @@ -51,6 +51,7 @@ progenitor::generate_api!( TypedUuidForDatasetKind = omicron_uuid_kinds::TypedUuid, TypedUuidForDemoSagaKind = omicron_uuid_kinds::DemoSagaUuid, TypedUuidForDownstairsKind = omicron_uuid_kinds::TypedUuid, + TypedUuidForPhysicalDiskKind = omicron_uuid_kinds::TypedUuid, TypedUuidForPropolisKind = omicron_uuid_kinds::TypedUuid, TypedUuidForSledKind = omicron_uuid_kinds::TypedUuid, TypedUuidForUpstairsKind = omicron_uuid_kinds::TypedUuid, diff --git a/common/src/disk.rs b/common/src/disk.rs index 21ca417b86..3500d4dabb 100644 --- a/common/src/disk.rs +++ b/common/src/disk.rs @@ -7,13 +7,13 @@ use anyhow::bail; use camino::{Utf8Path, Utf8PathBuf}; use omicron_uuid_kinds::DatasetUuid; +use omicron_uuid_kinds::PhysicalDiskUuid; use omicron_uuid_kinds::ZpoolUuid; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; use std::fmt; use std::str::FromStr; -use uuid::Uuid; use crate::{ api::external::{ByteCount, Generation}, @@ -37,7 +37,7 @@ pub use crate::api::internal::shared::DatasetKind; )] pub struct OmicronPhysicalDiskConfig { pub identity: DiskIdentity, - pub id: Uuid, + pub id: PhysicalDiskUuid, pub pool_id: ZpoolUuid, } diff --git a/dev-tools/omdb/src/bin/omdb/db.rs b/dev-tools/omdb/src/bin/omdb/db.rs index dcd9b4254f..4cccc3c23e 100644 --- a/dev-tools/omdb/src/bin/omdb/db.rs +++ b/dev-tools/omdb/src/bin/omdb/db.rs @@ -130,6 +130,7 @@ use omicron_uuid_kinds::CollectionUuid; use omicron_uuid_kinds::DatasetUuid; use omicron_uuid_kinds::GenericUuid; use omicron_uuid_kinds::InstanceUuid; +use omicron_uuid_kinds::PhysicalDiskUuid; use omicron_uuid_kinds::PropolisUuid; use omicron_uuid_kinds::SledUuid; use sled_agent_client::types::VolumeConstructionRequest; @@ -1857,7 +1858,7 @@ async fn cmd_db_disk_physical( #[derive(Tabled)] #[tabled(rename_all = "SCREAMING_SNAKE_CASE")] struct PhysicalDiskRow { - id: Uuid, + id: PhysicalDiskUuid, serial: String, vendor: String, model: String, diff --git a/dev-tools/omdb/src/bin/omdb/nexus.rs b/dev-tools/omdb/src/bin/omdb/nexus.rs index cb05bb575b..fe16b4076e 100644 --- a/dev-tools/omdb/src/bin/omdb/nexus.rs +++ b/dev-tools/omdb/src/bin/omdb/nexus.rs @@ -2852,7 +2852,7 @@ async fn cmd_nexus_sled_expunge_disk_with_datastore( // First, we need to look up the disk so we can lookup identity information. let (_authz_physical_disk, physical_disk) = LookupPath::new(opctx, &datastore) - .physical_disk(args.physical_disk_id.into_untyped_uuid()) + .physical_disk(args.physical_disk_id) .fetch() .await .with_context(|| { diff --git a/nexus/auth/src/authz/api_resources.rs b/nexus/auth/src/authz/api_resources.rs index df1a1efc29..bfde3d3b97 100644 --- a/nexus/auth/src/authz/api_resources.rs +++ b/nexus/auth/src/authz/api_resources.rs @@ -998,7 +998,7 @@ authz_resource! { authz_resource! { name = "PhysicalDisk", parent = "Fleet", - primary_key = Uuid, + primary_key = { uuid_kind = PhysicalDiskKind }, roles_allowed = false, polar_snippet = FleetChild, } diff --git a/nexus/db-model/src/deployment.rs b/nexus/db-model/src/deployment.rs index fff829f548..f7f1a90989 100644 --- a/nexus/db-model/src/deployment.rs +++ b/nexus/db-model/src/deployment.rs @@ -47,7 +47,8 @@ use omicron_common::disk::DiskIdentity; use omicron_common::zpool_name::ZpoolName; use omicron_uuid_kinds::{ DatasetKind, ExternalIpKind, ExternalIpUuid, GenericUuid, OmicronZoneKind, - OmicronZoneUuid, SledKind, SledUuid, ZpoolKind, ZpoolUuid, + OmicronZoneUuid, PhysicalDiskKind, SledKind, SledUuid, ZpoolKind, + ZpoolUuid, }; use std::net::{IpAddr, SocketAddrV6}; use uuid::Uuid; @@ -179,7 +180,7 @@ pub struct BpOmicronPhysicalDisk { pub serial: String, pub model: String, - pub id: Uuid, + pub id: DbTypedUuid, pub pool_id: Uuid, } @@ -195,7 +196,7 @@ impl BpOmicronPhysicalDisk { vendor: disk_config.identity.vendor.clone(), serial: disk_config.identity.serial.clone(), model: disk_config.identity.model.clone(), - id: disk_config.id, + id: disk_config.id.into(), pool_id: disk_config.pool_id.into_untyped_uuid(), } } @@ -209,7 +210,7 @@ impl From for BlueprintPhysicalDiskConfig { serial: disk.serial, model: disk.model, }, - id: disk.id, + id: disk.id.into(), pool_id: ZpoolUuid::from_untyped_uuid(disk.pool_id), } } diff --git a/nexus/db-model/src/physical_disk.rs b/nexus/db-model/src/physical_disk.rs index d4a1dcd33c..d7c03ff155 100644 --- a/nexus/db-model/src/physical_disk.rs +++ b/nexus/db-model/src/physical_disk.rs @@ -10,11 +10,13 @@ use crate::schema::{physical_disk, zpool}; use chrono::{DateTime, Utc}; use db_macros::Asset; use nexus_types::{external_api::views, identity::Asset}; +use omicron_uuid_kinds::PhysicalDiskUuid; use uuid::Uuid; /// Physical disk attached to sled. #[derive(Queryable, Insertable, Debug, Clone, Selectable, Asset)] #[diesel(table_name = physical_disk)] +#[asset(uuid_kind = PhysicalDiskKind)] pub struct PhysicalDisk { #[diesel(embed)] identity: PhysicalDiskIdentity, @@ -34,7 +36,7 @@ pub struct PhysicalDisk { impl PhysicalDisk { /// Creates a new in-service, active disk pub fn new( - id: Uuid, + id: PhysicalDiskUuid, vendor: String, serial: String, model: String, @@ -55,8 +57,8 @@ impl PhysicalDisk { } } - pub fn id(&self) -> Uuid { - self.identity.id + pub fn id(&self) -> PhysicalDiskUuid { + self.identity.id.into() } pub fn time_deleted(&self) -> Option> { diff --git a/nexus/db-model/src/zpool.rs b/nexus/db-model/src/zpool.rs index 1d129d4c57..970adb3330 100644 --- a/nexus/db-model/src/zpool.rs +++ b/nexus/db-model/src/zpool.rs @@ -5,8 +5,11 @@ use super::{Dataset, Generation}; use crate::collection::DatastoreCollectionConfig; use crate::schema::{dataset, zpool}; +use crate::typed_uuid::DbTypedUuid; use chrono::{DateTime, Utc}; use db_macros::Asset; +use omicron_uuid_kinds::PhysicalDiskKind; +use omicron_uuid_kinds::PhysicalDiskUuid; use uuid::Uuid; /// Database representation of a Pool. @@ -25,17 +28,21 @@ pub struct Zpool { pub sled_id: Uuid, // The physical disk to which this Zpool is attached. - pub physical_disk_id: Uuid, + pub physical_disk_id: DbTypedUuid, } impl Zpool { - pub fn new(id: Uuid, sled_id: Uuid, physical_disk_id: Uuid) -> Self { + pub fn new( + id: Uuid, + sled_id: Uuid, + physical_disk_id: PhysicalDiskUuid, + ) -> Self { Self { identity: ZpoolIdentity::new(id), time_deleted: None, rcgen: Generation::new(), sled_id, - physical_disk_id, + physical_disk_id: physical_disk_id.into(), } } } diff --git a/nexus/db-queries/src/db/datastore/dataset.rs b/nexus/db-queries/src/db/datastore/dataset.rs index f931403cb9..992db3705c 100644 --- a/nexus/db-queries/src/db/datastore/dataset.rs +++ b/nexus/db-queries/src/db/datastore/dataset.rs @@ -363,6 +363,7 @@ mod test { use omicron_common::api::internal::shared::DatasetKind as ApiDatasetKind; use omicron_test_utils::dev; use omicron_uuid_kinds::DatasetUuid; + use omicron_uuid_kinds::PhysicalDiskUuid; use omicron_uuid_kinds::SledUuid; use omicron_uuid_kinds::ZpoolUuid; @@ -396,7 +397,7 @@ mod test { let zpool = Zpool::new( *zpool_id.as_untyped_uuid(), *sled_id.as_untyped_uuid(), - Uuid::new_v4(), + PhysicalDiskUuid::new_v4(), ); datastore .zpool_insert(opctx, zpool) diff --git a/nexus/db-queries/src/db/datastore/mod.rs b/nexus/db-queries/src/db/datastore/mod.rs index 5bd35fbba9..25f1f282f7 100644 --- a/nexus/db-queries/src/db/datastore/mod.rs +++ b/nexus/db-queries/src/db/datastore/mod.rs @@ -475,6 +475,7 @@ mod test { use omicron_uuid_kinds::CollectionUuid; use omicron_uuid_kinds::DatasetUuid; use omicron_uuid_kinds::GenericUuid; + use omicron_uuid_kinds::PhysicalDiskUuid; use omicron_uuid_kinds::SledUuid; use std::collections::HashMap; use std::collections::HashSet; @@ -716,9 +717,9 @@ mod test { sled_id: SledUuid, kind: PhysicalDiskKind, serial: String, - ) -> Uuid { + ) -> PhysicalDiskUuid { let physical_disk = PhysicalDisk::new( - Uuid::new_v4(), + PhysicalDiskUuid::new_v4(), TEST_VENDOR.into(), serial, TEST_MODEL.into(), @@ -737,7 +738,7 @@ mod test { datastore: &DataStore, opctx: &OpContext, sled_id: SledUuid, - physical_disk_id: Uuid, + physical_disk_id: PhysicalDiskUuid, ) -> Uuid { let zpool_id = create_test_zpool_not_in_inventory( datastore, @@ -759,7 +760,7 @@ mod test { datastore: &DataStore, opctx: &OpContext, sled_id: SledUuid, - physical_disk_id: Uuid, + physical_disk_id: PhysicalDiskUuid, ) -> Uuid { let zpool_id = Uuid::new_v4(); let zpool = @@ -903,7 +904,7 @@ mod test { struct PhysicalDisk { sled_id: SledUuid, - disk_id: Uuid, + disk_id: PhysicalDiskUuid, } // create 9 disks on each sled diff --git a/nexus/db-queries/src/db/datastore/physical_disk.rs b/nexus/db-queries/src/db/datastore/physical_disk.rs index 989aae0267..a2499070c4 100644 --- a/nexus/db-queries/src/db/datastore/physical_disk.rs +++ b/nexus/db-queries/src/db/datastore/physical_disk.rs @@ -12,6 +12,7 @@ use crate::db::collection_insert::AsyncInsertError; use crate::db::collection_insert::DatastoreCollection; use crate::db::error::public_error_from_diesel; use crate::db::error::ErrorHandler; +use crate::db::model::to_db_typed_uuid; use crate::db::model::ApplySledFilterExt; use crate::db::model::InvPhysicalDisk; use crate::db::model::PhysicalDisk; @@ -148,40 +149,40 @@ impl DataStore { pub async fn physical_disk_update_policy( &self, opctx: &OpContext, - id: Uuid, + id: PhysicalDiskUuid, policy: PhysicalDiskPolicy, ) -> Result<(), Error> { opctx.authorize(authz::Action::Read, &authz::FLEET).await?; use db::schema::physical_disk::dsl; - diesel::update(dsl::physical_disk.filter(dsl::id.eq(id))) - .filter(dsl::time_deleted.is_null()) - .set(dsl::disk_policy.eq(policy)) - .execute_async(&*self.pool_connection_authorized(&opctx).await?) - .await - .map_err(|err| { - public_error_from_diesel(err, ErrorHandler::Server) - })?; + diesel::update( + dsl::physical_disk.filter(dsl::id.eq(to_db_typed_uuid(id))), + ) + .filter(dsl::time_deleted.is_null()) + .set(dsl::disk_policy.eq(policy)) + .execute_async(&*self.pool_connection_authorized(&opctx).await?) + .await + .map_err(|err| public_error_from_diesel(err, ErrorHandler::Server))?; Ok(()) } pub async fn physical_disk_update_state( &self, opctx: &OpContext, - id: Uuid, + id: PhysicalDiskUuid, state: PhysicalDiskState, ) -> Result<(), Error> { opctx.authorize(authz::Action::Read, &authz::FLEET).await?; use db::schema::physical_disk::dsl; - diesel::update(dsl::physical_disk.filter(dsl::id.eq(id))) - .filter(dsl::time_deleted.is_null()) - .set(dsl::disk_state.eq(state)) - .execute_async(&*self.pool_connection_authorized(&opctx).await?) - .await - .map_err(|err| { - public_error_from_diesel(err, ErrorHandler::Server) - })?; + diesel::update( + dsl::physical_disk.filter(dsl::id.eq(to_db_typed_uuid(id))), + ) + .filter(dsl::time_deleted.is_null()) + .set(dsl::disk_state.eq(state)) + .execute_async(&*self.pool_connection_authorized(&opctx).await?) + .await + .map_err(|err| public_error_from_diesel(err, ErrorHandler::Server))?; Ok(()) } @@ -309,7 +310,7 @@ impl DataStore { let now = Utc::now(); use db::schema::physical_disk::dsl; diesel::update(dsl::physical_disk) - .filter(dsl::id.eq(id.into_untyped_uuid())) + .filter(dsl::id.eq(to_db_typed_uuid(id))) .filter(dsl::time_deleted.is_null()) .set(dsl::time_deleted.eq(now)) .execute_async(&*self.pool_connection_authorized(opctx).await?) @@ -379,7 +380,7 @@ mod test { // Insert a disk let disk = PhysicalDisk::new( - Uuid::new_v4(), + PhysicalDiskUuid::new_v4(), String::from("Oxide"), String::from("123"), String::from("FakeDisk"), @@ -420,7 +421,7 @@ mod test { // Insert a disk let disk = PhysicalDisk::new( - Uuid::new_v4(), + PhysicalDiskUuid::new_v4(), String::from("Oxide"), String::from("123"), String::from("FakeDisk"), @@ -434,7 +435,7 @@ mod test { // Insert a second disk let disk = PhysicalDisk::new( - Uuid::new_v4(), + PhysicalDiskUuid::new_v4(), String::from("Noxide"), String::from("456"), String::from("UnrealDisk"), @@ -468,7 +469,7 @@ mod test { // Insert a disk let disk_id = PhysicalDiskUuid::new_v4(); let disk = PhysicalDisk::new( - disk_id.into_untyped_uuid(), + disk_id, String::from("Oxide"), String::from("123"), String::from("FakeDisk"), @@ -526,7 +527,7 @@ mod test { // Insert a disk let disk_id = PhysicalDiskUuid::new_v4(); let disk = PhysicalDisk::new( - disk_id.into_untyped_uuid(), + disk_id, String::from("Oxide"), String::from("123"), String::from("FakeDisk"), @@ -568,7 +569,7 @@ mod test { // Attach the disk to the second sled let disk_id = PhysicalDiskUuid::new_v4(); let disk = PhysicalDisk::new( - disk_id.into_untyped_uuid(), + disk_id, String::from("Oxide"), String::from("123"), String::from("FakeDisk"), @@ -615,7 +616,7 @@ mod test { // Insert a disk let disk_id = PhysicalDiskUuid::new_v4(); let disk = PhysicalDisk::new( - disk_id.into_untyped_uuid(), + disk_id, String::from("Oxide"), String::from("123"), String::from("FakeDisk"), @@ -646,7 +647,7 @@ mod test { // "Report the disk" from the second sled let disk = PhysicalDisk::new( - Uuid::new_v4(), + PhysicalDiskUuid::new_v4(), String::from("Oxide"), String::from("123"), String::from("FakeDisk"), @@ -761,7 +762,7 @@ mod test { inv_disk: &InventoryDisk, ) -> (PhysicalDisk, Zpool) { let disk = PhysicalDisk::new( - Uuid::new_v4(), + PhysicalDiskUuid::new_v4(), inv_disk.identity.vendor.clone(), inv_disk.identity.serial.clone(), inv_disk.identity.model.clone(), @@ -974,7 +975,7 @@ mod test { // Set a disk to "deleted". let now = Utc::now(); diesel::update(dsl::physical_disk) - .filter(dsl::id.eq(disk_003.id())) + .filter(dsl::id.eq(to_db_typed_uuid(disk_003.id()))) .filter(dsl::time_deleted.is_null()) .set(dsl::time_deleted.eq(now)) .execute_async( @@ -985,7 +986,7 @@ mod test { // Set another disk to "expunged" diesel::update(dsl::physical_disk) - .filter(dsl::id.eq(disk_102.id())) + .filter(dsl::id.eq(to_db_typed_uuid(disk_102.id()))) .filter(dsl::time_deleted.is_null()) .set(dsl::disk_policy.eq(PhysicalDiskPolicy::Expunged)) .execute_async( diff --git a/nexus/db-queries/src/db/datastore/sled.rs b/nexus/db-queries/src/db/datastore/sled.rs index 7cd05d8272..e4a9c82395 100644 --- a/nexus/db-queries/src/db/datastore/sled.rs +++ b/nexus/db-queries/src/db/datastore/sled.rs @@ -845,6 +845,7 @@ pub(in crate::db::datastore) mod test { sled_set_policy, sled_set_state, Expected, IneligibleSleds, }; use crate::db::lookup::LookupPath; + use crate::db::model::to_db_typed_uuid; use crate::db::model::ByteCount; use crate::db::model::SqlU32; use crate::db::pub_test_utils::TestDatabase; @@ -859,6 +860,7 @@ pub(in crate::db::datastore) mod test { use omicron_common::api::external; use omicron_test_utils::dev; use omicron_uuid_kinds::GenericUuid; + use omicron_uuid_kinds::PhysicalDiskUuid; use omicron_uuid_kinds::SledUuid; use predicates::{prelude::*, BoxPredicate}; use std::net::{Ipv6Addr, SocketAddrV6}; @@ -1156,11 +1158,11 @@ pub(in crate::db::datastore) mod test { async fn lookup_physical_disk( datastore: &DataStore, - id: Uuid, + id: PhysicalDiskUuid, ) -> PhysicalDisk { use db::schema::physical_disk::dsl; dsl::physical_disk - .filter(dsl::id.eq(id)) + .filter(dsl::id.eq(to_db_typed_uuid(id))) .filter(dsl::time_deleted.is_null()) .select(PhysicalDisk::as_select()) .get_result_async( @@ -1191,7 +1193,7 @@ pub(in crate::db::datastore) mod test { // Crucible regions, but it creates enough of a control plane object to // be associated with the Sled by UUID) let disk1 = PhysicalDisk::new( - Uuid::new_v4(), + PhysicalDiskUuid::new_v4(), "vendor1".to_string(), "serial1".to_string(), "model1".to_string(), @@ -1199,7 +1201,7 @@ pub(in crate::db::datastore) mod test { sled_id.into_untyped_uuid(), ); let disk2 = PhysicalDisk::new( - Uuid::new_v4(), + PhysicalDiskUuid::new_v4(), "vendor2".to_string(), "serial2".to_string(), "model2".to_string(), diff --git a/nexus/db-queries/src/db/lookup.rs b/nexus/db-queries/src/db/lookup.rs index 4dce6eeeab..e3b118f94f 100644 --- a/nexus/db-queries/src/db/lookup.rs +++ b/nexus/db-queries/src/db/lookup.rs @@ -21,6 +21,7 @@ use nexus_db_model::Name; use omicron_common::api::external::Error; use omicron_common::api::external::InternalContext; use omicron_common::api::external::{LookupResult, LookupType, ResourceType}; +use omicron_uuid_kinds::PhysicalDiskUuid; use omicron_uuid_kinds::TufRepoKind; use omicron_uuid_kinds::TypedUuid; use uuid::Uuid; @@ -385,7 +386,7 @@ impl<'a> LookupPath<'a> { } /// Select a resource of type PhysicalDisk, identified by its id - pub fn physical_disk(self, id: Uuid) -> PhysicalDisk<'a> { + pub fn physical_disk(self, id: PhysicalDiskUuid) -> PhysicalDisk<'a> { PhysicalDisk::PrimaryKey(Root { lookup_root: self }, id) } @@ -874,7 +875,7 @@ lookup_resource! { children = [], lookup_by_name = false, soft_deletes = true, - primary_key_columns = [ { column_name = "id", rust_type = Uuid } ] + primary_key_columns = [ { column_name = "id", uuid_kind = PhysicalDiskKind } ] } lookup_resource! { diff --git a/nexus/db-queries/src/policy_test/resources.rs b/nexus/db-queries/src/policy_test/resources.rs index 1a5ac77f53..8075908d05 100644 --- a/nexus/db-queries/src/policy_test/resources.rs +++ b/nexus/db-queries/src/policy_test/resources.rs @@ -11,6 +11,7 @@ use nexus_auth::authz; use nexus_db_model::SemverVersion; use omicron_common::api::external::LookupType; use omicron_uuid_kinds::GenericUuid; +use omicron_uuid_kinds::PhysicalDiskUuid; use oso::PolarClass; use std::collections::BTreeSet; use uuid::Uuid; @@ -102,12 +103,12 @@ pub async fn make_resources( make_services(&mut builder).await; - let physical_disk_id = + let physical_disk_id: PhysicalDiskUuid = "c9f923f6-caf3-4c83-96f9-8ffe8c627dd2".parse().unwrap(); builder.new_resource(authz::PhysicalDisk::new( authz::FLEET, physical_disk_id, - LookupType::ById(physical_disk_id), + LookupType::ById(physical_disk_id.into_untyped_uuid()), )); let device_user_code = String::from("a-device-user-code"); diff --git a/nexus/reconfigurator/execution/src/datasets.rs b/nexus/reconfigurator/execution/src/datasets.rs index 97cacb3efe..b0aa7410f0 100644 --- a/nexus/reconfigurator/execution/src/datasets.rs +++ b/nexus/reconfigurator/execution/src/datasets.rs @@ -263,8 +263,8 @@ mod tests { use omicron_common::disk::CompressionAlgorithm; use omicron_common::zpool_name::ZpoolName; use omicron_uuid_kinds::GenericUuid; + use omicron_uuid_kinds::PhysicalDiskUuid; use omicron_uuid_kinds::ZpoolUuid; - use uuid::Uuid; type ControlPlaneTestContext = nexus_test_utils::ControlPlaneTestContext; @@ -393,7 +393,7 @@ mod tests { let zpool = Zpool::new( new_zpool_id.into_untyped_uuid(), sled_id.into_untyped_uuid(), - Uuid::new_v4(), // physical_disk_id + PhysicalDiskUuid::new_v4(), ); datastore .zpool_insert(opctx, zpool) diff --git a/nexus/reconfigurator/execution/src/lib.rs b/nexus/reconfigurator/execution/src/lib.rs index 570a3512eb..5ba1665483 100644 --- a/nexus/reconfigurator/execution/src/lib.rs +++ b/nexus/reconfigurator/execution/src/lib.rs @@ -717,6 +717,7 @@ mod tests { use nexus_db_model::SledUpdate; use nexus_db_model::Zpool; use omicron_common::api::external::Error; + use omicron_uuid_kinds::PhysicalDiskUuid; use std::collections::BTreeSet; use uuid::Uuid; @@ -776,7 +777,7 @@ mod tests { continue; }; - let physical_disk_id = Uuid::new_v4(); + let physical_disk_id = PhysicalDiskUuid::new_v4(); let pool_id = dataset.dataset.pool_name.id(); let disk = PhysicalDisk::new( diff --git a/nexus/reconfigurator/execution/src/omicron_physical_disks.rs b/nexus/reconfigurator/execution/src/omicron_physical_disks.rs index be16341df6..5aeab020d1 100644 --- a/nexus/reconfigurator/execution/src/omicron_physical_disks.rs +++ b/nexus/reconfigurator/execution/src/omicron_physical_disks.rs @@ -248,7 +248,7 @@ mod test { serial: "test-serial".to_string(), model: "test-model".to_string(), }, - id: Uuid::new_v4(), + id: PhysicalDiskUuid::new_v4(), pool_id: ZpoolUuid::new_v4(), }], } @@ -407,9 +407,9 @@ mod test { i: usize, sled_id: SledUuid, ) -> PhysicalDiskUuid { - let id = PhysicalDiskUuid::from_untyped_uuid(Uuid::new_v4()); + let id = PhysicalDiskUuid::new_v4(); let physical_disk = PhysicalDisk::new( - id.into_untyped_uuid(), + id, "v".into(), format!("s-{i})"), "m".into(), @@ -432,11 +432,7 @@ mod test { let zpool = datastore .zpool_insert( opctx, - Zpool::new( - Uuid::new_v4(), - sled_id.into_untyped_uuid(), - id.into_untyped_uuid(), - ), + Zpool::new(Uuid::new_v4(), sled_id.into_untyped_uuid(), id), ) .await .unwrap(); @@ -559,7 +555,7 @@ mod test { datastore .physical_disk_update_policy( &opctx, - disk_to_decommission.into_untyped_uuid(), + disk_to_decommission, PhysicalDiskPolicy::Expunged, ) .await @@ -577,10 +573,10 @@ mod test { .into_iter() .map(|disk| (disk.id(), disk)) .collect::>(); - let d = &all_disks[&disk_to_decommission.into_untyped_uuid()]; + let d = &all_disks[&disk_to_decommission]; assert_eq!(d.disk_state, PhysicalDiskState::Active); assert_eq!(d.disk_policy, PhysicalDiskPolicy::Expunged); - let d = &all_disks[&other_disk.into_untyped_uuid()]; + let d = &all_disks[&other_disk]; assert_eq!(d.disk_state, PhysicalDiskState::Active); assert_eq!(d.disk_policy, PhysicalDiskPolicy::InService); @@ -607,10 +603,10 @@ mod test { .into_iter() .map(|disk| (disk.id(), disk)) .collect::>(); - let d = &all_disks[&disk_to_decommission.into_untyped_uuid()]; + let d = &all_disks[&disk_to_decommission]; assert_eq!(d.disk_state, PhysicalDiskState::Decommissioned); assert_eq!(d.disk_policy, PhysicalDiskPolicy::Expunged); - let d = &all_disks[&other_disk.into_untyped_uuid()]; + let d = &all_disks[&other_disk]; assert_eq!(d.disk_state, PhysicalDiskState::Active); assert_eq!(d.disk_policy, PhysicalDiskPolicy::InService); diff --git a/nexus/reconfigurator/planning/src/blueprint_builder/builder.rs b/nexus/reconfigurator/planning/src/blueprint_builder/builder.rs index f9010fe1f6..cf6cbfacc0 100644 --- a/nexus/reconfigurator/planning/src/blueprint_builder/builder.rs +++ b/nexus/reconfigurator/planning/src/blueprint_builder/builder.rs @@ -888,7 +888,7 @@ impl<'a> BlueprintBuilder<'a> { database_disk_ids.insert(disk_id); sled_storage.ensure_disk(BlueprintPhysicalDiskConfig { identity: disk.disk_identity.clone(), - id: disk_id.into_untyped_uuid(), + id: disk_id, pool_id: *zpool, }); } diff --git a/nexus/reconfigurator/planning/src/blueprint_builder/builder/disks_editor.rs b/nexus/reconfigurator/planning/src/blueprint_builder/builder/disks_editor.rs index c4fd14eccb..7c5c4c318f 100644 --- a/nexus/reconfigurator/planning/src/blueprint_builder/builder/disks_editor.rs +++ b/nexus/reconfigurator/planning/src/blueprint_builder/builder/disks_editor.rs @@ -8,7 +8,6 @@ use super::EditCounts; use nexus_types::deployment::BlueprintPhysicalDiskConfig; use nexus_types::deployment::BlueprintPhysicalDisksConfig; use omicron_common::api::external::Generation; -use omicron_uuid_kinds::GenericUuid; use omicron_uuid_kinds::PhysicalDiskUuid; use omicron_uuid_kinds::SledUuid; use std::collections::btree_map::Entry; @@ -127,7 +126,7 @@ impl<'a> SledDisksEditor<'a> { } pub fn ensure_disk(&mut self, disk: BlueprintPhysicalDiskConfig) { - let disk_id = PhysicalDiskUuid::from_untyped_uuid(disk.id); + let disk_id = disk.id; match self.config.disks.entry(disk_id) { Entry::Vacant(slot) => { slot.insert(disk); @@ -189,9 +188,7 @@ impl From for DisksConfig { disks: config .disks .into_iter() - .map(|disk| { - (PhysicalDiskUuid::from_untyped_uuid(disk.id), disk) - }) + .map(|disk| (disk.id, disk)) .collect(), } } diff --git a/nexus/reconfigurator/preparation/src/lib.rs b/nexus/reconfigurator/preparation/src/lib.rs index 39367824b9..c3b66c6e0e 100644 --- a/nexus/reconfigurator/preparation/src/lib.rs +++ b/nexus/reconfigurator/preparation/src/lib.rs @@ -48,7 +48,6 @@ use omicron_common::policy::NEXUS_REDUNDANCY; use omicron_common::policy::OXIMETER_REDUNDANCY; use omicron_uuid_kinds::GenericUuid; use omicron_uuid_kinds::OmicronZoneUuid; -use omicron_uuid_kinds::PhysicalDiskUuid; use omicron_uuid_kinds::SledUuid; use omicron_uuid_kinds::ZpoolUuid; use slog::error; @@ -234,7 +233,7 @@ impl PlanningInputFromDb<'_> { serial: disk.serial.clone(), model: disk.model.clone(), }, - disk_id: PhysicalDiskUuid::from_untyped_uuid(disk.id()), + disk_id: disk.id(), policy: disk.disk_policy.into(), state: disk.disk_state.into(), }; diff --git a/nexus/src/app/background/tasks/blueprint_execution.rs b/nexus/src/app/background/tasks/blueprint_execution.rs index a9d47af117..bdae1b4f20 100644 --- a/nexus/src/app/background/tasks/blueprint_execution.rs +++ b/nexus/src/app/background/tasks/blueprint_execution.rs @@ -195,6 +195,7 @@ mod test { use omicron_common::zpool_name::ZpoolName; use omicron_uuid_kinds::GenericUuid; use omicron_uuid_kinds::OmicronZoneUuid; + use omicron_uuid_kinds::PhysicalDiskUuid; use omicron_uuid_kinds::SledUuid; use omicron_uuid_kinds::ZpoolUuid; use serde::Deserialize; @@ -454,7 +455,7 @@ mod test { let zpool = Zpool::new( pool_id.into_untyped_uuid(), sled_id.into_untyped_uuid(), - Uuid::new_v4(), // physical_disk_id + PhysicalDiskUuid::new_v4(), ); datastore .zpool_insert(&opctx, zpool) diff --git a/nexus/src/app/background/tasks/decommissioned_disk_cleaner.rs b/nexus/src/app/background/tasks/decommissioned_disk_cleaner.rs index 2782c8799d..551372e67e 100644 --- a/nexus/src/app/background/tasks/decommissioned_disk_cleaner.rs +++ b/nexus/src/app/background/tasks/decommissioned_disk_cleaner.rs @@ -201,9 +201,9 @@ mod tests { i: usize, sled_id: SledUuid, ) -> PhysicalDiskUuid { - let id = PhysicalDiskUuid::from_untyped_uuid(Uuid::new_v4()); + let id = PhysicalDiskUuid::new_v4(); let physical_disk = PhysicalDisk::new( - id.into_untyped_uuid(), + id, "v".into(), format!("s-{i})"), "m".into(), @@ -226,11 +226,7 @@ mod tests { let zpool = datastore .zpool_insert( opctx, - Zpool::new( - Uuid::new_v4(), - sled_id.into_untyped_uuid(), - id.into_untyped_uuid(), - ), + Zpool::new(Uuid::new_v4(), sled_id.into_untyped_uuid(), id), ) .await .unwrap(); @@ -301,7 +297,7 @@ mod tests { datastore .physical_disk_update_policy( &opctx, - disk_id.into_untyped_uuid(), + disk_id, PhysicalDiskPolicy::Expunged, ) .await diff --git a/nexus/src/app/background/tasks/physical_disk_adoption.rs b/nexus/src/app/background/tasks/physical_disk_adoption.rs index b1eceed0b6..8ad17b5881 100644 --- a/nexus/src/app/background/tasks/physical_disk_adoption.rs +++ b/nexus/src/app/background/tasks/physical_disk_adoption.rs @@ -22,6 +22,7 @@ use nexus_types::identity::Asset; use omicron_common::api::external::DataPageParams; use omicron_uuid_kinds::CollectionUuid; use omicron_uuid_kinds::GenericUuid; +use omicron_uuid_kinds::PhysicalDiskUuid; use serde_json::json; use std::sync::Arc; use tokio::sync::watch; @@ -126,7 +127,7 @@ impl BackgroundTask for PhysicalDiskAdoption { for inv_disk in uninitialized { let disk = PhysicalDisk::new( - Uuid::new_v4(), + PhysicalDiskUuid::new_v4(), inv_disk.vendor, inv_disk.serial, inv_disk.model, diff --git a/nexus/src/app/background/tasks/region_snapshot_replacement_start.rs b/nexus/src/app/background/tasks/region_snapshot_replacement_start.rs index 70d9073971..04d86a1268 100644 --- a/nexus/src/app/background/tasks/region_snapshot_replacement_start.rs +++ b/nexus/src/app/background/tasks/region_snapshot_replacement_start.rs @@ -455,7 +455,7 @@ mod test { datastore .physical_disk_update_policy( &opctx, - db_zpool.physical_disk_id, + db_zpool.physical_disk_id.into(), PhysicalDiskPolicy::Expunged, ) .await diff --git a/nexus/src/app/sled.rs b/nexus/src/app/sled.rs index ff4cbc89c5..61a032f8bd 100644 --- a/nexus/src/app/sled.rs +++ b/nexus/src/app/sled.rs @@ -25,6 +25,7 @@ use omicron_common::api::external::LookupResult; use omicron_common::api::internal::shared::DatasetKind; use omicron_uuid_kinds::DatasetUuid; use omicron_uuid_kinds::GenericUuid; +use omicron_uuid_kinds::PhysicalDiskUuid; use omicron_uuid_kinds::SledUuid; use sled_agent_client::Client as SledAgentClient; use std::net::SocketAddrV6; @@ -208,8 +209,10 @@ impl super::Nexus { opctx: &'a OpContext, disk_selector: ¶ms::PhysicalDiskPath, ) -> Result, Error> { - Ok(lookup::LookupPath::new(&opctx, &self.db_datastore) - .physical_disk(disk_selector.disk_id)) + // XXX how to do typed UUID as part of dropshot path? + Ok(lookup::LookupPath::new(&opctx, &self.db_datastore).physical_disk( + PhysicalDiskUuid::from_untyped_uuid(disk_selector.disk_id), + )) } pub(crate) async fn sled_list_physical_disks( diff --git a/nexus/test-utils/src/lib.rs b/nexus/test-utils/src/lib.rs index 185965b61b..0ae562ed73 100644 --- a/nexus/test-utils/src/lib.rs +++ b/nexus/test-utils/src/lib.rs @@ -76,6 +76,7 @@ use omicron_uuid_kinds::DatasetUuid; use omicron_uuid_kinds::ExternalIpUuid; use omicron_uuid_kinds::GenericUuid; use omicron_uuid_kinds::OmicronZoneUuid; +use omicron_uuid_kinds::PhysicalDiskUuid; use omicron_uuid_kinds::SledUuid; use omicron_uuid_kinds::ZpoolUuid; use oximeter_collector::Oximeter; @@ -838,7 +839,7 @@ impl<'a, N: NexusServer> ControlPlaneTestContextBuilder<'a, N> { "nexus-test-disk-{disk_index}" ), }, - id: Uuid::new_v4(), + id: PhysicalDiskUuid::new_v4(), pool_id: zpool.id(), }); disk_index += 1; @@ -875,7 +876,7 @@ impl<'a, N: NexusServer> ControlPlaneTestContextBuilder<'a, N> { "nexus-test-disk-{disk_index}" ), }, - id: Uuid::new_v4(), + id: PhysicalDiskUuid::new_v4(), pool_id: ZpoolUuid::new_v4(), }); disk_index += 1; diff --git a/nexus/test-utils/src/resource_helpers.rs b/nexus/test-utils/src/resource_helpers.rs index ce1fb38f01..c5cb0231d1 100644 --- a/nexus/test-utils/src/resource_helpers.rs +++ b/nexus/test-utils/src/resource_helpers.rs @@ -1244,7 +1244,7 @@ impl<'a, N: NexusServer> DiskTest<'a, N> { let physical_disk_request = nexus_types::internal_api::params::PhysicalDiskPutRequest { - id: *physical_disk_id.as_untyped_uuid(), + id: physical_disk_id, vendor: disk_identity.vendor.clone(), serial: disk_identity.serial.clone(), model: disk_identity.model.clone(), @@ -1256,7 +1256,7 @@ impl<'a, N: NexusServer> DiskTest<'a, N> { let zpool_request = nexus_types::internal_api::params::ZpoolPutRequest { id: zpool.id.into_untyped_uuid(), - physical_disk_id: *physical_disk_id.as_untyped_uuid(), + physical_disk_id, sled_id: sled_id.into_untyped_uuid(), }; diff --git a/nexus/tests/integration_tests/crucible_replacements.rs b/nexus/tests/integration_tests/crucible_replacements.rs index 2f5317e249..5f7e92c393 100644 --- a/nexus/tests/integration_tests/crucible_replacements.rs +++ b/nexus/tests/integration_tests/crucible_replacements.rs @@ -100,7 +100,7 @@ async fn test_region_replacement_does_not_create_freed_region( datastore .physical_disk_update_policy( &opctx, - db_zpool.physical_disk_id, + db_zpool.physical_disk_id.into(), PhysicalDiskPolicy::Expunged, ) .await diff --git a/nexus/tests/integration_tests/disks.rs b/nexus/tests/integration_tests/disks.rs index 8bfe665c17..54cf9036af 100644 --- a/nexus/tests/integration_tests/disks.rs +++ b/nexus/tests/integration_tests/disks.rs @@ -2514,7 +2514,7 @@ async fn test_no_halt_disk_delete_one_region_on_expunged_agent( datastore .physical_disk_update_policy( &opctx, - db_zpool.physical_disk_id, + db_zpool.physical_disk_id.into(), PhysicalDiskPolicy::Expunged, ) .await diff --git a/nexus/tests/integration_tests/sleds.rs b/nexus/tests/integration_tests/sleds.rs index aa1ff3a667..612774db0e 100644 --- a/nexus/tests/integration_tests/sleds.rs +++ b/nexus/tests/integration_tests/sleds.rs @@ -113,7 +113,7 @@ async fn test_physical_disk_create_list_delete( let datastore = nexus.datastore(); let sled_id = Uuid::from_str(&SLED_AGENT_UUID).unwrap(); let physical_disk = DbPhysicalDisk::new( - Uuid::new_v4(), + PhysicalDiskUuid::new_v4(), "v".into(), "s".into(), "m".into(), diff --git a/nexus/types/src/internal_api/params.rs b/nexus/types/src/internal_api/params.rs index 32a16788b4..bbc7565370 100644 --- a/nexus/types/src/internal_api/params.rs +++ b/nexus/types/src/internal_api/params.rs @@ -21,6 +21,7 @@ use omicron_common::api::internal::shared::ExternalPortDiscovery; use omicron_common::api::internal::shared::RackNetworkConfig; use omicron_common::api::internal::shared::SourceNatConfig; use omicron_uuid_kinds::DatasetUuid; +use omicron_uuid_kinds::PhysicalDiskUuid; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use std::fmt; @@ -73,7 +74,7 @@ pub struct SwitchPutResponse {} #[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] pub struct PhysicalDiskPutRequest { - pub id: Uuid, + pub id: PhysicalDiskUuid, pub vendor: String, pub serial: String, @@ -89,7 +90,7 @@ pub struct PhysicalDiskPutRequest { pub struct ZpoolPutRequest { pub id: Uuid, pub sled_id: Uuid, - pub physical_disk_id: Uuid, + pub physical_disk_id: PhysicalDiskUuid, } /// Describes a dataset within a pool. diff --git a/openapi/nexus-internal.json b/openapi/nexus-internal.json index 70b281c143..4b91bf5e2b 100644 --- a/openapi/nexus-internal.json +++ b/openapi/nexus-internal.json @@ -4453,8 +4453,7 @@ "type": "object", "properties": { "id": { - "type": "string", - "format": "uuid" + "$ref": "#/components/schemas/TypedUuidForPhysicalDiskKind" }, "identity": { "$ref": "#/components/schemas/DiskIdentity" @@ -4597,8 +4596,7 @@ "type": "object", "properties": { "id": { - "type": "string", - "format": "uuid" + "$ref": "#/components/schemas/TypedUuidForPhysicalDiskKind" }, "model": { "type": "string" @@ -5810,6 +5808,10 @@ "type": "string", "format": "uuid" }, + "TypedUuidForPhysicalDiskKind": { + "type": "string", + "format": "uuid" + }, "TypedUuidForSledKind": { "type": "string", "format": "uuid" @@ -6034,8 +6036,7 @@ "format": "uuid" }, "physical_disk_id": { - "type": "string", - "format": "uuid" + "$ref": "#/components/schemas/TypedUuidForPhysicalDiskKind" }, "sled_id": { "type": "string", diff --git a/openapi/sled-agent.json b/openapi/sled-agent.json index e8884cc86a..14a4c92692 100644 --- a/openapi/sled-agent.json +++ b/openapi/sled-agent.json @@ -4470,8 +4470,7 @@ "type": "object", "properties": { "id": { - "type": "string", - "format": "uuid" + "$ref": "#/components/schemas/TypedUuidForPhysicalDiskKind" }, "identity": { "$ref": "#/components/schemas/DiskIdentity" @@ -5829,6 +5828,10 @@ "type": "string", "format": "uuid" }, + "TypedUuidForPhysicalDiskKind": { + "type": "string", + "format": "uuid" + }, "TypedUuidForSledKind": { "type": "string", "format": "uuid" diff --git a/schema/omicron-physical-disks.json b/schema/omicron-physical-disks.json index 60c32d98ff..280f4afeaf 100644 --- a/schema/omicron-physical-disks.json +++ b/schema/omicron-physical-disks.json @@ -58,8 +58,7 @@ ], "properties": { "id": { - "type": "string", - "format": "uuid" + "$ref": "#/definitions/TypedUuidForPhysicalDiskKind" }, "identity": { "$ref": "#/definitions/DiskIdentity" @@ -69,6 +68,10 @@ } } }, + "TypedUuidForPhysicalDiskKind": { + "type": "string", + "format": "uuid" + }, "TypedUuidForZpoolKind": { "type": "string", "format": "uuid" diff --git a/schema/rss-service-plan-v5.json b/schema/rss-service-plan-v5.json index 93257e8540..e88a846e1b 100644 --- a/schema/rss-service-plan-v5.json +++ b/schema/rss-service-plan-v5.json @@ -980,8 +980,7 @@ ], "properties": { "id": { - "type": "string", - "format": "uuid" + "$ref": "#/definitions/TypedUuidForPhysicalDiskKind" }, "identity": { "$ref": "#/definitions/DiskIdentity" @@ -1177,6 +1176,10 @@ "type": "string", "format": "uuid" }, + "TypedUuidForPhysicalDiskKind": { + "type": "string", + "format": "uuid" + }, "TypedUuidForZpoolKind": { "type": "string", "format": "uuid" diff --git a/sled-agent/src/rack_setup/plan/service.rs b/sled-agent/src/rack_setup/plan/service.rs index 2b5e35f036..f651ff0e07 100644 --- a/sled-agent/src/rack_setup/plan/service.rs +++ b/sled-agent/src/rack_setup/plan/service.rs @@ -46,8 +46,8 @@ use omicron_common::policy::{ SINGLE_NODE_CLICKHOUSE_REDUNDANCY, }; use omicron_uuid_kinds::{ - DatasetUuid, ExternalIpUuid, GenericUuid, OmicronZoneUuid, SledUuid, - ZpoolUuid, + DatasetUuid, ExternalIpUuid, GenericUuid, OmicronZoneUuid, + PhysicalDiskUuid, SledUuid, ZpoolUuid, }; use rand::prelude::SliceRandom; use schemars::JsonSchema; @@ -514,7 +514,7 @@ impl Plan { .filter(|disk| matches!(disk.variant, DiskVariant::U2)) .map(|disk| OmicronPhysicalDiskConfig { identity: disk.identity.clone(), - id: Uuid::new_v4(), + id: PhysicalDiskUuid::new_v4(), pool_id: ZpoolUuid::new_v4(), }) .collect(); diff --git a/sled-agent/src/sim/storage.rs b/sled-agent/src/sim/storage.rs index d855b40082..dc8cf63fe4 100644 --- a/sled-agent/src/sim/storage.rs +++ b/sled-agent/src/sim/storage.rs @@ -1260,7 +1260,7 @@ impl Storage { }; nexus_client::types::PhysicalDiskPutRequest { - id: *id.as_untyped_uuid(), + id: *id, vendor: disk.identity.vendor.clone(), serial: disk.identity.serial.clone(), model: disk.identity.model.clone(), @@ -1277,7 +1277,7 @@ impl Storage { .map(|pool| nexus_client::types::ZpoolPutRequest { id: pool.id.into_untyped_uuid(), sled_id: self.sled_id, - physical_disk_id: *pool.physical_disk_id.as_untyped_uuid(), + physical_disk_id: pool.physical_disk_id, }) .collect() } diff --git a/sled-storage/src/manager_test_harness.rs b/sled-storage/src/manager_test_harness.rs index 068816ffa7..33705dd0b8 100644 --- a/sled-storage/src/manager_test_harness.rs +++ b/sled-storage/src/manager_test_harness.rs @@ -12,13 +12,13 @@ use key_manager::StorageKeyRequester; use omicron_common::disk::{ OmicronPhysicalDiskConfig, OmicronPhysicalDisksConfig, }; +use omicron_uuid_kinds::PhysicalDiskUuid; use omicron_uuid_kinds::ZpoolUuid; use slog::{info, Logger}; use std::sync::{ atomic::{AtomicBool, Ordering}, Arc, }; -use uuid::Uuid; /// A [`key-manager::SecretRetriever`] that only returns hardcoded IKM for /// epoch 0 @@ -361,7 +361,7 @@ impl StorageManagerTestHarness { OmicronPhysicalDiskConfig { identity: identity.clone(), - id: Uuid::new_v4(), + id: PhysicalDiskUuid::new_v4(), pool_id: ZpoolUuid::new_v4(), } })