Merge pull request #3681 from yoctocloud/communicator
builder/qemu: dont fail on communicator set to none
This commit is contained in:
commit
3ab49595e6
|
@ -375,19 +375,40 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
HTTPPortMin: b.config.HTTPPortMin,
|
||||
HTTPPortMax: b.config.HTTPPortMax,
|
||||
},
|
||||
)
|
||||
|
||||
if b.config.Comm.Type != "none" {
|
||||
steps = append(steps,
|
||||
new(stepForwardSSH),
|
||||
)
|
||||
}
|
||||
|
||||
steps = append(steps,
|
||||
new(stepConfigureVNC),
|
||||
steprun,
|
||||
&stepBootWait{},
|
||||
&stepTypeBootCommand{},
|
||||
)
|
||||
|
||||
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),
|
||||
)
|
||||
|
||||
|
|
|
@ -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)
|
||||
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,6 +162,7 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error
|
|||
|
||||
httpPort := state.Get("http_port").(uint)
|
||||
ctx := config.ctx
|
||||
if config.Comm.Type != "none" {
|
||||
ctx.Data = qemuArgsTemplateData{
|
||||
"10.0.2.2",
|
||||
httpPort,
|
||||
|
@ -165,6 +171,15 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error
|
|||
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 {
|
||||
return nil, err
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue