-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add networking to containers to support non-legacy link networking * gofmt
- Loading branch information
1 parent
cf6f8e2
commit 71a4012
Showing
7 changed files
with
108 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package docker | ||
|
||
import "github.com/docker/docker/api/types" | ||
|
||
// CreateNetwork creates a docker network that can | ||
// be used for communication in between containers | ||
// see: https://docs.docker.com/network/ for details | ||
func (c Client) CreateNetwork(name string) (networkID string, err error) { | ||
networkResponse, err := c.NetworkCreate(c.Ctx, name, | ||
types.NetworkCreate{ | ||
CheckDuplicate: true, | ||
Attachable: true, | ||
Labels: c.getSessionLabels(), | ||
}) | ||
if err != nil { | ||
return "", err | ||
} | ||
return networkResponse.ID, err | ||
} | ||
|
||
// RemoveNetwork removes a network by id | ||
func (c Client) RemoveNetwork(networkID string) error { | ||
return c.NetworkRemove(c.Ctx, networkID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package docker | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/docker/docker/api/types/filters" | ||
) | ||
|
||
// getSessionLabels gets labels set for all resources created in this session | ||
func (c Client) getSessionLabels() map[string]string { | ||
return map[string]string{ | ||
"sessionId": c.SessionID, | ||
"created-by": "docker-utils", | ||
} | ||
} | ||
|
||
// filterByLabels creates filters.Args based on a set of labels | ||
func filterByLabels(labels map[string]string) (args filters.Args) { | ||
var kvps []filters.KeyValuePair | ||
for key, value := range labels { | ||
kvps = append(kvps, filters.KeyValuePair{ | ||
Key: "label", | ||
Value: fmt.Sprintf("%s=%s", key, value), | ||
}) | ||
} | ||
return filters.NewArgs(kvps...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters