Browse code

api/types/network: define `ConnectRequest` and `DisconnectRequest`

Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>

Austin Vazquez authored on 2025/10/23 04:28:00
Showing 14 changed files
... ...
@@ -2842,6 +2842,42 @@ definitions:
2842 2842
         type: "string"
2843 2843
         x-nullable: false
2844 2844
 
2845
+  NetworkConnectRequest:
2846
+    description: |
2847
+      NetworkConnectRequest represents the data to be used to connect a container to a network.
2848
+    type: "object"
2849
+    x-go-name: "ConnectRequest"
2850
+    required: ["Container"]
2851
+    properties:
2852
+      Container:
2853
+        type: "string"
2854
+        description: "The ID or name of the container to connect to the network."
2855
+        x-nullable: false
2856
+        example: "3613f73ba0e4"
2857
+      EndpointConfig:
2858
+        $ref: "#/definitions/EndpointSettings"
2859
+        x-nullable: true
2860
+
2861
+  NetworkDisconnectRequest:
2862
+    description: |
2863
+      NetworkDisconnectRequest represents the data to be used to disconnect a container from a network.
2864
+    type: "object"
2865
+    x-go-name: "DisconnectRequest"
2866
+    required: ["Container"]
2867
+    properties:
2868
+      Container:
2869
+        type: "string"
2870
+        description: "The ID or name of the container to disconnect from the network."
2871
+        x-nullable: false
2872
+        example: "3613f73ba0e4"
2873
+      Force:
2874
+        type: "boolean"
2875
+        description: "Force the container to disconnect from the network."
2876
+        default: false
2877
+        x-nullable: false
2878
+        x-omitempty: false
2879
+        example: false
2880
+
2845 2881
   EndpointSettings:
2846 2882
     description: "Configuration for a network endpoint."
2847 2883
     type: "object"
... ...
@@ -11359,22 +11395,7 @@ paths:
11359 11359
           in: "body"
11360 11360
           required: true
11361 11361
           schema:
11362
-            type: "object"
11363
-            title: "NetworkConnectRequest"
11364
-            properties:
11365
-              Container:
11366
-                type: "string"
11367
-                description: "The ID or name of the container to connect to the network."
11368
-              EndpointConfig:
11369
-                $ref: "#/definitions/EndpointSettings"
11370
-            example:
11371
-              Container: "3613f73ba0e4"
11372
-              EndpointConfig:
11373
-                IPAMConfig:
11374
-                  IPv4Address: "172.24.56.89"
11375
-                  IPv6Address: "2001:db8::5689"
11376
-                MacAddress: "02:42:ac:12:05:02"
11377
-                Priority: 100
11362
+            $ref: "#/definitions/NetworkConnectRequest"
11378 11363
       tags: ["Network"]
11379 11364
 
11380 11365
   /networks/{id}/disconnect:
... ...
@@ -11408,17 +11429,7 @@ paths:
11408 11408
           in: "body"
11409 11409
           required: true
11410 11410
           schema:
11411
-            type: "object"
11412
-            title: "NetworkDisconnectRequest"
11413
-            properties:
11414
-              Container:
11415
-                type: "string"
11416
-                description: |
11417
-                  The ID or name of the container to disconnect from the network.
11418
-              Force:
11419
-                type: "boolean"
11420
-                description: |
11421
-                  Force the container to disconnect from the network.
11411
+            $ref: "#/definitions/NetworkDisconnectRequest"
11422 11412
       tags: ["Network"]
11423 11413
   /networks/prune:
11424 11414
     post:
... ...
@@ -2842,6 +2842,42 @@ definitions:
2842 2842
         type: "string"
2843 2843
         x-nullable: false
2844 2844
 
