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

Expose the physical disk form factor #3556

Merged
merged 2 commits into from
Jul 10, 2023
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 nexus/db-model/src/physical_disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ impl From<PhysicalDisk> for views::PhysicalDisk {
vendor: disk.vendor,
serial: disk.serial,
model: disk.model,
form_factor: disk.variant.into(),
}
}
}
Expand Down
19 changes: 14 additions & 5 deletions nexus/db-model/src/physical_disk_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand All @@ -20,11 +20,20 @@ impl_enum_type!(
U2 => b"u2"
);

impl From<internal_api::params::PhysicalDiskKind> for PhysicalDiskKind {
fn from(k: internal_api::params::PhysicalDiskKind) -> Self {
impl From<external_api::params::PhysicalDiskKind> 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<PhysicalDiskKind> 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,
}
}
}
3 changes: 2 additions & 1 deletion nexus/test-utils/src/resource_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions nexus/tests/integration_tests/sleds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ 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;
use omicron_sled_agent::sim;
use std::str::FromStr;
use uuid::Uuid;
Expand Down Expand Up @@ -113,7 +113,7 @@ async fn test_physical_disk_create_list_delete(
"v",
"s",
"m",
internal_params::PhysicalDiskKind::U2,
PhysicalDiskKind::U2,
sled_id,
)
.await;
Expand Down
2 changes: 1 addition & 1 deletion nexus/tests/integration_tests/zpools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions nexus/types/src/external_api/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
4 changes: 4 additions & 0 deletions nexus/types/src/external_api/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use std::collections::BTreeSet;
use std::net::IpAddr;
use uuid::Uuid;

use super::params::PhysicalDiskKind;

// SILOS

/// View of a Silo
Expand Down Expand Up @@ -340,6 +342,8 @@ pub struct PhysicalDisk {
pub vendor: String,
pub serial: String,
pub model: String,

pub form_factor: PhysicalDiskKind,
}

// SILO USERS
Expand Down
11 changes: 1 addition & 10 deletions nexus/types/src/internal_api/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion openapi/nexus-internal.json
Original file line number Diff line number Diff line change
Expand Up @@ -2218,7 +2218,7 @@
]
},
"PhysicalDiskKind": {
"description": "Describes the type of physical disk.",
"description": "Describes the form factor of physical disks.",
"oneOf": [
{
"type": "object",
Expand Down
37 changes: 37 additions & 0 deletions openapi/nexus.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -10611,6 +10614,7 @@
}
},
"required": [
"form_factor",
"id",
"model",
"serial",
Expand All @@ -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",
Expand Down