2018-02-05 16:05:59 -05:00
|
|
|
package client // import "github.com/docker/docker/client"
|
2016-09-06 14:46:37 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
|
|
|
"io/ioutil"
|
2017-09-07 13:46:23 -04:00
|
|
|
"path"
|
2016-09-06 14:46:37 -04:00
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
// VolumeInspect returns the information about a specific volume in the docker host.
|
|
|
|
func (cli *Client) VolumeInspect(ctx context.Context, volumeID string) (types.Volume, error) {
|
|
|
|
volume, _, err := cli.VolumeInspectWithRaw(ctx, volumeID)
|
|
|
|
return volume, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// VolumeInspectWithRaw returns the information about a specific volume in the docker host and its raw representation
|
|
|
|
func (cli *Client) VolumeInspectWithRaw(ctx context.Context, volumeID string) (types.Volume, []byte, error) {
|
2017-09-07 13:46:23 -04:00
|
|
|
// The empty ID needs to be handled here because with an empty ID the
|
|
|
|
// request url will not contain a trailing / which calls the volume list API
|
|
|
|
// instead of volume inspect
|
|
|
|
if volumeID == "" {
|
2017-09-08 12:04:34 -04:00
|
|
|
return types.Volume{}, nil, objectNotFoundError{object: "volume", id: volumeID}
|
2017-09-07 13:46:23 -04:00
|
|
|
}
|
|
|
|
|
2016-09-06 14:46:37 -04:00
|
|
|
var volume types.Volume
|
2017-09-07 13:46:23 -04:00
|
|
|
resp, err := cli.get(ctx, path.Join("/volumes", volumeID), nil, nil)
|
2016-09-06 14:46:37 -04:00
|
|
|
if err != nil {
|
2017-09-08 12:04:34 -04:00
|
|
|
return volume, nil, wrapResponseError(err, resp, "volume", volumeID)
|
2016-09-06 14:46:37 -04:00
|
|
|
}
|
|
|
|
defer ensureReaderClosed(resp)
|
|
|
|
|
|
|
|
body, err := ioutil.ReadAll(resp.body)
|
|
|
|
if err != nil {
|
|
|
|
return volume, nil, err
|
|
|
|
}
|
|
|
|
rdr := bytes.NewReader(body)
|
|
|
|
err = json.NewDecoder(rdr).Decode(&volume)
|
|
|
|
return volume, body, err
|
|
|
|
}
|