diff --git a/omicron-common/src/api/external/mod.rs b/omicron-common/src/api/external/mod.rs index bd9780816d..7a4da3e9a1 100644 --- a/omicron-common/src/api/external/mod.rs +++ b/omicron-common/src/api/external/mod.rs @@ -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? */ diff --git a/omicron-common/src/api/internal/nexus.rs b/omicron-common/src/api/internal/nexus.rs index ecae30ec6d..6940cdfd1e 100644 --- a/omicron-common/src/api/internal/nexus.rs +++ b/omicron-common/src/api/internal/nexus.rs @@ -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}; @@ -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 diff --git a/omicron-nexus/src/db/model.rs b/omicron-nexus/src/db/model.rs index d327f0f9a1..788e38e952 100644 --- a/omicron-nexus/src/db/model.rs +++ b/omicron-nexus/src/db/model.rs @@ -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, } @@ -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, @@ -361,6 +370,9 @@ impl From 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, } @@ -373,6 +385,9 @@ impl Into 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, } diff --git a/omicron-nexus/src/sagas.rs b/omicron-nexus/src/sagas.rs index a7ab297daa..89d3f9e820 100644 --- a/omicron-nexus/src/sagas.rs +++ b/omicron-nexus/src/sagas.rs @@ -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(), }; diff --git a/omicron-sled-agent/src/common/instance.rs b/omicron-sled-agent/src/common/instance.rs index cdd3391928..70426345d6 100644 --- a/omicron-sled-agent/src/common/instance.rs +++ b/omicron-sled-agent/src/common/instance.rs @@ -143,12 +143,9 @@ impl InstanceStates { next: InstanceState, desired: Option, ) { - 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 }); } @@ -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, @@ -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(), }) diff --git a/omicron-sled-agent/src/instance.rs b/omicron-sled-agent/src/instance.rs index 1ba5964690..1c352de388 100644 --- a/omicron-sled-agent/src/instance.rs +++ b/omicron-sled-agent/src/instance.rs @@ -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, @@ -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, }; @@ -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(), } diff --git a/omicron-sled-agent/src/instance_manager.rs b/omicron-sled-agent/src/instance_manager.rs index 77e1f060fe..3173ed9a27 100644 --- a/omicron-sled-agent/src/instance_manager.rs +++ b/omicron-sled-agent/src/instance_manager.rs @@ -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, }; @@ -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(), } diff --git a/omicron-sled-agent/src/sim/collection.rs b/omicron-sled-agent/src/sim/collection.rs index 5ce37b3ef5..9a6c45b181 100644 --- a/omicron-sled-agent/src/sim/collection.rs +++ b/omicron-sled-agent/src/sim/collection.rs @@ -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; @@ -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(), }