-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathlib.rs
More file actions
1887 lines (1744 loc) · 70.6 KB
/
Copy pathlib.rs
File metadata and controls
1887 lines (1744 loc) · 70.6 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
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
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// 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/.
use std::collections::BTreeMap;
use camino::Utf8PathBuf;
use dropshot::{
Body, FreeformBody, Header, HttpError, HttpResponseAccepted,
HttpResponseCreated, HttpResponseDeleted, HttpResponseHeaders,
HttpResponseOk, HttpResponseUpdatedNoContent, Path, Query, RequestContext,
StreamingBody, TypedBody,
};
use dropshot_api_manager_types::api_versions;
use omicron_common::api::internal::{
nexus::DiskRuntimeState,
shared::{
ExternalIpGatewayMap, ResolvedVpcRouteSet, ResolvedVpcRouteState,
SledIdentifiers, VirtualNetworkInterfaceHost,
},
};
use sled_agent_types_versions::{
latest, v1, v4, v6, v7, v9, v10, v11, v12, v14, v16, v17, v18, v20, v22,
v24, v25, v26, v28, v29, v30, v31, v32, v33, v34, v37, v39, v40, v41, v42,
v43,
};
use sled_diagnostics::SledDiagnosticsQueryOutput;
use slog_error_chain::InlineErrorChain;
api_versions!([
// WHEN CHANGING THE API (part 1 of 2):
//
// +- Pick a new semver and define it in the list below. The list MUST
// | remain sorted, which generally means that your version should go at
// | the very top.
// |
// | Duplicate this line, uncomment the *second* copy, update that copy for
// | your new API version, and leave the first copy commented out as an
// | example for the next person.
// v
// (next_int, IDENT),
(46, MODIFY_SVC_STATE_ENUM),
(45, REMOVE_UPLINK_ENSURE),
(44, PROPOLIS_NVME_VWC),
(43, INVENTORY_BASEBOARD_ID),
(42, NON_EMPTY_UPLINK_PORTS),
(41, ADD_INSTANCE_PRIMARY_NIC_MTU),
(40, ADD_FMD_TO_INVENTORY),
(39, BOOTSTORE_SERVICE_NAT_GENERATION),
(38, RENAME_PORT_FEC_SPEED_TO_LINK_FEC_SPEED),
(37, MODIFY_SVC_ENABLED_NOT_ONLINE_STATE),
(36, DROPSHOT_FREEFORM_BODY_DESC),
(35, INLINE_ROUTER_PEER_IP_ADDR),
(34, MODIFY_SVCS_TYPES),
(33, BOOTSTORE_SERVICE_NAT),
(32, MAKE_ALL_EXTERNAL_IP_FIELDS_OPTIONAL),
(31, ADD_ICMPV6_FIREWALL_SUPPORT),
(30, STRONGER_BGP_UNNUMBERED_TYPES),
(29, ADD_VSOCK_COMPONENT),
(28, MODIFY_SERVICES_IN_INVENTORY),
(27, RENAME_SWITCH_LOCATION_TO_SWITCH_SLOT),
(26, RACK_NETWORK_CONFIG_NOT_OPTIONAL),
(25, BOOTSTORE_VERSIONING),
(24, ADD_ZPOOL_HEALTH_TO_INVENTORY),
(23, REMOVE_READ_BOOTSTORE_CONFIG_CACHE),
(22, REMOVE_HEALTH_MONITOR_KEEP_CHECKS),
(21, REMOVE_DISK_PUT),
(20, BGP_V6),
(19, ADD_ROT_ATTESTATION),
(18, ADD_ATTACHED_SUBNETS),
(17, TWO_TYPES_OF_DELEGATED_ZVOL),
(16, MEASUREMENT_PROPER_INVENTORY),
(15, ADD_TRUST_QUORUM_STATUS),
(14, MEASUREMENTS),
(13, ADD_TRUST_QUORUM),
(12, ADD_SMF_SERVICES_HEALTH_CHECK),
(11, ADD_DUAL_STACK_EXTERNAL_IP_CONFIG),
(10, ADD_DUAL_STACK_SHARED_NETWORK_INTERFACES),
(9, DELEGATE_ZVOL_TO_PROPOLIS),
(8, REMOVE_SLED_ROLE),
(7, MULTICAST_SUPPORT),
(6, ADD_PROBE_PUT_ENDPOINT),
(5, NEWTYPE_UUID_BUMP),
(4, ADD_NEXUS_LOCKSTEP_PORT_TO_INVENTORY),
(3, ADD_SWITCH_ZONE_OPERATOR_POLICY),
(2, REMOVE_DESTROY_ORPHANED_DATASETS_CHICKEN_SWITCH),
(1, INITIAL),
]);
// WHEN CHANGING THE API (part 2 of 2):
//
// The call to `api_versions!` above defines constants of type
// `semver::Version` that you can use in your Dropshot API definition to specify
// the version when a particular endpoint was added or removed. For example, if
// you used:
//
// (2, ADD_FOOBAR)
//
// Then you could use `VERSION_ADD_FOOBAR` as the version in which endpoints
// were added or removed.
// Host OS images are just over 800 MiB currently; set this to 2 GiB to give
// some breathing room.
const HOST_OS_IMAGE_MAX_BYTES: usize = 2 * 1024 * 1024 * 1024;
// The largest TUF repository artifact is in fact the host OS image. (TODO: or
// at least, it will be when we split up the composite control plane artifact;
// tracked by issue #4411.)
const UPDATE_ARTIFACT_MAX_BYTES: usize = HOST_OS_IMAGE_MAX_BYTES;
// TODO This was the previous API-wide max; what is the largest support bundle
// we expect to need to store?
const SUPPORT_BUNDLE_MAX_BYTES: usize = 2 * 1024 * 1024 * 1024;
#[dropshot::api_description]
pub trait SledAgentApi {
type Context;
/// List all zone bundles that exist, even for now-deleted zones.
#[endpoint {
method = GET,
path = "/zones/bundles",
}]
async fn zone_bundle_list_all(
rqctx: RequestContext<Self::Context>,
query: Query<latest::zone_bundle::ZoneBundleFilter>,
) -> Result<
HttpResponseOk<Vec<latest::zone_bundle::ZoneBundleMetadata>>,
HttpError,
>;
/// List the zone bundles that are available for a running zone.
#[endpoint {
method = GET,
path = "/zones/bundles/{zone_name}",
}]
async fn zone_bundle_list(
rqctx: RequestContext<Self::Context>,
params: Path<latest::zone_bundle::ZonePathParam>,
) -> Result<
HttpResponseOk<Vec<latest::zone_bundle::ZoneBundleMetadata>>,
HttpError,
>;
/// Fetch the binary content of a single zone bundle.
#[endpoint {
method = GET,
path = "/zones/bundles/{zone_name}/{bundle_id}",
}]
async fn zone_bundle_get(
rqctx: RequestContext<Self::Context>,
params: Path<latest::zone_bundle::ZoneBundleId>,
) -> Result<HttpResponseHeaders<HttpResponseOk<FreeformBody>>, HttpError>;
/// Delete a zone bundle.
#[endpoint {
method = DELETE,
path = "/zones/bundles/{zone_name}/{bundle_id}",
}]
async fn zone_bundle_delete(
rqctx: RequestContext<Self::Context>,
params: Path<latest::zone_bundle::ZoneBundleId>,
) -> Result<HttpResponseDeleted, HttpError>;
/// Return utilization information about all zone bundles.
#[endpoint {
method = GET,
path = "/zones/bundle-cleanup/utilization",
}]
async fn zone_bundle_utilization(
rqctx: RequestContext<Self::Context>,
) -> Result<
HttpResponseOk<
BTreeMap<Utf8PathBuf, latest::zone_bundle::BundleUtilization>,
>,
HttpError,
>;
/// Return context used by the zone-bundle cleanup task.
#[endpoint {
method = GET,
path = "/zones/bundle-cleanup/context",
}]
async fn zone_bundle_cleanup_context(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<latest::zone_bundle::CleanupContext>, HttpError>;
/// Update context used by the zone-bundle cleanup task.
#[endpoint {
method = PUT,
path = "/zones/bundle-cleanup/context",
}]
async fn zone_bundle_cleanup_context_update(
rqctx: RequestContext<Self::Context>,
body: TypedBody<latest::zone_bundle::CleanupContextUpdate>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
/// Trigger a zone bundle cleanup.
#[endpoint {
method = POST,
path = "/zones/bundle-cleanup",
}]
async fn zone_bundle_cleanup(
rqctx: RequestContext<Self::Context>,
) -> Result<
HttpResponseOk<
std::collections::BTreeMap<
Utf8PathBuf,
latest::zone_bundle::CleanupCount,
>,
>,
HttpError,
>;
/// List the zones that are currently managed by the sled agent.
#[endpoint {
method = GET,
path = "/zones",
}]
async fn zones_list(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<Vec<String>>, HttpError>;
/// List all support bundles within a particular dataset
#[endpoint {
method = GET,
path = "/support-bundles/{zpool_id}/{dataset_id}"
}]
async fn support_bundle_list(
rqctx: RequestContext<Self::Context>,
path_params: Path<latest::support_bundle::SupportBundleListPathParam>,
) -> Result<
HttpResponseOk<Vec<latest::support_bundle::SupportBundleMetadata>>,
HttpError,
>;
/// Starts creation of a support bundle within a particular dataset
///
/// Callers should transfer chunks of the bundle with
/// "support_bundle_transfer", and then call "support_bundle_finalize"
/// once the bundle has finished transferring.
///
/// If a support bundle was previously created without being finalized
/// successfully, this endpoint will reset the state.
///
/// If a support bundle was previously created and finalized successfully,
/// this endpoint will return metadata indicating that it already exists.
#[endpoint {
method = POST,
path = "/support-bundles/{zpool_id}/{dataset_id}/{support_bundle_id}"
}]
async fn support_bundle_start_creation(
rqctx: RequestContext<Self::Context>,
path_params: Path<latest::support_bundle::SupportBundlePathParam>,
) -> Result<
HttpResponseCreated<latest::support_bundle::SupportBundleMetadata>,
HttpError,
>;
/// Transfers a chunk of a support bundle within a particular dataset
#[endpoint {
method = PUT,
path = "/support-bundles/{zpool_id}/{dataset_id}/{support_bundle_id}/transfer",
request_body_max_bytes = SUPPORT_BUNDLE_MAX_BYTES,
}]
async fn support_bundle_transfer(
rqctx: RequestContext<Self::Context>,
path_params: Path<latest::support_bundle::SupportBundlePathParam>,
query_params: Query<
latest::support_bundle::SupportBundleTransferQueryParams,
>,
body: StreamingBody,
) -> Result<
HttpResponseCreated<latest::support_bundle::SupportBundleMetadata>,
HttpError,
>;
/// Finalizes the creation of a support bundle
///
/// If the requested hash matched the bundle, the bundle is created.
/// Otherwise, an error is returned.
#[endpoint {
method = POST,
path = "/support-bundles/{zpool_id}/{dataset_id}/{support_bundle_id}/finalize"
}]
async fn support_bundle_finalize(
rqctx: RequestContext<Self::Context>,
path_params: Path<latest::support_bundle::SupportBundlePathParam>,
query_params: Query<
latest::support_bundle::SupportBundleFinalizeQueryParams,
>,
) -> Result<
HttpResponseCreated<latest::support_bundle::SupportBundleMetadata>,
HttpError,
>;
/// Fetch a support bundle from a particular dataset
#[endpoint {
method = GET,
path = "/support-bundles/{zpool_id}/{dataset_id}/{support_bundle_id}/download"
}]
async fn support_bundle_download(
rqctx: RequestContext<Self::Context>,
headers: Header<latest::support_bundle::RangeRequestHeaders>,
path_params: Path<latest::support_bundle::SupportBundlePathParam>,
) -> Result<http::Response<Body>, HttpError>;
/// Fetch a file within a support bundle from a particular dataset
#[endpoint {
method = GET,
path = "/support-bundles/{zpool_id}/{dataset_id}/{support_bundle_id}/download/{file}"
}]
async fn support_bundle_download_file(
rqctx: RequestContext<Self::Context>,
headers: Header<latest::support_bundle::RangeRequestHeaders>,
path_params: Path<latest::support_bundle::SupportBundleFilePathParam>,
) -> Result<http::Response<Body>, HttpError>;
/// Fetch the index (list of files within a support bundle)
#[endpoint {
method = GET,
path = "/support-bundles/{zpool_id}/{dataset_id}/{support_bundle_id}/index"
}]
async fn support_bundle_index(
rqctx: RequestContext<Self::Context>,
headers: Header<latest::support_bundle::RangeRequestHeaders>,
path_params: Path<latest::support_bundle::SupportBundlePathParam>,
) -> Result<http::Response<Body>, HttpError>;
/// Fetch metadata about a support bundle from a particular dataset
#[endpoint {
method = HEAD,
path = "/support-bundles/{zpool_id}/{dataset_id}/{support_bundle_id}/download"
}]
async fn support_bundle_head(
rqctx: RequestContext<Self::Context>,
headers: Header<latest::support_bundle::RangeRequestHeaders>,
path_params: Path<latest::support_bundle::SupportBundlePathParam>,
) -> Result<http::Response<Body>, HttpError>;
/// Fetch metadata about a file within a support bundle from a particular dataset
#[endpoint {
method = HEAD,
path = "/support-bundles/{zpool_id}/{dataset_id}/{support_bundle_id}/download/{file}"
}]
async fn support_bundle_head_file(
rqctx: RequestContext<Self::Context>,
headers: Header<latest::support_bundle::RangeRequestHeaders>,
path_params: Path<latest::support_bundle::SupportBundleFilePathParam>,
) -> Result<http::Response<Body>, HttpError>;
/// Fetch metadata about the list of files within a support bundle
#[endpoint {
method = HEAD,
path = "/support-bundles/{zpool_id}/{dataset_id}/{support_bundle_id}/index"
}]
async fn support_bundle_head_index(
rqctx: RequestContext<Self::Context>,
headers: Header<latest::support_bundle::RangeRequestHeaders>,
path_params: Path<latest::support_bundle::SupportBundlePathParam>,
) -> Result<http::Response<Body>, HttpError>;
/// Delete a support bundle from a particular dataset
#[endpoint {
method = DELETE,
path = "/support-bundles/{zpool_id}/{dataset_id}/{support_bundle_id}"
}]
async fn support_bundle_delete(
rqctx: RequestContext<Self::Context>,
path_params: Path<latest::support_bundle::SupportBundlePathParam>,
) -> Result<HttpResponseDeleted, HttpError>;
#[endpoint {
method = PUT,
path = "/omicron-config",
versions = VERSION_MEASUREMENTS..,
}]
async fn omicron_config_put(
rqctx: RequestContext<Self::Context>,
body: TypedBody<latest::inventory::OmicronSledConfig>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
#[endpoint {
operation_id = "omicron_config_put",
method = PUT,
path = "/omicron-config",
versions =
VERSION_ADD_DUAL_STACK_EXTERNAL_IP_CONFIG..VERSION_MEASUREMENTS,
}]
async fn omicron_config_put_v11(
rqctx: RequestContext<Self::Context>,
body: TypedBody<v11::inventory::OmicronSledConfig>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let body =
body.try_map(latest::inventory::OmicronSledConfig::try_from)?;
Self::omicron_config_put(rqctx, body).await
}
#[endpoint {
operation_id = "omicron_config_put",
method = PUT,
path = "/omicron-config",
versions =
VERSION_ADD_DUAL_STACK_SHARED_NETWORK_INTERFACES..VERSION_ADD_DUAL_STACK_EXTERNAL_IP_CONFIG,
}]
async fn omicron_config_put_v10(
rqctx: RequestContext<Self::Context>,
body: TypedBody<v10::inventory::OmicronSledConfig>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let body = body.try_map(v11::inventory::OmicronSledConfig::try_from)?;
Self::omicron_config_put_v11(rqctx, body).await
}
#[endpoint {
operation_id = "omicron_config_put",
method = PUT,
path = "/omicron-config",
versions =
VERSION_ADD_NEXUS_LOCKSTEP_PORT_TO_INVENTORY..VERSION_ADD_DUAL_STACK_SHARED_NETWORK_INTERFACES,
}]
async fn omicron_config_put_v4(
rqctx: RequestContext<Self::Context>,
body: TypedBody<v4::inventory::OmicronSledConfig>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let body = body.try_map(v10::inventory::OmicronSledConfig::try_from)?;
Self::omicron_config_put_v10(rqctx, body).await
}
#[endpoint {
operation_id = "omicron_config_put",
method = PUT,
path = "/omicron-config",
versions = ..VERSION_ADD_NEXUS_LOCKSTEP_PORT_TO_INVENTORY,
}]
async fn omicron_config_put_v1(
rqctx: RequestContext<Self::Context>,
body: TypedBody<v1::inventory::OmicronSledConfig>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
Self::omicron_config_put_v4(rqctx, body.map(Into::into)).await
}
#[endpoint {
operation_id = "sled_role_get",
method = GET,
path = "/sled-role",
versions = ..VERSION_REMOVE_SLED_ROLE,
}]
async fn sled_role_get_v1(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<v1::inventory::SledRole>, HttpError>;
#[endpoint {
operation_id = "vmm_register",
method = PUT,
path = "/vmms/{propolis_id}",
versions = VERSION_PROPOLIS_NVME_VWC..
}]
async fn vmm_register(
rqctx: RequestContext<Self::Context>,
path_params: Path<latest::instance::VmmPathParam>,
body: TypedBody<latest::instance::InstanceEnsureBody>,
) -> Result<HttpResponseOk<latest::instance::SledVmmState>, HttpError>;
#[endpoint {
operation_id = "vmm_register",
method = PUT,
path = "/vmms/{propolis_id}",
versions = VERSION_ADD_INSTANCE_PRIMARY_NIC_MTU..VERSION_PROPOLIS_NVME_VWC
}]
async fn vmm_register_v41(
rqctx: RequestContext<Self::Context>,
path_params: Path<latest::instance::VmmPathParam>,
body: TypedBody<v41::instance::InstanceEnsureBody>,
) -> Result<HttpResponseOk<latest::instance::SledVmmState>, HttpError> {
Self::vmm_register(rqctx, path_params, body.map(Into::into)).await
}
#[endpoint {
operation_id = "vmm_register",
method = PUT,
path = "/vmms/{propolis_id}",
versions = VERSION_MAKE_ALL_EXTERNAL_IP_FIELDS_OPTIONAL..VERSION_ADD_INSTANCE_PRIMARY_NIC_MTU
}]
async fn vmm_register_v32(
rqctx: RequestContext<Self::Context>,
path_params: Path<latest::instance::VmmPathParam>,
body: TypedBody<v32::instance::InstanceEnsureBody>,
) -> Result<HttpResponseOk<latest::instance::SledVmmState>, HttpError> {
Self::vmm_register_v41(rqctx, path_params, body.map(Into::into)).await
}
#[endpoint {
operation_id = "vmm_register",
method = PUT,
path = "/vmms/{propolis_id}",
versions = VERSION_ADD_ICMPV6_FIREWALL_SUPPORT..VERSION_MAKE_ALL_EXTERNAL_IP_FIELDS_OPTIONAL
}]
async fn vmm_register_v31(
rqctx: RequestContext<Self::Context>,
path_params: Path<latest::instance::VmmPathParam>,
body: TypedBody<v31::instance::InstanceEnsureBody>,
) -> Result<HttpResponseOk<latest::instance::SledVmmState>, HttpError> {
Self::vmm_register_v32(rqctx, path_params, body.map(Into::into)).await
}
#[endpoint {
operation_id = "vmm_register",
method = PUT,
path = "/vmms/{propolis_id}",
versions = VERSION_ADD_VSOCK_COMPONENT..VERSION_ADD_ICMPV6_FIREWALL_SUPPORT
}]
async fn vmm_register_v29(
rqctx: RequestContext<Self::Context>,
path_params: Path<latest::instance::VmmPathParam>,
body: TypedBody<v29::instance::InstanceEnsureBody>,
) -> Result<HttpResponseOk<latest::instance::SledVmmState>, HttpError> {
Self::vmm_register_v31(rqctx, path_params, body.map(Into::into)).await
}
#[endpoint {
operation_id = "vmm_register",
method = PUT,
path = "/vmms/{propolis_id}",
versions =
VERSION_ADD_ATTACHED_SUBNETS..VERSION_ADD_VSOCK_COMPONENT
}]
async fn vmm_register_v18(
rqctx: RequestContext<Self::Context>,
path_params: Path<latest::instance::VmmPathParam>,
body: TypedBody<v18::instance::InstanceEnsureBody>,
) -> Result<HttpResponseOk<latest::instance::SledVmmState>, HttpError> {
Self::vmm_register_v29(rqctx, path_params, body.map(Into::into)).await
}
#[endpoint {
operation_id = "vmm_register",
method = PUT,
path = "/vmms/{propolis_id}",
versions =
VERSION_TWO_TYPES_OF_DELEGATED_ZVOL..VERSION_ADD_ATTACHED_SUBNETS
}]
async fn vmm_register_v17(
rqctx: RequestContext<Self::Context>,
path_params: Path<latest::instance::VmmPathParam>,
body: TypedBody<v17::instance::InstanceEnsureBody>,
) -> Result<HttpResponseOk<latest::instance::SledVmmState>, HttpError> {
Self::vmm_register_v18(rqctx, path_params, body.map(Into::into)).await
}
#[endpoint {
operation_id = "vmm_register",
method = PUT,
path = "/vmms/{propolis_id}",
versions = VERSION_ADD_DUAL_STACK_EXTERNAL_IP_CONFIG..VERSION_TWO_TYPES_OF_DELEGATED_ZVOL
}]
async fn vmm_register_v11(
rqctx: RequestContext<Self::Context>,
path_params: Path<latest::instance::VmmPathParam>,
body: TypedBody<v11::instance::InstanceEnsureBody>,
) -> Result<HttpResponseOk<latest::instance::SledVmmState>, HttpError> {
Self::vmm_register_v17(rqctx, path_params, body.map(Into::into)).await
}
#[endpoint {
operation_id = "vmm_register",
method = PUT,
path = "/vmms/{propolis_id}",
versions =
VERSION_ADD_DUAL_STACK_SHARED_NETWORK_INTERFACES..VERSION_ADD_DUAL_STACK_EXTERNAL_IP_CONFIG
}]
async fn vmm_register_v10(
rqctx: RequestContext<Self::Context>,
path_params: Path<v1::instance::VmmPathParam>,
body: TypedBody<v10::instance::InstanceEnsureBody>,
) -> Result<HttpResponseOk<latest::instance::SledVmmState>, HttpError> {
let body = body.try_map(v11::instance::InstanceEnsureBody::try_from)?;
Self::vmm_register_v11(rqctx, path_params, body).await
}
#[endpoint {
method = PUT,
path = "/vmms/{propolis_id}",
operation_id = "vmm_register",
versions =
VERSION_DELEGATE_ZVOL_TO_PROPOLIS..VERSION_ADD_DUAL_STACK_SHARED_NETWORK_INTERFACES
}]
async fn vmm_register_v9(
rqctx: RequestContext<Self::Context>,
path_params: Path<v1::instance::VmmPathParam>,
body: TypedBody<v9::instance::InstanceEnsureBody>,
) -> Result<HttpResponseOk<latest::instance::SledVmmState>, HttpError> {
let body = body.try_map(v10::instance::InstanceEnsureBody::try_from)?;
Self::vmm_register_v10(rqctx, path_params, body).await
}
#[endpoint {
operation_id = "vmm_register",
method = PUT,
path = "/vmms/{propolis_id}",
versions = VERSION_MULTICAST_SUPPORT..VERSION_DELEGATE_ZVOL_TO_PROPOLIS
}]
async fn vmm_register_v7(
rqctx: RequestContext<Self::Context>,
path_params: Path<v1::instance::VmmPathParam>,
body: TypedBody<v7::instance::InstanceEnsureBody>,
) -> Result<HttpResponseOk<latest::instance::SledVmmState>, HttpError> {
Self::vmm_register_v9(rqctx, path_params, body.map(Into::into)).await
}
#[endpoint {
operation_id = "vmm_register",
method = PUT,
path = "/vmms/{propolis_id}",
versions = ..VERSION_MULTICAST_SUPPORT
}]
async fn vmm_register_v1(
rqctx: RequestContext<Self::Context>,
path_params: Path<v1::instance::VmmPathParam>,
body: TypedBody<v1::instance::InstanceEnsureBody>,
) -> Result<HttpResponseOk<latest::instance::SledVmmState>, HttpError> {
Self::vmm_register_v7(rqctx, path_params, body.map(Into::into)).await
}
#[endpoint {
method = DELETE,
path = "/vmms/{propolis_id}"
}]
async fn vmm_unregister(
rqctx: RequestContext<Self::Context>,
path_params: Path<latest::instance::VmmPathParam>,
) -> Result<
HttpResponseOk<latest::instance::VmmUnregisterResponse>,
HttpError,
>;
#[endpoint {
method = PUT,
path = "/vmms/{propolis_id}/state",
}]
async fn vmm_put_state(
rqctx: RequestContext<Self::Context>,
path_params: Path<latest::instance::VmmPathParam>,
body: TypedBody<latest::instance::VmmPutStateBody>,
) -> Result<HttpResponseOk<latest::instance::VmmPutStateResponse>, HttpError>;
#[endpoint {
method = GET,
path = "/vmms/{propolis_id}/state",
}]
async fn vmm_get_state(
rqctx: RequestContext<Self::Context>,
path_params: Path<latest::instance::VmmPathParam>,
) -> Result<HttpResponseOk<latest::instance::SledVmmState>, HttpError>;
#[endpoint {
method = PUT,
path = "/vmms/{propolis_id}/external-ip",
}]
async fn vmm_put_external_ip(
rqctx: RequestContext<Self::Context>,
path_params: Path<latest::instance::VmmPathParam>,
body: TypedBody<latest::instance::InstanceExternalIpBody>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
#[endpoint {
method = DELETE,
path = "/vmms/{propolis_id}/external-ip",
}]
async fn vmm_delete_external_ip(
rqctx: RequestContext<Self::Context>,
path_params: Path<latest::instance::VmmPathParam>,
body: TypedBody<latest::instance::InstanceExternalIpBody>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
#[endpoint {
method = PUT,
path = "/vmms/{propolis_id}/multicast-group",
versions = VERSION_MULTICAST_SUPPORT..,
}]
async fn vmm_join_multicast_group(
rqctx: RequestContext<Self::Context>,
path_params: Path<latest::instance::VmmPathParam>,
body: TypedBody<latest::instance::InstanceMulticastBody>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
#[endpoint {
method = DELETE,
path = "/vmms/{propolis_id}/multicast-group",
versions = VERSION_MULTICAST_SUPPORT..,
}]
async fn vmm_leave_multicast_group(
rqctx: RequestContext<Self::Context>,
path_params: Path<latest::instance::VmmPathParam>,
body: TypedBody<latest::instance::InstanceMulticastBody>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
#[endpoint {
method = PUT,
path = "/disks/{disk_id}",
versions = ..VERSION_REMOVE_DISK_PUT,
}]
async fn disk_put(
rqctx: RequestContext<Self::Context>,
path_params: Path<latest::disk::DiskPathParam>,
body: TypedBody<latest::disk::DiskEnsureBody>,
) -> Result<HttpResponseOk<DiskRuntimeState>, HttpError>;
#[endpoint {
method = GET,
path = "/artifacts-config"
}]
async fn artifact_config_get(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<latest::artifact::ArtifactConfig>, HttpError>;
#[endpoint {
method = PUT,
path = "/artifacts-config"
}]
async fn artifact_config_put(
rqctx: RequestContext<Self::Context>,
body: TypedBody<latest::artifact::ArtifactConfig>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
#[endpoint {
method = GET,
path = "/artifacts"
}]
async fn artifact_list(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<latest::artifact::ArtifactListResponse>, HttpError>;
#[endpoint {
method = POST,
path = "/artifacts/{sha256}/copy-from-depot"
}]
async fn artifact_copy_from_depot(
rqctx: RequestContext<Self::Context>,
path_params: Path<latest::artifact::ArtifactPathParam>,
query_params: Query<latest::artifact::ArtifactQueryParam>,
body: TypedBody<latest::artifact::ArtifactCopyFromDepotBody>,
) -> Result<
HttpResponseAccepted<latest::artifact::ArtifactCopyFromDepotResponse>,
HttpError,
>;
#[endpoint {
method = PUT,
path = "/artifacts/{sha256}",
request_body_max_bytes = UPDATE_ARTIFACT_MAX_BYTES,
}]
async fn artifact_put(
rqctx: RequestContext<Self::Context>,
path_params: Path<latest::artifact::ArtifactPathParam>,
query_params: Query<latest::artifact::ArtifactQueryParam>,
body: StreamingBody,
) -> Result<HttpResponseOk<latest::artifact::ArtifactPutResponse>, HttpError>;
/// Take a snapshot of a disk that is attached to an instance
#[endpoint {
method = POST,
path = "/vmms/{propolis_id}/disks/{disk_id}/snapshot",
}]
async fn vmm_issue_disk_snapshot_request(
rqctx: RequestContext<Self::Context>,
path_params: Path<
latest::instance::VmmIssueDiskSnapshotRequestPathParam,
>,
body: TypedBody<latest::instance::VmmIssueDiskSnapshotRequestBody>,
) -> Result<
HttpResponseOk<latest::instance::VmmIssueDiskSnapshotRequestResponse>,
HttpError,
>;
#[endpoint {
method = PUT,
path = "/vpc/{vpc_id}/firewall/rules",
versions = VERSION_ADD_ICMPV6_FIREWALL_SUPPORT..,
}]
async fn vpc_firewall_rules_put(
rqctx: RequestContext<Self::Context>,
path_params: Path<latest::instance::VpcPathParam>,
body: TypedBody<latest::firewall_rules::VpcFirewallRulesEnsureBody>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
#[endpoint {
operation_id = "vpc_firewall_rules_put",
method = PUT,
path = "/vpc/{vpc_id}/firewall/rules",
versions = VERSION_ADD_DUAL_STACK_SHARED_NETWORK_INTERFACES..VERSION_ADD_ICMPV6_FIREWALL_SUPPORT,
}]
async fn vpc_firewall_rules_put_v11(
rqctx: RequestContext<Self::Context>,
path_params: Path<latest::instance::VpcPathParam>,
body: TypedBody<v11::firewall_rules::VpcFirewallRulesEnsureBody>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let body =
body.map(v31::firewall_rules::VpcFirewallRulesEnsureBody::from);
Self::vpc_firewall_rules_put(rqctx, path_params, body).await
}
#[endpoint {
operation_id = "vpc_firewall_rules_put",
method = PUT,
path = "/vpc/{vpc_id}/firewall/rules",
versions = ..VERSION_ADD_DUAL_STACK_SHARED_NETWORK_INTERFACES,
}]
async fn vpc_firewall_rules_put_v1(
rqctx: RequestContext<Self::Context>,
path_params: Path<v1::instance::VpcPathParam>,
body: TypedBody<v9::firewall_rules::VpcFirewallRulesEnsureBody>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
let body = body.try_map(
v11::firewall_rules::VpcFirewallRulesEnsureBody::try_from,
)?;
Self::vpc_firewall_rules_put_v11(rqctx, path_params, body).await
}
/// Create a mapping from a virtual NIC to a physical host
// Keep interface_id to maintain parity with the simulated sled agent, which
// requires interface_id on the path.
#[endpoint {
method = PUT,
path = "/v2p/",
}]
async fn set_v2p(
rqctx: RequestContext<Self::Context>,
body: TypedBody<VirtualNetworkInterfaceHost>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
/// Delete a mapping from a virtual NIC to a physical host
// Keep interface_id to maintain parity with the simulated sled agent, which
// requires interface_id on the path.
#[endpoint {
method = DELETE,
path = "/v2p/",
}]
async fn del_v2p(
rqctx: RequestContext<Self::Context>,
body: TypedBody<VirtualNetworkInterfaceHost>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
/// List v2p mappings present on sled
// Used by nexus background task
#[endpoint {
method = GET,
path = "/v2p/",
}]
async fn list_v2p(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<Vec<VirtualNetworkInterfaceHost>>, HttpError>;
#[endpoint {
method = POST,
path = "/switch-ports",
versions = VERSION_STRONGER_BGP_UNNUMBERED_TYPES..VERSION_REMOVE_UPLINK_ENSURE,
}]
async fn uplink_ensure(
_rqctx: RequestContext<Self::Context>,
_body: TypedBody<latest::uplink::SwitchPorts>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
// This endpoint has been removed, but we still have to provide an
// implementation in case we're called by an old client.
//
// Nexus's `sync_switch_configuration` used to call this endpoint to
// induce us to update SMF properties of services within the switch
// zone. Now, `sync_switch_configuration` only pushes config to the
// bootstore, and the scrimlet reconcilers automatically update those
// properties. During a live update, we may be updated before Nexus, so
// may receive this request after we've transitioned to the scrimlet
// reconcilers system, but Nexus still thinks it needs to tell us to do
// this explicitly. We have nothing to do in that case - just claim
// success.
Ok(HttpResponseUpdatedNoContent())
}
#[endpoint {
method = POST,
path = "/switch-ports",
versions = VERSION_BGP_V6..VERSION_STRONGER_BGP_UNNUMBERED_TYPES,
}]
async fn uplink_ensure_v20(
rqctx: RequestContext<Self::Context>,
body: TypedBody<v20::uplink::SwitchPorts>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
Self::uplink_ensure(
rqctx,
body.try_map(TryFrom::try_from).map_err(|err| {
HttpError::for_bad_request(
None,
InlineErrorChain::new(&err).to_string(),
)
})?,
)
.await
}
#[endpoint {
method = POST,
path = "/switch-ports",
versions = ..VERSION_BGP_V6,
}]
async fn uplink_ensure_v1(
rqctx: RequestContext<Self::Context>,
body: TypedBody<v1::uplink::SwitchPorts>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
Self::uplink_ensure_v20(rqctx, body.map(From::from)).await
}
/// This API endpoint is only reading the local sled agent's view of the
/// bootstore. The boostore is a distributed data store that is eventually
/// consistent. Reads from individual nodes may not represent the latest state.
// THIS HAS BEEN REMOVED AND SHOULD NOT BE RESTORED. Reading from the
// bootstore cache is inherently racy; the bootstore is eventually
// consistent, and reads from different nodes may return different values.
// Instead, callers should read from CRDB.
#[endpoint {
method = GET,
path = "/network-bootstore-config",
versions = VERSION_BGP_V6..VERSION_REMOVE_READ_BOOTSTORE_CONFIG_CACHE,
}]
async fn read_network_bootstore_config_cache(
rqctx: RequestContext<Self::Context>,
) -> Result<
HttpResponseOk<v20::early_networking::EarlyNetworkConfig>,
HttpError,
>;
/// This API endpoint is only reading the local sled agent's view of the
/// bootstore. The boostore is a distributed data store that is eventually
/// consistent. Reads from individual nodes may not represent the latest state.
#[endpoint {
method = GET,
path = "/network-bootstore-config",
versions = ..VERSION_BGP_V6,
}]
async fn read_network_bootstore_config_cache_v1(
rqctx: RequestContext<Self::Context>,
) -> Result<
HttpResponseOk<v1::early_networking::EarlyNetworkConfig>,
HttpError,
> {
let result: v1::early_networking::EarlyNetworkConfig =
Self::read_network_bootstore_config_cache(rqctx)
.await?
.0
.try_into()
.map_err(|e| {
HttpError::for_bad_request(
None,
format!("error getting v1 config: {e}"),
)
})?;
Ok(HttpResponseOk(result))
}
// -------------------------------------------------------------------------
// WARNING WARNING WARNING
//
// When adding new versions of `write_network_bootstore_config`, DO NOT
// provide a default implementation for the old version to convert the
// request to the latest type and forward the call to the latest method.
// Doing so can result in a broken update, because it can induce this
// sequence:
//
// 1. One scrimlet is updated; its sled agent is now running the new
// version.
// 2. Nexus (still running the old version) sends a
// `write_network_bootstore_config_vN()` request to the updated scrimlet.
// 3. The scrimlet converts the from-old-Nexus `vN` request to the latest
// bootstore format and tells the bootstore to replicate it.
// 4. Other sleds, which have NOT YET been updated, will now see the new
// version and be unable to deserialize it.
//
// We'll only hit this bad sequence if something in the underlying
// `EarlyNetworkConfigBody` body changes that causes Nexus to send a new
// config. That's not something we expect to be common in the middle of an
// update, but it's certainly possible!
//
// Instead, sled-agent needs to implement the old versions of this endpoint,
// and ensure they still do the same thing they did in the previous release
// (i.e., faithfully serialize the _old_ format into the bootstore). The
// latest version does _not_ use the `latest::*` type alias to be a gentle
// stumbling block toward this comment.
//
// This pattern opens the door for the opposite problem, too: what if we
// forget to add a new `write_network_bootstore_config_v*` endpoint when
// adding a new `WriteNetworkConfigRequest` type? `sled-agent-client` uses a
// `replace` directive pointed to `latest`, which will silently do the wrong
// thing: it will allow calling the most recent
// `write_network_bootstore_config_v*` endpoint defined here even though
// these types explicitly do not use the `latest` alias. To guard against
// this, the `static_assert_latest_write_network_config_type()` function
// below contains a compile-time check that the `latest` alias matches a
// specific version: when adding a new `write_network_bootstore_config_v*`
// endpoint, also update this assertion.
// -------------------------------------------------------------------------
fn static_assert_latest_write_network_config_type() {
static_assertions::assert_type_eq_all!(
v42::system_networking::WriteNetworkConfigRequest,
latest::system_networking::WriteNetworkConfigRequest