post-processor/vagrant: compression_level is an int

This commit is contained in:
Mitchell Hashimoto 2013-12-19 09:16:57 -08:00
parent ac36b33f98
commit eaf76618cb
1 changed files with 16 additions and 12 deletions

View File

@ -13,7 +13,6 @@ import (
"os"
"path/filepath"
"regexp"
"strconv"
)
type VBoxBoxConfig struct {
@ -21,7 +20,7 @@ type VBoxBoxConfig struct {
OutputPath string `mapstructure:"output"`
VagrantfileTemplate string `mapstructure:"vagrantfile_template"`
CompressionLevel string `mapstructure:"compression_level"`
CompressionLevel int `mapstructure:"compression_level"`
tpl *packer.ConfigTemplate
}
@ -46,13 +45,26 @@ func (p *VBoxBoxPostProcessor) Configure(raws ...interface{}) error {
}
p.config.tpl.UserVars = p.config.PackerUserVars
// Defaults
found := false
for _, k := range md.Keys {
println(k)
if k == "compression_level" {
found = true
break
}
}
if !found {
p.config.CompressionLevel = flate.DefaultCompression
}
// Accumulate any errors
errs := common.CheckUnusedConfig(md)
validates := map[string]*string{
"output": &p.config.OutputPath,
"vagrantfile_template": &p.config.VagrantfileTemplate,
"compression_level": &p.config.CompressionLevel,
}
for n, ptr := range validates {
@ -145,14 +157,6 @@ func (p *VBoxBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifac
vf.Write([]byte(vagrantfileContents))
vf.Close()
var level int = flate.DefaultCompression
if p.config.CompressionLevel != "" {
level, err = strconv.Atoi(p.config.CompressionLevel)
if err != nil {
return nil, false, err
}
}
// Create the metadata
metadata := map[string]string{"provider": "virtualbox"}
if err := WriteMetadata(dir, metadata); err != nil {
@ -167,7 +171,7 @@ func (p *VBoxBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifac
// Compress the directory to the given output path
ui.Message(fmt.Sprintf("Compressing box..."))
if err := DirToBox(outputPath, dir, ui, level); err != nil {
if err := DirToBox(outputPath, dir, ui, p.config.CompressionLevel); err != nil {
return nil, false, err
}