summaryrefslogtreecommitdiff
path: root/pkg/bindings/network
diff options
context:
space:
mode:
authorPaul Holzinger <paul.holzinger@web.de>2021-01-18 18:52:06 +0100
committerPaul Holzinger <paul.holzinger@web.de>2021-01-19 15:18:03 +0100
commita45d22a1ddd2840cf8c3a38540aa8683cc0d5c7d (patch)
treedfda1d8d5f64baa183dc0f166e2441d8719b1cc8 /pkg/bindings/network
parent5b3c7a52939275784c45c9747dd5864bd0581ff5 (diff)
downloadpodman-a45d22a1ddd2840cf8c3a38540aa8683cc0d5c7d.tar.gz
podman-a45d22a1ddd2840cf8c3a38540aa8683cc0d5c7d.tar.bz2
podman-a45d22a1ddd2840cf8c3a38540aa8683cc0d5c7d.zip
podman network exists
Add podman network exists command with remote support. Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
Diffstat (limited to 'pkg/bindings/network')
-rw-r--r--pkg/bindings/network/network.go13
-rw-r--r--pkg/bindings/network/types.go6
-rw-r--r--pkg/bindings/network/types_exists_options.go88
3 files changed, 107 insertions, 0 deletions
diff --git a/pkg/bindings/network/network.go b/pkg/bindings/network/network.go
index 7cd251b0e..8debeee84 100644
--- a/pkg/bindings/network/network.go
+++ b/pkg/bindings/network/network.go
@@ -167,3 +167,16 @@ func Connect(ctx context.Context, networkName string, ContainerNameOrId string,
}
return response.Process(nil)
}
+
+// Exists returns true if a given network exists
+func Exists(ctx context.Context, nameOrID string, options *ExistsOptions) (bool, error) {
+ conn, err := bindings.GetClient(ctx)
+ if err != nil {
+ return false, err
+ }
+ response, err := conn.DoRequest(nil, http.MethodGet, "/networks/%s/exists", nil, nil, nameOrID)
+ if err != nil {
+ return false, err
+ }
+ return response.IsSuccess(), nil
+}
diff --git a/pkg/bindings/network/types.go b/pkg/bindings/network/types.go
index 2a7e500dd..91cbcf044 100644
--- a/pkg/bindings/network/types.go
+++ b/pkg/bindings/network/types.go
@@ -68,3 +68,9 @@ type ConnectOptions struct {
// when using the dns plugin
Aliases *[]string
}
+
+//go:generate go run ../generator/generator.go ExistsOptions
+// ExistsOptions are optional options for checking
+// if a network exists
+type ExistsOptions struct {
+}
diff --git a/pkg/bindings/network/types_exists_options.go b/pkg/bindings/network/types_exists_options.go
new file mode 100644
index 000000000..8076a18e8
--- /dev/null
+++ b/pkg/bindings/network/types_exists_options.go
@@ -0,0 +1,88 @@
+package network
+
+import (
+ "net/url"
+ "reflect"
+ "strconv"
+ "strings"
+
+ jsoniter "github.com/json-iterator/go"
+ "github.com/pkg/errors"
+)
+
+/*
+This file is generated automatically by go generate. Do not edit.
+*/
+
+// Changed
+func (o *ExistsOptions) Changed(fieldName string) bool {
+ r := reflect.ValueOf(o)
+ value := reflect.Indirect(r).FieldByName(fieldName)
+ return !value.IsNil()
+}
+
+// ToParams
+func (o *ExistsOptions) ToParams() (url.Values, error) {
+ params := url.Values{}
+ if o == nil {
+ return params, nil
+ }
+ json := jsoniter.ConfigCompatibleWithStandardLibrary
+ s := reflect.ValueOf(o)
+ if reflect.Ptr == s.Kind() {
+ s = s.Elem()
+ }
+ sType := s.Type()
+ for i := 0; i < s.NumField(); i++ {
+ fieldName := sType.Field(i).Name
+ if !o.Changed(fieldName) {
+ continue
+ }
+ fieldName = strings.ToLower(fieldName)
+ f := s.Field(i)
+ if reflect.Ptr == f.Kind() {
+ f = f.Elem()
+ }
+ switch f.Kind() {
+ case reflect.Bool:
+ params.Set(fieldName, strconv.FormatBool(f.Bool()))
+ case reflect.String:
+ params.Set(fieldName, f.String())
+ case reflect.Int, reflect.Int64:
+ // f.Int() is always an int64
+ params.Set(fieldName, strconv.FormatInt(f.Int(), 10))
+ case reflect.Uint, reflect.Uint64:
+ // f.Uint() is always an uint64
+ params.Set(fieldName, strconv.FormatUint(f.Uint(), 10))
+ case reflect.Slice:
+ typ := reflect.TypeOf(f.Interface()).Elem()
+ switch typ.Kind() {
+ case reflect.String:
+ sl := f.Slice(0, f.Len())
+ s, ok := sl.Interface().([]string)
+ if !ok {
+ return nil, errors.New("failed to convert to string slice")
+ }
+ for _, val := range s {
+ params.Add(fieldName, val)
+ }
+ default:
+ return nil, errors.Errorf("unknown slice type %s", f.Kind().String())
+ }
+ case reflect.Map:
+ lowerCaseKeys := make(map[string][]string)
+ iter := f.MapRange()
+ for iter.Next() {
+ lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string)
+
+ }
+ s, err := json.MarshalToString(lowerCaseKeys)
+ if err != nil {
+ return nil, err
+ }
+
+ params.Set(fieldName, s)
+ }
+ }
+ return params, nil
+}