本文整理汇总了Golang中github.com/docker/machine/drivers.RunSSHCommandFromDriver函数的典型用法代码示例。如果您正苦于以下问题:Golang RunSSHCommandFromDriver函数的具体用法?Golang RunSSHCommandFromDriver怎么用?Golang RunSSHCommandFromDriver使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RunSSHCommandFromDriver函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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)
}
示例2: Kill
func (d *Driver) Kill() error {
log.Debug("Killing...")
if _, err := drivers.RunSSHCommandFromDriver(d, "sudo shutdown -P now"); err != nil {
return err
}
return nil
}
示例3: Restart
func (d *Driver) Restart() error {
log.Debug("Restarting...")
if _, err := drivers.RunSSHCommandFromDriver(d, "sudo shutdown -r now"); err != nil {
return err
}
return nil
}
示例4: DetectProvisioner
func DetectProvisioner(d drivers.Driver) (Provisioner, error) {
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: SSHCommand
func (provisioner *Boot2DockerProvisioner) SSHCommand(args string) (string, error) {
return drivers.RunSSHCommandFromDriver(provisioner.Driver, args)
}
示例6: RunSSHCommand
func (h *Host) RunSSHCommand(command string) (string, error) {
return drivers.RunSSHCommandFromDriver(h.Driver, command)
}