From 1b85879c039b0e09b8effe360283d92868a06bc1 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Tue, 18 Oct 2016 17:35:45 -0700 Subject: [PATCH] Generate container update response from swagger spec. Signed-off-by: Daniel Nephin Upstream-commit: f196cf6a090556ccb42198043a71d133482b510d Component: engine --- .../api/server/router/container/backend.go | 2 +- components/engine/api/swagger.yaml | 10 ++++------ .../api/types/container/container_update.go | 17 +++++++++++++++++ components/engine/api/types/types.go | 7 ------- components/engine/client/container_update.go | 5 ++--- .../engine/client/container_update_test.go | 3 +-- components/engine/client/interface.go | 2 +- components/engine/daemon/update.go | 9 ++++----- components/engine/hack/generate-swagger-api.sh | 3 ++- 9 files changed, 32 insertions(+), 26 deletions(-) create mode 100644 components/engine/api/types/container/container_update.go diff --git a/components/engine/api/server/router/container/backend.go b/components/engine/api/server/router/container/backend.go index 2a3fd8a091..0c9f081471 100644 --- a/components/engine/api/server/router/container/backend.go +++ b/components/engine/api/server/router/container/backend.go @@ -42,7 +42,7 @@ type stateBackend interface { ContainerStart(name string, hostConfig *container.HostConfig, validateHostname bool, checkpoint string, checkpointDir string) error ContainerStop(name string, seconds *int) error ContainerUnpause(name string) error - ContainerUpdate(name string, hostConfig *container.HostConfig, validateHostname bool) (types.ContainerUpdateResponse, error) + ContainerUpdate(name string, hostConfig *container.HostConfig, validateHostname bool) (container.ContainerUpdateOKBody, error) ContainerWait(name string, timeout time.Duration) (int, error) } diff --git a/components/engine/api/swagger.yaml b/components/engine/api/swagger.yaml index ad3c067e03..64ad015d41 100644 --- a/components/engine/api/swagger.yaml +++ b/components/engine/api/swagger.yaml @@ -3422,14 +3422,12 @@ paths: post: summary: "Update a container" description: "Change various configuration options of a container without having to recreate it." - operationId: "PostContainerUpdate" - consumes: - - "application/json" - produces: - - "application/json" + operationId: "ContainerUpdate" + consumes: ["application/json"] + produces: ["application/json"] responses: 200: - description: "no error" + description: "The container has been updated." schema: type: "object" properties: diff --git a/components/engine/api/types/container/container_update.go b/components/engine/api/types/container/container_update.go new file mode 100644 index 0000000000..81ee12c678 --- /dev/null +++ b/components/engine/api/types/container/container_update.go @@ -0,0 +1,17 @@ +package container + +// ---------------------------------------------------------------------------- +// DO NOT EDIT THIS FILE +// This file was generated by `swagger generate operation` +// +// See hack/swagger-gen.sh +// ---------------------------------------------------------------------------- + +// ContainerUpdateOKBody container update o k body +// swagger:model ContainerUpdateOKBody +type ContainerUpdateOKBody struct { + + // warnings + // Required: true + Warnings []string `json:"Warnings"` +} diff --git a/components/engine/api/types/types.go b/components/engine/api/types/types.go index 6dc833979a..fd58d4d856 100644 --- a/components/engine/api/types/types.go +++ b/components/engine/api/types/types.go @@ -13,13 +13,6 @@ import ( "github.com/docker/go-connections/nat" ) -// ContainerUpdateResponse contains response of Remote API: -// POST "/containers/{name:.*}/update" -type ContainerUpdateResponse struct { - // Warnings are any warnings encountered during the updating of the container. - Warnings []string `json:"Warnings"` -} - // AuthResponse contains response of Remote API: // POST "/auth" type AuthResponse struct { diff --git a/components/engine/client/container_update.go b/components/engine/client/container_update.go index 48b75bee30..5082f22dfa 100644 --- a/components/engine/client/container_update.go +++ b/components/engine/client/container_update.go @@ -3,14 +3,13 @@ package client import ( "encoding/json" - "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "golang.org/x/net/context" ) // ContainerUpdate updates resources of a container -func (cli *Client) ContainerUpdate(ctx context.Context, containerID string, updateConfig container.UpdateConfig) (types.ContainerUpdateResponse, error) { - var response types.ContainerUpdateResponse +func (cli *Client) ContainerUpdate(ctx context.Context, containerID string, updateConfig container.UpdateConfig) (container.ContainerUpdateOKBody, error) { + var response container.ContainerUpdateOKBody serverResp, err := cli.post(ctx, "/containers/"+containerID+"/update", nil, updateConfig, nil) if err != nil { return response, err diff --git a/components/engine/client/container_update_test.go b/components/engine/client/container_update_test.go index e151637a2b..715bb7ca23 100644 --- a/components/engine/client/container_update_test.go +++ b/components/engine/client/container_update_test.go @@ -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" ) @@ -33,7 +32,7 @@ func TestContainerUpdate(t *testing.T) { return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) } - b, err := json.Marshal(types.ContainerUpdateResponse{}) + b, err := json.Marshal(container.ContainerUpdateOKBody{}) if err != nil { return nil, err } diff --git a/components/engine/client/interface.go b/components/engine/client/interface.go index 2a355fa8ad..b303d2fde8 100644 --- a/components/engine/client/interface.go +++ b/components/engine/client/interface.go @@ -58,7 +58,7 @@ type ContainerAPIClient interface { ContainerStop(ctx context.Context, container string, timeout *time.Duration) error ContainerTop(ctx context.Context, container string, arguments []string) (types.ContainerProcessList, error) ContainerUnpause(ctx context.Context, container string) error - ContainerUpdate(ctx context.Context, container string, updateConfig container.UpdateConfig) (types.ContainerUpdateResponse, error) + ContainerUpdate(ctx context.Context, container string, updateConfig container.UpdateConfig) (container.ContainerUpdateOKBody, error) ContainerWait(ctx context.Context, container string) (int, error) CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) CopyToContainer(ctx context.Context, container, path string, content io.Reader, options types.CopyToContainerOptions) error diff --git a/components/engine/daemon/update.go b/components/engine/daemon/update.go index 46a3d35e5f..3e05047ae2 100644 --- a/components/engine/daemon/update.go +++ b/components/engine/daemon/update.go @@ -3,24 +3,23 @@ package daemon import ( "fmt" - "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" ) // ContainerUpdate updates configuration of the container -func (daemon *Daemon) ContainerUpdate(name string, hostConfig *container.HostConfig, validateHostname bool) (types.ContainerUpdateResponse, error) { +func (daemon *Daemon) ContainerUpdate(name string, hostConfig *container.HostConfig, validateHostname bool) (container.ContainerUpdateOKBody, error) { var warnings []string warnings, err := daemon.verifyContainerSettings(hostConfig, nil, true, validateHostname) if err != nil { - return types.ContainerUpdateResponse{Warnings: warnings}, err + return container.ContainerUpdateOKBody{Warnings: warnings}, err } if err := daemon.update(name, hostConfig); err != nil { - return types.ContainerUpdateResponse{Warnings: warnings}, err + return container.ContainerUpdateOKBody{Warnings: warnings}, err } - return types.ContainerUpdateResponse{Warnings: warnings}, nil + return container.ContainerUpdateOKBody{Warnings: warnings}, nil } // ContainerUpdateCmdOnBuild updates Path and Args for the container with ID cID. diff --git a/components/engine/hack/generate-swagger-api.sh b/components/engine/hack/generate-swagger-api.sh index 13977dbb8c..43e8da75e9 100755 --- a/components/engine/hack/generate-swagger-api.sh +++ b/components/engine/hack/generate-swagger-api.sh @@ -15,4 +15,5 @@ swagger generate operation -f api/swagger.yaml \ -T api/templates --skip-responses --skip-parameters --skip-validator \ -n VolumesList \ -n VolumesCreate \ - -n ContainerCreate + -n ContainerCreate \ + -n ContainerUpdate