mirror of https://github.com/docker/docs.git
Refactoring to move closures into methods
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
This commit is contained in:
parent
30e0ca00b6
commit
2da08635e8
|
@ -307,8 +307,7 @@ func (d *Driver) PreCreateCheck() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) Create() error {
|
func (d *Driver) waitForStart() {
|
||||||
waitForStart := func() {
|
|
||||||
log.Infof("Waiting for host to become available")
|
log.Infof("Waiting for host to become available")
|
||||||
for {
|
for {
|
||||||
s, err := d.GetState()
|
s, err := d.GetState()
|
||||||
|
@ -326,7 +325,32 @@ func (d *Driver) Create() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
waitForSetupTransactions := func() {
|
func (d *Driver) getIp() (string, error) {
|
||||||
|
log.Infof("Getting Host IP")
|
||||||
|
for {
|
||||||
|
var (
|
||||||
|
ip string
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
if d.deviceConfig.PrivateNet {
|
||||||
|
ip, err = d.getClient().VirtualGuest().GetPrivateIp(d.Id)
|
||||||
|
} else {
|
||||||
|
ip, err = d.getClient().VirtualGuest().GetPublicIp(d.Id)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// not a perfect regex, but should be just fine for our needs
|
||||||
|
exp := regexp.MustCompile(`\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}`)
|
||||||
|
if exp.MatchString(ip) {
|
||||||
|
return ip, nil
|
||||||
|
}
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Driver) waitForSetupTransactions() {
|
||||||
log.Infof("Waiting for host setup transactions to complete")
|
log.Infof("Waiting for host setup transactions to complete")
|
||||||
// sometimes we'll hit a case where there's no active transaction, but if
|
// sometimes we'll hit a case where there's no active transaction, but if
|
||||||
// we check again in a few seconds, it moves to the next transaction. We
|
// we check again in a few seconds, it moves to the next transaction. We
|
||||||
|
@ -353,32 +377,7 @@ func (d *Driver) Create() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getIp := func() {
|
func (d *Driver) Create() error {
|
||||||
log.Infof("Getting Host IP")
|
|
||||||
for {
|
|
||||||
var (
|
|
||||||
ip string
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
if d.deviceConfig.PrivateNet {
|
|
||||||
ip, err = d.getClient().VirtualGuest().GetPrivateIp(d.Id)
|
|
||||||
} else {
|
|
||||||
ip, err = d.getClient().VirtualGuest().GetPublicIp(d.Id)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
time.Sleep(2 * time.Second)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// not a perfect regex, but should be just fine for our needs
|
|
||||||
exp := regexp.MustCompile(`\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}`)
|
|
||||||
if exp.MatchString(ip) {
|
|
||||||
d.IPAddress = ip
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(2 * time.Second)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Infof("Creating SSH key...")
|
log.Infof("Creating SSH key...")
|
||||||
key, err := d.createSSHKey()
|
key, err := d.createSSHKey()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -393,9 +392,9 @@ func (d *Driver) Create() error {
|
||||||
return fmt.Errorf("Error creating host: %q", err)
|
return fmt.Errorf("Error creating host: %q", err)
|
||||||
}
|
}
|
||||||
d.Id = id
|
d.Id = id
|
||||||
getIp()
|
d.getIp()
|
||||||
waitForStart()
|
d.waitForStart()
|
||||||
waitForSetupTransactions()
|
d.waitForSetupTransactions()
|
||||||
ssh.WaitForTCP(d.IPAddress + ":22")
|
ssh.WaitForTCP(d.IPAddress + ":22")
|
||||||
|
|
||||||
cmd, err := drivers.GetSSHCommandFromDriver(d, "sudo apt-get update && DEBIAN_FRONTEND=noninteractive sudo apt-get install -yq curl")
|
cmd, err := drivers.GetSSHCommandFromDriver(d, "sudo apt-get update && DEBIAN_FRONTEND=noninteractive sudo apt-get install -yq curl")
|
||||||
|
|
Loading…
Reference in New Issue