Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add Volume Inspect API in daemon side #498

Merged
merged 1 commit into from
Jan 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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