From 84d6d856f69162eb55ec1fc399bca1383e941e05 Mon Sep 17 00:00:00 2001 From: Danny Lockard Date: Thu, 15 Jan 2015 19:53:01 -0600 Subject: [PATCH 1/3] Add the ability to create a SCSI Device as the main HD controller for virtualbox. --- builder/virtualbox/common/driver.go | 3 +++ builder/virtualbox/common/driver_4_2.go | 12 ++++++++++++ builder/virtualbox/common/driver_mock.go | 10 ++++++++++ builder/virtualbox/iso/builder.go | 4 ++-- builder/virtualbox/iso/step_create_disk.go | 13 +++++++++++++ 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/builder/virtualbox/common/driver.go b/builder/virtualbox/common/driver.go index a55b20199..9fb82f7da 100644 --- a/builder/virtualbox/common/driver.go +++ b/builder/virtualbox/common/driver.go @@ -18,6 +18,9 @@ import ( type Driver interface { // Create a SATA controller. CreateSATAController(vm string, controller string) error + + // Create a SCSI controller. + CreateSCSIController(vm string, controller string) error // Delete a VM by name Delete(string) error diff --git a/builder/virtualbox/common/driver_4_2.go b/builder/virtualbox/common/driver_4_2.go index 3462933cd..f53a7ac4b 100644 --- a/builder/virtualbox/common/driver_4_2.go +++ b/builder/virtualbox/common/driver_4_2.go @@ -36,6 +36,18 @@ func (d *VBox42Driver) CreateSATAController(vmName string, name string) error { return d.VBoxManage(command...) } +func (d *VBox42Driver) CreateSCSIController(vmName string, name string) error { + + command := []string{ + "storagectl", vmName, + "--name", name, + "--add", "scsi", + "--controller", "LSILogic", + } + + return d.VBoxManage(command...) +} + func (d *VBox42Driver) Delete(name string) error { return d.VBoxManage("unregistervm", name, "--delete") } diff --git a/builder/virtualbox/common/driver_mock.go b/builder/virtualbox/common/driver_mock.go index 1aacf9f8f..b0f5dbe94 100644 --- a/builder/virtualbox/common/driver_mock.go +++ b/builder/virtualbox/common/driver_mock.go @@ -9,6 +9,10 @@ type DriverMock struct { CreateSATAControllerController string CreateSATAControllerErr error + CreateSCSIControllerVM string + CreateSCSIControllerController string + CreateSCSIControllerErr error + DeleteCalled bool DeleteName string DeleteErr error @@ -49,6 +53,12 @@ func (d *DriverMock) CreateSATAController(vm string, controller string) error { return d.CreateSATAControllerErr } +func (d *DriverMock) CreateSCSIController(vm string, controller string) error { + d.CreateSCSIControllerVM = vm + d.CreateSCSIControllerController = vm + return d.CreateSCSIControllerErr +} + func (d *DriverMock) Delete(name string) error { d.DeleteCalled = true d.DeleteName = name diff --git a/builder/virtualbox/iso/builder.go b/builder/virtualbox/iso/builder.go index c4c51c892..826d3ffe9 100644 --- a/builder/virtualbox/iso/builder.go +++ b/builder/virtualbox/iso/builder.go @@ -158,9 +158,9 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { } } - if b.config.HardDriveInterface != "ide" && b.config.HardDriveInterface != "sata" { + if b.config.HardDriveInterface != "ide" && b.config.HardDriveInterface != "sata" && b.config.HardDriveInterface != "scsi" { errs = packer.MultiErrorAppend( - errs, errors.New("hard_drive_interface can only be ide or sata")) + errs, errors.New("hard_drive_interface can only be ide, sata, or scsi")) } if b.config.ISOChecksumType == "" { diff --git a/builder/virtualbox/iso/step_create_disk.go b/builder/virtualbox/iso/step_create_disk.go index 564a2f4d3..626ca9b28 100644 --- a/builder/virtualbox/iso/step_create_disk.go +++ b/builder/virtualbox/iso/step_create_disk.go @@ -63,11 +63,24 @@ func (s *stepCreateDisk) Run(state multistep.StateBag) multistep.StepAction { } } + if config.HardDriveInterface == "scsi" { + if err := driver.CreateSCSIController(vmName, "SCSI Controller"); err != nil { + err := fmt.Errorf("Error creating disk controller: %s", err) + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt + } + } + // Attach the disk to the controller controllerName := "IDE Controller" if config.HardDriveInterface == "sata" { controllerName = "SATA Controller" } + + if config.HardDriveInterface == "scsi" { + controllerName = "SCSI Controller" + } command = []string{ "storageattach", vmName, From fdcf10dc64414cfeb186a41cd47cb76fb05376f1 Mon Sep 17 00:00:00 2001 From: Danny Lockard Date: Thu, 15 Jan 2015 19:56:30 -0600 Subject: [PATCH 2/3] and update the docs to indicate you can use 'scsi' in place of sata or ide --- website/source/docs/builders/virtualbox-iso.html.markdown | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/website/source/docs/builders/virtualbox-iso.html.markdown b/website/source/docs/builders/virtualbox-iso.html.markdown index f8a45d352..b97045f16 100644 --- a/website/source/docs/builders/virtualbox-iso.html.markdown +++ b/website/source/docs/builders/virtualbox-iso.html.markdown @@ -136,7 +136,8 @@ each category, the available options are alphabetized and described. * `hard_drive_interface` (string) - The type of controller that the primary hard drive is attached to, defaults to "ide". When set to "sata", the - drive is attached to an AHCI SATA controller. + drive is attached to an AHCI SATA controller. When set to "scsi", the drive + is attached to an LsiLogic SCSI controller. * `headless` (boolean) - Packer defaults to building VirtualBox virtual machines by launching a GUI that shows the console of the From 7d1b95c907383a4e67a7e0db0035fe826b5d446f Mon Sep 17 00:00:00 2001 From: Danny Lockard Date: Fri, 16 Jan 2015 10:34:12 -0600 Subject: [PATCH 3/3] Formatting fix :) --- builder/virtualbox/common/driver.go | 6 +++--- builder/virtualbox/common/driver_4_2.go | 2 +- builder/virtualbox/common/driver_mock.go | 8 ++++---- builder/virtualbox/iso/step_create_disk.go | 24 +++++++++++----------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/builder/virtualbox/common/driver.go b/builder/virtualbox/common/driver.go index 9fb82f7da..add59c7f1 100644 --- a/builder/virtualbox/common/driver.go +++ b/builder/virtualbox/common/driver.go @@ -18,9 +18,9 @@ import ( type Driver interface { // Create a SATA controller. CreateSATAController(vm string, controller string) error - - // Create a SCSI controller. - CreateSCSIController(vm string, controller string) error + + // Create a SCSI controller. + CreateSCSIController(vm string, controller string) error // Delete a VM by name Delete(string) error diff --git a/builder/virtualbox/common/driver_4_2.go b/builder/virtualbox/common/driver_4_2.go index f53a7ac4b..c375fba32 100644 --- a/builder/virtualbox/common/driver_4_2.go +++ b/builder/virtualbox/common/driver_4_2.go @@ -42,7 +42,7 @@ func (d *VBox42Driver) CreateSCSIController(vmName string, name string) error { "storagectl", vmName, "--name", name, "--add", "scsi", - "--controller", "LSILogic", + "--controller", "LSILogic", } return d.VBoxManage(command...) diff --git a/builder/virtualbox/common/driver_mock.go b/builder/virtualbox/common/driver_mock.go index b0f5dbe94..da08ad072 100644 --- a/builder/virtualbox/common/driver_mock.go +++ b/builder/virtualbox/common/driver_mock.go @@ -9,7 +9,7 @@ type DriverMock struct { CreateSATAControllerController string CreateSATAControllerErr error - CreateSCSIControllerVM string + CreateSCSIControllerVM string CreateSCSIControllerController string CreateSCSIControllerErr error @@ -54,9 +54,9 @@ func (d *DriverMock) CreateSATAController(vm string, controller string) error { } func (d *DriverMock) CreateSCSIController(vm string, controller string) error { - d.CreateSCSIControllerVM = vm - d.CreateSCSIControllerController = vm - return d.CreateSCSIControllerErr + d.CreateSCSIControllerVM = vm + d.CreateSCSIControllerController = vm + return d.CreateSCSIControllerErr } func (d *DriverMock) Delete(name string) error { diff --git a/builder/virtualbox/iso/step_create_disk.go b/builder/virtualbox/iso/step_create_disk.go index 626ca9b28..82b849dbe 100644 --- a/builder/virtualbox/iso/step_create_disk.go +++ b/builder/virtualbox/iso/step_create_disk.go @@ -63,24 +63,24 @@ func (s *stepCreateDisk) Run(state multistep.StateBag) multistep.StepAction { } } - if config.HardDriveInterface == "scsi" { - if err := driver.CreateSCSIController(vmName, "SCSI Controller"); err != nil { - err := fmt.Errorf("Error creating disk controller: %s", err) - state.Put("error", err) - ui.Error(err.Error()) - return multistep.ActionHalt - } - } + if config.HardDriveInterface == "scsi" { + if err := driver.CreateSCSIController(vmName, "SCSI Controller"); err != nil { + err := fmt.Errorf("Error creating disk controller: %s", err) + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt + } + } // Attach the disk to the controller controllerName := "IDE Controller" if config.HardDriveInterface == "sata" { controllerName = "SATA Controller" } - - if config.HardDriveInterface == "scsi" { - controllerName = "SCSI Controller" - } + + if config.HardDriveInterface == "scsi" { + controllerName = "SCSI Controller" + } command = []string{ "storageattach", vmName,