Skip to content

Commit 4bfd815

Browse files
committed
Print IP instead of Port for non-local SSH
Signed-off-by: Anders F Björklund <[email protected]>
1 parent f9fda1c commit 4bfd815

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

pkg/hostagent/events/events.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ type Status struct {
1616

1717
Errors []string `json:"errors,omitempty"`
1818

19-
SSHLocalPort int `json:"sshLocalPort,omitempty"`
19+
SSHIPAddress string `json:"sshIPAddress,omitempty"`
20+
SSHLocalPort int `json:"sshLocalPort,omitempty"`
2021
}
2122

2223
type Event struct {

pkg/hostagent/hostagent.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,21 @@ func (a *HostAgent) Run(ctx context.Context) error {
372372
return a.startRoutinesAndWait(ctx, errCh)
373373
}
374374

375+
func getIP(address string) string {
376+
ip := net.ParseIP(address)
377+
if ip != nil {
378+
return address
379+
}
380+
ips, err := net.LookupIP(address)
381+
if err == nil && len(ips) > 0 {
382+
return ips[0].String()
383+
}
384+
return address
385+
}
386+
375387
func (a *HostAgent) startRoutinesAndWait(ctx context.Context, errCh <-chan error) error {
376388
stBase := events.Status{
389+
SSHIPAddress: getIP(a.instSSHAddress),
377390
SSHLocalPort: a.sshLocalPort,
378391
}
379392
stBooting := stBase

pkg/instance/start.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,13 @@ func watchHostAgentEvents(ctx context.Context, inst *store.Instance, haStdoutPat
288288
)
289289
onEvent := func(ev hostagentevents.Event) bool {
290290
if !printedSSHLocalPort && ev.Status.SSHLocalPort != 0 {
291-
logrus.Infof("SSH Local Port: %d", ev.Status.SSHLocalPort)
291+
if ev.Status.SSHIPAddress == "127.0.0.1" {
292+
logrus.Infof("SSH Local Port: %d", ev.Status.SSHLocalPort)
293+
} else if ev.Status.SSHLocalPort == 22 {
294+
logrus.Infof("SSH IP Address: %s", ev.Status.SSHIPAddress)
295+
} else {
296+
logrus.Infof("SSH IP Address: %s Port: %d", ev.Status.SSHIPAddress, ev.Status.SSHLocalPort)
297+
}
292298
printedSSHLocalPort = true
293299
}
294300

0 commit comments

Comments
 (0)