-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathlib.rs
More file actions
471 lines (440 loc) · 18 KB
/
lib.rs
File metadata and controls
471 lines (440 loc) · 18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//! Interface for making API requests to a Sled Agent
use async_trait::async_trait;
use omicron_uuid_kinds::PropolisUuid;
use schemars::JsonSchema;
use serde::Deserialize;
use serde::Serialize;
use std::convert::TryFrom;
use uuid::Uuid;
pub use propolis_client::{CrucibleOpts, VolumeConstructionRequest};
progenitor::generate_api!(
spec = "../../openapi/sled-agent/sled-agent-latest.json",
interface = Positional,
inner_type = slog::Logger,
pre_hook = (|log: &slog::Logger, request: &reqwest::Request| {
slog::debug!(log, "client request";
"method" => %request.method(),
"uri" => %request.url(),
"body" => ?&request.body(),
);
}),
post_hook = (|log: &slog::Logger, result: &Result<_, _>| {
slog::debug!(log, "client response"; "result" => ?result);
}),
derives = [schemars::JsonSchema, PartialEq],
patch = {
BfdPeerConfig = { derives = [Eq, Hash] },
BgpConfig = { derives = [Eq, Hash] },
BgpPeerConfig = { derives = [Eq, Hash] },
MaxPathConfig = { derives = [Eq, Hash] },
LldpPortConfig = { derives = [Eq, Hash, PartialOrd, Ord] },
TxEqConfig = { derives = [Eq, Hash] },
OmicronPhysicalDiskConfig = { derives = [Eq, Hash, PartialOrd, Ord] },
PortConfig = { derives = [Eq, Hash] },
RouteConfig = { derives = [Eq, Hash] },
RouterLifetimeConfig = { derives = [Eq, Hash] },
UplinkAddressConfig = { derives = [Eq, Hash] },
VirtualNetworkInterfaceHost = { derives = [Eq, Hash] },
},
crates = {
"omicron-uuid-kinds" = "*",
"oxnet" = "0.1.0",
},
replace = {
Attestation = sled_agent_types_versions::latest::rot::Attestation,
Baseboard = sled_agent_types_versions::latest::inventory::Baseboard,
BaseboardId = sled_hardware_types::BaseboardId,
ByteCount = omicron_common::api::external::ByteCount,
CertificateChain = sled_agent_types_versions::latest::rot::CertificateChain,
CommitRequest = trust_quorum_types::messages::CommitRequest,
CommitStatus = trust_quorum_types::status::CommitStatus,
CoordinatorStatus = trust_quorum_types::status::CoordinatorStatus,
DatasetsConfig = omicron_common::disk::DatasetsConfig,
DatasetManagementStatus = omicron_common::disk::DatasetManagementStatus,
DatasetKind = omicron_common::api::internal::shared::DatasetKind,
DiskIdentity = omicron_common::disk::DiskIdentity,
DiskManagementStatus = omicron_common::disk::DiskManagementStatus,
DiskManagementError = omicron_common::disk::DiskManagementError,
DiskVariant = omicron_common::disk::DiskVariant,
Epoch = trust_quorum_types::types::Epoch,
ExternalIpGatewayMap = omicron_common::api::internal::shared::ExternalIpGatewayMap,
ExternalIpConfig = omicron_common::api::internal::shared::ExternalIpConfig,
ExternalIpv4Config = omicron_common::api::internal::shared::ExternalIpv4Config,
ExternalIpv6Config = omicron_common::api::internal::shared::ExternalIpv6Config,
Generation = omicron_common::api::external::Generation,
Hostname = omicron_common::api::external::Hostname,
ImportExportPolicy = omicron_common::api::external::ImportExportPolicy,
Inventory = sled_agent_types_versions::latest::inventory::Inventory,
InventoryDisk = sled_agent_types_versions::latest::inventory::InventoryDisk,
InventoryZpool = sled_agent_types_versions::latest::inventory::InventoryZpool,
LrtqUpgradeMsg = trust_quorum_types::messages::LrtqUpgradeMsg,
MacAddr = omicron_common::api::external::MacAddr,
Measurement = sled_agent_types_versions::latest::rot::Measurement,
MeasurementLog = sled_agent_types_versions::latest::rot::MeasurementLog,
MupdateOverrideBootInventory = sled_agent_types_versions::latest::inventory::MupdateOverrideBootInventory,
Name = omicron_common::api::external::Name,
NetworkInterface = omicron_common::api::internal::shared::NetworkInterface,
Nonce = sled_agent_types_versions::latest::rot::Nonce,
OmicronPhysicalDiskConfig = omicron_common::disk::OmicronPhysicalDiskConfig,
OmicronPhysicalDisksConfig = omicron_common::disk::OmicronPhysicalDisksConfig,
OmicronSledConfig = sled_agent_types_versions::latest::inventory::OmicronSledConfig,
OmicronZoneConfig = sled_agent_types_versions::latest::inventory::OmicronZoneConfig,
OmicronZoneDataset = sled_agent_types_versions::latest::inventory::OmicronZoneDataset,
OmicronZoneImageSource = sled_agent_types_versions::latest::inventory::OmicronZoneImageSource,
OmicronZoneType = sled_agent_types_versions::latest::inventory::OmicronZoneType,
OmicronZonesConfig = sled_agent_types_versions::latest::inventory::OmicronZonesConfig,
PortFec = omicron_common::api::internal::shared::PortFec,
PortSpeed = omicron_common::api::internal::shared::PortSpeed,
PrepareAndCommitRequest = trust_quorum_types::messages::PrepareAndCommitRequest,
ReconfigureMsg = trust_quorum_types::messages::ReconfigureMsg,
ResolvedVpcFirewallRule = omicron_common::api::internal::shared::ResolvedVpcFirewallRule,
ResolvedVpcRoute = omicron_common::api::internal::shared::ResolvedVpcRoute,
ResolvedVpcRouteSet = omicron_common::api::internal::shared::ResolvedVpcRouteSet,
Rot = sled_agent_types_versions::latest::rot::Rot,
RouterId = omicron_common::api::internal::shared::RouterId,
RouterTarget = omicron_common::api::internal::shared::RouterTarget,
RouterVersion = omicron_common::api::internal::shared::RouterVersion,
Sha3_256Digest = sled_agent_types_versions::latest::rot::Sha3_256Digest,
SledRole = sled_agent_types_versions::latest::inventory::SledRole,
SourceNatConfigGeneric = omicron_common::api::internal::shared::SourceNatConfigGeneric,
SwitchLocation = omicron_common::api::external::SwitchLocation,
Threshold = trust_quorum_types::types::Threshold,
Vni = omicron_common::api::external::Vni,
VpcFirewallIcmpFilter = omicron_common::api::external::VpcFirewallIcmpFilter,
ZpoolKind = omicron_common::zpool_name::ZpoolKind,
ZpoolName = omicron_common::zpool_name::ZpoolName,
}
);
impl omicron_common::api::external::ClientError for types::Error {
fn message(&self) -> String {
self.message.clone()
}
}
impl From<omicron_common::api::internal::nexus::VmmState> for types::VmmState {
fn from(s: omicron_common::api::internal::nexus::VmmState) -> Self {
use omicron_common::api::internal::nexus::VmmState as Input;
match s {
Input::Starting => types::VmmState::Starting,
Input::Running => types::VmmState::Running,
Input::Stopping => types::VmmState::Stopping,
Input::Stopped => types::VmmState::Stopped,
Input::Rebooting => types::VmmState::Rebooting,
Input::Migrating => types::VmmState::Migrating,
Input::Failed => types::VmmState::Failed,
Input::Destroyed => types::VmmState::Destroyed,
}
}
}
impl From<types::VmmState> for omicron_common::api::internal::nexus::VmmState {
fn from(s: types::VmmState) -> Self {
use omicron_common::api::internal::nexus::VmmState as Output;
match s {
types::VmmState::Starting => Output::Starting,
types::VmmState::Running => Output::Running,
types::VmmState::Stopping => Output::Stopping,
types::VmmState::Stopped => Output::Stopped,
types::VmmState::Rebooting => Output::Rebooting,
types::VmmState::Migrating => Output::Migrating,
types::VmmState::Failed => Output::Failed,
types::VmmState::Destroyed => Output::Destroyed,
}
}
}
impl From<types::VmmRuntimeState>
for omicron_common::api::internal::nexus::VmmRuntimeState
{
fn from(s: types::VmmRuntimeState) -> Self {
Self {
state: s.state.into(),
generation: s.r#gen,
time_updated: s.time_updated,
}
}
}
impl From<types::SledVmmState>
for omicron_common::api::internal::nexus::SledVmmState
{
fn from(s: types::SledVmmState) -> Self {
Self {
vmm_state: s.vmm_state.into(),
migration_in: s.migration_in.map(Into::into),
migration_out: s.migration_out.map(Into::into),
}
}
}
impl From<types::MigrationRuntimeState>
for omicron_common::api::internal::nexus::MigrationRuntimeState
{
fn from(s: types::MigrationRuntimeState) -> Self {
Self {
migration_id: s.migration_id,
state: s.state.into(),
generation: s.r#gen,
time_updated: s.time_updated,
}
}
}
impl From<types::MigrationState>
for omicron_common::api::internal::nexus::MigrationState
{
fn from(s: types::MigrationState) -> Self {
use omicron_common::api::internal::nexus::MigrationState as Output;
match s {
types::MigrationState::Pending => Output::Pending,
types::MigrationState::InProgress => Output::InProgress,
types::MigrationState::Failed => Output::Failed,
types::MigrationState::Completed => Output::Completed,
}
}
}
impl From<omicron_common::api::internal::nexus::DiskRuntimeState>
for types::DiskRuntimeState
{
fn from(s: omicron_common::api::internal::nexus::DiskRuntimeState) -> Self {
Self {
disk_state: s.disk_state.into(),
r#gen: s.generation,
time_updated: s.time_updated,
}
}
}
impl From<omicron_common::api::external::DiskState> for types::DiskState {
fn from(s: omicron_common::api::external::DiskState) -> Self {
use omicron_common::api::external::DiskState::*;
match s {
Creating => Self::Creating,
Detached => Self::Detached,
ImportReady => Self::ImportReady,
ImportingFromUrl => Self::ImportingFromUrl,
ImportingFromBulkWrites => Self::ImportingFromBulkWrites,
Finalizing => Self::Finalizing,
Maintenance => Self::Maintenance,
Attaching(u) => Self::Attaching(u),
Attached(u) => Self::Attached(u),
Detaching(u) => Self::Detaching(u),
Destroyed => Self::Destroyed,
Faulted => Self::Faulted,
}
}
}
impl From<types::DiskRuntimeState>
for omicron_common::api::internal::nexus::DiskRuntimeState
{
fn from(s: types::DiskRuntimeState) -> Self {
Self {
disk_state: s.disk_state.into(),
generation: s.r#gen,
time_updated: s.time_updated,
}
}
}
impl From<types::DiskState> for omicron_common::api::external::DiskState {
fn from(s: types::DiskState) -> Self {
use types::DiskState::*;
match s {
Creating => Self::Creating,
Detached => Self::Detached,
ImportReady => Self::ImportReady,
ImportingFromUrl => Self::ImportingFromUrl,
ImportingFromBulkWrites => Self::ImportingFromBulkWrites,
Finalizing => Self::Finalizing,
Maintenance => Self::Maintenance,
Attaching(u) => Self::Attaching(u),
Attached(u) => Self::Attached(u),
Detaching(u) => Self::Detaching(u),
Destroyed => Self::Destroyed,
Faulted => Self::Faulted,
}
}
}
impl From<omicron_common::api::external::L4PortRange> for types::L4PortRange {
fn from(s: omicron_common::api::external::L4PortRange) -> Self {
Self::try_from(s.to_string()).unwrap_or_else(|e| panic!("{}: {}", s, e))
}
}
impl From<omicron_common::api::internal::nexus::HostIdentifier>
for types::HostIdentifier
{
fn from(s: omicron_common::api::internal::nexus::HostIdentifier) -> Self {
use omicron_common::api::internal::nexus::HostIdentifier::*;
match s {
Ip(net) => Self::Ip(net),
Vpc(vni) => Self::Vpc(vni),
}
}
}
impl From<omicron_common::api::external::VpcFirewallRuleAction>
for types::VpcFirewallRuleAction
{
fn from(s: omicron_common::api::external::VpcFirewallRuleAction) -> Self {
use omicron_common::api::external::VpcFirewallRuleAction::*;
match s {
Allow => Self::Allow,
Deny => Self::Deny,
}
}
}
impl From<omicron_common::api::external::VpcFirewallRuleDirection>
for types::VpcFirewallRuleDirection
{
fn from(
s: omicron_common::api::external::VpcFirewallRuleDirection,
) -> Self {
use omicron_common::api::external::VpcFirewallRuleDirection::*;
match s {
Inbound => Self::Inbound,
Outbound => Self::Outbound,
}
}
}
impl From<omicron_common::api::external::VpcFirewallRuleStatus>
for types::VpcFirewallRuleStatus
{
fn from(s: omicron_common::api::external::VpcFirewallRuleStatus) -> Self {
use omicron_common::api::external::VpcFirewallRuleStatus::*;
match s {
Enabled => Self::Enabled,
Disabled => Self::Disabled,
}
}
}
impl From<omicron_common::api::external::VpcFirewallRuleProtocol>
for types::VpcFirewallRuleProtocol
{
fn from(s: omicron_common::api::external::VpcFirewallRuleProtocol) -> Self {
use omicron_common::api::external::VpcFirewallRuleProtocol::*;
match s {
Tcp => Self::Tcp,
Udp => Self::Udp,
Icmp(v) => Self::Icmp(v),
}
}
}
impl From<omicron_common::api::internal::shared::NetworkInterfaceKind>
for types::NetworkInterfaceKind
{
fn from(
s: omicron_common::api::internal::shared::NetworkInterfaceKind,
) -> Self {
use omicron_common::api::internal::shared::NetworkInterfaceKind::*;
match s {
Instance { id } => Self::Instance(id),
Service { id } => Self::Service(id),
Probe { id } => Self::Probe(id),
}
}
}
// TODO-cleanup This is icky; can we move these methods to a separate client so
// we don't need to add this header by hand?
// https://github.com/oxidecomputer/omicron/issues/8900
trait ApiVersionHeader {
fn api_version_header(self, api_version: &'static str) -> Self;
}
impl ApiVersionHeader for reqwest::RequestBuilder {
fn api_version_header(self, api_version: &'static str) -> Self {
self.header("api-version", api_version)
}
}
/// Exposes additional [`Client`] interfaces for use by the test suite. These
/// are bonus endpoints, not generated in the real client.
#[async_trait]
pub trait TestInterfaces {
async fn vmm_single_step(&self, id: PropolisUuid);
async fn vmm_finish_transition(&self, id: PropolisUuid);
/// Essentially like `vmm_finish_transition`, but returns an error instead
/// of panicking if the request fails. Useful when the VMM may have been
/// removed.
async fn try_vmm_finish_transition(
&self,
id: PropolisUuid,
) -> Result<(), reqwest::Error>;
async fn vmm_simulate_migration_source(
&self,
id: PropolisUuid,
params: SimulateMigrationSource,
);
async fn disk_finish_transition(&self, id: Uuid);
}
#[async_trait]
impl TestInterfaces for Client {
async fn vmm_single_step(&self, id: PropolisUuid) {
let baseurl = self.baseurl();
let client = self.client();
let url = format!("{}/vmms/{}/poke-single-step", baseurl, id);
client
.post(url)
.api_version_header(self.api_version())
.send()
.await
.expect("instance_single_step() failed unexpectedly");
}
async fn vmm_finish_transition(&self, id: PropolisUuid) {
self.try_vmm_finish_transition(id)
.await
.expect("instance_finish_transition() failed unexpectedly");
}
async fn try_vmm_finish_transition(
&self,
id: PropolisUuid,
) -> Result<(), reqwest::Error> {
let baseurl = self.baseurl();
let client = self.client();
let url = format!("{}/vmms/{}/poke", baseurl, id);
client.post(url).api_version_header(self.api_version()).send().await?;
Ok(())
}
async fn disk_finish_transition(&self, id: Uuid) {
let baseurl = self.baseurl();
let client = self.client();
let url = format!("{}/disks/{}/poke", baseurl, id);
client
.post(url)
.api_version_header(self.api_version())
.send()
.await
.expect("disk_finish_transition() failed unexpectedly");
}
async fn vmm_simulate_migration_source(
&self,
id: PropolisUuid,
params: SimulateMigrationSource,
) {
let baseurl = self.baseurl();
let client = self.client();
let url = format!("{baseurl}/vmms/{id}/sim-migration-source");
client
.post(url)
.api_version_header(self.api_version())
.json(¶ms)
.send()
.await
.expect("instance_simulate_migration_source() failed unexpectedly");
}
}
/// Parameters to the `/instances/{id}/sim-migration-source` test API.
///
/// This message type is not included in the OpenAPI spec, because this API
/// exists only in test builds.
#[derive(Serialize, Deserialize, JsonSchema)]
pub struct SimulateMigrationSource {
/// The ID of the migration out of the instance's current active VMM.
pub migration_id: Uuid,
/// What migration result (success or failure) to simulate.
pub result: SimulatedMigrationResult,
}
/// The result of a simulated migration out from an instance's current active
/// VMM.
#[derive(Serialize, Deserialize, JsonSchema)]
pub enum SimulatedMigrationResult {
/// Simulate a successful migration out.
Success,
/// Simulate a failed migration out.
///
/// # Note
///
/// This is not currently implemented by the simulated sled-agent.
Failure,
}