summaryrefslogtreecommitdiff
path: root/pkg/bindings/pods.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-01-10 21:28:05 +0100
committerGitHub <noreply@github.com>2020-01-10 21:28:05 +0100
commite1ffac6cc73eb36640cbaf6a1a28ba44749a96d9 (patch)
tree61134dad4b2efdaa65dee6e7206e5ce20080302c /pkg/bindings/pods.go
parent6ed88e047579bd2d1eac99a6089cc617f0c4773d (diff)
parent986feef2e80cfaed7cbce0df4fd5d619bcffefd7 (diff)
downloadpodman-e1ffac6cc73eb36640cbaf6a1a28ba44749a96d9.tar.gz
podman-e1ffac6cc73eb36640cbaf6a1a28ba44749a96d9.tar.bz2
podman-e1ffac6cc73eb36640cbaf6a1a28ba44749a96d9.zip
Merge pull request #4832 from baude/apiv2tomaster
Apiv2tomaster
Diffstat (limited to 'pkg/bindings/pods.go')
-rw-r--r--pkg/bindings/pods.go128
1 files changed, 128 insertions, 0 deletions
diff --git a/pkg/bindings/pods.go b/pkg/bindings/pods.go
new file mode 100644
index 000000000..eac9d2ef5
--- /dev/null
+++ b/pkg/bindings/pods.go
@@ -0,0 +1,128 @@
+package bindings
+
+import (
+ "fmt"
+ "net/http"
+ "strconv"
+
+ "github.com/containers/libpod/libpod"
+)
+
+func (c Connection) CreatePod() error {
+ // TODO
+ return ErrNotImplemented
+}
+
+func (c Connection) PodExists(nameOrID string) (bool, error) {
+ response, err := http.Get(c.makeEndpoint(fmt.Sprintf("/pods/%s/exists", nameOrID)))
+ if err != nil {
+ return false, err
+ }
+ return response.StatusCode == http.StatusOK, err
+}
+
+func (c Connection) InspectPod(nameOrID string) (*libpod.PodInspect, error) {
+ inspect := libpod.PodInspect{}
+ response, err := c.newRequest(http.MethodGet, fmt.Sprintf("/pods/%s/json", nameOrID), nil, nil)
+ if err != nil {
+ return &inspect, err
+ }
+ return &inspect, response.Process(&inspect)
+}
+
+func (c Connection) KillPod(nameOrID string, signal int) error {
+ params := make(map[string]string)
+ params["signal"] = strconv.Itoa(signal)
+ response, err := c.newRequest(http.MethodPost, fmt.Sprintf("/pods/%s/kill", nameOrID), nil, params)
+ if err != nil {
+ return err
+ }
+ return response.Process(nil)
+}
+
+func (c Connection) PausePod(nameOrID string) error {
+ response, err := c.newRequest(http.MethodPost, fmt.Sprintf("/pods/%s/pause", nameOrID), nil, nil)
+ if err != nil {
+ return err
+ }
+ return response.Process(nil)
+}
+
+func (c Connection) PrunePods(force bool) error {
+ params := make(map[string]string)
+ params["force"] = strconv.FormatBool(force)
+ response, err := c.newRequest(http.MethodPost, "/pods/prune", nil, params)
+ if err != nil {
+ return err
+ }
+ return response.Process(nil)
+}
+
+func (c Connection) ListPods(filters []string) (*[]libpod.PodInspect, error) {
+ var (
+ inspect []libpod.PodInspect
+ )
+ params := make(map[string]string)
+ // TODO I dont remember how to do this for []string{}
+ // FIXME
+ //params["filters"] = strconv.FormatBool(force)
+ response, err := c.newRequest(http.MethodPost, "/pods/json", nil, params)
+ if err != nil {
+ return &inspect, err
+ }
+ return &inspect, response.Process(&inspect)
+}
+
+func (c Connection) RestartPod(nameOrID string) error {
+ response, err := c.newRequest(http.MethodPost, fmt.Sprintf("/pods/%s/restart", nameOrID), nil, nil)
+ if err != nil {
+ return err
+ }
+ return response.Process(nil)
+}
+
+func (c Connection) RemovePod(nameOrID string, force bool) error {
+ params := make(map[string]string)
+ params["force"] = strconv.FormatBool(force)
+ response, err := c.newRequest(http.MethodDelete, fmt.Sprintf("/pods/%s", nameOrID), nil, params)
+ if err != nil {
+ return err
+ }
+ return response.Process(nil)
+}
+
+func (c Connection) StartPod(nameOrID string) error {
+ response, err := c.newRequest(http.MethodDelete, fmt.Sprintf("/pods/%s/start", nameOrID), nil, nil)
+ if err != nil {
+ return err
+ }
+ return response.Process(nil)
+}
+
+func (c Connection) PodStats() error {
+ // TODO
+ return ErrNotImplemented
+}
+
+func (c Connection) StopPod(nameOrID string, timeout int) error {
+ params := make(map[string]string)
+ params["t"] = strconv.Itoa(timeout)
+ response, err := c.newRequest(http.MethodPost, fmt.Sprintf("/pods/%s/stop", nameOrID), nil, params)
+ if err != nil {
+ return err
+ }
+ return response.Process(nil)
+}
+
+func (c Connection) PodTop() error {
+ // TODO
+ return ErrNotImplemented // nolint:typecheck
+}
+
+func (c Connection) UnpausePod(nameOrID string) error {
+ response, err := c.newRequest(http.MethodPost, fmt.Sprintf("/pods/%s/unpause", nameOrID), nil, nil)
+ if err != nil {
+ return err
+ }
+ return response.Process(nil)
+}