Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decrease the delay between Hyper-V VM startup and hyper-v builder's ability to send keystrokes to the target VM. #7970

Merged
merged 1 commit into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions builder/hyperv/common/step_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import (
"fmt"
"log"

"github.com/hashicorp/packer/common"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
)

type StepRun struct {
GuiCancelFunc context.CancelFunc
Headless bool
SwitchName string
vmName string
}

Expand All @@ -20,17 +22,17 @@ func (s *StepRun) Run(ctx context.Context, state multistep.StateBag) multistep.S
ui := state.Get("ui").(packer.Ui)
vmName := state.Get("vmName").(string)

ui.Say("Starting the virtual machine...")

err := driver.Start(vmName)
ui.Say("Determine Host IP for HyperV machine...")
hostIp, err := driver.GetHostAdapterIpAddressForSwitch(s.SwitchName)
if err != nil {
err := fmt.Errorf("Error starting vm: %s", err)
err := fmt.Errorf("Error getting host adapter ip address: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}

s.vmName = vmName
ui.Say(fmt.Sprintf("Host IP for the HyperV machine: %s", hostIp))
common.SetHTTPIP(hostIp)

if !s.Headless {
ui.Say("Attempting to connect with vmconnect...")
Expand All @@ -39,6 +41,19 @@ func (s *StepRun) Run(ctx context.Context, state multistep.StateBag) multistep.S
log.Printf(fmt.Sprintf("Non-fatal error starting vmconnect: %s. continuing...", err))
}
}

ui.Say("Starting the virtual machine...")

err = driver.Start(vmName)
if err != nil {
err := fmt.Errorf("Error starting vm: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}

s.vmName = vmName

return multistep.ActionContinue
}

Expand Down
13 changes: 1 addition & 12 deletions builder/hyperv/common/step_type_boot_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func (s *StepTypeBootCommand) Run(ctx context.Context, state multistep.StateBag)
ui := state.Get("ui").(packer.Ui)
driver := state.Get("driver").(Driver)
vmName := state.Get("vmName").(string)
hostIp := common.GetHTTPIP()

// Wait the for the vm to boot.
if int64(s.BootWait) > 0 {
Expand All @@ -45,18 +46,6 @@ func (s *StepTypeBootCommand) Run(ctx context.Context, state multistep.StateBag)
}
}

hostIp, err := driver.GetHostAdapterIpAddressForSwitch(s.SwitchName)

if err != nil {
err := fmt.Errorf("Error getting host adapter ip address: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}

ui.Say(fmt.Sprintf("Host IP for the HyperV machine: %s", hostIp))

common.SetHTTPIP(hostIp)
s.Ctx.Data = &bootCommandTemplateData{
hostIp,
httpPort,
Expand Down
3 changes: 2 additions & 1 deletion builder/hyperv/iso/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,8 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
},

&hypervcommon.StepRun{
Headless: b.config.Headless,
Headless: b.config.Headless,
SwitchName: b.config.SwitchName,
},

&hypervcommon.StepTypeBootCommand{
Expand Down
3 changes: 2 additions & 1 deletion builder/hyperv/vmcx/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
},

&hypervcommon.StepRun{
Headless: b.config.Headless,
Headless: b.config.Headless,
SwitchName: b.config.SwitchName,
},

&hypervcommon.StepTypeBootCommand{
Expand Down