github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/pkg/api/server/register_networks.go (about) 1 package server 2 3 import ( 4 "net/http" 5 6 "github.com/hanks177/podman/v4/pkg/api/handlers/compat" 7 "github.com/hanks177/podman/v4/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. This endpoint is current a no-op 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 // 500: 148 // $ref: "#/responses/internalError" 149 r.HandleFunc(VersionedPath("/networks/{name}/connect"), s.APIHandler(compat.Connect)).Methods(http.MethodPost) 150 r.HandleFunc("/networks/{name}/connect", s.APIHandler(compat.Connect)).Methods(http.MethodPost) 151 // swagger:operation POST /networks/{name}/disconnect compat NetworkDisconnect 152 // --- 153 // tags: 154 // - networks (compat) 155 // summary: Disconnect container from network 156 // description: Disconnect a container from a network. This endpoint is current a no-op 157 // produces: 158 // - application/json 159 // parameters: 160 // - in: path 161 // name: name 162 // type: string 163 // required: true 164 // description: the name of the network 165 // - in: body 166 // name: create 167 // description: attributes for disconnecting a container from a network 168 // schema: 169 // $ref: "#/definitions/networkDisconnectRequest" 170 // responses: 171 // 200: 172 // description: OK 173 // 400: 174 // $ref: "#/responses/badParamError" 175 // 500: 176 // $ref: "#/responses/internalError" 177 r.HandleFunc(VersionedPath("/networks/{name}/disconnect"), s.APIHandler(compat.Disconnect)).Methods(http.MethodPost) 178 r.HandleFunc("/networks/{name}/disconnect", s.APIHandler(compat.Disconnect)).Methods(http.MethodPost) 179 // swagger:operation POST /networks/prune compat NetworkPrune 180 // --- 181 // tags: 182 // - networks (compat) 183 // summary: Delete unused networks 184 // description: Remove CNI networks that do not have containers 185 // produces: 186 // - application/json 187 // parameters: 188 // - in: query 189 // name: filters 190 // type: string 191 // description: | 192 // Filters to process on the prune list, encoded as JSON (a map[string][]string). 193 // Available filters: 194 // - `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. 195 // - `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. 196 // responses: 197 // 200: 198 // description: OK 199 // schema: 200 // type: object 201 // properties: 202 // NetworksDeleted: 203 // type: array 204 // items: 205 // type: string 206 // 500: 207 // $ref: "#/responses/internalError" 208 r.HandleFunc(VersionedPath("/networks/prune"), s.APIHandler(compat.Prune)).Methods(http.MethodPost) 209 r.HandleFunc("/networks/prune", s.APIHandler(compat.Prune)).Methods(http.MethodPost) 210 211 // swagger:operation DELETE /libpod/networks/{name} libpod NetworkDeleteLibpod 212 // --- 213 // tags: 214 // - networks 215 // summary: Remove a network 216 // description: Remove a CNI configured network 217 // parameters: 218 // - in: path 219 // name: name 220 // type: string 221 // required: true 222 // description: the name of the network 223 // - in: query 224 // name: force 225 // type: boolean 226 // description: remove containers associated with network 227 // produces: 228 // - application/json 229 // responses: 230 // 200: 231 // $ref: "#/responses/networkRmResponse" 232 // 404: 233 // $ref: "#/responses/networkNotFound" 234 // 500: 235 // $ref: "#/responses/internalError" 236 r.HandleFunc(VersionedPath("/libpod/networks/{name}"), s.APIHandler(libpod.RemoveNetwork)).Methods(http.MethodDelete) 237 // swagger:operation GET /libpod/networks/{name}/exists libpod NetworkExistsLibpod 238 // --- 239 // tags: 240 // - networks 241 // summary: Network exists 242 // description: Check if network exists 243 // parameters: 244 // - in: path 245 // name: name 246 // type: string 247 // required: true 248 // description: the name or ID of the network 249 // produces: 250 // - application/json 251 // responses: 252 // 204: 253 // description: network exists 254 // 404: 255 // $ref: '#/responses/networkNotFound' 256 // 500: 257 // $ref: '#/responses/internalError' 258 r.Handle(VersionedPath("/libpod/networks/{name}/exists"), s.APIHandler(libpod.ExistsNetwork)).Methods(http.MethodGet) 259 // swagger:operation GET /libpod/networks/json libpod NetworkListLibpod 260 // --- 261 // tags: 262 // - networks 263 // summary: List networks 264 // description: | 265 // Display summary of network configurations. 266 // - In a 200 response, all of the fields named Bytes are returned as a Base64 encoded string. 267 // parameters: 268 // - in: query 269 // name: filters 270 // type: string 271 // description: | 272 // JSON encoded value of the filters (a `map[string][]string`) to process on the network list. Available filters: 273 // - `name=[name]` Matches network name (accepts regex). 274 // - `id=[id]` Matches for full or partial ID. 275 // - `driver=[driver]` Only bridge is supported. 276 // - `label=[key]` or `label=[key=value]` Matches networks based on the presence of a label alone or a label and a value. 277 // - `until=[timestamp]` Matches all networks that were create before the given timestamp. 278 // produces: 279 // - application/json 280 // responses: 281 // 200: 282 // $ref: "#/responses/networkListLibpod" 283 // 500: 284 // $ref: "#/responses/internalError" 285 r.HandleFunc(VersionedPath("/libpod/networks/json"), s.APIHandler(libpod.ListNetworks)).Methods(http.MethodGet) 286 // swagger:operation GET /libpod/networks/{name}/json libpod NetworkInspectLibpod 287 // --- 288 // tags: 289 // - networks 290 // summary: Inspect a network 291 // description: | 292 // Display low level configuration for a CNI network. 293 // - In a 200 response, all of the fields named Bytes are returned as a Base64 encoded string. 294 // parameters: 295 // - in: path 296 // name: name 297 // type: string 298 // required: true 299 // description: the name of the network 300 // produces: 301 // - application/json 302 // responses: 303 // 200: 304 // $ref: "#/responses/networkInspectResponse" 305 // 404: 306 // $ref: "#/responses/networkNotFound" 307 // 500: 308 // $ref: "#/responses/internalError" 309 r.HandleFunc(VersionedPath("/libpod/networks/{name}/json"), s.APIHandler(libpod.InspectNetwork)).Methods(http.MethodGet) 310 r.HandleFunc(VersionedPath("/libpod/networks/{name}"), s.APIHandler(libpod.InspectNetwork)).Methods(http.MethodGet) 311 // swagger:operation POST /libpod/networks/create libpod NetworkCreateLibpod 312 // --- 313 // tags: 314 // - networks 315 // summary: Create network 316 // description: Create a new network configuration 317 // produces: 318 // - application/json 319 // parameters: 320 // - in: body 321 // name: create 322 // description: attributes for creating a network 323 // schema: 324 // $ref: "#/definitions/networkCreateLibpod" 325 // responses: 326 // 200: 327 // $ref: "#/responses/networkCreateResponse" 328 // 400: 329 // $ref: "#/responses/badParamError" 330 // 409: 331 // $ref: "#/responses/conflictError" 332 // 500: 333 // $ref: "#/responses/internalError" 334 r.HandleFunc(VersionedPath("/libpod/networks/create"), s.APIHandler(libpod.CreateNetwork)).Methods(http.MethodPost) 335 // swagger:operation POST /libpod/networks/{name}/connect libpod NetworkConnectLibpod 336 // --- 337 // tags: 338 // - networks 339 // summary: Connect container to network 340 // description: Connect a container to a network. 341 // produces: 342 // - application/json 343 // parameters: 344 // - in: path 345 // name: name 346 // type: string 347 // required: true 348 // description: the name of the network 349 // - in: body 350 // name: create 351 // description: attributes for connecting a container to a network 352 // schema: 353 // $ref: "#/definitions/networkConnectRequestLibpod" 354 // responses: 355 // 200: 356 // description: OK 357 // 404: 358 // $ref: "#/responses/networkNotFound" 359 // 500: 360 // $ref: "#/responses/internalError" 361 r.HandleFunc(VersionedPath("/libpod/networks/{name}/connect"), s.APIHandler(libpod.Connect)).Methods(http.MethodPost) 362 // swagger:operation POST /libpod/networks/{name}/disconnect libpod NetworkDisconnectLibpod 363 // --- 364 // tags: 365 // - networks 366 // summary: Disconnect container from network 367 // description: Disconnect a container from a network. 368 // produces: 369 // - application/json 370 // parameters: 371 // - in: path 372 // name: name 373 // type: string 374 // required: true 375 // description: the name of the network 376 // - in: body 377 // name: create 378 // description: attributes for disconnecting a container from a network 379 // schema: 380 // $ref: "#/definitions/networkDisconnectRequest" 381 // responses: 382 // 200: 383 // description: OK 384 // 404: 385 // $ref: "#/responses/networkNotFound" 386 // 500: 387 // $ref: "#/responses/internalError" 388 r.HandleFunc(VersionedPath("/libpod/networks/{name}/disconnect"), s.APIHandler(compat.Disconnect)).Methods(http.MethodPost) 389 // swagger:operation POST /libpod/networks/prune libpod NetworkPruneLibpod 390 // --- 391 // tags: 392 // - networks 393 // summary: Delete unused networks 394 // description: Remove CNI networks that do not have containers 395 // produces: 396 // - application/json 397 // parameters: 398 // - in: query 399 // name: filters 400 // type: string 401 // description: | 402 // Filters to process on the prune list, encoded as JSON (a `map[string][]string`). 403 // Available filters: 404 // - `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. 405 // - `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. 406 // responses: 407 // 200: 408 // $ref: "#/responses/networkPruneResponse" 409 // 500: 410 // $ref: "#/responses/internalError" 411 r.HandleFunc(VersionedPath("/libpod/networks/prune"), s.APIHandler(libpod.Prune)).Methods(http.MethodPost) 412 return nil 413 }