-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[nexus] Add Physical Disk Policy, State (#5335)
- Adds physical disk state, policy as defined in RFD 457 - Does not expose any way to modify this information - In the future, these values will toggled by both sled expungement, and explicitly through a physical disk API Fixes #5153
- Loading branch information
Showing
29 changed files
with
689 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
//! Database representation of a disks's operator-defined policy. | ||
//! | ||
//! This is related to, but different from `PhysicalDiskState`: a disk's **policy** is | ||
//! its disposition as specified by the operator, while its **state** refers to | ||
//! what's currently on it, as determined by Nexus. | ||
//! | ||
//! For example, a disk might be in the `Active` state, but have a policy of | ||
//! `Expunged` -- this would mean that Nexus knows about resources currently | ||
//! provisioned on the disk, but the operator has said that it should be marked | ||
//! as gone. | ||
|
||
use super::impl_enum_type; | ||
use nexus_types::external_api::views; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
impl_enum_type!( | ||
#[derive(Clone, SqlType, Debug, QueryId)] | ||
#[diesel(postgres_type(name = "physical_disk_policy", schema = "public"))] | ||
pub struct PhysicalDiskPolicyEnum; | ||
|
||
#[derive(Clone, Copy, Debug, AsExpression, FromSqlRow, Serialize, Deserialize, PartialEq)] | ||
#[diesel(sql_type = PhysicalDiskPolicyEnum)] | ||
pub enum PhysicalDiskPolicy; | ||
|
||
// Enum values | ||
InService => b"in_service" | ||
Expunged => b"expunged" | ||
); | ||
|
||
impl From<PhysicalDiskPolicy> for views::PhysicalDiskPolicy { | ||
fn from(policy: PhysicalDiskPolicy) -> Self { | ||
match policy { | ||
PhysicalDiskPolicy::InService => { | ||
views::PhysicalDiskPolicy::InService | ||
} | ||
PhysicalDiskPolicy::Expunged => views::PhysicalDiskPolicy::Expunged, | ||
} | ||
} | ||
} | ||
|
||
impl From<views::PhysicalDiskPolicy> for PhysicalDiskPolicy { | ||
fn from(policy: views::PhysicalDiskPolicy) -> Self { | ||
match policy { | ||
views::PhysicalDiskPolicy::InService => { | ||
PhysicalDiskPolicy::InService | ||
} | ||
views::PhysicalDiskPolicy::Expunged => PhysicalDiskPolicy::Expunged, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
//! Database representation of a physical disk's state as understood by Nexus. | ||
|
||
use super::impl_enum_type; | ||
use nexus_types::external_api::views; | ||
use serde::{Deserialize, Serialize}; | ||
use std::fmt; | ||
use strum::EnumIter; | ||
|
||
impl_enum_type!( | ||
#[derive(Clone, SqlType, Debug, QueryId)] | ||
#[diesel(postgres_type(name = "physical_disk_state", schema = "public"))] | ||
pub struct PhysicalDiskStateEnum; | ||
|
||
#[derive(Clone, Copy, Debug, AsExpression, FromSqlRow, Serialize, Deserialize, PartialEq, Eq, EnumIter)] | ||
#[diesel(sql_type = PhysicalDiskStateEnum)] | ||
pub enum PhysicalDiskState; | ||
|
||
// Enum values | ||
Active => b"active" | ||
Decommissioned => b"decommissioned" | ||
); | ||
|
||
impl fmt::Display for PhysicalDiskState { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
// Forward to the canonical implementation in nexus-types. | ||
views::PhysicalDiskState::from(*self).fmt(f) | ||
} | ||
} | ||
|
||
impl From<PhysicalDiskState> for views::PhysicalDiskState { | ||
fn from(state: PhysicalDiskState) -> Self { | ||
match state { | ||
PhysicalDiskState::Active => views::PhysicalDiskState::Active, | ||
PhysicalDiskState::Decommissioned => { | ||
views::PhysicalDiskState::Decommissioned | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl From<views::PhysicalDiskState> for PhysicalDiskState { | ||
fn from(state: views::PhysicalDiskState) -> Self { | ||
match state { | ||
views::PhysicalDiskState::Active => PhysicalDiskState::Active, | ||
views::PhysicalDiskState::Decommissioned => { | ||
PhysicalDiskState::Decommissioned | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.