Skip to content

Commit 3b51608

Browse files
authored
move VMM types from omicron-common to sled-agent-types-versions (#10302)
As described in #10290, the types in the sled-agent API that represent VMM states are currently defined in the `omicron-common` crate, rather than `sled-agent-types-versions`. This is problematic, as it is essentially equivalent to saying that these types can never be changed. The reason for this (also described in #10290) is that these types presently appear in both the `sled-agent` API and the `nexus-internal` API, the latter of which is client-side versioned. The appearance of these types in the client-side-versioned API is an issue, as they cannot easily be changed, since client-side versioned APIs are not currently handled by the API versioning tools. Thus, #10290 proposes that we decouple this mess by removing `cpapi_instances_put`, the nexus-internal API that currently uses the types also appearing in the sled-agent API. To do this, we must first move these types into the `sled-agent-types-versions` crate so that they can participate in versioning. This PR does that. Most code which references these types now gets them from `sled-agent-types`. The exception is the Nexus-Internal API itself, which, as previously mentioned, is client-side versioned, and must explicitly depend on the `v1` version of `SledVmmState` forever (which, again, is why we are gonna get rid of it entirely). I did *not* make the behavioral change described in #10290 (where Nexus would ignore the `SledVmmState` body sent to `cpapi_instances_put` and instead treat it as the doorbell API that will eventually replace it). Since this PR ends up touching so many files just to rename the types, I didn't want to make the behavioral changes here, or add the new nexus-internal version, because I think those deserve to be separate commits. These will come later.
1 parent aa13f77 commit 3b51608

44 files changed

Lines changed: 370 additions & 440 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clients/nexus-client/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ reqwest = { workspace = true, features = ["rustls", "stream"] }
2222
schemars.workspace = true
2323
serde.workspace = true
2424
serde_json.workspace = true
25+
sled-agent-types-versions.workspace = true
2526
sled-agent-types.workspace = true
2627
slog.workspace = true
2728
uuid.workspace = true

clients/nexus-client/src/lib.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ impl From<types::DiskState> for omicron_common::api::external::DiskState {
7272
}
7373
}
7474

