Skip to content

Commit d83a3e8

Browse files
committed
Merge pull request #4235 from krancour/fix-deisctl-sshexec-output
fix(deisctl): fix deisctl ssh <cmd> output
2 parents fbe9b84 + 6bda1bd commit d83a3e8

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

deisctl/backend/fleet/ssh.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
// SSH opens an interactive shell to a machine in the cluster
1616
func (c *FleetClient) SSH(name string) error {
17-
sshClient, err := c.sshConnect(name)
17+
sshClient, _, err := c.sshConnect(name)
1818
if err != nil {
1919
return err
2020
}
@@ -25,54 +25,56 @@ func (c *FleetClient) SSH(name string) error {
2525
}
2626

2727
func (c *FleetClient) SSHExec(name, cmd string) error {
28-
fmt.Printf("Executing '%s' on container '%s'\n", cmd, name)
2928

30-
conn, err := c.sshConnect(name)
29+
conn, ms, err := c.sshConnect(name)
3130
if err != nil {
3231
return err
3332
}
3433

34+
fmt.Printf("Executing '%s' on %s\n", cmd, ms.PublicIP)
35+
3536
err, _ = ssh.Execute(conn, cmd)
3637
return err
3738
}
3839

39-
func (c *FleetClient) sshConnect(name string) (*ssh.SSHForwardingClient, error) {
40+
func (c *FleetClient) sshConnect(name string) (*ssh.SSHForwardingClient, *machine.MachineState, error) {
4041

4142
timeout := time.Duration(Flags.SSHTimeout*1000) * time.Millisecond
4243

4344
ms, err := c.machineState(name)
4445
if err != nil {
45-
return nil, err
46+
return nil, nil, err
4647
}
4748

4849
// If name isn't a machine ID, try it as a unit instead
4950
if ms == nil {
5051
units, err := c.Units(name)
5152

5253
if err != nil {
53-
return nil, err
54+
return nil, nil, err
5455
}
5556

5657
machID, err := c.findUnit(units[0])
5758

5859
if err != nil {
59-
return nil, err
60+
return nil, nil, err
6061
}
6162

6263
ms, err = c.machineState(machID)
6364

6465
if err != nil || ms == nil {
65-
return nil, err
66+
return nil, nil, err
6667
}
6768
}
6869

6970
addr := ms.PublicIP
7071

7172
if tun := getTunnelFlag(); tun != "" {
72-
return ssh.NewTunnelledSSHClient("core", tun, addr, getChecker(), false, timeout)
73+
sshClient, err := ssh.NewTunnelledSSHClient("core", tun, addr, getChecker(), false, timeout)
74+
return sshClient, ms, err
7375
}
74-
return ssh.NewSSHClient("core", addr, getChecker(), false, timeout)
75-
76+
sshClient, err := ssh.NewSSHClient("core", addr, getChecker(), false, timeout)
77+
return sshClient, ms, err
7678
}
7779

7880
// runCommand will attempt to run a command on a given machine. It will attempt

0 commit comments

Comments
 (0)