Generate VolumesCreateRequest from the swagger spec.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2016-10-06 12:57:17 -04:00
parent bc75738545
commit 5c2498fd3c
11 changed files with 57 additions and 21 deletions

View File

@ -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
}

View File

@ -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"`
}

View File

@ -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"

View File

@ -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

View File

@ -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,

View File

@ -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)

View File

@ -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 {

View File

@ -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{

View File

@ -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,

View File

@ -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

View File

@ -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)