From a3e0b7d117251944375fd32449f6b26d65edf367 Mon Sep 17 00:00:00 2001 From: baude Date: Wed, 11 Nov 2020 09:45:07 -0600 Subject: add network connect|disconnect compat endpoints this enables the ability to connect and disconnect a container from a given network. it is only for the compatibility layer. some code had to be refactored to avoid circular imports. additionally, tests are being deferred temporarily due to some incompatibility/bug in either docker-py or our stack. Signed-off-by: baude --- pkg/bindings/network/network.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'pkg/bindings') diff --git a/pkg/bindings/network/network.go b/pkg/bindings/network/network.go index 151d15d3e..1d4be8a4c 100644 --- a/pkg/bindings/network/network.go +++ b/pkg/bindings/network/network.go @@ -88,3 +88,41 @@ func List(ctx context.Context, options entities.NetworkListOptions) ([]*entities } return netList, response.Process(&netList) } + +// Disconnect removes a container from a given network +func Disconnect(ctx context.Context, networkName string, options entities.NetworkDisconnectOptions) error { + conn, err := bindings.GetClient(ctx) + if err != nil { + return err + } + params := url.Values{} + body, err := jsoniter.MarshalToString(options) + if err != nil { + return err + } + stringReader := strings.NewReader(body) + response, err := conn.DoRequest(stringReader, http.MethodPost, "/networks/%s/disconnect", params, nil, networkName) + if err != nil { + return err + } + return response.Process(nil) +} + +// Connect adds a container to a network +func Connect(ctx context.Context, networkName string, options entities.NetworkConnectOptions) error { + conn, err := bindings.GetClient(ctx) + if err != nil { + return err + } + params := url.Values{} + body, err := jsoniter.MarshalToString(options) + if err != nil { + return err + } + stringReader := strings.NewReader(body) + response, err := conn.DoRequest(stringReader, http.MethodPost, "/networks/%s/connect", params, nil, networkName) + if err != nil { + return err + } + return response.Process(nil) +} -- cgit v1.2.3-54-g00ecf