diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-05-13 12:24:05 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-13 12:24:05 -0700 |
commit | 886b2cc4b10c32611b45da983fa9d1318d38356a (patch) | |
tree | 4484691fbb13faef71e7b11cfa3a81ab46c9fee2 /pkg/bindings | |
parent | d147b3ee027580dd7afdeb0fa04d990ae1d2ee91 (diff) | |
parent | cf502b99feda401ced410fbcfd1a3a2663c7a559 (diff) | |
download | podman-886b2cc4b10c32611b45da983fa9d1318d38356a.tar.gz podman-886b2cc4b10c32611b45da983fa9d1318d38356a.tar.bz2 podman-886b2cc4b10c32611b45da983fa9d1318d38356a.zip |
Merge pull request #6197 from baude/v2remotenetwork
enable podman v2 networking for remote client
Diffstat (limited to 'pkg/bindings')
-rw-r--r-- | pkg/bindings/network/network.go | 62 |
1 files changed, 49 insertions, 13 deletions
diff --git a/pkg/bindings/network/network.go b/pkg/bindings/network/network.go index c95b22953..7bba4f478 100644 --- a/pkg/bindings/network/network.go +++ b/pkg/bindings/network/network.go @@ -3,40 +3,76 @@ package network import ( "context" "net/http" + "net/url" + "strconv" + "strings" - "github.com/containernetworking/cni/libcni" "github.com/containers/libpod/pkg/bindings" + "github.com/containers/libpod/pkg/domain/entities" + jsoniter "github.com/json-iterator/go" ) -func Create() {} -func Inspect(ctx context.Context, nameOrID string) (map[string]interface{}, error) { +// Create makes a new CNI network configuration +func Create(ctx context.Context, options entities.NetworkCreateOptions, name *string) (*entities.NetworkCreateReport, error) { + var report entities.NetworkCreateReport + conn, err := bindings.GetClient(ctx) + if err != nil { + return nil, err + } + params := url.Values{} + if name != nil { + params.Set("name", *name) + } + networkConfig, err := jsoniter.MarshalToString(options) + if err != nil { + return nil, err + } + stringReader := strings.NewReader(networkConfig) + response, err := conn.DoRequest(stringReader, http.MethodPost, "/networks/create", params) + if err != nil { + return nil, err + } + return &report, response.Process(&report) +} + +// Inspect returns low level information about a CNI network configuration +func Inspect(ctx context.Context, nameOrID string) ([]entities.NetworkInspectReport, error) { + var reports []entities.NetworkInspectReport conn, err := bindings.GetClient(ctx) if err != nil { return nil, err } - n := make(map[string]interface{}) response, err := conn.DoRequest(nil, http.MethodGet, "/networks/%s/json", nil, nameOrID) if err != nil { - return n, err + return nil, err } - return n, response.Process(&n) + return reports, response.Process(&reports) } -func Remove(ctx context.Context, nameOrID string) error { +// Remove deletes a defined CNI network configuration by name. The optional force boolean +// will remove all containers associated with the network when set to true. A slice +// of NetworkRemoveReports are returned. +func Remove(ctx context.Context, nameOrID string, force *bool) ([]*entities.NetworkRmReport, error) { + var reports []*entities.NetworkRmReport conn, err := bindings.GetClient(ctx) if err != nil { - return err + return nil, err } - response, err := conn.DoRequest(nil, http.MethodDelete, "/networks/%s", nil, nameOrID) + params := url.Values{} + if force != nil { + params.Set("size", strconv.FormatBool(*force)) + } + response, err := conn.DoRequest(nil, http.MethodDelete, "/networks/%s", params, nameOrID) if err != nil { - return err + return nil, err } - return response.Process(nil) + return reports, response.Process(&reports) } -func List(ctx context.Context) ([]*libcni.NetworkConfigList, error) { +// List returns a summary of all CNI network configurations +func List(ctx context.Context) ([]*entities.NetworkListReport, error) { var ( - netList []*libcni.NetworkConfigList + netList []*entities.NetworkListReport ) conn, err := bindings.GetClient(ctx) if err != nil { |