2016-09-06 14:46:37 -04:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/api/types/filters"
|
|
|
|
"github.com/docker/docker/api/types/swarm"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NodeList returns the list of nodes.
|
|
|
|
func (cli *Client) NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error) {
|
|
|
|
query := url.Values{}
|
|
|
|
|
2016-11-01 10:01:16 -04:00
|
|
|
if options.Filters.Len() > 0 {
|
2017-09-26 07:59:45 -04:00
|
|
|
filterJSON, err := filters.ToJSON(options.Filters)
|
2016-09-06 14:46:37 -04:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
query.Set("filters", filterJSON)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := cli.get(ctx, "/nodes", query, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var nodes []swarm.Node
|
|
|
|
err = json.NewDecoder(resp.body).Decode(&nodes)
|
|
|
|
ensureReaderClosed(resp)
|
|
|
|
return nodes, err
|
|
|
|
}
|