Commit eeadafc4 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/vmware/*: can specify path to fusion [GH-677]

parent 525802e9
...@@ -52,6 +52,7 @@ IMPROVEMENTS: ...@@ -52,6 +52,7 @@ IMPROVEMENTS:
* builder/virtualbox: Nice errors if Packer can't write to * builder/virtualbox: Nice errors if Packer can't write to
the output directory. the output directory.
* builder/virtualbox: ISO is ejected prior to export. * builder/virtualbox: ISO is ejected prior to export.
* builder/vmware: Can now specify path to the Fusion application. [GH-677]
* provisioner/puppet-masterless: Can now specify a `manifest_dir` to * provisioner/puppet-masterless: Can now specify a `manifest_dir` to
upload manifests to the remote machine for imports. [GH-655] upload manifests to the remote machine for imports. [GH-655]
......
...@@ -56,7 +56,7 @@ type Driver interface { ...@@ -56,7 +56,7 @@ type Driver interface {
// NewDriver returns a new driver implementation for this operating // NewDriver returns a new driver implementation for this operating
// system, or an error if the driver couldn't be initialized. // system, or an error if the driver couldn't be initialized.
func NewDriver(config *SSHConfig) (Driver, error) { func NewDriver(dconfig *DriverConfig, config *SSHConfig) (Driver, error) {
drivers := []Driver{} drivers := []Driver{}
switch runtime.GOOS { switch runtime.GOOS {
...@@ -64,12 +64,12 @@ func NewDriver(config *SSHConfig) (Driver, error) { ...@@ -64,12 +64,12 @@ func NewDriver(config *SSHConfig) (Driver, error) {
drivers = []Driver{ drivers = []Driver{
&Fusion6Driver{ &Fusion6Driver{
Fusion5Driver: Fusion5Driver{ Fusion5Driver: Fusion5Driver{
AppPath: "/Applications/VMware Fusion.app", AppPath: dconfig.FusionAppPath,
SSHConfig: config, SSHConfig: config,
}, },
}, },
&Fusion5Driver{ &Fusion5Driver{
AppPath: "/Applications/VMware Fusion.app", AppPath: dconfig.FusionAppPath,
SSHConfig: config, SSHConfig: config,
}, },
} }
......
package common
import (
"fmt"
"github.com/mitchellh/packer/packer"
)
type DriverConfig struct {
FusionAppPath string `mapstructure:"fusion_app_path"`
}
func (c *DriverConfig) Prepare(t *packer.ConfigTemplate) []error {
if c.FusionAppPath == "" {
c.FusionAppPath = "/Applications/VMware Fusion.app"
}
templates := map[string]*string{
"fusion_app_path": &c.FusionAppPath,
}
var err error
errs := make([]error, 0)
for n, ptr := range templates {
*ptr, err = t.Process(*ptr, nil)
if err != nil {
errs = append(errs, fmt.Errorf("Error processing %s: %s", n, err))
}
}
return errs
}
package common
import (
"testing"
)
func TestDriverConfigPrepare(t *testing.T) {
var c *DriverConfig
// Test a default boot_wait
c = new(DriverConfig)
errs := c.Prepare(testConfigTemplate(t))
if len(errs) > 0 {
t.Fatalf("bad: %#v", errs)
}
if c.FusionAppPath != "/Applications/VMware Fusion.app" {
t.Fatalf("bad value: %s", c.FusionAppPath)
}
// Test with a good one
c = new(DriverConfig)
c.FusionAppPath = "foo"
errs = c.Prepare(testConfigTemplate(t))
if len(errs) > 0 {
t.Fatalf("bad: %#v", errs)
}
if c.FusionAppPath != "foo" {
t.Fatalf("bad value: %s", c.FusionAppPath)
}
}
...@@ -25,6 +25,7 @@ type Builder struct { ...@@ -25,6 +25,7 @@ type Builder struct {
type config struct { type config struct {
common.PackerConfig `mapstructure:",squash"` common.PackerConfig `mapstructure:",squash"`
vmwcommon.DriverConfig `mapstructure:",squash"`
vmwcommon.OutputConfig `mapstructure:",squash"` vmwcommon.OutputConfig `mapstructure:",squash"`
vmwcommon.RunConfig `mapstructure:",squash"` vmwcommon.RunConfig `mapstructure:",squash"`
vmwcommon.ShutdownConfig `mapstructure:",squash"` vmwcommon.ShutdownConfig `mapstructure:",squash"`
...@@ -77,6 +78,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { ...@@ -77,6 +78,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
// Accumulate any errors // Accumulate any errors
errs := common.CheckUnusedConfig(md) errs := common.CheckUnusedConfig(md)
errs = packer.MultiErrorAppend(errs, b.config.DriverConfig.Prepare(b.config.tpl)...)
errs = packer.MultiErrorAppend(errs, errs = packer.MultiErrorAppend(errs,
b.config.OutputConfig.Prepare(b.config.tpl, &b.config.PackerConfig)...) b.config.OutputConfig.Prepare(b.config.tpl, &b.config.PackerConfig)...)
errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(b.config.tpl)...) errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(b.config.tpl)...)
......
...@@ -12,7 +12,7 @@ func NewDriver(config *config) (vmwcommon.Driver, error) { ...@@ -12,7 +12,7 @@ func NewDriver(config *config) (vmwcommon.Driver, error) {
drivers := []vmwcommon.Driver{} drivers := []vmwcommon.Driver{}
if config.RemoteType == "" { if config.RemoteType == "" {
return vmwcommon.NewDriver(&config.SSHConfig) return vmwcommon.NewDriver(&config.DriverConfig, &config.SSHConfig)
} }
drivers = []vmwcommon.Driver{ drivers = []vmwcommon.Driver{
......
...@@ -33,7 +33,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { ...@@ -33,7 +33,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
// Run executes a Packer build and returns a packer.Artifact representing // Run executes a Packer build and returns a packer.Artifact representing
// a VirtualBox appliance. // a VirtualBox appliance.
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) { func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
driver, err := vmwcommon.NewDriver(&b.config.SSHConfig) driver, err := vmwcommon.NewDriver(&b.config.DriverConfig, &b.config.SSHConfig)
if err != nil { if err != nil {
return nil, fmt.Errorf("Failed creating VMware driver: %s", err) return nil, fmt.Errorf("Failed creating VMware driver: %s", err)
} }
......
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
// Config is the configuration structure for the builder. // Config is the configuration structure for the builder.
type Config struct { type Config struct {
common.PackerConfig `mapstructure:",squash"` common.PackerConfig `mapstructure:",squash"`
vmwcommon.DriverConfig `mapstructure:",squash"`
vmwcommon.OutputConfig `mapstructure:",squash"` vmwcommon.OutputConfig `mapstructure:",squash"`
vmwcommon.RunConfig `mapstructure:",squash"` vmwcommon.RunConfig `mapstructure:",squash"`
vmwcommon.ShutdownConfig `mapstructure:",squash"` vmwcommon.ShutdownConfig `mapstructure:",squash"`
...@@ -45,6 +46,7 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { ...@@ -45,6 +46,7 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
// Prepare the errors // Prepare the errors
errs := common.CheckUnusedConfig(md) errs := common.CheckUnusedConfig(md)
errs = packer.MultiErrorAppend(errs, c.DriverConfig.Prepare(c.tpl)...)
errs = packer.MultiErrorAppend(errs, c.OutputConfig.Prepare(c.tpl, &c.PackerConfig)...) errs = packer.MultiErrorAppend(errs, c.OutputConfig.Prepare(c.tpl, &c.PackerConfig)...)
errs = packer.MultiErrorAppend(errs, c.RunConfig.Prepare(c.tpl)...) errs = packer.MultiErrorAppend(errs, c.RunConfig.Prepare(c.tpl)...)
errs = packer.MultiErrorAppend(errs, c.ShutdownConfig.Prepare(c.tpl)...) errs = packer.MultiErrorAppend(errs, c.ShutdownConfig.Prepare(c.tpl)...)
......
...@@ -99,6 +99,10 @@ Optional: ...@@ -99,6 +99,10 @@ Optional:
be attached. The files listed in this configuration will all be put be attached. The files listed in this configuration will all be put
into the root directory of the floppy disk; sub-directories are not supported. into the root directory of the floppy disk; sub-directories are not supported.
* `fusion_app_path` (string) - Path to "VMware Fusion.app". By default this
is "/Applications/VMware Fusion.app" but this setting allows you to
customize this.
* `guest_os_type` (string) - The guest OS type being installed. This will be * `guest_os_type` (string) - The guest OS type being installed. This will be
set in the VMware VMX. By default this is "other". By specifying a more specific set in the VMware VMX. By default this is "other". By specifying a more specific
OS type, VMware may perform some optimizations or virtual hardware changes OS type, VMware may perform some optimizations or virtual hardware changes
......
...@@ -64,6 +64,10 @@ Optional: ...@@ -64,6 +64,10 @@ Optional:
be attached. The files listed in this configuration will all be put be attached. The files listed in this configuration will all be put
into the root directory of the floppy disk; sub-directories are not supported. into the root directory of the floppy disk; sub-directories are not supported.
* `fusion_app_path` (string) - Path to "VMware Fusion.app". By default this
is "/Applications/VMware Fusion.app" but this setting allows you to
customize this.
* `headless` (bool) - Packer defaults to building VMware * `headless` (bool) - Packer defaults to building VMware
virtual machines by launching a GUI that shows the console of the virtual machines by launching a GUI that shows the console of the
machine being built. When this value is set to true, the machine will machine being built. When this value is set to true, the machine will
......
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