2845
+  NetworkConnectRequest:
2846
+    description: |
2847
+      NetworkConnectRequest represents the data to be used to connect a container to a network.
2848
+    type: "object"
2849
+    x-go-name: "ConnectRequest"
2850
+    required: ["Container"]
2851
+    properties:
2852
+      Container:
2853
+        type: "string"
2854
+        description: "The ID or name of the container to connect to the network."
2855
+        x-nullable: false
2856
+        example: "3613f73ba0e4"
2857
+      EndpointConfig:
2858
+        $ref: "#/definitions/EndpointSettings"
2859
+        x-nullable: true
2860
+
2861
+  NetworkDisconnectRequest:
2862
+    description: |
2863
+      NetworkDisconnectRequest represents the data to be used to disconnect a container from a network.
2864
+    type: "object"
2865
+    x-go-name: "DisconnectRequest"
2866
+    required: ["Container"]
2867
+    properties:
2868
+      Container:
2869
+        type: "string"
2870
+        description: "The ID or name of the container to disconnect from the network."
2871
+        x-nullable: false
2872
+        example: "3613f73ba0e4"
2873
+      Force:
2874
+        type: "boolean"
2875
+        description: "Force the container to disconnect from the network."
2876
+        default: false
2877
+        x-nullable: false
2878
+        x-omitempty: false
2879
+        example: false
2880
+
2845 2881
   EndpointSettings:
2846 2882
     description: "Configuration for a network endpoint."
2847 2883
     type: "object"
... ...
@@ -11359,22 +11395,7 @@ paths:
11359 11359
           in: "body"
11360 11360
           required: true
11361 11361
           schema:
11362
-            type: "object"
11363
-            title: "NetworkConnectRequest"
11364
-            properties:
11365
-              Container:
11366
-                type: "string"
11367
-                description: "The ID or name of the container to connect to the network."
11368
-              EndpointConfig:
11369
-                $ref: "#/definitions/EndpointSettings"
11370
-            example:
11371
-              Container: "3613f73ba0e4"
11372
-              EndpointConfig:
11373
-                IPAMConfig:
11374
-                  IPv4Address: "172.24.56.89"
11375
-                  IPv6Address: "2001:db8::5689"
11376
-                MacAddress: "02:42:ac:12:05:02"
11377
-                Priority: 100
11362
+            $ref: "#/definitions/NetworkConnectRequest"
11378 11363
       tags: ["Network"]
11379 11364
 
11380 11365
   /networks/{id}/disconnect:
... ...
@@ -11408,17 +11429,7 @@ paths:
11408 11408
           in: "body"
11409 11409
           required: true
11410 11410
           schema:
11411
-            type: "object"
11412
-            title: "NetworkDisconnectRequest"
11413
-            properties:
11414
-              Container:
11415
-                type: "string"
11416
-                description: |
11417
-                  The ID or name of the container to disconnect from the network.
11418
-              Force:
11419
-                type: "boolean"
11420
-                description: |
11421
-                  Force the container to disconnect from the network.
11411
+            $ref: "#/definitions/NetworkDisconnectRequest"
11422 11412
       tags: ["Network"]
11423 11413
   /networks/prune:
11424 11414
     post:
11425 11415
new file mode 100644
... ...
@@ -0,0 +1,20 @@
0
+// Code generated by go-swagger; DO NOT EDIT.
1
+
2
+package network
3
+
4
+// This file was generated by the swagger tool.
5
+// Editing this file might prove futile when you re-run the swagger generate command
6
+
7
+// ConnectRequest NetworkConnectRequest represents the data to be used to connect a container to a network.
8
+//
9
+// swagger:model ConnectRequest
10
+type ConnectRequest struct {
11
+
12
+	// The ID or name of the container to connect to the network.
13
+	// Example: 3613f73ba0e4
14
+	// Required: true
15
+	Container string `json:"Container"`
16
+
17
+	// endpoint config
18
+	EndpointConfig *EndpointSettings `json:"EndpointConfig,omitempty"`
19
+}
0 20
new file mode 100644
... ...
@@ -0,0 +1,21 @@
0
+// Code generated by go-swagger; DO NOT EDIT.
1
+
2
+package network
3
+
4
+// This file was generated by the swagger tool.
5
+// Editing this file might prove futile when you re-run the swagger generate command
6
+
7
+// DisconnectRequest NetworkDisconnectRequest represents the data to be used to disconnect a container from a network.
8
+//
9
+// swagger:model DisconnectRequest
10
+type DisconnectRequest struct {
11
+
12
+	// The ID or name of the container to disconnect from the network.
13
+	// Example: 3613f73ba0e4
14
+	// Required: true
15
+	Container string `json:"Container"`
16
+
17
+	// Force the container to disconnect from the network.
18
+	// Example: false
19
+	Force bool `json:"Force"`
20
+}
... ...
@@ -18,11 +18,11 @@ func (cli *Client) NetworkConnect(ctx context.Context, networkID, containerID st
18 18
 		return err
19 19
 	}
