summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorhaircommander <pehunt@redhat.com>2018-08-14 17:16:22 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-08-16 20:31:50 +0000
commit8d5e0108d7c8b69abb9821bfe55475ae5d663b3a (patch)
tree6d8fa9c82a9181fad919bd797f64fe46440e7a4e /cmd
parent0059989783851ec536faf8a290eea863148dcb6c (diff)
downloadpodman-8d5e0108d7c8b69abb9821bfe55475ae5d663b3a.tar.gz
podman-8d5e0108d7c8b69abb9821bfe55475ae5d663b3a.tar.bz2
podman-8d5e0108d7c8b69abb9821bfe55475ae5d663b3a.zip
Change batchcontainer to shared
To better reflect it's usage: to share functions between podman and varlink. Signed-off-by: haircommander <pehunt@redhat.com> Closes: #1275 Approved by: mheon
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/inspect.go6
-rw-r--r--cmd/podman/pod_ps.go12
-rw-r--r--cmd/podman/ps.go56
-rw-r--r--cmd/podman/shared/.pod.go.swpbin0 -> 12288 bytes
-rw-r--r--cmd/podman/shared/container.go (renamed from cmd/podman/batchcontainer/container.go)2
-rw-r--r--cmd/podman/shared/pod.go62
6 files changed, 100 insertions, 38 deletions
diff --git a/cmd/podman/inspect.go b/cmd/podman/inspect.go
index 1fa8f55a2..a36f8c7a1 100644
--- a/cmd/podman/inspect.go
+++ b/cmd/podman/inspect.go
@@ -4,9 +4,9 @@ import (
"context"
"strings"
- "github.com/containers/libpod/cmd/podman/batchcontainer"
"github.com/containers/libpod/cmd/podman/formats"
"github.com/containers/libpod/cmd/podman/libpodruntime"
+ "github.com/containers/libpod/cmd/podman/shared"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/util"
"github.com/pkg/errors"
@@ -121,7 +121,7 @@ func iterateInput(ctx context.Context, c *cli.Context, args []string, runtime *l
inspectError = errors.Wrapf(err, "error getting libpod container inspect data %q", ctr.ID)
break
}
- data, err = batchcontainer.GetCtrInspectInfo(ctr, libpodInspectData)
+ data, err = shared.GetCtrInspectInfo(ctr, libpodInspectData)
if err != nil {
inspectError = errors.Wrapf(err, "error parsing container data %q", ctr.ID())
break
@@ -156,7 +156,7 @@ func iterateInput(ctx context.Context, c *cli.Context, args []string, runtime *l
inspectError = errors.Wrapf(err, "error getting libpod container inspect data %q", ctr.ID)
break
}
- data, err = batchcontainer.GetCtrInspectInfo(ctr, libpodInspectData)
+ data, err = shared.GetCtrInspectInfo(ctr, libpodInspectData)
if err != nil {
inspectError = errors.Wrapf(err, "error parsing container data %q", ctr.ID)
break
diff --git a/cmd/podman/pod_ps.go b/cmd/podman/pod_ps.go
index 52fbea6e5..20beae53a 100644
--- a/cmd/podman/pod_ps.go
+++ b/cmd/podman/pod_ps.go
@@ -7,9 +7,9 @@ import (
"strings"
"time"
- "github.com/containers/libpod/cmd/podman/batchcontainer"
"github.com/containers/libpod/cmd/podman/formats"
"github.com/containers/libpod/cmd/podman/libpodruntime"
+ "github.com/containers/libpod/cmd/podman/shared"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/util"
"github.com/docker/go-units"
@@ -28,7 +28,7 @@ const (
)
var (
- bc_opts batchcontainer.PsOptions
+ bc_opts shared.PsOptions
)
type podPsCtrInfo struct {
@@ -296,7 +296,7 @@ func generatePodFilterFuncs(filter, filterValue string, runtime *libpod.Runtime)
return nil, errors.Errorf("%s is not a valid status", filterValue)
}
return func(p *libpod.Pod) bool {
- ctr_statuses, err := p.ContainerStatus()
+ ctr_statuses, err := p.Status()
if err != nil {
return false
}
@@ -324,7 +324,7 @@ func generatePodFilterFuncs(filter, filterValue string, runtime *libpod.Runtime)
return nil, errors.Errorf("%s is not a valid pod status", filterValue)
}
return func(p *libpod.Pod) bool {
- status, err := p.Status()
+ status, err := shared.GetPodStatus(p)
if err != nil {
return false
}
@@ -473,13 +473,13 @@ func getAndSortPodJSONParams(pods []*libpod.Pod, opts podPsOptions, runtime *lib
return nil, err
}
ctrNum := len(ctrs)
- status, err := pod.Status()
+ status, err := shared.GetPodStatus(pod)
if err != nil {
return nil, err
}
for _, ctr := range ctrs {
- batchInfo, err := batchcontainer.BatchContainerOp(ctr, bc_opts)
+ batchInfo, err := shared.BatchContainerOp(ctr, bc_opts)
if err != nil {
return nil, err
}
diff --git a/cmd/podman/ps.go b/cmd/podman/ps.go
index 94e8a4920..0ad511217 100644
--- a/cmd/podman/ps.go
+++ b/cmd/podman/ps.go
@@ -8,9 +8,9 @@ import (
"strings"
"time"
- "github.com/containers/libpod/cmd/podman/batchcontainer"
"github.com/containers/libpod/cmd/podman/formats"
"github.com/containers/libpod/cmd/podman/libpodruntime"
+ "github.com/containers/libpod/cmd/podman/shared"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/util"
"github.com/cri-o/ocicni/pkg/ocicni"
@@ -52,25 +52,25 @@ type psTemplateParams struct {
// psJSONParams will be populated by data from libpod.Container,
// the members of the struct are the sama data types as their sources.
type psJSONParams struct {
- ID string `json:"id"`
- Image string `json:"image"`
- ImageID string `json:"image_id"`
- Command []string `json:"command"`
- ExitCode int32 `json:"exitCode"`
- Exited bool `json:"exited"`
- CreatedAt time.Time `json:"createdAt"`
- StartedAt time.Time `json:"startedAt"`
- ExitedAt time.Time `json:"exitedAt"`
- Status string `json:"status"`
- PID int `json:"PID"`
- Ports []ocicni.PortMapping `json:"ports"`
- Size *batchcontainer.ContainerSize `json:"size,omitempty"`
- Names string `json:"names"`
- Labels fields.Set `json:"labels"`
- Mounts []string `json:"mounts"`
- ContainerRunning bool `json:"ctrRunning"`
- Namespaces *batchcontainer.Namespace `json:"namespace,omitempty"`
- Pod string `json:"pod,omitempty"`
+ ID string `json:"id"`
+ Image string `json:"image"`
+ ImageID string `json:"image_id"`
+ Command []string `json:"command"`
+ ExitCode int32 `json:"exitCode"`
+ Exited bool `json:"exited"`
+ CreatedAt time.Time `json:"createdAt"`
+ StartedAt time.Time `json:"startedAt"`
+ ExitedAt time.Time `json:"exitedAt"`
+ Status string `json:"status"`
+ PID int `json:"PID"`
+ Ports []ocicni.PortMapping `json:"ports"`
+ Size *shared.ContainerSize `json:"size,omitempty"`
+ Names string `json:"names"`
+ Labels fields.Set `json:"labels"`
+ Mounts []string `json:"mounts"`
+ ContainerRunning bool `json:"ctrRunning"`
+ Namespaces *shared.Namespace `json:"namespace,omitempty"`
+ Pod string `json:"pod,omitempty"`
}
// Type declaration and functions for sorting the PS output
@@ -218,7 +218,7 @@ func psCmd(c *cli.Context) error {
format := genPsFormat(c.String("format"), c.Bool("quiet"), c.Bool("size"), c.Bool("namespace"), c.Bool("pod"))
- opts := batchcontainer.PsOptions{
+ opts := shared.PsOptions{
All: c.Bool("all"),
Filter: c.String("filter"),
Format: format,
@@ -497,11 +497,11 @@ func sortPsOutput(sortBy string, psOutput psSorted) (psSorted, error) {
}
// getTemplateOutput returns the modified container information
-func getTemplateOutput(psParams []psJSONParams, opts batchcontainer.PsOptions) ([]psTemplateParams, error) {
+func getTemplateOutput(psParams []psJSONParams, opts shared.PsOptions) ([]psTemplateParams, error) {
var (
psOutput []psTemplateParams
pod, status, size string
- ns *batchcontainer.Namespace
+ ns *shared.Namespace
)
// If the user is trying to filter based on size, or opted to sort on size
// the size bool must be set.
@@ -589,13 +589,13 @@ func getTemplateOutput(psParams []psJSONParams, opts batchcontainer.PsOptions) (
}
// getAndSortJSONOutput returns the container info in its raw, sorted form
-func getAndSortJSONParams(containers []*libpod.Container, opts batchcontainer.PsOptions) ([]psJSONParams, error) {
+func getAndSortJSONParams(containers []*libpod.Container, opts shared.PsOptions) ([]psJSONParams, error) {
var (
psOutput psSorted
- ns *batchcontainer.Namespace
+ ns *shared.Namespace
)
for _, ctr := range containers {
- batchInfo, err := batchcontainer.BatchContainerOp(ctr, opts)
+ batchInfo, err := shared.BatchContainerOp(ctr, opts)
if err != nil {
if errors.Cause(err) == libpod.ErrNoSuchCtr {
logrus.Warn(err)
@@ -605,7 +605,7 @@ func getAndSortJSONParams(containers []*libpod.Container, opts batchcontainer.Ps
}
if opts.Namespace {
- ns = batchcontainer.GetNamespaces(batchInfo.Pid)
+ ns = shared.GetNamespaces(batchInfo.Pid)
}
params := psJSONParams{
ID: ctr.ID(),
@@ -634,7 +634,7 @@ func getAndSortJSONParams(containers []*libpod.Container, opts batchcontainer.Ps
return sortPsOutput(opts.Sort, psOutput)
}
-func generatePsOutput(containers []*libpod.Container, opts batchcontainer.PsOptions) error {
+func generatePsOutput(containers []*libpod.Container, opts shared.PsOptions) error {
if len(containers) == 0 && opts.Format != formats.JSONString {
return nil
}
diff --git a/cmd/podman/shared/.pod.go.swp b/cmd/podman/shared/.pod.go.swp
new file mode 100644
index 000000000..a8565e752
--- /dev/null
+++ b/cmd/podman/shared/.pod.go.swp
Binary files differ
diff --git a/cmd/podman/batchcontainer/container.go b/cmd/podman/shared/container.go
index 364b28d40..7a5455046 100644
--- a/cmd/podman/batchcontainer/container.go
+++ b/cmd/podman/shared/container.go
@@ -1,4 +1,4 @@
-package batchcontainer
+package shared
import (
"encoding/json"
diff --git a/cmd/podman/shared/pod.go b/cmd/podman/shared/pod.go
new file mode 100644
index 000000000..50c642d59
--- /dev/null
+++ b/cmd/podman/shared/pod.go
@@ -0,0 +1,62 @@
+package shared
+
+import (
+ "github.com/projectatomic/libpod/libpod"
+)
+
+const (
+ stopped = "Stopped"
+ running = "Running"
+ paused = "Paused"
+ exited = "Exited"
+ errored = "Error"
+ created = "Created"
+)
+
+// GetPodStatus determines the status of the pod based on the
+// statuses of the containers in the pod.
+// Returns a string representation of the pod status
+func GetPodStatus(pod *libpod.Pod) (string, error) {
+ ctrStatuses, err := pod.Status()
+ if err != nil {
+ return errored, err
+ }
+ ctrNum := len(ctrStatuses)
+ if ctrNum == 0 {
+ return created, nil
+ }
+ statuses := map[string]int{
+ stopped: 0,
+ running: 0,
+ paused: 0,
+ created: 0,
+ errored: 0,
+ }
+ for _, ctrStatus := range ctrStatuses {
+ switch ctrStatus {
+ case libpod.ContainerStateStopped:
+ statuses[stopped]++
+ case libpod.ContainerStateRunning:
+ statuses[running]++
+ case libpod.ContainerStatePaused:
+ statuses[paused]++
+ case libpod.ContainerStateCreated, libpod.ContainerStateConfigured:
+ statuses[created]++
+ default:
+ statuses[errored]++
+ }
+ }
+
+ if statuses[running] > 0 {
+ return running, nil
+ } else if statuses[paused] == ctrNum {
+ return paused, nil
+ } else if statuses[stopped] == ctrNum {
+ return exited, nil
+ } else if statuses[stopped] > 0 {
+ return stopped, nil
+ } else if statuses[errored] > 0 {
+ return errored, nil
+ }
+ return created, nil
+}