當前位置: 首頁>>代碼示例>>Golang>>正文


Golang ssh.NewClient函數代碼示例

本文整理匯總了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
}
開發者ID:vmware,項目名稱:docker-machine-driver-vmwareappcatalyst,代碼行數:28,代碼來源:appcatalyst.go

示例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
}
開發者ID:ucloud,項目名稱:docker-machine-ucloud,代碼行數:36,代碼來源:client.go

示例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)
}
開發者ID:newpcraft,項目名稱:machine,代碼行數:17,代碼來源:host.go

示例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
}
開發者ID:rowancarr,項目名稱:machine,代碼行數:17,代碼來源:compute_util.go

示例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
}
開發者ID:chuchengcao,項目名稱:machine,代碼行數:45,代碼來源:ecs.go

示例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)
}
開發者ID:sheltowt,項目名稱:machine,代碼行數:18,代碼來源:host.go

示例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

}
開發者ID:usmanismail,項目名稱:machine,代碼行數:19,代碼來源:utils.go

示例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
}
開發者ID:vmware,項目名稱:docker-machine-driver-vmwareappcatalyst,代碼行數:40,代碼來源:appcatalyst.go


注:本文中的github.com/docker/machine/libmachine/ssh.NewClient函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。