builder/virtualbox: use proper SATA port arg [GH-547]

This commit is contained in:
Mitchell Hashimoto 2013-10-20 15:54:34 -07:00
parent 273e161b27
commit 30be4927d6
3 changed files with 32 additions and 8 deletions

View File

@ -19,8 +19,10 @@ BUG FIXES:
* builder/virtualbox: detect if vboxdrv isn't properly setup. [GH-488]
* builder/virtualbox: sleep a bit before export to ensure the sesssion
is unlocked. [GH-512]
* builder/virtualbox: create SATA drives properly on VirtualBox 4.3 [GH-547]
* communicator/ssh: Fix issue where a panic could arise from a nil
dereference. [GH-525]
* post-processor/vagrant: Fix issue with VirtualBox OVA. [GH-548]
* provisioner/shell: Won't block on certain scripts on Windows anymore.
[GH-507]

View File

@ -11,8 +11,15 @@ import (
)
// A driver is able to talk to VirtualBox and perform certain
// operations with it.
// operations with it. Some of the operations on here may seem overly
// specific, but they were built specifically in mind to handle features
// of the VirtualBox builder for Packer, and to abstract differences in
// versions out of the builder steps, so sometimes the methods are
// extremely specific.
type Driver interface {
// Create a SATA controller.
CreateSATAController(vm string, controller string) error
// Checks if the VM with the given name is running.
IsRunning(string) (bool, error)
@ -40,6 +47,27 @@ type VBox42Driver struct {
VBoxManagePath string
}
func (d *VBox42Driver) CreateSATAController(vmName string, name string) error {
version, err := d.Version()
if err != nil {
return err
}
portCountArg := "sataportcount"
if strings.HasPrefix(version, "4.3") {
portCountArg = "portcount"
}
command := []string{
"storagectl", vmName,
"--name", name,
"--add", "sata",
portCountArg, "1",
}
return d.VBoxManage(command...)
}
func (d *VBox42Driver) IsRunning(name string) (bool, error) {
var stdout bytes.Buffer

View File

@ -56,13 +56,7 @@ func (s *stepCreateDisk) Run(state multistep.StateBag) multistep.StepAction {
// that.
if config.HardDriveInterface == "sata" {
controllerName = "SATA Controller"
command = []string{
"storagectl", vmName,
"--name", controllerName,
"--add", "sata",
"--sataportcount", "1",
}
if err := driver.VBoxManage(command...); err != nil {
if err := driver.CreateSATAController(vmName, controllerName); err != nil {
err := fmt.Errorf("Error creating disk controller: %s", err)
state.Put("error", err)
ui.Error(err.Error())