Skip to content
Open
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
55 changes: 53 additions & 2 deletions nexus/db-model/src/physical_disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ use super::{
Generation, PhysicalDiskKind, PhysicalDiskPolicy, PhysicalDiskState,
};
use crate::DbTypedUuid;
use crate::InvPhysicalDisk;
use crate::collection::DatastoreCollectionConfig;
use chrono::{DateTime, Utc};
use db_macros::Asset;
use nexus_db_schema::schema::{physical_disk, zpool};
use nexus_types::external_api::physical_disk as physical_disk_types;
use nexus_types::external_api::physical_disk::PhysicalDiskManufacturerIdentity;
use nexus_types::identity::Asset;
use omicron_uuid_kinds::PhysicalDiskAdoptionRequestKind;
use omicron_uuid_kinds::PhysicalDiskKind as PhysicalDiskUuidKind;
use omicron_uuid_kinds::PhysicalDiskUuid;
use omicron_uuid_kinds::SledKind;
Expand All @@ -38,8 +41,20 @@ pub struct PhysicalDisk {
}

impl PhysicalDisk {
/// Creates a new in-service, active disk
pub fn new(
/// Creates a new in-service, active disk from an inventory disk
pub fn new(inv_disk: InvPhysicalDisk) -> Self {
Self::from_parts(
PhysicalDiskUuid::new_v4(),
inv_disk.vendor,
inv_disk.serial,
inv_disk.model,
inv_disk.variant,
inv_disk.sled_id.into(),
)
}

/// Creates a new in-service, active disk from individual fields
pub fn from_parts(
id: PhysicalDiskUuid,
vendor: String,
serial: String,
Expand Down Expand Up @@ -74,6 +89,14 @@ impl PhysicalDisk {
}
}

impl From<PhysicalDisk>
for physical_disk_types::PhysicalDiskManufacturerIdentity
{
fn from(value: PhysicalDisk) -> Self {
Self { vendor: value.vendor, serial: value.serial, model: value.model }
}
}

impl From<PhysicalDisk> for physical_disk_types::PhysicalDisk {
fn from(disk: PhysicalDisk) -> Self {
Self {
Expand All @@ -89,6 +112,34 @@ impl From<PhysicalDisk> for physical_disk_types::PhysicalDisk {
}
}

/// A request to adopt a physical disk into the control plane.
#[derive(Queryable, Insertable, Debug, Clone, Selectable)]
#[diesel(table_name = nexus_db_schema::schema::physical_disk_adoption_request)]
pub struct PhysicalDiskAdoptionRequest {
pub id: DbTypedUuid<PhysicalDiskAdoptionRequestKind>,
pub vendor: String,
pub serial: String,
pub model: String,
pub time_created: DateTime<Utc>,
pub time_deleted: Option<DateTime<Utc>>,
}

impl From<PhysicalDiskAdoptionRequest>
for physical_disk_types::PhysicalDiskAdoptionRequest
{
fn from(req: PhysicalDiskAdoptionRequest) -> Self {
Self {
id: req.id.into(),
disk_id: PhysicalDiskManufacturerIdentity {
vendor: req.vendor,
serial: req.serial,
model: req.model,
},
time_created: req.time_created,
}
}
}

impl DatastoreCollectionConfig<super::Zpool> for PhysicalDisk {
type CollectionId = DbTypedUuid<PhysicalDiskUuidKind>;
type GenerationNumberColumn = physical_disk::dsl::rcgen;
Expand Down
3 changes: 2 additions & 1 deletion nexus/db-model/src/schema_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::{collections::BTreeMap, sync::LazyLock};
///
/// This must be updated when you change the database schema. Refer to
/// schema/crdb/README.adoc in the root of this repository for details.
pub const SCHEMA_VERSION: Version = Version::new(253, 0, 0);
pub const SCHEMA_VERSION: Version = Version::new(254, 0, 0);

/// List of all past database schema versions, in *reverse* order
///
Expand All @@ -28,6 +28,7 @@ pub static KNOWN_VERSIONS: LazyLock<Vec<KnownVersion>> = LazyLock::new(|| {
// | leaving the first copy as an example for the next person.
// v
// KnownVersion::new(next_int, "unique-dirname-with-the-sql-files"),
KnownVersion::new(254, "add-disk-adoption-requests"),
KnownVersion::new(253, "delete-nexus-default-allow-firewall-rule"),
KnownVersion::new(252, "fm-support-bundle-and-alert-request-comments"),
KnownVersion::new(251, "fm-sitrep-next-inv-min-time-started"),
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ mod test {
kind: PhysicalDiskKind,
serial: String,
) -> PhysicalDiskUuid {
let physical_disk = PhysicalDisk::new(
let physical_disk = PhysicalDisk::from_parts(
PhysicalDiskUuid::new_v4(),
TEST_VENDOR.into(),
serial,
Expand Down
Loading
Loading