Browse code

Generate container create response from swagger spec.

Signed-off-by: Daniel Nephin <dnephin@docker.com>

Daniel Nephin authored on 2016/10/15 05:28:47
Showing 14 changed files
... ...
@@ -32,7 +32,7 @@ type copyBackend interface {
32 32
 
33 33
 // stateBackend includes functions to implement to provide container state lifecycle functionality.
34 34
 type stateBackend interface {
35
-	ContainerCreate(config types.ContainerCreateConfig, validateHostname bool) (types.ContainerCreateResponse, error)
35
+	ContainerCreate(config types.ContainerCreateConfig, validateHostname bool) (container.ContainerCreateCreatedBody, error)
36 36
 	ContainerKill(name string, sig uint64) error
37 37
 	ContainerPause(name string) error
38 38
 	ContainerRename(oldName, newName string) error
... ...
@@ -2393,7 +2393,7 @@ paths:
2393 2393
   /containers/create:
2394 2394
     post:
2395 2395
       summary: "Create a container"
2396
-      operationId: "PostContainerCreate"
2396
+      operationId: "ContainerCreate"
2397 2397
       consumes:
2398 2398
         - "application/json"
2399 2399
         - "application/octet-stream"
... ...
@@ -2542,15 +2542,19 @@ paths:
2542 2542
           required: true
2543 2543
       responses:
2544 2544
         201:
2545
-          description: "no error"
2545
+          description: "Container created successfully"
2546 2546
           schema:
2547 2547
             type: "object"
2548
+            required: [Id, Warnings]
2548 2549
             properties:
2549 2550
               Id:
2550 2551
                 description: "The ID of the created container"
2551 2552
                 type: "string"
2553
+                x-nullable: false
2552 2554
               Warnings:
2555
+                description: "Warnings encountered when creating the container"
2553 2556
                 type: "array"
2557
+                x-nullable: false
2554 2558
                 items:
2555 2559
                   type: "string"
2556 2560
           examples:
2557 2561
new file mode 100644
... ...
@@ -0,0 +1,21 @@
0
+package container
1
+
2
+// ----------------------------------------------------------------------------
3
+// DO NOT EDIT THIS FILE
4
+// This file was generated by `swagger generate operation`
5
+//
6
+// See hack/swagger-gen.sh
7
+// ----------------------------------------------------------------------------
8
+
9
+// ContainerCreateCreatedBody container create created body
10
+// swagger:model ContainerCreateCreatedBody
11
+type ContainerCreateCreatedBody struct {
12
+
13
+	// The ID of the created container
14
+	// Required: true
15
+	ID string `json:"Id"`
16
+
17
+	// Warnings encountered when creating the container
18
+	// Required: true
19
+	Warnings []string `json:"Warnings"`
20
+}
... ...
@@ -13,16 +13,6 @@ import (
13 13
 	"github.com/docker/go-connections/nat"
14 14
 )
15 15
 
16
-// ContainerCreateResponse contains the information returned to a client on the
17
-// creation of a new container.
18
-type ContainerCreateResponse struct {
19
-	// ID is the ID of the created container.
20
-	ID string `json:"Id"`
21
-
22
-	// Warnings are any warnings encountered during the creation of the container.
23
-	Warnings []string `json:"Warnings"`
24
-}
25
-
26 16
 // ContainerExecCreateResponse contains response of Remote API:
27 17
 // POST "/containers/{name:.*}/exec"
28 18
 type ContainerExecCreateResponse struct {
... ...
@@ -116,7 +116,7 @@ type Backend interface {
116 116
 	// ContainerAttachRaw attaches to container.
117 117
 	ContainerAttachRaw(cID string, stdin io.ReadCloser, stdout, stderr io.Writer, stream bool) error
118 118
 	// ContainerCreate creates a new Docker container and returns potential warnings
119
-	ContainerCreate(config types.ContainerCreateConfig, validateHostname bool) (types.ContainerCreateResponse, error)
119
+	ContainerCreate(config types.ContainerCreateConfig, validateHostname bool) (container.ContainerCreateCreatedBody, error)
120 120
 	// ContainerRm removes a container specified by `id`.
121 121
 	ContainerRm(name string, config *types.ContainerRmConfig) error
122 122
 	// Commit creates a new Docker image from an existing Docker container.
... ...
@@ -148,7 +148,7 @@ func newCIDFile(path string) (*cidFile, error) {
148 148
 	return &cidFile{path: path, file: f}, nil
149 149
 }
150 150
 
151
-func createContainer(ctx context.Context, dockerCli *command.DockerCli, config *container.Config, hostConfig *container.HostConfig, networkingConfig *networktypes.NetworkingConfig, cidfile, name string) (*types.ContainerCreateResponse, error) {
151
+func createContainer(ctx context.Context, dockerCli *command.DockerCli, config *container.Config, hostConfig *container.HostConfig, networkingConfig *networktypes.NetworkingConfig, cidfile, name string) (*container.ContainerCreateCreatedBody, error) {
152 152
 	stderr := dockerCli.Err()
153 153
 
154 154
 	var containerIDFile *cidFile
... ...
@@ -5,7 +5,6 @@ import (
5 5
 	"net/url"
6 6
 	"strings"
7 7
 
8
-	"github.com/docker/docker/api/types"
9 8
 	"github.com/docker/docker/api/types/container"
10 9
 	"github.com/docker/docker/api/types/network"
11 10
 	"golang.org/x/net/context"
... ...
@@ -19,8 +18,8 @@ type configWrapper struct {
19 19
 
20 20
 // ContainerCreate creates a new container based in the given configuration.
21 21
 // It can be associated with a name, but it's not mandatory.
22
-func (cli *Client) ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (types.ContainerCreateResponse, error) {
23
-	var response types.ContainerCreateResponse
22
+func (cli *Client) ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (container.ContainerCreateCreatedBody, error) {
23
+	var response container.ContainerCreateCreatedBody
24 24
 	query := url.Values{}
25 25
 	if containerName != "" {
26 26
 		query.Set("name", containerName)
... ...
@@ -9,7 +9,6 @@ import (
9 9
 	"strings"
10 10
 	"testing"
11 11
 
12
-	"github.com/docker/docker/api/types"
13 12
 	"github.com/docker/docker/api/types/container"
14 13
 	"golang.org/x/net/context"
15 14
 )
... ...
@@ -54,7 +53,7 @@ func TestContainerCreateWithName(t *testing.T) {
54 54
 			if name != "container_name" {
55 55
 				return nil, fmt.Errorf("container name not set in URL query properly. Expected `container_name`, got %s", name)
56 56
 			}
57
-			b, err := json.Marshal(types.ContainerCreateResponse{
57
+			b, err := json.Marshal(container.ContainerCreateCreatedBody{
58 58
 				ID: "container_id",
59 59
 			})
60 60
 			if err != nil {
... ...
@@ -34,7 +34,7 @@ type CommonAPIClient interface {
34 34
 type ContainerAPIClient interface {
35 35
 	ContainerAttach(ctx context.Context, container string, options types.ContainerAttachOptions) (types.HijackedResponse, error)
36 36
 	ContainerCommit(ctx context.Context, container string, options types.ContainerCommitOptions) (types.ContainerCommitResponse, error)
37
-	ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (types.ContainerCreateResponse, error)
37
+	ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (container.ContainerCreateCreatedBody, error)
38 38
 	ContainerDiff(ctx context.Context, container string) ([]types.ContainerChange, error)
39 39
 	ContainerExecAttach(ctx context.Context, execID string, config types.ExecConfig) (types.HijackedResponse, error)
40 40
 	ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.ContainerExecCreateResponse, error)
... ...
@@ -23,7 +23,7 @@ type Backend interface {
23 23
 	FindNetwork(idName string) (libnetwork.Network, error)
24 24
 	SetupIngress(req clustertypes.NetworkCreateRequest, nodeIP string) error
25 25
 	PullImage(ctx context.Context, image, tag string, metaHeaders map[string][]string, authConfig *types.AuthConfig, outStream io.Writer) error
26
-	CreateManagedContainer(config types.ContainerCreateConfig, validateHostname bool) (types.ContainerCreateResponse, error)
26
+	CreateManagedContainer(config types.ContainerCreateConfig, validateHostname bool) (container.ContainerCreateResponse, error)
27 27
 	ContainerStart(name string, hostConfig *container.HostConfig, validateHostname bool, checkpoint string, checkpointDir string) error
28 28
 	ContainerStop(name string, seconds *int) error
29 29
 	ConnectContainerToNetwork(containerName, networkName string, endpointConfig *network.EndpointSettings) error
... ...
@@ -12,6 +12,7 @@ import (
12 12
 	"github.com/Sirupsen/logrus"
13 13
 	"github.com/docker/docker/api/server/httputils"
14 14
 	"github.com/docker/docker/api/types"
15
+	containertypes "github.com/docker/docker/api/types/container"
15 16
 	"github.com/docker/docker/api/types/events"
16 17
 	"github.com/docker/docker/api/types/versions"
17 18
 	executorpkg "github.com/docker/docker/daemon/cluster/executor"
... ...
@@ -187,7 +188,7 @@ func (c *containerAdapter) waitForDetach(ctx context.Context) error {
187 187
 }
188 188
 
189 189
 func (c *containerAdapter) create(ctx context.Context) error {
190
-	var cr types.ContainerCreateResponse
190
+	var cr containertypes.ContainerCreateCreatedBody
191 191
 	var err error
192 192
 	version := httputils.VersionFromContext(ctx)
193 193
 	validateHostname := versions.GreaterThanOrEqualTo(version, "1.24")
... ...
@@ -22,29 +22,29 @@ import (
22 22
 )
23 23
 
24 24
 // CreateManagedContainer creates a container that is managed by a Service
25
-func (daemon *Daemon) CreateManagedContainer(params types.ContainerCreateConfig, validateHostname bool) (types.ContainerCreateResponse, error) {
25
+func (daemon *Daemon) CreateManagedContainer(params types.ContainerCreateConfig, validateHostname bool) (containertypes.ContainerCreateCreatedBody, error) {
26 26
 	return daemon.containerCreate(params, true, validateHostname)
27 27
 }
28 28
 
29 29
 // ContainerCreate creates a regular container
30
-func (daemon *Daemon) ContainerCreate(params types.ContainerCreateConfig, validateHostname bool) (types.ContainerCreateResponse, error) {
30
+func (daemon *Daemon) ContainerCreate(params types.ContainerCreateConfig, validateHostname bool) (containertypes.ContainerCreateCreatedBody, error) {
31 31
 	return daemon.containerCreate(params, false, validateHostname)
32 32
 }
33 33
 
34
-func (daemon *Daemon) containerCreate(params types.ContainerCreateConfig, managed bool, validateHostname bool) (types.ContainerCreateResponse, error) {
34
+func (daemon *Daemon) containerCreate(params types.ContainerCreateConfig, managed bool, validateHostname bool) (containertypes.ContainerCreateCreatedBody, error) {
35 35
 	start := time.Now()
36 36
 	if params.Config == nil {
37
-		return types.ContainerCreateResponse{}, fmt.Errorf("Config cannot be empty in order to create a container")
37
+		return containertypes.ContainerCreateCreatedBody{}, fmt.Errorf("Config cannot be empty in order to create a container")
38 38
 	}
39 39
 
40 40
 	warnings, err := daemon.verifyContainerSettings(params.HostConfig, params.Config, false, validateHostname)
41 41
 	if err != nil {
42
-		return types.ContainerCreateResponse{Warnings: warnings}, err
42
+		return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, err
43 43
 	}
44 44
 
45 45
 	err = daemon.verifyNetworkingConfig(params.NetworkingConfig)
46 46
 	if err != nil {
47
-		return types.ContainerCreateResponse{Warnings: warnings}, err
47
+		return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, err
48 48
 	}
49 49
 
50 50
 	if params.HostConfig == nil {
... ...
@@ -52,15 +52,16 @@ func (daemon *Daemon) containerCreate(params types.ContainerCreateConfig, manage
52 52
 	}
53 53
 	err = daemon.adaptContainerSettings(params.HostConfig, params.AdjustCPUShares)
54 54
 	if err != nil {
55
-		return types.ContainerCreateResponse{Warnings: warnings}, err
55
+		return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, err
56 56
 	}
57 57
 
58 58
 	container, err := daemon.create(params, managed)
59 59
 	if err != nil {
60
-		return types.ContainerCreateResponse{Warnings: warnings}, daemon.imageNotExistToErrcode(err)
60
+		return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, daemon.imageNotExistToErrcode(err)
61 61
 	}
62 62
 	containerActions.WithValues("create").UpdateSince(start)
63
-	return types.ContainerCreateResponse{ID: container.ID, Warnings: warnings}, nil
63
+
64
+	return containertypes.ContainerCreateCreatedBody{ID: container.ID, Warnings: warnings}, nil
64 65
 }
65 66
 
66 67
 // Create creates a new container from the given configuration with a given name.
... ...
@@ -13,4 +13,5 @@ swagger generate operation -f api/swagger.yaml \
13 13
     -t api -a types -m types -C api/swagger-gen.yaml \
14 14
     -T api/templates --skip-responses --skip-parameters --skip-validator \
15 15
     -n VolumesList \
16
-    -n VolumesCreate
16
+    -n VolumesCreate \
17
+    -n ContainerCreate
... ...
@@ -574,7 +574,7 @@ func (s *DockerSuite) TestContainerAPICreateWithHostName(c *check.C) {
574 574
 	c.Assert(err, checker.IsNil)
575 575
 	c.Assert(status, checker.Equals, http.StatusCreated)
576 576
 
577
-	var container types.ContainerCreateResponse
577
+	var container containertypes.ContainerCreateCreatedBody
578 578
 	c.Assert(json.Unmarshal(body, &container), checker.IsNil)
579 579
 
580 580
 	status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
... ...
@@ -597,7 +597,7 @@ func (s *DockerSuite) TestContainerAPICreateWithDomainName(c *check.C) {
597 597
 	c.Assert(err, checker.IsNil)
598 598
 	c.Assert(status, checker.Equals, http.StatusCreated)
599 599
 
600
-	var container types.ContainerCreateResponse
600
+	var container containertypes.ContainerCreateCreatedBody
601 601
 	c.Assert(json.Unmarshal(body, &container), checker.IsNil)
602 602
 
603 603
 	status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
... ...
@@ -632,7 +632,7 @@ func UtilCreateNetworkMode(c *check.C, networkMode string) {
632 632
 	c.Assert(err, checker.IsNil)
633 633
 	c.Assert(status, checker.Equals, http.StatusCreated)
634 634
 
635
-	var container types.ContainerCreateResponse
635
+	var container containertypes.ContainerCreateCreatedBody
636 636
 	c.Assert(json.Unmarshal(body, &container), checker.IsNil)
637 637
 
638 638
 	status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
... ...
@@ -657,7 +657,7 @@ func (s *DockerSuite) TestContainerAPICreateWithCpuSharesCpuset(c *check.C) {
657 657
 	c.Assert(err, checker.IsNil)
658 658
 	c.Assert(status, checker.Equals, http.StatusCreated)
659 659
 
660
-	var container types.ContainerCreateResponse
660
+	var container containertypes.ContainerCreateCreatedBody
661 661
 	c.Assert(json.Unmarshal(body, &container), checker.IsNil)
662 662
 
663 663
 	status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
... ...
@@ -1349,7 +1349,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeHostConfigOmitted(c *check.
1349 1349
 	c.Assert(err, check.IsNil)
1350 1350
 	c.Assert(status, check.Equals, http.StatusCreated)
1351 1351
 
1352
-	var container types.ContainerCreateResponse
1352
+	var container containertypes.ContainerCreateCreatedBody
1353 1353
 	c.Assert(json.Unmarshal(body, &container), check.IsNil)
1354 1354
 
1355 1355
 	status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
... ...
@@ -1381,7 +1381,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeOmitted(c *check.C) {
1381 1381
 	c.Assert(err, check.IsNil)
1382 1382
 	c.Assert(status, check.Equals, http.StatusCreated)
1383 1383
 
1384
-	var container types.ContainerCreateResponse
1384
+	var container containertypes.ContainerCreateCreatedBody
1385 1385
 	c.Assert(json.Unmarshal(body, &container), check.IsNil)
1386 1386
 
1387 1387
 	status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
... ...
@@ -1413,7 +1413,7 @@ func (s *DockerSuite) TestPostContainersCreateWithShmSize(c *check.C) {
1413 1413
 	c.Assert(err, check.IsNil)
1414 1414
 	c.Assert(status, check.Equals, http.StatusCreated)
1415 1415
 
1416
-	var container types.ContainerCreateResponse
1416
+	var container containertypes.ContainerCreateCreatedBody
1417 1417
 	c.Assert(json.Unmarshal(body, &container), check.IsNil)
1418 1418
 
1419 1419
 	status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
... ...
@@ -1443,7 +1443,7 @@ func (s *DockerSuite) TestPostContainersCreateMemorySwappinessHostConfigOmitted(
1443 1443
 	c.Assert(err, check.IsNil)
1444 1444
 	c.Assert(status, check.Equals, http.StatusCreated)
1445 1445
 
1446
-	var container types.ContainerCreateResponse
1446
+	var container containertypes.ContainerCreateCreatedBody
1447 1447
 	c.Assert(json.Unmarshal(body, &container), check.IsNil)
1448 1448
 
1449 1449
 	status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)