Skip to content

Commit 958cde1

Browse files
authored
Use SledUuid (#8991)
Use the typed SledUuid. Make sure to use the schemars trick so that the APIs dont' change. Also: - physical disk uuid and dataset uuid were already used, use that in more places - add a few missing MPL headers
1 parent 49d332e commit 958cde1

File tree

79 files changed

+432
-409
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+432
-409
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/src/api/external/http_pagination.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ impl ScanParams for ScanByName {
260260
/// Query parameters for pagination by id only
261261
pub type PaginatedById<Selector = ()> =
262262
PaginationParams<ScanById<Selector>, PageSelectorById<Selector>>;
263-
/// Page selector for pagination by name only
263+
/// Page selector for pagination by id only
264264
pub type PageSelectorById<Selector = ()> =
265265
PageSelector<ScanById<Selector>, Uuid>;
266266
/// Scan parameters for resources that support scanning by id only

common/src/api/external/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub use error::*;
2424
use futures::stream::BoxStream;
2525
use omicron_uuid_kinds::GenericUuid;
2626
use omicron_uuid_kinds::InstanceUuid;
27+
use omicron_uuid_kinds::SledUuid;
2728
use oxnet::IpNet;
2829
use oxnet::Ipv4Net;
2930
use parse_display::Display;
@@ -3485,7 +3486,9 @@ pub struct TufRepoGetResponse {
34853486
pub struct Probe {
34863487
#[serde(flatten)]
34873488
pub identity: IdentityMetadata,
3488-
pub sled: Uuid,
3489+
3490+
#[schemars(with = "Uuid")]
3491+
pub sled: SledUuid,
34893492
}
34903493

34913494
/// Define policy relating to the import and export of prefixes from a BGP

dev-tools/omdb/src/bin/omdb/db.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -455,14 +455,14 @@ enum DiskCommands {
455455

456456
#[derive(Debug, Args, Clone)]
457457
struct DiskInfoArgs {
458-
/// The UUID of the volume
458+
/// The UUID of the disk
459459
uuid: Uuid,
460460
}
461461

462462
#[derive(Debug, Args, Clone)]
463463
struct DiskPhysicalArgs {
464464
/// The UUID of the physical disk
465-
uuid: Uuid,
465+
uuid: PhysicalDiskUuid,
466466
}
467467

468468
#[derive(Debug, Args, Clone)]
@@ -1641,7 +1641,7 @@ async fn lookup_project(
16411641
#[tabled(rename_all = "SCREAMING_SNAKE_CASE")]
16421642
struct CrucibleDatasetRow {
16431643
// dataset fields
1644-
id: Uuid,
1644+
id: DatasetUuid,
16451645
time_deleted: String,
16461646
pool_id: Uuid,
16471647
address: String,
@@ -1710,7 +1710,7 @@ async fn get_crucible_dataset_rows(
17101710

17111711
result.push(CrucibleDatasetRow {
17121712
// dataset fields
1713-
id: d.id().into_untyped_uuid(),
1713+
id: d.id(),
17141714
time_deleted: match d.time_deleted() {
17151715
Some(t) => t.to_string(),
17161716
None => String::from(""),
@@ -2151,7 +2151,7 @@ async fn cmd_db_disk_info(
21512151
let my_sled_id = instance.sled_id().unwrap();
21522152

21532153
let (_, my_sled) = LookupPath::new(opctx, datastore)
2154-
.sled_id(my_sled_id.into_untyped_uuid())
2154+
.sled_id(my_sled_id)
21552155
.fetch()
21562156
.await
21572157
.context("failed to look up sled")?;
@@ -2207,7 +2207,7 @@ async fn cmd_db_disk_info(
22072207
.await
22082208
.context("failed to look up zpool")?;
22092209

2210-
let my_sled_id = my_zpool.sled_id;
2210+
let my_sled_id = my_zpool.sled_id();
22112211

22122212
let (_, my_sled) = LookupPath::new(opctx, datastore)
22132213
.sled_id(my_sled_id)
@@ -2282,7 +2282,7 @@ async fn cmd_db_disk_physical(
22822282
}
22832283

22842284
let zpools = query
2285-
.filter(zpool_dsl::physical_disk_id.eq(args.uuid))
2285+
.filter(zpool_dsl::physical_disk_id.eq(to_db_typed_uuid(args.uuid)))
22862286
.select(Zpool::as_select())
22872287
.load_async(&*conn)
22882288
.await
@@ -2301,7 +2301,7 @@ async fn cmd_db_disk_physical(
23012301
// changes, this code will still work.
23022302
for zp in zpools {
23032303
// zpool has the sled id, record that so we can find the serial number.
2304-
sled_ids.insert(zp.sled_id);
2304+
sled_ids.insert(zp.sled_id());
23052305

23062306
// Next, we find all the Crucible datasets that are on our zpool.
23072307
use nexus_db_schema::schema::crucible_dataset::dsl as dataset_dsl;
@@ -2514,7 +2514,7 @@ struct PhysicalDiskRow {
25142514
serial: String,
25152515
vendor: String,
25162516
model: String,
2517-
sled_id: Uuid,
2517+
sled_id: SledUuid,
25182518
policy: PhysicalDiskPolicy,
25192519
state: PhysicalDiskState,
25202520
}
@@ -2526,7 +2526,7 @@ impl From<PhysicalDisk> for PhysicalDiskRow {
25262526
serial: d.serial.clone(),
25272527
vendor: d.vendor.clone(),
25282528
model: d.model.clone(),
2529-
sled_id: d.sled_id,
2529+
sled_id: d.sled_id(),
25302530
policy: d.disk_policy.into(),
25312531
state: d.disk_state.into(),
25322532
}
@@ -2746,7 +2746,7 @@ async fn cmd_db_snapshot_info(
27462746
.await
27472747
.context("failed to look up zpool")?;
27482748

2749-
let my_sled_id = my_zpool.sled_id;
2749+
let my_sled_id = my_zpool.sled_id();
27502750

27512751
let (_, my_sled) = LookupPath::new(opctx, datastore)
27522752
.sled_id(my_sled_id)
@@ -2786,7 +2786,7 @@ async fn cmd_db_snapshot_info(
27862786
.await
27872787
.context("failed to look up zpool")?;
27882788

2789-
let my_sled_id = my_zpool.sled_id;
2789+
let my_sled_id = my_zpool.sled_id();
27902790

27912791
let (_, my_sled) = LookupPath::new(opctx, datastore)
27922792
.sled_id(my_sled_id)
@@ -3829,7 +3829,7 @@ async fn cmd_db_dry_run_region_allocation(
38293829
struct Row {
38303830
pub region_id: Uuid,
38313831

3832-
pub dataset_id: Uuid,
3832+
pub dataset_id: DatasetUuid,
38333833
pub size_used: i64,
38343834

38353835
pub pool_id: Uuid,
@@ -3867,7 +3867,7 @@ async fn cmd_db_dry_run_region_allocation(
38673867
rows.push(Row {
38683868
region_id: region.id(),
38693869

3870-
dataset_id: dataset.id().into_untyped_uuid(),
3870+
dataset_id: dataset.id(),
38713871
size_used: dataset.size_used,
38723872

38733873
pool_id,
@@ -4235,7 +4235,7 @@ struct SledRow {
42354235
role: &'static str,
42364236
policy: SledPolicy,
42374237
state: SledState,
4238-
id: Uuid,
4238+
id: SledUuid,
42394239
}
42404240

42414241
impl From<Sled> for SledRow {
@@ -4733,7 +4733,7 @@ async fn cmd_db_instance_info(
47334733
struct VmmRow {
47344734
#[tabled(inline)]
47354735
state: VmmStateRow,
4736-
sled_id: Uuid,
4736+
sled_id: SledUuid,
47374737
#[tabled(display_with = "datetime_rfc3339_concise")]
47384738
time_created: chrono::DateTime<Utc>,
47394739
#[tabled(display_with = "datetime_opt_rfc3339_concise")]
@@ -4775,7 +4775,7 @@ async fn cmd_db_instance_info(
47754775
state,
47764776
generation: r#gen.0.into(),
47774777
},
4778-
sled_id,
4778+
sled_id: sled_id.into(),
47794779
time_created,
47804780
time_deleted,
47814781
}
@@ -4859,7 +4859,7 @@ async fn cmd_db_instances(
48594859
h_to_s.entry(i.sled_id().unwrap())
48604860
{
48614861
let (_, my_sled) = LookupPath::new(opctx, datastore)
4862-
.sled_id(i.sled_id().unwrap().into_untyped_uuid())
4862+
.sled_id(i.sled_id().unwrap())
48634863
.fetch()
48644864
.await
48654865
.context("failed to look up sled")?;
@@ -7229,13 +7229,13 @@ async fn cmd_db_vmm_info(
72297229
.next()
72307230
.ok_or_else(|| anyhow::anyhow!("no VMM found with ID {uuid}"))?;
72317231
let sled_result =
7232-
LookupPath::new(opctx, datastore).sled_id(vmm.sled_id).fetch().await;
7232+
LookupPath::new(opctx, datastore).sled_id(vmm.sled_id()).fetch().await;
72337233
let sled = match sled_result {
72347234
Ok((_, sled)) => Some(sled),
72357235
Err(err) => {
72367236
eprintln!(
72377237
"WARN: failed to fetch sled with ID {}: {err}",
7238-
vmm.sled_id
7238+
vmm.sled_id()
72397239
);
72407240
None
72417241
}
@@ -7513,7 +7513,7 @@ async fn cmd_db_vmm_list(
75137513
struct VerboseVmmRow<'a> {
75147514
#[tabled(inline)]
75157515
inner: VmmRow<'a>,
7516-
sled_id: Uuid,
7516+
sled_id: SledUuid,
75177517
address: std::net::SocketAddr,
75187518
#[tabled(display_with = "datetime_rfc3339_concise")]
75197519
time_created: DateTime<Utc>,
@@ -7533,7 +7533,7 @@ async fn cmd_db_vmm_list(
75337533
..
75347534
} = it.0;
75357535
VerboseVmmRow {
7536-
sled_id,
7536+
sled_id: sled_id.into(),
75377537
inner: VmmRow::from(it),
75387538
address: std::net::SocketAddr::new(
75397539
propolis_ip.ip(),
@@ -7714,8 +7714,8 @@ async fn cmd_db_zpool_list(
77147714
struct ZpoolRow {
77157715
id: Uuid,
77167716
time_deleted: String,
7717-
sled_id: Uuid,
7718-
physical_disk_id: Uuid,
7717+
sled_id: SledUuid,
7718+
physical_disk_id: PhysicalDiskUuid,
77197719
#[tabled(display_with = "option_impl_display")]
77207720
total_size: Option<i64>,
77217721
control_plane_storage_buffer: i64,
@@ -7731,8 +7731,8 @@ async fn cmd_db_zpool_list(
77317731
Some(t) => t.to_string(),
77327732
None => String::from(""),
77337733
},
7734-
sled_id: p.sled_id,
7735-
physical_disk_id: p.physical_disk_id.into_untyped_uuid(),
7734+
sled_id: p.sled_id(),
7735+
physical_disk_id: p.physical_disk_id(),
77367736
total_size: zpool_total_size.get(&zpool_id).cloned(),
77377737
control_plane_storage_buffer: p
77387738
.control_plane_storage_buffer()

dev-tools/omdb/src/bin/omdb/nexus.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3848,7 +3848,7 @@ async fn cmd_nexus_sled_expunge_with_datastore(
38483848

38493849
// First, we need to look up the sled so we know its serial number.
38503850
let (_authz_sled, sled) = LookupPath::new(opctx, datastore)
3851-
.sled_id(args.sled_id.into_untyped_uuid())
3851+
.sled_id(args.sled_id)
38523852
.fetch()
38533853
.await
38543854
.with_context(|| format!("failed to find sled {}", args.sled_id))?;

nexus/auth/src/authz/api_resources.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ authz_resource! {
13131313
authz_resource! {
13141314
name = "Sled",
13151315
parent = "Fleet",
1316-
primary_key = Uuid,
1316+
primary_key = { uuid_kind = SledKind },
13171317
roles_allowed = false,
13181318
polar_snippet = FleetChild,
13191319
}

nexus/db-lookup/src/lookup.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ impl<'a> LookupPath<'a> {
284284
}
285285

286286
/// Select a resource of type Sled, identified by its id
287-
pub fn sled_id(self, id: Uuid) -> Sled<'a> {
287+
pub fn sled_id(self, id: SledUuid) -> Sled<'a> {
288288
Sled::PrimaryKey(Root { lookup_root: self }, id)
289289
}
290290

@@ -774,7 +774,7 @@ lookup_resource! {
774774
ancestors = [],
775775
lookup_by_name = false,
776776
soft_deletes = true,
777-
primary_key_columns = [ { column_name = "id", rust_type = Uuid } ]
777+
primary_key_columns = [ { column_name = "id", uuid_kind = SledKind } ]
778778
}
779779

780780
lookup_resource! {

nexus/db-model/src/physical_disk.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
use super::{
66
Generation, PhysicalDiskKind, PhysicalDiskPolicy, PhysicalDiskState,
77
};
8+
use crate::DbTypedUuid;
89
use crate::collection::DatastoreCollectionConfig;
910
use chrono::{DateTime, Utc};
1011
use db_macros::Asset;
1112
use nexus_db_schema::schema::{physical_disk, zpool};
1213
use nexus_types::{external_api::views, identity::Asset};
14+
use omicron_uuid_kinds::PhysicalDiskKind as PhysicalDiskUuidKind;
1315
use omicron_uuid_kinds::PhysicalDiskUuid;
14-
use uuid::Uuid;
16+
use omicron_uuid_kinds::SledKind;
17+
use omicron_uuid_kinds::SledUuid;
1518

1619
/// Physical disk attached to sled.
1720
#[derive(Queryable, Insertable, Debug, Clone, Selectable, Asset)]
@@ -28,7 +31,7 @@ pub struct PhysicalDisk {
2831
pub model: String,
2932

3033
pub variant: PhysicalDiskKind,
31-
pub sled_id: Uuid,
34+
pub sled_id: DbTypedUuid<SledKind>,
3235
pub disk_policy: PhysicalDiskPolicy,
3336
pub disk_state: PhysicalDiskState,
3437
}
@@ -41,7 +44,7 @@ impl PhysicalDisk {
4144
serial: String,
4245
model: String,
4346
variant: PhysicalDiskKind,
44-
sled_id: Uuid,
47+
sled_id: SledUuid,
4548
) -> Self {
4649
Self {
4750
identity: PhysicalDiskIdentity::new(id),
@@ -51,7 +54,7 @@ impl PhysicalDisk {
5154
serial,
5255
model,
5356
variant,
54-
sled_id,
57+
sled_id: sled_id.into(),
5558
disk_policy: PhysicalDiskPolicy::InService,
5659
disk_state: PhysicalDiskState::Active,
5760
}
@@ -64,6 +67,10 @@ impl PhysicalDisk {
6467
pub fn time_deleted(&self) -> Option<DateTime<Utc>> {
6568
self.time_deleted
6669
}
70+
71+
pub fn sled_id(&self) -> SledUuid {
72+
self.sled_id.into()
73+
}
6774
}
6875

6976
impl From<PhysicalDisk> for views::PhysicalDisk {
@@ -72,7 +79,7 @@ impl From<PhysicalDisk> for views::PhysicalDisk {
7279
identity: disk.identity(),
7380
policy: disk.disk_policy.into(),
7481
state: disk.disk_state.into(),
75-
sled_id: Some(disk.sled_id),
82+
sled_id: Some(disk.sled_id.into()),
7683
vendor: disk.vendor,
7784
serial: disk.serial,
7885
model: disk.model,
@@ -82,7 +89,7 @@ impl From<PhysicalDisk> for views::PhysicalDisk {
8289
}
8390

8491
impl DatastoreCollectionConfig<super::Zpool> for PhysicalDisk {
85-
type CollectionId = Uuid;
92+
type CollectionId = DbTypedUuid<PhysicalDiskUuidKind>;
8693
type GenerationNumberColumn = physical_disk::dsl::rcgen;
8794
type CollectionTimeDeletedColumn = physical_disk::dsl::time_deleted;
8895
type CollectionIdColumn = zpool::dsl::sled_id;

0 commit comments

Comments
 (0)