Skip to content

Commit

Permalink
Add host.lima.internal to /etc/hosts
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Dubois <[email protected]>
  • Loading branch information
jandubois committed Aug 4, 2021
1 parent fbb94ed commit 50727a5
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 deletions.
4 changes: 4 additions & 0 deletions pkg/cidata/cidata.TEMPLATE.d/boot/03-etc-hosts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -eux -o pipefail

echo -e "${LIMA_SLIRP_GATEWAY}\thost.lima.internal" >>/etc/hosts
1 change: 1 addition & 0 deletions pkg/cidata/cidata.TEMPLATE.d/lima.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
LIMA_CIDATA_USER={{ .User }}
LIMA_CIDATA_UID={{ .UID }}
LIMA_CIDATA_MOUNTS={{ len .Mounts }}
LIMA_SLIRP_GATEWAY={{ .SlirpGateway }}
{{- range $i, $val := .Mounts}}
LIMA_CIDATA_MOUNTS_{{$i}}_MOUNTPOINT={{$val}}
{{- end}}
Expand Down
9 changes: 5 additions & 4 deletions pkg/cidata/cidata.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML) error {
return err
}
args := TemplateArgs{
Name: name,
User: u.Username,
UID: uid,
Containerd: Containerd{System: *y.Containerd.System, User: *y.Containerd.User},
Name: name,
User: u.Username,
UID: uid,
Containerd: Containerd{System: *y.Containerd.System, User: *y.Containerd.User},
SlirpGateway: qemuconst.SlirpGateway,
}

pubKeys, err := sshutil.DefaultPubKeys(*y.SSH.LoadDotSSHPubKeys)
Expand Down
15 changes: 8 additions & 7 deletions pkg/cidata/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ type Network struct {
Name string
}
type TemplateArgs struct {
Name string // instance name
User string // user name
UID int
SSHPubKeys []string
Mounts []string // abs path, accessible by the User
Containerd Containerd
Networks []Network
Name string // instance name
User string // user name
UID int
SSHPubKeys []string
Mounts []string // abs path, accessible by the User
Containerd Containerd
Networks []Network
SlirpGateway string
}

func ValidateTemplateArgs(args TemplateArgs) error {
Expand Down
4 changes: 3 additions & 1 deletion pkg/qemu/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/AkihiroSuda/lima/pkg/downloader"
"github.com/AkihiroSuda/lima/pkg/iso9660util"
"github.com/AkihiroSuda/lima/pkg/limayaml"
"github.com/AkihiroSuda/lima/pkg/qemu/qemuconst"
"github.com/AkihiroSuda/lima/pkg/store/filenames"
"github.com/docker/go-units"
"github.com/mattn/go-shellwords"
Expand Down Expand Up @@ -194,7 +195,8 @@ func Cmdline(cfg Config) (string, []string, error) {

// Network
// CIDR is intentionally hardcoded to 192.168.5.0/24, as each of QEMU has its own independent slirp network.
args = append(args, "-netdev", fmt.Sprintf("user,id=net0,net=192.168.5.0/24,hostfwd=tcp:127.0.0.1:%d-:22", y.SSH.LocalPort))
args = append(args, "-netdev", fmt.Sprintf("user,id=net0,net=%s,dhcpstart=%s,hostfwd=tcp:127.0.0.1:%d-:22",
qemuconst.SlirpNetwork, qemuconst.SlirpIPAddress, y.SSH.LocalPort))
args = append(args, "-device", "virtio-net-pci,netdev=net0,mac="+limayaml.MACAddress(cfg.InstanceDir))
for i, vde := range y.Network.VDE {
args = append(args, "-netdev", fmt.Sprintf("vde,id=net%d,sock=%s", i+1, vde.URL))
Expand Down
3 changes: 3 additions & 0 deletions pkg/qemu/qemuconst/qemuconst.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ package qemuconst

const (
SlirpNICName = "eth0"
SlirpNetwork = "192.168.5.0/24"
SlirpGateway = "192.168.5.2"
SlirpIPAddress = "192.168.5.15"
)

0 comments on commit 50727a5

Please sign in to comment.