From d7efdb095ed8c738f2c734cbd36102f97ec68d6f Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Thu, 8 Sep 2016 13:45:05 -0700 Subject: [PATCH] Add DiskUsage method to SystemApiclient Signed-off-by: Kenfe-Mickael Laventure --- disk_usage.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 disk_usage.go diff --git a/disk_usage.go b/disk_usage.go new file mode 100644 index 0000000000..03c80b39af --- /dev/null +++ b/disk_usage.go @@ -0,0 +1,26 @@ +package client + +import ( + "encoding/json" + "fmt" + + "github.com/docker/docker/api/types" + "golang.org/x/net/context" +) + +// DiskUsage requests the current data usage from the daemon +func (cli *Client) DiskUsage(ctx context.Context) (types.DiskUsage, error) { + var du types.DiskUsage + + serverResp, err := cli.get(ctx, "/system/df", nil, nil) + if err != nil { + return du, err + } + defer ensureReaderClosed(serverResp) + + if err := json.NewDecoder(serverResp.body).Decode(&du); err != nil { + return du, fmt.Errorf("Error retrieving disk usage: %v", err) + } + + return du, nil +}