Skip to content

Commit 95eb85c

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

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
@@ -396,8 +396,21 @@ func (a *HostAgent) Run(ctx context.Context) error {
396396
return a.startRoutinesAndWait(ctx, errCh)
397397
}
398398

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

pkg/start/start.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,13 @@ func watchHostAgentEvents(ctx context.Context, inst *store.Instance, haStdoutPat
277277
)
278278
onEvent := func(ev hostagentevents.Event) bool {
279279
if !printedSSHLocalPort && ev.Status.SSHLocalPort != 0 {
280-
logrus.Infof("SSH Local Port: %d", ev.Status.SSHLocalPort)
280+
if ev.Status.SSHIPAddress == "127.0.0.1" {
281+
logrus.Infof("SSH Local Port: %d", ev.Status.SSHLocalPort)
282+
} else if ev.Status.SSHLocalPort == 22 {
283+
logrus.Infof("SSH IP Address: %s", ev.Status.SSHIPAddress)
284+
} else {
285+
logrus.Infof("SSH IP Address: %s Port: %d", ev.Status.SSHIPAddress, ev.Status.SSHLocalPort)
286+
}
281287
printedSSHLocalPort = true
282288
}
283289

0 commit comments

Comments
 (0)