Skip to content

Commit

Permalink
Merge pull request #2 from humblec/master
Browse files Browse the repository at this point in the history
Adding sudo command as optional
  • Loading branch information
Luis Pabón committed May 10, 2016
2 parents 9d2d6c5 + abee202 commit 62afec7
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ import (
"bytes"
"errors"
"fmt"
"github.com/heketi/utils"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
"io/ioutil"
"log"
"net"
"os"
"time"

"github.com/heketi/utils"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
)

type SshExec struct {
Expand Down Expand Up @@ -105,7 +106,7 @@ func NewSshExecWithKeyFile(logger *utils.Logger, user string, file string) *SshE
}

// This function was based from https://github.com/coreos/etcd-manager/blob/master/main.go
func (s *SshExec) ConnectAndExec(host string, commands []string, timeoutMinutes int) ([]string, error) {
func (s *SshExec) ConnectAndExec(host string, commands []string, timeoutMinutes int, useSudo bool) ([]string, error) {

buffers := make([]string, len(commands))

Expand Down Expand Up @@ -133,6 +134,10 @@ func (s *SshExec) ConnectAndExec(host string, commands []string, timeoutMinutes
session.Stdout = &b
session.Stderr = &berr

if useSudo {
command = "sudo " + command
}

err = session.Start(command)
if err != nil {
return nil, err
Expand Down

0 comments on commit 62afec7

Please sign in to comment.