mirror of https://github.com/containers/podman.git
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
This commit is contained in:
parent
0059989783
commit
8d5e0108d7
|
@ -4,9 +4,9 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containers/libpod/cmd/podman/batchcontainer"
|
|
||||||
"github.com/containers/libpod/cmd/podman/formats"
|
"github.com/containers/libpod/cmd/podman/formats"
|
||||||
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
||||||
|
"github.com/containers/libpod/cmd/podman/shared"
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
"github.com/containers/libpod/pkg/util"
|
"github.com/containers/libpod/pkg/util"
|
||||||
"github.com/pkg/errors"
|
"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)
|
inspectError = errors.Wrapf(err, "error getting libpod container inspect data %q", ctr.ID)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
data, err = batchcontainer.GetCtrInspectInfo(ctr, libpodInspectData)
|
data, err = shared.GetCtrInspectInfo(ctr, libpodInspectData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
inspectError = errors.Wrapf(err, "error parsing container data %q", ctr.ID())
|
inspectError = errors.Wrapf(err, "error parsing container data %q", ctr.ID())
|
||||||
break
|
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)
|
inspectError = errors.Wrapf(err, "error getting libpod container inspect data %q", ctr.ID)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
data, err = batchcontainer.GetCtrInspectInfo(ctr, libpodInspectData)
|
data, err = shared.GetCtrInspectInfo(ctr, libpodInspectData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
inspectError = errors.Wrapf(err, "error parsing container data %q", ctr.ID)
|
inspectError = errors.Wrapf(err, "error parsing container data %q", ctr.ID)
|
||||||
break
|
break
|
||||||
|
|
|
@ -7,9 +7,9 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containers/libpod/cmd/podman/batchcontainer"
|
|
||||||
"github.com/containers/libpod/cmd/podman/formats"
|
"github.com/containers/libpod/cmd/podman/formats"
|
||||||
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
||||||
|
"github.com/containers/libpod/cmd/podman/shared"
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
"github.com/containers/libpod/pkg/util"
|
"github.com/containers/libpod/pkg/util"
|
||||||
"github.com/docker/go-units"
|
"github.com/docker/go-units"
|
||||||
|
@ -28,7 +28,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
bc_opts batchcontainer.PsOptions
|
bc_opts shared.PsOptions
|
||||||
)
|
)
|
||||||
|
|
||||||
type podPsCtrInfo struct {
|
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 nil, errors.Errorf("%s is not a valid status", filterValue)
|
||||||
}
|
}
|
||||||
return func(p *libpod.Pod) bool {
|
return func(p *libpod.Pod) bool {
|
||||||
ctr_statuses, err := p.ContainerStatus()
|
ctr_statuses, err := p.Status()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
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 nil, errors.Errorf("%s is not a valid pod status", filterValue)
|
||||||
}
|
}
|
||||||
return func(p *libpod.Pod) bool {
|
return func(p *libpod.Pod) bool {
|
||||||
status, err := p.Status()
|
status, err := shared.GetPodStatus(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -473,13 +473,13 @@ func getAndSortPodJSONParams(pods []*libpod.Pod, opts podPsOptions, runtime *lib
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
ctrNum := len(ctrs)
|
ctrNum := len(ctrs)
|
||||||
status, err := pod.Status()
|
status, err := shared.GetPodStatus(pod)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, ctr := range ctrs {
|
for _, ctr := range ctrs {
|
||||||
batchInfo, err := batchcontainer.BatchContainerOp(ctr, bc_opts)
|
batchInfo, err := shared.BatchContainerOp(ctr, bc_opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,9 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containers/libpod/cmd/podman/batchcontainer"
|
|
||||||
"github.com/containers/libpod/cmd/podman/formats"
|
"github.com/containers/libpod/cmd/podman/formats"
|
||||||
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
||||||
|
"github.com/containers/libpod/cmd/podman/shared"
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
"github.com/containers/libpod/pkg/util"
|
"github.com/containers/libpod/pkg/util"
|
||||||
"github.com/cri-o/ocicni/pkg/ocicni"
|
"github.com/cri-o/ocicni/pkg/ocicni"
|
||||||
|
@ -52,25 +52,25 @@ type psTemplateParams struct {
|
||||||
// psJSONParams will be populated by data from libpod.Container,
|
// psJSONParams will be populated by data from libpod.Container,
|
||||||
// the members of the struct are the sama data types as their sources.
|
// the members of the struct are the sama data types as their sources.
|
||||||
type psJSONParams struct {
|
type psJSONParams struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Image string `json:"image"`
|
Image string `json:"image"`
|
||||||
ImageID string `json:"image_id"`
|
ImageID string `json:"image_id"`
|
||||||
Command []string `json:"command"`
|
Command []string `json:"command"`
|
||||||
ExitCode int32 `json:"exitCode"`
|
ExitCode int32 `json:"exitCode"`
|
||||||
Exited bool `json:"exited"`
|
Exited bool `json:"exited"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
StartedAt time.Time `json:"startedAt"`
|
StartedAt time.Time `json:"startedAt"`
|
||||||
ExitedAt time.Time `json:"exitedAt"`
|
ExitedAt time.Time `json:"exitedAt"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
PID int `json:"PID"`
|
PID int `json:"PID"`
|
||||||
Ports []ocicni.PortMapping `json:"ports"`
|
Ports []ocicni.PortMapping `json:"ports"`
|
||||||
Size *batchcontainer.ContainerSize `json:"size,omitempty"`
|
Size *shared.ContainerSize `json:"size,omitempty"`
|
||||||
Names string `json:"names"`
|
Names string `json:"names"`
|
||||||
Labels fields.Set `json:"labels"`
|
Labels fields.Set `json:"labels"`
|
||||||
Mounts []string `json:"mounts"`
|
Mounts []string `json:"mounts"`
|
||||||
ContainerRunning bool `json:"ctrRunning"`
|
ContainerRunning bool `json:"ctrRunning"`
|
||||||
Namespaces *batchcontainer.Namespace `json:"namespace,omitempty"`
|
Namespaces *shared.Namespace `json:"namespace,omitempty"`
|
||||||
Pod string `json:"pod,omitempty"`
|
Pod string `json:"pod,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type declaration and functions for sorting the PS output
|
// 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"))
|
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"),
|
All: c.Bool("all"),
|
||||||
Filter: c.String("filter"),
|
Filter: c.String("filter"),
|
||||||
Format: format,
|
Format: format,
|
||||||
|
@ -497,11 +497,11 @@ func sortPsOutput(sortBy string, psOutput psSorted) (psSorted, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// getTemplateOutput returns the modified container information
|
// 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 (
|
var (
|
||||||
psOutput []psTemplateParams
|
psOutput []psTemplateParams
|
||||||
pod, status, size string
|
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
|
// If the user is trying to filter based on size, or opted to sort on size
|
||||||
// the size bool must be set.
|
// 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
|
// 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 (
|
var (
|
||||||
psOutput psSorted
|
psOutput psSorted
|
||||||
ns *batchcontainer.Namespace
|
ns *shared.Namespace
|
||||||
)
|
)
|
||||||
for _, ctr := range containers {
|
for _, ctr := range containers {
|
||||||
batchInfo, err := batchcontainer.BatchContainerOp(ctr, opts)
|
batchInfo, err := shared.BatchContainerOp(ctr, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Cause(err) == libpod.ErrNoSuchCtr {
|
if errors.Cause(err) == libpod.ErrNoSuchCtr {
|
||||||
logrus.Warn(err)
|
logrus.Warn(err)
|
||||||
|
@ -605,7 +605,7 @@ func getAndSortJSONParams(containers []*libpod.Container, opts batchcontainer.Ps
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.Namespace {
|
if opts.Namespace {
|
||||||
ns = batchcontainer.GetNamespaces(batchInfo.Pid)
|
ns = shared.GetNamespaces(batchInfo.Pid)
|
||||||
}
|
}
|
||||||
params := psJSONParams{
|
params := psJSONParams{
|
||||||
ID: ctr.ID(),
|
ID: ctr.ID(),
|
||||||
|
@ -634,7 +634,7 @@ func getAndSortJSONParams(containers []*libpod.Container, opts batchcontainer.Ps
|
||||||
return sortPsOutput(opts.Sort, psOutput)
|
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 {
|
if len(containers) == 0 && opts.Format != formats.JSONString {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
|
@ -1,4 +1,4 @@
|
||||||
package batchcontainer
|
package shared
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
|
@ -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
|
||||||
|
}
|
|
@ -8,15 +8,6 @@ import (
|
||||||
"github.com/ulule/deepcopier"
|
"github.com/ulule/deepcopier"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
stopped = "Stopped"
|
|
||||||
running = "Running"
|
|
||||||
paused = "Paused"
|
|
||||||
exited = "Exited"
|
|
||||||
errored = "Error"
|
|
||||||
created = "Created"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Start starts all containers within a pod
|
// Start starts all containers within a pod
|
||||||
// It combines the effects of Init() and Start() on a container
|
// It combines the effects of Init() and Start() on a container
|
||||||
// If a container has already been initialized it will be started,
|
// If a container has already been initialized it will be started,
|
||||||
|
@ -371,9 +362,9 @@ func (p *Pod) Kill(signal uint) (map[string]error, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContainerStatus gets the status of all containers in the pod
|
// Status gets the status of all containers in the pod
|
||||||
// Returns a map of Container ID to Container Status
|
// Returns a map of Container ID to Container Status
|
||||||
func (p *Pod) ContainerStatus() (map[string]ContainerStatus, error) {
|
func (p *Pod) Status() (map[string]ContainerStatus, error) {
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
defer p.lock.Unlock()
|
defer p.lock.Unlock()
|
||||||
|
|
||||||
|
@ -405,54 +396,6 @@ func (p *Pod) ContainerStatus() (map[string]ContainerStatus, error) {
|
||||||
return status, nil
|
return status, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Status 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 (p *Pod) Status() (string, error) {
|
|
||||||
ctrStatuses, err := p.ContainerStatus()
|
|
||||||
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 ContainerStateStopped:
|
|
||||||
statuses[stopped]++
|
|
||||||
case ContainerStateRunning:
|
|
||||||
statuses[running]++
|
|
||||||
case ContainerStatePaused:
|
|
||||||
statuses[paused]++
|
|
||||||
case ContainerStateCreated, 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
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inspect returns a PodInspect struct to describe the pod
|
// Inspect returns a PodInspect struct to describe the pod
|
||||||
func (p *Pod) Inspect() (*PodInspect, error) {
|
func (p *Pod) Inspect() (*PodInspect, error) {
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containers/libpod/cmd/podman/batchcontainer"
|
"github.com/containers/libpod/cmd/podman/shared"
|
||||||
"github.com/containers/libpod/cmd/podman/varlink"
|
"github.com/containers/libpod/cmd/podman/varlink"
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
"github.com/containers/storage/pkg/archive"
|
"github.com/containers/storage/pkg/archive"
|
||||||
|
@ -26,12 +26,12 @@ func (i *LibpodAPI) ListContainers(call iopodman.VarlinkCall) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return call.ReplyErrorOccurred(err.Error())
|
return call.ReplyErrorOccurred(err.Error())
|
||||||
}
|
}
|
||||||
opts := batchcontainer.PsOptions{
|
opts := shared.PsOptions{
|
||||||
Namespace: true,
|
Namespace: true,
|
||||||
Size: true,
|
Size: true,
|
||||||
}
|
}
|
||||||
for _, ctr := range containers {
|
for _, ctr := range containers {
|
||||||
batchInfo, err := batchcontainer.BatchContainerOp(ctr, opts)
|
batchInfo, err := shared.BatchContainerOp(ctr, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return call.ReplyErrorOccurred(err.Error())
|
return call.ReplyErrorOccurred(err.Error())
|
||||||
}
|
}
|
||||||
|
@ -47,11 +47,11 @@ func (i *LibpodAPI) GetContainer(call iopodman.VarlinkCall, name string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return call.ReplyContainerNotFound(name)
|
return call.ReplyContainerNotFound(name)
|
||||||
}
|
}
|
||||||
opts := batchcontainer.PsOptions{
|
opts := shared.PsOptions{
|
||||||
Namespace: true,
|
Namespace: true,
|
||||||
Size: true,
|
Size: true,
|
||||||
}
|
}
|
||||||
batchInfo, err := batchcontainer.BatchContainerOp(ctr, opts)
|
batchInfo, err := shared.BatchContainerOp(ctr, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return call.ReplyErrorOccurred(err.Error())
|
return call.ReplyErrorOccurred(err.Error())
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ func (i *LibpodAPI) InspectContainer(call iopodman.VarlinkCall, name string) err
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return call.ReplyErrorOccurred(err.Error())
|
return call.ReplyErrorOccurred(err.Error())
|
||||||
}
|
}
|
||||||
data, err := batchcontainer.GetCtrInspectInfo(ctr, inspectInfo)
|
data, err := shared.GetCtrInspectInfo(ctr, inspectInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return call.ReplyErrorOccurred(err.Error())
|
return call.ReplyErrorOccurred(err.Error())
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/projectatomic/libpod/cmd/podman/batchcontainer"
|
"github.com/projectatomic/libpod/cmd/podman/shared"
|
||||||
"github.com/projectatomic/libpod/cmd/podman/varlink"
|
"github.com/projectatomic/libpod/cmd/podman/varlink"
|
||||||
"github.com/projectatomic/libpod/libpod"
|
"github.com/projectatomic/libpod/libpod"
|
||||||
)
|
)
|
||||||
|
@ -40,7 +40,7 @@ func (i *LibpodAPI) ListPods(call iopodman.VarlinkCall) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return call.ReplyErrorOccurred(err.Error())
|
return call.ReplyErrorOccurred(err.Error())
|
||||||
}
|
}
|
||||||
opts := batchcontainer.PsOptions{}
|
opts := shared.PsOptions{}
|
||||||
for _, pod := range pods {
|
for _, pod := range pods {
|
||||||
listPod, err := makeListPod(pod, opts)
|
listPod, err := makeListPod(pod, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -57,7 +57,7 @@ func (i *LibpodAPI) GetPod(call iopodman.VarlinkCall, name string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return call.ReplyPodNotFound(name)
|
return call.ReplyPodNotFound(name)
|
||||||
}
|
}
|
||||||
opts := batchcontainer.PsOptions{}
|
opts := shared.PsOptions{}
|
||||||
|
|
||||||
listPod, err := makeListPod(pod, opts)
|
listPod, err := makeListPod(pod, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containers/libpod/cmd/podman/batchcontainer"
|
"github.com/containers/libpod/cmd/podman/shared"
|
||||||
"github.com/containers/libpod/cmd/podman/varlink"
|
"github.com/containers/libpod/cmd/podman/varlink"
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
)
|
)
|
||||||
|
@ -15,12 +15,12 @@ func getContext() context.Context {
|
||||||
return context.TODO()
|
return context.TODO()
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeListContainer(containerID string, batchInfo batchcontainer.BatchContainerStruct) iopodman.ListContainerData {
|
func makeListContainer(containerID string, batchInfo shared.BatchContainerStruct) iopodman.ListContainerData {
|
||||||
var (
|
var (
|
||||||
mounts []iopodman.ContainerMount
|
mounts []iopodman.ContainerMount
|
||||||
ports []iopodman.ContainerPortMappings
|
ports []iopodman.ContainerPortMappings
|
||||||
)
|
)
|
||||||
ns := batchcontainer.GetNamespaces(batchInfo.Pid)
|
ns := shared.GetNamespaces(batchInfo.Pid)
|
||||||
|
|
||||||
for _, mount := range batchInfo.ConConfig.Spec.Mounts {
|
for _, mount := range batchInfo.ConConfig.Spec.Mounts {
|
||||||
m := iopodman.ContainerMount{
|
m := iopodman.ContainerMount{
|
||||||
|
@ -78,7 +78,7 @@ func makeListContainer(containerID string, batchInfo batchcontainer.BatchContain
|
||||||
return lc
|
return lc
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeListPodContainers(containerID string, batchInfo batchcontainer.BatchContainerStruct) iopodman.ListPodContainerInfo {
|
func makeListPodContainers(containerID string, batchInfo shared.BatchContainerStruct) iopodman.ListPodContainerInfo {
|
||||||
lc := iopodman.ListPodContainerInfo{
|
lc := iopodman.ListPodContainerInfo{
|
||||||
Id: containerID,
|
Id: containerID,
|
||||||
Status: batchInfo.ConState.String(),
|
Status: batchInfo.ConState.String(),
|
||||||
|
@ -87,10 +87,10 @@ func makeListPodContainers(containerID string, batchInfo batchcontainer.BatchCon
|
||||||
return lc
|
return lc
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeListPod(pod *libpod.Pod, batchInfo batchcontainer.PsOptions) (iopodman.ListPodData, error) {
|
func makeListPod(pod *libpod.Pod, batchInfo shared.PsOptions) (iopodman.ListPodData, error) {
|
||||||
var listPodsContainers []iopodman.ListPodContainerInfo
|
var listPodsContainers []iopodman.ListPodContainerInfo
|
||||||
var errPodData = iopodman.ListPodData{}
|
var errPodData = iopodman.ListPodData{}
|
||||||
status, err := pod.Status()
|
status, err := shared.GetPodStatus(pod)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errPodData, err
|
return errPodData, err
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ func makeListPod(pod *libpod.Pod, batchInfo batchcontainer.PsOptions) (iopodman.
|
||||||
return errPodData, err
|
return errPodData, err
|
||||||
}
|
}
|
||||||
for _, ctr := range containers {
|
for _, ctr := range containers {
|
||||||
batchInfo, err := batchcontainer.BatchContainerOp(ctr, batchInfo)
|
batchInfo, err := shared.BatchContainerOp(ctr, batchInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errPodData, err
|
return errPodData, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue