Generate container create response from swagger spec.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
29df3bdb11
commit
bad849fc82
14 changed files with 57 additions and 41 deletions
|
@ -32,7 +32,7 @@ type copyBackend interface {
|
|||
|
||||
// stateBackend includes functions to implement to provide container state lifecycle functionality.
|
||||
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
|
||||
ContainerPause(name string) error
|
||||
ContainerRename(oldName, newName string) error
|
||||
|
|
|
@ -2393,7 +2393,7 @@ paths:
|
|||
/containers/create:
|
||||
post:
|
||||
summary: "Create a container"
|
||||
operationId: "PostContainerCreate"
|
||||
operationId: "ContainerCreate"
|
||||
consumes:
|
||||
- "application/json"
|
||||
- "application/octet-stream"
|
||||
|
@ -2542,15 +2542,19 @@ paths:
|
|||
required: true
|
||||
responses:
|
||||
201:
|
||||
description: "no error"
|
||||
description: "Container created successfully"
|
||||
schema:
|
||||
type: "object"
|
||||
required: [Id, Warnings]
|
||||
properties:
|
||||
Id:
|
||||
description: "The ID of the created container"
|
||||
type: "string"
|
||||
x-nullable: false
|
||||
Warnings:
|
||||
description: "Warnings encountered when creating the container"
|
||||
type: "array"
|
||||
x-nullable: false
|
||||
items:
|
||||
type: "string"
|
||||
examples:
|
||||
|
|
21
api/types/container/container_create.go
Normal file
21
api/types/container/container_create.go
Normal file
|
@ -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"`
|
||||
}
|
|
@ -13,16 +13,6 @@ import (
|
|||
"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:
|
||||
// POST "/containers/{name:.*}/exec"
|
||||
type ContainerExecCreateResponse struct {
|
||||
|
|
|
@ -116,7 +116,7 @@ type Backend interface {
|
|||
// ContainerAttachRaw attaches to container.
|
||||
ContainerAttachRaw(cID string, stdin io.ReadCloser, stdout, stderr io.Writer, stream bool) error
|
||||
// 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(name string, config *types.ContainerRmConfig) error
|
||||
// Commit creates a new Docker image from an existing Docker container.
|
||||
|
|
|
@ -148,7 +148,7 @@ func newCIDFile(path string) (*cidFile, error) {
|
|||
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()
|
||||
|
||||
var containerIDFile *cidFile
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/network"
|
||||
"golang.org/x/net/context"
|
||||
|
@ -19,8 +18,8 @@ type configWrapper struct {
|
|||
|
||||
// ContainerCreate creates a new container based in the given configuration.
|
||||
// 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{}
|
||||
if containerName != "" {
|
||||
query.Set("name", containerName)
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
@ -54,7 +53,7 @@ func TestContainerCreateWithName(t *testing.T) {
|
|||
if name != "container_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",
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
@ -34,7 +34,7 @@ type CommonAPIClient interface {
|
|||
type ContainerAPIClient interface {
|
||||
ContainerAttach(ctx context.Context, container string, options types.ContainerAttachOptions) (types.HijackedResponse, 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)
|
||||
ContainerExecAttach(ctx context.Context, execID string, config types.ExecConfig) (types.HijackedResponse, error)
|
||||
ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.ContainerExecCreateResponse, error)
|
||||
|
|
|
@ -23,7 +23,7 @@ type Backend interface {
|
|||
FindNetwork(idName string) (libnetwork.Network, 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
|
||||
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
|
||||
ContainerStop(name string, seconds *int) error
|
||||
ConnectContainerToNetwork(containerName, networkName string, endpointConfig *network.EndpointSettings) error
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/api/server/httputils"
|
||||
"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/versions"
|
||||
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 {
|
||||
var cr types.ContainerCreateResponse
|
||||
var cr containertypes.ContainerCreateCreatedBody
|
||||
var err error
|
||||
version := httputils.VersionFromContext(ctx)
|
||||
validateHostname := versions.GreaterThanOrEqualTo(version, "1.24")
|
||||
|
|
|
@ -22,29 +22,29 @@ import (
|
|||
)
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
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()
|
||||
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)
|
||||
if err != nil {
|
||||
return types.ContainerCreateResponse{Warnings: warnings}, err
|
||||
return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, err
|
||||
}
|
||||
|
||||
err = daemon.verifyNetworkingConfig(params.NetworkingConfig)
|
||||
if err != nil {
|
||||
return types.ContainerCreateResponse{Warnings: warnings}, err
|
||||
return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, err
|
||||
}
|
||||
|
||||
if params.HostConfig == nil {
|
||||
|
@ -52,15 +52,16 @@ func (daemon *Daemon) containerCreate(params types.ContainerCreateConfig, manage
|
|||
}
|
||||
err = daemon.adaptContainerSettings(params.HostConfig, params.AdjustCPUShares)
|
||||
if err != nil {
|
||||
return types.ContainerCreateResponse{Warnings: warnings}, err
|
||||
return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, err
|
||||
}
|
||||
|
||||
container, err := daemon.create(params, managed)
|
||||
if err != nil {
|
||||
return types.ContainerCreateResponse{Warnings: warnings}, daemon.imageNotExistToErrcode(err)
|
||||
return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, daemon.imageNotExistToErrcode(err)
|
||||
}
|
||||
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.
|
||||
|
|
|
@ -13,4 +13,5 @@ swagger generate operation -f api/swagger.yaml \
|
|||
-t api -a types -m types -C api/swagger-gen.yaml \
|
||||
-T api/templates --skip-responses --skip-parameters --skip-validator \
|
||||
-n VolumesList \
|
||||
-n VolumesCreate
|
||||
-n VolumesCreate \
|
||||
-n ContainerCreate
|
||||
|
|
|
@ -574,7 +574,7 @@ func (s *DockerSuite) TestContainerAPICreateWithHostName(c *check.C) {
|
|||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusCreated)
|
||||
|
||||
var container types.ContainerCreateResponse
|
||||
var container containertypes.ContainerCreateCreatedBody
|
||||
c.Assert(json.Unmarshal(body, &container), checker.IsNil)
|
||||
|
||||
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(status, checker.Equals, http.StatusCreated)
|
||||
|
||||
var container types.ContainerCreateResponse
|
||||
var container containertypes.ContainerCreateCreatedBody
|
||||
c.Assert(json.Unmarshal(body, &container), checker.IsNil)
|
||||
|
||||
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(status, checker.Equals, http.StatusCreated)
|
||||
|
||||
var container types.ContainerCreateResponse
|
||||
var container containertypes.ContainerCreateCreatedBody
|
||||
c.Assert(json.Unmarshal(body, &container), checker.IsNil)
|
||||
|
||||
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(status, checker.Equals, http.StatusCreated)
|
||||
|
||||
var container types.ContainerCreateResponse
|
||||
var container containertypes.ContainerCreateCreatedBody
|
||||
c.Assert(json.Unmarshal(body, &container), checker.IsNil)
|
||||
|
||||
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(status, check.Equals, http.StatusCreated)
|
||||
|
||||
var container types.ContainerCreateResponse
|
||||
var container containertypes.ContainerCreateCreatedBody
|
||||
c.Assert(json.Unmarshal(body, &container), check.IsNil)
|
||||
|
||||
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(status, check.Equals, http.StatusCreated)
|
||||
|
||||
var container types.ContainerCreateResponse
|
||||
var container containertypes.ContainerCreateCreatedBody
|
||||
c.Assert(json.Unmarshal(body, &container), check.IsNil)
|
||||
|
||||
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(status, check.Equals, http.StatusCreated)
|
||||
|
||||
var container types.ContainerCreateResponse
|
||||
var container containertypes.ContainerCreateCreatedBody
|
||||
c.Assert(json.Unmarshal(body, &container), check.IsNil)
|
||||
|
||||
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(status, check.Equals, http.StatusCreated)
|
||||
|
||||
var container types.ContainerCreateResponse
|
||||
var container containertypes.ContainerCreateCreatedBody
|
||||
c.Assert(json.Unmarshal(body, &container), check.IsNil)
|
||||
|
||||
status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
|
||||
|
|
Loading…
Reference in a new issue