VirtualBox: added support for "virtio" storage.
This commit is contained in:
parent
c9c65383e9
commit
f48d7e3990
|
@ -22,6 +22,9 @@ type Driver interface {
|
|||
// Create a SCSI controller.
|
||||
CreateSCSIController(vm string, controller string) error
|
||||
|
||||
// Create a VirtIO controller.
|
||||
CreateVirtIOController(vm string, controller string) error
|
||||
|
||||
// Create an NVME controller
|
||||
CreateNVMeController(vm string, controller string, portcount int) error
|
||||
|
||||
|
|
|
@ -64,7 +64,6 @@ func (d *VBox42Driver) CreateNVMeController(vmName string, name string, portcoun
|
|||
}
|
||||
|
||||
func (d *VBox42Driver) CreateSCSIController(vmName string, name string) error {
|
||||
|
||||
command := []string{
|
||||
"storagectl", vmName,
|
||||
"--name", name,
|
||||
|
@ -75,6 +74,17 @@ func (d *VBox42Driver) CreateSCSIController(vmName string, name string) error {
|
|||
return d.VBoxManage(command...)
|
||||
}
|
||||
|
||||
func (d *VBox42Driver) CreateVirtIOController(vmName string, name string) error {
|
||||
command := []string{
|
||||
"storagectl", vmName,
|
||||
"--name", name,
|
||||
"--add", "VirtIO",
|
||||
"--controller", "VirtIO",
|
||||
}
|
||||
|
||||
return d.VBoxManage(command...)
|
||||
}
|
||||
|
||||
func (d *VBox42Driver) RemoveFloppyControllers(vmName string) error {
|
||||
var stdout bytes.Buffer
|
||||
|
||||
|
|
|
@ -13,6 +13,10 @@ type DriverMock struct {
|
|||
CreateSCSIControllerController string
|
||||
CreateSCSIControllerErr error
|
||||
|
||||
CreateVirtIOControllerVM string
|
||||
CreateVirtIOControllerController string
|
||||
CreateVirtIOControllerErr error
|
||||
|
||||
CreateNVMeControllerVM string
|
||||
CreateNVMeControllerController string
|
||||
CreateNVMeControllerErr error
|
||||
|
@ -78,6 +82,12 @@ func (d *DriverMock) CreateSCSIController(vm string, controller string) error {
|
|||
return d.CreateSCSIControllerErr
|
||||
}
|
||||
|
||||
func (d *DriverMock) CreateVirtIOController(vm string, controller string) error {
|
||||
d.CreateVirtIOControllerVM = vm
|
||||
d.CreateVirtIOControllerController = vm
|
||||
return d.CreateVirtIOControllerErr
|
||||
}
|
||||
|
||||
func (d *DriverMock) CreateNVMeController(vm string, controller string, portcount int) error {
|
||||
d.CreateNVMeControllerVM = vm
|
||||
d.CreateNVMeControllerController = vm
|
||||
|
|
|
@ -186,11 +186,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
|
|||
}
|
||||
|
||||
switch b.config.HardDriveInterface {
|
||||
case "ide", "sata", "scsi", "pcie":
|
||||
case "ide", "sata", "scsi", "pcie", "virtio":
|
||||
// do nothing
|
||||
default:
|
||||
errs = packersdk.MultiErrorAppend(
|
||||
errs, errors.New("hard_drive_interface can only be ide, sata, pcie or scsi"))
|
||||
errs, errors.New("hard_drive_interface can only be ide, sata, pcie, scsi or virtio"))
|
||||
}
|
||||
|
||||
if b.config.SATAPortCount == 0 {
|
||||
|
|
|
@ -73,6 +73,13 @@ func (s *stepCreateDisk) Run(ctx context.Context, state multistep.StateBag) mult
|
|||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
} else if config.HardDriveInterface == "virtio" {
|
||||
if err := driver.CreateVirtIOController(vmName, "VirtIO Controller"); err != nil {
|
||||
err := fmt.Errorf("Error creating disk controller: %s", err)
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
} else if config.HardDriveInterface == "pcie" {
|
||||
if err := driver.CreateNVMeController(vmName, "NVMe Controller", config.NVMePortCount); err != nil {
|
||||
err := fmt.Errorf("Error creating NVMe controller: %s", err)
|
||||
|
@ -86,13 +93,11 @@ func (s *stepCreateDisk) Run(ctx context.Context, state multistep.StateBag) mult
|
|||
controllerName := "IDE Controller"
|
||||
if config.HardDriveInterface == "sata" {
|
||||
controllerName = "SATA Controller"
|
||||
}
|
||||
|
||||
if config.HardDriveInterface == "scsi" {
|
||||
} else if config.HardDriveInterface == "scsi" {
|
||||
controllerName = "SCSI Controller"
|
||||
}
|
||||
|
||||
if config.HardDriveInterface == "pcie" {
|
||||
} else if config.HardDriveInterface == "virtio" {
|
||||
controllerName = "VirtIO Controller"
|
||||
} else if config.HardDriveInterface == "pcie" {
|
||||
controllerName = "NVMe Controller"
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue