Show image names in vm list and raise default memory
Make `banger vm list` easier to scan by resolving each VM image ID back to the registered image name when that mapping is available, while still falling back to a short ID for unknown images. Raise the shared default VM memory from 1024 MiB to 2048 MiB so new VMs, CLI help, and daemon-side defaults all align on a 2 GiB baseline. Add CLI coverage for the image-name rendering path and validate the change with go test ./..., make build, `banger vm list`, and `banger vm create --help`.
This commit is contained in:
parent
3b7e77a2de
commit
786d235f7f
3 changed files with 98 additions and 18 deletions
|
|
@ -477,24 +477,11 @@ func newVMListCommand() *cobra.Command {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
w := tabwriter.NewWriter(cmd.OutOrStdout(), 0, 8, 2, ' ', 0)
|
||||
fmt.Fprintln(w, "ID\tNAME\tSTATE\tIMAGE\tIP\tVCPU\tMEM\tDISK\tCREATED")
|
||||
for _, vm := range result.VMs {
|
||||
fmt.Fprintf(
|
||||
w,
|
||||
"%s\t%s\t%s\t%s\t%s\t%d\t%d MiB\t%s\t%s\n",
|
||||
shortID(vm.ID),
|
||||
vm.Name,
|
||||
vm.State,
|
||||
shortID(vm.ImageID),
|
||||
vm.Runtime.GuestIP,
|
||||
vm.Spec.VCPUCount,
|
||||
vm.Spec.MemoryMiB,
|
||||
model.FormatSizeBytes(vm.Spec.WorkDiskSizeBytes),
|
||||
relativeTime(vm.CreatedAt),
|
||||
)
|
||||
images, err := rpc.Call[api.ImageListResult](cmd.Context(), layout.SocketPath, "image.list", api.Empty{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return w.Flush()
|
||||
return printVMListTable(cmd.OutOrStdout(), result.VMs, imageNameIndex(images.Images))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -1308,11 +1295,51 @@ func printVMSummary(out anyWriter, vm model.VMRecord) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func printVMListTable(out anyWriter, vms []model.VMRecord, imageNames map[string]string) error {
|
||||
w := tabwriter.NewWriter(out, 0, 8, 2, ' ', 0)
|
||||
if _, err := fmt.Fprintln(w, "ID\tNAME\tSTATE\tIMAGE\tIP\tVCPU\tMEM\tDISK\tCREATED"); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, vm := range vms {
|
||||
if _, err := fmt.Fprintf(
|
||||
w,
|
||||
"%s\t%s\t%s\t%s\t%s\t%d\t%d MiB\t%s\t%s\n",
|
||||
shortID(vm.ID),
|
||||
vm.Name,
|
||||
vm.State,
|
||||
vmImageLabel(vm.ImageID, imageNames),
|
||||
vm.Runtime.GuestIP,
|
||||
vm.Spec.VCPUCount,
|
||||
vm.Spec.MemoryMiB,
|
||||
model.FormatSizeBytes(vm.Spec.WorkDiskSizeBytes),
|
||||
relativeTime(vm.CreatedAt),
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return w.Flush()
|
||||
}
|
||||
|
||||
func printImageSummary(out anyWriter, image model.Image) error {
|
||||
_, err := fmt.Fprintf(out, "%s\t%s\t%t\t%s\n", shortID(image.ID), image.Name, image.Managed, image.RootfsPath)
|
||||
return err
|
||||
}
|
||||
|
||||
func imageNameIndex(images []model.Image) map[string]string {
|
||||
index := make(map[string]string, len(images))
|
||||
for _, image := range images {
|
||||
index[image.ID] = image.Name
|
||||
}
|
||||
return index
|
||||
}
|
||||
|
||||
func vmImageLabel(imageID string, imageNames map[string]string) string {
|
||||
if name := strings.TrimSpace(imageNames[imageID]); name != "" {
|
||||
return name
|
||||
}
|
||||
return shortID(imageID)
|
||||
}
|
||||
|
||||
func printImageListTable(out anyWriter, images []model.Image) error {
|
||||
w := tabwriter.NewWriter(out, 0, 8, 2, ' ', 0)
|
||||
if _, err := fmt.Fprintln(w, "ID\tNAME\tMANAGED\tROOTFS SIZE\tCREATED"); err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue