From 2cf7e694bcf5566d93707ddff655ca698d43d819 Mon Sep 17 00:00:00 2001 From: Kent Holloway Date: Fri, 3 Oct 2014 10:14:02 -0500 Subject: [PATCH 1/4] Fix for panic when ssh min and max port is the same for qemu builder. Taken directly from a previous patch by mitchellh 8f50d2dd9a5b943881f0827fc07fbfb389e1407c --- builder/qemu/step_forward_ssh.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/builder/qemu/step_forward_ssh.go b/builder/qemu/step_forward_ssh.go index 7c7925b17..3b84d26c1 100644 --- a/builder/qemu/step_forward_ssh.go +++ b/builder/qemu/step_forward_ssh.go @@ -2,11 +2,12 @@ package qemu import ( "fmt" - "github.com/mitchellh/multistep" - "github.com/mitchellh/packer/packer" "log" "math/rand" "net" + + "github.com/mitchellh/multistep" + "github.com/mitchellh/packer/packer" ) // This step adds a NAT port forwarding definition so that SSH is available @@ -23,9 +24,16 @@ func (s *stepForwardSSH) Run(state multistep.StateBag) multistep.StepAction { log.Printf("Looking for available SSH port between %d and %d", config.SSHHostPortMin, config.SSHHostPortMax) var sshHostPort uint + var offset uint = 0 + portRange := int(config.SSHHostPortMax - config.SSHHostPortMin) + if portRange > 0 { + // Have to check if > 0 to avoid a panic + offset = uint(rand.Intn(portRange)) + } + for { - sshHostPort = uint(rand.Intn(portRange)) + config.SSHHostPortMin + sshHostPort = offset + config.SSHHostPortMin log.Printf("Trying port: %d", sshHostPort) l, err := net.Listen("tcp", fmt.Sprintf(":%d", sshHostPort)) if err == nil { From 2755ba17515eb6aa70b03735e79157cf9ebb2e9e Mon Sep 17 00:00:00 2001 From: Kent Holloway Date: Fri, 3 Oct 2014 10:37:03 -0500 Subject: [PATCH 2/4] Changing machinetype default to PC instead of PC-1.0 which seems to be a saner default that works on more platforms. RedHat in particular doesnt have PC-1.0 --- builder/qemu/builder.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/qemu/builder.go b/builder/qemu/builder.go index 971613dd8..77178ffd2 100644 --- a/builder/qemu/builder.go +++ b/builder/qemu/builder.go @@ -139,7 +139,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { } if b.config.MachineType == "" { - b.config.MachineType = "pc-1.0" + b.config.MachineType = "pc" } if b.config.OutputDir == "" { From 6b5a505384e2d62ce3341151afa333ab1435c3bb Mon Sep 17 00:00:00 2001 From: Kent Holloway Date: Fri, 3 Oct 2014 10:39:57 -0500 Subject: [PATCH 3/4] -redir is deprecated and missing on some versions of QEMU, using -netdev instead which is recommended. Removing M letter from Memory flag as QEMU now assumes this value is always in MB and errors out if you pass the M as a part of the command --- builder/qemu/step_run.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/builder/qemu/step_run.go b/builder/qemu/step_run.go index 6d4b43d6e..563237c96 100644 --- a/builder/qemu/step_run.go +++ b/builder/qemu/step_run.go @@ -2,11 +2,12 @@ package qemu import ( "fmt" - "github.com/mitchellh/multistep" - "github.com/mitchellh/packer/packer" "log" "path/filepath" "strings" + + "github.com/mitchellh/multistep" + "github.com/mitchellh/packer/packer" ) // stepRun runs the virtual machine @@ -78,13 +79,12 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error defaultArgs["-name"] = vmName defaultArgs["-machine"] = fmt.Sprintf("type=%s", config.MachineType) - defaultArgs["-netdev"] = "user,id=user.0" + defaultArgs["-netdev"] = fmt.Sprintf("user,id=user.0,hostfwd=tcp::%v-:22", sshHostPort) defaultArgs["-device"] = fmt.Sprintf("%s,netdev=user.0", config.NetDevice) defaultArgs["-drive"] = fmt.Sprintf("file=%s,if=%s", imgPath, config.DiskInterface) defaultArgs["-cdrom"] = isoPath defaultArgs["-boot"] = bootDrive - defaultArgs["-m"] = "512M" - defaultArgs["-redir"] = fmt.Sprintf("tcp:%v::22", sshHostPort) + defaultArgs["-m"] = "512" defaultArgs["-vnc"] = vnc // Append the accelerator to the machine type if it is specified From 9e2d0af5ab8e909f553200a0550ad1736c3a6767 Mon Sep 17 00:00:00 2001 From: Kent Holloway Date: Mon, 6 Oct 2014 10:11:39 -0500 Subject: [PATCH 4/4] Reverting previous change, including M on memory line to be explicit about what we are requesting --- builder/qemu/step_run.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/qemu/step_run.go b/builder/qemu/step_run.go index 563237c96..82a98dbba 100644 --- a/builder/qemu/step_run.go +++ b/builder/qemu/step_run.go @@ -84,7 +84,7 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error defaultArgs["-drive"] = fmt.Sprintf("file=%s,if=%s", imgPath, config.DiskInterface) defaultArgs["-cdrom"] = isoPath defaultArgs["-boot"] = bootDrive - defaultArgs["-m"] = "512" + defaultArgs["-m"] = "512M" defaultArgs["-vnc"] = vnc // Append the accelerator to the machine type if it is specified