aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/containers/create.go3
-rw-r--r--cmd/podman/containers/stats.go16
-rw-r--r--cmd/podman/pods/create.go53
-rw-r--r--cmd/podman/system/connection/list.go35
4 files changed, 99 insertions, 8 deletions
diff --git a/cmd/podman/containers/create.go b/cmd/podman/containers/create.go
index 2144a6e10..1e11c53d5 100644
--- a/cmd/podman/containers/create.go
+++ b/cmd/podman/containers/create.go
@@ -222,7 +222,6 @@ func createInit(c *cobra.Command) error {
}
cliVals.Env = env
}
-
if c.Flag("cgroups").Changed && cliVals.CGroupsMode == "split" && registry.IsRemote() {
return errors.Errorf("the option --cgroups=%q is not supported in remote mode", cliVals.CGroupsMode)
}
@@ -292,6 +291,8 @@ func createPodIfNecessary(s *specgen.SpecGenerator, netOpts *entities.NetOptions
Net: netOpts,
CreateCommand: os.Args,
Hostname: s.ContainerBasicConfig.Hostname,
+ Cpus: cliVals.CPUS,
+ CpusetCpus: cliVals.CPUSetCPUs,
}
// Unset config values we passed to the pod to prevent them being used twice for the container and pod.
s.ContainerBasicConfig.Hostname = ""
diff --git a/cmd/podman/containers/stats.go b/cmd/podman/containers/stats.go
index 27c5147a5..208d5d58f 100644
--- a/cmd/podman/containers/stats.go
+++ b/cmd/podman/containers/stats.go
@@ -143,7 +143,9 @@ func stats(cmd *cobra.Command, args []string) error {
func outputStats(reports []define.ContainerStats) error {
headers := report.Headers(define.ContainerStats{}, map[string]string{
"ID": "ID",
+ "UpTime": "CPU TIME",
"CPUPerc": "CPU %",
+ "AVGCPU": "Avg CPU %",
"MemUsage": "MEM USAGE / LIMIT",
"MemUsageBytes": "MEM USAGE / LIMIT",
"MemPerc": "MEM %",
@@ -163,7 +165,7 @@ func outputStats(reports []define.ContainerStats) error {
if report.IsJSON(statsOptions.Format) {
return outputJSON(stats)
}
- format := "{{.ID}}\t{{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.MemPerc}}\t{{.NetIO}}\t{{.BlockIO}}\t{{.PIDS}}\n"
+ format := "{{.ID}}\t{{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.MemPerc}}\t{{.NetIO}}\t{{.BlockIO}}\t{{.PIDS}}\t{{.UpTime}}\t{{.AVGCPU}}\n"
if len(statsOptions.Format) > 0 {
format = report.NormalizeFormat(statsOptions.Format)
}
@@ -203,6 +205,14 @@ func (s *containerStats) CPUPerc() string {
return floatToPercentString(s.CPU)
}
+func (s *containerStats) AVGCPU() string {
+ return floatToPercentString(s.AvgCPU)
+}
+
+func (s *containerStats) Up() string {
+ return (s.UpTime.String())
+}
+
func (s *containerStats) MemPerc() string {
return floatToPercentString(s.ContainerStats.MemPerc)
}
@@ -258,7 +268,9 @@ func outputJSON(stats []containerStats) error {
type jstat struct {
Id string `json:"id"` // nolint
Name string `json:"name"`
+ CPUTime string `json:"cpu_time"`
CpuPercent string `json:"cpu_percent"` // nolint
+ AverageCPU string `json:"avg_cpu"`
MemUsage string `json:"mem_usage"`
MemPerc string `json:"mem_percent"`
NetIO string `json:"net_io"`
@@ -270,7 +282,9 @@ func outputJSON(stats []containerStats) error {
jstats = append(jstats, jstat{
Id: j.ID(),
Name: j.Name,
+ CPUTime: j.Up(),
CpuPercent: j.CPUPerc(),
+ AverageCPU: j.AVGCPU(),
MemUsage: j.MemUsage(),
MemPerc: j.MemPerc(),
NetIO: j.NetIO(),
diff --git a/cmd/podman/pods/create.go b/cmd/podman/pods/create.go
index 735dfa78c..03e3ffaa0 100644
--- a/cmd/podman/pods/create.go
+++ b/cmd/podman/pods/create.go
@@ -5,9 +5,13 @@ import (
"fmt"
"io/ioutil"
"os"
+ "runtime"
+ "sort"
+ "strconv"
"strings"
"github.com/containers/common/pkg/completion"
+ "github.com/containers/common/pkg/sysinfo"
"github.com/containers/podman/v3/cmd/podman/common"
"github.com/containers/podman/v3/cmd/podman/parse"
"github.com/containers/podman/v3/cmd/podman/registry"
@@ -16,6 +20,7 @@ import (
"github.com/containers/podman/v3/pkg/errorhandling"
"github.com/containers/podman/v3/pkg/specgen"
"github.com/containers/podman/v3/pkg/util"
+ "github.com/docker/docker/pkg/parsers"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
@@ -55,6 +60,14 @@ func init() {
common.DefineNetFlags(createCommand)
+ cpusetflagName := "cpuset-cpus"
+ flags.StringVar(&createOptions.CpusetCpus, cpusetflagName, "", "CPUs in which to allow execution")
+ _ = createCommand.RegisterFlagCompletionFunc(cpusetflagName, completion.AutocompleteDefault)
+
+ cpusflagName := "cpus"
+ flags.Float64Var(&createOptions.Cpus, cpusflagName, 0.000, "set amount of CPUs for the pod")
+ _ = createCommand.RegisterFlagCompletionFunc(cpusflagName, completion.AutocompleteDefault)
+
cgroupParentflagName := "cgroup-parent"
flags.StringVar(&createOptions.CGroupParent, cgroupParentflagName, "", "Set parent cgroup for the pod")
_ = createCommand.RegisterFlagCompletionFunc(cgroupParentflagName, completion.AutocompleteDefault)
@@ -185,6 +198,46 @@ func create(cmd *cobra.Command, args []string) error {
}
}
+ numCPU := sysinfo.NumCPU()
+ if numCPU == 0 {
+ numCPU = runtime.NumCPU()
+ }
+ if createOptions.Cpus > float64(numCPU) {
+ createOptions.Cpus = float64(numCPU)
+ }
+ copy := createOptions.CpusetCpus
+ cpuSet := createOptions.Cpus
+ if cpuSet == 0 {
+ cpuSet = float64(sysinfo.NumCPU())
+ }
+ ret, err := parsers.ParseUintList(copy)
+ copy = ""
+ if err != nil {
+ errors.Wrapf(err, "could not parse list")
+ }
+ var vals []int
+ for ind, val := range ret {
+ if val {
+ vals = append(vals, ind)
+ }
+ }
+ sort.Ints(vals)
+ for ind, core := range vals {
+ if core > int(cpuSet) {
+ if copy == "" {
+ copy = "0-" + strconv.Itoa(int(cpuSet))
+ createOptions.CpusetCpus = copy
+ break
+ } else {
+ createOptions.CpusetCpus = copy
+ break
+ }
+ } else if ind != 0 {
+ copy += "," + strconv.Itoa(core)
+ } else {
+ copy = "" + strconv.Itoa(core)
+ }
+ }
response, err := registry.ContainerEngine().PodCreate(context.Background(), createOptions)
if err != nil {
return err
diff --git a/cmd/podman/system/connection/list.go b/cmd/podman/system/connection/list.go
index b0b15b57d..2f74215c1 100644
--- a/cmd/podman/system/connection/list.go
+++ b/cmd/podman/system/connection/list.go
@@ -1,11 +1,13 @@
package connection
import (
+ "fmt"
"os"
"github.com/containers/common/pkg/completion"
"github.com/containers/common/pkg/config"
"github.com/containers/common/pkg/report"
+ "github.com/containers/podman/v3/cmd/podman/common"
"github.com/containers/podman/v3/cmd/podman/registry"
"github.com/containers/podman/v3/cmd/podman/system"
"github.com/containers/podman/v3/cmd/podman/validate"
@@ -14,13 +16,14 @@ import (
var (
listCmd = &cobra.Command{
- Use: "list",
+ Use: "list [options]",
Aliases: []string{"ls"},
Args: validate.NoArgs,
Short: "List destination for the Podman service(s)",
Long: `List destination information for the Podman service(s) in podman configuration`,
Example: `podman system connection list
- podman system connection ls`,
+ podman system connection ls
+ podman system connection ls --format=json`,
ValidArgsFunction: completion.AutocompleteNone,
RunE: list,
TraverseChildren: false,
@@ -32,6 +35,9 @@ func init() {
Command: listCmd,
Parent: system.ConnectionCmd,
})
+
+ listCmd.Flags().String("format", "", "Custom Go template for printing connections")
+ _ = listCmd.RegisterFlagCompletionFunc("format", common.AutocompleteFormat(namedDestination{}))
}
type namedDestination struct {
@@ -39,7 +45,7 @@ type namedDestination struct {
config.Destination
}
-func list(_ *cobra.Command, _ []string) error {
+func list(cmd *cobra.Command, _ []string) error {
cfg, err := config.ReadCustomConfig()
if err != nil {
return err
@@ -71,8 +77,22 @@ func list(_ *cobra.Command, _ []string) error {
rows = append(rows, r)
}
- // TODO: Allow user to override format
- format := "{{range . }}{{.Name}}\t{{.Identity}}\t{{.URI}}\n{{end -}}"
+ format := "{{.Name}}\t{{.Identity}}\t{{.URI}}\n"
+ switch {
+ case report.IsJSON(cmd.Flag("format").Value.String()):
+ buf, err := registry.JSONLibrary().MarshalIndent(rows, "", " ")
+ if err == nil {
+ fmt.Println(string(buf))
+ }
+ return err
+ default:
+ if cmd.Flag("format").Changed {
+ format = cmd.Flag("format").Value.String()
+ format = report.NormalizeFormat(format)
+ }
+ }
+ format = report.EnforceRange(format)
+
tmpl, err := report.NewTemplate("list").Parse(format)
if err != nil {
return err
@@ -84,6 +104,9 @@ func list(_ *cobra.Command, _ []string) error {
}
defer w.Flush()
- _ = tmpl.Execute(w, hdrs)
+ isTable := report.HasTable(cmd.Flag("format").Value.String())
+ if !cmd.Flag("format").Changed || isTable {
+ _ = tmpl.Execute(w, hdrs)
+ }
return tmpl.Execute(w, rows)
}