Commit 081b0d68 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/virtualbox: Attach ISO

parent 54057b7b
...@@ -113,6 +113,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) packer ...@@ -113,6 +113,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) packer
new(stepSuppressMessages), new(stepSuppressMessages),
new(stepCreateVM), new(stepCreateVM),
new(stepCreateDisk), new(stepCreateDisk),
new(stepAttachISO),
} }
// Setup the state bag // Setup the state bag
......
package virtualbox
import (
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"time"
)
// This step attaches the ISO to the virtual machine.
//
// Uses:
//
// Produces:
type stepAttachISO struct{
diskPath string
}
func (s *stepAttachISO) Run(state map[string]interface{}) multistep.StepAction {
driver := state["driver"].(Driver)
isoPath := state["iso_path"].(string)
ui := state["ui"].(packer.Ui)
vmName := state["vmName"].(string)
// Attach the disk to the controller
command := []string{
"storageattach", vmName,
"--storagectl", "IDE Controller",
"--port", "0",
"--device", "1",
"--type", "dvddrive",
"--medium", isoPath,
}
if err := driver.VBoxManage(command...); err != nil {
ui.Error(fmt.Sprintf("Error attaching hard drive: %s", err))
return multistep.ActionHalt
}
// Track the path so that we can unregister it from VirtualBox later
s.diskPath = isoPath
time.Sleep(15 * time.Second)
return multistep.ActionContinue
}
func (s *stepAttachISO) Cleanup(state map[string]interface{}) {
if s.diskPath == "" {
return
}
driver := state["driver"].(Driver)
ui := state["ui"].(packer.Ui)
if err := driver.VBoxManage("closemedium", "disk", s.diskPath); err != nil {
ui.Error(fmt.Sprintf("Error unregistering ISO: %s", err))
}
}
...@@ -6,12 +6,11 @@ import ( ...@@ -6,12 +6,11 @@ import (
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"path/filepath" "path/filepath"
"strings" "strings"
"time"
) )
// This step creates the virtual disk that will be used as the // This step creates the virtual disk that will be used as the
// hard drive for the virtual machine. // hard drive for the virtual machine.
type stepCreateDisk struct{ type stepCreateDisk struct {
diskPath string diskPath string
} }
...@@ -64,7 +63,6 @@ func (s *stepCreateDisk) Run(state map[string]interface{}) multistep.StepAction ...@@ -64,7 +63,6 @@ func (s *stepCreateDisk) Run(state map[string]interface{}) multistep.StepAction
return multistep.ActionHalt return multistep.ActionHalt
} }
time.Sleep(15 * time.Second)
return multistep.ActionContinue return multistep.ActionContinue
} }
......
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
// //
// Produces: // Produces:
// vmName string - The name of the VM // vmName string - The name of the VM
type stepCreateVM struct{ type stepCreateVM struct {
vmName string vmName string
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment