summaryrefslogtreecommitdiff
path: root/cmd/podman/pods
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman/pods')
-rw-r--r--cmd/podman/pods/create.go62
-rw-r--r--cmd/podman/pods/inspect.go13
-rw-r--r--cmd/podman/pods/pod.go5
-rw-r--r--cmd/podman/pods/prune.go13
-rw-r--r--cmd/podman/pods/ps.go8
-rw-r--r--cmd/podman/pods/stats.go2
-rw-r--r--cmd/podman/pods/top.go22
7 files changed, 69 insertions, 56 deletions
diff --git a/cmd/podman/pods/create.go b/cmd/podman/pods/create.go
index 0c0d07b3e..62b5b849e 100644
--- a/cmd/podman/pods/create.go
+++ b/cmd/podman/pods/create.go
@@ -3,18 +3,22 @@ package pods
import (
"context"
"fmt"
+ "io/ioutil"
"os"
"strings"
"github.com/containers/libpod/cmd/podman/common"
"github.com/containers/libpod/cmd/podman/parse"
"github.com/containers/libpod/cmd/podman/registry"
+ "github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/pkg/domain/entities"
"github.com/containers/libpod/pkg/errorhandling"
"github.com/containers/libpod/pkg/specgen"
"github.com/containers/libpod/pkg/util"
"github.com/pkg/errors"
+ "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
+ "github.com/spf13/pflag"
)
var (
@@ -24,7 +28,7 @@ var (
createCommand = &cobra.Command{
Use: "create",
- Args: common.NoArgs,
+ Args: validate.NoArgs,
Short: "Create a new empty pod",
Long: podCreateDescription,
RunE: create,
@@ -56,7 +60,15 @@ func init() {
flags.StringVarP(&createOptions.Name, "name", "n", "", "Assign a name to the pod")
flags.StringVarP(&createOptions.Hostname, "hostname", "", "", "Set a hostname to the pod")
flags.StringVar(&podIDFile, "pod-id-file", "", "Write the pod ID to the file")
- flags.StringVar(&share, "share", common.DefaultKernelNamespaces, "A comma delimited list of kernel namespaces the pod will share")
+ flags.StringVar(&share, "share", specgen.DefaultKernelNamespaces, "A comma delimited list of kernel namespaces the pod will share")
+ flags.SetNormalizeFunc(aliasNetworkFlag)
+}
+
+func aliasNetworkFlag(_ *pflag.FlagSet, name string) pflag.NormalizedName {
+ if name == "net" {
+ name = "network"
+ }
+ return pflag.NormalizedName(name)
}
func create(cmd *cobra.Command, args []string) error {
@@ -70,6 +82,7 @@ func create(cmd *cobra.Command, args []string) error {
}
if !createOptions.Infra {
+ logrus.Debugf("Not creating an infra container")
if cmd.Flag("infra-command").Changed {
return errors.New("cannot set infra-command without an infra container")
}
@@ -103,32 +116,26 @@ func create(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
- netInput, err := cmd.Flags().GetString("network")
- if err != nil {
- return err
- }
- n := specgen.Namespace{}
- switch netInput {
- case "bridge":
- n.NSMode = specgen.Bridge
- case "host":
- n.NSMode = specgen.Host
- case "slip4netns":
- n.NSMode = specgen.Slirp
- default:
- if strings.HasPrefix(netInput, "container:") { //nolint
- split := strings.Split(netInput, ":")
- if len(split) != 2 {
- return errors.Errorf("invalid network paramater: %q", netInput)
- }
- n.NSMode = specgen.FromContainer
- n.Value = split[1]
- } else if strings.HasPrefix(netInput, "ns:") {
- return errors.New("the ns: network option is not supported for pods")
- } else {
+ createOptions.Net.Network = specgen.Namespace{}
+ if cmd.Flag("network").Changed {
+ netInput, err := cmd.Flags().GetString("network")
+ if err != nil {
+ return err
+ }
+ n := specgen.Namespace{}
+ switch netInput {
+ case "bridge":
+ n.NSMode = specgen.Bridge
+ case "host":
+ n.NSMode = specgen.Host
+ case "slirp4netns":
+ n.NSMode = specgen.Slirp
+ default:
+ // Container and NS mode are presently unsupported
n.NSMode = specgen.Bridge
createOptions.Net.CNINetworks = strings.Split(netInput, ",")
}
+ createOptions.Net.Network = n
}
if len(createOptions.Net.PublishPorts) > 0 {
if !createOptions.Infra {
@@ -140,6 +147,11 @@ func create(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
+ if len(podIDFile) > 0 {
+ if err = ioutil.WriteFile(podIDFile, []byte(response.Id), 0644); err != nil {
+ return errors.Wrapf(err, "failed to write pod ID to file %q", podIDFile)
+ }
+ }
fmt.Println(response.Id)
return nil
}
diff --git a/cmd/podman/pods/inspect.go b/cmd/podman/pods/inspect.go
index 1e333247b..34c07c11b 100644
--- a/cmd/podman/pods/inspect.go
+++ b/cmd/podman/pods/inspect.go
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
+ "github.com/containers/buildah/pkg/formats"
"github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/pkg/domain/entities"
"github.com/pkg/errors"
@@ -36,6 +37,7 @@ func init() {
})
flags := inspectCmd.Flags()
flags.BoolVarP(&inspectOptions.Latest, "latest", "l", false, "Act on the latest pod podman is aware of")
+ flags.StringVarP(&inspectOptions.Format, "format", "f", "json", "Format the output to a Go template or json")
if registry.IsRemote() {
_ = flags.MarkHidden("latest")
}
@@ -54,10 +56,11 @@ func inspect(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
- b, err := json.MarshalIndent(responses, "", " ")
- if err != nil {
- return err
+ var data interface{} = responses
+ var out formats.Writer = formats.JSONStruct{Output: data}
+ if inspectOptions.Format != "json" {
+ out = formats.StdoutTemplate{Output: data, Template: inspectOptions.Format}
}
- fmt.Println(string(b))
- return nil
+
+ return out.Out()
}
diff --git a/cmd/podman/pods/pod.go b/cmd/podman/pods/pod.go
index e86b8aba4..ed265ef90 100644
--- a/cmd/podman/pods/pod.go
+++ b/cmd/podman/pods/pod.go
@@ -2,6 +2,7 @@ package pods
import (
"github.com/containers/libpod/cmd/podman/registry"
+ "github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/pkg/domain/entities"
"github.com/containers/libpod/pkg/util"
"github.com/spf13/cobra"
@@ -15,9 +16,9 @@ var (
podCmd = &cobra.Command{
Use: "pod",
Short: "Manage pods",
- Long: "Manage pods",
+ Long: "Pods are a group of one or more containers sharing the same network, pid and ipc namespaces.",
TraverseChildren: true,
- RunE: registry.SubCommandExists,
+ RunE: validate.SubCommandExists,
}
containerConfig = util.DefaultContainerConfig()
)
diff --git a/cmd/podman/pods/prune.go b/cmd/podman/pods/prune.go
index 091e3375b..bc15d8035 100644
--- a/cmd/podman/pods/prune.go
+++ b/cmd/podman/pods/prune.go
@@ -41,9 +41,6 @@ func init() {
}
func prune(cmd *cobra.Command, args []string) error {
- var (
- errs utils.OutputErrors
- )
if len(args) > 0 {
return errors.Errorf("`%s` takes no arguments", cmd.CommandPath())
}
@@ -60,16 +57,8 @@ func prune(cmd *cobra.Command, args []string) error {
}
}
responses, err := registry.ContainerEngine().PodPrune(context.Background(), pruneOptions)
-
if err != nil {
return err
}
- for _, r := range responses {
- if r.Err == nil {
- fmt.Println(r.Id)
- } else {
- errs = append(errs, r.Err)
- }
- }
- return errs.PrintErrors()
+ return utils.PrintPodPruneResults(responses)
}
diff --git a/cmd/podman/pods/ps.go b/cmd/podman/pods/ps.go
index 8ae1f91a8..5703bd172 100644
--- a/cmd/podman/pods/ps.go
+++ b/cmd/podman/pods/ps.go
@@ -11,8 +11,8 @@ import (
"text/template"
"time"
- "github.com/containers/libpod/cmd/podman/common"
"github.com/containers/libpod/cmd/podman/registry"
+ "github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/pkg/domain/entities"
"github.com/docker/go-units"
"github.com/pkg/errors"
@@ -26,15 +26,15 @@ var (
psCmd = &cobra.Command{
Use: "ps",
Aliases: []string{"ls", "list"},
- Short: "list pods",
+ Short: "List pods",
Long: psDescription,
RunE: pods,
- Args: common.NoArgs,
+ Args: validate.NoArgs,
}
)
var (
- defaultHeaders string = "POD ID\tNAME\tSTATUS\tCREATED"
+ defaultHeaders = "POD ID\tNAME\tSTATUS\tCREATED"
inputFilters []string
noTrunc bool
psInput entities.PodPSOptions
diff --git a/cmd/podman/pods/stats.go b/cmd/podman/pods/stats.go
index 7c3597d9a..d3950fdbc 100644
--- a/cmd/podman/pods/stats.go
+++ b/cmd/podman/pods/stats.go
@@ -35,7 +35,7 @@ var (
// Command: podman pod _pod_
statsCmd = &cobra.Command{
Use: "stats [flags] [POD...]",
- Short: "Display resource-usage statistics of pods",
+ Short: "Display a live stream of resource usage statistics for the containers in one or more pods",
Long: statsDescription,
RunE: stats,
Example: `podman pod stats
diff --git a/cmd/podman/pods/top.go b/cmd/podman/pods/top.go
index ad602f4ea..ba1efb638 100644
--- a/cmd/podman/pods/top.go
+++ b/cmd/podman/pods/top.go
@@ -9,23 +9,21 @@ import (
"github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/pkg/domain/entities"
- "github.com/containers/psgo"
+ "github.com/containers/libpod/pkg/util"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
var (
- topDescription = fmt.Sprintf(`Specify format descriptors to alter the output.
+ topDescription = `Specify format descriptors to alter the output.
- You may run "podman pod top -l pid pcpu seccomp" to print the process ID, the CPU percentage and the seccomp mode of each process of the latest pod.
- Format Descriptors:
- %s`, strings.Join(psgo.ListDescriptors(), ","))
+ You may run "podman pod top -l pid pcpu seccomp" to print the process ID, the CPU percentage and the seccomp mode of each process of the latest pod.`
topOptions = entities.PodTopOptions{}
topCommand = &cobra.Command{
Use: "top [flags] POD [FORMAT-DESCRIPTORS|ARGS]",
- Short: "Display the running processes in a pod",
+ Short: "Display the running processes of containers in a pod",
Long: topDescription,
RunE: top,
Args: cobra.ArbitraryArgs,
@@ -43,6 +41,12 @@ func init() {
Parent: podCmd,
})
+ descriptors, err := util.GetContainerPidInformationDescriptors()
+ if err == nil {
+ topDescription = fmt.Sprintf("%s\n\n Format Descriptors:\n %s", topDescription, strings.Join(descriptors, ","))
+ topCommand.Long = topDescription
+ }
+
flags := topCommand.Flags()
flags.SetInterspersed(false)
flags.BoolVar(&topOptions.ListDescriptors, "list-descriptors", false, "")
@@ -56,7 +60,11 @@ func init() {
func top(cmd *cobra.Command, args []string) error {
if topOptions.ListDescriptors {
- fmt.Println(strings.Join(psgo.ListDescriptors(), "\n"))
+ descriptors, err := util.GetContainerPidInformationDescriptors()
+ if err != nil {
+ return err
+ }
+ fmt.Println(strings.Join(descriptors, "\n"))
return nil
}