75-
impl From<omicron_common::api::internal::nexus::VmmState> for types::VmmState {
76-
fn from(s: omicron_common::api::internal::nexus::VmmState) -> Self {
77-
use omicron_common::api::internal::nexus::VmmState as Input;
75+
impl From<sled_agent_types_versions::v1::instance::VmmState>
76+
for types::VmmState
77+
{
78+
fn from(s: sled_agent_types_versions::v1::instance::VmmState) -> Self {
79+
use sled_agent_types_versions::v1::instance::VmmState as Input;
7880
match s {
7981
Input::Starting => types::VmmState::Starting,
8082
Input::Running => types::VmmState::Running,
@@ -88,9 +90,11 @@ impl From<omicron_common::api::internal::nexus::VmmState> for types::VmmState {
8890
}
8991
}
9092

91-
impl From<types::VmmState> for omicron_common::api::internal::nexus::VmmState {
93+
impl From<types::VmmState>
94+
for sled_agent_types_versions::v1::instance::VmmState
95+
{
9296
fn from(s: types::VmmState) -> Self {
93-
use omicron_common::api::internal::nexus::VmmState as Output;
97+
use sled_agent_types_versions::v1::instance::VmmState as Output;
9498
match s {
9599
types::VmmState::Starting => Output::Starting,
96100
types::VmmState::Running => Output::Running,
@@ -104,10 +108,12 @@ impl From<types::VmmState> for omicron_common::api::internal::nexus::VmmState {
104108
}
105109
}
106110

107-
impl From<omicron_common::api::internal::nexus::VmmRuntimeState>
111+
impl From<sled_agent_types_versions::v1::instance::VmmRuntimeState>
108112
for types::VmmRuntimeState
109113
{
110-
fn from(s: omicron_common::api::internal::nexus::VmmRuntimeState) -> Self {
114+
fn from(
115+
s: sled_agent_types_versions::v1::instance::VmmRuntimeState,
116+
) -> Self {
111117
Self {
112118
gen_: s.generation,
113119
state: s.state.into(),
@@ -116,10 +122,10 @@ impl From<omicron_common::api::internal::nexus::VmmRuntimeState>
116122
}
117123
}
118124

119-
impl From<omicron_common::api::internal::nexus::SledVmmState>
125+
impl From<sled_agent_types_versions::v1::instance::SledVmmState>
120126
for types::SledVmmState
121127
{
122-
fn from(s: omicron_common::api::internal::nexus::SledVmmState) -> Self {
128+
fn from(s: sled_agent_types_versions::v1::instance::SledVmmState) -> Self {
123129
Self {
124130
vmm_state: s.vmm_state.into(),
125131
migration_in: s.migration_in.map(Into::into),
@@ -128,11 +134,11 @@ impl From<omicron_common::api::internal::nexus::SledVmmState>
128134
}
129135
}
130136

131-
impl From<omicron_common::api::internal::nexus::MigrationRuntimeState>
137+
impl From<sled_agent_types_versions::v1::instance::MigrationRuntimeState>
132138
for types::MigrationRuntimeState
133139
{
134140
fn from(
135-
s: omicron_common::api::internal::nexus::MigrationRuntimeState,
141+
s: sled_agent_types_versions::v1::instance::MigrationRuntimeState,
136142
) -> Self {
137143
Self {
138144
migration_id: s.migration_id,
@@ -143,11 +149,13 @@ impl From<omicron_common::api::internal::nexus::MigrationRuntimeState>
143149
}
144150
}
145151

146-
impl From<omicron_common::api::internal::nexus::MigrationState>
152+
impl From<sled_agent_types_versions::v1::instance::MigrationState>
147153
for types::MigrationState
148154
{
149-
fn from(s: omicron_common::api::internal::nexus::MigrationState) -> Self {
150-
use omicron_common::api::internal::nexus::MigrationState as Input;
155+
fn from(
156+
s: sled_agent_types_versions::v1::instance::MigrationState,
157+
) -> Self {
158+
use sled_agent_types_versions::v1::instance::MigrationState as Input;
151159
match s {
152160
Input::Pending => Self::Pending,
153161
Input::InProgress => Self::InProgress,

clients/sled-agent-client/src/lib.rs

Lines changed: 5 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ progenitor::generate_api!(
7373
MaxPathConfig = sled_agent_types_versions::latest::early_networking::MaxPathConfig,
7474
Measurement = sled_agent_types_versions::latest::rot::Measurement,
7575
MeasurementLog = sled_agent_types_versions::latest::rot::MeasurementLog,
76+
MigrationRuntimeState = sled_agent_types_versions::latest::instance::MigrationRuntimeState,
77+
MigrationState = sled_agent_types_versions::latest::instance::MigrationState,
7678
MupdateOverrideBootInventory = sled_agent_types_versions::latest::inventory::MupdateOverrideBootInventory,
7779
Name = omicron_common::api::external::Name,
7880
NetworkInterface = sled_agent_types_versions::latest::inventory::NetworkInterface,
@@ -103,12 +105,15 @@ progenitor::generate_api!(
103105
RouterVersion = omicron_common::api::internal::shared::RouterVersion,
104106
Sha3_256Digest = sled_agent_types_versions::latest::rot::Sha3_256Digest,
105107
SledRole = sled_agent_types_versions::latest::inventory::SledRole,
108+
SledVmmState = sled_agent_types_versions::latest::instance::SledVmmState,
106109
SourceNatConfigGeneric = sled_agent_types_versions::latest::inventory::SourceNatConfigGeneric,
107110
SwitchSlot = sled_agent_types_versions::latest::early_networking::SwitchSlot,
108111
SystemNetworkingConfig = sled_agent_types_versions::latest::system_networking::SystemNetworkingConfig,
109112
Threshold = trust_quorum_types::types::Threshold,
110113
TxEqConfig = sled_agent_types_versions::latest::early_networking::TxEqConfig,
111114
UplinkAddressConfig = sled_agent_types_versions::latest::early_networking::UplinkAddressConfig,
115+
VmmRuntimeState = sled_agent_types_versions::latest::instance::VmmRuntimeState,
116+
VmmState = sled_agent_types_versions::latest::instance::VmmState,
112117
Vni = omicron_common::api::external::Vni,
113118
VpcFirewallIcmpFilter = omicron_common::api::external::VpcFirewallIcmpFilter,
114119
WriteNetworkConfigRequest = sled_agent_types_versions::latest::system_networking::WriteNetworkConfigRequest,
@@ -123,89 +128,6 @@ impl omicron_common::api::external::ClientError for types::Error {
123128
}
124129
}
125130

126-
impl From<omicron_common::api::internal::nexus::VmmState> for types::VmmState {
127-
fn from(s: omicron_common::api::internal::nexus::VmmState) -> Self {
128-
use omicron_common::api::internal::nexus::VmmState as Input;
129-
match s {
130-
Input::Starting => types::VmmState::Starting,
131-
Input::Running => types::VmmState::Running,
132-
Input::Stopping => types::VmmState::Stopping,
133-
Input::Stopped => types::VmmState::Stopped,
134-
Input::Rebooting => types::VmmState::Rebooting,
135-
Input::Migrating => types::VmmState::Migrating,
136-
Input::Failed => types::VmmState::Failed,
137-
Input::Destroyed => types::VmmState::Destroyed,
138-
}
139-
}
140-
}
141-
142-
impl From<types::VmmState> for omicron_common::api::internal::nexus::VmmState {
143-
fn from(s: types::VmmState) -> Self {
144-
use omicron_common::api::internal::nexus::VmmState as Output;
145-
match s {
146-
types::VmmState::Starting => Output::Starting,
147-
types::VmmState::Running => Output::Running,
148-
types::VmmState::Stopping => Output::Stopping,
149-
types::VmmState::Stopped => Output::Stopped,
150-
types::VmmState::Rebooting => Output::Rebooting,
151-
types::VmmState::Migrating => Output::Migrating,
152-
types::VmmState::Failed => Output::Failed,
153-
types::VmmState::Destroyed => Output::Destroyed,
154-
}
155-
}
156-
}
157-
158-
impl From<types::VmmRuntimeState>
159-
for omicron_common::api::internal::nexus::VmmRuntimeState
160-
{
161-
fn from(s: types::VmmRuntimeState) -> Self {
162-
Self {
163-
state: s.state.into(),
164-
generation: s.gen_,
165-
time_updated: s.time_updated,
166-
}
167-
}
168-
}
169-
170-
impl From<types::SledVmmState>
171-
for omicron_common::api::internal::nexus::SledVmmState
172-
{
173-
fn from(s: types::SledVmmState) -> Self {
174-
Self {
175-
vmm_state: s.vmm_state.into(),
176-
migration_in: s.migration_in.map(Into::into),
177-
migration_out: s.migration_out.map(Into::into),
178-
}
179-
}
180-
}
181-
182-
impl From<types::MigrationRuntimeState>
183-
for omicron_common::api::internal::nexus::MigrationRuntimeState
184-
{
185-
fn from(s: types::MigrationRuntimeState) -> Self {
186-
Self {
187-
migration_id: s.migration_id,
188-
state: s.state.into(),
189-
generation: s.gen_,
190-
time_updated: s.time_updated,
191-
}
192-
}
193-
}
194-
195-
impl From<types::MigrationState>
196-
for omicron_common::api::internal::nexus::MigrationState
197-
{
198-
fn from(s: types::MigrationState) -> Self {
199-
use omicron_common::api::internal::nexus::MigrationState as Output;
200-
match s {
201-
types::MigrationState::Pending => Output::Pending,
202-
types::MigrationState::InProgress => Output::InProgress,
203-
types::MigrationState::Failed => Output::Failed,
204-
types::MigrationState::Completed => Output::Completed,
205-
}
206-
}
207-
}
208-
209131
impl From<omicron_common::api::external::L4PortRange> for types::L4PortRange {
210132
fn from(s: omicron_common::api::external::L4PortRange) -> Self {
211133
Self::try_from(s.to_string()).unwrap_or_else(|e| panic!("{}: {}", s, e))

common/src/api/external/mod.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,22 +1095,6 @@ pub enum InstanceState {
10951095
Destroyed,
10961096
}
10971097

1098-
impl From<crate::api::internal::nexus::VmmState> for InstanceState {
1099-
fn from(state: crate::api::internal::nexus::VmmState) -> Self {
1100-
use crate::api::internal::nexus::VmmState as InternalVmmState;
1101-
match state {
1102-
InternalVmmState::Starting => Self::Starting,
1103-
InternalVmmState::Running => Self::Running,
1104-
InternalVmmState::Stopping => Self::Stopping,
1105-
InternalVmmState::Stopped => Self::Stopped,
1106-
InternalVmmState::Rebooting => Self::Rebooting,
1107-
InternalVmmState::Migrating => Self::Migrating,
1108-
InternalVmmState::Failed => Self::Failed,
1109-
InternalVmmState::Destroyed => Self::Destroyed,
1110-
}
1111-
}
1112-
}
1113-
11141098
impl Display for InstanceState {
11151099
fn fmt(&self, f: &mut Formatter) -> FormatResult {
11161100
write!(f, "{}", self.label())

0 commit comments

Comments
 (0)