Merge pull request #8752 from baude/bindings3volumes

misc bindings to podman v3
This commit is contained in:
OpenShift Merge Robot
2020-12-17 17:22:37 +00:00
committed by GitHub
73 changed files with 3614 additions and 297 deletions

View File

@ -107,7 +107,7 @@ func push(cmd *cobra.Command, args []string) error {
if cmd.Flags().Changed("tls-verify") { if cmd.Flags().Changed("tls-verify") {
manifestPushOpts.SkipTLSVerify = types.NewOptionalBool(!manifestPushOpts.TLSVerifyCLI) manifestPushOpts.SkipTLSVerify = types.NewOptionalBool(!manifestPushOpts.TLSVerifyCLI)
} }
if err := registry.ImageEngine().ManifestPush(registry.Context(), args, manifestPushOpts.ManifestPushOptions); err != nil { if err := registry.ImageEngine().ManifestPush(registry.Context(), args[0], args[1], manifestPushOpts.ManifestPushOptions); err != nil {
return err return err
} }
return nil return nil

View File

@ -4,6 +4,7 @@ import (
"bufio" "bufio"
"context" "context"
"fmt" "fmt"
"net/url"
"os" "os"
"strings" "strings"
@ -12,12 +13,13 @@ import (
"github.com/containers/podman/v2/cmd/podman/utils" "github.com/containers/podman/v2/cmd/podman/utils"
"github.com/containers/podman/v2/cmd/podman/validate" "github.com/containers/podman/v2/cmd/podman/validate"
"github.com/containers/podman/v2/pkg/domain/entities" "github.com/containers/podman/v2/pkg/domain/entities"
"github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var ( var (
pruneOptions = entities.SystemPruneOptions{} pruneOptions = entities.SystemPruneOptions{}
filters []string
pruneDescription = fmt.Sprintf(` pruneDescription = fmt.Sprintf(`
podman system prune podman system prune
@ -47,7 +49,7 @@ func init() {
flags.BoolVarP(&pruneOptions.All, "all", "a", false, "Remove all unused data") flags.BoolVarP(&pruneOptions.All, "all", "a", false, "Remove all unused data")
flags.BoolVar(&pruneOptions.Volume, "volumes", false, "Prune volumes") flags.BoolVar(&pruneOptions.Volume, "volumes", false, "Prune volumes")
filterFlagName := "filter" filterFlagName := "filter"
flags.StringArrayVar(&pruneOptions.Filter, filterFlagName, []string{}, "Provide filter values (e.g. 'label=<key>=<value>')") flags.StringArrayVar(&filters, filterFlagName, []string{}, "Provide filter values (e.g. 'label=<key>=<value>')")
_ = pruneCommand.RegisterFlagCompletionFunc(filterFlagName, completion.AutocompleteNone) _ = pruneCommand.RegisterFlagCompletionFunc(filterFlagName, completion.AutocompleteNone)
} }
@ -77,6 +79,15 @@ Are you sure you want to continue? [y/N] `, volumeString)
} }
} }
pruneOptions.ContainerPruneOptions = entities.ContainerPruneOptions{}
for _, f := range filters {
t := strings.SplitN(f, "=", 2)
pruneOptions.ContainerPruneOptions.Filters = make(url.Values)
if len(t) < 2 {
return errors.Errorf("filter input must be in the form of filter=value: %s is invalid", f)
}
pruneOptions.ContainerPruneOptions.Filters.Add(t[0], t[1])
}
// TODO: support for filters in system prune // TODO: support for filters in system prune
response, err := registry.ContainerEngine().SystemPrune(context.Background(), pruneOptions) response, err := registry.ContainerEngine().SystemPrune(context.Background(), pruneOptions)
if err != nil { if err != nil {
@ -100,7 +111,5 @@ Are you sure you want to continue? [y/N] `, volumeString)
} }
} }
// Print Images prune results // Print Images prune results
utils.PrintImagePruneResults(response.ImagePruneReport, true) return utils.PrintImagePruneResults(response.ImagePruneReport, true)
return nil
} }

View File

@ -33,6 +33,8 @@ func filtersFromRequest(r *http.Request) ([]string, error) {
if _, found := r.URL.Query()["filters"]; found { if _, found := r.URL.Query()["filters"]; found {
raw = []byte(r.Form.Get("filters")) raw = []byte(r.Form.Get("filters"))
} else if _, found := r.URL.Query()["Filters"]; found {
raw = []byte(r.Form.Get("Filters"))
} else { } else {
return []string{}, nil return []string{}, nil
} }
@ -95,7 +97,6 @@ func GetEvents(w http.ResponseWriter, r *http.Request) {
utils.Error(w, "failed to parse parameters", http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String())) utils.Error(w, "failed to parse parameters", http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
return return
} }
eventChannel := make(chan *events.Event) eventChannel := make(chan *events.Event)
errorChannel := make(chan error) errorChannel := make(chan error)

View File

@ -286,7 +286,7 @@ func ExportImages(w http.ResponseWriter, r *http.Request) {
case define.OCIManifestDir, define.V2s2ManifestDir: case define.OCIManifestDir, define.V2s2ManifestDir:
tmpdir, err := ioutil.TempDir("", "save") tmpdir, err := ioutil.TempDir("", "save")
if err != nil { if err != nil {
utils.Error(w, "unable to create tmpdir", http.StatusInternalServerError, errors.Wrap(err, "unable to create tempdir")) utils.Error(w, "unable to create tmpdir", http.StatusInternalServerError, errors.Wrap(err, "unable to create tmpdir"))
return return
} }
output = tmpdir output = tmpdir

View File

@ -4,31 +4,23 @@ import (
"context" "context"
"errors" "errors"
"net/http" "net/http"
"net/url"
"strconv"
"github.com/containers/podman/v2/pkg/bindings" "github.com/containers/podman/v2/pkg/bindings"
"github.com/containers/podman/v2/pkg/domain/entities" "github.com/containers/podman/v2/pkg/domain/entities"
) )
func Systemd(ctx context.Context, nameOrID string, options entities.GenerateSystemdOptions) (*entities.GenerateSystemdReport, error) { func Systemd(ctx context.Context, nameOrID string, options *SystemdOptions) (*entities.GenerateSystemdReport, error) {
if options == nil {
options = new(SystemdOptions)
}
conn, err := bindings.GetClient(ctx) conn, err := bindings.GetClient(ctx)
if err != nil { if err != nil {
return nil, err return nil, err
} }
params := url.Values{} params, err := options.ToParams()
if err != nil {
params.Set("useName", strconv.FormatBool(options.Name)) return nil, err
params.Set("new", strconv.FormatBool(options.New))
if options.RestartPolicy != "" {
params.Set("restartPolicy", options.RestartPolicy)
} }
if options.StopTimeout != nil {
params.Set("stopTimeout", strconv.FormatUint(uint64(*options.StopTimeout), 10))
}
params.Set("containerPrefix", options.ContainerPrefix)
params.Set("podPrefix", options.PodPrefix)
params.Set("separator", options.Separator)
response, err := conn.DoRequest(nil, http.MethodGet, "/generate/%s/systemd", params, nil, nameOrID) response, err := conn.DoRequest(nil, http.MethodGet, "/generate/%s/systemd", params, nil, nameOrID)
if err != nil { if err != nil {
@ -38,7 +30,10 @@ func Systemd(ctx context.Context, nameOrID string, options entities.GenerateSyst
return report, response.Process(&report.Units) return report, response.Process(&report.Units)
} }
func Kube(ctx context.Context, nameOrIDs []string, options entities.GenerateKubeOptions) (*entities.GenerateKubeReport, error) { func Kube(ctx context.Context, nameOrIDs []string, options *KubeOptions) (*entities.GenerateKubeReport, error) {
if options == nil {
options = new(KubeOptions)
}
conn, err := bindings.GetClient(ctx) conn, err := bindings.GetClient(ctx)
if err != nil { if err != nil {
return nil, err return nil, err
@ -46,12 +41,14 @@ func Kube(ctx context.Context, nameOrIDs []string, options entities.GenerateKube
if len(nameOrIDs) < 1 { if len(nameOrIDs) < 1 {
return nil, errors.New("must provide the name or ID of one container or pod") return nil, errors.New("must provide the name or ID of one container or pod")
} }
params := url.Values{}
params, err := options.ToParams()
if err != nil {
return nil, err
}
for _, name := range nameOrIDs { for _, name := range nameOrIDs {
params.Add("names", name) params.Add("names", name)
} }
params.Set("service", strconv.FormatBool(options.Service))
response, err := conn.DoRequest(nil, http.MethodGet, "/generate/kube", params, nil) response, err := conn.DoRequest(nil, http.MethodGet, "/generate/kube", params, nil)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -0,0 +1,27 @@
package generate
//go:generate go run ../generator/generator.go KubeOptions
// KubeOptions are optional options for generating kube YAML files
type KubeOptions struct {
// Service - generate YAML for a Kubernetes _service_ object.
Service *bool
}
//go:generate go run ../generator/generator.go SystemdOptions
// SystemdOptions are optional options for generating ssytemd files
type SystemdOptions struct {
// Name - use container/pod name instead of its ID.
UseName *bool
// New - create a new container instead of starting a new one.
New *bool
// RestartPolicy - systemd restart policy.
RestartPolicy *string
// StopTimeout - time when stopping the container.
StopTimeout *uint
// ContainerPrefix - systemd unit name prefix for containers
ContainerPrefix *string
// PodPrefix - systemd unit name prefix for pods
PodPrefix *string
// Separator - systemd unit name separator between name/id and prefix
Separator *string
}

View File

@ -0,0 +1,104 @@
package generate
import (
"net/url"
"reflect"
"strconv"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
/*
This file is generated automatically by go generate. Do not edit.
Created 2020-12-17 09:35:23.528143172 -0600 CST m=+0.000203394
*/
// Changed
func (o *KubeOptions) Changed(fieldName string) bool {
r := reflect.ValueOf(o)
value := reflect.Indirect(r).FieldByName(fieldName)
return !value.IsNil()
}
// ToParams
func (o *KubeOptions) 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
}
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()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
switch typ.Kind() {
case reflect.String:
s, ok := slice.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
}
// WithService
func (o *KubeOptions) WithService(value bool) *KubeOptions {
v := &value
o.Service = v
return o
}
// GetService
func (o *KubeOptions) GetService() bool {
var service bool
if o.Service == nil {
return service
}
return *o.Service
}

View File

@ -0,0 +1,200 @@
package generate
import (
"net/url"
"reflect"
"strconv"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
/*
This file is generated automatically by go generate. Do not edit.
Created 2020-12-17 09:35:23.663318384 -0600 CST m=+0.000158454
*/
// Changed
func (o *SystemdOptions) Changed(fieldName string) bool {
r := reflect.ValueOf(o)
value := reflect.Indirect(r).FieldByName(fieldName)
return !value.IsNil()
}
// ToParams
func (o *SystemdOptions) 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
}
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()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
switch typ.Kind() {
case reflect.String:
s, ok := slice.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
}
// WithUseName
func (o *SystemdOptions) WithUseName(value bool) *SystemdOptions {
v := &value
o.UseName = v
return o
}
// GetUseName
func (o *SystemdOptions) GetUseName() bool {
var useName bool
if o.UseName == nil {
return useName
}
return *o.UseName
}
// WithNew
func (o *SystemdOptions) WithNew(value bool) *SystemdOptions {
v := &value
o.New = v
return o
}
// GetNew
func (o *SystemdOptions) GetNew() bool {
var new bool
if o.New == nil {
return new
}
return *o.New
}
// WithRestartPolicy
func (o *SystemdOptions) WithRestartPolicy(value string) *SystemdOptions {
v := &value
o.RestartPolicy = v
return o
}
// GetRestartPolicy
func (o *SystemdOptions) GetRestartPolicy() string {
var restartPolicy string
if o.RestartPolicy == nil {
return restartPolicy
}
return *o.RestartPolicy
}
// WithStopTimeout
func (o *SystemdOptions) WithStopTimeout(value uint) *SystemdOptions {
v := &value
o.StopTimeout = v
return o
}
// GetStopTimeout
func (o *SystemdOptions) GetStopTimeout() uint {
var stopTimeout uint
if o.StopTimeout == nil {
return stopTimeout
}
return *o.StopTimeout
}
// WithContainerPrefix
func (o *SystemdOptions) WithContainerPrefix(value string) *SystemdOptions {
v := &value
o.ContainerPrefix = v
return o
}
// GetContainerPrefix
func (o *SystemdOptions) GetContainerPrefix() string {
var containerPrefix string
if o.ContainerPrefix == nil {
return containerPrefix
}
return *o.ContainerPrefix
}
// WithPodPrefix
func (o *SystemdOptions) WithPodPrefix(value string) *SystemdOptions {
v := &value
o.PodPrefix = v
return o
}
// GetPodPrefix
func (o *SystemdOptions) GetPodPrefix() string {
var podPrefix string
if o.PodPrefix == nil {
return podPrefix
}
return *o.PodPrefix
}
// WithSeparator
func (o *SystemdOptions) WithSeparator(value string) *SystemdOptions {
v := &value
o.Separator = v
return o
}
// GetSeparator
func (o *SystemdOptions) GetSeparator() string {
var separator string
if o.Separator == nil {
return separator
}
return *o.Separator
}

View File

@ -64,6 +64,9 @@ func (o *{{.StructName}}) ToParams() (url.Values, error) {
case reflect.Int, reflect.Int64: case reflect.Int, reflect.Int64:
// f.Int() is always an int64 // f.Int() is always an int64
params.Set(fieldName, strconv.FormatInt(f.Int(), 10)) 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: case reflect.Slice:
typ := reflect.TypeOf(f.Interface()).Elem() typ := reflect.TypeOf(f.Interface()).Elem()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap()) slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
@ -92,8 +95,6 @@ func (o *{{.StructName}}) ToParams() (url.Values, error) {
} }
params.Set(fieldName, s) params.Set(fieldName, s)
default:
return nil, errors.Errorf("unknown type %s", f.Kind().String())
} }
} }
return params, nil return params, nil

View File

@ -79,7 +79,7 @@ type TagOptions struct {
} }
//go:generate go run ../generator/generator.go UntagOptions //go:generate go run ../generator/generator.go UntagOptions
// UntagOptions are optional options for tagging images // UntagOptions are optional options for untagging images
type UntagOptions struct { type UntagOptions struct {
} }

View File

@ -12,7 +12,7 @@ import (
/* /*
This file is generated automatically by go generate. Do not edit. This file is generated automatically by go generate. Do not edit.
Created 2020-12-15 15:22:46.528172042 -0600 CST m=+0.000279712 Created 2020-12-16 11:47:07.253097326 -0600 CST m=+0.000283385
*/ */
// Changed // Changed
@ -51,6 +51,9 @@ func (o *DiffOptions) ToParams() (url.Values, error) {
case reflect.Int, reflect.Int64: case reflect.Int, reflect.Int64:
// f.Int() is always an int64 // f.Int() is always an int64
params.Set(fieldName, strconv.FormatInt(f.Int(), 10)) 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: case reflect.Slice:
typ := reflect.TypeOf(f.Interface()).Elem() typ := reflect.TypeOf(f.Interface()).Elem()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap()) slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
@ -79,8 +82,6 @@ func (o *DiffOptions) ToParams() (url.Values, error) {
} }
params.Set(fieldName, s) params.Set(fieldName, s)
default:
return nil, errors.Errorf("unknown type %s", f.Kind().String())
} }
} }
return params, nil return params, nil

View File

@ -12,7 +12,7 @@ import (
/* /*
This file is generated automatically by go generate. Do not edit. This file is generated automatically by go generate. Do not edit.
Created 2020-12-15 15:22:47.379804635 -0600 CST m=+0.000257609 Created 2020-12-16 11:47:08.103165436 -0600 CST m=+0.000245546
*/ */
// Changed // Changed
@ -51,6 +51,9 @@ func (o *ExportOptions) ToParams() (url.Values, error) {
case reflect.Int, reflect.Int64: case reflect.Int, reflect.Int64:
// f.Int() is always an int64 // f.Int() is always an int64
params.Set(fieldName, strconv.FormatInt(f.Int(), 10)) 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: case reflect.Slice:
typ := reflect.TypeOf(f.Interface()).Elem() typ := reflect.TypeOf(f.Interface()).Elem()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap()) slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
@ -79,8 +82,6 @@ func (o *ExportOptions) ToParams() (url.Values, error) {
} }
params.Set(fieldName, s) params.Set(fieldName, s)
default:
return nil, errors.Errorf("unknown type %s", f.Kind().String())
} }
} }
return params, nil return params, nil

View File

@ -12,7 +12,7 @@ import (
/* /*
This file is generated automatically by go generate. Do not edit. This file is generated automatically by go generate. Do not edit.
Created 2020-12-15 15:22:46.81312808 -0600 CST m=+0.000257734 Created 2020-12-16 11:47:07.536472335 -0600 CST m=+0.000251379
*/ */
// Changed // Changed
@ -51,6 +51,9 @@ func (o *GetOptions) ToParams() (url.Values, error) {
case reflect.Int, reflect.Int64: case reflect.Int, reflect.Int64:
// f.Int() is always an int64 // f.Int() is always an int64
params.Set(fieldName, strconv.FormatInt(f.Int(), 10)) 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: case reflect.Slice:
typ := reflect.TypeOf(f.Interface()).Elem() typ := reflect.TypeOf(f.Interface()).Elem()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap()) slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
@ -79,8 +82,6 @@ func (o *GetOptions) ToParams() (url.Values, error) {
} }
params.Set(fieldName, s) params.Set(fieldName, s)
default:
return nil, errors.Errorf("unknown type %s", f.Kind().String())
} }
} }
return params, nil return params, nil

View File

@ -12,7 +12,7 @@ import (
/* /*
This file is generated automatically by go generate. Do not edit. This file is generated automatically by go generate. Do not edit.
Created 2020-12-15 15:22:47.095693605 -0600 CST m=+0.000243849 Created 2020-12-16 11:47:07.818738329 -0600 CST m=+0.000253937
*/ */
// Changed // Changed
@ -51,6 +51,9 @@ func (o *HistoryOptions) ToParams() (url.Values, error) {
case reflect.Int, reflect.Int64: case reflect.Int, reflect.Int64:
// f.Int() is always an int64 // f.Int() is always an int64
params.Set(fieldName, strconv.FormatInt(f.Int(), 10)) 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: case reflect.Slice:
typ := reflect.TypeOf(f.Interface()).Elem() typ := reflect.TypeOf(f.Interface()).Elem()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap()) slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
@ -79,8 +82,6 @@ func (o *HistoryOptions) ToParams() (url.Values, error) {
} }
params.Set(fieldName, s) params.Set(fieldName, s)
default:
return nil, errors.Errorf("unknown type %s", f.Kind().String())
} }
} }
return params, nil return params, nil

View File

@ -12,7 +12,7 @@ import (
/* /*
This file is generated automatically by go generate. Do not edit. This file is generated automatically by go generate. Do not edit.
Created 2020-12-15 15:22:47.943587389 -0600 CST m=+0.000238222 Created 2020-12-16 11:47:08.67072755 -0600 CST m=+0.000238081
*/ */
// Changed // Changed
@ -51,6 +51,9 @@ func (o *ImportOptions) ToParams() (url.Values, error) {
case reflect.Int, reflect.Int64: case reflect.Int, reflect.Int64:
// f.Int() is always an int64 // f.Int() is always an int64
params.Set(fieldName, strconv.FormatInt(f.Int(), 10)) 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: case reflect.Slice:
typ := reflect.TypeOf(f.Interface()).Elem() typ := reflect.TypeOf(f.Interface()).Elem()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap()) slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
@ -79,8 +82,6 @@ func (o *ImportOptions) ToParams() (url.Values, error) {
} }
params.Set(fieldName, s) params.Set(fieldName, s)
default:
return nil, errors.Errorf("unknown type %s", f.Kind().String())
} }
} }
return params, nil return params, nil

View File

@ -12,7 +12,7 @@ import (
/* /*
This file is generated automatically by go generate. Do not edit. This file is generated automatically by go generate. Do not edit.
Created 2020-12-15 15:22:46.671238196 -0600 CST m=+0.000266757 Created 2020-12-16 11:47:07.39332655 -0600 CST m=+0.000275349
*/ */
// Changed // Changed
@ -51,6 +51,9 @@ func (o *ListOptions) ToParams() (url.Values, error) {
case reflect.Int, reflect.Int64: case reflect.Int, reflect.Int64:
// f.Int() is always an int64 // f.Int() is always an int64
params.Set(fieldName, strconv.FormatInt(f.Int(), 10)) 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: case reflect.Slice:
typ := reflect.TypeOf(f.Interface()).Elem() typ := reflect.TypeOf(f.Interface()).Elem()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap()) slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
@ -79,8 +82,6 @@ func (o *ListOptions) ToParams() (url.Values, error) {
} }
params.Set(fieldName, s) params.Set(fieldName, s)
default:
return nil, errors.Errorf("unknown type %s", f.Kind().String())
} }
} }
return params, nil return params, nil

View File

@ -12,7 +12,7 @@ import (
/* /*
This file is generated automatically by go generate. Do not edit. This file is generated automatically by go generate. Do not edit.
Created 2020-12-15 15:22:47.237599061 -0600 CST m=+0.000247138 Created 2020-12-16 11:47:07.961817946 -0600 CST m=+0.000243444
*/ */
// Changed // Changed
@ -51,6 +51,9 @@ func (o *LoadOptions) ToParams() (url.Values, error) {
case reflect.Int, reflect.Int64: case reflect.Int, reflect.Int64:
// f.Int() is always an int64 // f.Int() is always an int64
params.Set(fieldName, strconv.FormatInt(f.Int(), 10)) 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: case reflect.Slice:
typ := reflect.TypeOf(f.Interface()).Elem() typ := reflect.TypeOf(f.Interface()).Elem()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap()) slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
@ -79,8 +82,6 @@ func (o *LoadOptions) ToParams() (url.Values, error) {
} }
params.Set(fieldName, s) params.Set(fieldName, s)
default:
return nil, errors.Errorf("unknown type %s", f.Kind().String())
} }
} }
return params, nil return params, nil

View File

@ -12,7 +12,7 @@ import (
/* /*
This file is generated automatically by go generate. Do not edit. This file is generated automatically by go generate. Do not edit.
Created 2020-12-15 15:22:47.521471344 -0600 CST m=+0.000250491 Created 2020-12-16 11:47:08.24781882 -0600 CST m=+0.000244039
*/ */
// Changed // Changed
@ -51,6 +51,9 @@ func (o *PruneOptions) ToParams() (url.Values, error) {
case reflect.Int, reflect.Int64: case reflect.Int, reflect.Int64:
// f.Int() is always an int64 // f.Int() is always an int64
params.Set(fieldName, strconv.FormatInt(f.Int(), 10)) 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: case reflect.Slice:
typ := reflect.TypeOf(f.Interface()).Elem() typ := reflect.TypeOf(f.Interface()).Elem()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap()) slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
@ -79,8 +82,6 @@ func (o *PruneOptions) ToParams() (url.Values, error) {
} }
params.Set(fieldName, s) params.Set(fieldName, s)
default:
return nil, errors.Errorf("unknown type %s", f.Kind().String())
} }
} }
return params, nil return params, nil

View File

@ -13,7 +13,7 @@ import (
/* /*
This file is generated automatically by go generate. Do not edit. This file is generated automatically by go generate. Do not edit.
Created 2020-12-15 15:22:48.373345229 -0600 CST m=+0.000247562 Created 2020-12-16 11:47:09.104988433 -0600 CST m=+0.000274515
*/ */
// Changed // Changed
@ -52,6 +52,9 @@ func (o *PullOptions) ToParams() (url.Values, error) {
case reflect.Int, reflect.Int64: case reflect.Int, reflect.Int64:
// f.Int() is always an int64 // f.Int() is always an int64
params.Set(fieldName, strconv.FormatInt(f.Int(), 10)) 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: case reflect.Slice:
typ := reflect.TypeOf(f.Interface()).Elem() typ := reflect.TypeOf(f.Interface()).Elem()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap()) slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
@ -80,8 +83,6 @@ func (o *PullOptions) ToParams() (url.Values, error) {
} }
params.Set(fieldName, s) params.Set(fieldName, s)
default:
return nil, errors.Errorf("unknown type %s", f.Kind().String())
} }
} }
return params, nil return params, nil

View File

@ -12,7 +12,7 @@ import (
/* /*
This file is generated automatically by go generate. Do not edit. This file is generated automatically by go generate. Do not edit.
Created 2020-12-15 15:22:48.08540302 -0600 CST m=+0.000302026 Created 2020-12-16 11:47:08.817442617 -0600 CST m=+0.000259111
*/ */
// Changed // Changed
@ -51,6 +51,9 @@ func (o *PushOptions) ToParams() (url.Values, error) {
case reflect.Int, reflect.Int64: case reflect.Int, reflect.Int64:
// f.Int() is always an int64 // f.Int() is always an int64
params.Set(fieldName, strconv.FormatInt(f.Int(), 10)) 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: case reflect.Slice:
typ := reflect.TypeOf(f.Interface()).Elem() typ := reflect.TypeOf(f.Interface()).Elem()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap()) slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
@ -79,8 +82,6 @@ func (o *PushOptions) ToParams() (url.Values, error) {
} }
params.Set(fieldName, s) params.Set(fieldName, s)
default:
return nil, errors.Errorf("unknown type %s", f.Kind().String())
} }
} }
return params, nil return params, nil

View File

@ -12,7 +12,7 @@ import (
/* /*
This file is generated automatically by go generate. Do not edit. This file is generated automatically by go generate. Do not edit.
Created 2020-12-15 15:22:46.378166859 -0600 CST m=+0.000249384 Created 2020-12-16 11:47:07.115421951 -0600 CST m=+0.000310512
*/ */
// Changed // Changed
@ -51,6 +51,9 @@ func (o *RemoveOptions) ToParams() (url.Values, error) {
case reflect.Int, reflect.Int64: case reflect.Int, reflect.Int64:
// f.Int() is always an int64 // f.Int() is always an int64
params.Set(fieldName, strconv.FormatInt(f.Int(), 10)) 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: case reflect.Slice:
typ := reflect.TypeOf(f.Interface()).Elem() typ := reflect.TypeOf(f.Interface()).Elem()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap()) slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
@ -79,8 +82,6 @@ func (o *RemoveOptions) ToParams() (url.Values, error) {
} }
params.Set(fieldName, s) params.Set(fieldName, s)
default:
return nil, errors.Errorf("unknown type %s", f.Kind().String())
} }
} }
return params, nil return params, nil

View File

@ -12,7 +12,7 @@ import (
/* /*
This file is generated automatically by go generate. Do not edit. This file is generated automatically by go generate. Do not edit.
Created 2020-12-15 15:22:48.229349981 -0600 CST m=+0.000244343 Created 2020-12-16 11:47:08.958897824 -0600 CST m=+0.000238136
*/ */
// Changed // Changed
@ -51,6 +51,9 @@ func (o *SearchOptions) ToParams() (url.Values, error) {
case reflect.Int, reflect.Int64: case reflect.Int, reflect.Int64:
// f.Int() is always an int64 // f.Int() is always an int64
params.Set(fieldName, strconv.FormatInt(f.Int(), 10)) 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: case reflect.Slice:
typ := reflect.TypeOf(f.Interface()).Elem() typ := reflect.TypeOf(f.Interface()).Elem()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap()) slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
@ -79,8 +82,6 @@ func (o *SearchOptions) ToParams() (url.Values, error) {
} }
params.Set(fieldName, s) params.Set(fieldName, s)
default:
return nil, errors.Errorf("unknown type %s", f.Kind().String())
} }
} }
return params, nil return params, nil

View File

@ -12,7 +12,7 @@ import (
/* /*
This file is generated automatically by go generate. Do not edit. This file is generated automatically by go generate. Do not edit.
Created 2020-12-15 15:22:47.66229668 -0600 CST m=+0.000246630 Created 2020-12-16 11:47:08.388404224 -0600 CST m=+0.000253809
*/ */
// Changed // Changed
@ -51,6 +51,9 @@ func (o *TagOptions) ToParams() (url.Values, error) {
case reflect.Int, reflect.Int64: case reflect.Int, reflect.Int64:
// f.Int() is always an int64 // f.Int() is always an int64
params.Set(fieldName, strconv.FormatInt(f.Int(), 10)) 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: case reflect.Slice:
typ := reflect.TypeOf(f.Interface()).Elem() typ := reflect.TypeOf(f.Interface()).Elem()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap()) slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
@ -79,8 +82,6 @@ func (o *TagOptions) ToParams() (url.Values, error) {
} }
params.Set(fieldName, s) params.Set(fieldName, s)
default:
return nil, errors.Errorf("unknown type %s", f.Kind().String())
} }
} }
return params, nil return params, nil

View File

@ -12,7 +12,7 @@ import (
/* /*
This file is generated automatically by go generate. Do not edit. This file is generated automatically by go generate. Do not edit.
Created 2020-12-15 15:22:46.954579136 -0600 CST m=+0.000248704 Created 2020-12-16 11:47:07.676177228 -0600 CST m=+0.000254279
*/ */
// Changed // Changed
@ -51,6 +51,9 @@ func (o *TreeOptions) ToParams() (url.Values, error) {
case reflect.Int, reflect.Int64: case reflect.Int, reflect.Int64:
// f.Int() is always an int64 // f.Int() is always an int64
params.Set(fieldName, strconv.FormatInt(f.Int(), 10)) 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: case reflect.Slice:
typ := reflect.TypeOf(f.Interface()).Elem() typ := reflect.TypeOf(f.Interface()).Elem()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap()) slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
@ -79,8 +82,6 @@ func (o *TreeOptions) ToParams() (url.Values, error) {
} }
params.Set(fieldName, s) params.Set(fieldName, s)
default:
return nil, errors.Errorf("unknown type %s", f.Kind().String())
} }
} }
return params, nil return params, nil

View File

@ -12,7 +12,7 @@ import (
/* /*
This file is generated automatically by go generate. Do not edit. This file is generated automatically by go generate. Do not edit.
Created 2020-12-15 15:22:47.802372989 -0600 CST m=+0.000239766 Created 2020-12-16 11:47:08.530676487 -0600 CST m=+0.000238259
*/ */
// Changed // Changed
@ -51,6 +51,9 @@ func (o *UntagOptions) ToParams() (url.Values, error) {
case reflect.Int, reflect.Int64: case reflect.Int, reflect.Int64:
// f.Int() is always an int64 // f.Int() is always an int64
params.Set(fieldName, strconv.FormatInt(f.Int(), 10)) 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: case reflect.Slice:
typ := reflect.TypeOf(f.Interface()).Elem() typ := reflect.TypeOf(f.Interface()).Elem()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap()) slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
@ -79,8 +82,6 @@ func (o *UntagOptions) ToParams() (url.Values, error) {
} }
params.Set(fieldName, s) params.Set(fieldName, s)
default:
return nil, errors.Errorf("unknown type %s", f.Kind().String())
} }
} }
return params, nil return params, nil

View File

