Commit 24895069 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/virtualbox: start the VM

parent 70df8c8c
......@@ -130,6 +130,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) packer
new(stepCreateDisk),
new(stepAttachISO),
new(stepForwardSSH),
new(stepRun),
}
// Setup the state bag
......
......@@ -7,7 +7,6 @@ import (
"log"
"math/rand"
"net"
"time"
)
// This step adds a NAT port forwarding definition so that SSH is available
......@@ -52,7 +51,6 @@ func (s *stepForwardSSH) Run(state map[string]interface{}) multistep.StepAction
// Save the port we're using so that future steps can use it
state["sshHostPort"] = sshHostPort
time.Sleep(15 * time.Second)
return multistep.ActionContinue
}
......
package virtualbox
import (
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"time"
)
// This step starts the virtual machine.
//
// Uses:
//
// Produces:
type stepRun struct{
vmName string
}
func (s *stepRun) Run(state map[string]interface{}) multistep.StepAction {
driver := state["driver"].(Driver)
ui := state["ui"].(packer.Ui)
vmName := state["vmName"].(string)
ui.Say("Starting the virtual machine...")
command := []string{"startvm", vmName, "--type", "gui"}
if err := driver.VBoxManage(command...); err != nil {
ui.Error(fmt.Sprintf("Error starting VM: %s", err))
return multistep.ActionHalt
}
s.vmName = vmName
time.Sleep(15 * time.Second)
return multistep.ActionContinue
}
func (s *stepRun) Cleanup(state map[string]interface{}) {
if s.vmName == "" {
return
}
driver := state["driver"].(Driver)
ui := state["ui"].(packer.Ui)
if err := driver.VBoxManage("controlvm", s.vmName, "poweroff"); err != nil {
ui.Error(fmt.Sprintf("Error shutting down VM: %s", err))
}
}
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