Add sata_port_count so that a SATA controller can be created with more than 1 port. The default of prevents additional drives being added. Default preserved if not overridden.

This commit is contained in:
Ben Phegan 2017-03-22 23:09:25 +11:00
parent 59881d052c
commit 67eb600c08
4 changed files with 19 additions and 7 deletions

View File

@ -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

View File

@ -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...)

View File

@ -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"))

View File

@ -2,12 +2,13 @@ package iso
import (
"fmt"
"github.com/mitchellh/multistep"
vboxcommon "github.com/mitchellh/packer/builder/virtualbox/common"
"github.com/mitchellh/packer/packer"
"path/filepath"
"strconv"
"strings"
"github.com/mitchellh/multistep"
vboxcommon "github.com/mitchellh/packer/builder/virtualbox/common"
"github.com/mitchellh/packer/packer"
)
// This step creates the virtual disk that will be used as the
@ -55,7 +56,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())