From 30be4927d6ddb708a4b216cdfa8b8881ec195928 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 20 Oct 2013 15:54:34 -0700 Subject: [PATCH] builder/virtualbox: use proper SATA port arg [GH-547] --- CHANGELOG.md | 2 ++ builder/virtualbox/driver.go | 30 +++++++++++++++++++++++++- builder/virtualbox/step_create_disk.go | 8 +------ 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50aa2ecec..e9ba9b196 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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] diff --git a/builder/virtualbox/driver.go b/builder/virtualbox/driver.go index b4a5392da..88d37eba9 100644 --- a/builder/virtualbox/driver.go +++ b/builder/virtualbox/driver.go @@ -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 diff --git a/builder/virtualbox/step_create_disk.go b/builder/virtualbox/step_create_disk.go index 14005cc85..f0d803295 100644 --- a/builder/virtualbox/step_create_disk.go +++ b/builder/virtualbox/step_create_disk.go @@ -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())