Skip to content

Commit 4f5aa02

Browse files
committed
Print IP instead of Port for non-local SSH
Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
1 parent 5173ce3 commit 4f5aa02

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

pkg/hostagent/events/events.go

+2-1
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

+13
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,21 @@ func (a *HostAgent) Run(ctx context.Context) error {
394394
return a.startRoutinesAndWait(ctx, errCh)
395395
}
396396

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

pkg/start/start.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,13 @@ func watchHostAgentEvents(ctx context.Context, inst *store.Instance, haStdoutPat
253253
)
254254
onEvent := func(ev hostagentevents.Event) bool {
255255
if !printedSSHLocalPort && ev.Status.SSHLocalPort != 0 {
256-
logrus.Infof("SSH Local Port: %d", ev.Status.SSHLocalPort)
256+
if ev.Status.SSHIPAddress == "127.0.0.1" {
257+
logrus.Infof("SSH Local Port: %d", ev.Status.SSHLocalPort)
258+
} else if ev.Status.SSHLocalPort == 22 {
259+
logrus.Infof("SSH IP Address: %s", ev.Status.SSHIPAddress)
260+
} else {
261+
logrus.Infof("SSH IP Address: %s Port: %d", ev.Status.SSHIPAddress, ev.Status.SSHLocalPort)
262+
}
257263
printedSSHLocalPort = true
258264
}
259265

0 commit comments

Comments
 (0)