20 20
 
21
-	nc := NetworkConnectOptions{
21
+	req := network.ConnectRequest{
22 22
 		Container:      containerID,
23 23
 		EndpointConfig: config,
24 24
 	}
25
-	resp, err := cli.post(ctx, "/networks/"+networkID+"/connect", nil, nc, nil)
25
+	resp, err := cli.post(ctx, "/networks/"+networkID+"/connect", nil, req, nil)
26 26
 	defer ensureReaderClosed(resp)
27 27
 	return err
28 28
 }
... ...
@@ -38,7 +38,7 @@ func TestNetworkConnectEmptyNilEndpointSettings(t *testing.T) {
38 38
 			return nil, err
39 39
 		}
40 40
 
41
-		var connect NetworkConnectOptions
41
+		var connect network.ConnectRequest
42 42
 		if err := json.NewDecoder(req.Body).Decode(&connect); err != nil {
43 43
 			return nil, err
44 44
 		}
... ...
@@ -2,6 +2,8 @@ package client
2 2
 
3 3
 import (
4 4
 	"context"
5
+
6
+	"github.com/moby/moby/api/types/network"
5 7
 )
6 8
 
7 9
 // NetworkDisconnect disconnects a container from an existent network in the docker host.
... ...
@@ -16,11 +18,11 @@ func (cli *Client) NetworkDisconnect(ctx context.Context, networkID, containerID
16 16
 		return err
17 17
 	}
18 18
 
19
-	nd := NetworkDisconnectOptions{
19
+	req := network.DisconnectRequest{
20 20
 		Container: containerID,
21 21
 		Force:     force,
22 22
 	}
23
-	resp, err := cli.post(ctx, "/networks/"+networkID+"/disconnect", nil, nd, nil)
23
+	resp, err := cli.post(ctx, "/networks/"+networkID+"/disconnect", nil, req, nil)
24 24
 	defer ensureReaderClosed(resp)
25 25
 	return err
26 26
 }
... ...
@@ -8,6 +8,7 @@ import (
8 8
 	"testing"
9 9
 
10 10
 	cerrdefs "github.com/containerd/errdefs"
11
+	"github.com/moby/moby/api/types/network"
11 12
 	"gotest.tools/v3/assert"
12 13
 	is "gotest.tools/v3/assert/cmp"
13 14
 )
... ...
@@ -37,7 +38,7 @@ func TestNetworkDisconnect(t *testing.T) {
37 37
 			return nil, err
38 38
 		}
39 39
 
40
-		var disconnect NetworkDisconnectOptions
40
+		var disconnect network.DisconnectRequest
41 41
 		if err := json.NewDecoder(req.Body).Decode(&disconnect); err != nil {
42 42
 			return nil, err
43 43
 		}
... ...
@@ -65,7 +65,9 @@ generate_model types/network --keep-spec-order --additional-initialism=IPAM <<-
65 65
 	EndpointResource
66 66
 	IPAMStatus
67 67
 	Network
68
+	NetworkConnectRequest
68 69
 	NetworkCreateResponse
70
+	NetworkDisconnectRequest
69 71
 	NetworkInspect
70 72
 	NetworkStatus
71 73
 	NetworkSummary
