2016-09-06 18:46:37 +00: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 14:01:16 +00:00
|
|
|
if options.Filters.Len() > 0 {
|
|
|
|
filterJSON, err := filters.ToParam(options.Filters)
|
2016-09-06 18:46:37 +00: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
|
|
|
|
}
|