diff --git a/api/server/router/volume/volume_routes.go b/api/server/router/volume/volume_routes.go index 43021591bd760c2feaf7a3ab58d5300010517184..b8a8b577a91475fda98980ea95f73e9e014cf10c 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 0000000000000000000000000000000000000000..98c12b9b10b8acff1ba46fdc719c210bae8c1b09 --- /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 cff1f754b3835eb96166f26f6b4ebf8642742ba6..682797d09bda5ed7dc3263fde67aa6de1b990b20 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 a1e909b01e5e2c5f99a306c308cf727f7132a9ba..151e355cbe9751cd82aa14ed13137747222e10b9 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 fbf62a5ef105987a34b200d63d27df353339b490..f16e650bbc48091847422f132d52de6629cc0c34 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 613015f86593ab98af8a093e23d261e7d6a12bfb..5ec750abe1908cdc43f687e5238fc4f8df78203b 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 f3a79f1e11ea302d2813a5aa02e87411cb1a7318..b18e5fe600592f4bb7321339e606df65314e3b2e 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 75085296cc2bff4e2125724dc5e8af3781544b3b..d5d3791685ce56782ed10f6f1b2cd0bc51b658f4 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 7b5203715f803a512955729f10cd028ff54c4164..ab5b0c35b584f699c9893f93d9f0b69867d817e2 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 12161b859c7575089204a27c97b30decb9861b1b..6f64d43130ff7d5c6caadef833ba4460f69a2283 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 5db607488e78f08ea61528ebb43ef33b46986a45..d7f4c6fc135dfaf60c31583bc2b3de3a738f482a 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)