2016-06-07 21:46:47 +03:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2016-06-17 02:23:42 +03:00
|
|
|
"bytes"
|
2016-06-07 21:46:47 +03:00
|
|
|
"encoding/json"
|
2016-06-17 02:23:42 +03:00
|
|
|
"io/ioutil"
|
2016-06-07 21:46:47 +03:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/docker/engine-api/types/swarm"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
2016-06-17 02:23:42 +03:00
|
|
|
// NodeInspectWithRaw returns the node information.
|
|
|
|
func (cli *Client) NodeInspectWithRaw(ctx context.Context, nodeID string) (swarm.Node, []byte, error) {
|
2016-06-07 21:46:47 +03:00
|
|
|
serverResp, err := cli.get(ctx, "/nodes/"+nodeID, nil, nil)
|
|
|
|
if err != nil {
|
|
|
|
if serverResp.statusCode == http.StatusNotFound {
|
2016-06-17 02:23:42 +03:00
|
|
|
return swarm.Node{}, nil, nodeNotFoundError{nodeID}
|
2016-06-07 21:46:47 +03:00
|
|
|
}
|
2016-06-17 02:23:42 +03:00
|
|
|
return swarm.Node{}, nil, err
|
|
|
|
}
|
|
|
|
defer ensureReaderClosed(serverResp)
|
|
|
|
|
|
|
|
body, err := ioutil.ReadAll(serverResp.body)
|
|
|
|
if err != nil {
|
|
|
|
return swarm.Node{}, nil, err
|
2016-06-07 21:46:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
var response swarm.Node
|
2016-06-17 02:23:42 +03:00
|
|
|
rdr := bytes.NewReader(body)
|
|
|
|
err = json.NewDecoder(rdr).Decode(&response)
|
|
|
|
return response, body, err
|
2016-06-07 21:46:47 +03:00
|
|
|
}
|