Merge pull request #1173 from rickard-von-essen/pvm_bootcommand
[feature] Support boot command for pvm builder
This commit is contained in:
commit
a5d39cebc7
|
@ -1,4 +1,4 @@
|
||||||
package iso
|
package common
|
||||||
|
|
||||||
// Interface to help find the host IP that is available from within
|
// Interface to help find the host IP that is available from within
|
||||||
// the Parallels virtual machines.
|
// the Parallels virtual machines.
|
|
@ -1,4 +1,4 @@
|
||||||
package iso
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
|
@ -1,4 +1,4 @@
|
||||||
package iso
|
package common
|
||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
package iso
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
parallelscommon "github.com/mitchellh/packer/builder/parallels/common"
|
|
||||||
"github.com/mitchellh/packer/packer"
|
"github.com/mitchellh/packer/packer"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -24,7 +23,6 @@ type bootCommandTemplateData struct {
|
||||||
// Parallels Virtualization SDK - C API.
|
// Parallels Virtualization SDK - C API.
|
||||||
//
|
//
|
||||||
// Uses:
|
// Uses:
|
||||||
// config *config
|
|
||||||
// driver Driver
|
// driver Driver
|
||||||
// http_port int
|
// http_port int
|
||||||
// ui packer.Ui
|
// ui packer.Ui
|
||||||
|
@ -32,24 +30,32 @@ type bootCommandTemplateData struct {
|
||||||
//
|
//
|
||||||
// Produces:
|
// Produces:
|
||||||
// <nothing>
|
// <nothing>
|
||||||
type stepTypeBootCommand struct{}
|
type StepTypeBootCommand struct {
|
||||||
|
BootCommand []string
|
||||||
|
HostInterfaces []string
|
||||||
|
VMName string
|
||||||
|
Tpl *packer.ConfigTemplate
|
||||||
|
}
|
||||||
|
|
||||||
func (s *stepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction {
|
func (s *StepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
config := state.Get("config").(*config)
|
|
||||||
httpPort := state.Get("http_port").(uint)
|
httpPort := state.Get("http_port").(uint)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
vmName := state.Get("vmName").(string)
|
driver := state.Get("driver").(Driver)
|
||||||
driver := state.Get("driver").(parallelscommon.Driver)
|
|
||||||
|
|
||||||
// Determine the host IP
|
hostIp := "0.0.0.0"
|
||||||
ipFinder := &IfconfigIPFinder{Devices: config.HostInterfaces}
|
|
||||||
|
|
||||||
hostIp, err := ipFinder.HostIP()
|
if len(s.HostInterfaces) > 0 {
|
||||||
if err != nil {
|
// Determine the host IP
|
||||||
err := fmt.Errorf("Error detecting host IP: %s", err)
|
ipFinder := &IfconfigIPFinder{Devices: s.HostInterfaces}
|
||||||
state.Put("error", err)
|
|
||||||
ui.Error(err.Error())
|
ip, err := ipFinder.HostIP()
|
||||||
return multistep.ActionHalt
|
if err != nil {
|
||||||
|
err := fmt.Errorf("Error detecting host IP: %s", err)
|
||||||
|
state.Put("error", err)
|
||||||
|
ui.Error(err.Error())
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
|
hostIp = ip
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.Say(fmt.Sprintf("Host IP for the Parallels machine: %s", hostIp))
|
ui.Say(fmt.Sprintf("Host IP for the Parallels machine: %s", hostIp))
|
||||||
|
@ -57,12 +63,12 @@ func (s *stepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction
|
||||||
tplData := &bootCommandTemplateData{
|
tplData := &bootCommandTemplateData{
|
||||||
hostIp,
|
hostIp,
|
||||||
httpPort,
|
httpPort,
|
||||||
config.VMName,
|
s.VMName,
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.Say("Typing the boot command...")
|
ui.Say("Typing the boot command...")
|
||||||
for _, command := range config.BootCommand {
|
for _, command := range s.BootCommand {
|
||||||
command, err := config.tpl.Process(command, tplData)
|
command, err := s.Tpl.Process(command, tplData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error preparing boot command: %s", err)
|
err := fmt.Errorf("Error preparing boot command: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
|
@ -73,7 +79,7 @@ func (s *stepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction
|
||||||
codes := []string{}
|
codes := []string{}
|
||||||
for _, code := range scancodes(command) {
|
for _, code := range scancodes(command) {
|
||||||
if code == "wait" {
|
if code == "wait" {
|
||||||
if err := driver.SendKeyScanCodes(vmName, codes...); err != nil {
|
if err := driver.SendKeyScanCodes(s.VMName, codes...); err != nil {
|
||||||
err := fmt.Errorf("Error sending boot command: %s", err)
|
err := fmt.Errorf("Error sending boot command: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
|
@ -85,7 +91,7 @@ func (s *stepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction
|
||||||
}
|
}
|
||||||
|
|
||||||
if code == "wait5" {
|
if code == "wait5" {
|
||||||
if err := driver.SendKeyScanCodes(vmName, codes...); err != nil {
|
if err := driver.SendKeyScanCodes(s.VMName, codes...); err != nil {
|
||||||
err := fmt.Errorf("Error sending boot command: %s", err)
|
err := fmt.Errorf("Error sending boot command: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
|
@ -97,7 +103,7 @@ func (s *stepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction
|
||||||
}
|
}
|
||||||
|
|
||||||
if code == "wait10" {
|
if code == "wait10" {
|
||||||
if err := driver.SendKeyScanCodes(vmName, codes...); err != nil {
|
if err := driver.SendKeyScanCodes(s.VMName, codes...); err != nil {
|
||||||
err := fmt.Errorf("Error sending boot command: %s", err)
|
err := fmt.Errorf("Error sending boot command: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
|
@ -116,7 +122,7 @@ func (s *stepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction
|
||||||
codes = append(codes, code)
|
codes = append(codes, code)
|
||||||
}
|
}
|
||||||
log.Printf("Sending scancodes: %#v", codes)
|
log.Printf("Sending scancodes: %#v", codes)
|
||||||
if err := driver.SendKeyScanCodes(vmName, codes...); err != nil {
|
if err := driver.SendKeyScanCodes(s.VMName, codes...); err != nil {
|
||||||
err := fmt.Errorf("Error sending boot command: %s", err)
|
err := fmt.Errorf("Error sending boot command: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
|
@ -127,7 +133,7 @@ func (s *stepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*stepTypeBootCommand) Cleanup(multistep.StateBag) {}
|
func (*StepTypeBootCommand) Cleanup(multistep.StateBag) {}
|
||||||
|
|
||||||
func scancodes(message string) []string {
|
func scancodes(message string) []string {
|
||||||
// Scancodes reference: http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html
|
// Scancodes reference: http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html
|
|
@ -298,7 +298,12 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
BootWait: b.config.BootWait,
|
BootWait: b.config.BootWait,
|
||||||
Headless: b.config.Headless, // TODO: migth work on Enterprise Ed.
|
Headless: b.config.Headless, // TODO: migth work on Enterprise Ed.
|
||||||
},
|
},
|
||||||
new(stepTypeBootCommand),
|
¶llelscommon.StepTypeBootCommand{
|
||||||
|
BootCommand: b.config.BootCommand,
|
||||||
|
HostInterfaces: b.config.HostInterfaces,
|
||||||
|
VMName: b.config.VMName,
|
||||||
|
Tpl: b.config.tpl,
|
||||||
|
},
|
||||||
&common.StepConnectSSH{
|
&common.StepConnectSSH{
|
||||||
SSHAddress: parallelscommon.SSHAddress,
|
SSHAddress: parallelscommon.SSHAddress,
|
||||||
SSHConfig: parallelscommon.SSHConfigFunc(b.config.SSHConfig),
|
SSHConfig: parallelscommon.SSHConfigFunc(b.config.SSHConfig),
|
||||||
|
|
|
@ -43,6 +43,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
state.Put("driver", driver)
|
state.Put("driver", driver)
|
||||||
state.Put("hook", hook)
|
state.Put("hook", hook)
|
||||||
state.Put("ui", ui)
|
state.Put("ui", ui)
|
||||||
|
state.Put("http_port", uint(0))
|
||||||
|
|
||||||
// Build the steps.
|
// Build the steps.
|
||||||
steps := []multistep.Step{
|
steps := []multistep.Step{
|
||||||
|
@ -70,6 +71,12 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
BootWait: b.config.BootWait,
|
BootWait: b.config.BootWait,
|
||||||
Headless: b.config.Headless,
|
Headless: b.config.Headless,
|
||||||
},
|
},
|
||||||
|
¶llelscommon.StepTypeBootCommand{
|
||||||
|
BootCommand: b.config.BootCommand,
|
||||||
|
HostInterfaces: []string{},
|
||||||
|
VMName: b.config.VMName,
|
||||||
|
Tpl: b.config.tpl,
|
||||||
|
},
|
||||||
&common.StepConnectSSH{
|
&common.StepConnectSSH{
|
||||||
SSHAddress: parallelscommon.SSHAddress,
|
SSHAddress: parallelscommon.SSHAddress,
|
||||||
SSHConfig: parallelscommon.SSHConfigFunc(b.config.SSHConfig),
|
SSHConfig: parallelscommon.SSHConfigFunc(b.config.SSHConfig),
|
||||||
|
|
|
@ -19,12 +19,12 @@ type Config struct {
|
||||||
parallelscommon.PrlctlConfig `mapstructure:",squash"`
|
parallelscommon.PrlctlConfig `mapstructure:",squash"`
|
||||||
parallelscommon.PrlctlVersionConfig `mapstructure:",squash"`
|
parallelscommon.PrlctlVersionConfig `mapstructure:",squash"`
|
||||||
|
|
||||||
ParallelsToolsMode string `mapstructure:"parallels_tools_mode"`
|
BootCommand []string `mapstructure:"boot_command"`
|
||||||
ParallelsToolsGuestPath string `mapstructure:"parallels_tools_guest_path"`
|
ParallelsToolsMode string `mapstructure:"parallels_tools_mode"`
|
||||||
ParallelsToolsHostPath string `mapstructure:"parallels_tools_host_path"`
|
ParallelsToolsGuestPath string `mapstructure:"parallels_tools_guest_path"`
|
||||||
|
ParallelsToolsHostPath string `mapstructure:"parallels_tools_host_path"`
|
||||||
SourcePath string `mapstructure:"source_path"`
|
SourcePath string `mapstructure:"source_path"`
|
||||||
VMName string `mapstructure:"vm_name"`
|
VMName string `mapstructure:"vm_name"`
|
||||||
|
|
||||||
tpl *packer.ConfigTemplate
|
tpl *packer.ConfigTemplate
|
||||||
}
|
}
|
||||||
|
@ -86,6 +86,13 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for i, command := range c.BootCommand {
|
||||||
|
if err := c.tpl.Validate(command); err != nil {
|
||||||
|
errs = packer.MultiErrorAppend(errs,
|
||||||
|
fmt.Errorf("Error processing boot_command[%d]: %s", i, err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
validMode := false
|
validMode := false
|
||||||
validModes := []string{
|
validModes := []string{
|
||||||
parallelscommon.ParallelsToolsModeDisable,
|
parallelscommon.ParallelsToolsModeDisable,
|
||||||
|
|
|
@ -53,6 +53,19 @@ each category, the available options are alphabetized and described.
|
||||||
|
|
||||||
### Optional:
|
### Optional:
|
||||||
|
|
||||||
|
* `boot_command` (array of strings) - This is an array of commands to type
|
||||||
|
when the virtual machine is first booted. The goal of these commands should
|
||||||
|
be to type just enough to initialize the operating system installer. Special
|
||||||
|
keys can be typed as well, and are covered in the section below on the boot
|
||||||
|
command. If this is not specified, it is assumed the installer will start
|
||||||
|
itself.
|
||||||
|
|
||||||
|
* `boot_wait` (string) - The time to wait after booting the initial virtual
|
||||||
|
machine before typing the `boot_command`. The value of this should be
|
||||||
|
a duration. Examples are "5s" and "1m30s" which will cause Packer to wait
|
||||||
|
five seconds and one minute 30 seconds, respectively. If this isn't specified,
|
||||||
|
the default is 10 seconds.
|
||||||
|
|
||||||
* `floppy_files` (array of strings) - A list of files to put onto a floppy
|
* `floppy_files` (array of strings) - A list of files to put onto a floppy
|
||||||
disk that is attached when the VM is booted for the first time. This is
|
disk that is attached when the VM is booted for the first time. This is
|
||||||
most useful for unattended Windows installs, which look for an
|
most useful for unattended Windows installs, which look for an
|
||||||
|
@ -135,6 +148,34 @@ uploaded is controllable by `parallels_tools_path`, and defaults to
|
||||||
of the SSH user. Parallels Tools ISO's can be found in:
|
of the SSH user. Parallels Tools ISO's can be found in:
|
||||||
"/Applications/Parallels Desktop.app/Contents/Resources/Tools/"
|
"/Applications/Parallels Desktop.app/Contents/Resources/Tools/"
|
||||||
|
|
||||||
|
## Boot Command
|
||||||
|
|
||||||
|
The `boot_command` specifies the keys to type when the virtual machine is first booted. This command is typed after `boot_wait`.
|
||||||
|
|
||||||
|
As documented above, the `boot_command` is an array of strings. The
|
||||||
|
strings are all typed in sequence. It is an array only to improve readability
|
||||||
|
within the template.
|
||||||
|
|
||||||
|
The boot command is "typed" character for character using the `prltype` (part
|
||||||
|
of prl-utils, see [Parallels Builder](/docs/builders/parallels.html))
|
||||||
|
command connected to the machine, simulating a human actually typing the
|
||||||
|
keyboard. There are a set of special keys available. If these are in your
|
||||||
|
boot command, they will be replaced by the proper key:
|
||||||
|
|
||||||
|
* `<enter>` and `<return>` - Simulates an actual "enter" or "return" keypress.
|
||||||
|
|
||||||
|
* `<esc>` - Simulates pressing the escape key.
|
||||||
|
|
||||||
|
* `<tab>` - Simulates pressing the tab key.
|
||||||
|
|
||||||
|
* `<wait>` `<wait5>` `<wait10>` - Adds a 1, 5 or 10 second pause before sending
|
||||||
|
any additional keys. This is useful if you have to generally wait for the UI
|
||||||
|
to update before typing more.
|
||||||
|
|
||||||
|
In addition to the special keys, each command to type is treated as a
|
||||||
|
[configuration template](/docs/templates/configuration-templates.html).
|
||||||
|
The available variables are:
|
||||||
|
|
||||||
## prlctl Commands
|
## prlctl Commands
|
||||||
In order to perform extra customization of the virtual machine, a template can
|
In order to perform extra customization of the virtual machine, a template can
|
||||||
define extra calls to `prlctl` to perform.
|
define extra calls to `prlctl` to perform.
|
||||||
|
|
Loading…
Reference in New Issue