Repository navigation
Expand file tree
/
Copy pathlib.rs
More file actions
406 lines (367 loc) · 14 KB
/
Copy pathlib.rs
File metadata and controls
406 lines (367 loc) · 14 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
// 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::BTreeSet;
use dropshot::{
HttpError, HttpResponseCreated, HttpResponseOk,
HttpResponseUpdatedNoContent, Path, Query, RequestContext, ResultsPage,
TypedBody,
};
use dropshot_api_manager_types::api_versions;
use nexus_types::{
external_api::{
probe::ProbeExternalIp,
system::{Ping, PingStatus},
},
internal_api::{
params::{
OximeterInfo, SledAgentInfo, SwitchPutRequest, SwitchPutResponse,
},
views::NatEntryView,
},
};
use omicron_common::api::{
external::{Name, http_pagination::PaginatedById},
internal::nexus::{
DiskRuntimeState, DownstairsClientStopRequest, DownstairsClientStopped,
ProducerEndpoint, ProducerRegistrationResponse, RepairFinishInfo,
RepairProgress, RepairStartInfo,
},
};
use omicron_uuid_kinds::*;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use sled_agent_types_versions::v1::inventory::NetworkInterface as NetworkInterfaceV1;
use uuid::Uuid;
api_versions!([
// Do not create new versions of this client-side versioned API.
// https://github.com/oxidecomputer/omicron/issues/9290
(1, INITIAL),
]);
#[dropshot::api_description]
pub trait NexusInternalApi {
type Context;
/// Ping API
///
/// Always responds with Ok if it responds at all.
#[endpoint {
method = GET,
path = "/v1/ping",
}]
async fn ping(
_rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<Ping>, HttpError> {
Ok(HttpResponseOk(Ping { status: PingStatus::Ok }))
}
/// Return information about the given sled agent
#[endpoint {
method = GET,
path = "/sled-agents/{sled_id}",
}]
async fn sled_agent_get(
rqctx: RequestContext<Self::Context>,
path_params: Path<SledAgentPathParam>,
) -> Result<HttpResponseOk<SledAgentInfo>, HttpError>;
/// Report that the sled agent for the specified sled has come online.
#[endpoint {
method = POST,
path = "/sled-agents/{sled_id}",
}]
async fn sled_agent_put(
rqctx: RequestContext<Self::Context>,
path_params: Path<SledAgentPathParam>,
sled_info: TypedBody<SledAgentInfo>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
#[endpoint {
method = PUT,
path = "/switch/{switch_id}",
}]
async fn switch_put(
rqctx: RequestContext<Self::Context>,
path_params: Path<SwitchPathParam>,
body: TypedBody<SwitchPutRequest>,
) -> Result<HttpResponseOk<SwitchPutResponse>, HttpError>;
/// Report updated state for a VMM.
#[endpoint {
method = PUT,
path = "/vmms/{propolis_id}",
}]
async fn cpapi_instances_put(
rqctx: RequestContext<Self::Context>,
path_params: Path<VmmPathParam>,
// Note that this is explicitly pointed at the V1 version of
// `SledVmmState`, NOT latest. That is because the Nexus internal API is
// client-side versioned, and cannot be updated to use the latest
// version of this type freely.
//
// Instead, this API is deprecated and will be replaced with
// `cpapi_vmm_doorbell`, which does *not* provide a body, in a
// subsequent version of the Nexus API.
new_runtime_state: TypedBody<
sled_agent_types_versions::v1::instance::SledVmmState,
>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
/// Report updated state for a disk.
#[endpoint {
method = PUT,
path = "/disks/{disk_id}",
}]
async fn cpapi_disks_put(
rqctx: RequestContext<Self::Context>,
path_params: Path<DiskPathParam>,
new_runtime_state: TypedBody<DiskRuntimeState>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
/// Request removal of a read_only_parent from a volume.
///
/// A volume can be created with the source data for that volume being another
/// volume that attached as a "read_only_parent". In the background there
/// exists a scrubber that will copy the data from the read_only_parent
/// into the volume. When that scrubber has completed copying the data, this
/// endpoint can be called to update the database that the read_only_parent
/// is no longer needed for a volume and future attachments of this volume
/// should not include that read_only_parent.
#[endpoint {
method = POST,
path = "/volume/{volume_id}/remove-read-only-parent",
}]
async fn cpapi_volume_remove_read_only_parent(
rqctx: RequestContext<Self::Context>,
path_params: Path<VolumePathParam>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
/// Request removal of a read_only_parent from a disk.
///
/// This is a thin wrapper around the volume_remove_read_only_parent saga.
/// All we are doing here is, given a disk UUID, figure out what the
/// volume_id is for that disk, then use that to call the
/// disk_remove_read_only_parent saga on it.
#[endpoint {
method = POST,
path = "/disk/{disk_id}/remove-read-only-parent",
}]
async fn cpapi_disk_remove_read_only_parent(
rqctx: RequestContext<Self::Context>,
path_params: Path<DiskPathParam>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
/// Accept a registration from a new metric producer
#[endpoint {
method = POST,
path = "/metrics/producers",
}]
async fn cpapi_producers_post(
request_context: RequestContext<Self::Context>,
producer_info: TypedBody<ProducerEndpoint>,
) -> Result<HttpResponseCreated<ProducerRegistrationResponse>, HttpError>;
/// List all metric producers assigned to an oximeter collector.
#[endpoint {
method = GET,
path = "/metrics/collectors/{collector_id}/producers",
}]
async fn cpapi_assigned_producers_list(
request_context: RequestContext<Self::Context>,
path_params: Path<CollectorIdPathParams>,
query_params: Query<PaginatedById>,
) -> Result<HttpResponseOk<ResultsPage<ProducerEndpoint>>, HttpError>;
/// Accept a notification of a new oximeter collection server.
#[endpoint {
method = POST,
path = "/metrics/collectors",
}]
async fn cpapi_collectors_post(
request_context: RequestContext<Self::Context>,
oximeter_info: TypedBody<OximeterInfo>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
/// An Upstairs will notify this endpoint when a repair starts
#[endpoint {
method = POST,
path = "/crucible/0/upstairs/{upstairs_id}/repair-start",
}]
async fn cpapi_upstairs_repair_start(
rqctx: RequestContext<Self::Context>,
path_params: Path<UpstairsPathParam>,
repair_start_info: TypedBody<RepairStartInfo>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
/// An Upstairs will notify this endpoint when a repair finishes.
#[endpoint {
method = POST,
path = "/crucible/0/upstairs/{upstairs_id}/repair-finish",
}]
async fn cpapi_upstairs_repair_finish(
rqctx: RequestContext<Self::Context>,
path_params: Path<UpstairsPathParam>,
repair_finish_info: TypedBody<RepairFinishInfo>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
/// An Upstairs will update this endpoint with the progress of a repair
#[endpoint {
method = POST,
path = "/crucible/0/upstairs/{upstairs_id}/repair/{repair_id}/progress",
}]
async fn cpapi_upstairs_repair_progress(
rqctx: RequestContext<Self::Context>,
path_params: Path<UpstairsRepairPathParam>,
repair_progress: TypedBody<RepairProgress>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
/// An Upstairs will update this endpoint if a Downstairs client task is
/// requested to stop
#[endpoint {
method = POST,
path = "/crucible/0/upstairs/{upstairs_id}/downstairs/{downstairs_id}/stop-request",
}]
async fn cpapi_downstairs_client_stop_request(
rqctx: RequestContext<Self::Context>,
path_params: Path<UpstairsDownstairsPathParam>,
downstairs_client_stop_request: TypedBody<DownstairsClientStopRequest>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
/// An Upstairs will update this endpoint if a Downstairs client task stops for
/// any reason (not just after being requested to)
#[endpoint {
method = POST,
path = "/crucible/0/upstairs/{upstairs_id}/downstairs/{downstairs_id}/stopped",
}]
async fn cpapi_downstairs_client_stopped(
rqctx: RequestContext<Self::Context>,
path_params: Path<UpstairsDownstairsPathParam>,
downstairs_client_stopped: TypedBody<DownstairsClientStopped>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
// NAT RPW internal APIs
/// Fetch NAT ChangeSet
///
/// NOTE: This is no longer just IPv4, it includes IPv6. However, this API
/// cannot have forward-incompatable changes (e.g. clients running against
/// new API definitions need to be able to talk to older server still) so
/// we cannot add a generic nat_changeset API endpoint which would only be
/// backwards compatiable. So for the time being we are stuck with this
/// misleading name.
///
/// Caller provides their generation as `from_gen`, along with a query
/// parameter for the page size (`limit`). Endpoint will return changes
/// that have occured since the caller's generation number up to the latest
/// change or until the `limit` is reached. If there are no changes, an
/// empty vec is returned.
#[endpoint {
method = GET,
path = "/nat/ipv4/changeset/{from_gen}"
}]
async fn ipv4_nat_changeset(
rqctx: RequestContext<Self::Context>,
path_params: Path<RpwNatPathParam>,
query_params: Query<RpwNatQueryParam>,
) -> Result<HttpResponseOk<Vec<NatEntryView>>, HttpError>;
/// This endpoint has been abandoned and will permanently return a 410 Gone
/// error.
//
// Remove this once we can appropriately handle client-side versioned APIs.
// See https://github.com/oxidecomputer/omicron/issues/9290 for details.
#[endpoint {
method = GET,
path = "/probes/{sled}"
}]
async fn probes_get(
rqctx: RequestContext<Self::Context>,
path_params: Path<ProbePathParam>,
query_params: Query<PaginatedById>,
) -> Result<HttpResponseOk<Vec<ProbeInfo>>, HttpError>;
/// This endpoint has been abandoned and will permanently return a 410 Gone
/// error.
//
// Remove this once we can appropriately handle client-side versioned APIs.
// See https://github.com/oxidecomputer/omicron/issues/9290 for details.
#[endpoint {
method = POST,
path = "/refresh-vpc-routes"
}]
async fn refresh_vpc_routes(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
}
/// Information about a networking probe.
//
// This type is used by the abandoned `probes_get` endpoint which always
// returns 410 Gone. That type uses V1 of the shared network interface type. We
// cannot update the actual API type, since that's part of the client-side
// versioned Nexus internal API. When that's supported, we can make this change
// versioned too.
//
// See https://github.com/oxidecomputer/omicron/issues/9290.
#[derive(Debug, Clone, JsonSchema, Serialize, Deserialize)]
pub struct ProbeInfo {
pub id: Uuid,
pub name: Name,
#[schemars(with = "Uuid")]
pub sled: SledUuid,
pub external_ips: Vec<ProbeExternalIp>,
pub interface: NetworkInterfaceV1,
}
/// Path parameters for Sled Agent requests (internal API)
#[derive(Deserialize, JsonSchema)]
pub struct SledAgentPathParam {
pub sled_id: SledUuid,
}
/// Path parameters for Disk requests (internal API)
#[derive(Deserialize, JsonSchema)]
pub struct DiskPathParam {
pub disk_id: Uuid,
}
/// Path parameters for Volume requests (internal API)
#[derive(Deserialize, JsonSchema)]
pub struct VolumePathParam {
pub volume_id: VolumeUuid,
}
/// Path parameters for Switch requests.
#[derive(Deserialize, JsonSchema)]
pub struct SwitchPathParam {
pub switch_id: Uuid,
}
/// Path parameters for VMM requests (internal API)
#[derive(Deserialize, JsonSchema)]
pub struct VmmPathParam {
pub propolis_id: PropolisUuid,
}
#[derive(Clone, Copy, Debug, Deserialize, JsonSchema, Serialize)]
pub struct CollectorIdPathParams {
/// The ID of the oximeter collector.
pub collector_id: Uuid,
}
/// Path parameters for Upstairs requests (internal API)
#[derive(Deserialize, JsonSchema)]
pub struct UpstairsPathParam {
pub upstairs_id: TypedUuid<UpstairsKind>,
}
/// Path parameters for Upstairs requests (internal API)
#[derive(Deserialize, JsonSchema)]
pub struct UpstairsRepairPathParam {
pub upstairs_id: TypedUuid<UpstairsKind>,
pub repair_id: TypedUuid<UpstairsRepairKind>,
}
/// Path parameters for Downstairs requests (internal API)
#[derive(Deserialize, JsonSchema)]
pub struct UpstairsDownstairsPathParam {
pub upstairs_id: TypedUuid<UpstairsKind>,
pub downstairs_id: TypedUuid<DownstairsKind>,
}
/// Query parameters for Background Task activation requests.
#[derive(Deserialize, JsonSchema)]
pub struct BackgroundTasksActivateRequest {
pub bgtask_names: BTreeSet<String>,
}
/// Path parameters for NAT ChangeSet
#[derive(Deserialize, JsonSchema)]
pub struct RpwNatPathParam {
/// which change number to start generating
/// the change set from
pub from_gen: i64,
}
/// Query parameters for NAT ChangeSet
#[derive(Deserialize, JsonSchema)]
pub struct RpwNatQueryParam {
pub limit: u32,
}
#[derive(Clone, Debug, Serialize, JsonSchema)]
pub struct SledId {
pub id: SledUuid,
}
/// Path parameters for probes
#[derive(Deserialize, JsonSchema)]
pub struct ProbePathParam {
#[schemars(with = "Uuid")]
pub sled: SledUuid,
}