Only validate vmware resources on local hosts

Disable resource validation when `remote_type` is specified
This commit is contained in:
Jake Champlin 2016-01-25 12:01:56 -05:00
parent eda84cb2d3
commit f01578c91e
3 changed files with 17 additions and 12 deletions

View File

@ -13,16 +13,19 @@ type VMXConfig struct {
VMXDataPost map[string]string `mapstructure:"vmx_data_post"` VMXDataPost map[string]string `mapstructure:"vmx_data_post"`
} }
func (c *VMXConfig) Prepare(ctx *interpolate.Context) []error { func (c *VMXConfig) Prepare(ctx *interpolate.Context, remoteType string) []error {
var errs []error var errs []error
var err error var err error
var desiredMem uint64 var desiredMem uint64
for k, v := range c.VMXData { // Validate memory resources, only on local hosts
if k == "memsize" { if remoteType == "" {
desiredMem, err = strconv.ParseUint(v, 10, 64) for k, v := range c.VMXData {
if err != nil { if k == "memsize" {
errs = append(errs, fmt.Errorf("Error parsing string: %s", err)) desiredMem, err = strconv.ParseUint(v, 10, 64)
if err != nil {
errs = append(errs, fmt.Errorf("Error parsing string: %s", err))
}
} }
} }
} }

View File

@ -93,7 +93,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
errs = packer.MultiErrorAppend(errs, b.config.ShutdownConfig.Prepare(&b.config.ctx)...) errs = packer.MultiErrorAppend(errs, b.config.ShutdownConfig.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.SSHConfig.Prepare(&b.config.ctx)...) errs = packer.MultiErrorAppend(errs, b.config.SSHConfig.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.ToolsConfig.Prepare(&b.config.ctx)...) errs = packer.MultiErrorAppend(errs, b.config.ToolsConfig.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.VMXConfig.Prepare(&b.config.ctx)...) errs = packer.MultiErrorAppend(errs, b.config.VMXConfig.Prepare(&b.config.ctx, b.config.RemoteType)...)
if b.config.DiskName == "" { if b.config.DiskName == "" {
b.config.DiskName = "disk" b.config.DiskName = "disk"
@ -171,10 +171,12 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
} }
} }
// Determine if DiskSize is able to be allocated // Determine if DiskSize is able to be allocated, only when running locally
if err = common.AvailableDisk(uint64(b.config.DiskSize)); err != nil { if b.config.RemoteType == "" {
errs = packer.MultiErrorAppend(errs, if err = common.AvailableDisk(uint64(b.config.DiskSize)); err != nil {
fmt.Errorf("Unavailable Resources: %s", err)) errs = packer.MultiErrorAppend(errs,
fmt.Errorf("Unavailable Resources: %s", err))
}
} }
// Warnings // Warnings

View File

@ -63,7 +63,7 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
errs = packer.MultiErrorAppend(errs, c.ShutdownConfig.Prepare(&c.ctx)...) errs = packer.MultiErrorAppend(errs, c.ShutdownConfig.Prepare(&c.ctx)...)
errs = packer.MultiErrorAppend(errs, c.SSHConfig.Prepare(&c.ctx)...) errs = packer.MultiErrorAppend(errs, c.SSHConfig.Prepare(&c.ctx)...)
errs = packer.MultiErrorAppend(errs, c.ToolsConfig.Prepare(&c.ctx)...) errs = packer.MultiErrorAppend(errs, c.ToolsConfig.Prepare(&c.ctx)...)
errs = packer.MultiErrorAppend(errs, c.VMXConfig.Prepare(&c.ctx)...) errs = packer.MultiErrorAppend(errs, c.VMXConfig.Prepare(&c.ctx, c.RemoteType)...)
if c.SourcePath == "" { if c.SourcePath == "" {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("source_path is blank, but is required")) errs = packer.MultiErrorAppend(errs, fmt.Errorf("source_path is blank, but is required"))