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


Golang drivers.RunSSHCommandFromDriver函數代碼示例

本文整理匯總了Golang中github.com/docker/machine/libmachine/drivers.RunSSHCommandFromDriver函數的典型用法代碼示例。如果您正苦於以下問題:Golang RunSSHCommandFromDriver函數的具體用法?Golang RunSSHCommandFromDriver怎麽用?Golang RunSSHCommandFromDriver使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了RunSSHCommandFromDriver函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: mountShareFolder

func (d *Driver) mountShareFolder(shareName string, mountPoint string) error {
	// Check the host path is available
	if _, err := os.Stat(mountPoint); err != nil {
		if os.IsNotExist(err) {
			log.Infof("Host path '%s' does not exist. Skipping mount to VM...", mountPoint)
			return nil
		}
		return err
	}

	// Ensure that share is available on the guest side
	checkCmd := "sudo modprobe prl_fs && grep -w " + shareName + " /proc/fs/prl_fs/sf_list"
	if _, err := drivers.RunSSHCommandFromDriver(d, checkCmd); err != nil {
		log.Infof("Shared folder '%s' is unavailable. Skipping mount to VM...", shareName)
		return nil
	}

	// Mount shared folder
	mountCmd := "sudo mkdir -p " + mountPoint + " && sudo mount -t prl_fs " + shareName + " " + mountPoint
	if _, err := drivers.RunSSHCommandFromDriver(d, mountCmd); err != nil {
		return fmt.Errorf("Error mounting shared folder: %s", err)
	}

	return nil
}
開發者ID:ianbytchek,項目名稱:docker-machine-parallels,代碼行數:25,代碼來源:parallels.go

示例2: setupNFSShare

// Setup NFS share
func (d *Driver) setupNFSShare() error {
	nfsConfig := fmt.Sprintf("/Users %s -alldirs -maproot=root", d.IPAddress)

	if _, err := nfsexports.Add("", d.nfsExportIdentifier(), nfsConfig); err != nil {
		return err
	}

	if err := nfsexports.ReloadDaemon(); err != nil {
		return err
	}

	hostIP, err := vmnet.GetNetAddr()
	if err != nil {
		return err
	}

	bootScriptName := "/var/lib/boot2docker/bootlocal.sh"
	bootScript := fmt.Sprintf("#/bin/bash\\n"+
		"sudo mkdir -p /Users\\n"+
		"sudo /usr/local/etc/init.d/nfs-client start\\n"+
		"sudo mount -t nfs -o noacl,async %s:/Users /Users\\n", hostIP)

	writeScriptCmd := fmt.Sprintf("echo -e \"%s\" | sudo tee %s && sudo chmod +x %s && %s",
		bootScript, bootScriptName, bootScriptName, bootScriptName)

	if _, err := drivers.RunSSHCommandFromDriver(d, writeScriptCmd); err != nil {
		return err
	}

	return nil
}
開發者ID:fayep,項目名稱:docker-machine-driver-xhyve,代碼行數:32,代碼來源:xhyve.go

示例3: GetIP

func (d *Driver) GetIP() (string, error) {
	// DHCP is used to get the IP, so virtualbox hosts don't have IPs unless
	// they are running
	s, err := d.GetState()
	if err != nil {
		return "", err
	}
	if s != state.Running {
		return "", drivers.ErrHostIsNotRunning
	}

	macAddress, err := d.getHostOnlyMACAddress()
	if err != nil {
		return "", err
	}

	log.Debugf("Host-only MAC: %s\n", macAddress)

	output, err := drivers.RunSSHCommandFromDriver(d, "ip addr show")
	if err != nil {
		return "", err
	}

	log.Debugf("SSH returned: %s\nEND SSH\n", output)

	ipAddress, err := d.parseIPForMACFromIPAddr(output, macAddress)
	if err != nil {
		return "", err
	}

	return ipAddress, nil
}
開發者ID:dduportal,項目名稱:machine,代碼行數:32,代碼來源:virtualbox.go

示例4: DetectProvisioner

