Skip to content

Commit

Permalink
[api][instance] Relocate instance hardware info to InstanceRuntimeSta…
Browse files Browse the repository at this point in the history
…te (#165)
  • Loading branch information
smklein authored Sep 1, 2021
1 parent ee3fa44 commit 220889e
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 14 deletions.
2 changes: 1 addition & 1 deletion omicron-common/src/api/external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ pub struct Instance {

/** number of CPUs allocated for this Instance */
pub ncpus: InstanceCpuCount,
/** memory, in gigabytes, allocated for this Instance */
/** memory allocated for this Instance */
pub memory: ByteCount,
/** RFC1035-compliant hostname for the Instance. */
pub hostname: String, /* TODO-cleanup different type? */
Expand Down
11 changes: 10 additions & 1 deletion omicron-common/src/api/internal/nexus.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! APIs exposed by Nexus.
use crate::api::external::{DiskState, Generation, InstanceState};
use crate::api::external::{
ByteCount, DiskState, Generation, InstanceCpuCount, InstanceState,
};
use chrono::{DateTime, Utc};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -30,6 +32,13 @@ pub struct InstanceRuntimeState {
pub run_state: InstanceState,
/// which sled is running this Instance
pub sled_uuid: Uuid,
/// number of CPUs allocated for this Instance
pub ncpus: InstanceCpuCount,
/// memory allocated for this Instance
pub memory: ByteCount,
/// RFC1035-compliant hostname for the Instance.
// TODO-cleanup different type?
pub hostname: String,
/// generation number for this state
pub gen: Generation,
/// timestamp for this information
Expand Down
15 changes: 15 additions & 0 deletions omicron-nexus/src/db/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ impl Instance {
InstanceRuntimeState {
state: self.state,
sled_uuid: self.active_server_id,
ncpus: self.ncpus,
memory: self.memory,
hostname: self.hostname.clone(),
gen: self.state_generation,
time_updated: self.time_state_updated,
}
Expand Down Expand Up @@ -337,6 +340,12 @@ pub struct InstanceRuntimeState {
// TODO: should this be optional?
#[column_name = "active_server_id"]
pub sled_uuid: Uuid,
#[column_name = "ncpus"]
pub ncpus: InstanceCpuCount,
#[column_name = "memory"]
pub memory: ByteCount,
#[column_name = "hostname"]
pub hostname: String,
/// generation number for this state
#[column_name = "state_generation"]
pub gen: Generation,
Expand All @@ -361,6 +370,9 @@ impl From<internal::nexus::InstanceRuntimeState> for InstanceRuntimeState {
Self {
state: InstanceState::new(state.run_state),
sled_uuid: state.sled_uuid,
ncpus: state.ncpus,
memory: state.memory,
hostname: state.hostname,
gen: state.gen,
time_updated: state.time_updated,
}
Expand All @@ -373,6 +385,9 @@ impl Into<internal::nexus::InstanceRuntimeState> for InstanceRuntimeState {
internal::sled_agent::InstanceRuntimeState {
run_state: *self.state.state(),
sled_uuid: self.sled_uuid,
ncpus: self.ncpus,
memory: self.memory,
hostname: self.hostname,
gen: self.gen,
time_updated: self.time_updated,
}
Expand Down
3 changes: 3 additions & 0 deletions omicron-nexus/src/sagas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ async fn sic_create_instance_record(
let runtime = InstanceRuntimeState {
run_state: InstanceState::Creating,
sled_uuid: sled_uuid?,
hostname: params.create_params.hostname.clone(),
memory: params.create_params.memory,
ncpus: params.create_params.ncpus,
gen: Generation::new(),
time_updated: Utc::now(),
};
Expand Down
16 changes: 9 additions & 7 deletions omicron-sled-agent/src/common/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,9 @@ impl InstanceStates {
next: InstanceState,
desired: Option<InstanceStateRequested>,
) {
self.current = InstanceRuntimeState {
run_state: next,
sled_uuid: self.current.sled_uuid,
gen: self.current.gen.next(),
time_updated: Utc::now(),
};
self.current.run_state = next;
self.current.gen = self.current.gen.next();
self.current.time_updated = Utc::now();
self.desired = desired
.map(|run_state| InstanceRuntimeStateRequested { run_state });
}
Expand Down Expand Up @@ -261,7 +258,9 @@ impl InstanceStates {
mod test {
use super::{Action, InstanceStates};
use chrono::Utc;
use omicron_common::api::external::{Generation, InstanceState as State};
use omicron_common::api::external::{
ByteCount, Generation, InstanceCpuCount, InstanceState as State,
};
use omicron_common::api::internal::{
nexus::InstanceRuntimeState,
sled_agent::InstanceStateRequested as Requested,
Expand All @@ -272,6 +271,9 @@ mod test {
InstanceStates::new(InstanceRuntimeState {
run_state: State::Creating,
sled_uuid: uuid::Uuid::new_v4(),
ncpus: InstanceCpuCount(2),
memory: ByteCount::from_mebibytes_u32(512),
hostname: "myvm".to_string(),
gen: Generation::new(),
time_updated: Utc::now(),
})
Expand Down
15 changes: 11 additions & 4 deletions omicron-sled-agent/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,14 @@ impl Instance {
// NOTE: Mostly lies.
properties: propolis_client::api::InstanceProperties {
id,
name: "Test instance".to_string(),
name: initial_runtime.hostname.clone(),
description: "Test description".to_string(),
image_id: Uuid::nil(),
bootrom_id: Uuid::nil(),
memory: 256,
vcpus: 2,
memory: initial_runtime.memory.to_bytes(),
// TODO: we should probably make propolis aligned with
// InstanceCpuCount here, to avoid any casting...
vcpus: initial_runtime.ncpus.0 as u8,
},
state: InstanceStates::new(initial_runtime),
nexus_client,
Expand Down Expand Up @@ -477,7 +479,9 @@ mod test {
RequestContext, TypedBody,
};
use futures::future::FutureExt;
use omicron_common::api::external::{Generation, InstanceState};
use omicron_common::api::external::{
ByteCount, Generation, InstanceCpuCount, InstanceState,
};
use omicron_common::api::internal::{
nexus::InstanceRuntimeState, sled_agent::InstanceStateRequested,
};
Expand Down Expand Up @@ -808,6 +812,9 @@ mod test {
InstanceRuntimeState {
run_state: InstanceState::Creating,
sled_uuid: Uuid::new_v4(),
ncpus: InstanceCpuCount(2),
memory: ByteCount::from_mebibytes_u32(512),
hostname: "myvm".to_string(),
gen: Generation::new(),
time_updated: Utc::now(),
}
Expand Down
7 changes: 6 additions & 1 deletion omicron-sled-agent/src/instance_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ mod test {
use crate::instance::MockInstance;
use crate::mocks::MockNexusClient;
use chrono::Utc;
use omicron_common::api::external::{Generation, InstanceState};
use omicron_common::api::external::{
ByteCount, Generation, InstanceCpuCount, InstanceState,
};
use omicron_common::api::internal::{
nexus::InstanceRuntimeState, sled_agent::InstanceStateRequested,
};
Expand All @@ -221,6 +223,9 @@ mod test {
InstanceRuntimeState {
run_state: InstanceState::Creating,
sled_uuid: Uuid::new_v4(),
ncpus: InstanceCpuCount(2),
memory: ByteCount::from_mebibytes_u32(512),
hostname: "myvm".to_string(),
gen: Generation::new(),
time_updated: Utc::now(),
}
Expand Down
5 changes: 5 additions & 0 deletions omicron-sled-agent/src/sim/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,11 @@ mod test {
use chrono::Utc;
use dropshot::test_util::LogContext;
use futures::channel::mpsc::Receiver;
use omicron_common::api::external::ByteCount;
use omicron_common::api::external::DiskState;
use omicron_common::api::external::Error;
use omicron_common::api::external::Generation;
use omicron_common::api::external::InstanceCpuCount;
use omicron_common::api::external::InstanceState;
use omicron_common::api::internal::nexus::DiskRuntimeState;
use omicron_common::api::internal::nexus::InstanceRuntimeState;
Expand All @@ -354,6 +356,9 @@ mod test {
InstanceRuntimeState {
run_state: InstanceState::Creating,
sled_uuid: uuid::Uuid::new_v4(),
ncpus: InstanceCpuCount(2),
memory: ByteCount::from_mebibytes_u32(512),
hostname: "myvm".to_string(),
gen: Generation::new(),
time_updated: Utc::now(),
}
Expand Down

0 comments on commit 220889e

Please sign in to comment.