-
Notifications
You must be signed in to change notification settings - Fork 39
/
http_entrypoints.rs
730 lines (657 loc) · 25.3 KB
/
http_entrypoints.rs
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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
// 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/.
//! HTTP entrypoint functions for the sled agent's exposed API
use super::sled_agent::SledAgent;
use crate::sled_agent::Error as SledAgentError;
use crate::zone_bundle::BundleError;
use bootstore::schemes::v0::NetworkConfig;
use camino::Utf8PathBuf;
use display_error_chain::DisplayErrorChain;
use dropshot::{
ApiDescription, Body, FreeformBody, HttpError, HttpResponseCreated,
HttpResponseDeleted, HttpResponseHeaders, HttpResponseOk,
HttpResponseUpdatedNoContent, Path, Query, RequestContext, StreamingBody,
TypedBody,
};
use nexus_sled_agent_shared::inventory::{
Inventory, OmicronZonesConfig, SledRole,
};
use omicron_common::api::external::Error;
use omicron_common::api::internal::nexus::{
DiskRuntimeState, SledVmmState, UpdateArtifactId,
};
use omicron_common::api::internal::shared::{
ExternalIpGatewayMap, ResolvedVpcRouteSet, ResolvedVpcRouteState,
SledIdentifiers, SwitchPorts, VirtualNetworkInterfaceHost,
};
use omicron_common::disk::{
DatasetsConfig, DatasetsManagementResult, DiskVariant,
DisksManagementResult, M2Slot, OmicronPhysicalDisksConfig,
};
use sled_agent_api::*;
use sled_agent_types::boot_disk::{
BootDiskOsWriteStatus, BootDiskPathParams, BootDiskUpdatePathParams,
BootDiskWriteStartQueryParams,
};
use sled_agent_types::bootstore::BootstoreStatus;
use sled_agent_types::disk::DiskEnsureBody;
use sled_agent_types::early_networking::EarlyNetworkConfig;
use sled_agent_types::firewall_rules::VpcFirewallRulesEnsureBody;
use sled_agent_types::instance::{
InstanceEnsureBody, InstanceExternalIpBody, VmmPutStateBody,
VmmPutStateResponse, VmmUnregisterResponse,
};
use sled_agent_types::sled::AddSledRequest;
use sled_agent_types::time_sync::TimeSync;
use sled_agent_types::zone_bundle::{
BundleUtilization, CleanupContext, CleanupCount, CleanupPeriod,
StorageLimit, ZoneBundleId, ZoneBundleMetadata,
};
use std::collections::BTreeMap;
type SledApiDescription = ApiDescription<SledAgent>;
/// Returns a description of the sled agent API
pub fn api() -> SledApiDescription {
sled_agent_api_mod::api_description::<SledAgentImpl>()
.expect("registered entrypoints")
}
enum SledAgentImpl {}
impl SledAgentApi for SledAgentImpl {
type Context = SledAgent;
async fn zone_bundle_list_all(
rqctx: RequestContext<Self::Context>,
query: Query<ZoneBundleFilter>,
) -> Result<HttpResponseOk<Vec<ZoneBundleMetadata>>, HttpError> {
let sa = rqctx.context();
let filter = query.into_inner().filter;
sa.list_all_zone_bundles(filter.as_deref())
.await
.map(HttpResponseOk)
.map_err(HttpError::from)
}
async fn zone_bundle_list(
rqctx: RequestContext<Self::Context>,
params: Path<ZonePathParam>,
) -> Result<HttpResponseOk<Vec<ZoneBundleMetadata>>, HttpError> {
let params = params.into_inner();
let zone_name = params.zone_name;
let sa = rqctx.context();
sa.list_zone_bundles(&zone_name)
.await
.map(HttpResponseOk)
.map_err(HttpError::from)
}
async fn zone_bundle_create(
rqctx: RequestContext<Self::Context>,
params: Path<ZonePathParam>,
) -> Result<HttpResponseCreated<ZoneBundleMetadata>, HttpError> {
let params = params.into_inner();
let zone_name = params.zone_name;
let sa = rqctx.context();
sa.create_zone_bundle(&zone_name)
.await
.map(HttpResponseCreated)
.map_err(HttpError::from)
}
async fn zone_bundle_get(
rqctx: RequestContext<Self::Context>,
params: Path<ZoneBundleId>,
) -> Result<HttpResponseHeaders<HttpResponseOk<FreeformBody>>, HttpError>
{
let params = params.into_inner();
let zone_name = params.zone_name;
let bundle_id = params.bundle_id;
let sa = rqctx.context();
let Some(path) = sa
.get_zone_bundle_paths(&zone_name, &bundle_id)
.await
.map_err(HttpError::from)?
.into_iter()
.next()
else {
return Err(HttpError::for_not_found(
None,
format!(
"No zone bundle for zone '{}' with ID '{}'",
zone_name, bundle_id
),
));
};
let f = tokio::fs::File::open(&path).await.map_err(|e| {
HttpError::for_internal_error(format!(
"failed to open zone bundle file at {}: {:?}",
path, e,
))
})?;
let file_access = hyper_staticfile::vfs::TokioFileAccess::new(f);
let file_stream =
hyper_staticfile::util::FileBytesStream::new(file_access);
let body = Body::wrap(hyper_staticfile::Body::Full(file_stream));
let body = FreeformBody(body);
let mut response =
HttpResponseHeaders::new_unnamed(HttpResponseOk(body));
response.headers_mut().append(
http::header::CONTENT_TYPE,
"application/gzip".try_into().unwrap(),
);
Ok(response)
}
async fn zone_bundle_delete(
rqctx: RequestContext<Self::Context>,
params: Path<ZoneBundleId>,
) -> Result<HttpResponseDeleted, HttpError> {
let params = params.into_inner();
let zone_name = params.zone_name;
let bundle_id = params.bundle_id;
let sa = rqctx.context();
let paths = sa
.get_zone_bundle_paths(&zone_name, &bundle_id)
.await
.map_err(HttpError::from)?;
if paths.is_empty() {
return Err(HttpError::for_not_found(
None,
format!(
"No zone bundle for zone '{}' with ID '{}'",
zone_name, bundle_id
),
));
};
for path in paths.into_iter() {
tokio::fs::remove_file(&path).await.map_err(|e| {
HttpError::for_internal_error(format!(
"Failed to delete zone bundle: {e}"
))
})?;
}
Ok(HttpResponseDeleted())
}
async fn zone_bundle_utilization(
rqctx: RequestContext<Self::Context>,
) -> Result<
HttpResponseOk<BTreeMap<Utf8PathBuf, BundleUtilization>>,
HttpError,
> {
let sa = rqctx.context();
sa.zone_bundle_utilization()
.await
.map(HttpResponseOk)
.map_err(HttpError::from)
}
async fn zone_bundle_cleanup_context(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<CleanupContext>, HttpError> {
let sa = rqctx.context();
Ok(HttpResponseOk(sa.zone_bundle_cleanup_context().await))
}
async fn zone_bundle_cleanup_context_update(
rqctx: RequestContext<Self::Context>,
body: TypedBody<CleanupContextUpdate>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let sa = rqctx.context();
let params = body.into_inner();
let new_period =
params.period.map(CleanupPeriod::new).transpose().map_err(|e| {
HttpError::from(SledAgentError::from(BundleError::from(e)))
})?;
let new_priority = params.priority;
let new_limit =
params.storage_limit.map(StorageLimit::new).transpose().map_err(
|e| HttpError::from(SledAgentError::from(BundleError::from(e))),
)?;
sa.update_zone_bundle_cleanup_context(
new_period,
new_limit,
new_priority,
)
.await
.map(|_| HttpResponseUpdatedNoContent())
.map_err(HttpError::from)
}
async fn datasets_put(
rqctx: RequestContext<Self::Context>,
body: TypedBody<DatasetsConfig>,
) -> Result<HttpResponseOk<DatasetsManagementResult>, HttpError> {
let sa = rqctx.context();
let body_args = body.into_inner();
let result = sa.datasets_ensure(body_args).await?;
Ok(HttpResponseOk(result))
}
async fn datasets_get(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<DatasetsConfig>, HttpError> {
let sa = rqctx.context();
Ok(HttpResponseOk(sa.datasets_config_list().await?))
}
async fn zone_bundle_cleanup(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<BTreeMap<Utf8PathBuf, CleanupCount>>, HttpError>
{
let sa = rqctx.context();
sa.zone_bundle_cleanup()
.await
.map(HttpResponseOk)
.map_err(HttpError::from)
}
async fn zones_list(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<Vec<String>>, HttpError> {
let sa = rqctx.context();
sa.zones_list().await.map(HttpResponseOk).map_err(HttpError::from)
}
async fn omicron_zones_put(
rqctx: RequestContext<Self::Context>,
body: TypedBody<OmicronZonesConfig>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let sa = rqctx.context();
let body_args = body.into_inner();
sa.omicron_zones_ensure(body_args).await?;
Ok(HttpResponseUpdatedNoContent())
}
async fn omicron_physical_disks_get(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<OmicronPhysicalDisksConfig>, HttpError> {
let sa = rqctx.context();
Ok(HttpResponseOk(sa.omicron_physical_disks_list().await?))
}
async fn omicron_physical_disks_put(
rqctx: RequestContext<Self::Context>,
body: TypedBody<OmicronPhysicalDisksConfig>,
) -> Result<HttpResponseOk<DisksManagementResult>, HttpError> {
let sa = rqctx.context();
let body_args = body.into_inner();
let result = sa.omicron_physical_disks_ensure(body_args).await?;
Ok(HttpResponseOk(result))
}
async fn zpools_get(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<Vec<Zpool>>, HttpError> {
let sa = rqctx.context();
Ok(HttpResponseOk(sa.zpools_get().await))
}
async fn sled_role_get(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<SledRole>, HttpError> {
let sa = rqctx.context();
Ok(HttpResponseOk(sa.get_role()))
}
async fn cockroachdb_init(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let sa = rqctx.context();
sa.cockroachdb_initialize().await?;
Ok(HttpResponseUpdatedNoContent())
}
async fn vmm_register(
rqctx: RequestContext<Self::Context>,
path_params: Path<VmmPathParam>,
body: TypedBody<InstanceEnsureBody>,
) -> Result<HttpResponseOk<SledVmmState>, HttpError> {
let sa = rqctx.context();
let propolis_id = path_params.into_inner().propolis_id;
let body_args = body.into_inner();
Ok(HttpResponseOk(
sa.instance_ensure_registered(propolis_id, body_args).await?,
))
}
async fn vmm_unregister(
rqctx: RequestContext<Self::Context>,
path_params: Path<VmmPathParam>,
) -> Result<HttpResponseOk<VmmUnregisterResponse>, HttpError> {
let sa = rqctx.context();
let id = path_params.into_inner().propolis_id;
Ok(HttpResponseOk(sa.instance_ensure_unregistered(id).await?))
}
async fn vmm_put_state(
rqctx: RequestContext<Self::Context>,
path_params: Path<VmmPathParam>,
body: TypedBody<VmmPutStateBody>,
) -> Result<HttpResponseOk<VmmPutStateResponse>, HttpError> {
let sa = rqctx.context();
let id = path_params.into_inner().propolis_id;
let body_args = body.into_inner();
Ok(HttpResponseOk(sa.instance_ensure_state(id, body_args.state).await?))
}
async fn vmm_get_state(
rqctx: RequestContext<Self::Context>,
path_params: Path<VmmPathParam>,
) -> Result<HttpResponseOk<SledVmmState>, HttpError> {
let sa = rqctx.context();
let id = path_params.into_inner().propolis_id;
Ok(HttpResponseOk(sa.instance_get_state(id).await?))
}
async fn vmm_put_external_ip(
rqctx: RequestContext<Self::Context>,
path_params: Path<VmmPathParam>,
body: TypedBody<InstanceExternalIpBody>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let sa = rqctx.context();
let id = path_params.into_inner().propolis_id;
let body_args = body.into_inner();
sa.instance_put_external_ip(id, &body_args).await?;
Ok(HttpResponseUpdatedNoContent())
}
async fn vmm_delete_external_ip(
rqctx: RequestContext<Self::Context>,
path_params: Path<VmmPathParam>,
body: TypedBody<InstanceExternalIpBody>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let sa = rqctx.context();
let id = path_params.into_inner().propolis_id;
let body_args = body.into_inner();
sa.instance_delete_external_ip(id, &body_args).await?;
Ok(HttpResponseUpdatedNoContent())
}
async fn disk_put(
rqctx: RequestContext<Self::Context>,
path_params: Path<DiskPathParam>,
body: TypedBody<DiskEnsureBody>,
) -> Result<HttpResponseOk<DiskRuntimeState>, HttpError> {
let sa = rqctx.context();
let disk_id = path_params.into_inner().disk_id;
let body_args = body.into_inner();
Ok(HttpResponseOk(
sa.disk_ensure(
disk_id,
body_args.initial_runtime.clone(),
body_args.target.clone(),
)
.await
.map_err(|e| Error::from(e))?,
))
}
async fn update_artifact(
rqctx: RequestContext<Self::Context>,
artifact: TypedBody<UpdateArtifactId>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let sa = rqctx.context();
sa.update_artifact(artifact.into_inner()).await.map_err(Error::from)?;
Ok(HttpResponseUpdatedNoContent())
}
async fn vmm_issue_disk_snapshot_request(
rqctx: RequestContext<Self::Context>,
path_params: Path<VmmIssueDiskSnapshotRequestPathParam>,
body: TypedBody<VmmIssueDiskSnapshotRequestBody>,
) -> Result<HttpResponseOk<VmmIssueDiskSnapshotRequestResponse>, HttpError>
{
let sa = rqctx.context();
let path_params = path_params.into_inner();
let body = body.into_inner();
sa.vmm_issue_disk_snapshot_request(
path_params.propolis_id,
path_params.disk_id,
body.snapshot_id,
)
.await?;
Ok(HttpResponseOk(VmmIssueDiskSnapshotRequestResponse {
snapshot_id: body.snapshot_id,
}))
}
async fn vpc_firewall_rules_put(
rqctx: RequestContext<Self::Context>,
path_params: Path<VpcPathParam>,
body: TypedBody<VpcFirewallRulesEnsureBody>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let sa = rqctx.context();
let _vpc_id = path_params.into_inner().vpc_id;
let body_args = body.into_inner();
sa.firewall_rules_ensure(body_args.vni, &body_args.rules[..])
.await
.map_err(Error::from)?;
Ok(HttpResponseUpdatedNoContent())
}
async fn set_v2p(
rqctx: RequestContext<Self::Context>,
body: TypedBody<VirtualNetworkInterfaceHost>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let sa = rqctx.context();
let body_args = body.into_inner();
sa.set_virtual_nic_host(&body_args).await.map_err(Error::from)?;
Ok(HttpResponseUpdatedNoContent())
}
async fn del_v2p(
rqctx: RequestContext<Self::Context>,
body: TypedBody<VirtualNetworkInterfaceHost>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let sa = rqctx.context();
let body_args = body.into_inner();
sa.unset_virtual_nic_host(&body_args).await.map_err(Error::from)?;
Ok(HttpResponseUpdatedNoContent())
}
async fn list_v2p(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<Vec<VirtualNetworkInterfaceHost>>, HttpError>
{
let sa = rqctx.context();
let vnics = sa.list_virtual_nics().await.map_err(Error::from)?;
Ok(HttpResponseOk(vnics))
}
async fn timesync_get(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<TimeSync>, HttpError> {
let sa = rqctx.context();
Ok(HttpResponseOk(sa.timesync_get().await.map_err(|e| Error::from(e))?))
}
async fn uplink_ensure(
rqctx: RequestContext<Self::Context>,
body: TypedBody<SwitchPorts>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let sa = rqctx.context();
sa.ensure_scrimlet_host_ports(body.into_inner().uplinks).await?;
Ok(HttpResponseUpdatedNoContent())
}
async fn read_network_bootstore_config_cache(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<EarlyNetworkConfig>, HttpError> {
let sa = rqctx.context();
let bs = sa.bootstore();
let config = bs.get_network_config().await.map_err(|e| {
HttpError::for_internal_error(format!(
"failed to get bootstore: {e}"
))
})?;
let config = match config {
Some(config) => EarlyNetworkConfig::deserialize_bootstore_config(
&rqctx.log, &config,
)
.map_err(|e| {
HttpError::for_internal_error(format!(
"deserialize early network config: {e}"
))
})?,
None => {
return Err(HttpError::for_unavail(
None,
"early network config does not exist yet".into(),
));
}
};
Ok(HttpResponseOk(config))
}
async fn write_network_bootstore_config(
rqctx: RequestContext<Self::Context>,
body: TypedBody<EarlyNetworkConfig>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let sa = rqctx.context();
let bs = sa.bootstore();
let config = body.into_inner();
bs.update_network_config(NetworkConfig::from(config)).await.map_err(
|e| {
HttpError::for_internal_error(format!(
"failed to write updated config to boot store: {e}"
))
},
)?;
Ok(HttpResponseUpdatedNoContent())
}
async fn sled_add(
rqctx: RequestContext<Self::Context>,
body: TypedBody<AddSledRequest>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let sa = rqctx.context();
let request = body.into_inner();
// Perform some minimal validation
if request.start_request.body.use_trust_quorum
&& !request.start_request.body.is_lrtq_learner
{
return Err(HttpError::for_bad_request(
None,
"New sleds must be LRTQ learners if trust quorum is in use"
.to_string(),
));
}
crate::sled_agent::sled_add(
sa.logger().clone(),
sa.sprockets().clone(),
request.sled_id,
request.start_request,
)
.await
.map_err(|e| {
let message = format!("Failed to add sled to rack cluster: {e}");
HttpError {
status_code: http::StatusCode::INTERNAL_SERVER_ERROR,
error_code: None,
external_message: message.clone(),
internal_message: message,
}
})?;
Ok(HttpResponseUpdatedNoContent())
}
async fn host_os_write_start(
request_context: RequestContext<Self::Context>,
path_params: Path<BootDiskPathParams>,
query_params: Query<BootDiskWriteStartQueryParams>,
body: StreamingBody,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let sa = request_context.context();
let boot_disk = path_params.into_inner().boot_disk;
// Find our corresponding disk.
let maybe_disk_path =
sa.storage().get_latest_disks().await.iter_managed().find_map(
|(_identity, disk)| {
// Synthetic disks panic if asked for their `slot()`, so filter
// them out first; additionally, filter out any non-M2 disks.
if disk.is_synthetic() || disk.variant() != DiskVariant::M2
{
return None;
}
// Convert this M2 disk's slot to an M2Slot, and skip any that
// don't match the requested boot_disk.
let Ok(slot) = M2Slot::try_from(disk.slot()) else {
return None;
};
if slot != boot_disk {
return None;
}
let raw_devs_path = true;
Some(disk.boot_image_devfs_path(raw_devs_path))
},
);
let disk_path = match maybe_disk_path {
Some(Ok(path)) => path,
Some(Err(err)) => {
let message = format!(
"failed to find devfs path for {boot_disk:?}: {}",
DisplayErrorChain::new(&err)
);
return Err(HttpError {
status_code: http::StatusCode::SERVICE_UNAVAILABLE,
error_code: None,
external_message: message.clone(),
internal_message: message,
});
}
None => {
let message = format!("no disk found for slot {boot_disk:?}",);
return Err(HttpError {
status_code: http::StatusCode::SERVICE_UNAVAILABLE,
error_code: None,
external_message: message.clone(),
internal_message: message,
});
}
};
let BootDiskWriteStartQueryParams { update_id, sha3_256_digest } =
query_params.into_inner();
sa.boot_disk_os_writer()
.start_update(
boot_disk,
disk_path,
update_id,
sha3_256_digest,
body.into_stream(),
)
.await
.map_err(|err| HttpError::from(&*err))?;
Ok(HttpResponseUpdatedNoContent())
}
async fn host_os_write_status_get(
request_context: RequestContext<Self::Context>,
path_params: Path<BootDiskPathParams>,
) -> Result<HttpResponseOk<BootDiskOsWriteStatus>, HttpError> {
let sa = request_context.context();
let boot_disk = path_params.into_inner().boot_disk;
let status = sa.boot_disk_os_writer().status(boot_disk);
Ok(HttpResponseOk(status))
}
async fn host_os_write_status_delete(
request_context: RequestContext<Self::Context>,
path_params: Path<BootDiskUpdatePathParams>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let sa = request_context.context();
let BootDiskUpdatePathParams { boot_disk, update_id } =
path_params.into_inner();
sa.boot_disk_os_writer()
.clear_terminal_status(boot_disk, update_id)
.map_err(|err| HttpError::from(&err))?;
Ok(HttpResponseUpdatedNoContent())
}
async fn inventory(
request_context: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<Inventory>, HttpError> {
let sa = request_context.context();
Ok(HttpResponseOk(sa.inventory().await?))
}
async fn sled_identifiers(
request_context: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<SledIdentifiers>, HttpError> {
Ok(HttpResponseOk(request_context.context().sled_identifiers()))
}
async fn bootstore_status(
request_context: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<BootstoreStatus>, HttpError> {
let sa = request_context.context();
let bootstore = sa.bootstore();
let status = bootstore
.get_status()
.await
.map_err(|e| {
HttpError::from(omicron_common::api::external::Error::from(e))
})?
.into();
Ok(HttpResponseOk(status))
}
async fn list_vpc_routes(
request_context: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<Vec<ResolvedVpcRouteState>>, HttpError> {
let sa = request_context.context();
Ok(HttpResponseOk(sa.list_vpc_routes()))
}
async fn set_vpc_routes(
request_context: RequestContext<Self::Context>,
body: TypedBody<Vec<ResolvedVpcRouteSet>>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let sa = request_context.context();
sa.set_vpc_routes(body.into_inner())?;
Ok(HttpResponseUpdatedNoContent())
}
async fn set_eip_gateways(
request_context: RequestContext<Self::Context>,
body: TypedBody<ExternalIpGatewayMap>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let sa = request_context.context();
sa.set_eip_gateways(body.into_inner()).await?;
Ok(HttpResponseUpdatedNoContent())
}
}