Merge pull request #1066 in YUNIONIO/onecloud from ~LIZEXI/onecloud:feature/lzx-ssh-raw-run to release/2.6.0

* commit 'fb5e60c8fe873283c458b62592ba8e0f3530a1d4':
  util/ssh: add RawRun to get cmd output directly.
This commit is contained in:
邱剑
2019-02-16 22:22:14 +08:00
+13 -1
View File
@@ -94,7 +94,15 @@ func (s *Client) GetConfig() ClientConfig {
return s.config
}
func (s *Client) RawRun(cmds ...string) ([]string, error) {
return s.run(false, cmds...)
}
func (s *Client) Run(cmds ...string) ([]string, error) {
return s.run(true, cmds...)
}
func (s *Client) run(parseOutput bool, cmds ...string) ([]string, error) {
ret := []string{}
for _, cmd := range cmds {
session, err := s.client.NewSession()
@@ -113,7 +121,11 @@ func (s *Client) Run(cmds ...string) ([]string, error) {
log.Errorf("%v", err)
return nil, err
}
ret = append(ret, ParseOutput(stdOut.Bytes())...)
if parseOutput {
ret = append(ret, ParseOutput(stdOut.Bytes())...)
} else {
ret = append(ret, stdOut.String())
}
}
return ret, nil