2018-02-05 21:05:59 +00:00
|
|
|
package client // import "github.com/docker/docker/client"
|
2016-09-06 18:46:37 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2018-04-19 22:30:59 +00:00
|
|
|
"context"
|
2016-09-06 18:46:37 +00:00
|
|
|
"encoding/json"
|
|
|
|
"io/ioutil"
|
2017-03-09 19:42:10 +00:00
|
|
|
"net/url"
|
2016-09-06 18:46:37 +00:00
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NetworkInspect returns the information for a specific network configured in the docker host.
|
2017-06-11 18:04:35 +00:00
|
|
|
func (cli *Client) NetworkInspect(ctx context.Context, networkID string, options types.NetworkInspectOptions) (types.NetworkResource, error) {
|
|
|
|
networkResource, _, err := cli.NetworkInspectWithRaw(ctx, networkID, options)
|
2016-09-06 18:46:37 +00:00
|
|
|
return networkResource, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// NetworkInspectWithRaw returns the information for a specific network configured in the docker host and its raw representation.
|
2017-06-11 18:04:35 +00:00
|
|
|
func (cli *Client) NetworkInspectWithRaw(ctx context.Context, networkID string, options types.NetworkInspectOptions) (types.NetworkResource, []byte, error) {
|
2018-01-30 12:35:22 +00:00
|
|
|
if networkID == "" {
|
|
|
|
return types.NetworkResource{}, nil, objectNotFoundError{object: "network", id: networkID}
|
|
|
|
}
|
2017-03-09 19:42:10 +00:00
|
|
|
var (
|
|
|
|
networkResource types.NetworkResource
|
|
|
|
resp serverResponse
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
query := url.Values{}
|
2017-06-11 18:04:35 +00:00
|
|
|
if options.Verbose {
|
2017-03-09 19:42:10 +00:00
|
|
|
query.Set("verbose", "true")
|
|
|
|
}
|
2017-06-11 18:04:35 +00:00
|
|
|
if options.Scope != "" {
|
|
|
|
query.Set("scope", options.Scope)
|
|
|
|
}
|
2017-03-09 19:42:10 +00:00
|
|
|
resp, err = cli.get(ctx, "/networks/"+networkID, query, nil)
|
2019-02-11 12:26:12 +00:00
|
|
|
defer ensureReaderClosed(resp)
|
2016-09-06 18:46:37 +00:00
|
|
|
if err != nil {
|
2017-09-08 16:04:34 +00:00
|
|
|
return networkResource, nil, wrapResponseError(err, resp, "network", networkID)
|
2016-09-06 18:46:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
body, err := ioutil.ReadAll(resp.body)
|
|
|
|
if err != nil {
|
|
|
|
return networkResource, nil, err
|
|
|
|
}
|
|
|
|
rdr := bytes.NewReader(body)
|
|
|
|
err = json.NewDecoder(rdr).Decode(&networkResource)
|
|
|
|
return networkResource, body, err
|
|
|
|
}
|