Tizen_4.0 base
[platform/upstream/docker-engine.git] / client / network_inspect.go
1 package client
2
3 import (
4         "bytes"
5         "encoding/json"
6         "io/ioutil"
7         "net/http"
8         "net/url"
9
10         "github.com/docker/docker/api/types"
11         "golang.org/x/net/context"
12 )
13
14 // NetworkInspect returns the information for a specific network configured in the docker host.
15 func (cli *Client) NetworkInspect(ctx context.Context, networkID string, options types.NetworkInspectOptions) (types.NetworkResource, error) {
16         networkResource, _, err := cli.NetworkInspectWithRaw(ctx, networkID, options)
17         return networkResource, err
18 }
19
20 // NetworkInspectWithRaw returns the information for a specific network configured in the docker host and its raw representation.
21 func (cli *Client) NetworkInspectWithRaw(ctx context.Context, networkID string, options types.NetworkInspectOptions) (types.NetworkResource, []byte, error) {
22         var (
23                 networkResource types.NetworkResource
24                 resp            serverResponse
25                 err             error
26         )
27         query := url.Values{}
28         if options.Verbose {
29                 query.Set("verbose", "true")
30         }
31         if options.Scope != "" {
32                 query.Set("scope", options.Scope)
33         }
34         resp, err = cli.get(ctx, "/networks/"+networkID, query, nil)
35         if err != nil {
36                 if resp.statusCode == http.StatusNotFound {
37                         return networkResource, nil, networkNotFoundError{networkID}
38                 }
39                 return networkResource, nil, err
40         }
41         defer ensureReaderClosed(resp)
42
43         body, err := ioutil.ReadAll(resp.body)
44         if err != nil {
45                 return networkResource, nil, err
46         }
47         rdr := bytes.NewReader(body)
48         err = json.NewDecoder(rdr).Decode(&networkResource)
49         return networkResource, body, err
50 }