From a54c76834ec2d0766384dde4fbced5744bea1d43 Mon Sep 17 00:00:00 2001 From: Justin Bennett Date: Mon, 10 Jul 2023 16:00:16 -0400 Subject: [PATCH 1/2] Expose the physical disk form factor --- nexus/db-model/src/physical_disk.rs | 1 + nexus/db-model/src/physical_disk_kind.rs | 19 ++++++++---- nexus/test-utils/src/resource_helpers.rs | 3 +- nexus/tests/integration_tests/sleds.rs | 3 +- nexus/tests/integration_tests/zpools.rs | 2 +- nexus/types/src/external_api/params.rs | 10 +++++++ nexus/types/src/external_api/views.rs | 4 +++ nexus/types/src/internal_api/params.rs | 11 +------ openapi/nexus-internal.json | 2 +- openapi/nexus.json | 37 ++++++++++++++++++++++++ 10 files changed, 73 insertions(+), 19 deletions(-) diff --git a/nexus/db-model/src/physical_disk.rs b/nexus/db-model/src/physical_disk.rs index c40ebd9a9b..3628f7077f 100644 --- a/nexus/db-model/src/physical_disk.rs +++ b/nexus/db-model/src/physical_disk.rs @@ -74,6 +74,7 @@ impl From for views::PhysicalDisk { vendor: disk.vendor, serial: disk.serial, model: disk.model, + form_factor: disk.variant.into(), } } } diff --git a/nexus/db-model/src/physical_disk_kind.rs b/nexus/db-model/src/physical_disk_kind.rs index 469ae4f085..a55d42beef 100644 --- a/nexus/db-model/src/physical_disk_kind.rs +++ b/nexus/db-model/src/physical_disk_kind.rs @@ -3,7 +3,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use super::impl_enum_type; -use nexus_types::internal_api; +use nexus_types::external_api; use serde::{Deserialize, Serialize}; impl_enum_type!( @@ -20,11 +20,20 @@ impl_enum_type!( U2 => b"u2" ); -impl From for PhysicalDiskKind { - fn from(k: internal_api::params::PhysicalDiskKind) -> Self { +impl From for PhysicalDiskKind { + fn from(k: external_api::params::PhysicalDiskKind) -> Self { match k { - internal_api::params::PhysicalDiskKind::M2 => PhysicalDiskKind::M2, - internal_api::params::PhysicalDiskKind::U2 => PhysicalDiskKind::U2, + external_api::params::PhysicalDiskKind::M2 => PhysicalDiskKind::M2, + external_api::params::PhysicalDiskKind::U2 => PhysicalDiskKind::U2, + } + } +} + +impl From for external_api::params::PhysicalDiskKind { + fn from(value: PhysicalDiskKind) -> Self { + match value { + PhysicalDiskKind::M2 => external_api::params::PhysicalDiskKind::M2, + PhysicalDiskKind::U2 => external_api::params::PhysicalDiskKind::U2, } } } diff --git a/nexus/test-utils/src/resource_helpers.rs b/nexus/test-utils/src/resource_helpers.rs index 44a35f2471..e27e0f6bf5 100644 --- a/nexus/test-utils/src/resource_helpers.rs +++ b/nexus/test-utils/src/resource_helpers.rs @@ -14,6 +14,7 @@ use dropshot::Method; use http::StatusCode; use nexus_test_interface::NexusServer; use nexus_types::external_api::params; +use nexus_types::external_api::params::PhysicalDiskKind; use nexus_types::external_api::params::UserId; use nexus_types::external_api::shared; use nexus_types::external_api::shared::IdentityType; @@ -201,7 +202,7 @@ pub async fn create_physical_disk( vendor: &str, serial: &str, model: &str, - variant: internal_params::PhysicalDiskKind, + variant: PhysicalDiskKind, sled_id: Uuid, ) -> internal_params::PhysicalDiskPutResponse { object_put( diff --git a/nexus/tests/integration_tests/sleds.rs b/nexus/tests/integration_tests/sleds.rs index 4692d2aeb2..8c8404e898 100644 --- a/nexus/tests/integration_tests/sleds.rs +++ b/nexus/tests/integration_tests/sleds.rs @@ -16,6 +16,7 @@ use nexus_test_utils::resource_helpers::populate_ip_pool; use nexus_test_utils::start_sled_agent; use nexus_test_utils::SLED_AGENT_UUID; use nexus_test_utils_macros::nexus_test; +use omicron_nexus::external_api::params::PhysicalDiskKind; use omicron_nexus::external_api::views::SledInstance; use omicron_nexus::external_api::views::{PhysicalDisk, Sled}; use omicron_nexus::internal_api::params as internal_params; @@ -113,7 +114,7 @@ async fn test_physical_disk_create_list_delete( "v", "s", "m", - internal_params::PhysicalDiskKind::U2, + PhysicalDiskKind::U2, sled_id, ) .await; diff --git a/nexus/tests/integration_tests/zpools.rs b/nexus/tests/integration_tests/zpools.rs index 26c705a8f0..639434b9d6 100644 --- a/nexus/tests/integration_tests/zpools.rs +++ b/nexus/tests/integration_tests/zpools.rs @@ -6,7 +6,7 @@ use dropshot::test_util::ClientTestContext; use http::method::Method; use http::StatusCode; use omicron_common::api::external::ByteCount; -use omicron_nexus::internal_api::params::PhysicalDiskKind; +use omicron_nexus::external_api::params::PhysicalDiskKind; use omicron_nexus::internal_api::params::PhysicalDiskPutRequest; use omicron_nexus::internal_api::params::ZpoolPutRequest; use uuid::Uuid; diff --git a/nexus/types/src/external_api/params.rs b/nexus/types/src/external_api/params.rs index c599a02a7a..d726e047b9 100644 --- a/nexus/types/src/external_api/params.rs +++ b/nexus/types/src/external_api/params.rs @@ -1118,6 +1118,16 @@ impl JsonSchema for BlockSize { } } +/// Describes the form factor of physical disks. +#[derive( + Debug, Serialize, Deserialize, JsonSchema, Clone, Copy, PartialEq, Eq, +)] +#[serde(rename_all = "snake_case", tag = "type", content = "content")] +pub enum PhysicalDiskKind { + M2, + U2, +} + /// Different sources for a disk #[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)] #[serde(tag = "type", rename_all = "snake_case")] diff --git a/nexus/types/src/external_api/views.rs b/nexus/types/src/external_api/views.rs index 628be8c15b..b1f047f78b 100644 --- a/nexus/types/src/external_api/views.rs +++ b/nexus/types/src/external_api/views.rs @@ -22,6 +22,8 @@ use std::collections::BTreeSet; use std::net::IpAddr; use uuid::Uuid; +use super::params::PhysicalDiskKind; + // SILOS /// View of a Silo @@ -340,6 +342,8 @@ pub struct PhysicalDisk { pub vendor: String, pub serial: String, pub model: String, + + pub form_factor: PhysicalDiskKind, } // SILO USERS diff --git a/nexus/types/src/internal_api/params.rs b/nexus/types/src/internal_api/params.rs index b99eee24d3..8463fe15ca 100644 --- a/nexus/types/src/internal_api/params.rs +++ b/nexus/types/src/internal_api/params.rs @@ -4,6 +4,7 @@ //! Params define the request bodies of API endpoints for creating or updating resources. +use crate::external_api::params::PhysicalDiskKind; use crate::external_api::params::UserId; use crate::external_api::shared::IpRange; use omicron_common::api::external::ByteCount; @@ -66,16 +67,6 @@ pub struct SledAgentStartupInfo { pub reservoir_size: ByteCount, } -/// Describes the type of physical disk. -#[derive( - Debug, Serialize, Deserialize, JsonSchema, Clone, Copy, PartialEq, Eq, -)] -#[serde(rename_all = "snake_case", tag = "type", content = "content")] -pub enum PhysicalDiskKind { - M2, - U2, -} - #[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] pub struct SwitchPutRequest { pub baseboard: Baseboard, diff --git a/openapi/nexus-internal.json b/openapi/nexus-internal.json index 615eb0c930..81baf3ac1c 100644 --- a/openapi/nexus-internal.json +++ b/openapi/nexus-internal.json @@ -2218,7 +2218,7 @@ ] }, "PhysicalDiskKind": { - "description": "Describes the type of physical disk.", + "description": "Describes the form factor of physical disks.", "oneOf": [ { "type": "object", diff --git a/openapi/nexus.json b/openapi/nexus.json index 04922cc941..5358213242 100644 --- a/openapi/nexus.json +++ b/openapi/nexus.json @@ -10579,6 +10579,9 @@ "description": "View of a Physical Disk\n\nPhysical disks reside in a particular sled and are used to store both Instance Disk data as well as internal metadata.", "type": "object", "properties": { + "form_factor": { + "$ref": "#/components/schemas/PhysicalDiskKind" + }, "id": { "description": "unique, immutable, system-controlled identifier for each resource", "type": "string", @@ -10611,6 +10614,7 @@ } }, "required": [ + "form_factor", "id", "model", "serial", @@ -10619,6 +10623,39 @@ "vendor" ] }, + "PhysicalDiskKind": { + "description": "Describes the form factor of physical disks.", + "oneOf": [ + { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "m2" + ] + } + }, + "required": [ + "type" + ] + }, + { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "u2" + ] + } + }, + "required": [ + "type" + ] + } + ] + }, "PhysicalDiskResultsPage": { "description": "A single page of results", "type": "object", From 79747c479aa94084178628f7978e579b85c1f6b7 Mon Sep 17 00:00:00 2001 From: Justin Bennett Date: Mon, 10 Jul 2023 16:28:03 -0400 Subject: [PATCH 2/2] Fix clippy issue --- nexus/tests/integration_tests/sleds.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/nexus/tests/integration_tests/sleds.rs b/nexus/tests/integration_tests/sleds.rs index 8c8404e898..25ef6f32ce 100644 --- a/nexus/tests/integration_tests/sleds.rs +++ b/nexus/tests/integration_tests/sleds.rs @@ -19,7 +19,6 @@ use nexus_test_utils_macros::nexus_test; use omicron_nexus::external_api::params::PhysicalDiskKind; use omicron_nexus::external_api::views::SledInstance; use omicron_nexus::external_api::views::{PhysicalDisk, Sled}; -use omicron_nexus::internal_api::params as internal_params; use omicron_sled_agent::sim; use std::str::FromStr; use uuid::Uuid;