Merge pull request #4699 from BenPhegan/virtualbox_sata_port_count

Add configuration to virtualbox-iso to allow sata port count configuration
pull/4967/head
Matthew Hooker 9 years ago committed by GitHub
commit ab81b3ef7d

@ -17,7 +17,7 @@ import (
// extremely specific. // extremely specific.
type Driver interface { type Driver interface {
// Create a SATA controller. // Create a SATA controller.
CreateSATAController(vm string, controller string) error CreateSATAController(vm string, controller string, portcount int) error
// Create a SCSI controller. // Create a SCSI controller.
CreateSCSIController(vm string, controller string) error CreateSCSIController(vm string, controller string) error

@ -6,6 +6,7 @@ import (
"log" "log"
"os/exec" "os/exec"
"regexp" "regexp"
"strconv"
"strings" "strings"
"time" "time"
) )
@ -15,7 +16,7 @@ type VBox42Driver struct {
VBoxManagePath string VBoxManagePath string
} }
func (d *VBox42Driver) CreateSATAController(vmName string, name string) error { func (d *VBox42Driver) CreateSATAController(vmName string, name string, portcount int) error {
version, err := d.Version() version, err := d.Version()
if err != nil { if err != nil {
return err return err
@ -30,7 +31,7 @@ func (d *VBox42Driver) CreateSATAController(vmName string, name string) error {
"storagectl", vmName, "storagectl", vmName,
"--name", name, "--name", name,
"--add", "sata", "--add", "sata",
portCountArg, "1", portCountArg, strconv.Itoa(portcount),
} }
return d.VBoxManage(command...) return d.VBoxManage(command...)

@ -47,7 +47,7 @@ type DriverMock struct {
VersionErr error VersionErr error
} }
func (d *DriverMock) CreateSATAController(vm string, controller string) error { func (d *DriverMock) CreateSATAController(vm string, controller string, portcount int) error {
d.CreateSATAControllerVM = vm d.CreateSATAControllerVM = vm
d.CreateSATAControllerController = vm d.CreateSATAControllerController = vm
return d.CreateSATAControllerErr return d.CreateSATAControllerErr

@ -46,6 +46,7 @@ type Config struct {
GuestOSType string `mapstructure:"guest_os_type"` GuestOSType string `mapstructure:"guest_os_type"`
HardDriveDiscard bool `mapstructure:"hard_drive_discard"` HardDriveDiscard bool `mapstructure:"hard_drive_discard"`
HardDriveInterface string `mapstructure:"hard_drive_interface"` HardDriveInterface string `mapstructure:"hard_drive_interface"`
SATAPortCount int `mapstructure:"sata_port_count"`
HardDriveNonrotational bool `mapstructure:"hard_drive_nonrotational"` HardDriveNonrotational bool `mapstructure:"hard_drive_nonrotational"`
ISOInterface string `mapstructure:"iso_interface"` ISOInterface string `mapstructure:"iso_interface"`
KeepRegistered bool `mapstructure:"keep_registered"` KeepRegistered bool `mapstructure:"keep_registered"`
@ -128,6 +129,15 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
errs, errors.New("hard_drive_interface can only be ide, sata, or scsi")) errs, errors.New("hard_drive_interface can only be ide, sata, or scsi"))
} }
if b.config.SATAPortCount == 0 {
b.config.SATAPortCount = 1
}
if b.config.SATAPortCount > 30 {
errs = packer.MultiErrorAppend(
errs, errors.New("sata_port_count cannot be greater than 30"))
}
if b.config.ISOInterface != "ide" && b.config.ISOInterface != "sata" { if b.config.ISOInterface != "ide" && b.config.ISOInterface != "sata" {
errs = packer.MultiErrorAppend( errs = packer.MultiErrorAppend(
errs, errors.New("iso_interface can only be ide or sata")) errs, errors.New("iso_interface can only be ide or sata"))

@ -2,9 +2,11 @@ package iso
import ( import (
"fmt" "fmt"
vboxcommon "github.com/hashicorp/packer/builder/virtualbox/common" vboxcommon "github.com/hashicorp/packer/builder/virtualbox/common"
"github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/packer"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
@ -55,7 +57,7 @@ func (s *stepCreateDisk) Run(state multistep.StateBag) multistep.StepAction {
// the IDE controller above because some other things (disks) require // the IDE controller above because some other things (disks) require
// that. // that.
if config.HardDriveInterface == "sata" || config.ISOInterface == "sata" { if config.HardDriveInterface == "sata" || config.ISOInterface == "sata" {
if err := driver.CreateSATAController(vmName, "SATA Controller"); err != nil { if err := driver.CreateSATAController(vmName, "SATA Controller", config.SATAPortCount); err != nil {
err := fmt.Errorf("Error creating disk controller: %s", err) err := fmt.Errorf("Error creating disk controller: %s", err)
state.Put("error", err) state.Put("error", err)
ui.Error(err.Error()) ui.Error(err.Error())

@ -199,6 +199,11 @@ builder.
is attached to an AHCI SATA controller. When set to "scsi", the drive is is attached to an AHCI SATA controller. When set to "scsi", the drive is
attached to an LsiLogic SCSI controller. attached to an LsiLogic SCSI controller.
- `sata_port_count` (integer) - The number of ports available on any SATA
controller created, defaults to 1. VirtualBox supports up to 30 ports on a
maxiumum of 1 SATA controller. Increasing this value can be useful if you
want to attach additional drives.
- `hard_drive_nonrotational` (boolean) - Forces some guests (i.e. Windows 7+) - `hard_drive_nonrotational` (boolean) - Forces some guests (i.e. Windows 7+)
to treat disks as SSDs and stops them from performing disk fragmentation. to treat disks as SSDs and stops them from performing disk fragmentation.
Also set `hard_drive_Discard` to `true` to enable TRIM support. Also set `hard_drive_Discard` to `true` to enable TRIM support.

Loading…
Cancel
Save