summaryrefslogtreecommitdiff
path: root/pkg/bindings
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/bindings')
-rw-r--r--pkg/bindings/containers/containers.go31
-rw-r--r--pkg/bindings/containers/types.go4
-rw-r--r--pkg/bindings/containers/types_kill_options.go16
-rw-r--r--pkg/bindings/containers/types_remove_options.go16
-rw-r--r--pkg/bindings/containers/types_stop_options.go16
-rw-r--r--pkg/bindings/containers/types_wait_options.go16
-rw-r--r--pkg/bindings/test/containers_test.go12
7 files changed, 67 insertions, 44 deletions
diff --git a/pkg/bindings/containers/containers.go b/pkg/bindings/containers/containers.go
index 40fcfbded..8e644b712 100644
--- a/pkg/bindings/containers/containers.go
+++ b/pkg/bindings/containers/containers.go
@@ -5,7 +5,6 @@ import (
"io"
"net/http"
"net/url"
- "strconv"
"strings"
"github.com/containers/podman/v2/libpod/define"
@@ -83,18 +82,9 @@ func Remove(ctx context.Context, nameOrID string, options *RemoveOptions) error
if err != nil {
return err
}
- params := url.Values{}
- if v := options.GetVolumes(); options.Changed("Volumes") {
- params.Set("v", strconv.FormatBool(v))
- }
- if all := options.GetAll(); options.Changed("All") {
- params.Set("all", strconv.FormatBool(all))
- }
- if force := options.GetForce(); options.Changed("Force") {
- params.Set("force", strconv.FormatBool(force))
- }
- if ignore := options.GetIgnore(); options.Changed("Ignore") {
- params.Set("ignore", strconv.FormatBool(ignore))
+ params, err := options.ToParams()
+ if err != nil {
+ return err
}
response, err := conn.DoRequest(nil, http.MethodDelete, "/containers/%s", params, nil, nameOrID)
if err != nil {
@@ -130,7 +120,7 @@ func Inspect(ctx context.Context, nameOrID string, options *InspectOptions) (*de
// Kill sends a given signal to a given container. The signal should be the string
// representation of a signal like 'SIGKILL'. The nameOrID can be a container name
// or a partial/full ID
-func Kill(ctx context.Context, nameOrID string, sig string, options *KillOptions) error {
+func Kill(ctx context.Context, nameOrID string, options *KillOptions) error {
if options == nil {
options = new(KillOptions)
}
@@ -142,7 +132,6 @@ func Kill(ctx context.Context, nameOrID string, sig string, options *KillOptions
if err != nil {
return err
}
- params.Set("signal", sig)
response, err := conn.DoRequest(nil, http.MethodPost, "/containers/%s/kill", params, nil, nameOrID)
if err != nil {
return err
@@ -180,9 +169,9 @@ func Restart(ctx context.Context, nameOrID string, options *RestartOptions) erro
if err != nil {
return err
}
- params := url.Values{}
- if options.Changed("Timeout") {
- params.Set("t", strconv.Itoa(options.GetTimeout()))
+ params, err := options.ToParams()
+ if err != nil {
+ return err
}
response, err := conn.DoRequest(nil, http.MethodPost, "/containers/%s/restart", params, nil, nameOrID)
if err != nil {
@@ -335,9 +324,9 @@ func Wait(ctx context.Context, nameOrID string, options *WaitOptions) (int32, er
if err != nil {
return exitCode, err
}
- params := url.Values{}
- if options.Changed("Condition") {
- params.Set("condition", options.GetCondition().String())
+ params, err := options.ToParams()
+ if err != nil {
+ return exitCode, err
}
response, err := conn.DoRequest(nil, http.MethodPost, "/containers/%s/wait", params, nil, nameOrID)
if err != nil {
diff --git a/pkg/bindings/containers/types.go b/pkg/bindings/containers/types.go
index 3fb1ab733..771cde72c 100644
--- a/pkg/bindings/containers/types.go
+++ b/pkg/bindings/containers/types.go
@@ -123,7 +123,6 @@ type PruneOptions struct {
//go:generate go run ../generator/generator.go RemoveOptions
// RemoveOptions are optional options for removing containers
type RemoveOptions struct {
- All *bool
Ignore *bool
Force *bool
Volumes *bool
@@ -138,6 +137,7 @@ type InspectOptions struct {
//go:generate go run ../generator/generator.go KillOptions
// KillOptions are optional options for killing containers
type KillOptions struct {
+ Signal *string
}
//go:generate go run ../generator/generator.go PauseOptions
@@ -177,11 +177,13 @@ type UnpauseOptions struct{}
// WaitOptions are optional options for waiting on containers
type WaitOptions struct {
Condition *define.ContainerStatus
+ Interval *string
}
//go:generate go run ../generator/generator.go StopOptions
// StopOptions are optional options for stopping containers
type StopOptions struct {
+ Ignore *bool
Timeout *uint
}
diff --git a/pkg/bindings/containers/types_kill_options.go b/pkg/bindings/containers/types_kill_options.go
index dd84f0d9f..c5d5a3c6a 100644
--- a/pkg/bindings/containers/types_kill_options.go
+++ b/pkg/bindings/containers/types_kill_options.go
@@ -86,3 +86,19 @@ func (o *KillOptions) ToParams() (url.Values, error) {
}
return params, nil
}
+
+// WithSignal
+func (o *KillOptions) WithSignal(value string) *KillOptions {
+ v := &value
+ o.Signal = v
+ return o
+}
+
+// GetSignal
+func (o *KillOptions) GetSignal() string {
+ var signal string
+ if o.Signal == nil {
+ return signal
+ }
+ return *o.Signal
+}
diff --git a/pkg/bindings/containers/types_remove_options.go b/pkg/bindings/containers/types_remove_options.go
index 3ef32fa03..ffe1488c1 100644
--- a/pkg/bindings/containers/types_remove_options.go
+++ b/pkg/bindings/containers/types_remove_options.go
@@ -87,22 +87,6 @@ func (o *RemoveOptions) ToParams() (url.Values, error) {
return params, nil
}
-// WithAll
-func (o *RemoveOptions) WithAll(value bool) *RemoveOptions {
- v := &value
- o.All = v
- return o
-}
-
-// GetAll
-func (o *RemoveOptions) GetAll() bool {
- var all bool
- if o.All == nil {
- return all
- }
- return *o.All
-}
-
// WithIgnore
func (o *RemoveOptions) WithIgnore(value bool) *RemoveOptions {
v := &value
diff --git a/pkg/bindings/containers/types_stop_options.go b/pkg/bindings/containers/types_stop_options.go
index db692dbf0..940ec5832 100644
--- a/pkg/bindings/containers/types_stop_options.go
+++ b/pkg/bindings/containers/types_stop_options.go
@@ -87,6 +87,22 @@ func (o *StopOptions) ToParams() (url.Values, error) {
return params, nil
}
+// WithIgnore
+func (o *StopOptions) WithIgnore(value bool) *StopOptions {
+ v := &value
+ o.Ignore = v
+ return o
+}
+
+// GetIgnore
+func (o *StopOptions) GetIgnore() bool {
+ var ignore bool
+ if o.Ignore == nil {
+ return ignore
+ }
+ return *o.Ignore
+}
+
// WithTimeout
func (o *StopOptions) WithTimeout(value uint) *StopOptions {
v := &value
diff --git a/pkg/bindings/containers/types_wait_options.go b/pkg/bindings/containers/types_wait_options.go
index 470d67611..2f5aa983e 100644
--- a/pkg/bindings/containers/types_wait_options.go
+++ b/pkg/bindings/containers/types_wait_options.go
@@ -103,3 +103,19 @@ func (o *WaitOptions) GetCondition() define.ContainerStatus {
}
return *o.Condition
}
+
+// WithInterval
+func (o *WaitOptions) WithInterval(value string) *WaitOptions {
+ v := &value
+ o.Interval = v
+ return o
+}
+
+// GetInterval
+func (o *WaitOptions) GetInterval() string {
+ var interval string
+ if o.Interval == nil {
+ return interval
+ }
+ return *o.Interval
+}
diff --git a/pkg/bindings/test/containers_test.go b/pkg/bindings/test/containers_test.go
index 3d7526cb8..9b9f98047 100644
--- a/pkg/bindings/test/containers_test.go
+++ b/pkg/bindings/test/containers_test.go
@@ -443,7 +443,7 @@ var _ = Describe("Podman containers ", func() {
It("podman kill bogus container", func() {
// Killing bogus container should return 404
- err := containers.Kill(bt.conn, "foobar", "SIGTERM", nil)
+ err := containers.Kill(bt.conn, "foobar", new(containers.KillOptions).WithSignal("SIGTERM"))
Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound))
@@ -454,7 +454,7 @@ var _ = Describe("Podman containers ", func() {
var name = "top"
_, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
Expect(err).To(BeNil())
- err = containers.Kill(bt.conn, name, "SIGINT", nil)
+ err = containers.Kill(bt.conn, name, new(containers.KillOptions).WithSignal("SIGINT"))
Expect(err).To(BeNil())
_, err = containers.Exists(bt.conn, name, nil)
Expect(err).To(BeNil())
@@ -465,7 +465,7 @@ var _ = Describe("Podman containers ", func() {
var name = "top"
cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
Expect(err).To(BeNil())
- err = containers.Kill(bt.conn, cid, "SIGTERM", nil)
+ err = containers.Kill(bt.conn, cid, new(containers.KillOptions).WithSignal("SIGTERM"))
Expect(err).To(BeNil())
_, err = containers.Exists(bt.conn, cid, nil)
Expect(err).To(BeNil())
@@ -476,7 +476,7 @@ var _ = Describe("Podman containers ", func() {
var name = "top"
cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
Expect(err).To(BeNil())
- err = containers.Kill(bt.conn, cid, "SIGKILL", nil)
+ err = containers.Kill(bt.conn, cid, new(containers.KillOptions).WithSignal("SIGKILL"))
Expect(err).To(BeNil())
})
@@ -485,7 +485,7 @@ var _ = Describe("Podman containers ", func() {
var name = "top"
cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
Expect(err).To(BeNil())
- err = containers.Kill(bt.conn, cid, "foobar", nil)
+ err = containers.Kill(bt.conn, cid, new(containers.KillOptions).WithSignal("foobar"))
Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
@@ -501,7 +501,7 @@ var _ = Describe("Podman containers ", func() {
Expect(err).To(BeNil())
containerLatestList, err := containers.List(bt.conn, new(containers.ListOptions).WithLast(1))
Expect(err).To(BeNil())
- err = containers.Kill(bt.conn, containerLatestList[0].Names[0], "SIGTERM", nil)
+ err = containers.Kill(bt.conn, containerLatestList[0].Names[0], new(containers.KillOptions).WithSignal("SIGTERM"))
Expect(err).To(BeNil())
})