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

This commit is contained in:
Mitchell Hashimoto 2013-12-27 08:37:39 -07:00
parent 525802e9e6
commit eeadafc452
10 changed files with 80 additions and 5 deletions

View File

@ -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]

View File

@ -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,
},
}

View File

@ -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
}

View File

@ -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)
}
}

View File

@ -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)...)

View File

@ -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{

View File

@ -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)
}

View File

@ -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)...)

View File

@ -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

View File

@ -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