... ...
@@ -236,7 +236,7 @@ func createNetwork(t *testing.T, config network.CreateRequest, expectedStatusCod
236 236
 }
237 237
 
238 238
 func connectNetwork(t *testing.T, nid, cid string) {
239
-	resp, _, err := request.Post(testutil.GetContext(t), "/networks/"+nid+"/connect", request.JSONBody(client.NetworkConnectOptions{
239
+	resp, _, err := request.Post(testutil.GetContext(t), "/networks/"+nid+"/connect", request.JSONBody(network.ConnectRequest{
240 240
 		Container: cid,
241 241
 	}))
242 242
 	assert.NilError(t, err)
243 243
new file mode 100644
... ...
@@ -0,0 +1,20 @@
0
+// Code generated by go-swagger; DO NOT EDIT.
1
+
2
+package network
3
+
4
+// This file was generated by the swagger tool.
5
+// Editing this file might prove futile when you re-run the swagger generate command
6
+
7
+// ConnectRequest NetworkConnectRequest represents the data to be used to connect a container to a network.
8
+//
9
+// swagger:model ConnectRequest
10
+type ConnectRequest struct {
11
+
12
+	// The ID or name of the container to connect to the network.
13
+	// Example: 3613f73ba0e4
14
+	// Required: true
15
+	Container string `json:"Container"`
16
+
17
+	// endpoint config
18
+	EndpointConfig *EndpointSettings `json:"EndpointConfig,omitempty"`
19
+}
0 20
new file mode 100644
... ...
@@ -0,0 +1,21 @@
0
+// Code generated by go-swagger; DO NOT EDIT.
1
+
2
+package network
3
+
4
+// This file was generated by the swagger tool.
5
+// Editing this file might prove futile when you re-run the swagger generate command
6
+
7
+// DisconnectRequest NetworkDisconnectRequest represents the data to be used to disconnect a container from a network.
8
+//
9
+// swagger:model DisconnectRequest
10
+type DisconnectRequest struct {
11
+
12
+	// The ID or name of the container to disconnect from the network.
13
+	// Example: 3613f73ba0e4
14
+	// Required: true
15
+	Container string `json:"Container"`
16
+
17
+	// Force the container to disconnect from the network.
18
+	// Example: false
19
+	Force bool `json:"Force"`
20
+}
... ...
@@ -18,11 +18,11 @@ func (cli *Client) NetworkConnect(ctx context.Context, networkID, containerID st
18 18
 		return err
19 19
 	}
20 20
 
21
-	nc := NetworkConnectOptions{
21
+	req := network.ConnectRequest{
22 22
 		Container:      containerID,
23 23
 		EndpointConfig: config,
24 24
 	}
25
-	resp, err := cli.post(ctx, "/networks/"+networkID+"/connect", nil, nc, nil)
25
+	resp, err := cli.post(ctx, "/networks/"+networkID+"/connect", nil, req, nil)
26 26
 	defer ensureReaderClosed(resp)
27 27
 	return err
28 28
 }
... ...
@@ -2,6 +2,8 @@ package client
2 2
 
3 3
 import (
4 4
 	"context"
5
+
6
+	"github.com/moby/moby/api/types/network"
5 7
 )
6 8
 
7 9
 // NetworkDisconnect disconnects a container from an existent network in the docker host.
... ...
@@ -16,11 +18,11 @@ func (cli *Client) NetworkDisconnect(ctx context.Context, networkID, containerID
16 16
 		return err
17 17
 	}
18 18
 
19
-	nd := NetworkDisconnectOptions{
19
+	req := network.DisconnectRequest{
20 20
 		Container: containerID,
21 21
 		Force:     force,
22 22
 	}
23
-	resp, err := cli.post(ctx, "/networks/"+networkID+"/disconnect", nil, nd, nil)
23
+	resp, err := cli.post(ctx, "/networks/"+networkID+"/disconnect", nil, req, nil)
24 24
 	defer ensureReaderClosed(resp)
25 25
 	return err
26 26
 }