Skip to content

Commit 1dba601

Browse files
Merge pull request #11691 from afbjorklund/machine-list
Add more information about the VM to podman machine list
2 parents 626df0a + 0baee2c commit 1dba601

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

cmd/podman/machine/list.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@ type listFlagType struct {
4040
}
4141

4242
type machineReporter struct {
43-
Name string
44-
Created string
45-
LastUp string
46-
VMType string
43+
Name string
44+
Created string
45+
LastUp string
46+
VMType string
47+
CPUs uint64
48+
Memory string
49+
DiskSize string
4750
}
4851

4952
func init() {
@@ -54,7 +57,7 @@ func init() {
5457

5558
flags := lsCmd.Flags()
5659
formatFlagName := "format"
57-
flags.StringVar(&listFlag.format, formatFlagName, "{{.Name}}\t{{.VMType}}\t{{.Created}}\t{{.LastUp}}\n", "Format volume output using Go template")
60+
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")
5861
_ = lsCmd.RegisterFlagCompletionFunc(formatFlagName, completion.AutocompleteNone)
5962
flags.BoolVar(&listFlag.noHeading, "noheading", false, "Do not print headers")
6063
}
@@ -85,8 +88,11 @@ func list(cmd *cobra.Command, args []string) error {
8588

8689
func outputTemplate(cmd *cobra.Command, responses []*machineReporter) error {
8790
headers := report.Headers(machineReporter{}, map[string]string{
88-
"LastUp": "LAST UP",
89-
"VmType": "VM TYPE",
91+
"LastUp": "LAST UP",
92+
"VmType": "VM TYPE",
93+
"CPUs": "CPUS",
94+
"Memory": "MEMORY",
95+
"DiskSize": "DISK SIZE",
9096
})
9197

9298
row := report.NormalizeFormat(listFlag.format)
@@ -136,6 +142,9 @@ func toHumanFormat(vms []*machine.ListResponse) ([]*machineReporter, error) {
136142
}
137143
response.Created = units.HumanDuration(time.Since(vm.CreatedAt)) + " ago"
138144
response.VMType = vm.VMType
145+
response.CPUs = vm.CPUs
146+
response.Memory = units.HumanSize(float64(vm.Memory) * units.MiB)
147+
response.DiskSize = units.HumanSize(float64(vm.DiskSize) * units.GiB)
139148

140149
humanResponses = append(humanResponses, response)
141150
}

pkg/machine/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ type ListResponse struct {
5858
LastUp time.Time
5959
Running bool
6060
VMType string
61+
CPUs uint64
62+
Memory uint64
63+
DiskSize uint64
6164
}
6265

6366
type SSHOptions struct {

pkg/machine/qemu/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ type MachineVM struct {
1717
ImagePath string
1818
// Memory in megabytes assigned to the vm
1919
Memory uint64
20+
// Disk size in gigabytes assigned to the vm
21+
DiskSize uint64
2022
// Name of the vm
2123
Name string
2224
// SSH port for user networking

pkg/machine/qemu/machine.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func NewMachine(opts machine.InitOptions) (machine.VM, error) {
6464

6565
vm.CPUs = opts.CPUS
6666
vm.Memory = opts.Memory
67+
vm.DiskSize = opts.DiskSize
6768

6869
// Look up the executable
6970
execPath, err := exec.LookPath(QemuCommand)
@@ -574,6 +575,9 @@ func GetVMInfos() ([]*machine.ListResponse, error) {
574575

575576
listEntry.Name = vm.Name
576577
listEntry.VMType = "qemu"
578+
listEntry.CPUs = vm.CPUs
579+
listEntry.Memory = vm.Memory
580+
listEntry.DiskSize = vm.DiskSize
577581
fi, err := os.Stat(fullPath)
578582
if err != nil {
579583
return err

0 commit comments

Comments
 (0)