@ -5,11 +5,9 @@ import (
"errors" "errors"
"net/http" "net/http"
"net/url" "net/url"
"strconv"
"strings" "strings"
"github.com/containers/image/v5/manifest" "github.com/containers/image/v5/manifest"
"github.com/containers/podman/v2/libpod/image"
"github.com/containers/podman/v2/pkg/api/handlers" "github.com/containers/podman/v2/pkg/api/handlers"
"github.com/containers/podman/v2/pkg/bindings" "github.com/containers/podman/v2/pkg/bindings"
jsoniter "github.com/json-iterator/go" jsoniter "github.com/json-iterator/go"
@ -19,8 +17,11 @@ import (
// the new manifest can also be specified. The all boolean specifies to add all entries // the new manifest can also be specified. The all boolean specifies to add all entries
// of a list if the name provided is a manifest list. The ID of the new manifest list // of a list if the name provided is a manifest list. The ID of the new manifest list
// is returned as a string. // is returned as a string.
func Create(ctx context.Context, names, images []string, all *bool) (string, error) { func Create(ctx context.Context, names, images []string, options *CreateOptions) (string, error) {
var idr handlers.IDResponse var idr handlers.IDResponse
if options == nil {
options = new(CreateOptions)
}
conn, err := bindings.GetClient(ctx) conn, err := bindings.GetClient(ctx)
if err != nil { if err != nil {
return "", err return "", err
@ -28,9 +29,9 @@ func Create(ctx context.Context, names, images []string, all *bool) (string, err
if len(names) < 1 { if len(names) < 1 {
return "", errors.New("creating a manifest requires at least one name argument") return "", errors.New("creating a manifest requires at least one name argument")
} }
params := url.Values{} params, err := options.ToParams()
if all != nil { if err != nil {
params.Set("all", strconv.FormatBool(*all)) return "", err
} }
for _, name := range names { for _, name := range names {
params.Add("name", name) params.Add("name", name)
@ -47,8 +48,12 @@ func Create(ctx context.Context, names, images []string, all *bool) (string, err
} }
// Inspect returns a manifest list for a given name. // Inspect returns a manifest list for a given name.
func Inspect(ctx context.Context, name string) (*manifest.Schema2List, error) { func Inspect(ctx context.Context, name string, options *InspectOptions) (*manifest.Schema2List, error) {
var list manifest.Schema2List var list manifest.Schema2List
if options == nil {
options = new(InspectOptions)
}
_ = options
conn, err := bindings.GetClient(ctx) conn, err := bindings.GetClient(ctx)
if err != nil { if err != nil {
return nil, err return nil, err
@ -62,8 +67,11 @@ func Inspect(ctx context.Context, name string) (*manifest.Schema2List, error) {
// Add adds a manifest to a given manifest list. Additional options for the manifest // Add adds a manifest to a given manifest list. Additional options for the manifest
// can also be specified. The ID of the new manifest list is returned as a string // can also be specified. The ID of the new manifest list is returned as a string
func Add(ctx context.Context, name string, options image.ManifestAddOpts) (string, error) { func Add(ctx context.Context, name string, options *AddOptions) (string, error) {
var idr handlers.IDResponse var idr handlers.IDResponse
if options == nil {
options = new(AddOptions)
}
conn, err := bindings.GetClient(ctx) conn, err := bindings.GetClient(ctx)
if err != nil { if err != nil {
return "", err return "", err
@ -82,8 +90,12 @@ func Add(ctx context.Context, name string, options image.ManifestAddOpts) (strin
// Remove deletes a manifest entry from a manifest list. Both name and the digest to be // Remove deletes a manifest entry from a manifest list. Both name and the digest to be
// removed are mandatory inputs. The ID of the new manifest list is returned as a string. // removed are mandatory inputs. The ID of the new manifest list is returned as a string.
func Remove(ctx context.Context, name, digest string) (string, error) { func Remove(ctx context.Context, name, digest string, options *RemoveOptions) (string, error) {
var idr handlers.IDResponse var idr handlers.IDResponse
if options == nil {
options = new(RemoveOptions)
}
_ = options
conn, err := bindings.GetClient(ctx) conn, err := bindings.GetClient(ctx)
if err != nil { if err != nil {
return "", err return "", err
@ -100,24 +112,26 @@ func Remove(ctx context.Context, name, digest string) (string, error) {
// Push takes a manifest list and pushes to a destination. If the destination is not specified, // Push takes a manifest list and pushes to a destination. If the destination is not specified,
// the name will be used instead. If the optional all boolean is specified, all images specified // the name will be used instead. If the optional all boolean is specified, all images specified
// in the list will be pushed as well. // in the list will be pushed as well.
func Push(ctx context.Context, name string, destination *string, all *bool) (string, error) { func Push(ctx context.Context, name, destination string, options *PushOptions) (string, error) {
var ( var (
idr handlers.IDResponse idr handlers.IDResponse
) )
dest := name if options == nil {
options = new(PushOptions)
}
if len(destination) < 1 {
destination = name
}
conn, err := bindings.GetClient(ctx) conn, err := bindings.GetClient(ctx)
if err != nil { if err != nil {
return "", err return "", err
} }
params := url.Values{} params, err := options.ToParams()
if err != nil {
return "", err
}
params.Set("image", name) params.Set("image", name)
if destination != nil { params.Set("destination", destination)
dest = *destination
}
params.Set("destination", dest)
if all != nil {
params.Set("all", strconv.FormatBool(*all))
}
_, err = conn.DoRequest(nil, http.MethodPost, "/manifests/%s/push", params, nil, name) _, err = conn.DoRequest(nil, http.MethodPost, "/manifests/%s/push", params, nil, name)
if err != nil { if err != nil {
return "", err return "", err

View File

@ -0,0 +1,36 @@
package manifests
//go:generate go run ../generator/generator.go InspectOptions
// InspectOptions are optional options for inspecting manifests
type InspectOptions struct {
}
//go:generate go run ../generator/generator.go CreateOptions
// CreateOptions are optional options for creating manifests
type CreateOptions struct {
All *bool
}
//go:generate go run ../generator/generator.go AddOptions
// AddOptions are optional options for adding manifests
type AddOptions struct {
All *bool
Annotation map[string]string
Arch *string
Features []string
Images []string
OS *string
OSVersion *string
Variant *string
}
//go:generate go run ../generator/generator.go RemoveOptions
// RemoveOptions are optional options for removing manifests
type RemoveOptions struct {
}
//go:generate go run ../generator/generator.go PushOptions
// RemoveOptions are optional options for pushing manifests
type PushOptions struct {
All *bool
}

View File

@ -0,0 +1,216 @@
package manifests
import (
"net/url"
"reflect"
"strconv"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
/*
This file is generated automatically by go generate. Do not edit.
Created 2020-12-16 11:58:59.192715649 -0600 CST m=+0.000150326
*/
// Changed
func (o *AddOptions) Changed(fieldName string) bool {
r := reflect.ValueOf(o)
value := reflect.Indirect(r).FieldByName(fieldName)
return !value.IsNil()
}
// ToParams
func (o *AddOptions) 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
}
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()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
switch typ.Kind() {
case reflect.String:
s, ok := slice.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
}
// WithAll
func (o *AddOptions) WithAll(value bool) *AddOptions {
v := &value
o.All = v
return o
}
// GetAll
func (o *AddOptions) GetAll() bool {
var all bool
if o.All == nil {
return all
}
return *o.All
}
// WithAnnotation
func (o *AddOptions) WithAnnotation(value map[string]string) *AddOptions {
v := value
o.Annotation = v
return o
}
// GetAnnotation
func (o *AddOptions) GetAnnotation() map[string]string {
var annotation map[string]string
if o.Annotation == nil {
return annotation
}
return o.Annotation
}
// WithArch
func (o *AddOptions) WithArch(value string) *AddOptions {
v := &value
o.Arch = v
return o
}
// GetArch
func (o *AddOptions) GetArch() string {
var arch string
if o.Arch == nil {
return arch
}
return *o.Arch
}
// WithFeatures
func (o *AddOptions) WithFeatures(value []string) *AddOptions {
v := value
o.Features = v
return o
}
// GetFeatures
func (o *AddOptions) GetFeatures() []string {
var features []string
if o.Features == nil {
return features
}
return o.Features
}
// WithImages
func (o *AddOptions) WithImages(value []string) *AddOptions {
v := value
o.Images = v
return o
}
// GetImages
func (o *AddOptions) GetImages() []string {
var images []string
if o.Images == nil {
return images
}
return o.Images
}
// WithOS
func (o *AddOptions) WithOS(value string) *AddOptions {
v := &value
o.OS = v
return o
}
// GetOS
func (o *AddOptions) GetOS() string {
var oS string
if o.OS == nil {
return oS
}
return *o.OS
}
// WithOSVersion
func (o *AddOptions) WithOSVersion(value string) *AddOptions {
v := &value
o.OSVersion = v
return o
}
// GetOSVersion
func (o *AddOptions) GetOSVersion() string {
var oSVersion string
if o.OSVersion == nil {
return oSVersion
}
return *o.OSVersion
}
// WithVariant
func (o *AddOptions) WithVariant(value string) *AddOptions {
v := &value
o.Variant = v
return o
}
// GetVariant
func (o *AddOptions) GetVariant() string {
var variant string
if o.Variant == nil {
return variant
}
return *o.Variant
}

View File

@ -0,0 +1,104 @@
package manifests
import (
"net/url"
"reflect"
"strconv"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
/*
This file is generated automatically by go generate. Do not edit.
Created 2020-12-16 11:58:59.053719568 -0600 CST m=+0.000144061
*/
// Changed
func (o *CreateOptions) Changed(fieldName string) bool {
r := reflect.ValueOf(o)
value := reflect.Indirect(r).FieldByName(fieldName)
return !value.IsNil()
}
// ToParams
func (o *CreateOptions) 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
}
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()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
switch typ.Kind() {
case reflect.String:
s, ok := slice.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
}
// WithAll
func (o *CreateOptions) WithAll(value bool) *CreateOptions {
v := &value
o.All = v
return o
}
// GetAll
func (o *CreateOptions) GetAll() bool {
var all bool
if o.All == nil {
return all
}
return *o.All
}

View File

@ -0,0 +1,88 @@
package manifests
import (
"net/url"
"reflect"
"strconv"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
/*
This file is generated automatically by go generate. Do not edit.
Created 2020-12-16 11:58:58.908440858 -0600 CST m=+0.000142730
*/
// Changed
func (o *InspectOptions) Changed(fieldName string) bool {
r := reflect.ValueOf(o)
value := reflect.Indirect(r).FieldByName(fieldName)
return !value.IsNil()
}
// ToParams
func (o *InspectOptions) 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
}
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()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
switch typ.Kind() {
case reflect.String:
s, ok := slice.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
}

View File

@ -0,0 +1,104 @@
package manifests
import (
"net/url"
"reflect"
"strconv"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
/*
This file is generated automatically by go generate. Do not edit.
Created 2020-12-16 11:58:59.466796313 -0600 CST m=+0.000143189
*/
// Changed
func (o *PushOptions) Changed(fieldName string) bool {
r := reflect.ValueOf(o)
value := reflect.Indirect(r).FieldByName(fieldName)
return !value.IsNil()
}
// ToParams
func (o *PushOptions) 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
}
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()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
switch typ.Kind() {
case reflect.String:
s, ok := slice.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
}
// WithAll
func (o *PushOptions) WithAll(value bool) *PushOptions {
v := &value
o.All = v
return o
}
// GetAll
func (o *PushOptions) GetAll() bool {
var all bool
if o.All == nil {
return all
}
return *o.All
}

View File

@ -0,0 +1,88 @@
package manifests
import (
"net/url"
"reflect"
"strconv"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
/*
This file is generated automatically by go generate. Do not edit.
Created 2020-12-16 11:58:59.33119706 -0600 CST m=+0.000143915
*/
// Changed
func (o *RemoveOptions) Changed(fieldName string) bool {
r := reflect.ValueOf(o)
value := reflect.Indirect(r).FieldByName(fieldName)
return !value.IsNil()
}
// ToParams
func (o *RemoveOptions) 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
}
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()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
switch typ.Kind() {
case reflect.String:
s, ok := slice.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
}

View File

@ -2,10 +2,8 @@ package network
import ( import (
"context" "context"
"encoding/json"
"net/http" "net/http"
"net/url" "net/url"
"strconv"
"strings" "strings"
"github.com/containers/podman/v2/pkg/bindings" "github.com/containers/podman/v2/pkg/bindings"
@ -14,15 +12,18 @@ import (
) )
// Create makes a new CNI network configuration // Create makes a new CNI network configuration
func Create(ctx context.Context, options entities.NetworkCreateOptions, name *string) (*entities.NetworkCreateReport, error) { func Create(ctx context.Context, options *CreateOptions) (*entities.NetworkCreateReport, error) {
var report entities.NetworkCreateReport var report entities.NetworkCreateReport
if options == nil {
options = new(CreateOptions)
}
conn, err := bindings.GetClient(ctx) conn, err := bindings.GetClient(ctx)
if err != nil { if err != nil {
return nil, err return nil, err
} }
params := url.Values{} params := url.Values{}
if name != nil { if options.Name != nil {
params.Set("name", *name) params.Set("name", options.GetName())
} }
networkConfig, err := jsoniter.MarshalToString(options) networkConfig, err := jsoniter.MarshalToString(options)
if err != nil { if err != nil {
@ -37,8 +38,12 @@ func Create(ctx context.Context, options entities.NetworkCreateOptions, name *st
} }
// Inspect returns low level information about a CNI network configuration // Inspect returns low level information about a CNI network configuration
func Inspect(ctx context.Context, nameOrID string) ([]entities.NetworkInspectReport, error) { func Inspect(ctx context.Context, nameOrID string, options *InspectOptions) ([]entities.NetworkInspectReport, error) {
var reports []entities.NetworkInspectReport var reports []entities.NetworkInspectReport
if options == nil {
options = new(InspectOptions)
}
_ = options
conn, err := bindings.GetClient(ctx) conn, err := bindings.GetClient(ctx)
if err != nil { if err != nil {
return nil, err return nil, err
@ -53,15 +58,18 @@ func Inspect(ctx context.Context, nameOrID string) ([]entities.NetworkInspectRep
// Remove deletes a defined CNI network configuration by name. The optional force boolean // 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 // will remove all containers associated with the network when set to true. A slice
// of NetworkRemoveReports are returned. // of NetworkRemoveReports are returned.
func Remove(ctx context.Context, nameOrID string, force *bool) ([]*entities.NetworkRmReport, error) { func Remove(ctx context.Context, nameOrID string, options *RemoveOptions) ([]*entities.NetworkRmReport, error) {
var reports []*entities.NetworkRmReport var reports []*entities.NetworkRmReport
if options == nil {
options = new(RemoveOptions)
}
conn, err := bindings.GetClient(ctx) conn, err := bindings.GetClient(ctx)
if err != nil { if err != nil {
return nil, err return nil, err
} }
params := url.Values{} params, err := options.ToParams()
if force != nil { if err != nil {
params.Set("force", strconv.FormatBool(*force)) return nil, err
} }
response, err := conn.DoRequest(nil, http.MethodDelete, "/networks/%s", params, nil, nameOrID) response, err := conn.DoRequest(nil, http.MethodDelete, "/networks/%s", params, nil, nameOrID)
if err != nil { if err != nil {
@ -71,21 +79,20 @@ func Remove(ctx context.Context, nameOrID string, force *bool) ([]*entities.Netw
} }
// List returns a summary of all CNI network configurations // List returns a summary of all CNI network configurations
func List(ctx context.Context, options entities.NetworkListOptions) ([]*entities.NetworkListReport, error) { func List(ctx context.Context, options *ListOptions) ([]*entities.NetworkListReport, error) {
var ( var (
netList []*entities.NetworkListReport netList []*entities.NetworkListReport
) )
if options == nil {
options = new(ListOptions)
}
conn, err := bindings.GetClient(ctx) conn, err := bindings.GetClient(ctx)
if err != nil { if err != nil {
return nil, err return nil, err
} }
params := url.Values{} params, err := options.ToParams()
if options.Filters != nil { if err != nil {
b, err := json.Marshal(options.Filters) return nil, err
if err != nil {
return nil, err
}
params.Set("filters", string(b))
} }
response, err := conn.DoRequest(nil, http.MethodGet, "/networks/json", params, nil) response, err := conn.DoRequest(nil, http.MethodGet, "/networks/json", params, nil)
if err != nil { if err != nil {
@ -95,13 +102,28 @@ func List(ctx context.Context, options entities.NetworkListOptions) ([]*entities
} }
// Disconnect removes a container from a given network // Disconnect removes a container from a given network
func Disconnect(ctx context.Context, networkName string, options entities.NetworkDisconnectOptions) error { func Disconnect(ctx context.Context, networkName string, ContainerNameOrId string, options *DisconnectOptions) error {
if options == nil {
options = new(DisconnectOptions)
}
conn, err := bindings.GetClient(ctx) conn, err := bindings.GetClient(ctx)
if err != nil { if err != nil {
return err return err
} }
// No params are used for disconnect
params := url.Values{} params := url.Values{}
body, err := jsoniter.MarshalToString(options) // Disconnect sends everything in body
disconnect := struct {
Container string
Force bool
}{
Container: ContainerNameOrId,
}
if force := options.GetForce(); options.Changed("Force") {
disconnect.Force = force
}
body, err := jsoniter.MarshalToString(disconnect)
if err != nil { if err != nil {
return err return err
} }
@ -114,13 +136,27 @@ func Disconnect(ctx context.Context, networkName string, options entities.Networ
} }
// Connect adds a container to a network // Connect adds a container to a network
func Connect(ctx context.Context, networkName string, options entities.NetworkConnectOptions) error { func Connect(ctx context.Context, networkName string, ContainerNameOrId string, options *ConnectOptions) error {
if options == nil {
options = new(ConnectOptions)
}
conn, err := bindings.GetClient(ctx) conn, err := bindings.GetClient(ctx)
if err != nil { if err != nil {
return err return err
} }
// No params are used in connect
params := url.Values{} params := url.Values{}
body, err := jsoniter.MarshalToString(options) // Connect sends everything in body
connect := struct {
Container string
Aliases []string
}{
Container: ContainerNameOrId,
}
if aliases := options.GetAliases(); options.Changed("Aliases") {
connect.Aliases = aliases
}
body, err := jsoniter.MarshalToString(connect)
if err != nil { if err != nil {
return err return err
} }

View File

@ -0,0 +1,70 @@
package network
import "net"
//go:generate go run ../generator/generator.go CreateOptions
// CreateOptions are optional options for creating networks
type CreateOptions struct {
// DisableDNS turns off use of DNSMasq for name resolution
// on the network
DisableDNS *bool
// Driver is the name of network driver
Driver *string
// Gateway of the network
Gateway *net.IP
// Internal turns off communication outside the networking
// being created
Internal *bool
// Labels are metadata that can be associated with the network
Labels map[string]string
// MacVLAN is the name of the macvlan network to associate with
MacVLAN *string
// Range is the CIDR description of leasable IP addresses
IPRange *net.IPNet `scheme:"range"`
// Subnet to use
Subnet *net.IPNet
// IPv6 means the network is ipv6 capable
IPv6 *bool
// Options are a mapping of driver options and values.
Options map[string]string
// Name of the network
Name *string
}
//go:generate go run ../generator/generator.go InspectOptions
// InspectOptions are optional options for inspecting networks
type InspectOptions struct {
}
//go:generate go run ../generator/generator.go RemoveOptions
// RemoveOptions are optional options for inspecting networks
type RemoveOptions struct {
// Force removes the network even if it is being used
Force *bool
}
//go:generate go run ../generator/generator.go ListOptions
// ListOptions are optional options for listing networks
type ListOptions struct {
// Filters are applied to the list of networks to be more
// specific on the output
Filters map[string][]string
}
//go:generate go run ../generator/generator.go DisconnectOptions
// DisconnectOptions are optional options for disconnecting
// containers from a network
type DisconnectOptions struct {
// Force indicates to remove the container from
// the network forcibly
Force *bool
}
//go:generate go run ../generator/generator.go ConnectOptions
// ConnectOptions are optional options for connecting
// containers from a network
type ConnectOptions struct {
// Aliases are names the container will be known as
// when using the dns plugin
Aliases *[]string
}

View File

@ -0,0 +1,104 @@
package network
import (
"net/url"
"reflect"
"strconv"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
/*
This file is generated automatically by go generate. Do not edit.
Created 2020-12-16 11:59:06.213411549 -0600 CST m=+0.000201795
*/
// Changed
func (o *ConnectOptions) Changed(fieldName string) bool {
r := reflect.ValueOf(o)
value := reflect.Indirect(r).FieldByName(fieldName)
return !value.IsNil()
}
// ToParams
func (o *ConnectOptions) 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
}
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()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
switch typ.Kind() {
case reflect.String:
s, ok := slice.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
}
// WithAliases
func (o *ConnectOptions) WithAliases(value []string) *ConnectOptions {
v := &value
o.Aliases = v
return o
}
// GetAliases
func (o *ConnectOptions) GetAliases() []string {
var aliases []string
if o.Aliases == nil {
return aliases
}
return *o.Aliases
}

View File

@ -0,0 +1,265 @@
package network
import (
"net"
"net/url"
"reflect"
"strconv"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
/*
This file is generated automatically by go generate. Do not edit.
Created 2020-12-16 11:59:05.523424301 -0600 CST m=+0.000180953
*/
// Changed
func (o *CreateOptions) Changed(fieldName string) bool {
r := reflect.ValueOf(o)
value := reflect.Indirect(r).FieldByName(fieldName)
return !value.IsNil()
}
// ToParams
func (o *CreateOptions) 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
}
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()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
switch typ.Kind() {
case reflect.String:
s, ok := slice.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
}
// WithDisableDNS
func (o *CreateOptions) WithDisableDNS(value bool) *CreateOptions {
v := &value
o.DisableDNS = v
return o
}
// GetDisableDNS
func (o *CreateOptions) GetDisableDNS() bool {
var disableDNS bool
if o.DisableDNS == nil {
return disableDNS
}
return *o.DisableDNS
}
// WithDriver
func (o *CreateOptions) WithDriver(value string) *CreateOptions {
v := &value
o.Driver = v
return o
}
// GetDriver
func (o *CreateOptions) GetDriver() string {
var driver string
if o.Driver == nil {
return driver
}
return *o.Driver
}
// WithGateway
func (o *CreateOptions) WithGateway(value net.IP) *CreateOptions {
v := &value
o.Gateway = v
return o
}
// GetGateway
func (o *CreateOptions) GetGateway() net.IP {
var gateway net.IP
if o.Gateway == nil {
return gateway
}
return *o.Gateway
}
// WithInternal
func (o *CreateOptions) WithInternal(value bool) *CreateOptions {
v := &value
o.Internal = v
return o
}
// GetInternal
func (o *CreateOptions) GetInternal() bool {
var internal bool
if o.Internal == nil {
return internal
}
return *o.Internal
}
// WithLabels
func (o *CreateOptions) WithLabels(value map[string]string) *CreateOptions {
v := value
o.Labels = v
return o
}
// GetLabels
func (o *CreateOptions) GetLabels() map[string]string {
var labels map[string]string
if o.Labels == nil {
return labels
}
return o.Labels
}
// WithMacVLAN
func (o *CreateOptions) WithMacVLAN(value string) *CreateOptions {
v := &value
o.MacVLAN = v
return o
}
// GetMacVLAN
func (o *CreateOptions) GetMacVLAN() string {
var macVLAN string
if o.MacVLAN == nil {
return macVLAN
}
return *o.MacVLAN
}
// WithIPRange
func (o *CreateOptions) WithIPRange(value net.IPNet) *CreateOptions {
v := &value
o.IPRange = v
return o
}
// GetIPRange
func (o *CreateOptions) GetIPRange() net.IPNet {
var iPRange net.IPNet
if o.IPRange == nil {
return iPRange
}
return *o.IPRange
}
// WithSubnet
func (o *CreateOptions) WithSubnet(value net.IPNet) *CreateOptions {
v := &value
o.Subnet = v
return o
}
// GetSubnet
func (o *CreateOptions) GetSubnet() net.IPNet {
var subnet net.IPNet
if o.Subnet == nil {
return subnet
}
return *o.Subnet
}
// WithIPv6
func (o *CreateOptions) WithIPv6(value bool) *CreateOptions {
v := &value
o.IPv6 = v
return o
}
// GetIPv6
func (o *CreateOptions) GetIPv6() bool {
var iPv6 bool
if o.IPv6 == nil {
return iPv6
}
return *o.IPv6
}
// WithOptions
func (o *CreateOptions) WithOptions(value map[string]string) *CreateOptions {
v := value
o.Options = v
return o
}
// GetOptions
func (o *CreateOptions) GetOptions() map[string]string {
var options map[string]string
if o.Options == nil {
return options
}
return o.Options
}
// WithName
func (o *CreateOptions) WithName(value string) *CreateOptions {
v := &value
o.Name = v
return o
}
// GetName
func (o *CreateOptions) GetName() string {
var name string
if o.Name == nil {
return name
}
return *o.Name
}

View File

@ -0,0 +1,104 @@
package network
import (
"net/url"
"reflect"
"strconv"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
/*
This file is generated automatically by go generate. Do not edit.
Created 2020-12-16 11:59:06.07634068 -0600 CST m=+0.000179587
*/
// Changed
func (o *DisconnectOptions) Changed(fieldName string) bool {
r := reflect.ValueOf(o)
value := reflect.Indirect(r).FieldByName(fieldName)
return !value.IsNil()
}
// ToParams
func (o *DisconnectOptions) 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
}
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()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
switch typ.Kind() {
case reflect.String:
s, ok := slice.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
}
// WithForce
func (o *DisconnectOptions) WithForce(value bool) *DisconnectOptions {
v := &value
o.Force = v
return o
}
// GetForce
func (o *DisconnectOptions) GetForce() bool {
var force bool
if o.Force == nil {
return force
}
return *o.Force
}

View File

@ -0,0 +1,88 @@
package network
import (
"net/url"
"reflect"
"strconv"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
/*
This file is generated automatically by go generate. Do not edit.
Created 2020-12-16 11:59:05.661597872 -0600 CST m=+0.000168252
*/
// Changed
func (o *InspectOptions) Changed(fieldName string) bool {
r := reflect.ValueOf(o)
value := reflect.Indirect(r).FieldByName(fieldName)
return !value.IsNil()
}
// ToParams
func (o *InspectOptions) 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
}
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()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
switch typ.Kind() {
case reflect.String:
s, ok := slice.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
}

View File

@ -0,0 +1,104 @@
package network
import (
"net/url"
"reflect"
"strconv"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
/*
This file is generated automatically by go generate. Do not edit.
Created 2020-12-16 11:59:05.936262707 -0600 CST m=+0.000172058
*/
// Changed
func (o *ListOptions) Changed(fieldName string) bool {
r := reflect.ValueOf(o)
value := reflect.Indirect(r).FieldByName(fieldName)
return !value.IsNil()
}
// ToParams
func (o *ListOptions) 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
}
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()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
switch typ.Kind() {
case reflect.String:
s, ok := slice.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
}
// WithFilters
func (o *ListOptions) WithFilters(value map[string][]string) *ListOptions {
v := value
o.Filters = v
return o
}
// GetFilters
func (o *ListOptions) GetFilters() map[string][]string {
var filters map[string][]string
if o.Filters == nil {
return filters
}
return o.Filters
}

View File

@ -0,0 +1,104 @@
package network
import (
"net/url"
"reflect"
"strconv"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
/*
This file is generated automatically by go generate. Do not edit.
Created 2020-12-16 11:59:05.798818224 -0600 CST m=+0.000173420
*/
// Changed
func (o *RemoveOptions) Changed(fieldName string) bool {
r := reflect.ValueOf(o)
value := reflect.Indirect(r).FieldByName(fieldName)
return !value.IsNil()
}
// ToParams
func (o *RemoveOptions) 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
}
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()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
switch typ.Kind() {
case reflect.String:
s, ok := slice.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
}
// WithForce
func (o *RemoveOptions) WithForce(value bool) *RemoveOptions {
v := &value
o.Force = v
return o
}
// GetForce
func (o *RemoveOptions) GetForce() bool {
var force bool
if o.Force == nil {
return force
}
return *o.Force
}

View File

@ -3,18 +3,19 @@ package play
import ( import (
"context" "context"
"net/http" "net/http"
"net/url"
"os" "os"
"strconv" "strconv"
"github.com/containers/image/v5/types"
"github.com/containers/podman/v2/pkg/auth" "github.com/containers/podman/v2/pkg/auth"
"github.com/containers/podman/v2/pkg/bindings" "github.com/containers/podman/v2/pkg/bindings"
"github.com/containers/podman/v2/pkg/domain/entities" "github.com/containers/podman/v2/pkg/domain/entities"
) )
func Kube(ctx context.Context, path string, options entities.PlayKubeOptions) (*entities.PlayKubeReport, error) { func Kube(ctx context.Context, path string, options *KubeOptions) (*entities.PlayKubeReport, error) {
var report entities.PlayKubeReport var report entities.PlayKubeReport
if options == nil {
options = new(KubeOptions)
}
conn, err := bindings.GetClient(ctx) conn, err := bindings.GetClient(ctx)
if err != nil { if err != nil {
return nil, err return nil, err
@ -26,18 +27,19 @@ func Kube(ctx context.Context, path string, options entities.PlayKubeOptions) (*
} }
defer f.Close() defer f.Close()
params := url.Values{} params, err := options.ToParams()
params.Set("network", options.Network) if err != nil {
params.Set("logDriver", options.LogDriver) return nil, err
if options.SkipTLSVerify != types.OptionalBoolUndefined {
params.Set("tlsVerify", strconv.FormatBool(options.SkipTLSVerify != types.OptionalBoolTrue))
} }
if options.Start != types.OptionalBoolUndefined { if options.SkipTLSVerify != nil {
params.Set("start", strconv.FormatBool(options.Start == types.OptionalBoolTrue)) params.Set("tlsVerify", strconv.FormatBool(options.GetSkipTLSVerify()))
}
if options.Start != nil {
params.Set("start", strconv.FormatBool(options.GetStart()))
} }
// TODO: have a global system context we can pass around (1st argument) // TODO: have a global system context we can pass around (1st argument)
header, err := auth.Header(nil, auth.XRegistryAuthHeader, options.Authfile, options.Username, options.Password) header, err := auth.Header(nil, auth.XRegistryAuthHeader, options.GetAuthfile(), options.GetUsername(), options.GetPassword())
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -0,0 +1,32 @@
package play
//go:generate go run ../generator/generator.go KubeOptions
// KubeOptions are optional options for replaying kube YAML files
type KubeOptions struct {
// Authfile - path to an authentication file.
Authfile *string
// CertDir - to a directory containing TLS certifications and keys.
CertDir *string
// Username for authenticating against the registry.
Username *string
// Password for authenticating against the registry.
Password *string
// Network - name of the CNI network to connect to.
Network *string
// Quiet - suppress output when pulling images.
Quiet *bool
// SignaturePolicy - path to a signature-policy file.
SignaturePolicy *string
// SkipTLSVerify - skip https and certificate validation when
// contacting container registries.
SkipTLSVerify *bool
// SeccompProfileRoot - path to a directory containing seccomp
// profiles.
SeccompProfileRoot *string
// ConfigMaps - slice of pathnames to kubernetes configmap YAMLs.
ConfigMaps *[]string
// LogDriver for the container. For example: journald
LogDriver *string
// Start - don't start the pod if false
Start *bool
}

View File

@ -0,0 +1,280 @@
package play
import (
"net/url"
"reflect"
"strconv"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
/*
This file is generated automatically by go generate. Do not edit.
Created 2020-12-16 11:59:11.20490387 -0600 CST m=+0.000181859
*/
// Changed
func (o *KubeOptions) Changed(fieldName string) bool {
r := reflect.ValueOf(o)
value := reflect.Indirect(r).FieldByName(fieldName)
return !value.IsNil()
}
// ToParams
func (o *KubeOptions) 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
}
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()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
switch typ.Kind() {
case reflect.String:
s, ok := slice.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
}
// WithAuthfile
func (o *KubeOptions) WithAuthfile(value string) *KubeOptions {
v := &value
o.Authfile = v
return o
}
// GetAuthfile
func (o *KubeOptions) GetAuthfile() string {
var authfile string
if o.Authfile == nil {
return authfile
}
return *o.Authfile
}
// WithCertDir
func (o *KubeOptions) WithCertDir(value string) *KubeOptions {
v := &value
o.CertDir = v
return o
}
// GetCertDir
func (o *KubeOptions) GetCertDir() string {
var certDir string
if o.CertDir == nil {
return certDir
}
return *o.CertDir
}
// WithUsername
func (o *KubeOptions) WithUsername(value string) *KubeOptions {
v := &value
o.Username = v
return o
}
// GetUsername
func (o *KubeOptions) GetUsername() string {
var username string
if o.Username == nil {
return username
}
return *o.Username
}
// WithPassword
func (o *KubeOptions) WithPassword(value string) *KubeOptions {
v := &value
o.Password = v
return o
}
// GetPassword
func (o *KubeOptions) GetPassword() string {
var password string
if o.Password == nil {
return password
}
return *o.Password
}
// WithNetwork
func (o *KubeOptions) WithNetwork(value string) *KubeOptions {
v := &value
o.Network = v
return o
}
// GetNetwork
func (o *KubeOptions) GetNetwork() string {
var network string
if o.Network == nil {
return network
}
return *o.Network
}
// WithQuiet
func (o *KubeOptions) WithQuiet(value bool) *KubeOptions {
v := &value
o.Quiet = v
return o
}
// GetQuiet
func (o *KubeOptions) GetQuiet() bool {
var quiet bool
if o.Quiet == nil {
return quiet
}
return *o.Quiet
}
// WithSignaturePolicy
func (o *KubeOptions) WithSignaturePolicy(value string) *KubeOptions {
v := &value
o.SignaturePolicy = v
return o
}
// GetSignaturePolicy
func (o *KubeOptions) GetSignaturePolicy() string {
var signaturePolicy string
if o.SignaturePolicy == nil {
return signaturePolicy
}
return *o.SignaturePolicy
}
// WithSkipTLSVerify
func (o *KubeOptions) WithSkipTLSVerify(value bool) *KubeOptions {
v := &value
o.SkipTLSVerify = v
return o
}
// GetSkipTLSVerify
func (o *KubeOptions) GetSkipTLSVerify() bool {
var skipTLSVerify bool
if o.SkipTLSVerify == nil {
return skipTLSVerify
}
return *o.SkipTLSVerify
}
// WithSeccompProfileRoot
func (o *KubeOptions) WithSeccompProfileRoot(value string) *KubeOptions {
v := &value
o.SeccompProfileRoot = v
return o
}
// GetSeccompProfileRoot
func (o *KubeOptions) GetSeccompProfileRoot() string {
var seccompProfileRoot string
if o.SeccompProfileRoot == nil {
return seccompProfileRoot
}
return *o.SeccompProfileRoot
}
// WithConfigMaps
func (o *KubeOptions) WithConfigMaps(value []string) *KubeOptions {
v := &value
o.ConfigMaps = v
return o
}
// GetConfigMaps
func (o *KubeOptions) GetConfigMaps() []string {
var configMaps []string
if o.ConfigMaps == nil {
return configMaps
}
return *o.ConfigMaps
}
// WithLogDriver
func (o *KubeOptions) WithLogDriver(value string) *KubeOptions {
v := &value
o.LogDriver = v
return o
}
// GetLogDriver
func (o *KubeOptions) GetLogDriver() string {
var logDriver string
if o.LogDriver == nil {
return logDriver
}
return *o.LogDriver
}
// WithStart
func (o *KubeOptions) WithStart(value bool) *KubeOptions {
v := &value
o.Start = v
return o
}
// GetStart
func (o *KubeOptions) GetStart() bool {
var start bool
if o.Start == nil {
return start
}
return *o.Start
}

View File

@ -9,7 +9,11 @@ import (
) )
// Info returns information about the libpod environment and its stores // Info returns information about the libpod environment and its stores
func Info(ctx context.Context) (*define.Info, error) { func Info(ctx context.Context, options *InfoOptions) (*define.Info, error) {
if options == nil {
options = new(InfoOptions)
}
_ = options
info := define.Info{} info := define.Info{}
conn, err := bindings.GetClient(ctx) conn, err := bindings.GetClient(ctx)
if err != nil { if err != nil {

View File

@ -6,8 +6,6 @@ import (
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
"net/url"
"strconv"
"time" "time"
"github.com/containers/podman/v2/libpod/define" "github.com/containers/podman/v2/libpod/define"
@ -20,27 +18,14 @@ import (
// Events allows you to monitor libdpod related events like container creation and // Events allows you to monitor libdpod related events like container creation and
// removal. The events are then passed to the eventChan provided. The optional cancelChan // removal. The events are then passed to the eventChan provided. The optional cancelChan
// can be used to cancel the read of events and close down the HTTP connection. // can be used to cancel the read of events and close down the HTTP connection.
func Events(ctx context.Context, eventChan chan entities.Event, cancelChan chan bool, since, until *string, filters map[string][]string, stream *bool) error { func Events(ctx context.Context, eventChan chan entities.Event, cancelChan chan bool, options *EventsOptions) error {
conn, err := bindings.GetClient(ctx) conn, err := bindings.GetClient(ctx)
if err != nil { if err != nil {
return err return err
} }
params := url.Values{} params, err := options.ToParams()
if since != nil { if err != nil {
params.Set("since", *since) return err
}
if until != nil {
params.Set("until", *until)
}
if stream != nil {
params.Set("stream", strconv.FormatBool(*stream))
}
if filters != nil {
filterString, err := bindings.FiltersToString(filters)
if err != nil {
return errors.Wrap(err, "invalid filters")
}
params.Set("filters", filterString)
} }
response, err := conn.DoRequest(nil, http.MethodGet, "/events", params, nil) response, err := conn.DoRequest(nil, http.MethodGet, "/events", params, nil)
if err != nil { if err != nil {
@ -74,7 +59,7 @@ func Events(ctx context.Context, eventChan chan entities.Event, cancelChan chan
} }
// Prune removes all unused system data. // Prune removes all unused system data.
func Prune(ctx context.Context, all, volumes *bool) (*entities.SystemPruneReport, error) { func Prune(ctx context.Context, options *PruneOptions) (*entities.SystemPruneReport, error) {
var ( var (
report entities.SystemPruneReport report entities.SystemPruneReport
) )
@ -82,12 +67,9 @@ func Prune(ctx context.Context, all, volumes *bool) (*entities.SystemPruneReport
if err != nil { if err != nil {
return nil, err return nil, err
} }
params := url.Values{} params, err := options.ToParams()
if all != nil { if err != nil {
params.Set("All", strconv.FormatBool(*all)) return nil, err
}
if volumes != nil {
params.Set("Volumes", strconv.FormatBool(*volumes))
} }
response, err := conn.DoRequest(nil, http.MethodPost, "/system/prune", params, nil) response, err := conn.DoRequest(nil, http.MethodPost, "/system/prune", params, nil)
if err != nil { if err != nil {
@ -96,10 +78,15 @@ func Prune(ctx context.Context, all, volumes *bool) (*entities.SystemPruneReport
return &report, response.Process(&report) return &report, response.Process(&report)
} }
func Version(ctx context.Context) (*entities.SystemVersionReport, error) { func Version(ctx context.Context, options *VersionOptions) (*entities.SystemVersionReport, error) {
var report entities.SystemVersionReport var (
var component entities.ComponentVersion component entities.ComponentVersion
report entities.SystemVersionReport
)
if options == nil {
options = new(VersionOptions)
}
_ = options
version, err := define.GetVersion() version, err := define.GetVersion()
if err != nil { if err != nil {
return nil, err return nil, err
@ -140,8 +127,12 @@ func Version(ctx context.Context) (*entities.SystemVersionReport, error) {
// DiskUsage returns information about image, container, and volume disk // DiskUsage returns information about image, container, and volume disk
// consumption // consumption
func DiskUsage(ctx context.Context) (*entities.SystemDfReport, error) { func DiskUsage(ctx context.Context, options *DiskOptions) (*entities.SystemDfReport, error) {
var report entities.SystemDfReport var report entities.SystemDfReport
if options == nil {
options = new(DiskOptions)
}
_ = options
conn, err := bindings.GetClient(ctx) conn, err := bindings.GetClient(ctx)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -0,0 +1,34 @@
package system
//go:generate go run ../generator/generator.go EventsOptions
// EventsOptions are optional options for monitoring events
type EventsOptions struct {
Filters map[string][]string
Since *string
Stream *bool
Until *string
}
//go:generate go run ../generator/generator.go PruneOptions
// PruneOptions are optional options for pruning
type PruneOptions struct {
All *bool
Filters map[string][]string
Volumes *bool
}
//go:generate go run ../generator/generator.go VersionOptions
// VersionOptions are optional options for getting version info
type VersionOptions struct {
}
//go:generate go run ../generator/generator.go DiskOptions
// DiskOptions are optional options for getting storage consumption
type DiskOptions struct {
}
//go:generate go run ../generator/generator.go InfoOptions
// InfoOptions are optional options for getting info
// about libpod
type InfoOptions struct {
}

View File

@ -0,0 +1,88 @@
package system
import (
"net/url"
"reflect"
"strconv"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
/*
This file is generated automatically by go generate. Do not edit.
Created 2020-12-17 09:13:10.734962166 -0600 CST m=+0.000145336
*/
// Changed
func (o *DiskOptions) Changed(fieldName string) bool {
r := reflect.ValueOf(o)
value := reflect.Indirect(r).FieldByName(fieldName)
return !value.IsNil()
}
// ToParams
func (o *DiskOptions) 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
}
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()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
switch typ.Kind() {
case reflect.String:
s, ok := slice.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
}

View File

@ -0,0 +1,152 @@
package system
import (
"net/url"
"reflect"
"strconv"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
/*
This file is generated automatically by go generate. Do not edit.
Created 2020-12-17 09:13:10.308724359 -0600 CST m=+0.000145204
*/
// Changed
func (o *EventsOptions) Changed(fieldName string) bool {
r := reflect.ValueOf(o)
value := reflect.Indirect(r).FieldByName(fieldName)
return !value.IsNil()
}
// ToParams
func (o *EventsOptions) 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
}
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()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
switch typ.Kind() {
case reflect.String:
s, ok := slice.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
}
// WithFilters
func (o *EventsOptions) WithFilters(value map[string][]string) *EventsOptions {
v := value
o.Filters = v
return o
}
// GetFilters
func (o *EventsOptions) GetFilters() map[string][]string {
var filters map[string][]string
if o.Filters == nil {
return filters
}
return o.Filters
}
// WithSince
func (o *EventsOptions) WithSince(value string) *EventsOptions {
v := &value
o.Since = v
return o
}
// GetSince
func (o *EventsOptions) GetSince() string {
var since string
if o.Since == nil {
return since
}
return *o.Since
}
// WithStream
func (o *EventsOptions) WithStream(value bool) *EventsOptions {
v := &value
o.Stream = v
return o
}
// GetStream
func (o *EventsOptions) GetStream() bool {
var stream bool
if o.Stream == nil {
return stream
}
return *o.Stream
}
// WithUntil
func (o *EventsOptions) WithUntil(value string) *EventsOptions {
v := &value
o.Until = v
return o
}
// GetUntil
func (o *EventsOptions) GetUntil() string {
var until string
if o.Until == nil {
return until
}
return *o.Until
}

View File

@ -0,0 +1,88 @@
package system
import (
"net/url"
"reflect"
"strconv"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
/*
This file is generated automatically by go generate. Do not edit.
Created 2020-12-17 09:13:10.872420889 -0600 CST m=+0.000136023
*/
// Changed
func (o *InfoOptions) Changed(fieldName string) bool {
r := reflect.ValueOf(o)
value := reflect.Indirect(r).FieldByName(fieldName)
return !value.IsNil()
}
// ToParams
func (o *InfoOptions) 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
}
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()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
switch typ.Kind() {
case reflect.String:
s, ok := slice.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
}

View File

@ -0,0 +1,136 @@
package system
import (
"net/url"
"reflect"
"strconv"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
/*
This file is generated automatically by go generate. Do not edit.
Created 2020-12-17 09:13:10.456894557 -0600 CST m=+0.000141897
*/
// Changed
func (o *PruneOptions) Changed(fieldName string) bool {
r := reflect.ValueOf(o)
value := reflect.Indirect(r).FieldByName(fieldName)
return !value.IsNil()
}
// ToParams
func (o *PruneOptions) 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
}
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()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
switch typ.Kind() {
case reflect.String:
s, ok := slice.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
}
// WithAll
func (o *PruneOptions) WithAll(value bool) *PruneOptions {
v := &value
o.All = v
return o
}
// GetAll
func (o *PruneOptions) GetAll() bool {
var all bool
if o.All == nil {
return all
}
return *o.All
}
// WithFilters
func (o *PruneOptions) WithFilters(value map[string][]string) *PruneOptions {
v := value
o.Filters = v
return o
}
// GetFilters
func (o *PruneOptions) GetFilters() map[string][]string {
var filters map[string][]string
if o.Filters == nil {
return filters
}
return o.Filters
}
// WithVolumes
func (o *PruneOptions) WithVolumes(value bool) *PruneOptions {
v := &value
o.Volumes = v
return o
}
// GetVolumes
func (o *PruneOptions) GetVolumes() bool {
var volumes bool
if o.Volumes == nil {
return volumes
}
return *o.Volumes
}

View File

@ -0,0 +1,88 @@
package system
import (
"net/url"
"reflect"
"strconv"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
/*
This file is generated automatically by go generate. Do not edit.
Created 2020-12-17 09:13:10.596882708 -0600 CST m=+0.000141540
*/
// Changed
func (o *VersionOptions) Changed(fieldName string) bool {
r := reflect.ValueOf(o)
value := reflect.Indirect(r).FieldByName(fieldName)
return !value.IsNil()
}
// ToParams
func (o *VersionOptions) 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
}
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()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
switch typ.Kind() {
case reflect.String:
s, ok := slice.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
}

View File

@ -34,7 +34,7 @@ var _ = Describe("Podman info", func() {
}) })
It("podman info", func() { It("podman info", func() {
info, err := system.Info(bt.conn) info, err := system.Info(bt.conn, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(info.Host.Arch).To(Equal(runtime.GOARCH)) Expect(info.Host.Arch).To(Equal(runtime.GOARCH))
Expect(info.Host.OS).To(Equal(runtime.GOOS)) Expect(info.Host.OS).To(Equal(runtime.GOOS))
@ -62,7 +62,7 @@ var _ = Describe("Podman info", func() {
_, err = bt.RunTopContainer(nil, nil, nil) _, err = bt.RunTopContainer(nil, nil, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
info, err := system.Info(bt.conn) info, err := system.Info(bt.conn, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(info.Store.ContainerStore.Number).To(BeNumerically("==", 4)) Expect(info.Store.ContainerStore.Number).To(BeNumerically("==", 4))

View File

@ -4,7 +4,6 @@ import (
"net/http" "net/http"
"time" "time"
"github.com/containers/podman/v2/libpod/image"
"github.com/containers/podman/v2/pkg/bindings" "github.com/containers/podman/v2/pkg/bindings"
"github.com/containers/podman/v2/pkg/bindings/images" "github.com/containers/podman/v2/pkg/bindings/images"
"github.com/containers/podman/v2/pkg/bindings/manifests" "github.com/containers/podman/v2/pkg/bindings/manifests"
@ -37,7 +36,7 @@ var _ = Describe("Podman containers ", func() {
// create manifest list without images // create manifest list without images
id, err := manifests.Create(bt.conn, []string{"quay.io/libpod/foobar:latest"}, []string{}, nil) id, err := manifests.Create(bt.conn, []string{"quay.io/libpod/foobar:latest"}, []string{}, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
list, err := manifests.Inspect(bt.conn, id) list, err := manifests.Inspect(bt.conn, id, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(len(list.Manifests)).To(BeZero()) Expect(len(list.Manifests)).To(BeZero())
@ -53,13 +52,13 @@ var _ = Describe("Podman containers ", func() {
// create manifest list with images // create manifest list with images
id, err = manifests.Create(bt.conn, []string{"quay.io/libpod/foobar:latest"}, []string{alpine.name}, nil) id, err = manifests.Create(bt.conn, []string{"quay.io/libpod/foobar:latest"}, []string{alpine.name}, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
list, err = manifests.Inspect(bt.conn, id) list, err = manifests.Inspect(bt.conn, id, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(len(list.Manifests)).To(BeNumerically("==", 1)) Expect(len(list.Manifests)).To(BeNumerically("==", 1))
}) })
It("inspect bogus manifest", func() { It("inspect bogus manifest", func() {
_, err := manifests.Inspect(bt.conn, "larry") _, err := manifests.Inspect(bt.conn, "larry", nil)
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err) code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound)) Expect(code).To(BeNumerically("==", http.StatusNotFound))
@ -67,23 +66,23 @@ var _ = Describe("Podman containers ", func() {
It("add manifest", func() { It("add manifest", func() {
// add to bogus should 404 // add to bogus should 404
_, err := manifests.Add(bt.conn, "foobar", image.ManifestAddOpts{}) _, err := manifests.Add(bt.conn, "foobar", nil)
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err) code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound)) Expect(code).To(BeNumerically("==", http.StatusNotFound))
id, err := manifests.Create(bt.conn, []string{"quay.io/libpod/foobar:latest"}, []string{}, nil) id, err := manifests.Create(bt.conn, []string{"quay.io/libpod/foobar:latest"}, []string{}, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
opts := image.ManifestAddOpts{Images: []string{alpine.name}} options := new(manifests.AddOptions).WithImages([]string{alpine.name})
_, err = manifests.Add(bt.conn, id, opts) _, err = manifests.Add(bt.conn, id, options)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
list, err := manifests.Inspect(bt.conn, id) list, err := manifests.Inspect(bt.conn, id, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(len(list.Manifests)).To(BeNumerically("==", 1)) Expect(len(list.Manifests)).To(BeNumerically("==", 1))
// add bogus name to existing list should fail // add bogus name to existing list should fail
opts.Images = []string{"larry"} options.WithImages([]string{"larry"})
_, err = manifests.Add(bt.conn, id, opts) _, err = manifests.Add(bt.conn, id, options)
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
code, _ = bindings.CheckResponseCode(err) code, _ = bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusInternalServerError)) Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
@ -91,29 +90,29 @@ var _ = Describe("Podman containers ", func() {
It("remove manifest", func() { It("remove manifest", func() {
// removal on bogus manifest list should be 404 // removal on bogus manifest list should be 404
_, err := manifests.Remove(bt.conn, "larry", "1234") _, err := manifests.Remove(bt.conn, "larry", "1234", nil)
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err) code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound)) Expect(code).To(BeNumerically("==", http.StatusNotFound))
id, err := manifests.Create(bt.conn, []string{"quay.io/libpod/foobar:latest"}, []string{alpine.name}, nil) id, err := manifests.Create(bt.conn, []string{"quay.io/libpod/foobar:latest"}, []string{alpine.name}, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
data, err := manifests.Inspect(bt.conn, id) data, err := manifests.Inspect(bt.conn, id, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(len(data.Manifests)).To(BeNumerically("==", 1)) Expect(len(data.Manifests)).To(BeNumerically("==", 1))
// removal on a good manifest list with a bad digest should be 400 // removal on a good manifest list with a bad digest should be 400
_, err = manifests.Remove(bt.conn, id, "!234") _, err = manifests.Remove(bt.conn, id, "!234", nil)
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
code, _ = bindings.CheckResponseCode(err) code, _ = bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusBadRequest)) Expect(code).To(BeNumerically("==", http.StatusBadRequest))
digest := data.Manifests[0].Digest.String() digest := data.Manifests[0].Digest.String()
_, err = manifests.Remove(bt.conn, id, digest) _, err = manifests.Remove(bt.conn, id, digest, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
// removal on good manifest with good digest should work // removal on good manifest with good digest should work
data, err = manifests.Inspect(bt.conn, id) data, err = manifests.Inspect(bt.conn, id, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(len(data.Manifests)).To(BeZero()) Expect(len(data.Manifests)).To(BeZero())
}) })

View File

@ -56,8 +56,8 @@ var _ = Describe("Podman system", func() {
eventCounter++ eventCounter++
} }
}() }()
options := new(system.EventsOptions).WithFilters(filters).WithStream(false)
err = system.Events(bt.conn, binChan, nil, nil, nil, filters, bindings.PFalse) err = system.Events(bt.conn, binChan, nil, options)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
done.Lock() done.Lock()
Expect(eventCounter).To(BeNumerically(">", 0)) Expect(eventCounter).To(BeNumerically(">", 0))
@ -76,7 +76,8 @@ var _ = Describe("Podman system", func() {
err = containers.Stop(bt.conn, name, nil) err = containers.Stop(bt.conn, name, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
systemPruneResponse, err := system.Prune(bt.conn, bindings.PTrue, bindings.PFalse) options := new(system.PruneOptions).WithAll(true)
systemPruneResponse, err := system.Prune(bt.conn, options)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(len(systemPruneResponse.PodPruneReport)).To(Equal(1)) Expect(len(systemPruneResponse.PodPruneReport)).To(Equal(1))
Expect(len(systemPruneResponse.ContainerPruneReport.ID)).To(Equal(1)) Expect(len(systemPruneResponse.ContainerPruneReport.ID)).To(Equal(1))
@ -107,10 +108,10 @@ var _ = Describe("Podman system", func() {
Expect(err).To(BeNil()) Expect(err).To(BeNil())
// Adding an unused volume // Adding an unused volume
_, err = volumes.Create(bt.conn, entities.VolumeCreateOptions{}) _, err = volumes.Create(bt.conn, entities.VolumeCreateOptions{}, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
options := new(system.PruneOptions).WithAll(true)
systemPruneResponse, err := system.Prune(bt.conn, bindings.PTrue, bindings.PFalse) systemPruneResponse, err := system.Prune(bt.conn, options)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(len(systemPruneResponse.PodPruneReport)).To(Equal(1)) Expect(len(systemPruneResponse.PodPruneReport)).To(Equal(1))
Expect(len(systemPruneResponse.ContainerPruneReport.ID)).To(Equal(1)) Expect(len(systemPruneResponse.ContainerPruneReport.ID)).To(Equal(1))
@ -141,10 +142,11 @@ var _ = Describe("Podman system", func() {
Expect(err).To(BeNil()) Expect(err).To(BeNil())
// Adding an unused volume should work // Adding an unused volume should work
_, err = volumes.Create(bt.conn, entities.VolumeCreateOptions{}) _, err = volumes.Create(bt.conn, entities.VolumeCreateOptions{}, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
systemPruneResponse, err := system.Prune(bt.conn, bindings.PTrue, bindings.PTrue) options := new(system.PruneOptions).WithAll(true).WithVolumes(true)
systemPruneResponse, err := system.Prune(bt.conn, options)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(len(systemPruneResponse.PodPruneReport)).To(Equal(0)) Expect(len(systemPruneResponse.PodPruneReport)).To(Equal(0))
Expect(len(systemPruneResponse.ContainerPruneReport.ID)).To(Equal(1)) Expect(len(systemPruneResponse.ContainerPruneReport.ID)).To(Equal(1))

View File

@ -52,7 +52,7 @@ var _ = Describe("Podman volumes", func() {
It("create volume", func() { It("create volume", func() {
// create a volume with blank config should work // create a volume with blank config should work
_, err := volumes.Create(connText, entities.VolumeCreateOptions{}) _, err := volumes.Create(connText, entities.VolumeCreateOptions{}, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
vcc := entities.VolumeCreateOptions{ vcc := entities.VolumeCreateOptions{
@ -60,21 +60,21 @@ var _ = Describe("Podman volumes", func() {
Label: nil, Label: nil,
Options: nil, Options: nil,
} }
vol, err := volumes.Create(connText, vcc) vol, err := volumes.Create(connText, vcc, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(vol.Name).To(Equal("foobar")) Expect(vol.Name).To(Equal("foobar"))
// create volume with same name should 500 // create volume with same name should 500
_, err = volumes.Create(connText, vcc) _, err = volumes.Create(connText, vcc, nil)
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err) code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusInternalServerError)) Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
}) })
It("inspect volume", func() { It("inspect volume", func() {
vol, err := volumes.Create(connText, entities.VolumeCreateOptions{}) vol, err := volumes.Create(connText, entities.VolumeCreateOptions{}, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
data, err := volumes.Inspect(connText, vol.Name) data, err := volumes.Inspect(connText, vol.Name, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(data.Name).To(Equal(vol.Name)) Expect(data.Name).To(Equal(vol.Name))
}) })
@ -86,13 +86,13 @@ var _ = Describe("Podman volumes", func() {
Expect(code).To(BeNumerically("==", http.StatusNotFound)) Expect(code).To(BeNumerically("==", http.StatusNotFound))
// Removing an unused volume should work // Removing an unused volume should work
vol, err := volumes.Create(connText, entities.VolumeCreateOptions{}) vol, err := volumes.Create(connText, entities.VolumeCreateOptions{}, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
err = volumes.Remove(connText, vol.Name, nil) err = volumes.Remove(connText, vol.Name, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
// Removing a volume that is being used without force should be 409 // Removing a volume that is being used without force should be 409
vol, err = volumes.Create(connText, entities.VolumeCreateOptions{}) vol, err = volumes.Create(connText, entities.VolumeCreateOptions{}, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
session := bt.runPodman([]string{"run", "-dt", "-v", fmt.Sprintf("%s:/foobar", vol.Name), "--name", "vtest", alpine.name, "top"}) session := bt.runPodman([]string{"run", "-dt", "-v", fmt.Sprintf("%s:/foobar", vol.Name), "--name", "vtest", alpine.name, "top"})
session.Wait(45) session.Wait(45)
@ -105,7 +105,8 @@ var _ = Describe("Podman volumes", func() {
zero := uint(0) zero := uint(0)
err = containers.Stop(connText, "vtest", &zero) err = containers.Stop(connText, "vtest", &zero)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
err = volumes.Remove(connText, vol.Name, bindings.PTrue) options := new(volumes.RemoveOptions).WithForce(true)
err = volumes.Remove(connText, vol.Name, options)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
}) })
@ -118,7 +119,7 @@ var _ = Describe("Podman volumes", func() {
// create a bunch of named volumes and make verify with list // create a bunch of named volumes and make verify with list
volNames := []string{"homer", "bart", "lisa", "maggie", "marge"} volNames := []string{"homer", "bart", "lisa", "maggie", "marge"}
for i := 0; i < 5; i++ { for i := 0; i < 5; i++ {
_, err = volumes.Create(connText, entities.VolumeCreateOptions{Name: volNames[i]}) _, err = volumes.Create(connText, entities.VolumeCreateOptions{Name: volNames[i]}, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
} }
vols, err = volumes.List(connText, nil) vols, err = volumes.List(connText, nil)
@ -131,14 +132,16 @@ var _ = Describe("Podman volumes", func() {
// list with bad filter should be 500 // list with bad filter should be 500
filters := make(map[string][]string) filters := make(map[string][]string)
filters["foobar"] = []string{"1234"} filters["foobar"] = []string{"1234"}
_, err = volumes.List(connText, filters) options := new(volumes.ListOptions).WithFilters(filters)
_, err = volumes.List(connText, options)
Expect(err).ToNot(BeNil()) Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err) code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusInternalServerError)) Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
filters = make(map[string][]string) filters = make(map[string][]string)
filters["name"] = []string{"homer"} filters["name"] = []string{"homer"}
vols, err = volumes.List(connText, filters) options = new(volumes.ListOptions).WithFilters(filters)
vols, err = volumes.List(connText, options)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(len(vols)).To(BeNumerically("==", 1)) Expect(len(vols)).To(BeNumerically("==", 1))
Expect(vols[0].Name).To(Equal("homer")) Expect(vols[0].Name).To(Equal("homer"))
@ -150,22 +153,22 @@ var _ = Describe("Podman volumes", func() {
Expect(err).To(BeNil()) Expect(err).To(BeNil())
// Removing an unused volume should work // Removing an unused volume should work
_, err = volumes.Create(connText, entities.VolumeCreateOptions{}) _, err = volumes.Create(connText, entities.VolumeCreateOptions{}, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
vols, err := volumes.Prune(connText, nil) vols, err := volumes.Prune(connText, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(len(vols)).To(BeNumerically("==", 1)) Expect(len(vols)).To(BeNumerically("==", 1))
_, err = volumes.Create(connText, entities.VolumeCreateOptions{Name: "homer"}) _, err = volumes.Create(connText, entities.VolumeCreateOptions{Name: "homer"}, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
_, err = volumes.Create(connText, entities.VolumeCreateOptions{}) _, err = volumes.Create(connText, entities.VolumeCreateOptions{}, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
session := bt.runPodman([]string{"run", "-dt", "-v", fmt.Sprintf("%s:/homer", "homer"), "--name", "vtest", alpine.name, "top"}) session := bt.runPodman([]string{"run", "-dt", "-v", fmt.Sprintf("%s:/homer", "homer"), "--name", "vtest", alpine.name, "top"})
session.Wait(45) session.Wait(45)
vols, err = volumes.Prune(connText, nil) vols, err = volumes.Prune(connText, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(len(vols)).To(BeNumerically("==", 1)) Expect(len(vols)).To(BeNumerically("==", 1))
_, err = volumes.Inspect(connText, "homer") _, err = volumes.Inspect(connText, "homer", nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
// Removing volume with non matching filter shouldn't prune any volumes // Removing volume with non matching filter shouldn't prune any volumes
@ -173,24 +176,26 @@ var _ = Describe("Podman volumes", func() {
filters["label"] = []string{"label1=idontmatch"} filters["label"] = []string{"label1=idontmatch"}
_, err = volumes.Create(connText, entities.VolumeCreateOptions{Label: map[string]string{ _, err = volumes.Create(connText, entities.VolumeCreateOptions{Label: map[string]string{
"label1": "value1", "label1": "value1",
}}) }}, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
vols, err = volumes.Prune(connText, filters) options := new(volumes.PruneOptions).WithFilters(filters)
vols, err = volumes.Prune(connText, options)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(len(vols)).To(BeNumerically("==", 0)) Expect(len(vols)).To(BeNumerically("==", 0))
vol2, err := volumes.Create(connText, entities.VolumeCreateOptions{Label: map[string]string{ vol2, err := volumes.Create(connText, entities.VolumeCreateOptions{Label: map[string]string{
"label1": "value2", "label1": "value2",
}}) }}, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
_, err = volumes.Create(connText, entities.VolumeCreateOptions{Label: map[string]string{ _, err = volumes.Create(connText, entities.VolumeCreateOptions{Label: map[string]string{
"label1": "value3", "label1": "value3",
}}) }}, nil)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
// Removing volume with matching filter label and value should remove specific entry // Removing volume with matching filter label and value should remove specific entry
filters = make(map[string][]string) filters = make(map[string][]string)
filters["label"] = []string{"label1=value2"} filters["label"] = []string{"label1=value2"}
vols, err = volumes.Prune(connText, filters) options = new(volumes.PruneOptions).WithFilters(filters)
vols, err = volumes.Prune(connText, options)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(len(vols)).To(BeNumerically("==", 1)) Expect(len(vols)).To(BeNumerically("==", 1))
Expect(vols[0].Id).To(Equal(vol2.Name)) Expect(vols[0].Id).To(Equal(vol2.Name))
@ -198,7 +203,8 @@ var _ = Describe("Podman volumes", func() {
// Removing volumes with matching filter label should remove all matching volumes // Removing volumes with matching filter label should remove all matching volumes
filters = make(map[string][]string) filters = make(map[string][]string)
filters["label"] = []string{"label1"} filters["label"] = []string{"label1"}
vols, err = volumes.Prune(connText, filters) options = new(volumes.PruneOptions).WithFilters(filters)
vols, err = volumes.Prune(connText, options)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
Expect(len(vols)).To(BeNumerically("==", 2)) Expect(len(vols)).To(BeNumerically("==", 2))
}) })

View File

@ -0,0 +1,32 @@
package volumes
//go:generate go run ../generator/generator.go CreateOptions
// CreateOptions are optional options for creating volumes
type CreateOptions struct {
}
//go:generate go run ../generator/generator.go InspectOptions
// InspectOptions are optional options for inspecting volumes
type InspectOptions struct {
}
//go:generate go run ../generator/generator.go ListOptions
// ListOptions are optional options for listing volumes
type ListOptions struct {
// Filters applied to the listing of volumes
Filters map[string][]string
}
//go:generate go run ../generator/generator.go PruneOptions
// PruneOptions are optional options for pruning volumes
type PruneOptions struct {
// Filters applied to the pruning of volumes
Filters map[string][]string
}
//go:generate go run ../generator/generator.go RemoveOptions
// RemoveOptions are optional options for removing volumes
type RemoveOptions struct {
// Force removes the volume even if it is being used
Force *bool
}

View File

@ -0,0 +1,88 @@
package volumes
import (
"net/url"
"reflect"
"strconv"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
/*
This file is generated automatically by go generate. Do not edit.
Created 2020-12-16 11:59:25.536700522 -0600 CST m=+0.000174605
*/
// Changed
func (o *CreateOptions) Changed(fieldName string) bool {
r := reflect.ValueOf(o)
value := reflect.Indirect(r).FieldByName(fieldName)
return !value.IsNil()
}
// ToParams
func (o *CreateOptions) 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
}
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()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
switch typ.Kind() {
case reflect.String:
s, ok := slice.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
}

View File

@ -0,0 +1,88 @@
package volumes
import (
"net/url"
"reflect"
"strconv"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
/*
This file is generated automatically by go generate. Do not edit.
Created 2020-12-16 11:59:25.697109241 -0600 CST m=+0.000142064
*/
// Changed
func (o *InspectOptions) Changed(fieldName string) bool {
r := reflect.ValueOf(o)
value := reflect.Indirect(r).FieldByName(fieldName)
return !value.IsNil()
}
// ToParams
func (o *InspectOptions) 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
}
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()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
switch typ.Kind() {
case reflect.String:
s, ok := slice.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
}

View File

@ -0,0 +1,104 @@
package volumes
import (
"net/url"
"reflect"
"strconv"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
/*
This file is generated automatically by go generate. Do not edit.
Created 2020-12-16 11:59:25.835646604 -0600 CST m=+0.000141801
*/
// Changed
func (o *ListOptions) Changed(fieldName string) bool {
r := reflect.ValueOf(o)
value := reflect.Indirect(r).FieldByName(fieldName)
return !value.IsNil()
}
// ToParams
func (o *ListOptions) 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
}
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()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
switch typ.Kind() {
case reflect.String:
s, ok := slice.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
}
// WithFilters
func (o *ListOptions) WithFilters(value map[string][]string) *ListOptions {
v := value
o.Filters = v
return o
}
// GetFilters
func (o *ListOptions) GetFilters() map[string][]string {
var filters map[string][]string
if o.Filters == nil {
return filters
}
return o.Filters
}

View File

@ -0,0 +1,104 @@
package volumes
import (
"net/url"
"reflect"
"strconv"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
/*
This file is generated automatically by go generate. Do not edit.
Created 2020-12-16 11:59:25.972202545 -0600 CST m=+0.000209541
*/
// Changed
func (o *PruneOptions) Changed(fieldName string) bool {
r := reflect.ValueOf(o)
value := reflect.Indirect(r).FieldByName(fieldName)
return !value.IsNil()
}
// ToParams
func (o *PruneOptions) 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
}
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()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
switch typ.Kind() {
case reflect.String:
s, ok := slice.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
}
// WithFilters
func (o *PruneOptions) WithFilters(value map[string][]string) *PruneOptions {
v := value
o.Filters = v
return o
}
// GetFilters
func (o *PruneOptions) GetFilters() map[string][]string {
var filters map[string][]string
if o.Filters == nil {
return filters
}
return o.Filters
}

View File

@ -0,0 +1,104 @@
package volumes
import (
"net/url"
"reflect"
"strconv"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
/*
This file is generated automatically by go generate. Do not edit.
Created 2020-12-16 11:59:26.109834902 -0600 CST m=+0.000175439
*/
// Changed
func (o *RemoveOptions) Changed(fieldName string) bool {
r := reflect.ValueOf(o)
value := reflect.Indirect(r).FieldByName(fieldName)
return !value.IsNil()
}
// ToParams
func (o *RemoveOptions) 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
}
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()
slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap())
switch typ.Kind() {
case reflect.String:
s, ok := slice.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
}
// WithForce
func (o *RemoveOptions) WithForce(value bool) *RemoveOptions {
v := &value
o.Force = v
return o
}
// GetForce
func (o *RemoveOptions) GetForce() bool {
var force bool
if o.Force == nil {
return force
}
return *o.Force
}

View File

@ -3,8 +3,6 @@ package volumes
import ( import (
"context" "context"
"net/http" "net/http"
"net/url"
"strconv"
"strings" "strings"
"github.com/containers/podman/v2/pkg/bindings" "github.com/containers/podman/v2/pkg/bindings"
@ -13,10 +11,14 @@ import (
) )
// Create creates a volume given its configuration. // Create creates a volume given its configuration.
func Create(ctx context.Context, config entities.VolumeCreateOptions) (*entities.VolumeConfigResponse, error) { func Create(ctx context.Context, config entities.VolumeCreateOptions, options *CreateOptions) (*entities.VolumeConfigResponse, error) {
var ( var (
v entities.VolumeConfigResponse v entities.VolumeConfigResponse
) )
if options == nil {
options = new(CreateOptions)
}
_ = options
conn, err := bindings.GetClient(ctx) conn, err := bindings.GetClient(ctx)
if err != nil { if err != nil {
return nil, err return nil, err
@ -34,10 +36,14 @@ func Create(ctx context.Context, config entities.VolumeCreateOptions) (*entities
} }
// Inspect returns low-level information about a volume. // Inspect returns low-level information about a volume.
func Inspect(ctx context.Context, nameOrID string) (*entities.VolumeConfigResponse, error) { func Inspect(ctx context.Context, nameOrID string, options *InspectOptions) (*entities.VolumeConfigResponse, error) {
var ( var (
inspect entities.VolumeConfigResponse inspect entities.VolumeConfigResponse
) )
if options == nil {
options = new(InspectOptions)
}
_ = options
conn, err := bindings.GetClient(ctx) conn, err := bindings.GetClient(ctx)
if err != nil { if err != nil {
return nil, err return nil, err
@ -51,7 +57,7 @@ func Inspect(ctx context.Context, nameOrID string) (*entities.VolumeConfigRespon
// List returns the configurations for existing volumes in the form of a slice. Optionally, filters // List returns the configurations for existing volumes in the form of a slice. Optionally, filters
// can be used to refine the list of volumes. // can be used to refine the list of volumes.
func List(ctx context.Context, filters map[string][]string) ([]*entities.VolumeListReport, error) { func List(ctx context.Context, options *ListOptions) ([]*entities.VolumeListReport, error) {
var ( var (
vols []*entities.VolumeListReport vols []*entities.VolumeListReport
) )
@ -59,13 +65,9 @@ func List(ctx context.Context, filters map[string][]string) ([]*entities.VolumeL
if err != nil { if err != nil {
return nil, err return nil, err
} }
params := url.Values{} params, err := options.ToParams()
if len(filters) > 0 { if err != nil {
strFilters, err := bindings.FiltersToString(filters) return nil, err
if err != nil {
return nil, err
}
params.Set("filters", strFilters)
} }
response, err := conn.DoRequest(nil, http.MethodGet, "/volumes/json", params, nil) response, err := conn.DoRequest(nil, http.MethodGet, "/volumes/json", params, nil)
if err != nil { if err != nil {
@ -75,7 +77,7 @@ func List(ctx context.Context, filters map[string][]string) ([]*entities.VolumeL
} }
// Prune removes unused volumes from the local filesystem. // Prune removes unused volumes from the local filesystem.
func Prune(ctx context.Context, filters map[string][]string) ([]*entities.VolumePruneReport, error) { func Prune(ctx context.Context, options *PruneOptions) ([]*entities.VolumePruneReport, error) {
var ( var (
pruned []*entities.VolumePruneReport pruned []*entities.VolumePruneReport
) )
@ -83,13 +85,9 @@ func Prune(ctx context.Context, filters map[string][]string) ([]*entities.Volume
if err != nil { if err != nil {
return nil, err return nil, err
} }
params := url.Values{} params, err := options.ToParams()
if len(filters) > 0 { if err != nil {
strFilters, err := bindings.FiltersToString(filters) return nil, err
if err != nil {
return nil, err
}
params.Set("filters", strFilters)
} }
response, err := conn.DoRequest(nil, http.MethodPost, "/volumes/prune", params, nil) response, err := conn.DoRequest(nil, http.MethodPost, "/volumes/prune", params, nil)
if err != nil { if err != nil {
@ -100,14 +98,14 @@ func Prune(ctx context.Context, filters map[string][]string) ([]*entities.Volume
// Remove deletes the given volume from storage. The optional force parameter // Remove deletes the given volume from storage. The optional force parameter
// is used to remove a volume even if it is being used by a container. // is used to remove a volume even if it is being used by a container.
func Remove(ctx context.Context, nameOrID string, force *bool) error { func Remove(ctx context.Context, nameOrID string, options *RemoveOptions) error {
conn, err := bindings.GetClient(ctx) conn, err := bindings.GetClient(ctx)
if err != nil { if err != nil {
return err return err
} }
params := url.Values{} params, err := options.ToParams()
if force != nil { if err != nil {
params.Set("force", strconv.FormatBool(*force)) return err
} }
response, err := conn.DoRequest(nil, http.MethodDelete, "/volumes/%s", params, nil, nameOrID) response, err := conn.DoRequest(nil, http.MethodDelete, "/volumes/%s", params, nil, nameOrID)
if err != nil { if err != nil {

View File

@ -35,6 +35,6 @@ type ImageEngine interface {
ManifestAdd(ctx context.Context, opts ManifestAddOptions) (string, error) ManifestAdd(ctx context.Context, opts ManifestAddOptions) (string, error)
ManifestAnnotate(ctx context.Context, names []string, opts ManifestAnnotateOptions) (string, error) ManifestAnnotate(ctx context.Context, names []string, opts ManifestAnnotateOptions) (string, error)
ManifestRemove(ctx context.Context, names []string) (string, error) ManifestRemove(ctx context.Context, names []string) (string, error)
ManifestPush(ctx context.Context, names []string, manifestPushOpts ManifestPushOptions) error ManifestPush(ctx context.Context, name, destination string, manifestPushOpts ManifestPushOptions) error
Sign(ctx context.Context, names []string, options SignOptions) (*SignReport, error) Sign(ctx context.Context, names []string, options SignOptions) (*SignReport, error)
} }

View File

@ -19,7 +19,7 @@ type ServiceOptions struct {
type SystemPruneOptions struct { type SystemPruneOptions struct {
All bool All bool
Volume bool Volume bool
Filter []string ContainerPruneOptions
} }
// SystemPruneReport provides report after system prune is executed. // SystemPruneReport provides report after system prune is executed.

View File

@ -244,15 +244,16 @@ func (ir *ImageEngine) ManifestRemove(ctx context.Context, names []string) (stri
} }
// ManifestPush pushes a manifest list or image index to the destination // ManifestPush pushes a manifest list or image index to the destination
func (ir *ImageEngine) ManifestPush(ctx context.Context, names []string, opts entities.ManifestPushOptions) error { func (ir *ImageEngine) ManifestPush(ctx context.Context, name, destination string, opts entities.ManifestPushOptions) error {
listImage, err := ir.Libpod.ImageRuntime().NewFromLocal(names[0]) listImage, err := ir.Libpod.ImageRuntime().NewFromLocal(name)
if err != nil { if err != nil {
return errors.Wrapf(err, "error retrieving local image from image name %s", names[0]) return errors.Wrapf(err, "error retrieving local image from image name %s", name)
} }
dest, err := alltransports.ParseImageName(names[1]) dest, err := alltransports.ParseImageName(destination)
if err != nil { if err != nil {
return err return err
} }
var manifestType string var manifestType string
if opts.Format != "" { if opts.Format != "" {
switch opts.Format { switch opts.Format {
@ -267,8 +268,8 @@ func (ir *ImageEngine) ManifestPush(ctx context.Context, names []string, opts en
// Set the system context. // Set the system context.
sys := ir.Libpod.SystemContext() sys := ir.Libpod.SystemContext()
if sys != nil { if sys == nil {
sys = &types.SystemContext{} sys = new(types.SystemContext)
} }
sys.AuthFilePath = opts.Authfile sys.AuthFilePath = opts.Authfile
sys.DockerInsecureSkipTLSVerify = opts.SkipTLSVerify sys.DockerInsecureSkipTLSVerify = opts.SkipTLSVerify
@ -296,12 +297,12 @@ func (ir *ImageEngine) ManifestPush(ctx context.Context, names []string, opts en
if !opts.Quiet { if !opts.Quiet {
options.ReportWriter = os.Stderr options.ReportWriter = os.Stderr
} }
digest, err := listImage.PushManifest(dest, options) manDigest, err := listImage.PushManifest(dest, options)
if err == nil && opts.Purge { if err == nil && opts.Purge {
_, err = ir.Libpod.GetStore().DeleteImage(listImage.ID(), true) _, err = ir.Libpod.GetStore().DeleteImage(listImage.ID(), true)
} }
if opts.DigestFile != "" { if opts.DigestFile != "" {
if err = ioutil.WriteFile(opts.DigestFile, []byte(digest.String()), 0644); err != nil { if err = ioutil.WriteFile(opts.DigestFile, []byte(manDigest.String()), 0644); err != nil {
return buildahUtil.GetFailureCause(err, errors.Wrapf(err, "failed to write digest to file %q", opts.DigestFile)) return buildahUtil.GetFailureCause(err, errors.Wrapf(err, "failed to write digest to file %q", opts.DigestFile))
} }
} }

View File

@ -4,7 +4,6 @@ import (
"context" "context"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/url"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -169,6 +168,7 @@ func checkInput() error { // nolint:deadcode,unused
// SystemPrune removes unused data from the system. Pruning pods, containers, volumes and images. // SystemPrune removes unused data from the system. Pruning pods, containers, volumes and images.
func (ic *ContainerEngine) SystemPrune(ctx context.Context, options entities.SystemPruneOptions) (*entities.SystemPruneReport, error) { func (ic *ContainerEngine) SystemPrune(ctx context.Context, options entities.SystemPruneOptions) (*entities.SystemPruneReport, error) {
var systemPruneReport = new(entities.SystemPruneReport) var systemPruneReport = new(entities.SystemPruneReport)
var filters []string
found := true found := true
for found { for found {
found = false found = false
@ -180,16 +180,7 @@ func (ic *ContainerEngine) SystemPrune(ctx context.Context, options entities.Sys
found = true found = true
} }
systemPruneReport.PodPruneReport = append(systemPruneReport.PodPruneReport, podPruneReport...) systemPruneReport.PodPruneReport = append(systemPruneReport.PodPruneReport, podPruneReport...)
containerPruneOptions := entities.ContainerPruneOptions{} containerPruneReport, err := ic.ContainerPrune(ctx, options.ContainerPruneOptions)
for _, f := range options.Filter {
t := strings.SplitN(f, "=", 2)
containerPruneOptions.Filters = make(url.Values)
if len(t) < 2 {
return nil, errors.Errorf("filter input must be in the form of filter=value: %s is invalid", f)
}
containerPruneOptions.Filters.Add(t[0], t[1])
}
containerPruneReport, err := ic.ContainerPrune(ctx, containerPruneOptions)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -203,8 +194,10 @@ func (ic *ContainerEngine) SystemPrune(ctx context.Context, options entities.Sys
systemPruneReport.ContainerPruneReport.ID[name] = val systemPruneReport.ContainerPruneReport.ID[name] = val
} }
} }
for k, v := range options.Filters {
results, err := ic.Libpod.ImageRuntime().PruneImages(ctx, options.All, options.Filter) filters = append(filters, fmt.Sprintf("%s=%s", k, v[0]))
}
results, err := ic.Libpod.ImageRuntime().PruneImages(ctx, options.All, filters)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -2,7 +2,6 @@ package tunnel
import ( import (
"context" "context"
// "fmt"
"strings" "strings"
"github.com/containers/podman/v2/libpod/events" "github.com/containers/podman/v2/libpod/events"
@ -29,7 +28,8 @@ func (ic *ContainerEngine) Events(ctx context.Context, opts entities.EventsOptio
} }
close(opts.EventChan) close(opts.EventChan)
}() }()
return system.Events(ic.ClientCxt, binChan, nil, &opts.Since, &opts.Until, filters, &opts.Stream) options := new(system.EventsOptions).WithFilters(filters).WithSince(opts.Since).WithStream(opts.Stream).WithUntil(opts.Until)
return system.Events(ic.ClientCxt, binChan, nil, options)
} }
// GetLastContainerEvent takes a container name or ID and an event status and returns // GetLastContainerEvent takes a container name or ID and an event status and returns

View File

@ -7,10 +7,16 @@ import (
"github.com/containers/podman/v2/pkg/domain/entities" "github.com/containers/podman/v2/pkg/domain/entities"
) )
func (ic *ContainerEngine) GenerateSystemd(ctx context.Context, nameOrID string, options entities.GenerateSystemdOptions) (*entities.GenerateSystemdReport, error) { func (ic *ContainerEngine) GenerateSystemd(ctx context.Context, nameOrID string, opts entities.GenerateSystemdOptions) (*entities.GenerateSystemdReport, error) {
options := new(generate.SystemdOptions).WithUseName(opts.Name).WithContainerPrefix(opts.ContainerPrefix).WithNew(opts.New)
options.WithPodPrefix(opts.PodPrefix).WithRestartPolicy(opts.RestartPolicy).WithSeparator(opts.Separator)
if to := opts.StopTimeout; to != nil {
options.WithStopTimeout(*opts.StopTimeout)
}
return generate.Systemd(ic.ClientCxt, nameOrID, options) return generate.Systemd(ic.ClientCxt, nameOrID, options)
} }
func (ic *ContainerEngine) GenerateKube(ctx context.Context, nameOrIDs []string, options entities.GenerateKubeOptions) (*entities.GenerateKubeReport, error) { func (ic *ContainerEngine) GenerateKube(ctx context.Context, nameOrIDs []string, opts entities.GenerateKubeOptions) (*entities.GenerateKubeReport, error) {
options := new(generate.KubeOptions).WithService(opts.Service)
return generate.Kube(ic.ClientCxt, nameOrIDs, options) return generate.Kube(ic.ClientCxt, nameOrIDs, options)
} }

View File

@ -6,7 +6,6 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/containers/podman/v2/libpod/image"
"github.com/containers/podman/v2/pkg/bindings/manifests" "github.com/containers/podman/v2/pkg/bindings/manifests"
"github.com/containers/podman/v2/pkg/domain/entities" "github.com/containers/podman/v2/pkg/domain/entities"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -14,7 +13,8 @@ import (
// ManifestCreate implements manifest create via ImageEngine // ManifestCreate implements manifest create via ImageEngine
func (ir *ImageEngine) ManifestCreate(ctx context.Context, names, images []string, opts entities.ManifestCreateOptions) (string, error) { func (ir *ImageEngine) ManifestCreate(ctx context.Context, names, images []string, opts entities.ManifestCreateOptions) (string, error) {
imageID, err := manifests.Create(ir.ClientCxt, names, images, &opts.All) options := new(manifests.CreateOptions).WithAll(opts.All)
imageID, err := manifests.Create(ir.ClientCxt, names, images, options)
if err != nil { if err != nil {
return imageID, errors.Wrapf(err, "error creating manifest") return imageID, errors.Wrapf(err, "error creating manifest")
} }
@ -23,7 +23,7 @@ func (ir *ImageEngine) ManifestCreate(ctx context.Context, names, images []strin
// ManifestInspect returns contents of manifest list with given name // ManifestInspect returns contents of manifest list with given name
func (ir *ImageEngine) ManifestInspect(ctx context.Context, name string) ([]byte, error) { func (ir *ImageEngine) ManifestInspect(ctx context.Context, name string) ([]byte, error) {
list, err := manifests.Inspect(ir.ClientCxt, name) list, err := manifests.Inspect(ir.ClientCxt, name, nil)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "error getting content of manifest list or image %s", name) return nil, errors.Wrapf(err, "error getting content of manifest list or image %s", name)
} }
@ -37,15 +37,8 @@ func (ir *ImageEngine) ManifestInspect(ctx context.Context, name string) ([]byte
// ManifestAdd adds images to the manifest list // ManifestAdd adds images to the manifest list
func (ir *ImageEngine) ManifestAdd(ctx context.Context, opts entities.ManifestAddOptions) (string, error) { func (ir *ImageEngine) ManifestAdd(ctx context.Context, opts entities.ManifestAddOptions) (string, error) {
manifestAddOpts := image.ManifestAddOpts{ options := new(manifests.AddOptions).WithAll(opts.All).WithArch(opts.Arch).WithVariant(opts.Variant)
All: opts.All, options.WithFeatures(opts.Features).WithImages(opts.Images).WithOS(opts.OS).WithOSVersion(opts.OSVersion)
Arch: opts.Arch,
Features: opts.Features,
Images: opts.Images,
OS: opts.OS,
OSVersion: opts.OSVersion,
Variant: opts.Variant,
}
if len(opts.Annotation) != 0 { if len(opts.Annotation) != 0 {
annotations := make(map[string]string) annotations := make(map[string]string)
for _, annotationSpec := range opts.Annotation { for _, annotationSpec := range opts.Annotation {
@ -55,9 +48,10 @@ func (ir *ImageEngine) ManifestAdd(ctx context.Context, opts entities.ManifestAd
} }
annotations[spec[0]] = spec[1] annotations[spec[0]] = spec[1]
} }
manifestAddOpts.Annotation = annotations options.WithAnnotation(annotations)
} }
listID, err := manifests.Add(ir.ClientCxt, opts.Images[1], manifestAddOpts)
listID, err := manifests.Add(ir.ClientCxt, opts.Images[1], options)
if err != nil { if err != nil {
return listID, errors.Wrapf(err, "error adding to manifest list %s", opts.Images[1]) return listID, errors.Wrapf(err, "error adding to manifest list %s", opts.Images[1])
} }
@ -71,7 +65,7 @@ func (ir *ImageEngine) ManifestAnnotate(ctx context.Context, names []string, opt
// ManifestRemove removes the digest from manifest list // ManifestRemove removes the digest from manifest list
func (ir *ImageEngine) ManifestRemove(ctx context.Context, names []string) (string, error) { func (ir *ImageEngine) ManifestRemove(ctx context.Context, names []string) (string, error) {
updatedListID, err := manifests.Remove(ir.ClientCxt, names[0], names[1]) updatedListID, err := manifests.Remove(ir.ClientCxt, names[0], names[1], nil)
if err != nil { if err != nil {
return updatedListID, errors.Wrapf(err, "error removing from manifest %s", names[0]) return updatedListID, errors.Wrapf(err, "error removing from manifest %s", names[0])
} }
@ -79,7 +73,8 @@ func (ir *ImageEngine) ManifestRemove(ctx context.Context, names []string) (stri
} }
// ManifestPush pushes a manifest list or image index to the destination // ManifestPush pushes a manifest list or image index to the destination
func (ir *ImageEngine) ManifestPush(ctx context.Context, names []string, opts entities.ManifestPushOptions) error { func (ir *ImageEngine) ManifestPush(ctx context.Context, name, destination string, opts entities.ManifestPushOptions) error {
_, err := manifests.Push(ir.ClientCxt, names[0], &names[1], &opts.All) options := new(manifests.PushOptions).WithAll(opts.All)
_, err := manifests.Push(ir.ClientCxt, name, destination, options)
return err return err
} }

View File

@ -8,17 +8,19 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
) )
func (ic *ContainerEngine) NetworkList(ctx context.Context, options entities.NetworkListOptions) ([]*entities.NetworkListReport, error) { func (ic *ContainerEngine) NetworkList(ctx context.Context, opts entities.NetworkListOptions) ([]*entities.NetworkListReport, error) {
options := new(network.ListOptions).WithFilters(opts.Filters)
return network.List(ic.ClientCxt, options) return network.List(ic.ClientCxt, options)
} }
func (ic *ContainerEngine) NetworkInspect(ctx context.Context, namesOrIds []string, options entities.InspectOptions) ([]entities.NetworkInspectReport, []error, error) { func (ic *ContainerEngine) NetworkInspect(ctx context.Context, namesOrIds []string, opts entities.InspectOptions) ([]entities.NetworkInspectReport, []error, error) {
var ( var (
reports = make([]entities.NetworkInspectReport, 0, len(namesOrIds)) reports = make([]entities.NetworkInspectReport, 0, len(namesOrIds))
errs = []error{} errs = []error{}
) )
options := new(network.InspectOptions)
for _, name := range namesOrIds { for _, name := range namesOrIds {
report, err := network.Inspect(ic.ClientCxt, name) report, err := network.Inspect(ic.ClientCxt, name, options)
if err != nil { if err != nil {
errModel, ok := err.(entities.ErrorModel) errModel, ok := err.(entities.ErrorModel)
if !ok { if !ok {
@ -35,14 +37,15 @@ func (ic *ContainerEngine) NetworkInspect(ctx context.Context, namesOrIds []stri
return reports, errs, nil return reports, errs, nil
} }
func (ic *ContainerEngine) NetworkReload(ctx context.Context, names []string, options entities.NetworkReloadOptions) ([]*entities.NetworkReloadReport, error) { func (ic *ContainerEngine) NetworkReload(ctx context.Context, names []string, opts entities.NetworkReloadOptions) ([]*entities.NetworkReloadReport, error) {
return nil, errors.New("not implemented") return nil, errors.New("not implemented")
} }
func (ic *ContainerEngine) NetworkRm(ctx context.Context, namesOrIds []string, options entities.NetworkRmOptions) ([]*entities.NetworkRmReport, error) { func (ic *ContainerEngine) NetworkRm(ctx context.Context, namesOrIds []string, opts entities.NetworkRmOptions) ([]*entities.NetworkRmReport, error) {
reports := make([]*entities.NetworkRmReport, 0, len(namesOrIds)) reports := make([]*entities.NetworkRmReport, 0, len(namesOrIds))
options := new(network.RemoveOptions).WithForce(opts.Force)
for _, name := range namesOrIds { for _, name := range namesOrIds {
response, err := network.Remove(ic.ClientCxt, name, &options.Force) response, err := network.Remove(ic.ClientCxt, name, options)
if err != nil { if err != nil {
report := &entities.NetworkRmReport{ report := &entities.NetworkRmReport{
Name: name, Name: name,
@ -56,16 +59,21 @@ func (ic *ContainerEngine) NetworkRm(ctx context.Context, namesOrIds []string, o
return reports, nil return reports, nil
} }
func (ic *ContainerEngine) NetworkCreate(ctx context.Context, name string, options entities.NetworkCreateOptions) (*entities.NetworkCreateReport, error) { func (ic *ContainerEngine) NetworkCreate(ctx context.Context, name string, opts entities.NetworkCreateOptions) (*entities.NetworkCreateReport, error) {
return network.Create(ic.ClientCxt, options, &name) options := new(network.CreateOptions).WithName(name).WithDisableDNS(opts.DisableDNS).WithDriver(opts.Driver).WithGateway(opts.Gateway)
options.WithInternal(opts.Internal).WithIPRange(opts.Range).WithIPv6(opts.IPv6).WithLabels(opts.Labels).WithIPv6(opts.IPv6)
options.WithMacVLAN(opts.MacVLAN).WithOptions(opts.Options).WithSubnet(opts.Subnet)
return network.Create(ic.ClientCxt, options)
} }
// NetworkDisconnect removes a container from a given network // NetworkDisconnect removes a container from a given network
func (ic *ContainerEngine) NetworkDisconnect(ctx context.Context, networkname string, options entities.NetworkDisconnectOptions) error { func (ic *ContainerEngine) NetworkDisconnect(ctx context.Context, networkname string, opts entities.NetworkDisconnectOptions) error {
return network.Disconnect(ic.ClientCxt, networkname, options) options := new(network.DisconnectOptions).WithForce(opts.Force)
return network.Disconnect(ic.ClientCxt, networkname, opts.Container, options)
} }
// NetworkConnect removes a container from a given network // NetworkConnect removes a container from a given network
func (ic *ContainerEngine) NetworkConnect(ctx context.Context, networkname string, options entities.NetworkConnectOptions) error { func (ic *ContainerEngine) NetworkConnect(ctx context.Context, networkname string, opts entities.NetworkConnectOptions) error {
return network.Connect(ic.ClientCxt, networkname, options) options := new(network.ConnectOptions).WithAliases(opts.Aliases)
return network.Connect(ic.ClientCxt, networkname, opts.Container, options)
} }

View File

@ -3,10 +3,21 @@ package tunnel
import ( import (
"context" "context"
"github.com/containers/image/v5/types"
"github.com/containers/podman/v2/pkg/bindings/play" "github.com/containers/podman/v2/pkg/bindings/play"
"github.com/containers/podman/v2/pkg/domain/entities" "github.com/containers/podman/v2/pkg/domain/entities"
) )
func (ic *ContainerEngine) PlayKube(ctx context.Context, path string, options entities.PlayKubeOptions) (*entities.PlayKubeReport, error) { func (ic *ContainerEngine) PlayKube(ctx context.Context, path string, opts entities.PlayKubeOptions) (*entities.PlayKubeReport, error) {
options := new(play.KubeOptions).WithAuthfile(opts.Authfile).WithUsername(opts.Username).WithPassword(opts.Password)
options.WithCertDir(opts.CertDir).WithQuiet(opts.Quiet).WithSignaturePolicy(opts.SignaturePolicy).WithConfigMaps(opts.ConfigMaps)
options.WithLogDriver(opts.LogDriver).WithNetwork(opts.Network).WithSeccompProfileRoot(opts.SeccompProfileRoot)
if s := opts.SkipTLSVerify; s != types.OptionalBoolUndefined {
options.WithSkipTLSVerify(s == types.OptionalBoolTrue)
}
if start := opts.Start; start != types.OptionalBoolUndefined {
options.WithStart(start == types.OptionalBoolTrue)
}
return play.Kube(ic.ClientCxt, path, options) return play.Kube(ic.ClientCxt, path, options)
} }

View File

@ -11,7 +11,7 @@ import (
) )
func (ic *ContainerEngine) Info(ctx context.Context) (*define.Info, error) { func (ic *ContainerEngine) Info(ctx context.Context) (*define.Info, error) {
return system.Info(ic.ClientCxt) return system.Info(ic.ClientCxt, nil)
} }
func (ic *ContainerEngine) SetupRootless(_ context.Context, cmd *cobra.Command) error { func (ic *ContainerEngine) SetupRootless(_ context.Context, cmd *cobra.Command) error {
@ -19,12 +19,13 @@ func (ic *ContainerEngine) SetupRootless(_ context.Context, cmd *cobra.Command)
} }
// SystemPrune prunes unused data from the system. // SystemPrune prunes unused data from the system.
func (ic *ContainerEngine) SystemPrune(ctx context.Context, options entities.SystemPruneOptions) (*entities.SystemPruneReport, error) { func (ic *ContainerEngine) SystemPrune(ctx context.Context, opts entities.SystemPruneOptions) (*entities.SystemPruneReport, error) {
return system.Prune(ic.ClientCxt, &options.All, &options.Volume) options := new(system.PruneOptions).WithAll(opts.All).WithVolumes(opts.Volume).WithFilters(opts.ContainerPruneOptions.Filters)
return system.Prune(ic.ClientCxt, options)
} }
func (ic *ContainerEngine) SystemDf(ctx context.Context, options entities.SystemDfOptions) (*entities.SystemDfReport, error) { func (ic *ContainerEngine) SystemDf(ctx context.Context, options entities.SystemDfOptions) (*entities.SystemDfReport, error) {
return system.DiskUsage(ic.ClientCxt) return system.DiskUsage(ic.ClientCxt, nil)
} }
func (ic *ContainerEngine) Unshare(ctx context.Context, args []string) error { func (ic *ContainerEngine) Unshare(ctx context.Context, args []string) error {
@ -32,5 +33,5 @@ func (ic *ContainerEngine) Unshare(ctx context.Context, args []string) error {
} }
func (ic ContainerEngine) Version(ctx context.Context) (*entities.SystemVersionReport, error) { func (ic ContainerEngine) Version(ctx context.Context) (*entities.SystemVersionReport, error) {
return system.Version(ic.ClientCxt) return system.Version(ic.ClientCxt, nil)
} }

View File

@ -9,7 +9,7 @@ import (
) )
func (ic *ContainerEngine) VolumeCreate(ctx context.Context, opts entities.VolumeCreateOptions) (*entities.IDOrNameResponse, error) { func (ic *ContainerEngine) VolumeCreate(ctx context.Context, opts entities.VolumeCreateOptions) (*entities.IDOrNameResponse, error) {
response, err := volumes.Create(ic.ClientCxt, opts) response, err := volumes.Create(ic.ClientCxt, opts, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -28,8 +28,9 @@ func (ic *ContainerEngine) VolumeRm(ctx context.Context, namesOrIds []string, op
} }
reports := make([]*entities.VolumeRmReport, 0, len(namesOrIds)) reports := make([]*entities.VolumeRmReport, 0, len(namesOrIds))
for _, id := range namesOrIds { for _, id := range namesOrIds {
options := new(volumes.RemoveOptions).WithForce(opts.Force)
reports = append(reports, &entities.VolumeRmReport{ reports = append(reports, &entities.VolumeRmReport{
Err: volumes.Remove(ic.ClientCxt, id, &opts.Force), Err: volumes.Remove(ic.ClientCxt, id, options),
Id: id, Id: id,
}) })
} }
@ -51,7 +52,7 @@ func (ic *ContainerEngine) VolumeInspect(ctx context.Context, namesOrIds []strin
} }
} }
for _, id := range namesOrIds { for _, id := range namesOrIds {
data, err := volumes.Inspect(ic.ClientCxt, id) data, err := volumes.Inspect(ic.ClientCxt, id, nil)
if err != nil { if err != nil {
errModel, ok := err.(entities.ErrorModel) errModel, ok := err.(entities.ErrorModel)
if !ok { if !ok {
@ -69,9 +70,11 @@ func (ic *ContainerEngine) VolumeInspect(ctx context.Context, namesOrIds []strin
} }
func (ic *ContainerEngine) VolumePrune(ctx context.Context, opts entities.VolumePruneOptions) ([]*entities.VolumePruneReport, error) { func (ic *ContainerEngine) VolumePrune(ctx context.Context, opts entities.VolumePruneOptions) ([]*entities.VolumePruneReport, error) {
return volumes.Prune(ic.ClientCxt, (map[string][]string)(opts.Filters)) options := new(volumes.PruneOptions).WithFilters(opts.Filters)
return volumes.Prune(ic.ClientCxt, options)
} }
func (ic *ContainerEngine) VolumeList(ctx context.Context, opts entities.VolumeListOptions) ([]*entities.VolumeListReport, error) { func (ic *ContainerEngine) VolumeList(ctx context.Context, opts entities.VolumeListOptions) ([]*entities.VolumeListReport, error) {
return volumes.List(ic.ClientCxt, opts.Filter) options := new(volumes.ListOptions).WithFilters(opts.Filter)
return volumes.List(ic.ClientCxt, options)
} }