Migrate the type to the network package, and generate it from swagger.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -13,7 +13,7 @@ import ( |
| 13 | 13 |
// to provide network specific functionality. |
| 14 | 14 |
type Backend interface {
|
| 15 | 15 |
GetNetworks(filters.Args, backend.NetworkListConfig) ([]types.NetworkResource, error) |
| 16 |
- CreateNetwork(nc types.NetworkCreateRequest) (*types.NetworkCreateResponse, error) |
|
| 16 |
+ CreateNetwork(nc types.NetworkCreateRequest) (*network.CreateResponse, error) |
|
| 17 | 17 |
ConnectContainerToNetwork(containerName, networkName string, endpointConfig *network.EndpointSettings) error |
| 18 | 18 |
DisconnectContainerFromNetwork(containerName string, networkName string, force bool) error |
| 19 | 19 |
DeleteNetwork(networkID string) error |
| ... | ... |
@@ -2380,6 +2380,24 @@ definitions: |
| 2380 | 2380 |
type: "string" |
| 2381 | 2381 |
example: "10.133.77.91" |
| 2382 | 2382 |
|
| 2383 |
+ NetworkCreateResponse: |
|
| 2384 |
+ description: "OK response to NetworkCreate operation" |
|
| 2385 |
+ type: "object" |
|
| 2386 |
+ title: "NetworkCreateResponse" |
|
| 2387 |
+ x-go-name: "CreateResponse" |
|
| 2388 |
+ required: [Id, Warning] |
|
| 2389 |
+ properties: |
|
| 2390 |
+ Id: |
|
| 2391 |
+ description: "The ID of the created network." |
|
| 2392 |
+ type: "string" |
|
| 2393 |
+ x-nullable: false |
|
| 2394 |
+ example: "b5c4fc71e8022147cd25de22b22173de4e3b170134117172eb595cb91b4e7e5d" |
|
| 2395 |
+ Warning: |
|
| 2396 |
+ description: "Warnings encountered when creating the container" |
|
| 2397 |
+ type: "string" |
|
| 2398 |
+ x-nullable: false |
|
| 2399 |
+ example: "" |
|
| 2400 |
+ |
|
| 2383 | 2401 |
BuildInfo: |
| 2384 | 2402 |
type: "object" |
| 2385 | 2403 |
properties: |
| ... | ... |
@@ -10144,19 +10162,9 @@ paths: |
| 10144 | 10144 |
- "application/json" |
| 10145 | 10145 |
responses: |
| 10146 | 10146 |
201: |
| 10147 |
- description: "No error" |
|
| 10147 |
+ description: "Network created successfully" |
|
| 10148 | 10148 |
schema: |
| 10149 |
- type: "object" |
|
| 10150 |
- title: "NetworkCreateResponse" |
|
| 10151 |
- properties: |
|
| 10152 |
- Id: |
|
| 10153 |
- description: "The ID of the created network." |
|
| 10154 |
- type: "string" |
|
| 10155 |
- Warning: |
|
| 10156 |
- type: "string" |
|
| 10157 |
- example: |
|
| 10158 |
- Id: "22be93d5babb089c5aab8dbc369042fad48ff791584ca2da2100db837a1c7c30" |
|
| 10159 |
- Warning: "" |
|
| 10149 |
+ $ref: "#/definitions/NetworkCreateResponse" |
|
| 10160 | 10150 |
400: |
| 10161 | 10151 |
description: "bad parameter" |
| 10162 | 10152 |
schema: |
| 10163 | 10153 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,19 @@ |
| 0 |
+package network |
|
| 1 |
+ |
|
| 2 |
+// This file was generated by the swagger tool. |
|
| 3 |
+// Editing this file might prove futile when you re-run the swagger generate command |
|
| 4 |
+ |
|
| 5 |
+// CreateResponse NetworkCreateResponse |
|
| 6 |
+// |
|
| 7 |
+// OK response to NetworkCreate operation |
|
| 8 |
+// swagger:model CreateResponse |
|
| 9 |
+type CreateResponse struct {
|
|
| 10 |
+ |
|
| 11 |
+ // The ID of the created network. |
|
| 12 |
+ // Required: true |
|
| 13 |
+ ID string `json:"Id"` |
|
| 14 |
+ |
|
| 15 |
+ // Warnings encountered when creating the container |
|
| 16 |
+ // Required: true |
|
| 17 |
+ Warning string `json:"Warning"` |
|
| 18 |
+} |
| ... | ... |
@@ -477,12 +477,6 @@ type NetworkCreateRequest struct {
|
| 477 | 477 |
Name string // Name is the requested name of the network. |
| 478 | 478 |
} |
| 479 | 479 |
|
| 480 |
-// NetworkCreateResponse is the response message sent by the server for network create call |
|
| 481 |
-type NetworkCreateResponse struct {
|
|
| 482 |
- ID string `json:"Id"` |
|
| 483 |
- Warning string |
|
| 484 |
-} |
|
| 485 |
- |
|
| 486 | 480 |
// NetworkConnect represents the data to be used to connect a container to the network |
| 487 | 481 |
type NetworkConnect struct {
|
| 488 | 482 |
Container string |
| ... | ... |
@@ -2,6 +2,7 @@ package types |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"github.com/docker/docker/api/types/image" |
| 5 |
+ "github.com/docker/docker/api/types/network" |
|
| 5 | 6 |
) |
| 6 | 7 |
|
| 7 | 8 |
// ImageImportOptions holds information to import images from the client host. |
| ... | ... |
@@ -33,3 +34,8 @@ type ImageListOptions = image.ListOptions |
| 33 | 33 |
// |
| 34 | 34 |
// Deprecated: use [image.RemoveOptions]. |
| 35 | 35 |
type ImageRemoveOptions = image.RemoveOptions |
| 36 |
+ |
|
| 37 |
+// NetworkCreateResponse is the response message sent by the server for network create call. |
|
| 38 |
+// |
|
| 39 |
+// Deprecated: use [network.CreateResponse]. |
|
| 40 |
+type NetworkCreateResponse = network.CreateResponse |
| ... | ... |
@@ -108,7 +108,7 @@ type ImageAPIClient interface {
|
| 108 | 108 |
// NetworkAPIClient defines API client methods for the networks |
| 109 | 109 |
type NetworkAPIClient interface {
|
| 110 | 110 |
NetworkConnect(ctx context.Context, network, container string, config *network.EndpointSettings) error |
| 111 |
- NetworkCreate(ctx context.Context, name string, options types.NetworkCreate) (types.NetworkCreateResponse, error) |
|
| 111 |
+ NetworkCreate(ctx context.Context, name string, options types.NetworkCreate) (network.CreateResponse, error) |
|
| 112 | 112 |
NetworkDisconnect(ctx context.Context, network, container string, force bool) error |
| 113 | 113 |
NetworkInspect(ctx context.Context, network string, options types.NetworkInspectOptions) (types.NetworkResource, error) |
| 114 | 114 |
NetworkInspectWithRaw(ctx context.Context, network string, options types.NetworkInspectOptions) (types.NetworkResource, []byte, error) |
| ... | ... |
@@ -5,12 +5,13 @@ import ( |
| 5 | 5 |
"encoding/json" |
| 6 | 6 |
|
| 7 | 7 |
"github.com/docker/docker/api/types" |
| 8 |
+ "github.com/docker/docker/api/types/network" |
|
| 8 | 9 |
"github.com/docker/docker/api/types/versions" |
| 9 | 10 |
) |
| 10 | 11 |
|
| 11 | 12 |
// NetworkCreate creates a new network in the docker host. |
| 12 |
-func (cli *Client) NetworkCreate(ctx context.Context, name string, options types.NetworkCreate) (types.NetworkCreateResponse, error) {
|
|
| 13 |
- var response types.NetworkCreateResponse |
|
| 13 |
+func (cli *Client) NetworkCreate(ctx context.Context, name string, options types.NetworkCreate) (network.CreateResponse, error) {
|
|
| 14 |
+ var response network.CreateResponse |
|
| 14 | 15 |
|
| 15 | 16 |
// Make sure we negotiated (if the client is configured to do so), |
| 16 | 17 |
// as code below contains API-version specific handling of options. |
| ... | ... |
@@ -11,6 +11,7 @@ import ( |
| 11 | 11 |
"testing" |
| 12 | 12 |
|
| 13 | 13 |
"github.com/docker/docker/api/types" |
| 14 |
+ "github.com/docker/docker/api/types/network" |
|
| 14 | 15 |
"github.com/docker/docker/errdefs" |
| 15 | 16 |
"gotest.tools/v3/assert" |
| 16 | 17 |
is "gotest.tools/v3/assert/cmp" |
| ... | ... |
@@ -50,7 +51,7 @@ func TestNetworkCreate(t *testing.T) {
|
| 50 | 50 |
return nil, fmt.Errorf("expected POST method, got %s", req.Method)
|
| 51 | 51 |
} |
| 52 | 52 |
|
| 53 |
- content, err := json.Marshal(types.NetworkCreateResponse{
|
|
| 53 |
+ content, err := json.Marshal(network.CreateResponse{
|
|
| 54 | 54 |
ID: "network_id", |
| 55 | 55 |
Warning: "warning", |
| 56 | 56 |
}) |
| ... | ... |
@@ -286,11 +286,11 @@ func (daemon *Daemon) CreateManagedNetwork(create clustertypes.NetworkCreateRequ |
| 286 | 286 |
} |
| 287 | 287 |
|
| 288 | 288 |
// CreateNetwork creates a network with the given name, driver and other optional parameters |
| 289 |
-func (daemon *Daemon) CreateNetwork(create types.NetworkCreateRequest) (*types.NetworkCreateResponse, error) {
|
|
| 289 |
+func (daemon *Daemon) CreateNetwork(create types.NetworkCreateRequest) (*network.CreateResponse, error) {
|
|
| 290 | 290 |
return daemon.createNetwork(&daemon.config().Config, create, "", false) |
| 291 | 291 |
} |
| 292 | 292 |
|
| 293 |
-func (daemon *Daemon) createNetwork(cfg *config.Config, create types.NetworkCreateRequest, id string, agent bool) (*types.NetworkCreateResponse, error) {
|
|
| 293 |
+func (daemon *Daemon) createNetwork(cfg *config.Config, create types.NetworkCreateRequest, id string, agent bool) (*network.CreateResponse, error) {
|
|
| 294 | 294 |
if runconfig.IsPreDefinedNetwork(create.Name) {
|
| 295 | 295 |
return nil, PredefinedNetworkError(create.Name) |
| 296 | 296 |
} |
| ... | ... |
@@ -396,9 +396,7 @@ func (daemon *Daemon) createNetwork(cfg *config.Config, create types.NetworkCrea |
| 396 | 396 |
} |
| 397 | 397 |
daemon.LogNetworkEvent(n, events.ActionCreate) |
| 398 | 398 |
|
| 399 |
- return &types.NetworkCreateResponse{
|
|
| 400 |
- ID: n.ID(), |
|
| 401 |
- }, nil |
|
| 399 |
+ return &network.CreateResponse{ID: n.ID()}, nil
|
|
| 402 | 400 |
} |
| 403 | 401 |
|
| 404 | 402 |
func (daemon *Daemon) pluginRefCount(driver, capability string, mode int) {
|
| ... | ... |
@@ -27,6 +27,10 @@ swagger generate model -f api/swagger.yaml \ |
| 27 | 27 |
-n ImageSummary |
| 28 | 28 |
|
| 29 | 29 |
swagger generate model -f api/swagger.yaml \ |
| 30 |
+ -t api -m types/network --skip-validator -C api/swagger-gen.yaml \ |
|
| 31 |
+ -n NetworkCreateResponse |
|
| 32 |
+ |
|
| 33 |
+swagger generate model -f api/swagger.yaml \ |
|
| 30 | 34 |
-t api -m types/volume --skip-validator -C api/swagger-gen.yaml \ |
| 31 | 35 |
-n Volume \ |
| 32 | 36 |
-n VolumeCreateOptions \ |
| ... | ... |
@@ -280,7 +280,7 @@ func createNetwork(c *testing.T, config types.NetworkCreateRequest, expectedStat |
| 280 | 280 |
} |
| 281 | 281 |
|
| 282 | 282 |
if expectedStatusCode == http.StatusCreated || expectedStatusCode < 0 {
|
| 283 |
- var nr types.NetworkCreateResponse |
|
| 283 |
+ var nr network.CreateResponse |
|
| 284 | 284 |
err = json.NewDecoder(body).Decode(&nr) |
| 285 | 285 |
assert.NilError(c, err) |
| 286 | 286 |
|