mirror of
https://github.com/containers/podman.git
synced 2025-06-21 17:38:12 +08:00
Merge pull request #11691 from afbjorklund/machine-list
Add more information about the VM to podman machine list
This commit is contained in:
@ -44,6 +44,9 @@ type machineReporter struct {
|
|||||||
Created string
|
Created string
|
||||||
LastUp string
|
LastUp string
|
||||||
VMType string
|
VMType string
|
||||||
|
CPUs uint64
|
||||||
|
Memory string
|
||||||
|
DiskSize string
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -54,7 +57,7 @@ func init() {
|
|||||||
|
|
||||||
flags := lsCmd.Flags()
|
flags := lsCmd.Flags()
|
||||||
formatFlagName := "format"
|
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}}\t{{.DiskSize}}\n", "Format volume output using Go template")
|
||||||
_ = lsCmd.RegisterFlagCompletionFunc(formatFlagName, completion.AutocompleteNone)
|
_ = lsCmd.RegisterFlagCompletionFunc(formatFlagName, completion.AutocompleteNone)
|
||||||
flags.BoolVar(&listFlag.noHeading, "noheading", false, "Do not print headers")
|
flags.BoolVar(&listFlag.noHeading, "noheading", false, "Do not print headers")
|
||||||
}
|
}
|
||||||
@ -87,6 +90,9 @@ func outputTemplate(cmd *cobra.Command, responses []*machineReporter) error {
|
|||||||
headers := report.Headers(machineReporter{}, map[string]string{
|
headers := report.Headers(machineReporter{}, map[string]string{
|
||||||
"LastUp": "LAST UP",
|
"LastUp": "LAST UP",
|
||||||
"VmType": "VM TYPE",
|
"VmType": "VM TYPE",
|
||||||
|
"CPUs": "CPUS",
|
||||||
|
"Memory": "MEMORY",
|
||||||
|
"DiskSize": "DISK SIZE",
|
||||||
})
|
})
|
||||||
|
|
||||||
row := report.NormalizeFormat(listFlag.format)
|
row := report.NormalizeFormat(listFlag.format)
|
||||||
@ -136,6 +142,9 @@ func toHumanFormat(vms []*machine.ListResponse) ([]*machineReporter, error) {
|
|||||||
}
|
}
|
||||||
response.Created = units.HumanDuration(time.Since(vm.CreatedAt)) + " ago"
|
response.Created = units.HumanDuration(time.Since(vm.CreatedAt)) + " ago"
|
||||||
response.VMType = vm.VMType
|
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)
|
humanResponses = append(humanResponses, response)
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,9 @@ type ListResponse struct {
|
|||||||
LastUp time.Time
|
LastUp time.Time
|
||||||
Running bool
|
Running bool
|
||||||
VMType string
|
VMType string
|
||||||
|
CPUs uint64
|
||||||
|
Memory uint64
|
||||||
|
DiskSize uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
type SSHOptions struct {
|
type SSHOptions struct {
|
||||||
|
@ -17,6 +17,8 @@ type MachineVM struct {
|
|||||||
ImagePath string
|
ImagePath string
|
||||||
// Memory in megabytes assigned to the vm
|
// Memory in megabytes assigned to the vm
|
||||||
Memory uint64
|
Memory uint64
|
||||||
|
// Disk size in gigabytes assigned to the vm
|
||||||
|
DiskSize uint64
|
||||||
// Name of the vm
|
// Name of the vm
|
||||||
Name string
|
Name string
|
||||||
// SSH port for user networking
|
// SSH port for user networking
|
||||||
|
@ -64,6 +64,7 @@ func NewMachine(opts machine.InitOptions) (machine.VM, error) {
|
|||||||
|
|
||||||
vm.CPUs = opts.CPUS
|
vm.CPUs = opts.CPUS
|
||||||
vm.Memory = opts.Memory
|
vm.Memory = opts.Memory
|
||||||
|
vm.DiskSize = opts.DiskSize
|
||||||
|
|
||||||
// Look up the executable
|
// Look up the executable
|
||||||
execPath, err := exec.LookPath(QemuCommand)
|
execPath, err := exec.LookPath(QemuCommand)
|
||||||
@ -574,6 +575,9 @@ func GetVMInfos() ([]*machine.ListResponse, error) {
|
|||||||
|
|
||||||
listEntry.Name = vm.Name
|
listEntry.Name = vm.Name
|
||||||
listEntry.VMType = "qemu"
|
listEntry.VMType = "qemu"
|
||||||
|
listEntry.CPUs = vm.CPUs
|
||||||
|
listEntry.Memory = vm.Memory
|
||||||
|
listEntry.DiskSize = vm.DiskSize
|
||||||
fi, err := os.Stat(fullPath)
|
fi, err := os.Stat(fullPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Reference in New Issue
Block a user