Skip to content

Commit 76be255

Browse files
committed
add limactl info to show diagnostic information
Signed-off-by: Akihiro Suda <[email protected]>
1 parent 721f7d0 commit 76be255

File tree

4 files changed

+95
-51
lines changed

4 files changed

+95
-51
lines changed

cmd/limactl/info.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
7+
"github.com/lima-vm/lima/pkg/limayaml"
8+
"github.com/lima-vm/lima/pkg/version"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
func newInfoCommand() *cobra.Command {
13+
infoCommand := &cobra.Command{
14+
Use: "info",
15+
Short: "Show diagnostic information",
16+
Args: cobra.NoArgs,
17+
RunE: infoAction,
18+
}
19+
return infoCommand
20+
}
21+
22+
type Info struct {
23+
Version string `json:"version"`
24+
DefaultTemplate *limayaml.LimaYAML `json:"defaultTemplate"`
25+
// TODO: add diagnostic info of QEMU
26+
}
27+
28+
func infoAction(cmd *cobra.Command, args []string) error {
29+
y, err := limayaml.Load(limayaml.DefaultTemplate, "")
30+
if err != nil {
31+
return err
32+
}
33+
info := &Info{
34+
Version: version.Version,
35+
DefaultTemplate: y,
36+
}
37+
j, err := json.MarshalIndent(info, "", " ")
38+
if err != nil {
39+
return err
40+
}
41+
_, err = fmt.Fprintln(cmd.OutOrStdout(), string(j))
42+
return err
43+
}

cmd/limactl/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func newApp() *cobra.Command {
7979
newSudoersCommand(),
8080
newPruneCommand(),
8181
newHostagentCommand(),
82+
newInfoCommand(),
8283
)
8384
return rootCmd
8485
}

pkg/limayaml/default.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ containerd:
7171
# Default: true
7272
user: true
7373
# # Override containerd archive
74-
# # Default: hard-coded URL with hard-coded digest
74+
# # Default: hard-coded URL with hard-coded digest (see the output of `limactl info | jq .defaultTemplate.containerd.archives`)
7575
# archives:
7676
# - location: "~/Downloads/nerdctl-full-X.Y.Z-linux-amd64.tar.gz"
7777
# arch: "x86_64"

pkg/limayaml/limayaml.go

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@ import (
77
)
88

99
type LimaYAML struct {
10-
Arch Arch `yaml:"arch,omitempty"`
11-
Images []File `yaml:"images"` // REQUIRED
12-
CPUs int `yaml:"cpus,omitempty"`
13-
Memory string `yaml:"memory,omitempty"` // go-units.RAMInBytes
14-
Disk string `yaml:"disk,omitempty"` // go-units.RAMInBytes
15-
Mounts []Mount `yaml:"mounts,omitempty"`
16-
SSH SSH `yaml:"ssh,omitempty"` // REQUIRED (FIXME)
17-
Firmware Firmware `yaml:"firmware,omitempty"`
18-
Video Video `yaml:"video,omitempty"`
19-
Provision []Provision `yaml:"provision,omitempty"`
20-
Containerd Containerd `yaml:"containerd,omitempty"`
21-
Probes []Probe `yaml:"probes,omitempty"`
22-
PortForwards []PortForward `yaml:"portForwards,omitempty"`
23-
Networks []Network `yaml:"networks,omitempty"`
24-
Network NetworkDeprecated `yaml:"network,omitempty"` // DEPRECATED, use `networks` instead
25-
Env map[string]string `yaml:"env,omitempty"`
26-
DNS []net.IP `yaml:"dns,omitempty"`
27-
UseHostResolver *bool `yaml:"useHostResolver,omitempty"`
10+
Arch Arch `yaml:"arch,omitempty" json:"arch,omitempty"`
11+
Images []File `yaml:"images" json:"images"` // REQUIRED
12+
CPUs int `yaml:"cpus,omitempty" json:"cpus,omitempty"`
13+
Memory string `yaml:"memory,omitempty" json:"memory,omitempty"` // go-units.RAMInBytes
14+
Disk string `yaml:"disk,omitempty" json:"disk,omitempty"` // go-units.RAMInBytes
15+
Mounts []Mount `yaml:"mounts,omitempty" json:"mounts,omitempty"`
16+
SSH SSH `yaml:"ssh,omitempty" json:"ssh,omitempty"` // REQUIRED (FIXME)
17+
Firmware Firmware `yaml:"firmware,omitempty" json:"firmware,omitempty"`
18+
Video Video `yaml:"video,omitempty" json:"video,omitempty"`
19+
Provision []Provision `yaml:"provision,omitempty" json:"provision,omitempty"`
20+
Containerd Containerd `yaml:"containerd,omitempty" json:"containerd,omitempty"`
21+
Probes []Probe `yaml:"probes,omitempty" json:"probes,omitempty"`
22+
PortForwards []PortForward `yaml:"portForwards,omitempty" json:"portForwards,omitempty"`
23+
Networks []Network `yaml:"networks,omitempty" json:"networks,omitempty"`
24+
Network NetworkDeprecated `yaml:"network,omitempty" json:"network,omitempty"` // DEPRECATED, use `networks` instead
25+
Env map[string]string `yaml:"env,omitempty" json:"env,omitempty"`
26+
DNS []net.IP `yaml:"dns,omitempty" json:"dns,omitempty"`
27+
UseHostResolver *bool `yaml:"useHostResolver,omitempty" json:"useHostResolver,omitempty"`
2828
}
2929