func DetectProvisioner(d drivers.Driver) (Provisioner, error) {
	log.Info("Detecting the provisioner...")

	osReleaseOut, err := drivers.RunSSHCommandFromDriver(d, "cat /etc/os-release")
	if err != nil {
		return nil, fmt.Errorf("Error getting SSH command: %s", err)
	}

	osReleaseInfo, err := NewOsRelease([]byte(osReleaseOut))
	if err != nil {
		return nil, fmt.Errorf("Error parsing /etc/os-release file: %s", err)
	}

	for _, p := range provisioners {
		provisioner := p.New(d)
		provisioner.SetOsReleaseInfo(osReleaseInfo)

		if provisioner.CompatibleWithHost() {
			log.Debugf("found compatible host: %s", osReleaseInfo.ID)
			return provisioner, nil
		}
	}

	return nil, ErrDetectionFailed
}
開發者ID:rowancarr,項目名稱:machine,代碼行數:25,代碼來源:provisioner.go

示例5: Kill

// Kill stops a host forcefully
func (d *Driver) Kill() error {
	log.Debug("Killing...")
	if _, err := drivers.RunSSHCommandFromDriver(d, "sudo shutdown -P now"); err != nil {
		return err
	}
	return nil
}
開發者ID:openit-lib,項目名稱:docker-machine-hypriot,代碼行數:8,代碼來源:hypriot.go

示例6: GetIP

func (d *Driver) GetIP() (string, error) {
	// DHCP is used to get the IP, so virtualbox hosts don't have IPs unless
	// they are running
	s, err := d.GetState()
	if err != nil {
		return "", err
	}
	if s != state.Running {
		return "", drivers.ErrHostIsNotRunning
	}

	output, err := drivers.RunSSHCommandFromDriver(d, "ip addr show dev eth1")
	if err != nil {
		return "", err
	}

	log.Debugf("SSH returned: %s\nEND SSH\n", output)

	// parse to find: inet 192.168.59.103/24 brd 192.168.59.255 scope global eth1
	lines := strings.Split(output, "\n")
	for _, line := range lines {
		vals := strings.Split(strings.TrimSpace(line), " ")
		if len(vals) >= 2 && vals[0] == "inet" {
			return vals[1][:strings.Index(vals[1], "/")], nil
		}
	}

	return "", fmt.Errorf("No IP address found %s", output)
}
開發者ID:austinhyde,項目名稱:machine,代碼行數:29,代碼來源:virtualbox.go

示例7: GetSShState

func (d *Driver) GetSShState() (bool, error) {
	log.Debug("Getting to VM SSH status...")
	if _, err := drivers.RunSSHCommandFromDriver(d, "exit 0"); err != nil {
		return false, nil
	}
	return true, nil
}
開發者ID:adamreese,項目名稱:docker-machine-driver-xhyve,代碼行數:7,代碼來源:xhyve.go

示例8: sshAvailableFunc

func sshAvailableFunc(d *Driver) func() bool {
	return func() bool {
		if _, err := drivers.RunSSHCommandFromDriver(d, "exit 0"); err != nil {
			log.Debugf("Error getting ssh command 'exit 0' : %s", err)
			return false
		}
		return true
	}
}
開發者ID:waterytowers,項目名稱:machine-cloudformation,代碼行數:9,代碼來源:amazoncf.go

示例9: Kill

func (d *Driver) Kill() error {
	log.Infof("Killing %s use hardware to stop all CPU ...", d.MachineName)
	if _, err := drivers.RunSSHCommandFromDriver(d, "sudo halt"); err != nil {
		log.Debugf("Error getting ssh command 'exit 0' : %s", err)
		return err
	}

	return nil
}
開發者ID:adamreese,項目名稱:docker-machine-driver-xhyve,代碼行數:9,代碼來源:xhyve.go

示例10: Restart

func (d *Driver) Restart() error {
	log.Debug("Restarting...")

	if _, err := drivers.RunSSHCommandFromDriver(d, "sudo shutdown -r now"); err != nil {
		return err
	}

	return nil
}
開發者ID:rutulpatel,項目名稱:machine,代碼行數:9,代碼來源:generic.go

示例11: setupHostname

