Skip to content

Commit c7764c3

Browse files
committed
pkg/hostagent/events: Add GuestIP net.IP field to Status
Support printing "Guest IP Address: %s" on `limactl start` Signed-off-by: Norio Nomura <norio.nomura@gmail.com> # Conflicts: # pkg/hostagent/requirements.go
1 parent 0b51cab commit c7764c3

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

pkg/hostagent/events/events.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package events
55

66
import (
7+
"net"
78
"time"
89
)
910

@@ -16,6 +17,9 @@ type Status struct {
1617

1718
Errors []string `json:"errors,omitempty"`
1819

20+
// Guest IP address directly accessible from the host.
21+
GuestIP net.IP `json:"guestIP,omitempty"`
22+
// SSH local port on the host forwarded to the guest's port 22.
1923
SSHLocalPort int `json:"sshLocalPort,omitempty"`
2024

2125
// Cloud-init progress information

pkg/hostagent/hostagent.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,17 @@ func (a *HostAgent) emitCloudInitProgressEvent(ctx context.Context, progress *ev
363363
a.emitEvent(ctx, ev)
364364
}
365365

366+
func (a *HostAgent) emitGuestIPEvent(ctx context.Context, ip string) {
367+
a.statusMu.RLock()
368+
currentStatus := a.currentStatus
369+
a.statusMu.RUnlock()
370+
371+
currentStatus.GuestIP = net.ParseIP(ip)
372+
373+
ev := events.Event{Status: currentStatus}
374+
a.emitEvent(ctx, ev)
375+
}
376+
366377
func generatePassword(length int) (string, error) {
367378
// avoid any special symbols, to make it easier to copy/paste
368379
return password.Generate(length, length/4, 0, false, false)

pkg/hostagent/requirements.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,5 +391,6 @@ func (a *HostAgent) detectGuestIPAddress(stdout string) error {
391391
a.guestIPv6 = guestIPv6
392392
a.guestIPMu.Unlock()
393393
ctx := context.Background()
394+
a.emitGuestIPEvent(ctx, a.GuestIP().String())
394395
return a.WriteSSHConfigFile(ctx)
395396
}

pkg/instance/start.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ func watchHostAgentEvents(ctx context.Context, inst *limatype.Instance, haStdout
278278

279279
var (
280280
printedSSHLocalPort bool
281+
printedGuestIP bool
281282
receivedRunningEvent bool
282283
cloudInitCompleted bool
283284
err error
@@ -292,6 +293,14 @@ func watchHostAgentEvents(ctx context.Context, inst *limatype.Instance, haStdout
292293
inst.SSHLocalPort = ev.Status.SSHLocalPort
293294
}
294295

296+
if !printedGuestIP && ev.Status.GuestIP != nil {
297+
logrus.Infof("Guest IP Address: %s", ev.Status.GuestIP.String())
298+
printedGuestIP = true
299+
300+
// Update the instance's Guest IP address
301+
inst.GuestIP = ev.Status.GuestIP
302+
}
303+
295304
if showProgress && ev.Status.CloudInitProgress != nil {
296305
progress := ev.Status.CloudInitProgress
297306
if progress.Active && progress.LogLine == "" {

0 commit comments

Comments
 (0)