-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sled/instance association for inventory and insights (#3092)
- Loading branch information
Showing
20 changed files
with
460 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -705,6 +705,7 @@ pub enum ResourceType { | |
Rack, | ||
Service, | ||
Sled, | ||
SledInstance, | ||
Switch, | ||
SagaDbg, | ||
Snapshot, | ||
|
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
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,43 @@ | ||
use crate::schema::sled_instance; | ||
use crate::InstanceState; | ||
use crate::Name; | ||
use db_macros::Asset; | ||
use nexus_types::external_api::views; | ||
use nexus_types::identity::Asset; | ||
use serde::Deserialize; | ||
use serde::Serialize; | ||
use uuid::Uuid; | ||
|
||
/// An operator view of an instance as exposed by the sled API. | ||
#[derive(Queryable, Debug, Selectable, Asset, Serialize, Deserialize)] | ||
#[diesel(table_name = sled_instance)] | ||
pub struct SledInstance { | ||
#[diesel(embed)] | ||
identity: SledInstanceIdentity, | ||
active_sled_id: Uuid, | ||
pub migration_id: Option<Uuid>, | ||
|
||
pub name: Name, | ||
pub silo_name: Name, | ||
pub project_name: Name, | ||
|
||
pub state: InstanceState, | ||
pub ncpus: i64, | ||
pub memory: i64, | ||
} | ||
|
||
impl From<SledInstance> for views::SledInstance { | ||
fn from(sled_instance: SledInstance) -> Self { | ||
Self { | ||
identity: sled_instance.identity(), | ||
name: sled_instance.name.into(), | ||
active_sled_id: sled_instance.active_sled_id, | ||
silo_name: sled_instance.silo_name.into(), | ||
project_name: sled_instance.project_name.into(), | ||
state: *sled_instance.state.state(), | ||
migration_id: sled_instance.migration_id, | ||
ncpus: sled_instance.ncpus, | ||
memory: sled_instance.memory, | ||
} | ||
} | ||
} |
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,32 @@ | ||
use super::DataStore; | ||
|
||
use crate::authz; | ||
use crate::context::OpContext; | ||
use crate::db; | ||
use crate::db::error::public_error_from_diesel_pool; | ||
use crate::db::error::ErrorHandler; | ||
use crate::db::pagination::paginated; | ||
use async_bb8_diesel::AsyncRunQueryDsl; | ||
use diesel::prelude::*; | ||
use nexus_db_model::SledInstance; | ||
use omicron_common::api::external::DataPageParams; | ||
use omicron_common::api::external::ListResultVec; | ||
use uuid::Uuid; | ||
|
||
impl DataStore { | ||
pub async fn sled_instance_list( | ||
&self, | ||
opctx: &OpContext, | ||
authz_sled: &authz::Sled, | ||
pagparams: &DataPageParams<'_, Uuid>, | ||
) -> ListResultVec<SledInstance> { | ||
opctx.authorize(authz::Action::ListChildren, &authz::FLEET).await?; | ||
use db::schema::sled_instance::dsl; | ||
paginated(dsl::sled_instance, dsl::id, &pagparams) | ||
.filter(dsl::active_sled_id.eq(authz_sled.id())) | ||
.select(SledInstance::as_select()) | ||
.load_async::<SledInstance>(self.pool_authorized(opctx).await?) | ||
.await | ||
.map_err(|e| public_error_from_diesel_pool(e, ErrorHandler::Server)) | ||
} | ||
} |
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
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,23 @@ | ||
use crate::authz; | ||
use crate::db; | ||
use nexus_db_queries::context::OpContext; | ||
use nexus_db_queries::db::lookup; | ||
use omicron_common::api::external::DataPageParams; | ||
use omicron_common::api::external::ListResultVec; | ||
use uuid::Uuid; | ||
|
||
impl super::Nexus { | ||
pub async fn sled_instance_list( | ||
&self, | ||
opctx: &OpContext, | ||
sled_lookup: &lookup::Sled<'_>, | ||
pagparams: &DataPageParams<'_, Uuid>, | ||
) -> ListResultVec<db::model::SledInstance> { | ||
let (.., authz_sled) = | ||
sled_lookup.lookup_for(authz::Action::Read).await?; | ||
opctx.authorize(authz::Action::ListChildren, &authz::FLEET).await?; | ||
self.db_datastore | ||
.sled_instance_list(opctx, &authz_sled, pagparams) | ||
.await | ||
} | ||
} |
Oops, something went wrong.