2016-10-18 04:36:52 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
2016-11-17 05:46:37 +00:00
|
|
|
"github.com/docker/docker/api/types/filters"
|
2016-10-18 04:36:52 +00:00
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NetworksPrune requests the daemon to delete unused networks
|
2016-11-17 05:46:37 +00:00
|
|
|
func (cli *Client) NetworksPrune(ctx context.Context, pruneFilters filters.Args) (types.NetworksPruneReport, error) {
|
2016-10-18 04:36:52 +00:00
|
|
|
var report types.NetworksPruneReport
|
|
|
|
|
2016-11-17 05:46:37 +00:00
|
|
|
if err := cli.NewVersionError("1.25", "network prune"); err != nil {
|
|
|
|
return report, err
|
|
|
|
}
|
|
|
|
|
|
|
|
query, err := getFiltersQuery(pruneFilters)
|
|
|
|
if err != nil {
|
|
|
|
return report, err
|
|
|
|
}
|
|
|
|
|
|
|
|
serverResp, err := cli.post(ctx, "/networks/prune", query, nil, nil)
|
2016-10-18 04:36:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return report, err
|
|
|
|
}
|
|
|
|
defer ensureReaderClosed(serverResp)
|
|
|
|
|
|
|
|
if err := json.NewDecoder(serverResp.body).Decode(&report); err != nil {
|
|
|
|
return report, fmt.Errorf("Error retrieving network prune report: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return report, nil
|
|
|
|
}
|