forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
non_interactive.go
35 lines (27 loc) · 921 Bytes
/
non_interactive.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package ssh
import (
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshsys "github.com/cloudfoundry/bosh-utils/system"
boshdir "github.com/cloudfoundry/bosh-cli/director"
)
type NonInteractiveRunner struct {
comboRunner ComboRunner
}
func NewNonInteractiveRunner(comboRunner ComboRunner) NonInteractiveRunner {
return NonInteractiveRunner{comboRunner}
}
func (r NonInteractiveRunner) Run(connOpts ConnectionOpts, result boshdir.SSHResult, rawCmd []string) error {
if len(result.Hosts) == 0 {
return bosherr.Errorf("Non-interactive SSH expects at least one host")
}
if len(rawCmd) == 0 {
return bosherr.Errorf("Non-interactive SSH expects non-empty command")
}
cmdFactory := func(host boshdir.Host) boshsys.Command {
return boshsys.Command{
Name: "ssh",
Args: append([]string{host.Host, "-l", host.Username}, rawCmd...),
}
}
return r.comboRunner.Run(connOpts, result, cmdFactory)
}