Commit 14fae4c5 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

Merge pull request #1561 from kholloway/master

builder/qemu: Updates to QEMU builder - Fix -redir and machine type issues
parents b6238ec7 39e90de9
...@@ -139,7 +139,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { ...@@ -139,7 +139,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
} }
if b.config.MachineType == "" { if b.config.MachineType == "" {
b.config.MachineType = "pc-1.0" b.config.MachineType = "pc"
} }
if b.config.OutputDir == "" { if b.config.OutputDir == "" {
......
...@@ -2,11 +2,12 @@ package qemu ...@@ -2,11 +2,12 @@ package qemu
import ( import (
"fmt" "fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log" "log"
"math/rand" "math/rand"
"net" "net"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
) )
// This step adds a NAT port forwarding definition so that SSH is available // 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 { ...@@ -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) log.Printf("Looking for available SSH port between %d and %d", config.SSHHostPortMin, config.SSHHostPortMax)
var sshHostPort uint var sshHostPort uint
var offset uint = 0
portRange := int(config.SSHHostPortMax - config.SSHHostPortMin) portRange := int(config.SSHHostPortMax - config.SSHHostPortMin)
if portRange > 0 {
// Have to check if > 0 to avoid a panic
offset = uint(rand.Intn(portRange))
}
for { for {
sshHostPort = uint(rand.Intn(portRange)) + config.SSHHostPortMin sshHostPort = offset + config.SSHHostPortMin
log.Printf("Trying port: %d", sshHostPort) log.Printf("Trying port: %d", sshHostPort)
l, err := net.Listen("tcp", fmt.Sprintf(":%d", sshHostPort)) l, err := net.Listen("tcp", fmt.Sprintf(":%d", sshHostPort))
if err == nil { if err == nil {
......
...@@ -2,11 +2,12 @@ package qemu ...@@ -2,11 +2,12 @@ package qemu
import ( import (
"fmt" "fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log" "log"
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
) )
// stepRun runs the virtual machine // stepRun runs the virtual machine
...@@ -78,13 +79,12 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error ...@@ -78,13 +79,12 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error
defaultArgs["-name"] = vmName defaultArgs["-name"] = vmName
defaultArgs["-machine"] = fmt.Sprintf("type=%s", config.MachineType) 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["-device"] = fmt.Sprintf("%s,netdev=user.0", config.NetDevice)
defaultArgs["-drive"] = fmt.Sprintf("file=%s,if=%s", imgPath, config.DiskInterface) defaultArgs["-drive"] = fmt.Sprintf("file=%s,if=%s", imgPath, config.DiskInterface)
defaultArgs["-cdrom"] = isoPath defaultArgs["-cdrom"] = isoPath
defaultArgs["-boot"] = bootDrive defaultArgs["-boot"] = bootDrive
defaultArgs["-m"] = "512M" defaultArgs["-m"] = "512M"
defaultArgs["-redir"] = fmt.Sprintf("tcp:%v::22", sshHostPort)
defaultArgs["-vnc"] = vnc defaultArgs["-vnc"] = vnc
// Append the accelerator to the machine type if it is specified // Append the accelerator to the machine type if it is specified
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment