diff options
author | baude <bbaude@redhat.com> | 2020-11-11 09:45:07 -0600 |
---|---|---|
committer | baude <bbaude@redhat.com> | 2020-11-19 08:16:19 -0600 |
commit | a3e0b7d117251944375fd32449f6b26d65edf367 (patch) | |
tree | 824e4acb1529fb72276630fdd4d57127c07aadc8 /pkg/bindings/network | |
parent | 286d356db03a2511722155022c19855f8aee73cf (diff) | |
download | podman-a3e0b7d117251944375fd32449f6b26d65edf367.tar.gz podman-a3e0b7d117251944375fd32449f6b26d65edf367.tar.bz2 podman-a3e0b7d117251944375fd32449f6b26d65edf367.zip |
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 <bbaude@redhat.com>
Diffstat (limited to 'pkg/bindings/network')
-rw-r--r-- | pkg/bindings/network/network.go | 38 |
1 files changed, 38 insertions, 0 deletions
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) +} |