podman

Форк
0
/
register_networks.go 
441 строка · 14.8 Кб
1
package server
2

3
import (
4
	"net/http"
5

6
	"github.com/containers/podman/v5/pkg/api/handlers/compat"
7
	"github.com/containers/podman/v5/pkg/api/handlers/libpod"
8
	"github.com/gorilla/mux"
9
)
10

11
func (s *APIServer) registerNetworkHandlers(r *mux.Router) error {
12
	// swagger:operation DELETE /networks/{name} compat NetworkDelete
13
	// ---
14
	// tags:
15
	//  - networks (compat)
16
	// summary: Remove a network
17
	// description: Remove a network
18
	// parameters:
19
	//  - in: path
20
	//    name: name
21
	//    type: string
22
	//    required: true
23
	//    description: the name of the network
24
	// produces:
25
	// - application/json
26
	// responses:
27
	//   204:
28
	//     description: no error
29
	//   404:
30
	//     $ref: "#/responses/networkNotFound"
31
	//   500:
32
	//     $ref: "#/responses/internalError"
33
	r.HandleFunc(VersionedPath("/networks/{name}"), s.APIHandler(compat.RemoveNetwork)).Methods(http.MethodDelete)
34
	r.HandleFunc("/networks/{name}", s.APIHandler(compat.RemoveNetwork)).Methods(http.MethodDelete)
35
	// swagger:operation GET /networks/{name} compat NetworkInspect
36
	// ---
37
	// tags:
38
	//  - networks (compat)
39
	// summary: Inspect a network
40
	// description: Display low level configuration network
41
	// parameters:
42
	//  - in: path
43
	//    name: name
44
	//    type: string
45
	//    required: true
46
	//    description: the name of the network
47
	//  - in: query
48
	//    name: verbose
49
	//    type: boolean
50
	//    required: false
51
	//    description: Detailed inspect output for troubleshooting
52
	//  - in: query
53
	//    name: scope
54
	//    type: string
55
	//    required: false
56
	//    description: Filter the network by scope (swarm, global, or local)
57
	// produces:
58
	// - application/json
59
	// responses:
60
	//   200:
61
	//     $ref: "#/responses/networkInspectCompat"
62
	//   404:
63
	//     $ref: "#/responses/networkNotFound"
64
	//   500:
65
	//     $ref: "#/responses/internalError"
66
	r.HandleFunc(VersionedPath("/networks/{name}"), s.APIHandler(compat.InspectNetwork)).Methods(http.MethodGet)
67
	r.HandleFunc("/networks/{name}", s.APIHandler(compat.InspectNetwork)).Methods(http.MethodGet)
68
	// swagger:operation GET /networks compat NetworkList
69
	// ---
70
	// tags:
71
	//  - networks (compat)
72
	// summary: List networks
73
	// description: Display summary of network configurations
74
	// parameters:
75
	//  - in: query
76
	//    name: filters
77
	//    type: string
78
	//    description: |
79
	//      JSON encoded value of the filters (a `map[string][]string`) to process on the network list. Currently available filters:
80
	//        - `name=[name]` Matches network name (accepts regex).
81
	//        - `id=[id]` Matches for full or partial ID.
82
	//        - `driver=[driver]` Only bridge is supported.
83
	//        - `label=[key]` or `label=[key=value]` Matches networks based on the presence of a label alone or a label and a value.
84
	// produces:
85
	// - application/json
86
	// responses:
87
	//   200:
88
	//     $ref: "#/responses/networkListCompat"
89
	//   500:
90
	//     $ref: "#/responses/internalError"
91
	r.HandleFunc(VersionedPath("/networks"), s.APIHandler(compat.ListNetworks)).Methods(http.MethodGet)
92
	r.HandleFunc("/networks", s.APIHandler(compat.ListNetworks)).Methods(http.MethodGet)
93
	// swagger:operation POST /networks/create compat NetworkCreate
94
	// ---
95
	// tags:
96
	//  - networks (compat)
97
	// summary: Create network
98
	// description: Create a network configuration
99
	// produces:
100
	// - application/json
101
	// parameters:
102
	//  - in: body
103
	//    name: create
104
	//    description: attributes for creating a network
105
	//    schema:
106
	//      $ref: "#/definitions/networkCreate"
107
	// responses:
108
	//   201:
109
	//     description: network created
110
	//     schema:
111
	//       type: object
112
	//       properties:
113
	//         Id:
114
	//           type: string
115
	//         Warning:
116
	//           type: string
117
	//   400:
118
	//     $ref: "#/responses/badParamError"
119
	//   500:
120
	//     $ref: "#/responses/internalError"
121
	r.HandleFunc(VersionedPath("/networks/create"), s.APIHandler(compat.CreateNetwork)).Methods(http.MethodPost)
122
	r.HandleFunc("/networks/create", s.APIHandler(compat.CreateNetwork)).Methods(http.MethodPost)
123
	// swagger:operation POST /networks/{name}/connect compat NetworkConnect
124
	// ---
125
	// tags:
126
	//  - networks (compat)
127
	// summary: Connect container to network
128
	// description: Connect a container to a network
129
	// produces:
130
	// - application/json
131
	// parameters:
132
	//  - in: path
133
	//    name: name
134
	//    type: string
135
	//    required: true
136
	//    description: the name of the network
137
	//  - in: body
138
	//    name: create
139
	//    description: attributes for connecting a container to a network
140
	//    schema:
141
	//      $ref: "#/definitions/networkConnectRequest"
142
	// responses:
143
	//   200:
144
	//     description: OK
145
	//   400:
146
	//     $ref: "#/responses/badParamError"
147
	//   403:
148
	//     $ref: "#/responses/networkConnectedError"
149
	//   500:
150
	//     $ref: "#/responses/internalError"
151
	r.HandleFunc(VersionedPath("/networks/{name}/connect"), s.APIHandler(compat.Connect)).Methods(http.MethodPost)
152
	r.HandleFunc("/networks/{name}/connect", s.APIHandler(compat.Connect)).Methods(http.MethodPost)
153
	// swagger:operation POST /networks/{name}/disconnect compat NetworkDisconnect
154
	// ---
155
	// tags:
156
	//  - networks (compat)
157
	// summary: Disconnect container from network
158
	// description: Disconnect a container from a network
159
	// produces:
160
	// - application/json
161
	// parameters:
162
	//  - in: path
163
	//    name: name
164
	//    type: string
165
	//    required: true
166
	//    description: the name of the network
167
	//  - in: body
168
	//    name: create
169
	//    description: attributes for disconnecting a container from a network
170
	//    schema:
171
	//      $ref: "#/definitions/networkDisconnectRequest"
172
	// responses:
173
	//   200:
174
	//     description: OK
175
	//   400:
176
	//     $ref: "#/responses/badParamError"
177
	//   500:
178
	//     $ref: "#/responses/internalError"
179
	r.HandleFunc(VersionedPath("/networks/{name}/disconnect"), s.APIHandler(compat.Disconnect)).Methods(http.MethodPost)
180
	r.HandleFunc("/networks/{name}/disconnect", s.APIHandler(compat.Disconnect)).Methods(http.MethodPost)
181
	// swagger:operation POST /networks/prune compat NetworkPrune
182
	// ---
183
	// tags:
184
	//  - networks (compat)
185
	// summary: Delete unused networks
186
	// description: Remove networks that do not have containers
187
	// produces:
188
	// - application/json
189
	// parameters:
190
	//  - in: query
191
	//    name: filters
192
	//    type: string
193
	//    description: |
194
	//      Filters to process on the prune list, encoded as JSON (a map[string][]string).
195
	//      Available filters:
196
	//        - `until=<timestamp>` Prune networks created before this timestamp. The <timestamp> can be Unix timestamps, date formatted timestamps, or Go duration strings (e.g. `10m`, `1h30m`) computed relative to the daemon machine’s time.
197
	//        - `label` (`label=<key>`, `label=<key>=<value>`, `label!=<key>`, or `label!=<key>=<value>`) Prune networks with (or without, in case `label!=...` is used) the specified labels.
198
	// responses:
199
	//   200:
200
	//     description: OK
201
	//     schema:
202
	//       type: object
203
	//       properties:
204
	//         NetworksDeleted:
205
	//           type: array
206
	//           items:
207
	//             type: string
208
	//   500:
209
	//     $ref: "#/responses/internalError"
210
	r.HandleFunc(VersionedPath("/networks/prune"), s.APIHandler(compat.Prune)).Methods(http.MethodPost)
211
	r.HandleFunc("/networks/prune", s.APIHandler(compat.Prune)).Methods(http.MethodPost)
212

213
	// swagger:operation DELETE /libpod/networks/{name} libpod NetworkDeleteLibpod
214
	// ---
215
	// tags:
216
	//  - networks
217
	// summary: Remove a network
218
	// description: Remove a configured network
219
	// parameters:
220
	//  - in: path
221
	//    name: name
222
	//    type: string
223
	//    required: true
224
	//    description: the name of the network
225
	//  - in: query
226
	//    name: force
227
	//    type: boolean
228
	//    description: remove containers associated with network
229
	// produces:
230
	// - application/json
231
	// responses:
232
	//   200:
233
	//     $ref: "#/responses/networkRmResponse"
234
	//   404:
235
	//     $ref: "#/responses/networkNotFound"
236
	//   500:
237
	//     $ref: "#/responses/internalError"
238
	r.HandleFunc(VersionedPath("/libpod/networks/{name}"), s.APIHandler(libpod.RemoveNetwork)).Methods(http.MethodDelete)
239
	// swagger:operation POST /libpod/networks/{name}/update libpod NetworkUpdateLibpod
240
	// ---
241
	// tags:
242
	//  - networks
243
	// summary: Update existing podman network
244
	// description: Update existing podman network
245
	// produces:
246
	// - application/json
247
	// parameters:
248
	//  - in: path
249
	//    name: name
250
	//    type: string
251
	//    required: true
252
	//    description: the name or ID of the network
253
	//  - in: body
254
	//    name: update
255
	//    description: attributes for updating a netavark network
256
	//    schema:
257
	//      $ref: "#/definitions/networkUpdateRequestLibpod"
258
	// responses:
259
	//   200:
260
	//     description: OK
261
	//   400:
262
	//     $ref: "#/responses/badParamError"
263
	//   500:
264
	//     $ref: "#/responses/internalError"
265
	r.HandleFunc(VersionedPath("/libpod/networks/{name}/update"), s.APIHandler(libpod.UpdateNetwork)).Methods(http.MethodPost)
266
	// swagger:operation GET /libpod/networks/{name}/exists libpod NetworkExistsLibpod
267
	// ---
268
	// tags:
269
	//  - networks
270
	// summary: Network exists
271
	// description: Check if network exists
272
	// parameters:
273
	//  - in: path
274
	//    name: name
275
	//    type: string
276
	//    required: true
277
	//    description: the name or ID of the network
278
	// produces:
279
	// - application/json
280
	// responses:
281
	//   204:
282
	//     description: network exists
283
	//   404:
284
	//     $ref: '#/responses/networkNotFound'
285
	//   500:
286
	//     $ref: '#/responses/internalError'
287
	r.Handle(VersionedPath("/libpod/networks/{name}/exists"), s.APIHandler(libpod.ExistsNetwork)).Methods(http.MethodGet)
288
	// swagger:operation GET /libpod/networks/json libpod NetworkListLibpod
289
	// ---
290
	// tags:
291
	//  - networks
292
	// summary: List networks
293
	// description: |
294
	//   Display summary of network configurations.
295
	//     - In a 200 response, all of the fields named Bytes are returned as a Base64 encoded string.
296
	// parameters:
297
	//  - in: query
298
	//    name: filters
299
	//    type: string
300
	//    description: |
301
	//      JSON encoded value of the filters (a `map[string][]string`) to process on the network list. Available filters:
302
	//        - `name=[name]` Matches network name (accepts regex).
303
	//        - `id=[id]` Matches for full or partial ID.
304
	//        - `driver=[driver]` Only bridge is supported.
305
	//        - `label=[key]` or `label=[key=value]` Matches networks based on the presence of a label alone or a label and a value.
306
	//        - `until=[timestamp]` Matches all networks that were created before the given timestamp.
307
	// produces:
308
	// - application/json
309
	// responses:
310
	//   200:
311
	//     $ref: "#/responses/networkListLibpod"
312
	//   500:
313
	//     $ref: "#/responses/internalError"
314
	r.HandleFunc(VersionedPath("/libpod/networks/json"), s.APIHandler(libpod.ListNetworks)).Methods(http.MethodGet)
315
	// swagger:operation GET /libpod/networks/{name}/json libpod NetworkInspectLibpod
316
	// ---
317
	// tags:
318
	//  - networks
319
	// summary: Inspect a network
320
	// description: |
321
	//   Display configuration for a network.
322
	// parameters:
323
	//  - in: path
324
	//    name: name
325
	//    type: string
326
	//    required: true
327
	//    description: the name of the network
328
	// produces:
329
	// - application/json
330
	// responses:
331
	//   200:
332
	//     $ref: "#/responses/networkInspectResponse"
333
	//   404:
334
	//     $ref: "#/responses/networkNotFound"
335
	//   500:
336
	//     $ref: "#/responses/internalError"
337
	r.HandleFunc(VersionedPath("/libpod/networks/{name}/json"), s.APIHandler(libpod.InspectNetwork)).Methods(http.MethodGet)
338
	r.HandleFunc(VersionedPath("/libpod/networks/{name}"), s.APIHandler(libpod.InspectNetwork)).Methods(http.MethodGet)
339
	// swagger:operation POST /libpod/networks/create libpod NetworkCreateLibpod
340
	// ---
341
	// tags:
342
	//  - networks
343
	// summary: Create network
344
	// description: Create a new network configuration
345
	// produces:
346
	// - application/json
347
	// parameters:
348
	//  - in: body
349
	//    name: create
350
	//    description: attributes for creating a network
351
	//    schema:
352
	//      $ref: "#/definitions/networkCreateLibpod"
353
	// responses:
354
	//   200:
355
	//     $ref: "#/responses/networkCreateResponse"
356
	//   400:
357
	//     $ref: "#/responses/badParamError"
358
	//   409:
359
	//     $ref: "#/responses/conflictError"
360
	//   500:
361
	//     $ref: "#/responses/internalError"
362
	r.HandleFunc(VersionedPath("/libpod/networks/create"), s.APIHandler(libpod.CreateNetwork)).Methods(http.MethodPost)
363
	// swagger:operation POST /libpod/networks/{name}/connect libpod NetworkConnectLibpod
364
	// ---
365
	// tags:
366
	//  - networks
367
	// summary: Connect container to network
368
	// description: Connect a container to a network.
369
	// produces:
370
	// - application/json
371
	// parameters:
372
	//  - in: path
373
	//    name: name
374
	//    type: string
375
	//    required: true
376
	//    description: the name of the network
377
	//  - in: body
378
	//    name: create
379
	//    description: attributes for connecting a container to a network
380
	//    schema:
381
	//      $ref: "#/definitions/networkConnectRequestLibpod"
382
	// responses:
383
	//   200:
384
	//     description: OK
385
	//   404:
386
	//     $ref: "#/responses/networkNotFound"
387
	//   500:
388
	//     $ref: "#/responses/internalError"
389
	r.HandleFunc(VersionedPath("/libpod/networks/{name}/connect"), s.APIHandler(libpod.Connect)).Methods(http.MethodPost)
390
	// swagger:operation POST /libpod/networks/{name}/disconnect libpod NetworkDisconnectLibpod
391
	// ---
392
	// tags:
393
	//  - networks
394
	// summary: Disconnect container from network
395
	// description: Disconnect a container from a network.
396
	// produces:
397
	// - application/json
398
	// parameters:
399
	//  - in: path
400
	//    name: name
401
	//    type: string
402
	//    required: true
403
	//    description: the name of the network
404
	//  - in: body
405
	//    name: create
406
	//    description: attributes for disconnecting a container from a network
407
	//    schema:
408
	//      $ref: "#/definitions/networkDisconnectRequest"
409
	// responses:
410
	//   200:
411
	//     description: OK
412
	//   404:
413
	//     $ref: "#/responses/networkNotFound"
414
	//   500:
415
	//     $ref: "#/responses/internalError"
416
	r.HandleFunc(VersionedPath("/libpod/networks/{name}/disconnect"), s.APIHandler(compat.Disconnect)).Methods(http.MethodPost)
417
	// swagger:operation POST /libpod/networks/prune libpod NetworkPruneLibpod
418
	// ---
419
	// tags:
420
	//  - networks
421
	// summary: Delete unused networks
422
	// description: Remove networks that do not have containers
423
	// produces:
424
	// - application/json
425
	// parameters:
426
	//  - in: query
427
	//    name: filters
428
	//    type: string
429
	//    description: |
430
	//      Filters to process on the prune list, encoded as JSON (a `map[string][]string`).
431
	//      Available filters:
432
	//        - `until=<timestamp>` Prune networks created before this timestamp. The `<timestamp>` can be Unix timestamps, date formatted timestamps, or Go duration strings (e.g. `10m`, `1h30m`) computed relative to the daemon machine’s time.
433
	//        - `label` (`label=<key>`, `label=<key>=<value>`, `label!=<key>`, or `label!=<key>=<value>`) Prune networks with (or without, in case `label!=...` is used) the specified labels.
434
	// responses:
435
	//   200:
436
	//     $ref: "#/responses/networkPruneResponse"
437
	//   500:
438
	//     $ref: "#/responses/internalError"
439
	r.HandleFunc(VersionedPath("/libpod/networks/prune"), s.APIHandler(libpod.Prune)).Methods(http.MethodPost)
440
	return nil
441
}
442

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.