2018-02-05 21:05:59 +00:00
|
|
|
package client // import "github.com/docker/docker/client"
|
2016-09-08 20:45:05 +00:00
|
|
|
|
|
|
|
import (
|
2018-04-19 22:30:59 +00:00
|
|
|
"context"
|
2016-09-08 20:45:05 +00:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2021-06-23 13:26:54 +00:00
|
|
|
"net/url"
|
2016-09-08 20:45:05 +00:00
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DiskUsage requests the current data usage from the daemon
|
2021-06-23 13:26:54 +00:00
|
|
|
func (cli *Client) DiskUsage(ctx context.Context, options types.DiskUsageOptions) (types.DiskUsage, error) {
|
|
|
|
var query url.Values
|
|
|
|
if len(options.Types) > 0 {
|
|
|
|
query = url.Values{}
|
|
|
|
for _, t := range options.Types {
|
|
|
|
query.Add("type", string(t))
|
|
|
|
}
|
|
|
|
}
|
2016-09-08 20:45:05 +00:00
|
|
|
|
2021-06-23 13:26:54 +00:00
|
|
|
serverResp, err := cli.get(ctx, "/system/df", query, nil)
|
2019-02-11 12:26:12 +00:00
|
|
|
defer ensureReaderClosed(serverResp)
|
2016-09-08 20:45:05 +00:00
|
|
|
if err != nil {
|
2021-06-23 13:26:54 +00:00
|
|
|
return types.DiskUsage{}, err
|
2016-09-08 20:45:05 +00:00
|
|
|
}
|
|
|
|
|
2021-06-23 13:26:54 +00:00
|
|
|
var du types.DiskUsage
|
2016-09-08 20:45:05 +00:00
|
|
|
if err := json.NewDecoder(serverResp.body).Decode(&du); err != nil {
|
2021-06-23 13:26:54 +00:00
|
|
|
return types.DiskUsage{}, fmt.Errorf("Error retrieving disk usage: %v", err)
|
2016-09-08 20:45:05 +00:00
|
|
|
}
|
|
|
|
return du, nil
|
|
|
|
}
|