Merge pull request #3145 from mitchellh/b-resource-check

Reverting resouce constraint checking
This commit is contained in:
Chris Bednarski 2016-02-02 12:54:56 -08:00
commit 6fd6156fd9
10 changed files with 6 additions and 116 deletions

View File

@ -33,7 +33,6 @@ IMPROVEMENTS:
for broader compatibility. [GH-2913] for broader compatibility. [GH-2913]
* core: `target_path` for builder downloads can now be specified. [GH-2600] * core: `target_path` for builder downloads can now be specified. [GH-2600]
* core: WinRM communicator now supports HTTPS protocol [GH-3061] * core: WinRM communicator now supports HTTPS protocol [GH-3061]
* core: Local linux builds will attempt to verify that sufficient resources are available prior to starting the build [GH-3096]
* builder/amazon: Add support for `ebs_optimized` [GH-2806] * builder/amazon: Add support for `ebs_optimized` [GH-2806]
* builder/amazon: You can now specify `0` for `spot_price` to switch to on * builder/amazon: You can now specify `0` for `spot_price` to switch to on
demand instances [GH-2845] demand instances [GH-2845]

View File

@ -66,7 +66,6 @@ updatedeps:
fi fi
go get -u github.com/mitchellh/gox go get -u github.com/mitchellh/gox
go get -u golang.org/x/tools/cmd/stringer go get -u golang.org/x/tools/cmd/stringer
go get -u github.com/cloudfoundry/gosigar
go list ./... \ go list ./... \
| xargs go list -f '{{join .Deps "\n"}}' \ | xargs go list -f '{{join .Deps "\n"}}' \
| grep -v github.com/mitchellh/packer \ | grep -v github.com/mitchellh/packer \

View File

@ -1,10 +1,6 @@
package common package common
import ( import (
"fmt"
"strconv"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/template/interpolate" "github.com/mitchellh/packer/template/interpolate"
) )
@ -15,25 +11,7 @@ type VBoxManageConfig struct {
func (c *VBoxManageConfig) Prepare(ctx *interpolate.Context) []error { func (c *VBoxManageConfig) Prepare(ctx *interpolate.Context) []error {
if c.VBoxManage == nil { if c.VBoxManage == nil {
c.VBoxManage = make([][]string, 0) c.VBoxManage = make([][]string, 0)
return nil
} }
var errs []error return nil
var err error
var desiredMem uint64
for _, cmd := range c.VBoxManage {
if cmd[2] == "--memory" {
desiredMem, err = strconv.ParseUint(cmd[3], 10, 64)
if err != nil {
errs = append(errs, fmt.Errorf("Error parsing string: %s", err))
}
}
}
if err = common.AvailableMem(desiredMem); err != nil {
errs = append(errs, fmt.Errorf("Unavailable Resources: %s", err))
}
return errs
} }

View File

@ -152,12 +152,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b.config.GuestAdditionsSHA256 = strings.ToLower(b.config.GuestAdditionsSHA256) b.config.GuestAdditionsSHA256 = strings.ToLower(b.config.GuestAdditionsSHA256)
} }
// Determine if DiskSize is able to be allocated
if err = common.AvailableDisk(uint64(b.config.DiskSize)); err != nil {
errs = packer.MultiErrorAppend(errs,
fmt.Errorf("Unavailable Resources: %s", err))
}
// Warnings // Warnings
if b.config.ShutdownCommand == "" { if b.config.ShutdownCommand == "" {
warnings = append(warnings, warnings = append(warnings,

View File

@ -1,10 +1,6 @@
package common package common
import ( import (
"fmt"
"strconv"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/template/interpolate" "github.com/mitchellh/packer/template/interpolate"
) )
@ -13,26 +9,6 @@ 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, remoteType string) []error { func (c *VMXConfig) Prepare(ctx *interpolate.Context) []error {
var errs []error return nil
var err error
var desiredMem uint64
// Validate memory resources, only on local hosts
if remoteType == "" {
for k, v := range c.VMXData {
if k == "memsize" {
desiredMem, err = strconv.ParseUint(v, 10, 64)
if err != nil {
errs = append(errs, fmt.Errorf("Error parsing string: %s", err))
}
}
}
}
if err = common.AvailableMem(desiredMem); err != nil {
errs = append(errs, fmt.Errorf("Unavailable Resources: %s", err))
}
return errs
} }

View File

@ -11,7 +11,7 @@ func TestVMXConfigPrepare(t *testing.T) {
"two": "bar", "two": "bar",
} }
errs := c.Prepare(testConfigTemplate(t), "") errs := c.Prepare(testConfigTemplate(t))
if len(errs) > 0 { if len(errs) > 0 {
t.Fatalf("bad: %#v", errs) t.Fatalf("bad: %#v", errs)
} }

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, b.config.RemoteType)...) errs = packer.MultiErrorAppend(errs, b.config.VMXConfig.Prepare(&b.config.ctx)...)
if b.config.DiskName == "" { if b.config.DiskName == "" {
b.config.DiskName = "disk" b.config.DiskName = "disk"
@ -171,14 +171,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
} }
} }
// Determine if DiskSize is able to be allocated, only when running locally
if b.config.RemoteType == "" {
if err = common.AvailableDisk(uint64(b.config.DiskSize)); err != nil {
errs = packer.MultiErrorAppend(errs,
fmt.Errorf("Unavailable Resources: %s", err))
}
}
// Warnings // Warnings
if b.config.ShutdownCommand == "" { if b.config.ShutdownCommand == "" {
warnings = append(warnings, warnings = append(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, c.RemoteType)...) errs = packer.MultiErrorAppend(errs, c.VMXConfig.Prepare(&c.ctx)...)
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"))

View File

@ -1,37 +0,0 @@
package common
import (
"fmt"
"os"
sigar "github.com/cloudfoundry/gosigar"
)
func AvailableMem(desired uint64) error {
free := freeMem()
if desired > free {
return fmt.Errorf("RAM - Requested - %dMB - Available %dMB", desired, free)
}
return nil
}
func freeMem() uint64 {
mem := sigar.Mem{}
mem.Get()
return (mem.Free / 1024 / 1024)
}
func AvailableDisk(desired uint64) error {
free := freeDisk()
if desired > free {
return fmt.Errorf("Disk - Requested - %dMB - Available %dMB", desired, free)
}
return nil
}
func freeDisk() uint64 {
disk := sigar.FileSystemUsage{}
workingDirectory, _ := os.Getwd()
disk.Get(workingDirectory)
return (disk.Avail / 1024)
}

View File

@ -1,11 +0,0 @@
// +build !linux
package common
func AvailableMem(desired uint64) error {
return nil
}
func AvailableDisk(desired uint64) error {
return nil
}