MCPcopy
hub / github.com/kubernetes/node-problem-detector / Run

Function Run

test/e2e/lib/ssh/ssh.go:37–62  ·  view source on GitHub ↗

Run synchronously SSHs to a machine and runs cmd.

(cmd, ip, sshUser, sshKey string)

Source from the content-addressed store, hash-verified

35
36// Run synchronously SSHs to a machine and runs cmd.
37func Run(cmd, ip, sshUser, sshKey string) Result {
38 result := Result{User: sshUser, Host: ip, Cmd: cmd}
39
40 if result.User == "" {
41 result.User = os.Getenv("USER")
42 }
43
44 if ip == "" {
45 result.SSHError = fmt.Errorf("empty IP address")
46 return result
47 }
48
49 signer, err := MakePrivateKeySignerFromFile(sshKey)
50 if err != nil {
51 result.SSHError = fmt.Errorf("error getting signer from key file %s: %v", sshKey, err)
52 return result
53 }
54
55 stdout, stderr, code, err := RunSSHCommand(cmd, result.User, net.JoinHostPort(ip, "22"), signer)
56 result.Stdout = stdout
57 result.Stderr = stderr
58 result.Code = code
59 result.SSHError = err
60
61 return result
62}

Callers 2

CreateInstanceFunction · 0.92
RunCommandMethod · 0.92

Calls 2

RunSSHCommandFunction · 0.85

Tested by

no test coverage detected