diff --git a/CHANGELOG.md b/CHANGELOG.md index 56730953a..1419d99d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,7 @@ IMPROVEMENTS: * builder/virtualbox: Nice errors if Packer can't write to the output directory. * 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 upload manifests to the remote machine for imports. [GH-655] diff --git a/builder/vmware/common/driver.go b/builder/vmware/common/driver.go index aee7997e1..79721599c 100644 --- a/builder/vmware/common/driver.go +++ b/builder/vmware/common/driver.go @@ -56,7 +56,7 @@ type Driver interface { // NewDriver returns a new driver implementation for this operating // 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{} switch runtime.GOOS { @@ -64,12 +64,12 @@ func NewDriver(config *SSHConfig) (Driver, error) { drivers = []Driver{ &Fusion6Driver{ Fusion5Driver: Fusion5Driver{ - AppPath: "/Applications/VMware Fusion.app", + AppPath: dconfig.FusionAppPath, SSHConfig: config, }, }, &Fusion5Driver{ - AppPath: "/Applications/VMware Fusion.app", + AppPath: dconfig.FusionAppPath, SSHConfig: config, }, } diff --git a/builder/vmware/common/driver_config.go b/builder/vmware/common/driver_config.go new file mode 100644 index 000000000..d1288cf4c --- /dev/null +++ b/builder/vmware/common/driver_config.go @@ -0,0 +1,32 @@ +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 +} diff --git a/builder/vmware/common/driver_config_test.go b/builder/vmware/common/driver_config_test.go new file mode 100644 index 000000000..419023ec5 --- /dev/null +++ b/builder/vmware/common/driver_config_test.go @@ -0,0 +1,30 @@ +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) + } +} diff --git a/builder/vmware/iso/builder.go b/builder/vmware/iso/builder.go index 0a3f33b75..f5dbb9f03 100644 --- a/builder/vmware/iso/builder.go +++ b/builder/vmware/iso/builder.go @@ -25,6 +25,7 @@ type Builder struct { type config struct { common.PackerConfig `mapstructure:",squash"` + vmwcommon.DriverConfig `mapstructure:",squash"` vmwcommon.OutputConfig `mapstructure:",squash"` vmwcommon.RunConfig `mapstructure:",squash"` vmwcommon.ShutdownConfig `mapstructure:",squash"` @@ -77,6 +78,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { // Accumulate any errors errs := common.CheckUnusedConfig(md) + errs = packer.MultiErrorAppend(errs, b.config.DriverConfig.Prepare(b.config.tpl)...) errs = packer.MultiErrorAppend(errs, b.config.OutputConfig.Prepare(b.config.tpl, &b.config.PackerConfig)...) errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(b.config.tpl)...) diff --git a/builder/vmware/iso/driver.go b/builder/vmware/iso/driver.go index 22c6b6902..ebe8d126b 100644 --- a/builder/vmware/iso/driver.go +++ b/builder/vmware/iso/driver.go @@ -12,7 +12,7 @@ func NewDriver(config *config) (vmwcommon.Driver, error) { drivers := []vmwcommon.Driver{} if config.RemoteType == "" { - return vmwcommon.NewDriver(&config.SSHConfig) + return vmwcommon.NewDriver(&config.DriverConfig, &config.SSHConfig) } drivers = []vmwcommon.Driver{ diff --git a/builder/vmware/vmx/builder.go b/builder/vmware/vmx/builder.go index e799efd0b..dd47598b0 100644 --- a/builder/vmware/vmx/builder.go +++ b/builder/vmware/vmx/builder.go @@ -33,7 +33,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { // Run executes a Packer build and returns a packer.Artifact representing // a VirtualBox appliance. 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 { return nil, fmt.Errorf("Failed creating VMware driver: %s", err) } diff --git a/builder/vmware/vmx/config.go b/builder/vmware/vmx/config.go index 5f68d1f42..70f125c0a 100644 --- a/builder/vmware/vmx/config.go +++ b/builder/vmware/vmx/config.go @@ -12,6 +12,7 @@ import ( // Config is the configuration structure for the builder. type Config struct { common.PackerConfig `mapstructure:",squash"` + vmwcommon.DriverConfig `mapstructure:",squash"` vmwcommon.OutputConfig `mapstructure:",squash"` vmwcommon.RunConfig `mapstructure:",squash"` vmwcommon.ShutdownConfig `mapstructure:",squash"` @@ -45,6 +46,7 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { // Prepare the errors 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.RunConfig.Prepare(c.tpl)...) errs = packer.MultiErrorAppend(errs, c.ShutdownConfig.Prepare(c.tpl)...) diff --git a/website/source/docs/builders/vmware-iso.html.markdown b/website/source/docs/builders/vmware-iso.html.markdown index 0b03d6d55..0b884deea 100644 --- a/website/source/docs/builders/vmware-iso.html.markdown +++ b/website/source/docs/builders/vmware-iso.html.markdown @@ -99,6 +99,10 @@ Optional: 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. +* `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 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 diff --git a/website/source/docs/builders/vmware-vmx.html.markdown b/website/source/docs/builders/vmware-vmx.html.markdown index e62375514..1fbbb3103 100644 --- a/website/source/docs/builders/vmware-vmx.html.markdown +++ b/website/source/docs/builders/vmware-vmx.html.markdown @@ -64,6 +64,10 @@ Optional: 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. +* `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 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