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