Skip to content

Commit

Permalink
Show more VM details in the limactl list command
Browse files Browse the repository at this point in the history
Add cpus / memory / disk, in addition to the arch.

Use numbers for the machine-readable representation.

Signed-off-by: Anders F Björklund <[email protected]>
  • Loading branch information
afbjorklund committed Oct 8, 2021
1 parent 1c43407 commit d4526a4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
8 changes: 6 additions & 2 deletions cmd/limactl/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"text/tabwriter"

"github.com/docker/go-units"
"github.com/lima-vm/lima/pkg/store"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -70,7 +71,7 @@ func listAction(cmd *cobra.Command, args []string) error {
}

w := tabwriter.NewWriter(cmd.OutOrStdout(), 4, 8, 4, ' ', 0)
fmt.Fprintln(w, "NAME\tSTATUS\tSSH\tARCH\tDIR")
fmt.Fprintln(w, "NAME\tSTATUS\tSSH\tARCH\tCPUS\tMEMORY\tDISK\tDIR")

if len(instances) == 0 {
logrus.Warn("No instance found. Run `limactl start` to create an instance.")
Expand All @@ -85,11 +86,14 @@ func listAction(cmd *cobra.Command, args []string) error {
if len(inst.Errors) > 0 {
logrus.WithField("errors", inst.Errors).Warnf("instance %q has errors", instName)
}
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n",
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%d\t%s\t%s\t%s\n",
inst.Name,
inst.Status,
fmt.Sprintf("127.0.0.1:%d", inst.SSHLocalPort),
inst.Arch,
inst.CPUs,
units.BytesSize(inst.Memory),
units.BytesSize(inst.Disk),
inst.Dir,
)
}
Expand Down
22 changes: 18 additions & 4 deletions pkg/store/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"syscall"
"time"

"github.com/docker/go-units"
hostagentclient "github.com/lima-vm/lima/pkg/hostagent/api/client"
"github.com/lima-vm/lima/pkg/limayaml"
"github.com/lima-vm/lima/pkg/store/filenames"
Expand All @@ -26,10 +27,14 @@ const (
)

type Instance struct {
Name string `json:"name"`
Status Status `json:"status"`
Dir string `json:"dir"`
Arch limayaml.Arch `json:"arch"`
Name string `json:"name"`
Status Status `json:"status"`
Dir string `json:"dir"`
Arch limayaml.Arch `json:"arch"`
CPUs int `json:"cpus,omitempty"`
Memory float64 `json:"memory,omitempty"` // bytes
Disk float64 `json:"disk,omitempty"` // bytes

Networks []limayaml.Network `json:"network,omitempty"`
SSHLocalPort int `json:"sshLocalPort,omitempty"`
HostAgentPID int `json:"hostAgentPID,omitempty"`
Expand Down Expand Up @@ -68,6 +73,15 @@ func Inspect(instName string) (*Instance, error) {
}
inst.Dir = instDir
inst.Arch = y.Arch
inst.CPUs = y.CPUs
memory, err := units.RAMInBytes(y.Memory)
if err == nil {
inst.Memory = float64(memory)
}
disk, err := units.RAMInBytes(y.Disk)
if err == nil {
inst.Disk = float64(disk)
}
inst.Networks = y.Networks
inst.SSHLocalPort = y.SSH.LocalPort // maybe 0

Expand Down

0 comments on commit d4526a4

Please sign in to comment.