1 Star 0 Fork 0

powerpaas/machine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
Godeps
cmd
commands
contrib/completion
docs
drivers
experimental
its
libmachine
auth
cert
check
crashreport
drivers
plugin
rpc
base.go
base_test.go
check.go
drivers.go
notsupported.go
serial.go
serial_test.go
utils.go
engine
examples
host
hosttest
libmachinetest
log
mcndockerclient
mcnerror
mcnflag
mcnutils
persist
provider
provision
shell
ssh
state
swarm
version
libmachine.go
mk
script
test
vendor
version
.dockerignore
.gitignore
.godir
.travis.yml
CHANGELOG.md
CONTRIBUTING.md
Dockerfile
LICENSE
MAINTAINERS
Makefile
Makefile.inc
README.md
ROADMAP.md
appveyor.yml
circle.yml
doc.go
克隆/下载
utils.go 1.61 KB
一键复制 编辑 原始数据 按行查看 历史
package drivers
import (
"fmt"
"github.com/docker/machine/libmachine/log"
"github.com/docker/machine/libmachine/mcnutils"
"github.com/docker/machine/libmachine/ssh"
)
func GetSSHClientFromDriver(d Driver) (ssh.Client, error) {
address, err := d.GetSSHHostname()
if err != nil {
return nil, err
}
port, err := d.GetSSHPort()
if err != nil {
return nil, err
}
var auth *ssh.Auth
if d.GetSSHKeyPath() == "" {
auth = &ssh.Auth{}
} else {
auth = &ssh.Auth{
Keys: []string{d.GetSSHKeyPath()},
}
}
client, err := ssh.NewClient(d.GetSSHUsername(), address, port, auth)
return client, err
}
func RunSSHCommandFromDriver(d Driver, command string) (string, error) {
client, err := GetSSHClientFromDriver(d)
if err != nil {
return "", err
}
log.Debugf("About to run SSH command:\n%s", command)
output, err := client.Output(command)
log.Debugf("SSH cmd err, output: %v: %s", err, output)
if err != nil {
return "", fmt.Errorf(`Something went wrong running an SSH command!
command : %s
err : %v
output : %s
`, command, err, output)
}
return output, nil
}
func sshAvailableFunc(d Driver) func() bool {
return func() bool {
log.Debug("Getting to WaitForSSH function...")
if _, err := RunSSHCommandFromDriver(d, "exit 0"); err != nil {
log.Debugf("Error getting ssh command 'exit 0' : %s", err)
return false
}
return true
}
}
func WaitForSSH(d Driver) error {
// Try to dial SSH for 30 seconds before timing out.
if err := mcnutils.WaitFor(sshAvailableFunc(d)); err != nil {
return fmt.Errorf("Too many retries waiting for SSH to be available. Last error: %s", err)
}
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/powerpaas/machine.git
git@gitee.com:powerpaas/machine.git
powerpaas
machine
machine
v0.8.0

搜索帮助