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"
|
2018-04-19 18:30:59 -04:00
|
|
|
"context"
|
2016-09-06 14:46:37 -04:00
|
|
|
"encoding/json"
|
|
|
|
"io/ioutil"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
|
|
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
|
2018-01-30 07:35:22 -05:00
|
|
|
resp, err := cli.get(ctx, "/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
|
|
|
|
}
|