builder/virtualbox: Attach ISO
This commit is contained in:
parent
54057b7b49
commit
081b0d6853
|
@ -23,10 +23,10 @@ type Builder struct {
|
||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
GuestOSType string `mapstructure:"guest_os_type"`
|
GuestOSType string `mapstructure:"guest_os_type"`
|
||||||
ISOMD5 string `mapstructure:"iso_md5"`
|
ISOMD5 string `mapstructure:"iso_md5"`
|
||||||
ISOUrl string `mapstructure:"iso_url"`
|
ISOUrl string `mapstructure:"iso_url"`
|
||||||
OutputDir string `mapstructure:"output_directory"`
|
OutputDir string `mapstructure:"output_directory"`
|
||||||
VMName string `mapstructure:"vm_name"`
|
VMName string `mapstructure:"vm_name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) Prepare(raw interface{}) error {
|
func (b *Builder) Prepare(raw interface{}) error {
|
||||||
|
@ -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
|
||||||
|
|
|
@ -34,7 +34,7 @@ func (d *VBox42Driver) SuppressMessages() error {
|
||||||
extraData := map[string]string{
|
extraData := map[string]string{
|
||||||
"GUI/RegistrationData": "triesLeft=0",
|
"GUI/RegistrationData": "triesLeft=0",
|
||||||
"GUI/SuppressMessages": "confirmInputCapture,remindAboutAutoCapture,remindAboutMouseIntegrationOff,remindAboutMouseIntegrationOn,remindAboutWrongColorDepth",
|
"GUI/SuppressMessages": "confirmInputCapture,remindAboutAutoCapture,remindAboutMouseIntegrationOff,remindAboutMouseIntegrationOn,remindAboutWrongColorDepth",
|
||||||
"GUI/UpdateDate": fmt.Sprintf("1 d, %d-01-01, stable", time.Now().Year()+1),
|
"GUI/UpdateDate": fmt.Sprintf("1 d, %d-01-01, stable", time.Now().Year()+1),
|
||||||
"GUI/UpdateCheckCount": "60",
|
"GUI/UpdateCheckCount": "60",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
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 (
|
||||||
"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
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(15 * time.Second)
|
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue