parent
78d53c81ce
commit
4875b82d12
|
@ -50,6 +50,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
&common.StepRun{
|
&common.StepRun{
|
||||||
Config: &b.config.RunConfig,
|
Config: &b.config.RunConfig,
|
||||||
},
|
},
|
||||||
|
&common.StepWaitForIp{},
|
||||||
&communicator.StepConnect{
|
&communicator.StepConnect{
|
||||||
Config: &b.config.Comm,
|
Config: &b.config.Comm,
|
||||||
Host: common.CommHost,
|
Host: common.CommHost,
|
||||||
|
|
|
@ -39,15 +39,6 @@ func (s *StepRun) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.Say("Waiting for IP...")
|
|
||||||
ip, err := vm.WaitForIP()
|
|
||||||
if err != nil {
|
|
||||||
state.Put("error", err)
|
|
||||||
return multistep.ActionHalt
|
|
||||||
}
|
|
||||||
state.Put("ip", ip)
|
|
||||||
ui.Say(fmt.Sprintf("IP address: %v", ip))
|
|
||||||
|
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/mitchellh/multistep"
|
||||||
|
"fmt"
|
||||||
|
"github.com/hashicorp/packer/packer"
|
||||||
|
"github.com/jetbrains-infra/packer-builder-vsphere/driver"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type StepWaitForIp struct{}
|
||||||
|
|
||||||
|
func (s *StepWaitForIp) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
vm := state.Get("vm").(*driver.VirtualMachine)
|
||||||
|
|
||||||
|
ui.Say("Waiting for IP...")
|
||||||
|
|
||||||
|
ipChan := make(chan string)
|
||||||
|
errChan := make(chan error)
|
||||||
|
go func() {
|
||||||
|
ip, err := vm.WaitForIP()
|
||||||
|
if err != nil {
|
||||||
|
errChan <- err
|
||||||
|
} else {
|
||||||
|
ipChan <- ip
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case err := <-errChan:
|
||||||
|
state.Put("error", err)
|
||||||
|
return multistep.ActionHalt
|
||||||
|
case ip := <-ipChan:
|
||||||
|
state.Put("ip", ip)
|
||||||
|
ui.Say(fmt.Sprintf("IP address: %v", ip))
|
||||||
|
return multistep.ActionContinue
|
||||||
|
case <-time.After(1 * time.Second):
|
||||||
|
if _, ok := state.GetOk(multistep.StateCancelled); ok {
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *StepWaitForIp) Cleanup(state multistep.StateBag) {
|
||||||
|
// nothing
|
||||||
|
}
|
|
@ -57,6 +57,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
&common.StepRun{
|
&common.StepRun{
|
||||||
Config: &b.config.RunConfig,
|
Config: &b.config.RunConfig,
|
||||||
},
|
},
|
||||||
|
&common.StepWaitForIp{},
|
||||||
&communicator.StepConnect{
|
&communicator.StepConnect{
|
||||||
Config: &b.config.Comm,
|
Config: &b.config.Comm,
|
||||||
Host: common.CommHost,
|
Host: common.CommHost,
|
||||||
|
|
Loading…
Reference in New Issue