1 Star 0 Fork 0

litian/machine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
ssh.go 975 Bytes
一键复制 编辑 原始数据 按行查看 历史
package commands
import (
"fmt"
"github.com/docker/machine/libmachine"
"github.com/docker/machine/libmachine/state"
)
type errStateInvalidForSSH struct {
HostName string
}
func (e errStateInvalidForSSH) Error() string {
return fmt.Sprintf("Error: Cannot run SSH command: Host %q is not running", e.HostName)
}
func cmdSSH(c CommandLine, api libmachine.API) error {
// Check for help flag -- Needed due to SkipFlagParsing
firstArg := c.Args().First()
if firstArg == "-help" || firstArg == "--help" || firstArg == "-h" {
c.ShowHelp()
return nil
}
target, err := targetHost(c, api)
if err != nil {
return err
}
host, err := api.Load(target)
if err != nil {
return err
}
currentState, err := host.Driver.GetState()
if err != nil {
return err
}
if currentState != state.Running {
return errStateInvalidForSSH{host.Name}
}
client, err := host.CreateSSHClient()
if err != nil {
return err
}
return client.Shell(c.Args().Tail()...)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/litian33/machine.git
git@gitee.com:litian33/machine.git
litian33
machine
machine
v0.6.0-rc4

搜索帮助