Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use more PhysicalDiskUuid #7163

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clients/nexus-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ progenitor::generate_api!(
TypedUuidForDatasetKind = omicron_uuid_kinds::TypedUuid<omicron_uuid_kinds::DatasetKind>,
TypedUuidForDemoSagaKind = omicron_uuid_kinds::DemoSagaUuid,
TypedUuidForDownstairsKind = omicron_uuid_kinds::TypedUuid<omicron_uuid_kinds::DownstairsKind>,
TypedUuidForPhysicalDiskKind = omicron_uuid_kinds::TypedUuid<omicron_uuid_kinds::PhysicalDiskKind>,
TypedUuidForPropolisKind = omicron_uuid_kinds::TypedUuid<omicron_uuid_kinds::PropolisKind>,
TypedUuidForSledKind = omicron_uuid_kinds::TypedUuid<omicron_uuid_kinds::SledKind>,
TypedUuidForUpstairsKind = omicron_uuid_kinds::TypedUuid<omicron_uuid_kinds::UpstairsKind>,
Expand Down
4 changes: 2 additions & 2 deletions common/src/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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,
}

Expand Down
3 changes: 2 additions & 1 deletion dev-tools/omdb/src/bin/omdb/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion dev-tools/omdb/src/bin/omdb/nexus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|| {
Expand Down
2 changes: 1 addition & 1 deletion nexus/auth/src/authz/api_resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
9 changes: 5 additions & 4 deletions nexus/db-model/src/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -179,7 +180,7 @@ pub struct BpOmicronPhysicalDisk {
pub serial: String,
pub model: String,

pub id: Uuid,
pub id: DbTypedUuid<PhysicalDiskKind>,
pub pool_id: Uuid,
}

Expand All @@ -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(),
}
}
Expand All @@ -209,7 +210,7 @@ impl From<BpOmicronPhysicalDisk> for BlueprintPhysicalDiskConfig {
serial: disk.serial,
model: disk.model,
},
id: disk.id,
id: disk.id.into(),
pool_id: ZpoolUuid::from_untyped_uuid(disk.pool_id),
}
}
Expand Down
8 changes: 5 additions & 3 deletions nexus/db-model/src/physical_disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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<DateTime<Utc>> {
Expand Down
13 changes: 10 additions & 3 deletions nexus/db-model/src/zpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<PhysicalDiskKind>,
}

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(),
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion nexus/db-queries/src/db/datastore/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions nexus/db-queries/src/db/datastore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand All @@ -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,
Expand All @@ -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 =
Expand Down Expand Up @@ -903,7 +904,7 @@ mod test {

struct PhysicalDisk {
sled_id: SledUuid,
disk_id: Uuid,
disk_id: PhysicalDiskUuid,
}

// create 9 disks on each sled
Expand Down
Loading
Loading