-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathlib.rs
3640 lines (3324 loc) · 124 KB
/
lib.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
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
use std::collections::BTreeMap;
use anyhow::anyhow;
use dropshot::Body;
use dropshot::{
EmptyScanParams, EndpointTagPolicy, HttpError, HttpResponseAccepted,
HttpResponseCreated, HttpResponseDeleted, HttpResponseFound,
HttpResponseHeaders, HttpResponseOk, HttpResponseSeeOther,
HttpResponseUpdatedNoContent, PaginationParams, Path, Query,
RequestContext, ResultsPage, StreamingBody, TypedBody,
WebsocketChannelResult, WebsocketConnection,
};
use http::Response;
use ipnetwork::IpNetwork;
use nexus_types::{
authn::cookies::Cookies,
external_api::{params, shared, views},
};
use omicron_common::api::external::{
http_pagination::{PaginatedById, PaginatedByName, PaginatedByNameOrId},
*,
};
use openapi_manager_types::ValidationContext;
use openapiv3::OpenAPI;
pub const API_VERSION: &str = "20250212.0.0";
const MIB: usize = 1024 * 1024;
const GIB: usize = 1024 * MIB;
const DISK_BULK_WRITE_MAX_BYTES: usize = 8 * MIB;
// Full release repositories are currently (Dec 2024) 1.8 GiB and are likely to
// continue growing.
const PUT_UPDATE_REPOSITORY_MAX_BYTES: usize = 4 * GIB;
// API ENDPOINT FUNCTION NAMING CONVENTIONS
//
// Generally, HTTP resources are grouped within some collection. For a
// relatively simple example:
//
// GET v1/projects (list the projects in the collection)
// POST v1/projects (create a project in the collection)
// GET v1/projects/{project} (look up a project in the collection)
// DELETE v1/projects/{project} (delete a project in the collection)
// PUT v1/projects/{project} (update a project in the collection)
//
// We pick a name for the function that implements a given API entrypoint
// based on how we expect it to appear in the CLI subcommand hierarchy. For
// example:
//
// GET v1/projects -> project_list()
// POST v1/projects -> project_create()
// GET v1/projects/{project} -> project_view()
// DELETE v1/projects/{project} -> project_delete()
// PUT v1/projects/{project} -> project_update()
//
// Note that the path typically uses the entity's plural form while the
// function name uses its singular.
//
// Operations beyond list, create, view, delete, and update should use a
// descriptive noun or verb, again bearing in mind that this will be
// transcribed into the CLI and SDKs:
//
// POST -> instance_reboot
// POST -> instance_stop
// GET -> instance_serial_console
//
// Note that these function names end up in generated OpenAPI spec as the
// operationId for each endpoint, and therefore represent a contract with
// clients. Client generators use operationId to name API methods, so changing
// a function name is a breaking change from a client perspective.
#[dropshot::api_description {
tag_config = {
allow_other_tags = false,
policy = EndpointTagPolicy::ExactlyOne,
tags = {
"affinity" = {
description = "Affinity and anti-affinity groups give control over instance placement.",
external_docs = {
url = "http://docs.oxide.computer/api/affinity"
}
},
"disks" = {
description = "Virtual disks are used to store instance-local data which includes the operating system.",
external_docs = {
url = "http://docs.oxide.computer/api/disks"
}
},
"floating-ips" = {
description = "Floating IPs allow a project to allocate well-known IPs to instances.",
external_docs = {
url = "http://docs.oxide.computer/api/floating-ips"
}
},
"hidden" = {
description = "TODO operations that will not ship to customers",
external_docs = {
url = "http://docs.oxide.computer/api"
}
},
"images" = {
description = "Images are read-only virtual disks that may be used to boot virtual machines.",
external_docs = {
url = "http://docs.oxide.computer/api/images"
}
},
"instances" = {
description = "Virtual machine instances are the basic unit of computation. These operations are used for provisioning, controlling, and destroying instances.",
external_docs = {
url = "http://docs.oxide.computer/api/instances"
}
},
"login" = {
description = "Authentication endpoints",
external_docs = {
url = "http://docs.oxide.computer/api/login"
}
},
"metrics" = {
description = "Silo-scoped metrics",
external_docs = {
url = "http://docs.oxide.computer/api/metrics"
}
},
"policy" = {
description = "System-wide IAM policy",
external_docs = {
url = "http://docs.oxide.computer/api/policy"
}
},
"projects" = {
description = "Projects are a grouping of associated resources such as instances and disks within a silo for purposes of billing and access control.",
external_docs = {
url = "http://docs.oxide.computer/api/projects"
}
},
"roles" = {
description = "Roles are a component of Identity and Access Management (IAM) that allow a user or agent account access to additional permissions.",
external_docs = {
url = "http://docs.oxide.computer/api/roles"
}
},
"session" = {
description = "Information pertaining to the current session.",
external_docs = {
url = "http://docs.oxide.computer/api/session"
}
},
"silos" = {
description = "Silos represent a logical partition of users and resources.",
external_docs = {
url = "http://docs.oxide.computer/api/silos"
}
},
"snapshots" = {
description = "Snapshots of virtual disks at a particular point in time.",
external_docs = {
url = "http://docs.oxide.computer/api/snapshots"
}
},
"vpcs" = {
description = "Virtual Private Clouds (VPCs) provide isolated network environments for managing and deploying services.",
external_docs = {
url = "http://docs.oxide.computer/api/vpcs"
}
},
"system/probes" = {
description = "Probes for testing network connectivity",
external_docs = {
url = "http://docs.oxide.computer/api/probes"
}
},
"system/status" = {
description = "Endpoints related to system health",
external_docs = {
url = "http://docs.oxide.computer/api/system-status"
}
},
"system/hardware" = {
description = "These operations pertain to hardware inventory and management. Racks are the unit of expansion of an Oxide deployment. Racks are in turn composed of sleds, switches, power supplies, and a cabled backplane.",
external_docs = {
url = "http://docs.oxide.computer/api/system-hardware"
}
},
"system/metrics" = {
description = "Metrics provide insight into the operation of the Oxide deployment. These include telemetry on hardware and software components that can be used to understand the current state as well as to diagnose issues.",
external_docs = {
url = "http://docs.oxide.computer/api/system-metrics"
}
},
"system/ip-pools" = {
description = "IP pools are collections of external IPs that can be assigned to silos. When a pool is linked to a silo, users in that silo can allocate IPs from the pool for their instances.",
external_docs = {
url = "http://docs.oxide.computer/api/system-ip-pools"
}
},
"system/networking" = {
description = "This provides rack-level network configuration.",
external_docs = {
url = "http://docs.oxide.computer/api/system-networking"
}
},
"system/silos" = {
description = "Silos represent a logical partition of users and resources.",
external_docs = {
url = "http://docs.oxide.computer/api/system-silos"
}
}
}
}
}]
pub trait NexusExternalApi {
type Context;
/// Ping API
///
/// Always responds with Ok if it responds at all.
#[endpoint {
method = GET,
path = "/v1/ping",
tags = ["system/status"],
}]
async fn ping(
_rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<views::Ping>, HttpError> {
Ok(HttpResponseOk(views::Ping { status: views::PingStatus::Ok }))
}
/// Fetch top-level IAM policy
#[endpoint {
method = GET,
path = "/v1/system/policy",
tags = ["policy"],
}]
async fn system_policy_view(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<shared::Policy<shared::FleetRole>>, HttpError>;
/// Update top-level IAM policy
#[endpoint {
method = PUT,
path = "/v1/system/policy",
tags = ["policy"],
}]
async fn system_policy_update(
rqctx: RequestContext<Self::Context>,
new_policy: TypedBody<shared::Policy<shared::FleetRole>>,
) -> Result<HttpResponseOk<shared::Policy<shared::FleetRole>>, HttpError>;
/// Fetch current silo's IAM policy
#[endpoint {
method = GET,
path = "/v1/policy",
tags = ["silos"],
}]
async fn policy_view(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<shared::Policy<shared::SiloRole>>, HttpError>;
/// Update current silo's IAM policy
#[endpoint {
method = PUT,
path = "/v1/policy",
tags = ["silos"],
}]
async fn policy_update(
rqctx: RequestContext<Self::Context>,
new_policy: TypedBody<shared::Policy<shared::SiloRole>>,
) -> Result<HttpResponseOk<shared::Policy<shared::SiloRole>>, HttpError>;
/// Fetch resource utilization for user's current silo
#[endpoint {
method = GET,
path = "/v1/utilization",
tags = ["silos"],
}]
async fn utilization_view(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<views::Utilization>, HttpError>;
/// Fetch current utilization for given silo
#[endpoint {
method = GET,
path = "/v1/system/utilization/silos/{silo}",
tags = ["system/silos"],
}]
async fn silo_utilization_view(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::SiloPath>,
) -> Result<HttpResponseOk<views::SiloUtilization>, HttpError>;
/// List current utilization state for all silos
#[endpoint {
method = GET,
path = "/v1/system/utilization/silos",
tags = ["system/silos"],
}]
async fn silo_utilization_list(
rqctx: RequestContext<Self::Context>,
query_params: Query<PaginatedByNameOrId>,
) -> Result<HttpResponseOk<ResultsPage<views::SiloUtilization>>, HttpError>;
/// Lists resource quotas for all silos
#[endpoint {
method = GET,
path = "/v1/system/silo-quotas",
tags = ["system/silos"],
}]
async fn system_quotas_list(
rqctx: RequestContext<Self::Context>,
query_params: Query<PaginatedById>,
) -> Result<HttpResponseOk<ResultsPage<views::SiloQuotas>>, HttpError>;
/// Fetch resource quotas for silo
#[endpoint {
method = GET,
path = "/v1/system/silos/{silo}/quotas",
tags = ["system/silos"],
}]
async fn silo_quotas_view(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::SiloPath>,
) -> Result<HttpResponseOk<views::SiloQuotas>, HttpError>;
/// Update resource quotas for silo
///
/// If a quota value is not specified, it will remain unchanged.
#[endpoint {
method = PUT,
path = "/v1/system/silos/{silo}/quotas",
tags = ["system/silos"],
}]
async fn silo_quotas_update(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::SiloPath>,
new_quota: TypedBody<params::SiloQuotasUpdate>,
) -> Result<HttpResponseOk<views::SiloQuotas>, HttpError>;
/// List silos
///
/// Lists silos that are discoverable based on the current permissions.
#[endpoint {
method = GET,
path = "/v1/system/silos",
tags = ["system/silos"],
}]
async fn silo_list(
rqctx: RequestContext<Self::Context>,
query_params: Query<PaginatedByNameOrId>,
) -> Result<HttpResponseOk<ResultsPage<views::Silo>>, HttpError>;
/// Create a silo
#[endpoint {
method = POST,
path = "/v1/system/silos",
tags = ["system/silos"],
}]
async fn silo_create(
rqctx: RequestContext<Self::Context>,
new_silo_params: TypedBody<params::SiloCreate>,
) -> Result<HttpResponseCreated<views::Silo>, HttpError>;
/// Fetch silo
///
/// Fetch silo by name or ID.
#[endpoint {
method = GET,
path = "/v1/system/silos/{silo}",
tags = ["system/silos"],
}]
async fn silo_view(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::SiloPath>,
) -> Result<HttpResponseOk<views::Silo>, HttpError>;
/// List IP pools linked to silo
///
/// Linked IP pools are available to users in the specified silo. A silo
/// can have at most one default pool. IPs are allocated from the default
/// pool when users ask for one without specifying a pool.
#[endpoint {
method = GET,
path = "/v1/system/silos/{silo}/ip-pools",
tags = ["system/silos"],
}]
async fn silo_ip_pool_list(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::SiloPath>,
query_params: Query<PaginatedByNameOrId>,
) -> Result<HttpResponseOk<ResultsPage<views::SiloIpPool>>, HttpError>;
/// Delete a silo
///
/// Delete a silo by name or ID.
#[endpoint {
method = DELETE,
path = "/v1/system/silos/{silo}",
tags = ["system/silos"],
}]
async fn silo_delete(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::SiloPath>,
) -> Result<HttpResponseDeleted, HttpError>;
/// Fetch silo IAM policy
#[endpoint {
method = GET,
path = "/v1/system/silos/{silo}/policy",
tags = ["system/silos"],
}]
async fn silo_policy_view(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::SiloPath>,
) -> Result<HttpResponseOk<shared::Policy<shared::SiloRole>>, HttpError>;
/// Update silo IAM policy
#[endpoint {
method = PUT,
path = "/v1/system/silos/{silo}/policy",
tags = ["system/silos"],
}]
async fn silo_policy_update(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::SiloPath>,
new_policy: TypedBody<shared::Policy<shared::SiloRole>>,
) -> Result<HttpResponseOk<shared::Policy<shared::SiloRole>>, HttpError>;
// Silo-specific user endpoints
/// List built-in (system) users in silo
#[endpoint {
method = GET,
path = "/v1/system/users",
tags = ["system/silos"],
}]
async fn silo_user_list(
rqctx: RequestContext<Self::Context>,
query_params: Query<PaginatedById<params::SiloSelector>>,
) -> Result<HttpResponseOk<ResultsPage<views::User>>, HttpError>;
/// Fetch built-in (system) user
#[endpoint {
method = GET,
path = "/v1/system/users/{user_id}",
tags = ["system/silos"],
}]
async fn silo_user_view(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::UserParam>,
query_params: Query<params::SiloSelector>,
) -> Result<HttpResponseOk<views::User>, HttpError>;
// Silo identity providers
/// List a silo's IdP's name
#[endpoint {
method = GET,
path = "/v1/system/identity-providers",
tags = ["system/silos"],
}]
async fn silo_identity_provider_list(
rqctx: RequestContext<Self::Context>,
query_params: Query<PaginatedByNameOrId<params::SiloSelector>>,
) -> Result<HttpResponseOk<ResultsPage<views::IdentityProvider>>, HttpError>;
// Silo SAML identity providers
/// Create SAML IdP
#[endpoint {
method = POST,
path = "/v1/system/identity-providers/saml",
tags = ["system/silos"],
}]
async fn saml_identity_provider_create(
rqctx: RequestContext<Self::Context>,
query_params: Query<params::SiloSelector>,
new_provider: TypedBody<params::SamlIdentityProviderCreate>,
) -> Result<HttpResponseCreated<views::SamlIdentityProvider>, HttpError>;
/// Fetch SAML IdP
#[endpoint {
method = GET,
path = "/v1/system/identity-providers/saml/{provider}",
tags = ["system/silos"],
}]
async fn saml_identity_provider_view(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::ProviderPath>,
query_params: Query<params::SiloSelector>,
) -> Result<HttpResponseOk<views::SamlIdentityProvider>, HttpError>;
// TODO: no DELETE for identity providers?
// "Local" Identity Provider
/// Create user
///
/// Users can only be created in Silos with `provision_type` == `Fixed`.
/// Otherwise, Silo users are just-in-time (JIT) provisioned when a user
/// first logs in using an external Identity Provider.
#[endpoint {
method = POST,
path = "/v1/system/identity-providers/local/users",
tags = ["system/silos"],
}]
async fn local_idp_user_create(
rqctx: RequestContext<Self::Context>,
query_params: Query<params::SiloSelector>,
new_user_params: TypedBody<params::UserCreate>,
) -> Result<HttpResponseCreated<views::User>, HttpError>;
/// Delete user
#[endpoint {
method = DELETE,
path = "/v1/system/identity-providers/local/users/{user_id}",
tags = ["system/silos"],
}]
async fn local_idp_user_delete(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::UserParam>,
query_params: Query<params::SiloSelector>,
) -> Result<HttpResponseDeleted, HttpError>;
/// Set or invalidate user's password
///
/// Passwords can only be updated for users in Silos with identity mode
/// `LocalOnly`.
#[endpoint {
method = POST,
path = "/v1/system/identity-providers/local/users/{user_id}/set-password",
tags = ["system/silos"],
}]
async fn local_idp_user_set_password(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::UserParam>,
query_params: Query<params::SiloPath>,
update: TypedBody<params::UserPassword>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
/// List projects
#[endpoint {
method = GET,
path = "/v1/projects",
tags = ["projects"],
}]
async fn project_list(
rqctx: RequestContext<Self::Context>,
query_params: Query<PaginatedByNameOrId>,
) -> Result<HttpResponseOk<ResultsPage<views::Project>>, HttpError>;
/// Create project
#[endpoint {
method = POST,
path = "/v1/projects",
tags = ["projects"],
}]
async fn project_create(
rqctx: RequestContext<Self::Context>,
new_project: TypedBody<params::ProjectCreate>,
) -> Result<HttpResponseCreated<views::Project>, HttpError>;
/// Fetch project
#[endpoint {
method = GET,
path = "/v1/projects/{project}",
tags = ["projects"],
}]
async fn project_view(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::ProjectPath>,
) -> Result<HttpResponseOk<views::Project>, HttpError>;
/// Delete project
#[endpoint {
method = DELETE,
path = "/v1/projects/{project}",
tags = ["projects"],
}]
async fn project_delete(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::ProjectPath>,
) -> Result<HttpResponseDeleted, HttpError>;
// TODO-correctness: Is it valid for PUT to accept application/json that's
// a subset of what the resource actually represents? If not, is that a
// problem? (HTTP may require that this be idempotent.) If so, can we get
// around that having this be a slightly different content-type (e.g.,
// "application/json-patch")? We should see what other APIs do.
/// Update a project
#[endpoint {
method = PUT,
path = "/v1/projects/{project}",
tags = ["projects"],
}]
async fn project_update(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::ProjectPath>,
updated_project: TypedBody<params::ProjectUpdate>,
) -> Result<HttpResponseOk<views::Project>, HttpError>;
/// Fetch project's IAM policy
#[endpoint {
method = GET,
path = "/v1/projects/{project}/policy",
tags = ["projects"],
}]
async fn project_policy_view(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::ProjectPath>,
) -> Result<HttpResponseOk<shared::Policy<shared::ProjectRole>>, HttpError>;
/// Update project's IAM policy
#[endpoint {
method = PUT,
path = "/v1/projects/{project}/policy",
tags = ["projects"],
}]
async fn project_policy_update(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::ProjectPath>,
new_policy: TypedBody<shared::Policy<shared::ProjectRole>>,
) -> Result<HttpResponseOk<shared::Policy<shared::ProjectRole>>, HttpError>;
// IP Pools
/// List IP pools
#[endpoint {
method = GET,
path = "/v1/ip-pools",
tags = ["projects"],
}]
async fn project_ip_pool_list(
rqctx: RequestContext<Self::Context>,
query_params: Query<PaginatedByNameOrId>,
) -> Result<HttpResponseOk<ResultsPage<views::SiloIpPool>>, HttpError>;
/// Fetch IP pool
#[endpoint {
method = GET,
path = "/v1/ip-pools/{pool}",
tags = ["projects"],
}]
async fn project_ip_pool_view(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::IpPoolPath>,
) -> Result<HttpResponseOk<views::SiloIpPool>, HttpError>;
/// List IP pools
#[endpoint {
method = GET,
path = "/v1/system/ip-pools",
tags = ["system/ip-pools"],
}]
async fn ip_pool_list(
rqctx: RequestContext<Self::Context>,
query_params: Query<PaginatedByNameOrId>,
) -> Result<HttpResponseOk<ResultsPage<views::IpPool>>, HttpError>;
/// Create IP pool
#[endpoint {
method = POST,
path = "/v1/system/ip-pools",
tags = ["system/ip-pools"],
}]
async fn ip_pool_create(
rqctx: RequestContext<Self::Context>,
pool_params: TypedBody<params::IpPoolCreate>,
) -> Result<HttpResponseCreated<views::IpPool>, HttpError>;
/// Fetch IP pool
#[endpoint {
method = GET,
path = "/v1/system/ip-pools/{pool}",
tags = ["system/ip-pools"],
}]
async fn ip_pool_view(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::IpPoolPath>,
) -> Result<HttpResponseOk<views::IpPool>, HttpError>;
/// Delete IP pool
#[endpoint {
method = DELETE,
path = "/v1/system/ip-pools/{pool}",
tags = ["system/ip-pools"],
}]
async fn ip_pool_delete(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::IpPoolPath>,
) -> Result<HttpResponseDeleted, HttpError>;
/// Update IP pool
#[endpoint {
method = PUT,
path = "/v1/system/ip-pools/{pool}",
tags = ["system/ip-pools"],
}]
async fn ip_pool_update(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::IpPoolPath>,
updates: TypedBody<params::IpPoolUpdate>,
) -> Result<HttpResponseOk<views::IpPool>, HttpError>;
/// Fetch IP pool utilization
#[endpoint {
method = GET,
path = "/v1/system/ip-pools/{pool}/utilization",
tags = ["system/ip-pools"],
}]
async fn ip_pool_utilization_view(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::IpPoolPath>,
) -> Result<HttpResponseOk<views::IpPoolUtilization>, HttpError>;
/// List IP pool's linked silos
#[endpoint {
method = GET,
path = "/v1/system/ip-pools/{pool}/silos",
tags = ["system/ip-pools"],
}]
async fn ip_pool_silo_list(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::IpPoolPath>,
// paginating by resource_id because they're unique per pool. most robust
// option would be to paginate by a composite key representing the (pool,
// resource_type, resource)
query_params: Query<PaginatedById>,
// TODO: this could just list views::Silo -- it's not like knowing silo_id
// and nothing else is particularly useful -- except we also want to say
// whether the pool is marked default on each silo. So one option would
// be to do the same as we did with SiloIpPool -- include is_default on
// whatever the thing is. Still... all we'd have to do to make this usable
// in both places would be to make it { ...IpPool, silo_id, silo_name,
// is_default }
) -> Result<HttpResponseOk<ResultsPage<views::IpPoolSiloLink>>, HttpError>;
/// Link IP pool to silo
///
/// Users in linked silos can allocate external IPs from this pool for their
/// instances. A silo can have at most one default pool. IPs are allocated from
/// the default pool when users ask for one without specifying a pool.
#[endpoint {
method = POST,
path = "/v1/system/ip-pools/{pool}/silos",
tags = ["system/ip-pools"],
}]
async fn ip_pool_silo_link(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::IpPoolPath>,
resource_assoc: TypedBody<params::IpPoolLinkSilo>,
) -> Result<HttpResponseCreated<views::IpPoolSiloLink>, HttpError>;
/// Unlink IP pool from silo
///
/// Will fail if there are any outstanding IPs allocated in the silo.
#[endpoint {
method = DELETE,
path = "/v1/system/ip-pools/{pool}/silos/{silo}",
tags = ["system/ip-pools"],
}]
async fn ip_pool_silo_unlink(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::IpPoolSiloPath>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
/// Make IP pool default for silo
///
/// When a user asks for an IP (e.g., at instance create time) without
/// specifying a pool, the IP comes from the default pool if a default is
/// configured. When a pool is made the default for a silo, any existing
/// default will remain linked to the silo, but will no longer be the
/// default.
#[endpoint {
method = PUT,
path = "/v1/system/ip-pools/{pool}/silos/{silo}",
tags = ["system/ip-pools"],
}]
async fn ip_pool_silo_update(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::IpPoolSiloPath>,
update: TypedBody<params::IpPoolSiloUpdate>,
) -> Result<HttpResponseOk<views::IpPoolSiloLink>, HttpError>;
/// Fetch Oxide service IP pool
#[endpoint {
method = GET,
path = "/v1/system/ip-pools-service",
tags = ["system/ip-pools"],
}]
async fn ip_pool_service_view(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<views::IpPool>, HttpError>;
/// List ranges for IP pool
///
/// Ranges are ordered by their first address.
#[endpoint {
method = GET,
path = "/v1/system/ip-pools/{pool}/ranges",
tags = ["system/ip-pools"],
}]
async fn ip_pool_range_list(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::IpPoolPath>,
query_params: Query<IpPoolRangePaginationParams>,
) -> Result<HttpResponseOk<ResultsPage<views::IpPoolRange>>, HttpError>;
/// Add range to IP pool
///
/// IPv6 ranges are not allowed yet.
#[endpoint {
method = POST,
path = "/v1/system/ip-pools/{pool}/ranges/add",
tags = ["system/ip-pools"],
}]
async fn ip_pool_range_add(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::IpPoolPath>,
range_params: TypedBody<shared::IpRange>,
) -> Result<HttpResponseCreated<views::IpPoolRange>, HttpError>;
/// Remove range from IP pool
#[endpoint {
method = POST,
path = "/v1/system/ip-pools/{pool}/ranges/remove",
tags = ["system/ip-pools"],
}]
async fn ip_pool_range_remove(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::IpPoolPath>,
range_params: TypedBody<shared::IpRange>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
/// List IP ranges for the Oxide service pool
///
/// Ranges are ordered by their first address.
#[endpoint {
method = GET,
path = "/v1/system/ip-pools-service/ranges",
tags = ["system/ip-pools"],
}]
async fn ip_pool_service_range_list(
rqctx: RequestContext<Self::Context>,
query_params: Query<IpPoolRangePaginationParams>,
) -> Result<HttpResponseOk<ResultsPage<views::IpPoolRange>>, HttpError>;
/// Add IP range to Oxide service pool
///
/// IPv6 ranges are not allowed yet.
#[endpoint {
method = POST,
path = "/v1/system/ip-pools-service/ranges/add",
tags = ["system/ip-pools"],
}]
async fn ip_pool_service_range_add(
rqctx: RequestContext<Self::Context>,
range_params: TypedBody<shared::IpRange>,
) -> Result<HttpResponseCreated<views::IpPoolRange>, HttpError>;
/// Remove IP range from Oxide service pool
#[endpoint {
method = POST,
path = "/v1/system/ip-pools-service/ranges/remove",
tags = ["system/ip-pools"],
}]
async fn ip_pool_service_range_remove(
rqctx: RequestContext<Self::Context>,
range_params: TypedBody<shared::IpRange>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
// Floating IP Addresses
/// List floating IPs
#[endpoint {
method = GET,
path = "/v1/floating-ips",
tags = ["floating-ips"],
}]
async fn floating_ip_list(
rqctx: RequestContext<Self::Context>,
query_params: Query<PaginatedByNameOrId<params::ProjectSelector>>,
) -> Result<HttpResponseOk<ResultsPage<views::FloatingIp>>, HttpError>;
/// Create floating IP
#[endpoint {
method = POST,
path = "/v1/floating-ips",
tags = ["floating-ips"],
}]
async fn floating_ip_create(
rqctx: RequestContext<Self::Context>,
query_params: Query<params::ProjectSelector>,
floating_params: TypedBody<params::FloatingIpCreate>,
) -> Result<HttpResponseCreated<views::FloatingIp>, HttpError>;
/// Update floating IP
#[endpoint {
method = PUT,
path = "/v1/floating-ips/{floating_ip}",
tags = ["floating-ips"],
}]
async fn floating_ip_update(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::FloatingIpPath>,
query_params: Query<params::OptionalProjectSelector>,
updated_floating_ip: TypedBody<params::FloatingIpUpdate>,
) -> Result<HttpResponseOk<views::FloatingIp>, HttpError>;
/// Delete floating IP
#[endpoint {
method = DELETE,
path = "/v1/floating-ips/{floating_ip}",
tags = ["floating-ips"],
}]
async fn floating_ip_delete(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::FloatingIpPath>,
query_params: Query<params::OptionalProjectSelector>,
) -> Result<HttpResponseDeleted, HttpError>;
/// Fetch floating IP
#[endpoint {
method = GET,
path = "/v1/floating-ips/{floating_ip}",
tags = ["floating-ips"]
}]
async fn floating_ip_view(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::FloatingIpPath>,
query_params: Query<params::OptionalProjectSelector>,
) -> Result<HttpResponseOk<views::FloatingIp>, HttpError>;
/// Attach floating IP
///
/// Attach floating IP to an instance or other resource.
#[endpoint {
method = POST,
path = "/v1/floating-ips/{floating_ip}/attach",
tags = ["floating-ips"],
}]
async fn floating_ip_attach(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::FloatingIpPath>,
query_params: Query<params::OptionalProjectSelector>,
target: TypedBody<params::FloatingIpAttach>,
) -> Result<HttpResponseAccepted<views::FloatingIp>, HttpError>;
/// Detach floating IP
///
// Detach floating IP from instance or other resource.
#[endpoint {
method = POST,
path = "/v1/floating-ips/{floating_ip}/detach",
tags = ["floating-ips"],
}]
async fn floating_ip_detach(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::FloatingIpPath>,
query_params: Query<params::OptionalProjectSelector>,
) -> Result<HttpResponseAccepted<views::FloatingIp>, HttpError>;
// Disks
/// List disks
#[endpoint {
method = GET,
path = "/v1/disks",
tags = ["disks"],
}]
async fn disk_list(
rqctx: RequestContext<Self::Context>,
query_params: Query<PaginatedByNameOrId<params::ProjectSelector>>,
) -> Result<HttpResponseOk<ResultsPage<Disk>>, HttpError>;
// TODO-correctness See note about instance create. This should be async.
/// Create a disk
#[endpoint {
method = POST,
path = "/v1/disks",
tags = ["disks"]
}]
async fn disk_create(
rqctx: RequestContext<Self::Context>,
query_params: Query<params::ProjectSelector>,
new_disk: TypedBody<params::DiskCreate>,
) -> Result<HttpResponseCreated<Disk>, HttpError>;
/// Fetch disk
#[endpoint {
method = GET,
path = "/v1/disks/{disk}",
tags = ["disks"]
}]
async fn disk_view(
rqctx: RequestContext<Self::Context>,
path_params: Path<params::DiskPath>,
query_params: Query<params::OptionalProjectSelector>,
) -> Result<HttpResponseOk<Disk>, HttpError>;