Skip to content

Commit 3681784

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 149d5a0 commit 3681784

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
@@ -362,6 +362,17 @@ func (a *HostAgent) emitCloudInitProgressEvent(ctx context.Context, progress *ev
362362
a.emitEvent(ctx, ev)
363363
}
364364

365+
func (a *HostAgent) emitGuestIPEvent(ctx context.Context, ip string) {
366+
a.statusMu.RLock()
367+
currentStatus := a.currentStatus
368+
a.statusMu.RUnlock()
369+
370+
currentStatus.GuestIP = net.ParseIP(ip)
371+
372+
ev := events.Event{Status: currentStatus}
373+
a.emitEvent(ctx, ev)
374+
}
375+
365376
func generatePassword(length int) (string, error) {
366377
// avoid any special symbols, to make it easier to copy/paste
367378
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
@@ -381,5 +381,6 @@ func (a *HostAgent) detectGuestIPAddress(stdout string) error {
381381
a.guestIPv6 = guestIPv6
382382
a.guestIPMu.Unlock()
383383
ctx := context.Background()
384+
a.emitGuestIPEvent(ctx, a.GuestIP().String())
384385
return a.WriteSSHConfigFile(ctx)
385386
}

pkg/instance/start.go

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

291291
var (
292292
printedSSHLocalPort bool
293+
printedGuestIP bool
293294
receivedRunningEvent bool
294295
cloudInitCompleted bool
295296
err error
@@ -304,6 +305,14 @@ func watchHostAgentEvents(ctx context.Context, inst *limatype.Instance, haStdout
304305
inst.SSHLocalPort = ev.Status.SSHLocalPort
305306
}
306307

308+
if !printedGuestIP && ev.Status.GuestIP != nil {
309+
logrus.Infof("Guest IP Address: %s", ev.Status.GuestIP.String())
310+
printedGuestIP = true
311+
312+
// Update the instance's Guest IP address
313+
inst.GuestIP = ev.Status.GuestIP
314+
}
315+
307316
if showProgress && ev.Status.CloudInitProgress != nil {
308317
progress := ev.Status.CloudInitProgress
309318
if progress.Active && progress.LogLine == "" {

0 commit comments

Comments
 (0)