Skip to content

Commit 220889e

Browse files
authored
[api][instance] Relocate instance hardware info to InstanceRuntimeState (#165)
1 parent ee3fa44 commit 220889e

File tree

8 files changed

+60
-14
lines changed

8 files changed

+60
-14
lines changed

omicron-common/src/api/external/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ pub struct Instance {
846846

847847
/** number of CPUs allocated for this Instance */
848848
pub ncpus: InstanceCpuCount,
849-
/** memory, in gigabytes, allocated for this Instance */
849+
/** memory allocated for this Instance */
850850
pub memory: ByteCount,
851851
/** RFC1035-compliant hostname for the Instance. */
852852
pub hostname: String, /* TODO-cleanup different type? */

omicron-common/src/api/internal/nexus.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! APIs exposed by Nexus.
22
3-
use crate::api::external::{DiskState, Generation, InstanceState};
3+
use crate::api::external::{
4+
ByteCount, DiskState, Generation, InstanceCpuCount, InstanceState,
5+
};
46
use chrono::{DateTime, Utc};
57
use schemars::JsonSchema;
68
use serde::{Deserialize, Serialize};
@@ -30,6 +32,13 @@ pub struct InstanceRuntimeState {
3032
pub run_state: InstanceState,
3133
/// which sled is running this Instance
3234
pub sled_uuid: Uuid,
35+
/// number of CPUs allocated for this Instance
36+
pub ncpus: InstanceCpuCount,
37+
/// memory allocated for this Instance
38+
pub memory: ByteCount,
39+
/// RFC1035-compliant hostname for the Instance.
40+
// TODO-cleanup different type?
41+
pub hostname: String,
3342
/// generation number for this state
3443
pub gen: Generation,
3544
/// timestamp for this information

omicron-nexus/src/db/model.rs

+15
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ impl Instance {
303303
InstanceRuntimeState {
304304
state: self.state,
305305
sled_uuid: self.active_server_id,
306+
ncpus: self.ncpus,
307+
memory: self.memory,
308+
hostname: self.hostname.clone(),
306309
gen: self.state_generation,
307310
time_updated: self.time_state_updated,
308311
}
@@ -337,6 +340,12 @@ pub struct InstanceRuntimeState {
337340
// TODO: should this be optional?
338341
#[column_name = "active_server_id"]
339342
pub sled_uuid: Uuid,
343+
#[column_name = "ncpus"]
344+
pub ncpus: InstanceCpuCount,
345+
#[column_name = "memory"]
346+
pub memory: ByteCount,
347+
#[column_name = "hostname"]
348+
pub hostname: String,
340349
/// generation number for this state
341350
#[column_name = "state_generation"]
342351
pub gen: Generation,
@@ -361,6 +370,9 @@ impl From<internal::nexus::InstanceRuntimeState> for InstanceRuntimeState {
361370
Self {
362371
state: InstanceState::new(state.run_state),
363372
sled_uuid: state.sled_uuid,
373+
ncpus: state.ncpus,
374+
memory: state.memory,
375+
hostname: state.hostname,
364376
gen: state.gen,
365377
time_updated: state.time_updated,
366378
}
@@ -373,6 +385,9 @@ impl Into<internal::nexus::InstanceRuntimeState> for InstanceRuntimeState {
373385
internal::sled_agent::InstanceRuntimeState {
374386
run_state: *self.state.state(),
375387
sled_uuid: self.sled_uuid,
388+
ncpus: self.ncpus,
389+
memory: self.memory,
390+
hostname: self.hostname,
376391
gen: self.gen,
377392
time_updated: self.time_updated,
378393
}

omicron-nexus/src/sagas.rs

+3
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ async fn sic_create_instance_record(
134134
let runtime = InstanceRuntimeState {
135135
run_state: InstanceState::Creating,
136136
sled_uuid: sled_uuid?,
137+
hostname: params.create_params.hostname.clone(),
138+
memory: params.create_params.memory,
139+
ncpus: params.create_params.ncpus,
137140
gen: Generation::new(),
138141
time_updated: Utc::now(),
139142
};

omicron-sled-agent/src/common/instance.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,9 @@ impl InstanceStates {
143143
next: InstanceState,
144144
desired: Option<InstanceStateRequested>,
145145
) {
146-
self.current = InstanceRuntimeState {
147-
run_state: next,
148-
sled_uuid: self.current.sled_uuid,
149-
gen: self.current.gen.next(),
150-
time_updated: Utc::now(),
151-
};
146+
self.current.run_state = next;
147+
self.current.gen = self.current.gen.next();
148+
self.current.time_updated = Utc::now();
152149
self.desired = desired
153150
.map(|run_state| InstanceRuntimeStateRequested { run_state });
154151
}
@@ -261,7 +258,9 @@ impl InstanceStates {
261258
mod test {
262259
use super::{Action, InstanceStates};
263260
use chrono::Utc;
264-
use omicron_common::api::external::{Generation, InstanceState as State};
261+
use omicron_common::api::external::{
262+
ByteCount, Generation, InstanceCpuCount, InstanceState as State,
263+
};
265264
use omicron_common::api::internal::{
266265
nexus::InstanceRuntimeState,
267266
sled_agent::InstanceStateRequested as Requested,
@@ -272,6 +271,9 @@ mod test {
272271
InstanceStates::new(InstanceRuntimeState {
273272
run_state: State::Creating,
274273
sled_uuid: uuid::Uuid::new_v4(),
274+
ncpus: InstanceCpuCount(2),
275+
memory: ByteCount::from_mebibytes_u32(512),
276+
hostname: "myvm".to_string(),
275277
gen: Generation::new(),
276278
time_updated: Utc::now(),
277279
})

omicron-sled-agent/src/instance.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,14 @@ impl Instance {
281281
// NOTE: Mostly lies.
282282
properties: propolis_client::api::InstanceProperties {
283283
id,
284-
name: "Test instance".to_string(),
284+
name: initial_runtime.hostname.clone(),
285285
description: "Test description".to_string(),
286286
image_id: Uuid::nil(),
287287
bootrom_id: Uuid::nil(),
288-
memory: 256,
289-
vcpus: 2,
288+
memory: initial_runtime.memory.to_bytes(),
289+
// TODO: we should probably make propolis aligned with
290+
// InstanceCpuCount here, to avoid any casting...
291+
vcpus: initial_runtime.ncpus.0 as u8,
290292
},
291293
state: InstanceStates::new(initial_runtime),
292294
nexus_client,
@@ -477,7 +479,9 @@ mod test {
477479
RequestContext, TypedBody,
478480
};
479481
use futures::future::FutureExt;
480-
use omicron_common::api::external::{Generation, InstanceState};
482+
use omicron_common::api::external::{
483+
ByteCount, Generation, InstanceCpuCount, InstanceState,
484+
};
481485
use omicron_common::api::internal::{
482486
nexus::InstanceRuntimeState, sled_agent::InstanceStateRequested,
483487
};
@@ -808,6 +812,9 @@ mod test {
808812
InstanceRuntimeState {
809813
run_state: InstanceState::Creating,
810814
sled_uuid: Uuid::new_v4(),
815+
ncpus: InstanceCpuCount(2),
816+
memory: ByteCount::from_mebibytes_u32(512),
817+
hostname: "myvm".to_string(),
811818
gen: Generation::new(),
812819
time_updated: Utc::now(),
813820
}

omicron-sled-agent/src/instance_manager.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ mod test {
198198
use crate::instance::MockInstance;
199199
use crate::mocks::MockNexusClient;
200200
use chrono::Utc;
201-
use omicron_common::api::external::{Generation, InstanceState};
201+
use omicron_common::api::external::{
202+
ByteCount, Generation, InstanceCpuCount, InstanceState,
203+
};
202204
use omicron_common::api::internal::{
203205
nexus::InstanceRuntimeState, sled_agent::InstanceStateRequested,
204206
};
@@ -221,6 +223,9 @@ mod test {
221223
InstanceRuntimeState {
222224
run_state: InstanceState::Creating,
223225
sled_uuid: Uuid::new_v4(),
226+
ncpus: InstanceCpuCount(2),
227+
memory: ByteCount::from_mebibytes_u32(512),
228+
hostname: "myvm".to_string(),
224229
gen: Generation::new(),
225230
time_updated: Utc::now(),
226231
}

omicron-sled-agent/src/sim/collection.rs

+5
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,11 @@ mod test {
336336
use chrono::Utc;
337337
use dropshot::test_util::LogContext;
338338
use futures::channel::mpsc::Receiver;
339+
use omicron_common::api::external::ByteCount;
339340
use omicron_common::api::external::DiskState;
340341
use omicron_common::api::external::Error;
341342
use omicron_common::api::external::Generation;
343+
use omicron_common::api::external::InstanceCpuCount;
342344
use omicron_common::api::external::InstanceState;
343345
use omicron_common::api::internal::nexus::DiskRuntimeState;
344346
use omicron_common::api::internal::nexus::InstanceRuntimeState;
@@ -354,6 +356,9 @@ mod test {
354356
InstanceRuntimeState {
355357
run_state: InstanceState::Creating,
356358
sled_uuid: uuid::Uuid::new_v4(),
359+
ncpus: InstanceCpuCount(2),
360+
memory: ByteCount::from_mebibytes_u32(512),
361+
hostname: "myvm".to_string(),
357362
gen: Generation::new(),
358363
time_updated: Utc::now(),
359364
}

0 commit comments

Comments
 (0)