本文整理汇总了Golang中github.com/docker/machine/libmachine/ssh.NewClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewClient函数的具体用法?Golang NewClient怎么用?Golang NewClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewClient函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: mountSharedFolder
func (d *Driver) mountSharedFolder(shareDir, shareName string) error {
// create mountpoint and mount shared folder
addr, err := d.GetSSHHostname()
if err != nil {
return err
}
port, err := d.GetSSHPort()
if err != nil {
return err
}
auth := &ssh.Auth{
Keys: []string{d.GetSSHKeyPath()},
}
client, err := ssh.NewClient(d.GetSSHUsername(), addr, port, auth)
if err != nil {
return err
}
command := "[ ! -d " + shareDir + " ]&& sudo mkdir " + shareDir + "; [ -f /usr/bin/vmhgfs-fuse ]&& sudo /usr/bin/vmhgfs-fuse -o allow_other .host:/" + shareName + " " + shareDir + " || sudo mount -t vmhgfs .host:/" + shareName + " " + shareDir
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)
return err
}
示例2: uploadKeyPair
// uploadKeyPair upload the public key to docker-machine
func (d *Driver) uploadKeyPair() error {
ipAddr, err := d.GetIP()
if err != nil {
return err
}
port, _ := d.GetSSHPort()
auth := ssh.Auth{
Passwords: []string{d.Password},
}
ssh.SetDefaultClient(ssh.Native)
sshClient, err := ssh.NewClient(d.GetSSHUsername(), ipAddr, port, &auth)
if err != nil {
return err
}
d.waitForSSHFunc(sshClient, "exit 0")
publicKey, err := ioutil.ReadFile(d.GetSSHKeyPath() + ".pub")
if err != nil {
return err
}
command := fmt.Sprintf("mkdir -p ~/.ssh; echo '%s' > ~/.ssh/authorized_keys", string(publicKey))
log.Debugf("Upload the public key with command: %s", command)
output, err := sshClient.Output(command)
if err != nil {
log.Debugf("Upload command err, output: %v: %s", err, output)
return err
}
return nil
}
示例3: CreateSSHClient
func (h *Host) CreateSSHClient() (ssh.Client, error) {
addr, err := h.Driver.GetSSHHostname()
if err != nil {
return ssh.ExternalClient{}, err
}
port, err := h.Driver.GetSSHPort()
if err != nil {
return ssh.ExternalClient{}, err
}
auth := &ssh.Auth{
Keys: []string{h.Driver.GetSSHKeyPath()},
}
return ssh.NewClient(h.Driver.GetSSHUsername(), addr, port, auth)
}
示例4: executeCommands
func (c *ComputeUtil) executeCommands(commands []string, ip, sshKeyPath string) error {
for _, command := range commands {
auth := &ssh.Auth{
Keys: []string{sshKeyPath},
}
client, err := ssh.NewClient(c.userName, ip, 22, auth)
if err != nil {
return err
}
if _, err := client.Output(command); err != nil {
return err
}
}
return nil
}
示例5: uploadKeyPair
func (d *Driver) uploadKeyPair() error {
ipAddr := d.IPAddress
port, _ := d.GetSSHPort()
tcpAddr := fmt.Sprintf("%s:%d", ipAddr, port)
log.Infof("%s | Waiting SSH service %s is ready to connect ...", d.MachineName, tcpAddr)
log.Infof("%s | Uploading SSH keypair to %s ...", d.MachineName, tcpAddr)
auth := ssh.Auth{
Passwords: []string{d.SSHPassword},
}
sshClient, err := ssh.NewClient(d.GetSSHUsername(), ipAddr, port, &auth)
if err != nil {
return err
}
command := fmt.Sprintf("mkdir -p ~/.ssh; echo '%s' > ~/.ssh/authorized_keys", string(d.PublicKey))
log.Debugf("%s | Upload the public key with command: %s", d.MachineName, command)
output, err := sshClient.Output(command)
log.Debugf("%s | Upload command err, output: %v: %s", d.MachineName, err, output)
if err != nil {
return err
}
log.Debugf("%s | Upload the public key with command: %s", d.MachineName, command)
d.fixRoutingRules(sshClient)
if d.DiskSize > 0 {
d.autoFdisk(sshClient)
}
if d.UpgradeKernel {
d.upgradeKernel(sshClient, tcpAddr)
}
return nil
}
示例6: CreateSSHClient
func (creator *StandardSSHClientCreator) CreateSSHClient(d drivers.Driver) (ssh.Client, error) {
addr, err := d.GetSSHHostname()
if err != nil {
return ssh.ExternalClient{}, err
}
port, err := d.GetSSHPort()
if err != nil {
return ssh.ExternalClient{}, err
}
auth := &ssh.Auth{}
if d.GetSSHKeyPath() != "" {
auth.Keys = []string{d.GetSSHKeyPath()}
}
return ssh.NewClient(d.GetSSHUsername(), addr, port, auth)
}
示例7: GetSSHClientFromDriver
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
}
auth := &ssh.Auth{
Keys: []string{d.GetSSHKeyPath()},
}
client, err := ssh.NewClient(d.GetSSHUsername(), address, port, auth)
return client, err
}
示例8: replaceInsecureSSHKey
func (d *Driver) replaceInsecureSSHKey() error {
addr, err := d.GetSSHHostname()
if err != nil {
return err
}
port, err := d.GetSSHPort()
if err != nil {
return err
}
tempssh, err := ioutil.TempFile(os.TempDir(), "appcatalyst-ssh-insecure-key")
defer os.Remove(tempssh.Name())
_, err = tempssh.WriteString(insecureSSHKey)
if err != nil {
return err
}
auth := &ssh.Auth{
Keys: []string{tempssh.Name()},
}
client, err := ssh.NewClient(d.GetSSHUsername(), addr, port, auth)
if err != nil {
return err
}
pubkey, err := d.readSSHKey()
if err != nil {
return err
}
command := "echo '" + pubkey + "' > ~/.ssh/authorized_keys"
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)
return err
}