func (d *Driver) setupHostname() error {
	log.Debugf("[Scaleway] Setting hostname: %s", d.MachineName)
	_, err := drivers.RunSSHCommandFromDriver(d,
		fmt.Sprintf(
			"echo \"127.0.0.1 %s\" | sudo tee -a /etc/hosts && sudo hostname %s && echo \"%s\" | sudo tee /etc/hostname",
			d.MachineName,
			d.MachineName,
			d.MachineName,
		))
	return err
}
開發者ID:nlamirault,項目名稱:docker-machine-scaleway,代碼行數:11,代碼來源:scaleway.go

示例12: Kill

func (d *Driver) Kill() error {
	log.Debug("Killing...")

	command := "shutdown -P now"
	command = d.SSHSudo(command)
	if _, err := drivers.RunSSHCommandFromDriver(d, command); err != nil {
		return err
	}

	return nil
}
開發者ID:pdxjohnny,項目名稱:machine,代碼行數:11,代碼來源:generic.go

示例13: setupNFSShare

// Setup NFS share
func (d *Driver) setupNFSShare() error {
	nfsConfig := fmt.Sprintf("\n/Users %s -alldirs -maproot=root\n", d.IPAddress)

	file, err := os.OpenFile("/etc/exports", os.O_WRONLY|os.O_APPEND, 0644)
	if err != nil {
		return err
	}
	defer file.Close()
	if _, err := file.Write([]byte(nfsConfig)); err != nil {
		return err
	}
	file.Close()

	// TODO Do nfsd checkexports

	cmd := exec.Command("sudo", "nfsd", "restart")
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr

	log.Debugf("executing: %v %v", cmd)

	if err := cmd.Run(); err != nil {
		return err
	}

	hostIP, err := vmnet.GetNetAddr()
	if err != nil {
		return err
	}

	bootScriptName := "/var/lib/boot2docker/bootlocal.sh"
	bootScript := fmt.Sprintf("#/bin/bash\\n"+
		"sudo mkdir -p /Users\\n"+
		"sudo /usr/local/etc/init.d/nfs-client start\\n"+
		"sudo mount -t nfs -o noacl,async %s:/Users /Users\\n", hostIP)

	writeScriptCmd := fmt.Sprintf("echo -e \"%s\" | sudo tee %s && sudo chmod +x %s && %s",
		bootScript, bootScriptName, bootScriptName, bootScriptName)

	if _, err := drivers.RunSSHCommandFromDriver(d, writeScriptCmd); err != nil {
		return err
	}

	return nil
}
開發者ID:adamreese,項目名稱:docker-machine-driver-xhyve,代碼行數:46,代碼來源:xhyve.go

示例14: setupVirt9pShare

func (d *Driver) setupVirt9pShare() error {
	user, err := user.Current()
	if err != nil {
		return err
	}
	bootScriptName := "/var/lib/boot2docker/bootlocal.sh"
	bootScript := fmt.Sprintf("#/bin/bash\\n"+
		"sudo mkdir -p %s\\n"+
		"sudo mount -t 9p -o version=9p2000 -o trans=virtio -o uname=%s -o dfltuid=1000 -o dfltgid=50 -o access=any host %s", d.Virtio9pFolder, user.Username, d.Virtio9pFolder)

	writeScriptCmd := fmt.Sprintf("echo -e \"%s\" | sudo tee %s && sudo chmod +x %s && %s",
		bootScript, bootScriptName, bootScriptName, bootScriptName)

	if _, err := drivers.RunSSHCommandFromDriver(d, writeScriptCmd); err != nil {
		return err
	}

	return nil
}
開發者ID:johanneswuerbach,項目名稱:docker-machine-xhyve,代碼行數:19,代碼來源:xhyve.go

示例15: Stop

// Stop - stop the docker machine target
func (d *Driver) Stop() error {
	log.Debug("Stop...")
	log.Infof("Stop ... %s", d.MachineName)
	// gracefully attempt to stop the os

	if _, err := drivers.RunSSHCommandFromDriver(d, "sudo shutdown -P now"); err != nil {
		log.Warnf("Problem shutting down gracefully : %s", err)
	}

	// get the blade for this driver
	if err := d.getBlade(); err != nil {
		return err
	}

	// power on the server, and leave it in that state
	if err := d.Hardware.PowerOff(); err != nil {
		return err
	}
	// cleanup
	defer closeAll(d)
	return nil
}
開發者ID:JohnKDay,項目名稱:docker-machine-oneview,代碼行數:23,代碼來源:oneview.go


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