diff --git a/api/server/router/volume/volume_routes.go b/api/server/router/volume/volume_routes.go index 43021591bd..b8a8b577a9 100644 --- a/api/server/router/volume/volume_routes.go +++ b/api/server/router/volume/volume_routes.go @@ -43,7 +43,7 @@ func (v *volumeRouter) postVolumesCreate(ctx context.Context, w http.ResponseWri return err } - var req types.VolumeCreateRequest + var req volumetypes.VolumesCreateBody if err := json.NewDecoder(r.Body).Decode(&req); err != nil { return err } diff --git a/api/server/types/volume/volumes_create.go b/api/server/types/volume/volumes_create.go new file mode 100644 index 0000000000..98c12b9b10 --- /dev/null +++ b/api/server/types/volume/volumes_create.go @@ -0,0 +1,39 @@ +package volume + +// ---------------------------------------------------------------------------- +// DO NOT EDIT THIS FILE +// This file was generated by `swagger generate operation` +// +// See hack/swagger-gen.sh +// ---------------------------------------------------------------------------- + +/*VolumesCreateBody volumes create body + +swagger:model VolumesCreateBody +*/ +type VolumesCreateBody struct { + + /* Name of the volume driver to use. + + Required: true + */ + Driver string `json:"Driver"` + + /* A mapping of driver options and values. These options are passed directly to the driver and are driver specific. + + Required: true + */ + DriverOpts map[string]string `json:"DriverOpts"` + + /* A mapping of arbitrary key/value data to set on the volume. + + Required: true + */ + Labels map[string]string `json:"Labels"` + + /* The new volume's name. If not specified, Docker generates a name. + + Required: true + */ + Name string `json:"Name"` +} diff --git a/api/swagger.yaml b/api/swagger.yaml index cff1f754b3..682797d09b 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -5480,10 +5480,12 @@ paths: Name: description: "The new volume's name. If not specified, Docker generates a name." type: "string" + x-nullable: false Driver: description: "Name of the volume driver to use." type: "string" default: "local" + x-nullable: false DriverOpts: description: "A mapping of driver options and values. These options are passed directly to the driver and are driver specific." type: "object" diff --git a/api/types/types.go b/api/types/types.go index a1e909b01e..151e355cbe 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -410,15 +410,6 @@ type MountPoint struct { Propagation mount.Propagation } -// VolumeCreateRequest contains the request for the remote API: -// POST "/volumes/create" -type VolumeCreateRequest struct { - Name string // Name is the requested name of the volume - Driver string // Driver is the name of the driver that should be used to create the volume - DriverOpts map[string]string // DriverOpts holds the driver specific options to use for when creating the volume. - Labels map[string]string // Labels holds metadata specific to the volume being created. -} - // NetworkResource is the body of the "get network" http response message type NetworkResource struct { Name string // Name is the requested name of the network diff --git a/cli/command/volume/create.go b/cli/command/volume/create.go index fbf62a5ef1..f16e650bbc 100644 --- a/cli/command/volume/create.go +++ b/cli/command/volume/create.go @@ -5,7 +5,7 @@ import ( "golang.org/x/net/context" - "github.com/docker/docker/api/types" + volumetypes "github.com/docker/docker/api/server/types/volume" "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" "github.com/docker/docker/opts" @@ -55,7 +55,7 @@ func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command { func runCreate(dockerCli *command.DockerCli, opts createOptions) error { client := dockerCli.Client() - volReq := types.VolumeCreateRequest{ + volReq := volumetypes.VolumesCreateBody{ Driver: opts.driver, DriverOpts: opts.driverOpts.GetAll(), Name: opts.name, diff --git a/client/interface.go b/client/interface.go index 613015f865..5ec750abe1 100644 --- a/client/interface.go +++ b/client/interface.go @@ -134,7 +134,7 @@ type SystemAPIClient interface { // VolumeAPIClient defines API client methods for the volumes type VolumeAPIClient interface { - VolumeCreate(ctx context.Context, options types.VolumeCreateRequest) (types.Volume, error) + VolumeCreate(ctx context.Context, options volumetypes.VolumesCreateBody) (types.Volume, error) VolumeInspect(ctx context.Context, volumeID string) (types.Volume, error) VolumeInspectWithRaw(ctx context.Context, volumeID string) (types.Volume, []byte, error) VolumeList(ctx context.Context, filter filters.Args) (volumetypes.VolumesListOKBody, error) diff --git a/client/volume_create.go b/client/volume_create.go index f3a79f1e11..b18e5fe600 100644 --- a/client/volume_create.go +++ b/client/volume_create.go @@ -3,12 +3,13 @@ package client import ( "encoding/json" + volumetypes "github.com/docker/docker/api/server/types/volume" "github.com/docker/docker/api/types" "golang.org/x/net/context" ) // VolumeCreate creates a volume in the docker host. -func (cli *Client) VolumeCreate(ctx context.Context, options types.VolumeCreateRequest) (types.Volume, error) { +func (cli *Client) VolumeCreate(ctx context.Context, options volumetypes.VolumesCreateBody) (types.Volume, error) { var volume types.Volume resp, err := cli.post(ctx, "/volumes/create", nil, options, nil) if err != nil { diff --git a/client/volume_create_test.go b/client/volume_create_test.go index 75085296cc..d5d3791685 100644 --- a/client/volume_create_test.go +++ b/client/volume_create_test.go @@ -9,6 +9,7 @@ import ( "strings" "testing" + volumetypes "github.com/docker/docker/api/server/types/volume" "github.com/docker/docker/api/types" "golang.org/x/net/context" ) @@ -18,7 +19,7 @@ func TestVolumeCreateError(t *testing.T) { client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), } - _, err := client.VolumeCreate(context.Background(), types.VolumeCreateRequest{}) + _, err := client.VolumeCreate(context.Background(), volumetypes.VolumesCreateBody{}) if err == nil || err.Error() != "Error response from daemon: Server error" { t.Fatalf("expected a Server Error, got %v", err) } @@ -52,7 +53,7 @@ func TestVolumeCreate(t *testing.T) { }), } - volume, err := client.VolumeCreate(context.Background(), types.VolumeCreateRequest{ + volume, err := client.VolumeCreate(context.Background(), volumetypes.VolumesCreateBody{ Name: "myvolume", Driver: "mydriver", DriverOpts: map[string]string{ diff --git a/daemon/cluster/executor/container/container.go b/daemon/cluster/executor/container/container.go index 7b5203715f..ab5b0c35b5 100644 --- a/daemon/cluster/executor/container/container.go +++ b/daemon/cluster/executor/container/container.go @@ -9,6 +9,7 @@ import ( "github.com/Sirupsen/logrus" + volumetypes "github.com/docker/docker/api/server/types/volume" "github.com/docker/docker/api/types" enginecontainer "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/events" @@ -335,7 +336,7 @@ func (c *containerConfig) hostConfig() *enginecontainer.HostConfig { } // This handles the case of volumes that are defined inside a service Mount -func (c *containerConfig) volumeCreateRequest(mount *api.Mount) *types.VolumeCreateRequest { +func (c *containerConfig) volumeCreateRequest(mount *api.Mount) *volumetypes.VolumesCreateBody { var ( driverName string driverOpts map[string]string @@ -349,7 +350,7 @@ func (c *containerConfig) volumeCreateRequest(mount *api.Mount) *types.VolumeCre } if mount.VolumeOptions != nil { - return &types.VolumeCreateRequest{ + return &volumetypes.VolumesCreateBody{ Name: mount.Source, Driver: driverName, DriverOpts: driverOpts, diff --git a/hack/generate-swagger-api.sh b/hack/generate-swagger-api.sh index 12161b859c..6f64d43130 100755 --- a/hack/generate-swagger-api.sh +++ b/hack/generate-swagger-api.sh @@ -12,4 +12,5 @@ swagger generate model -f api/swagger.yaml \ swagger generate operation -f api/swagger.yaml \ -t api -s server -a types -m types \ -T api/templates --skip-responses --skip-parameters --skip-validator \ - -n VolumesList + -n VolumesList \ + -n VolumesCreate diff --git a/integration-cli/docker_api_volumes_test.go b/integration-cli/docker_api_volumes_test.go index 5db607488e..d7f4c6fc13 100644 --- a/integration-cli/docker_api_volumes_test.go +++ b/integration-cli/docker_api_volumes_test.go @@ -26,7 +26,7 @@ func (s *DockerSuite) TestVolumesAPIList(c *check.C) { } func (s *DockerSuite) TestVolumesAPICreate(c *check.C) { - config := types.VolumeCreateRequest{ + config := volumetypes.VolumesCreateBody{ Name: "test", } status, b, err := sockRequest("POST", "/volumes/create", config) @@ -65,7 +65,7 @@ func (s *DockerSuite) TestVolumesAPIRemove(c *check.C) { } func (s *DockerSuite) TestVolumesAPIInspect(c *check.C) { - config := types.VolumeCreateRequest{ + config := volumetypes.VolumesCreateBody{ Name: "test", } status, b, err := sockRequest("POST", "/volumes/create", config)