2018-02-05 16:05:59 -05:00
|
|
|
package client // import "github.com/docker/docker/client"
|
2016-09-08 16:45:05 -04:00
|
|
|
|
|
|
|
import (
|
2018-04-19 18:30:59 -04:00
|
|
|
"context"
|
2016-09-08 16:45:05 -04:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2021-06-23 09:26:54 -04:00
|
|
|
"net/url"
|
2016-09-08 16:45:05 -04:00
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DiskUsage requests the current data usage from the daemon
|
2021-06-23 09:26:54 -04: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 16:45:05 -04:00
|
|
|
|
2021-06-23 09:26:54 -04:00
|
|
|
serverResp, err := cli.get(ctx, "/system/df", query, nil)
|
2019-02-11 07:26:12 -05:00
|
|
|
defer ensureReaderClosed(serverResp)
|
2016-09-08 16:45:05 -04:00
|
|
|
if err != nil {
|
2021-06-23 09:26:54 -04:00
|
|
|
return types.DiskUsage{}, err
|
2016-09-08 16:45:05 -04:00
|
|
|
}
|
|
|
|
|
2021-06-23 09:26:54 -04:00
|
|
|
var du types.DiskUsage
|
2016-09-08 16:45:05 -04:00
|
|
|
if err := json.NewDecoder(serverResp.body).Decode(&du); err != nil {
|
2021-06-23 09:26:54 -04:00
|
|
|
return types.DiskUsage{}, fmt.Errorf("Error retrieving disk usage: %v", err)
|
2016-09-08 16:45:05 -04:00
|
|
|
}
|
|
|
|
return du, nil
|
|
|
|
}
|