Skip to content

Commit

Permalink
Merge pull request #498 from allencloud/add-volume-get
Browse files Browse the repository at this point in the history
feature: add Volume Inspect API in daemon side
  • Loading branch information
Letty5411 committed Jan 4, 2018
2 parents 0bb9841 + 8e3ed79 commit c21b3e7
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
1 change: 1 addition & 0 deletions apis/server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func initRoute(s *Server) http.Handler {

// volume
r.Path("/volumes/create").Methods(http.MethodPost).Handler(s.filter(s.createVolume))
r.Path("/volumes/{name:.*}").Methods(http.MethodGet).Handler(s.filter(s.getVolume))
r.Path("/volumes/{name:.*}").Methods(http.MethodDelete).Handler(s.filter(s.removeVolume))

// metrics
Expand Down
9 changes: 9 additions & 0 deletions apis/server/volume_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ func (s *Server) createVolume(ctx context.Context, rw http.ResponseWriter, req *
return EncodeResponse(rw, http.StatusCreated, volume)
}

func (s *Server) getVolume(ctx context.Context, rw http.ResponseWriter, req *http.Request) (err error) {
name := mux.Vars(req)["name"]
volume, err := s.VolumeMgr.Get(ctx, name)
if err != nil {
return err
}
return EncodeResponse(rw, http.StatusOK, volume)
}

func (s *Server) removeVolume(ctx context.Context, rw http.ResponseWriter, req *http.Request) (err error) {
name := mux.Vars(req)["name"]

Expand Down
32 changes: 32 additions & 0 deletions apis/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,38 @@ paths:
$ref: "#/definitions/VolumeCreateConfig"
tags: ["Volume"]

/volumes/{id}:
get:
summary: "Inspect a volume"
operationId: "VolumeInspect"
produces: ["application/json"]
responses:
200:
description: "No error"
schema:
$ref: "#/definitions/VolumeInfo"
404:
$ref: "#/responses/404ErrorResponse"
500:
$ref: "#/responses/500ErrorResponse"
parameters:
- $ref: "#/parameters/id"
tags: ["Volume"]

delete:
summary: "Delete a volume"
operationId: "VolumeDelete"
responses:
204:
description: "No error"
404:
$ref: "#/responses/404ErrorResponse"
500:
$ref: "#/responses/500ErrorResponse"
parameters:
- $ref: "#/parameters/id"
tags: ["Volume"]

/networks/create:
post:
summary: "Create a network"
Expand Down
2 changes: 1 addition & 1 deletion daemon/mgr/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ func (mgr *ContainerManager) parseVolumes(ctx context.Context, c *types.Containe
source = randomid.Generate()
}
if !path.IsAbs(source) {
_, err := mgr.VolumeMgr.Info(ctx, source)
_, err := mgr.VolumeMgr.Get(ctx, source)
if err != nil {
opts := map[string]string{
"backend": "local",
Expand Down
8 changes: 4 additions & 4 deletions daemon/mgr/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ type VolumeMgr interface {
// List returns all volumes on this host.
List(ctx context.Context, labels map[string]string) ([]string, error)

// Info returns the information of volume that specified name/id.
Info(ctx context.Context, name string) (*types.Volume, error)
// Get returns the information of volume that specified name/id.
Get(ctx context.Context, name string) (*types.Volume, error)

// Path returns the mount path of volume.
Path(ctx context.Context, name string) (string, error)
Expand Down Expand Up @@ -109,8 +109,8 @@ func (vm *VolumeManager) List(ctx context.Context, labels map[string]string) ([]
return vm.core.ListVolumeName(labels)
}

// Info returns the information of volume that specified name/id.
func (vm *VolumeManager) Info(ctx context.Context, name string) (*types.Volume, error) {
// Get returns the information of volume that specified name/id.
func (vm *VolumeManager) Get(ctx context.Context, name string) (*types.Volume, error) {
id := types.VolumeID{
Name: name,
}
Expand Down

0 comments on commit c21b3e7

Please sign in to comment.