From 911298252ad38b040c261a0055931795f19b222b Mon Sep 17 00:00:00 2001 From: Anders F Björklund Date: Wed, 22 Sep 2021 12:29:24 +0200 Subject: Show cpus and memory in machine list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [NO TESTS NEEDED] Signed-off-by: Anders F Björklund --- cmd/podman/machine/list.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'cmd') diff --git a/cmd/podman/machine/list.go b/cmd/podman/machine/list.go index d4360bb9b..b9dc62d6d 100644 --- a/cmd/podman/machine/list.go +++ b/cmd/podman/machine/list.go @@ -44,6 +44,8 @@ type machineReporter struct { Created string LastUp string VMType string + CPUs uint64 + Memory string } func init() { @@ -54,7 +56,7 @@ func init() { flags := lsCmd.Flags() formatFlagName := "format" - flags.StringVar(&listFlag.format, formatFlagName, "{{.Name}}\t{{.VMType}}\t{{.Created}}\t{{.LastUp}}\n", "Format volume output using Go template") + flags.StringVar(&listFlag.format, formatFlagName, "{{.Name}}\t{{.VMType}}\t{{.Created}}\t{{.LastUp}}\t{{.CPUs}}\t{{.Memory}}\n", "Format volume output using Go template") _ = lsCmd.RegisterFlagCompletionFunc(formatFlagName, completion.AutocompleteNone) flags.BoolVar(&listFlag.noHeading, "noheading", false, "Do not print headers") } @@ -87,6 +89,8 @@ func outputTemplate(cmd *cobra.Command, responses []*machineReporter) error { headers := report.Headers(machineReporter{}, map[string]string{ "LastUp": "LAST UP", "VmType": "VM TYPE", + "CPUs": "CPUS", + "Memory": "MEMORY", }) row := report.NormalizeFormat(listFlag.format) @@ -136,6 +140,8 @@ func toHumanFormat(vms []*machine.ListResponse) ([]*machineReporter, error) { } response.Created = units.HumanDuration(time.Since(vm.CreatedAt)) + " ago" response.VMType = vm.VMType + response.CPUs = vm.CPUs + response.Memory = units.HumanSize(float64(vm.Memory) * units.MiB) humanResponses = append(humanResponses, response) } -- cgit v1.2.3-54-g00ecf From 0baee2cc33000aa8d311d987308849cb2e8420d9 Mon Sep 17 00:00:00 2001 From: Anders F Björklund Date: Wed, 22 Sep 2021 12:29:28 +0200 Subject: Also show the (initial) disk size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [NO TESTS NEEDED] Signed-off-by: Anders F Björklund --- cmd/podman/machine/list.go | 25 ++++++++++++++----------- pkg/machine/config.go | 1 + pkg/machine/qemu/config.go | 2 ++ pkg/machine/qemu/machine.go | 2 ++ 4 files changed, 19 insertions(+), 11 deletions(-) (limited to 'cmd') diff --git a/cmd/podman/machine/list.go b/cmd/podman/machine/list.go index b9dc62d6d..fe9d712e3 100644 --- a/cmd/podman/machine/list.go +++ b/cmd/podman/machine/list.go @@ -40,12 +40,13 @@ type listFlagType struct { } type machineReporter struct { - Name string - Created string - LastUp string - VMType string - CPUs uint64 - Memory string + Name string + Created string + LastUp string + VMType string + CPUs uint64 + Memory string + DiskSize string } func init() { @@ -56,7 +57,7 @@ func init() { flags := lsCmd.Flags() formatFlagName := "format" - flags.StringVar(&listFlag.format, formatFlagName, "{{.Name}}\t{{.VMType}}\t{{.Created}}\t{{.LastUp}}\t{{.CPUs}}\t{{.Memory}}\n", "Format volume output using Go template") + flags.StringVar(&listFlag.format, formatFlagName, "{{.Name}}\t{{.VMType}}\t{{.Created}}\t{{.LastUp}}\t{{.CPUs}}\t{{.Memory}}\t{{.DiskSize}}\n", "Format volume output using Go template") _ = lsCmd.RegisterFlagCompletionFunc(formatFlagName, completion.AutocompleteNone) flags.BoolVar(&listFlag.noHeading, "noheading", false, "Do not print headers") } @@ -87,10 +88,11 @@ func list(cmd *cobra.Command, args []string) error { func outputTemplate(cmd *cobra.Command, responses []*machineReporter) error { headers := report.Headers(machineReporter{}, map[string]string{ - "LastUp": "LAST UP", - "VmType": "VM TYPE", - "CPUs": "CPUS", - "Memory": "MEMORY", + "LastUp": "LAST UP", + "VmType": "VM TYPE", + "CPUs": "CPUS", + "Memory": "MEMORY", + "DiskSize": "DISK SIZE", }) row := report.NormalizeFormat(listFlag.format) @@ -142,6 +144,7 @@ func toHumanFormat(vms []*machine.ListResponse) ([]*machineReporter, error) { response.VMType = vm.VMType response.CPUs = vm.CPUs response.Memory = units.HumanSize(float64(vm.Memory) * units.MiB) + response.DiskSize = units.HumanSize(float64(vm.DiskSize) * units.GiB) humanResponses = append(humanResponses, response) } diff --git a/pkg/machine/config.go b/pkg/machine/config.go index 583eacbaa..3ff5c7fe7 100644 --- a/pkg/machine/config.go +++ b/pkg/machine/config.go @@ -60,6 +60,7 @@ type ListResponse struct { VMType string CPUs uint64 Memory uint64 + DiskSize uint64 } type SSHOptions struct { diff --git a/pkg/machine/qemu/config.go b/pkg/machine/qemu/config.go index 3d0fa4094..9f5f45b58 100644 --- a/pkg/machine/qemu/config.go +++ b/pkg/machine/qemu/config.go @@ -17,6 +17,8 @@ type MachineVM struct { ImagePath string // Memory in megabytes assigned to the vm Memory uint64 + // Disk size in gigabytes assigned to the vm + DiskSize uint64 // Name of the vm Name string // SSH port for user networking diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go index 9dfdacb09..a125506a1 100644 --- a/pkg/machine/qemu/machine.go +++ b/pkg/machine/qemu/machine.go @@ -64,6 +64,7 @@ func NewMachine(opts machine.InitOptions) (machine.VM, error) { vm.CPUs = opts.CPUS vm.Memory = opts.Memory + vm.DiskSize = opts.DiskSize // Look up the executable execPath, err := exec.LookPath(QemuCommand) @@ -576,6 +577,7 @@ func GetVMInfos() ([]*machine.ListResponse, error) { listEntry.VMType = "qemu" listEntry.CPUs = vm.CPUs listEntry.Memory = vm.Memory + listEntry.DiskSize = vm.DiskSize fi, err := os.Stat(fullPath) if err != nil { return err -- cgit v1.2.3-54-g00ecf