Skip to content

Commit

Permalink
Starting up the machine works.
Browse files Browse the repository at this point in the history
  • Loading branch information
rickard-von-essen committed Jan 20, 2014
1 parent c61f750 commit 3cf9c4c
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 176 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/pkg
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ go:

install: make deps
script:
- go test ./...
- go test -race ./...
- go test ./builder-parallels-iso/...
- go test -race ./builder-parallels-iso/...

matrix:
allow_failures:
Expand Down
74 changes: 9 additions & 65 deletions common/step_attach_floppy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ import (
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
)

// This step attaches the ISO to the virtual machine.
// This step attaches a floppy to the virtual machine.
//
// Uses:
// driver Driver
Expand All @@ -33,15 +30,6 @@ func (s *StepAttachFloppy) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionContinue
}

// VirtualBox is really dumb and can't figure out the format of the file
// without an extension, so we need to add the "vfd" extension to the
// floppy.
floppyPath, err := s.copyFloppy(floppyPath)
if err != nil {
state.Put("error", fmt.Errorf("Error preparing floppy: %s", err))
return multistep.ActionHalt
}

driver := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui)
vmName := state.Get("vmName").(string)
Expand All @@ -50,30 +38,16 @@ func (s *StepAttachFloppy) Run(state multistep.StateBag) multistep.StepAction {

// Create the floppy disk controller
command := []string{
"storagectl", vmName,
"--name", "Floppy Controller",
"--add", "floppy",
"set", vmName,
"--device-add", "fdd",
"--image", floppyPath,
}
if err := driver.Prlctl(command...); err != nil {
state.Put("error", fmt.Errorf("Error creating floppy controller: %s", err))
state.Put("error", fmt.Errorf("Error adding floppy: %s", err))
return multistep.ActionHalt
}

// Attach the floppy to the controller
command = []string{
"storageattach", vmName,
"--storagectl", "Floppy Controller",
"--port", "0",
"--device", "0",
"--type", "fdd",
"--medium", floppyPath,
}
if err := driver.Prlctl(command...); err != nil {
state.Put("error", fmt.Errorf("Error attaching floppy: %s", err))
return multistep.ActionHalt
}

// Track the path so that we can unregister it from VirtualBox later
// Track the path so that we can unregister it from Parallels later
s.floppyPath = floppyPath

return multistep.ActionContinue
Expand All @@ -91,41 +65,11 @@ func (s *StepAttachFloppy) Cleanup(state multistep.StateBag) {
vmName := state.Get("vmName").(string)

command := []string{
"storageattach", vmName,
"--storagectl", "Floppy Controller",
"--port", "0",
"--device", "0",
"--medium", "none",
"set", vmName,
"--device-del", s.floppyPath,
}

if err := driver.Prlctl(command...); err != nil {
log.Printf("Error unregistering floppy: %s", err)
}
}

func (s *StepAttachFloppy) copyFloppy(path string) (string, error) {
tempdir, err := ioutil.TempDir("", "packer")
if err != nil {
return "", err
log.Printf("Error removing floppy: %s", err)
}

floppyPath := filepath.Join(tempdir, "floppy.vfd")
f, err := os.Create(floppyPath)
if err != nil {
return "", err
}
defer f.Close()

sourceF, err := os.Open(path)
if err != nil {
return "", err
}
defer sourceF.Close()

log.Printf("Copying floppy to temp location: %s", floppyPath)
if _, err := io.Copy(f, sourceF); err != nil {
return "", err
}

return floppyPath, nil
}
2 changes: 1 addition & 1 deletion common/step_prlctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (s *StepPrlctl) Run(state multistep.StateBag) multistep.StepAction {
var err error
command[i], err = s.Tpl.Process(arg, tplData)
if err != nil {
err := fmt.Errorf("Error preparing vboxmanage command: %s", err)
err := fmt.Errorf("Error preparing prlctl command: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
Expand Down
10 changes: 5 additions & 5 deletions common/step_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ func (s *StepRun) Run(state multistep.StateBag) multistep.StepAction {
vmName := state.Get("vmName").(string)

ui.Say("Starting the virtual machine...")
guiArgument := "gui"
//guiArgument := "gui"
if s.Headless == true {
ui.Message("WARNING: The VM will be started in headless mode, as configured.\n" +
"In headless mode, errors during the boot sequence or OS setup\n" +
"won't be easily visible. Use at your own discretion.")
guiArgument = "headless"
//guiArgument = "headless"
}
command := []string{"startvm", vmName, "--type", guiArgument}
command := []string{"start", vmName}
if err := driver.Prlctl(command...); err != nil {
err := fmt.Errorf("Error starting VM: %s", err)
state.Put("error", err)
Expand Down Expand Up @@ -73,8 +73,8 @@ func (s *StepRun) Cleanup(state multistep.StateBag) {
ui := state.Get("ui").(packer.Ui)

if running, _ := driver.IsRunning(s.vmName); running {
if err := driver.Prlctl("controlvm", s.vmName, "poweroff"); err != nil {
ui.Error(fmt.Sprintf("Error shutting down VM: %s", err))
if err := driver.Prlctl("stop", s.vmName); err != nil {
ui.Error(fmt.Sprintf("Error stopping VM: %s", err))
}
}
}
5 changes: 0 additions & 5 deletions common/step_use_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,9 @@ import (
type StepUseDefaults struct{}

func (StepUseDefaults) Run(state multistep.StateBag) multistep.StepAction {
log.Printf("DEFAULT: 1") //DEBUG
driver := state.Get("driver").(Driver)
log.Printf("DEFAULT: 2") //DEBUG
ui := state.Get("ui").(packer.Ui)
log.Printf("DEFAULT: 3") //DEBUG
log.Printf("State: %s", state) // DEBUG
vmName := state.Get("vmName").(string)
log.Printf("DEFAULT: 4") //DEBUG

log.Println("Use default answers in Parallels")
if err := driver.UseDefaults(vmName); err != nil {
Expand Down
64 changes: 35 additions & 29 deletions iso/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type config struct {
ISOChecksumType string `mapstructure:"iso_checksum_type"`
ISOUrls []string `mapstructure:"iso_urls"`
VMName string `mapstructure:"vm_name"`
DeleteVM bool `mapstructure:"delete_vm"`

RawSingleISOUrl string `mapstructure:"iso_url"`

Expand Down Expand Up @@ -115,7 +116,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
if b.config.VMName == "" {
b.config.VMName = fmt.Sprintf("packer-%s", b.config.PackerBuildName)
}
log.Printf("VMName: %s", b.config.VMName) // DEBUG

// Errors
templates := map[string]*string{
Expand Down Expand Up @@ -267,6 +267,13 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
}

steps := []multistep.Step{
&common.StepDownload{
Checksum: b.config.ISOChecksum,
ChecksumType: b.config.ISOChecksumType,
Description: "ISO",
ResultKey: "iso_path",
Url: b.config.ISOUrls,
},
&parallelscommon.StepOutputDir{
Force: b.config.PackerForce,
Path: b.config.OutputDir,
Expand All @@ -281,39 +288,40 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
new(stepAttachISO),
new(stepAttachParallelsTools),
new(parallelscommon.StepAttachFloppy),
&parallelscommon.StepForwardSSH{
GuestPort: b.config.SSHPort,
HostPortMin: b.config.SSHHostPortMin,
HostPortMax: b.config.SSHHostPortMax,
},
// TODO: This has to be done in a different way for Parallels
//&parallelscommon.StepForwardSSH{
// GuestPort: b.config.SSHPort,
// HostPortMin: b.config.SSHHostPortMin,
// HostPortMax: b.config.SSHHostPortMax,
//},
&parallelscommon.StepPrlctl{
Commands: b.config.Prlctl,
Tpl: b.config.tpl,
},
&parallelscommon.StepRun{
BootWait: b.config.BootWait,
Headless: b.config.Headless,
},
new(stepTypeBootCommand),
&common.StepConnectSSH{
SSHAddress: parallelscommon.SSHAddress,
SSHConfig: parallelscommon.SSHConfigFunc(b.config.SSHConfig),
SSHWaitTimeout: b.config.SSHWaitTimeout,
},
&parallelscommon.StepUploadVersion{
Path: b.config.PrlctlVersionFile,
},
new(stepUploadParallelsTools),
new(common.StepProvision),
&parallelscommon.StepShutdown{
Command: b.config.ShutdownCommand,
Timeout: b.config.ShutdownTimeout,
},
new(parallelscommon.StepRemoveDevices),
&parallelscommon.StepExport{
Format: b.config.Format,
OutputDir: b.config.OutputDir,
Headless: b.config.Headless, // TODO: migth work on Enterprise Ed.
},
//new(stepTypeBootCommand),
//&common.StepConnectSSH{
// SSHAddress: parallelscommon.SSHAddress,
// SSHConfig: parallelscommon.SSHConfigFunc(b.config.SSHConfig),
// SSHWaitTimeout: b.config.SSHWaitTimeout,
//},
//&parallelscommon.StepUploadVersion{
// Path: b.config.PrlctlVersionFile,
//},
//new(stepUploadParallelsTools),
//new(common.StepProvision),
//&parallelscommon.StepShutdown{
// Command: b.config.ShutdownCommand,
// Timeout: b.config.ShutdownTimeout,
//},
//new(parallelscommon.StepRemoveDevices),
//&parallelscommon.StepExport{
// Format: b.config.Format,
// OutputDir: b.config.OutputDir,
//},
}

// Setup the state bag
Expand All @@ -324,8 +332,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
state.Put("hook", hook)
state.Put("ui", ui)

log.Printf("State %s", state) //DEBUG

// Run
if b.config.PackerDebug {
b.runner = &multistep.DebugRunner{
Expand Down
19 changes: 7 additions & 12 deletions iso/step_attach_iso.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ func (s *stepAttachISO) Run(state multistep.StateBag) multistep.StepAction {

// Attach the disk to the controller
command := []string{
"storageattach", vmName,
"--storagectl", "IDE Controller",
"--port", "0",
"--device", "1",
"--type", "dvddrive",
"--medium", isoPath,
"set", vmName,
"--device-set", "cdrom0",
"--image", isoPath,
"--enable", "--connect",
}
if err := driver.Prlctl(command...); err != nil {
err := fmt.Errorf("Error attaching ISO: %s", err)
Expand All @@ -38,7 +36,7 @@ func (s *stepAttachISO) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionHalt
}

// Track the path so that we can unregister it from VirtualBox later
// Track the path so that we can unregister it from Parallels later
s.diskPath = isoPath

// Set some state so we know to remove
Expand All @@ -56,11 +54,8 @@ func (s *stepAttachISO) Cleanup(state multistep.StateBag) {
vmName := state.Get("vmName").(string)

command := []string{
"storageattach", vmName,
"--storagectl", "IDE Controller",
"--port", "0",
"--device", "1",
"--medium", "none",
"set", vmName,
"--device-del", "cdrom0",
}

// Remove the ISO. Note that this will probably fail since
Expand Down
Loading

0 comments on commit 3cf9c4c

Please sign in to comment.