-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
17 changed files
with
689 additions
and
152 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
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,66 @@ | ||
// 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/. | ||
|
||
use super::impl_enum_type; | ||
use nexus_types::external_api::views::{SledPolicy, SledProvisionPolicy}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
impl_enum_type!( | ||
#[derive(Clone, SqlType, Debug, QueryId)] | ||
#[diesel(postgres_type(name = "sled_policy", schema = "public"))] | ||
pub struct SledPolicyEnum; | ||
|
||
/// This type is not actually public, because [`SledPolicy`] has a somewhat | ||
/// different, friendlier shape while being equivalent -- external code | ||
/// should always use [`SledPolicy`]. | ||
#[derive(Clone, Copy, Debug, AsExpression, FromSqlRow, Serialize, Deserialize, PartialEq)] | ||
#[diesel(sql_type = SledPolicyEnum)] | ||
pub enum DbSledPolicy; | ||
|
||
// Enum values | ||
InService => b"in_service" | ||
InServiceNoProvision => b"in_service_no_provision" | ||
Expunged => b"expunged" | ||
); | ||
|
||
/// Converts a [`SledPolicy`] to a version that can be inserted into a | ||
/// database. | ||
pub fn to_db_sled_policy(policy: SledPolicy) -> DbSledPolicy { | ||
match policy { | ||
SledPolicy::InService { | ||
provision_policy: SledProvisionPolicy::Provisionable, | ||
} => DbSledPolicy::InService, | ||
SledPolicy::InService { | ||
provision_policy: SledProvisionPolicy::NonProvisionable, | ||
} => DbSledPolicy::InServiceNoProvision, | ||
SledPolicy::Expunged => DbSledPolicy::Expunged, | ||
} | ||
} | ||
|
||
impl DbSledPolicy { | ||
/// Converts self into the appropriate provision policy, in a lossy manner. | ||
pub fn to_provision_policy(self) -> SledProvisionPolicy { | ||
match self { | ||
DbSledPolicy::InService => SledProvisionPolicy::Provisionable, | ||
DbSledPolicy::InServiceNoProvision => { | ||
SledProvisionPolicy::NonProvisionable | ||
} | ||
DbSledPolicy::Expunged => SledProvisionPolicy::NonProvisionable, | ||
} | ||
} | ||
} | ||
|
||
impl From<DbSledPolicy> for SledPolicy { | ||
fn from(policy: DbSledPolicy) -> Self { | ||
match policy { | ||
DbSledPolicy::InService => SledPolicy::InService { | ||
provision_policy: SledProvisionPolicy::Provisionable, | ||
}, | ||
DbSledPolicy::InServiceNoProvision => SledPolicy::InService { | ||
provision_policy: SledProvisionPolicy::NonProvisionable, | ||
}, | ||
DbSledPolicy::Expunged => SledPolicy::Expunged, | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,39 @@ | ||
// 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/. | ||
|
||
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 = "sled_state", schema = "public"))] | ||
pub struct SledStateEnum; | ||
|
||
#[derive(Clone, Copy, Debug, AsExpression, FromSqlRow, Serialize, Deserialize, PartialEq)] | ||
#[diesel(sql_type = SledStateEnum)] | ||
pub enum SledState; | ||
|
||
// Enum values | ||
Active => b"active" | ||
Decommissioned => b"decommissioned" | ||
); | ||
|
||
impl From<SledState> for views::SledState { | ||
fn from(state: SledState) -> Self { | ||
match state { | ||
SledState::Active => views::SledState::Active, | ||
SledState::Decommissioned => views::SledState::Decommissioned, | ||
} | ||
} | ||
} | ||
|
||
impl From<views::SledState> for SledState { | ||
fn from(state: views::SledState) -> Self { | ||
match state { | ||
views::SledState::Active => SledState::Active, | ||
views::SledState::Decommissioned => SledState::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
Oops, something went wrong.