mirror of
https://github.com/hashicorp/packer.git
synced 2026-06-09 00:32:09 -04:00
Merge pull request #4699 from BenPhegan/virtualbox_sata_port_count
Add configuration to virtualbox-iso to allow sata port count configuration
This commit is contained in:
commit
ab81b3ef7d
6 changed files with 23 additions and 5 deletions
|
|
@ -17,7 +17,7 @@ import (
|
|||
// extremely specific.
|
||||
type Driver interface {
|
||||
// Create a SATA controller.
|
||||
CreateSATAController(vm string, controller string) error
|
||||
CreateSATAController(vm string, controller string, portcount int) error
|
||||
|
||||
// Create a SCSI controller.
|
||||
CreateSCSIController(vm string, controller string) error
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"log"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
|
@ -15,7 +16,7 @@ type VBox42Driver struct {
|
|||
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()
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -30,7 +31,7 @@ func (d *VBox42Driver) CreateSATAController(vmName string, name string) error {
|
|||
"storagectl", vmName,
|
||||
"--name", name,
|
||||
"--add", "sata",
|
||||
portCountArg, "1",
|
||||
portCountArg, strconv.Itoa(portcount),
|
||||
}
|
||||
|
||||
return d.VBoxManage(command...)
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ type DriverMock struct {
|
|||
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.CreateSATAControllerController = vm
|
||||
return d.CreateSATAControllerErr
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ type Config struct {
|
|||
GuestOSType string `mapstructure:"guest_os_type"`
|
||||
HardDriveDiscard bool `mapstructure:"hard_drive_discard"`
|
||||
HardDriveInterface string `mapstructure:"hard_drive_interface"`
|
||||
SATAPortCount int `mapstructure:"sata_port_count"`
|
||||
HardDriveNonrotational bool `mapstructure:"hard_drive_nonrotational"`
|
||||
ISOInterface string `mapstructure:"iso_interface"`
|
||||
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"))
|
||||
}
|
||||
|
||||
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" {
|
||||
errs = packer.MultiErrorAppend(
|
||||
errs, errors.New("iso_interface can only be ide or sata"))
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@ package iso
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
vboxcommon "github.com/hashicorp/packer/builder/virtualbox/common"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/mitchellh/multistep"
|
||||
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
|
@ -55,7 +57,7 @@ func (s *stepCreateDisk) Run(state multistep.StateBag) multistep.StepAction {
|
|||
// the IDE controller above because some other things (disks) require
|
||||
// that.
|
||||
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)
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
|
|
|
|||
|
|
@ -199,6 +199,11 @@ builder.
|
|||
is attached to an AHCI SATA controller. When set to "scsi", the drive is
|
||||
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+)
|
||||
to treat disks as SSDs and stops them from performing disk fragmentation.
|
||||
Also set `hard_drive_Discard` to `true` to enable TRIM support.
|
||||
|
|
|
|||
Loading…
Reference in a new issue