本文整理汇总了Golang中github.com/docker/machine/ssh.WaitForTCP函数的典型用法代码示例。如果您正苦于以下问题:Golang WaitForTCP函数的具体用法?Golang WaitForTCP怎么用?Golang WaitForTCP使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了WaitForTCP函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: sshAvailableFunc
func sshAvailableFunc(h *Host) func() bool {
return func() bool {
log.Debug("Getting to WaitForSSH function...")
hostname, err := h.Driver.GetSSHHostname()
if err != nil {
log.Debugf("Error getting IP address waiting for SSH: %s", err)
return false
}
port, err := h.Driver.GetSSHPort()
if err != nil {
log.Debugf("Error getting SSH port: %s", err)
return false
}
if err := ssh.WaitForTCP(fmt.Sprintf("%s:%d", hostname, port)); err != nil {
log.Debugf("Error waiting for TCP waiting for SSH: %s", err)
return false
}
cmd, err := h.GetSSHCommand("exit 0")
if err != nil {
log.Debugf("Error getting ssh command 'exit 0' : %s", err)
return false
}
if err := cmd.Run(); err != nil {
log.Debugf("Error running ssh command 'exit 0' : %s", err)
return false
}
return true
}
}
示例2: Start
func (d *Driver) Start() error {
if err := vbm("startvm", d.MachineName, "--type", "headless"); err != nil {
return err
}
log.Infof("Waiting for VM to start...")
return ssh.WaitForTCP(fmt.Sprintf("localhost:%d", d.SSHPort))
}
示例3: Create
func (d *Driver) Create() error {
log.Infof("Creating SSH key...")
key, err := d.createSSHKey()
if err != nil {
return err
}
spec := d.buildHostSpec()
spec.SshKeys = []*SshKey{key}
id, err := d.getClient().VirtualGuest().Create(spec)
if err != nil {
return fmt.Errorf("Error creating host: %q", err)
}
d.Id = id
d.getIp()
d.waitForStart()
d.waitForSetupTransactions()
ssh.WaitForTCP(d.IPAddress + ":22")
cmd, err := drivers.GetSSHCommandFromDriver(d, "sudo apt-get update && DEBIAN_FRONTEND=noninteractive sudo apt-get install -yq curl")
if err != nil {
return err
}
if err := cmd.Run(); err != nil {
return err
}
return nil
}
示例4: sshAvailableFunc
func sshAvailableFunc(d Driver) func() bool {
return func() bool {
log.Debug("Getting to WaitForSSH function...")
hostname, err := d.GetSSHHostname()
if err != nil {
log.Debugf("Error getting IP address waiting for SSH: %s", err)
return false
}
port, err := d.GetSSHPort()
if err != nil {
log.Debugf("Error getting SSH port: %s", err)
return false
}
if err := ssh.WaitForTCP(fmt.Sprintf("%s:%d", hostname, port)); err != nil {
log.Debugf("Error waiting for TCP waiting for SSH: %s", err)
return false
}
if _, err := RunSSHCommandFromDriver(d, "exit 0"); err != nil {
log.Debugf("Error getting ssh command 'exit 0' : %s", err)
return false
}
return true
}
}
示例5: waitForSSH
func (driver *Driver) waitForSSH() error {
log.Infof("Waiting for SSH...")
err := ssh.WaitForTCP(fmt.Sprintf("%s:%v", driver.getHostname(), driver.SSHPort))
if err != nil {
return err
}
return nil
}
示例6: waitForSSHServer
func (d *Driver) waitForSSHServer() error {
ip, err := d.GetIP()
if err != nil {
return err
}
log.WithFields(log.Fields{
"MachineId": d.MachineId,
"IP": ip,
}).Debug("Waiting for the SSH server to be started...")
return ssh.WaitForTCP(fmt.Sprintf("%s:%d", ip, d.SSHPort))
}
示例7: wait
func (d *Driver) wait() error {
log.Infof("Waiting for host to start...")
for {
ip, _ := d.GetIP()
if ip != "" {
break
}
time.Sleep(1 * time.Second)
}
log.Infof("Got IP, waiting for SSH")
ip, err := d.GetIP()
if err != nil {
return err
}
return ssh.WaitForTCP(fmt.Sprintf("%s:22", ip))
}
示例8: Start
func (d *Driver) Start() error {
s, err := d.GetState()
if err != nil {
return err
}
if s == state.Stopped {
// check network to re-create if needed
if err := d.setupHostOnlyNetwork(d.MachineName); err != nil {
return fmt.Errorf("Error setting up host only network on machine start: %s", err)
}
}
switch s {
case state.Stopped, state.Saved:
d.SSHPort, err = setPortForwarding(d.MachineName, 1, "ssh", "tcp", 22, d.SSHPort)
if err != nil {
return err
}
if err := vbm("startvm", d.MachineName, "--type", "headless"); err != nil {
return err
}
log.Infof("Starting VM...")
case state.Paused:
if err := vbm("controlvm", d.MachineName, "resume", "--type", "headless"); err != nil {
return err
}
log.Infof("Resuming VM ...")
default:
log.Infof("VM not in restartable state")
}
addr, err := d.GetSSHHostname()
if err := ssh.WaitForTCP(fmt.Sprintf("%s:%d", addr, d.SSHPort)); err != nil {
return err
}
// Bail if we don't get an IP from DHCP after a given number of seconds.
if err := utils.WaitForSpecific(d.hostOnlyIpAvailable, 5, 4*time.Second); err != nil {
return err
}
return err
}
示例9: wait
func (d *Driver) wait(timeout time.Duration) (err error) {
log.Infof("Waiting for VM to start...")
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
out := make(chan error, 1)
go func(ctx context.Context, out chan<- error) {
var ip string
for {
ip, _ = d.GetIP()
if ip != "" {
break
}
if t, ok := ctx.Deadline(); ok && time.Now().After(t) {
out <- fmt.Errorf("Wait GetIP timed out")
return
}
time.Sleep(1 * time.Second)
}
port, err := d.GetSSHPort()
if err != nil {
out <- err
return
}
addr := fmt.Sprintf("%s:%d", ip, port)
log.Infof("Got VM address(%v), Now waiting for SSH", addr)
out <- ssh.WaitForTCP(addr)
}(ctx, out)
select {
case err := <-out:
return err
case <-ctx.Done():
return fmt.Errorf("Wait for VM to start timed out: %v", ctx.Err())
}
return nil
}
示例10: Start
func (d *Driver) Start() error {
s, err := d.GetState()
if err != nil {
return err
}
switch s {
case state.Stopped, state.Saved:
if err := vbm("startvm", d.MachineName, "--type", "headless"); err != nil {
return err
}
log.Infof("Waiting for VM to start...")
case state.Paused:
if err := vbm("controlvm", d.MachineName, "resume", "--type", "headless"); err != nil {
return err
}
log.Infof("Resuming VM ...")
default:
log.Infof("VM not in restartable state")
}
return ssh.WaitForTCP(fmt.Sprintf("localhost:%d", d.SSHPort))
}
示例11: Create
func (d *Driver) Create() error {
if err := d.setUserSubscription(); err != nil {
return err
}
log.Info("Creating Azure machine...")
vmConfig, err := vmClient.CreateAzureVMConfiguration(d.MachineName, d.Size, d.Image, d.Location)
if err != nil {
return err
}
log.Debug("Generating certificate for Azure...")
if err := d.generateCertForAzure(); err != nil {
return err
}
log.Debug("Adding Linux provisioning...")
vmConfig, err = vmClient.AddAzureLinuxProvisioningConfig(vmConfig, d.GetSSHUsername(), d.UserPassword, d.azureCertPath(), d.SSHPort)
if err != nil {
return err
}
log.Debug("Authorizing ports...")
if err := d.addDockerEndpoint(vmConfig); err != nil {
return err
}
log.Debug("Creating VM...")
if err := vmClient.CreateAzureVM(vmConfig, d.MachineName, d.Location); err != nil {
return err
}
log.Info("Waiting for SSH...")
log.Debugf("Host: %s SSH Port: %d", d.getHostname(), d.SSHPort)
return ssh.WaitForTCP(fmt.Sprintf("%s:%d", d.getHostname(), d.SSHPort))
}
示例12: uploadKeyPair
func (d *Driver) uploadKeyPair() error {
ipAddr := d.IPAddress
port, _ := d.GetSSHPort()
tcpAddr := fmt.Sprintf("%s:%d", ipAddr, port)
ssh.WaitForTCP(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("Upload the public key with command: %s", command)
output, err := sshClient.Output(command)
log.Debugf("Upload command err, output: %v: %s", err, output)
if err != nil {
return err
}
log.Debugf("Upload the public key with command: %s", command)
fixRoutingRules(sshClient)
return nil
}
示例13: Create
func (d *Driver) Create() error {
d.setDropletNameIfNotSet()
log.Infof("Creating SSH key...")
key, err := d.createSSHKey()
if err != nil {
return err
}
d.SSHKeyID = key.ID
log.Infof("Creating Digital Ocean droplet...")
client := d.getClient()
createRequest := &godo.DropletCreateRequest{
Image: d.Image,
Name: d.DropletName,
Region: d.Region,
Size: d.Size,
SSHKeys: []interface{}{d.SSHKeyID},
}
newDroplet, _, err := client.Droplets.Create(createRequest)
if err != nil {
return err
}
d.DropletID = newDroplet.Droplet.ID
for {
newDroplet, _, err = client.Droplets.Get(d.DropletID)
if err != nil {
return err
}
for _, network := range newDroplet.Droplet.Networks.V4 {
if network.Type == "public" {
d.IPAddress = network.IPAddress
}
}
if d.IPAddress != "" {
break
}
time.Sleep(1 * time.Second)
}
log.Debugf("Created droplet ID %d, IP address %s",
newDroplet.Droplet.ID,
d.IPAddress)
log.Infof("Waiting for SSH...")
if err := ssh.WaitForTCP(fmt.Sprintf("%s:%d", d.IPAddress, 22)); err != nil {
return err
}
log.Debugf("HACK: Downloading version of Docker with identity auth...")
cmd, err := d.GetSSHCommand("stop docker")
if err != nil {
return err
}
if err := cmd.Run(); err != nil {
return err
}
cmd, err = d.GetSSHCommand("curl -sS https://ehazlett.s3.amazonaws.com/public/docker/linux/docker-1.4.1-136b351e-identity > /usr/bin/docker")
if err != nil {
return err
}
if err := cmd.Run(); err != nil {
return err
}
log.Debugf("Updating /etc/default/docker to use identity auth...")
cmd, err = d.GetSSHCommand("echo 'export DOCKER_OPTS=\"--auth=identity --host=tcp://0.0.0.0:2376\"' >> /etc/default/docker")
if err != nil {
return err
}
if err := cmd.Run(); err != nil {
return err
}
log.Debugf("Adding key to authorized-keys.d...")
if err := drivers.AddPublicKeyToAuthorizedHosts(d, "/.docker/authorized-keys.d"); err != nil {
return err
}
cmd, err = d.GetSSHCommand("start docker")
if err != nil {
return err
}
if err := cmd.Run(); err != nil {
return err
}
//.........这里部分代码省略.........
示例14: waitForSSH
func (d *Driver) waitForSSH() error {
log.Infof("Waiting for SSH...")
return ssh.WaitForTCP(fmt.Sprintf("%s:%v", d.getHostname(), d.SSHPort))
}
示例15: Create
//.........这里部分代码省略.........
vapptemplate, err := cati.GetVAppTemplate()
if err != nil {
return err
}
// Create a new empty vApp
vapp := govcloudair.NewVApp(p)
log.Infof("Creating a new vApp: %s...", d.MachineName)
// Compose the vApp with ComposeVApp
task, err := vapp.ComposeVApp(net, vapptemplate, d.MachineName, "Container Host created with Docker Host")
if err != nil {
return err
}
// Wait for the creation to be completed
if err = task.WaitTaskCompletion(); err != nil {
return err
}
task, err = vapp.ChangeCPUcount(d.CPUCount)
if err != nil {
return err
}
if err = task.WaitTaskCompletion(); err != nil {
return err
}
task, err = vapp.ChangeMemorySize(d.MemorySize)
if err != nil {
return err
}
if err = task.WaitTaskCompletion(); err != nil {
return err
}
sshCustomScript := "echo \"" + strings.TrimSpace(key) + "\" > /root/.ssh/authorized_keys"
task, err = vapp.RunCustomizationScript(d.MachineName, sshCustomScript)
if err != nil {
return err
}
if err = task.WaitTaskCompletion(); err != nil {
return err
}
task, err = vapp.PowerOn()
if err != nil {
return err
}
log.Infof("Waiting for the VM to power on and run the customization script...")
if err = task.WaitTaskCompletion(); err != nil {
return err
}
log.Infof("Creating NAT and Firewall Rules on %s...", d.EdgeGateway)
task, err = edge.Create1to1Mapping(vapp.VApp.Children.VM[0].NetworkConnectionSection.NetworkConnection.IPAddress, d.PublicIP, d.MachineName)
if err != nil {
return err
}
if err = task.WaitTaskCompletion(); err != nil {
return err
}
log.Infof("Waiting for SSH...")
if err := ssh.WaitForTCP(fmt.Sprintf("%s:%d", d.PublicIP, d.SSHPort)); err != nil {
return err
}
connTest := "ping -c 3 www.google.com >/dev/null 2>&1 && ( echo \"Connectivity and DNS tests passed.\" ) || ( echo \"Connectivity and DNS tests failed, trying to add Nameserver to resolv.conf\"; echo \"nameserver 8.8.8.8\" >> /etc/resolv.conf )"
log.Debugf("Connectivity and DNS sanity test...")
cmd, err := drivers.GetSSHCommandFromDriver(d, connTest)
if err != nil {
return err
}
if err := cmd.Run(); err != nil {
return err
}
log.Debugf("Disconnecting from vCloud Air...")
if err = p.Disconnect(); err != nil {
return err
}
// Set VAppID with ID of the created VApp
d.VAppID = vapp.VApp.ID
return nil
}