summaryrefslogtreecommitdiff
path: root/pkg/bindings
diff options
context:
space:
mode:
authorBrent Baude <bbaude@redhat.com>2020-05-12 13:04:10 -0500
committerBrent Baude <bbaude@redhat.com>2020-05-12 13:23:43 -0500
commitcf502b99feda401ced410fbcfd1a3a2663c7a559 (patch)
tree408c4ae509fc8563da7ae1ac3f8d141cfd96e695 /pkg/bindings
parent5b4e91db73a80f31f67b7c28832527e64b074b74 (diff)
downloadpodman-cf502b99feda401ced410fbcfd1a3a2663c7a559.tar.gz
podman-cf502b99feda401ced410fbcfd1a3a2663c7a559.tar.bz2
podman-cf502b99feda401ced410fbcfd1a3a2663c7a559.zip
enable podman v2 networking for remote client
Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'pkg/bindings')
-rw-r--r--pkg/bindings/network/network.go62
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 {