diff --git a/builder/qemu/builder.go b/builder/qemu/builder.go index f151bf68c..413591899 100644 --- a/builder/qemu/builder.go +++ b/builder/qemu/builder.go @@ -376,19 +376,40 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe HTTPPortMin: b.config.HTTPPortMin, HTTPPortMax: b.config.HTTPPortMax, }, - new(stepForwardSSH), + ) + + if b.config.Comm.Type != "none" { + steps = append(steps, + new(stepForwardSSH), + ) + } + + steps = append(steps, new(stepConfigureVNC), steprun, &stepBootWait{}, &stepTypeBootCommand{}, - &communicator.StepConnect{ - Config: &b.config.Comm, - Host: commHost, - SSHConfig: sshConfig, - SSHPort: commPort, - }, + ) + + if b.config.Comm.Type != "none" { + steps = append(steps, + &communicator.StepConnect{ + Config: &b.config.Comm, + Host: commHost, + SSHConfig: sshConfig, + SSHPort: commPort, + }, + ) + } + + steps = append(steps, new(common.StepProvision), + ) + steps = append(steps, new(stepShutdown), + ) + + steps = append(steps, new(stepConvertDisk), ) diff --git a/builder/qemu/step_run.go b/builder/qemu/step_run.go index 82bcbe7c0..36ab074f5 100644 --- a/builder/qemu/step_run.go +++ b/builder/qemu/step_run.go @@ -63,7 +63,6 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error isoPath := state.Get("iso_path").(string) vncIP := state.Get("vnc_ip").(string) vncPort := state.Get("vnc_port").(uint) - sshHostPort := state.Get("sshHostPort").(uint) ui := state.Get("ui").(packer.Ui) driver := state.Get("driver").(Driver) @@ -74,10 +73,16 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error defaultArgs := make(map[string]interface{}) var deviceArgs []string var driveArgs []string + var sshHostPort uint defaultArgs["-name"] = vmName defaultArgs["-machine"] = fmt.Sprintf("type=%s", config.MachineType) - defaultArgs["-netdev"] = fmt.Sprintf("user,id=user.0,hostfwd=tcp::%v-:%d", sshHostPort, config.Comm.Port()) + if config.Comm.Type != "none" { + sshHostPort = state.Get("sshHostPort").(uint) + defaultArgs["-netdev"] = fmt.Sprintf("user,id=user.0,hostfwd=tcp::%v-:%d", sshHostPort, config.Comm.Port()) + } else { + defaultArgs["-netdev"] = fmt.Sprintf("user,id=user.0") + } qemuVersion, err := driver.Version() if err != nil { @@ -157,13 +162,23 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error httpPort := state.Get("http_port").(uint) ctx := config.ctx - ctx.Data = qemuArgsTemplateData{ - "10.0.2.2", - httpPort, - config.HTTPDir, - config.OutputDir, - config.VMName, - sshHostPort, + if config.Comm.Type != "none" { + ctx.Data = qemuArgsTemplateData{ + "10.0.2.2", + httpPort, + config.HTTPDir, + config.OutputDir, + config.VMName, + sshHostPort, + } + } else { + ctx.Data = qemuArgsTemplateData{ + HTTPIP: "10.0.2.2", + HTTPPort: httpPort, + HTTPDir: config.HTTPDir, + OutputDir: config.OutputDir, + Name: config.VMName, + } } newQemuArgs, err := processArgs(config.QemuArgs, &ctx) if err != nil { diff --git a/builder/qemu/step_shutdown.go b/builder/qemu/step_shutdown.go index 127dcff12..2bca7a09e 100644 --- a/builder/qemu/step_shutdown.go +++ b/builder/qemu/step_shutdown.go @@ -3,10 +3,11 @@ package qemu import ( "errors" "fmt" - "github.com/mitchellh/multistep" - "github.com/mitchellh/packer/packer" "log" "time" + + "github.com/mitchellh/multistep" + "github.com/mitchellh/packer/packer" ) // This step shuts down the machine. It first attempts to do so gracefully, @@ -23,11 +24,29 @@ import ( type stepShutdown struct{} func (s *stepShutdown) Run(state multistep.StateBag) multistep.StepAction { - comm := state.Get("communicator").(packer.Communicator) config := state.Get("config").(*Config) driver := state.Get("driver").(Driver) ui := state.Get("ui").(packer.Ui) + if state.Get("communicator") == nil { + cancelCh := make(chan struct{}, 1) + go func() { + defer close(cancelCh) + <-time.After(config.shutdownTimeout) + }() + ui.Say("Waiting for shutdown...") + if ok := driver.WaitForShutdown(cancelCh); ok { + log.Println("VM shut down.") + return multistep.ActionContinue + } else { + err := fmt.Errorf("Failed to shutdown") + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt + } + } + + comm := state.Get("communicator").(packer.Communicator) if config.ShutdownCommand != "" { ui.Say("Gracefully halting virtual machine...") log.Printf("Executing shutdown command: %s", config.ShutdownCommand)