3030
type Arch = string
@@ -35,33 +35,33 @@ const (
3535
)
3636

3737
type File struct {
38-
Location string `yaml:"location"` // REQUIRED
39-
Arch Arch `yaml:"arch,omitempty"`
40-
Digest digest.Digest `yaml:"digest,omitempty"`
38+
Location string `yaml:"location" json:"location"` // REQUIRED
39+
Arch Arch `yaml:"arch,omitempty" json:"arch,omitempty"`
40+
Digest digest.Digest `yaml:"digest,omitempty" json:"digest,omitempty"`
4141
}
4242

4343
type Mount struct {
44-
Location string `yaml:"location"` // REQUIRED
45-
Writable bool `yaml:"writable,omitempty"`
44+
Location string `yaml:"location" json:"location"` // REQUIRED
45+
Writable bool `yaml:"writable,omitempty" json:"writable,omitempty"`
4646
}
4747

4848
type SSH struct {
49-
LocalPort int `yaml:"localPort,omitempty"` // REQUIRED (FIXME: auto assign)
49+
LocalPort int `yaml:"localPort,omitempty" json:"localPort,omitempty"` // REQUIRED (FIXME: auto assign)
5050

5151
// LoadDotSSHPubKeys loads ~/.ssh/*.pub in addition to $LIMA_HOME/_config/user.pub .
5252
// Default: true
53-
LoadDotSSHPubKeys *bool `yaml:"loadDotSSHPubKeys,omitempty"`
53+
LoadDotSSHPubKeys *bool `yaml:"loadDotSSHPubKeys,omitempty" json:"loadDotSSHPubKeys,omitempty"`
5454
}
5555

5656
type Firmware struct {
5757
// LegacyBIOS disables UEFI if set.
5858
// LegacyBIOS is ignored for aarch64.
59-
LegacyBIOS bool `yaml:"legacyBIOS,omitempty"`
59+
LegacyBIOS bool `yaml:"legacyBIOS,omitempty" json:"legacyBIOS,omitempty"`
6060
}
6161

6262
type Video struct {
6363
// Display is a QEMU display string
64-
Display string `yaml:"display,omitempty"`
64+
Display string `yaml:"display,omitempty" json:"display,omitempty"`
6565
}
6666

6767
type ProvisionMode = string
@@ -72,14 +72,14 @@ const (
7272
)
7373

7474
type Provision struct {
75-
Mode ProvisionMode `yaml:"mode"` // default: "system"
76-
Script string `yaml:"script"`
75+
Mode ProvisionMode `yaml:"mode" json:"mode"` // default: "system"
76+
Script string `yaml:"script" json:"script"`
7777
}
7878

7979
type Containerd struct {
80-
System *bool `yaml:"system,omitempty"` // default: false
81-
User *bool `yaml:"user,omitempty"` // default: true
82-
Archives []File `yaml:"archives,omitempty"` // default: see defaultContainerdArchives
80+
System *bool `yaml:"system,omitempty" json:"system,omitempty"` // default: false
81+
User *bool `yaml:"user,omitempty" json:"user,omitempty"` // default: true
82+
Archives []File `yaml:"archives,omitempty" json:"archives,omitempty"` // default: see defaultContainerdArchives
8383
}
8484

