Skip to content

Commit 732007c

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

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
@@ -13,7 +13,8 @@ type Status struct {
1313

1414
Errors []string `json:"errors,omitempty"`
1515

16-
SSHLocalPort int `json:"sshLocalPort,omitempty"`
16+
SSHIPAddress string `json:"sshIPAddress,omitempty"`
17+
SSHLocalPort int `json:"sshLocalPort,omitempty"`
1718
}
1819

1920
type Event struct {

pkg/hostagent/hostagent.go

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

401+
func getIP(address string) string {
402+
ip := net.ParseIP(address)
403+
if ip != nil {
404+
return address
405+
}
406+
ips, err := net.LookupIP(address)
407+
if err == nil && len(ips) > 0 {
408+
return ips[0].String()
409+
}
410+
return address
411+
}
412+
401413
func (a *HostAgent) startRoutinesAndWait(ctx context.Context, errCh chan error) error {
402414
stBase := events.Status{
415+
SSHIPAddress: getIP(a.instSSHAddress),
403416
SSHLocalPort: a.sshLocalPort,
404417
}
405418
stBooting := stBase

pkg/instance/start.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,13 @@ func watchHostAgentEvents(ctx context.Context, inst *store.Instance, haStdoutPat
273273
)
274274
onEvent := func(ev hostagentevents.Event) bool {
275275
if !printedSSHLocalPort && ev.Status.SSHLocalPort != 0 {
276-
logrus.Infof("SSH Local Port: %d", ev.Status.SSHLocalPort)
276+
if ev.Status.SSHIPAddress == "127.0.0.1" {
277+
logrus.Infof("SSH Local Port: %d", ev.Status.SSHLocalPort)
278+
} else if ev.Status.SSHLocalPort == 22 {
279+
logrus.Infof("SSH IP Address: %s", ev.Status.SSHIPAddress)
280+
} else {
281+
logrus.Infof("SSH IP Address: %s Port: %d", ev.Status.SSHIPAddress, ev.Status.SSHLocalPort)
282+
}
277283
printedSSHLocalPort = true
278284
}
279285

0 commit comments

Comments
 (0)