本文整理汇总了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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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
}
示例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
}
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}