summaryrefslogtreecommitdiff
path: root/pkg/bindings
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-01-21 15:31:32 -0500
committerGitHub <noreply@github.com>2021-01-21 15:31:32 -0500
commit6fd83de31dab0c60932972c6b26f68fa0bd1871f (patch)
treed017ed4d59da4a0f0b703430d60b2d2f43484aaa /pkg/bindings
parent3ba1a8de8649db2f5cdde80d0f4cf02370e10b8a (diff)
parent9d31fed5f75186f618e95ab7492ef6bc2b511d5f (diff)
downloadpodman-6fd83de31dab0c60932972c6b26f68fa0bd1871f.tar.gz
podman-6fd83de31dab0c60932972c6b26f68fa0bd1871f.tar.bz2
podman-6fd83de31dab0c60932972c6b26f68fa0bd1871f.zip
Merge pull request #9027 from Luap99/podman-volume-exists
Podman volume exists
Diffstat (limited to 'pkg/bindings')
-rw-r--r--pkg/bindings/volumes/types.go6
-rw-r--r--pkg/bindings/volumes/types_exists_options.go88
-rw-r--r--pkg/bindings/volumes/volumes.go13
3 files changed, 107 insertions, 0 deletions
diff --git a/pkg/bindings/volumes/types.go b/pkg/bindings/volumes/types.go
index 379174e33..3fda77ddd 100644
--- a/pkg/bindings/volumes/types.go
+++ b/pkg/bindings/volumes/types.go
@@ -30,3 +30,9 @@ type RemoveOptions struct {
// Force removes the volume even if it is being used
Force *bool
}
+
+//go:generate go run ../generator/generator.go ExistsOptions
+// ExistsOptions are optional options for checking
+// if a volume exists
+type ExistsOptions struct {
+}
diff --git a/pkg/bindings/volumes/types_exists_options.go b/pkg/bindings/volumes/types_exists_options.go
new file mode 100644
index 000000000..c66586a23
--- /dev/null
+++ b/pkg/bindings/volumes/types_exists_options.go
@@ -0,0 +1,88 @@
+package volumes
+
+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
+}
diff --git a/pkg/bindings/volumes/volumes.go b/pkg/bindings/volumes/volumes.go
index fe081eb46..60fdd0a23 100644
--- a/pkg/bindings/volumes/volumes.go
+++ b/pkg/bindings/volumes/volumes.go
@@ -114,3 +114,16 @@ func Remove(ctx context.Context, nameOrID string, options *RemoveOptions) error
}
return response.Process(nil)
}
+
+// Exists returns true if a given volume 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, "/volumes/%s/exists", nil, nil, nameOrID)
+ if err != nil {
+ return false, err
+ }
+ return response.IsSuccess(), nil
+}