8585
type ProbeMode = string
@@ -102,25 +102,25 @@ const (
102102
)
103103

104104
type PortForward struct {
105-
GuestIP net.IP `yaml:"guestIP,omitempty"`
106-
GuestPort int `yaml:"guestPort,omitempty"`
107-
GuestPortRange [2]int `yaml:"guestPortRange,omitempty"`
108-
HostIP net.IP `yaml:"hostIP,omitempty"`
109-
HostPort int `yaml:"hostPort,omitempty"`
110-
HostPortRange [2]int `yaml:"hostPortRange,omitempty"`
111-
Proto Proto `yaml:"proto,omitempty"`
112-
Ignore bool `yaml:"ignore,omitempty"`
105+
GuestIP net.IP `yaml:"guestIP,omitempty" json:"guestIP,omitempty"`
106+
GuestPort int `yaml:"guestPort,omitempty" json:"guestPort,omitempty"`
107+
GuestPortRange [2]int `yaml:"guestPortRange,omitempty" json:"guestPortRange,omitempty"`
108+
HostIP net.IP `yaml:"hostIP,omitempty" json:"hostIP,omitempty"`
109+
HostPort int `yaml:"hostPort,omitempty" json:"hostPort,omitempty"`
110+
HostPortRange [2]int `yaml:"hostPortRange,omitempty" json:"hostPortRange,omitempty"`
111+
Proto Proto `yaml:"proto,omitempty" json:"proto,omitempty"`
112+
Ignore bool `yaml:"ignore,omitempty" json:"ignore,omitempty"`
113113
}
114114

115115
type Network struct {
116116
// `Lima` and `VNL` are mutually exclusive; exactly one is required
117-
Lima string `yaml:"lima,omitempty"`
117+
Lima string `yaml:"lima,omitempty" json:"lima,omitempty"`
118118
// VNL is a Virtual Network Locator (https://github.com/rd235/vdeplug4/commit/089984200f447abb0e825eb45548b781ba1ebccd).
119119
// On macOS, only VDE2-compatible form (optionally with vde:// prefix) is supported.
120-
VNL string `yaml:"vnl,omitempty"`
121-
SwitchPort uint16 `yaml:"switchPort,omitempty"` // VDE Switch port, not TCP/UDP port (only used by VDE networking)
122-
MACAddress string `yaml:"macAddress,omitempty"`
123-
Interface string `yaml:"interface,omitempty"`
120+
VNL string `yaml:"vnl,omitempty" json:"vnl,omitempty"`
121+
SwitchPort uint16 `yaml:"switchPort,omitempty" json:"switchPort,omitempty"` // VDE Switch port, not TCP/UDP port (only used by VDE networking)
122+
MACAddress string `yaml:"macAddress,omitempty" json:"macAddress,omitempty"`
123+
Interface string `yaml:"interface,omitempty" json:"interface,omitempty"`
124124
}
125125

126126
// DEPRECATED types below
@@ -129,14 +129,14 @@ type Network struct {
129129
// and to avoid accidental usage in new code.
130130

131131
type NetworkDeprecated struct {
132-
VDEDeprecated []VDEDeprecated `yaml:"vde,omitempty"`
132+
VDEDeprecated []VDEDeprecated `yaml:"vde,omitempty" json:"vde,omitempty"`
133133
// migrate will be true when `network.VDE` has been copied to `networks` by FillDefaults()
134134
migrated bool
135135
}
136136

137137
type VDEDeprecated struct {
138-
VNL string `yaml:"vnl,omitempty"`
139-
SwitchPort uint16 `yaml:"switchPort,omitempty"` // VDE Switch port, not TCP/UDP port
140-
MACAddress string `yaml:"macAddress,omitempty"`
141-
Name string `yaml:"name,omitempty"`
138+
VNL string `yaml:"vnl,omitempty" json:"vnl,omitempty"`
139+
SwitchPort uint16 `yaml:"switchPort,omitempty" json:"switchPort,omitempty"` // VDE Switch port, not TCP/UDP port
140+
MACAddress string `yaml:"macAddress,omitempty" json:"macAddress,omitempty"`
141+
Name string `yaml:"name,omitempty" json:"name,omitempty"`
142142
}

0 commit comments

Comments
 (0)