Browse Source

Generate container create response from swagger spec.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Daniel Nephin 8 years ago
parent
commit
bad849fc82

+ 1 - 1
api/server/router/container/backend.go

@@ -32,7 +32,7 @@ type copyBackend interface {
 
 
 // stateBackend includes functions to implement to provide container state lifecycle functionality.
 // stateBackend includes functions to implement to provide container state lifecycle functionality.
 type stateBackend interface {
 type stateBackend interface {
-	ContainerCreate(config types.ContainerCreateConfig, validateHostname bool) (types.ContainerCreateResponse, error)
+	ContainerCreate(config types.ContainerCreateConfig, validateHostname bool) (container.ContainerCreateCreatedBody, error)
 	ContainerKill(name string, sig uint64) error
 	ContainerKill(name string, sig uint64) error
 	ContainerPause(name string) error
 	ContainerPause(name string) error
 	ContainerRename(oldName, newName string) error
 	ContainerRename(oldName, newName string) error

+ 6 - 2
api/swagger.yaml

@@ -2393,7 +2393,7 @@ paths:
   /containers/create:
   /containers/create:
     post:
     post:
       summary: "Create a container"
       summary: "Create a container"
-      operationId: "PostContainerCreate"
+      operationId: "ContainerCreate"
       consumes:
       consumes:
         - "application/json"
         - "application/json"
         - "application/octet-stream"
         - "application/octet-stream"
@@ -2542,15 +2542,19 @@ paths:
           required: true
           required: true
       responses:
       responses:
         201:
         201:
-          description: "no error"
+          description: "Container created successfully"
           schema:
           schema:
             type: "object"
             type: "object"
+            required: [Id, Warnings]
             properties:
             properties:
               Id:
               Id:
                 description: "The ID of the created container"
                 description: "The ID of the created container"
                 type: "string"
                 type: "string"
+                x-nullable: false
               Warnings:
               Warnings:
+                description: "Warnings encountered when creating the container"
                 type: "array"
                 type: "array"
+                x-nullable: false
                 items:
                 items:
                   type: "string"
                   type: "string"
           examples:
           examples:

+ 21 - 0
api/types/container/container_create.go

@@ -0,0 +1,21 @@
+package container
+
+// ----------------------------------------------------------------------------
+// DO NOT EDIT THIS FILE
+// This file was generated by `swagger generate operation`
+//
+// See hack/swagger-gen.sh
+// ----------------------------------------------------------------------------
+
+// ContainerCreateCreatedBody container create created body
+// swagger:model ContainerCreateCreatedBody
+type ContainerCreateCreatedBody struct {
+
+	// The ID of the created container
+	// Required: true
+	ID string `json:"Id"`
+
+	// Warnings encountered when creating the container
+	// Required: true
+	Warnings []string `json:"Warnings"`
+}

+ 0 - 10
api/types/types.go

@@ -13,16 +13,6 @@ import (
 	"github.com/docker/go-connections/nat"
 	"github.com/docker/go-connections/nat"
 )
 )
 
 
-// ContainerCreateResponse contains the information returned to a client on the
-// creation of a new container.
-type ContainerCreateResponse struct {
-	// ID is the ID of the created container.
-	ID string `json:"Id"`
-
-	// Warnings are any warnings encountered during the creation of the container.
-	Warnings []string `json:"Warnings"`
-}
-
 // ContainerExecCreateResponse contains response of Remote API:
 // ContainerExecCreateResponse contains response of Remote API:
 // POST "/containers/{name:.*}/exec"
 // POST "/containers/{name:.*}/exec"
 type ContainerExecCreateResponse struct {
 type ContainerExecCreateResponse struct {

+ 1 - 1
builder/builder.go

@@ -116,7 +116,7 @@ type Backend interface {
 	// ContainerAttachRaw attaches to container.
 	// ContainerAttachRaw attaches to container.
 	ContainerAttachRaw(cID string, stdin io.ReadCloser, stdout, stderr io.Writer, stream bool) error
 	ContainerAttachRaw(cID string, stdin io.ReadCloser, stdout, stderr io.Writer, stream bool) error
 	// ContainerCreate creates a new Docker container and returns potential warnings
 	// ContainerCreate creates a new Docker container and returns potential warnings
-	ContainerCreate(config types.ContainerCreateConfig, validateHostname bool) (types.ContainerCreateResponse, error)
+	ContainerCreate(config types.ContainerCreateConfig, validateHostname bool) (container.ContainerCreateCreatedBody, error)
 	// ContainerRm removes a container specified by `id`.
 	// ContainerRm removes a container specified by `id`.
 	ContainerRm(name string, config *types.ContainerRmConfig) error
 	ContainerRm(name string, config *types.ContainerRmConfig) error
 	// Commit creates a new Docker image from an existing Docker container.
 	// Commit creates a new Docker image from an existing Docker container.

+ 1 - 1
cli/command/container/create.go

@@ -148,7 +148,7 @@ func newCIDFile(path string) (*cidFile, error) {
 	return &cidFile{path: path, file: f}, nil
 	return &cidFile{path: path, file: f}, nil
 }
 }
 
 
-func createContainer(ctx context.Context, dockerCli *command.DockerCli, config *container.Config, hostConfig *container.HostConfig, networkingConfig *networktypes.NetworkingConfig, cidfile, name string) (*types.ContainerCreateResponse, error) {
+func createContainer(ctx context.Context, dockerCli *command.DockerCli, config *container.Config, hostConfig *container.HostConfig, networkingConfig *networktypes.NetworkingConfig, cidfile, name string) (*container.ContainerCreateCreatedBody, error) {
 	stderr := dockerCli.Err()
 	stderr := dockerCli.Err()
 
 
 	var containerIDFile *cidFile
 	var containerIDFile *cidFile

+ 2 - 3
client/container_create.go

@@ -5,7 +5,6 @@ import (
 	"net/url"
 	"net/url"
 	"strings"
 	"strings"
 
 
-	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/api/types/container"
 	"github.com/docker/docker/api/types/container"
 	"github.com/docker/docker/api/types/network"
 	"github.com/docker/docker/api/types/network"
 	"golang.org/x/net/context"
 	"golang.org/x/net/context"
@@ -19,8 +18,8 @@ type configWrapper struct {
 
 
 // ContainerCreate creates a new container based in the given configuration.
 // ContainerCreate creates a new container based in the given configuration.
 // It can be associated with a name, but it's not mandatory.
 // It can be associated with a name, but it's not mandatory.
-func (cli *Client) ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (types.ContainerCreateResponse, error) {
-	var response types.ContainerCreateResponse
+func (cli *Client) ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (container.ContainerCreateCreatedBody, error) {
+	var response container.ContainerCreateCreatedBody
 	query := url.Values{}
 	query := url.Values{}
 	if containerName != "" {
 	if containerName != "" {
 		query.Set("name", containerName)
 		query.Set("name", containerName)

+ 1 - 2
client/container_create_test.go

@@ -9,7 +9,6 @@ import (
 	"strings"
 	"strings"
 	"testing"
 	"testing"
 
 
-	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/api/types/container"
 	"github.com/docker/docker/api/types/container"
 	"golang.org/x/net/context"
 	"golang.org/x/net/context"
 )
 )
@@ -54,7 +53,7 @@ func TestContainerCreateWithName(t *testing.T) {
 			if name != "container_name" {
 			if name != "container_name" {
 				return nil, fmt.Errorf("container name not set in URL query properly. Expected `container_name`, got %s", name)
 				return nil, fmt.Errorf("container name not set in URL query properly. Expected `container_name`, got %s", name)
 			}
 			}
-			b, err := json.Marshal(types.ContainerCreateResponse{
+			b, err := json.Marshal(container.ContainerCreateCreatedBody{
 				ID: "container_id",
 				ID: "container_id",
 			})
 			})
 			if err != nil {
 			if err != nil {

+ 1 - 1
client/interface.go

@@ -34,7 +34,7 @@ type CommonAPIClient interface {
 type ContainerAPIClient interface {
 type ContainerAPIClient interface {
 	ContainerAttach(ctx context.Context, container string, options types.ContainerAttachOptions) (types.HijackedResponse, error)
 	ContainerAttach(ctx context.Context, container string, options types.ContainerAttachOptions) (types.HijackedResponse, error)
 	ContainerCommit(ctx context.Context, container string, options types.ContainerCommitOptions) (types.ContainerCommitResponse, error)
 	ContainerCommit(ctx context.Context, container string, options types.ContainerCommitOptions) (types.ContainerCommitResponse, error)
-	ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (types.ContainerCreateResponse, error)
+	ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (container.ContainerCreateCreatedBody, error)
 	ContainerDiff(ctx context.Context, container string) ([]types.ContainerChange, error)
 	ContainerDiff(ctx context.Context, container string) ([]types.ContainerChange, error)
 	ContainerExecAttach(ctx context.Context, execID string, config types.ExecConfig) (types.HijackedResponse, error)
 	ContainerExecAttach(ctx context.Context, execID string, config types.ExecConfig) (types.HijackedResponse, error)
 	ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.ContainerExecCreateResponse, error)
 	ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.ContainerExecCreateResponse, error)

+ 1 - 1
daemon/cluster/executor/backend.go

@@ -23,7 +23,7 @@ type Backend interface {
 	FindNetwork(idName string) (libnetwork.Network, error)
 	FindNetwork(idName string) (libnetwork.Network, error)
 	SetupIngress(req clustertypes.NetworkCreateRequest, nodeIP string) error
 	SetupIngress(req clustertypes.NetworkCreateRequest, nodeIP string) error
 	PullImage(ctx context.Context, image, tag string, metaHeaders map[string][]string, authConfig *types.AuthConfig, outStream io.Writer) error
 	PullImage(ctx context.Context, image, tag string, metaHeaders map[string][]string, authConfig *types.AuthConfig, outStream io.Writer) error
-	CreateManagedContainer(config types.ContainerCreateConfig, validateHostname bool) (types.ContainerCreateResponse, error)
+	CreateManagedContainer(config types.ContainerCreateConfig, validateHostname bool) (container.ContainerCreateResponse, error)
 	ContainerStart(name string, hostConfig *container.HostConfig, validateHostname bool, checkpoint string, checkpointDir string) error
 	ContainerStart(name string, hostConfig *container.HostConfig, validateHostname bool, checkpoint string, checkpointDir string) error
 	ContainerStop(name string, seconds *int) error
 	ContainerStop(name string, seconds *int) error
 	ConnectContainerToNetwork(containerName, networkName string, endpointConfig *network.EndpointSettings) error
 	ConnectContainerToNetwork(containerName, networkName string, endpointConfig *network.EndpointSettings) error

+ 2 - 1
daemon/cluster/executor/container/adapter.go

@@ -12,6 +12,7 @@ import (
 	"github.com/Sirupsen/logrus"
 	"github.com/Sirupsen/logrus"
 	"github.com/docker/docker/api/server/httputils"
 	"github.com/docker/docker/api/server/httputils"
 	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/api/types"
+	containertypes "github.com/docker/docker/api/types/container"
 	"github.com/docker/docker/api/types/events"
 	"github.com/docker/docker/api/types/events"
 	"github.com/docker/docker/api/types/versions"
 	"github.com/docker/docker/api/types/versions"
 	executorpkg "github.com/docker/docker/daemon/cluster/executor"
 	executorpkg "github.com/docker/docker/daemon/cluster/executor"
@@ -187,7 +188,7 @@ func (c *containerAdapter) waitForDetach(ctx context.Context) error {
 }
 }
 
 
 func (c *containerAdapter) create(ctx context.Context) error {
 func (c *containerAdapter) create(ctx context.Context) error {
-	var cr types.ContainerCreateResponse
+	var cr containertypes.ContainerCreateCreatedBody
 	var err error
 	var err error
 	version := httputils.VersionFromContext(ctx)
 	version := httputils.VersionFromContext(ctx)
 	validateHostname := versions.GreaterThanOrEqualTo(version, "1.24")
 	validateHostname := versions.GreaterThanOrEqualTo(version, "1.24")

+ 10 - 9
daemon/create.go

@@ -22,29 +22,29 @@ import (
 )
 )
 
 
 // CreateManagedContainer creates a container that is managed by a Service
 // CreateManagedContainer creates a container that is managed by a Service
-func (daemon *Daemon) CreateManagedContainer(params types.ContainerCreateConfig, validateHostname bool) (types.ContainerCreateResponse, error) {
+func (daemon *Daemon) CreateManagedContainer(params types.ContainerCreateConfig, validateHostname bool) (containertypes.ContainerCreateCreatedBody, error) {
 	return daemon.containerCreate(params, true, validateHostname)
 	return daemon.containerCreate(params, true, validateHostname)
 }
 }
 
 
 // ContainerCreate creates a regular container
 // ContainerCreate creates a regular container
-func (daemon *Daemon) ContainerCreate(params types.ContainerCreateConfig, validateHostname bool) (types.ContainerCreateResponse, error) {
+func (daemon *Daemon) ContainerCreate(params types.ContainerCreateConfig, validateHostname bool) (containertypes.ContainerCreateCreatedBody, error) {
 	return daemon.containerCreate(params, false, validateHostname)
 	return daemon.containerCreate(params, false, validateHostname)
 }
 }
 
 
-func (daemon *Daemon) containerCreate(params types.ContainerCreateConfig, managed bool, validateHostname bool) (types.ContainerCreateResponse, error) {
+func (daemon *Daemon) containerCreate(params types.ContainerCreateConfig, managed bool, validateHostname bool) (containertypes.ContainerCreateCreatedBody, error) {
 	start := time.Now()
 	start := time.Now()
 	if params.Config == nil {
 	if params.Config == nil {
-		return types.ContainerCreateResponse{}, fmt.Errorf("Config cannot be empty in order to create a container")
+		return containertypes.ContainerCreateCreatedBody{}, fmt.Errorf("Config cannot be empty in order to create a container")
 	}
 	}
 
 
 	warnings, err := daemon.verifyContainerSettings(params.HostConfig, params.Config, false, validateHostname)
 	warnings, err := daemon.verifyContainerSettings(params.HostConfig, params.Config, false, validateHostname)
 	if err != nil {
 	if err != nil {
-		return types.ContainerCreateResponse{Warnings: warnings}, err
+		return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, err
 	}
 	}
 
 
 	err = daemon.verifyNetworkingConfig(params.NetworkingConfig)
 	err = daemon.verifyNetworkingConfig(params.NetworkingConfig)
 	if err != nil {
 	if err != nil {
-		return types.ContainerCreateResponse{Warnings: warnings}, err
+		return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, err
 	}
 	}
 
 
 	if params.HostConfig == nil {
 	if params.HostConfig == nil {
@@ -52,15 +52,16 @@ func (daemon *Daemon) containerCreate(params types.ContainerCreateConfig, manage
 	}
 	}
 	err = daemon.adaptContainerSettings(params.HostConfig, params.AdjustCPUShares)
 	err = daemon.adaptContainerSettings(params.HostConfig, params.AdjustCPUShares)
 	if err != nil {
 	if err != nil {
-		return types.ContainerCreateResponse{Warnings: warnings}, err
+		return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, err
 	}
 	}
 
 
 	container, err := daemon.create(params, managed)
 	container, err := daemon.create(params, managed)
 	if err != nil {
 	if err != nil {
-		return types.ContainerCreateResponse{Warnings: warnings}, daemon.imageNotExistToErrcode(err)
+		return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, daemon.imageNotExistToErrcode(err)
 	}
 	}
 	containerActions.WithValues("create").UpdateSince(start)
 	containerActions.WithValues("create").UpdateSince(start)
-	return types.ContainerCreateResponse{ID: container.ID, Warnings: warnings}, nil
+
+	return containertypes.ContainerCreateCreatedBody{ID: container.ID, Warnings: warnings}, nil
 }
 }
 
 
 // Create creates a new container from the given configuration with a given name.
 // Create creates a new container from the given configuration with a given name.

+ 2 - 1
hack/generate-swagger-api.sh

@@ -13,4 +13,5 @@ swagger generate operation -f api/swagger.yaml \
     -t api -a types -m types -C api/swagger-gen.yaml \
     -t api -a types -m types -C api/swagger-gen.yaml \
     -T api/templates --skip-responses --skip-parameters --skip-validator \
     -T api/templates --skip-responses --skip-parameters --skip-validator \
     -n VolumesList \
     -n VolumesList \
-    -n VolumesCreate
+    -n VolumesCreate \
+    -n ContainerCreate

+ 8 - 8
integration-cli/docker_api_containers_test.go

@@ -574,7 +574,7 @@ func (s *DockerSuite) TestContainerAPICreateWithHostName(c *check.C) {
 	c.Assert(err, checker.IsNil)
 	c.Assert(err, checker.IsNil)
 	c.Assert(status, checker.Equals, http.StatusCreated)
 	c.Assert(status, checker.Equals, http.StatusCreated)
 
 
-	var container types.ContainerCreateResponse
+	var container containertypes.ContainerCreateCreatedBody
 	c.Assert(json.Unmarshal(body, &container), checker.IsNil)
 	c.Assert(json.Unmarshal(body, &container), checker.IsNil)
 
 
 	status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
 	status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
@@ -597,7 +597,7 @@ func (s *DockerSuite) TestContainerAPICreateWithDomainName(c *check.C) {
 	c.Assert(err, checker.IsNil)
 	c.Assert(err, checker.IsNil)
 	c.Assert(status, checker.Equals, http.StatusCreated)
 	c.Assert(status, checker.Equals, http.StatusCreated)
 
 
-	var container types.ContainerCreateResponse
+	var container containertypes.ContainerCreateCreatedBody
 	c.Assert(json.Unmarshal(body, &container), checker.IsNil)
 	c.Assert(json.Unmarshal(body, &container), checker.IsNil)
 
 
 	status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
 	status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
@@ -632,7 +632,7 @@ func UtilCreateNetworkMode(c *check.C, networkMode string) {
 	c.Assert(err, checker.IsNil)
 	c.Assert(err, checker.IsNil)
 	c.Assert(status, checker.Equals, http.StatusCreated)
 	c.Assert(status, checker.Equals, http.StatusCreated)
 
 
-	var container types.ContainerCreateResponse
+	var container containertypes.ContainerCreateCreatedBody
 	c.Assert(json.Unmarshal(body, &container), checker.IsNil)
 	c.Assert(json.Unmarshal(body, &container), checker.IsNil)
 
 
 	status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
 	status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
@@ -657,7 +657,7 @@ func (s *DockerSuite) TestContainerAPICreateWithCpuSharesCpuset(c *check.C) {
 	c.Assert(err, checker.IsNil)
 	c.Assert(err, checker.IsNil)
 	c.Assert(status, checker.Equals, http.StatusCreated)
 	c.Assert(status, checker.Equals, http.StatusCreated)
 
 
-	var container types.ContainerCreateResponse
+	var container containertypes.ContainerCreateCreatedBody
 	c.Assert(json.Unmarshal(body, &container), checker.IsNil)
 	c.Assert(json.Unmarshal(body, &container), checker.IsNil)
 
 
 	status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
 	status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
@@ -1349,7 +1349,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeHostConfigOmitted(c *check.
 	c.Assert(err, check.IsNil)
 	c.Assert(err, check.IsNil)
 	c.Assert(status, check.Equals, http.StatusCreated)
 	c.Assert(status, check.Equals, http.StatusCreated)
 
 
-	var container types.ContainerCreateResponse
+	var container containertypes.ContainerCreateCreatedBody
 	c.Assert(json.Unmarshal(body, &container), check.IsNil)
 	c.Assert(json.Unmarshal(body, &container), check.IsNil)
 
 
 	status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
 	status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
@@ -1381,7 +1381,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeOmitted(c *check.C) {
 	c.Assert(err, check.IsNil)
 	c.Assert(err, check.IsNil)
 	c.Assert(status, check.Equals, http.StatusCreated)
 	c.Assert(status, check.Equals, http.StatusCreated)
 
 
-	var container types.ContainerCreateResponse
+	var container containertypes.ContainerCreateCreatedBody
 	c.Assert(json.Unmarshal(body, &container), check.IsNil)
 	c.Assert(json.Unmarshal(body, &container), check.IsNil)
 
 
 	status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
 	status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
@@ -1413,7 +1413,7 @@ func (s *DockerSuite) TestPostContainersCreateWithShmSize(c *check.C) {
 	c.Assert(err, check.IsNil)
 	c.Assert(err, check.IsNil)
 	c.Assert(status, check.Equals, http.StatusCreated)
 	c.Assert(status, check.Equals, http.StatusCreated)
 
 
-	var container types.ContainerCreateResponse
+	var container containertypes.ContainerCreateCreatedBody
 	c.Assert(json.Unmarshal(body, &container), check.IsNil)
 	c.Assert(json.Unmarshal(body, &container), check.IsNil)
 
 
 	status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
 	status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
@@ -1443,7 +1443,7 @@ func (s *DockerSuite) TestPostContainersCreateMemorySwappinessHostConfigOmitted(
 	c.Assert(err, check.IsNil)
 	c.Assert(err, check.IsNil)
 	c.Assert(status, check.Equals, http.StatusCreated)
 	c.Assert(status, check.Equals, http.StatusCreated)
 
 
-	var container types.ContainerCreateResponse
+	var container containertypes.ContainerCreateCreatedBody
 	c.Assert(json.Unmarshal(body, &container), check.IsNil)
 	c.Assert(json.Unmarshal(body, &container), check.IsNil)
 
 
 	status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
 	status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)