Skip to content

Commit 36b0cb8

Browse files
committed
Add context to api calls
1 parent da1ce2f commit 36b0cb8

File tree

5 files changed

+16
-13
lines changed

5 files changed

+16
-13
lines changed

cli/container.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/docker/engine-api/types/container"
99
"github.com/docker/engine-api/types/strslice"
1010
"github.com/docker/go-connections/nat"
11+
"golang.org/x/net/context"
1112
)
1213

1314
var errNetworkNotFound = errors.New("Error: Network not found. Consider restarting dockward.")
@@ -21,7 +22,7 @@ func imageString() string {
2122

2223
// containerIp retrieves the ip address of container with id on the dockward network.
2324
func containerIp(id string) (string, error) {
24-
info, err := client.ContainerInspect(id)
25+
info, err := client.ContainerInspect(context.Background(), id)
2526
if err != nil {
2627
return "", err
2728
}
@@ -80,7 +81,7 @@ func launchBalancerContainer(hostPort int, monitorPort int, policy string, desti
8081
},
8182
}
8283

83-
resp, err := client.ContainerCreate(containerConf, hostConf, nil, "")
84+
resp, err := client.ContainerCreate(context.Background(), containerConf, hostConf, nil, "")
8485
if err != nil {
8586
return err
8687
}
@@ -89,12 +90,12 @@ func launchBalancerContainer(hostPort int, monitorPort int, policy string, desti
8990
return err
9091
}
9192

92-
if err := client.ContainerStart(resp.ID); err != nil {
93+
if err := client.ContainerStart(context.Background(), resp.ID); err != nil {
9394
return err
9495
}
9596

9697
addCleanUpFunc(func() {
97-
client.ContainerKill(resp.ID, "")
98+
client.ContainerKill(context.Background(), resp.ID, "")
9899
})
99100

100101
return err

cli/docker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func setupDocker() error {
3636

3737
func pullImage() error {
3838
// check if image is already pulled
39-
l, err := client.ImageList(types.ImageListOptions{})
39+
l, err := client.ImageList(context.Background(), types.ImageListOptions{})
4040
for i := range l {
4141
for _, tag := range l[i].RepoTags {
4242
if tag == imageString() {

cli/filter.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/abiosoft/dockward/balancer"
55
"github.com/docker/engine-api/types"
66
"github.com/docker/engine-api/types/filters"
7+
"golang.org/x/net/context"
78
)
89

910
type filterType string
@@ -19,7 +20,7 @@ const (
1920
func endpointsFromFilter(containerPort int, key, value string) (balancer.Endpoints, error) {
2021
filter := filters.NewArgs()
2122
filter.Add(key, value)
22-
containers, err := client.ContainerList(types.ContainerListOptions{Filter: filter})
23+
containers, err := client.ContainerList(context.Background(), types.ContainerListOptions{Filter: filter})
2324
if err != nil {
2425
return nil, err
2526
}

cli/monitor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func updateContainerEndpoints(msg balancer.Message, dockerHost string, endpointP
115115

116116
// validContainer validates if the container can be added/removed from endpoints.
117117
func validContainer(name string, label string) bool {
118-
info, err := client.ContainerInspect(name)
118+
info, err := client.ContainerInspect(context.Background(), name)
119119
if err != nil {
120120
log.Println(err)
121121
return false

network/network.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/abiosoft/dockward/util"
55
docker "github.com/docker/engine-api/client"
66
"github.com/docker/engine-api/types"
7+
"golang.org/x/net/context"
78
)
89

910
const namePrefix = "dockward_"
@@ -24,7 +25,7 @@ func Create(client *docker.Client) (*Network, error) {
2425

2526
// Create creates a new network using name.
2627
func CreateWithName(client *docker.Client, name string) (*Network, error) {
27-
n, err := client.NetworkCreate(types.NetworkCreate{Name: name, Internal: true})
28+
n, err := client.NetworkCreate(context.Background(), types.NetworkCreate{Name: name, Internal: true})
2829
if err != nil {
2930
return nil, err
3031
}
@@ -37,27 +38,27 @@ func CreateWithName(client *docker.Client, name string) (*Network, error) {
3738

3839
// ConnectContainer connects docker container with id to the network.
3940
func (n *Network) ConnectContainer(id string) error {
40-
return n.client.NetworkConnect(n.Id, id, nil)
41+
return n.client.NetworkConnect(context.Background(), n.Id, id, nil)
4142
}
4243

4344
// DisconnectContainer disconnects docker container with id from the network.
4445
func (n *Network) DisconnectContainer(id string) error {
45-
return n.client.NetworkDisconnect(n.Id, id, false)
46+
return n.client.NetworkDisconnect(context.Background(), n.Id, id, false)
4647
}
4748

4849
// Stop disconnects all connected docker containers from the network and
4950
// removes the network.
5051
func (n *Network) Stop() error {
51-
info, err := n.client.NetworkInspect(n.Id)
52+
info, err := n.client.NetworkInspect(context.Background(), n.Id)
5253
if err != nil {
5354
return err
5455
}
5556
// disconnect all containers from it
5657
for id, _ := range info.Containers {
57-
if err := n.client.NetworkDisconnect(n.Id, id, true); err != nil {
58+
if err := n.client.NetworkDisconnect(context.Background(), n.Id, id, true); err != nil {
5859
return err
5960
}
6061
}
6162
// Remove network
62-
return n.client.NetworkRemove(n.Id)
63+
return n.client.NetworkRemove(context.Background(), n.Id)
6364
}

0 commit comments

Comments
 (0)