Separate config defaults from validation

This commit is contained in:
Cheng Sun 2014-12-10 11:22:31 +00:00
parent a9fb6532ae
commit 649798b4ac

View File

@ -119,10 +119,31 @@ func (self *Builder) Prepare(raws ...interface{}) (params []string, retErr error
self.config.RawSSHWaitTimeout = "200m" self.config.RawSSHWaitTimeout = "200m"
} }
if self.config.InstanceMemory == "" {
self.config.InstanceMemory = "1024000000"
}
if self.config.CloneTemplate == "" {
self.config.CloneTemplate = "Other install media"
}
if self.config.OutputDir == "" { if self.config.OutputDir == "" {
self.config.OutputDir = fmt.Sprintf("output-%s", self.config.PackerBuildName) self.config.OutputDir = fmt.Sprintf("output-%s", self.config.PackerBuildName)
} }
if len(self.config.PlatformArgs) == 0 {
pargs := make(map[string]string)
pargs["viridian"] = "false"
pargs["nx"] = "true"
pargs["pae"] = "true"
pargs["apic"] = "true"
pargs["timeoffset"] = "0"
pargs["acpi"] = "1"
self.config.PlatformArgs = pargs
}
// Template substitution
templates := map[string]*string{ templates := map[string]*string{
"username": &self.config.Username, "username": &self.config.Username,
"password": &self.config.Password, "password": &self.config.Password,
@ -156,6 +177,8 @@ func (self *Builder) Prepare(raws ...interface{}) (params []string, retErr error
} }
} }
// Validation
/* /*
if self.config.IsoUrl == "" { if self.config.IsoUrl == "" {
errs = packer.MultiErrorAppend( errs = packer.MultiErrorAppend(
@ -166,7 +189,7 @@ func (self *Builder) Prepare(raws ...interface{}) (params []string, retErr error
self.config.BootWait, err = time.ParseDuration(self.config.RawBootWait) self.config.BootWait, err = time.ParseDuration(self.config.RawBootWait)
if err != nil { if err != nil {
errs = packer.MultiErrorAppend( errs = packer.MultiErrorAppend(
errs, errors.New("Failed to parse boot_wait.")) errs, fmt.Errorf("Failed to parse boot_wait: %s", err))
} }
self.config.SSHWaitTimeout, err = time.ParseDuration(self.config.RawSSHWaitTimeout) self.config.SSHWaitTimeout, err = time.ParseDuration(self.config.RawSSHWaitTimeout)
@ -223,19 +246,11 @@ func (self *Builder) Prepare(raws ...interface{}) (params []string, retErr error
errs, errors.New("An instance name must be specified.")) errs, errors.New("An instance name must be specified."))
} }
if self.config.InstanceMemory == "" {
self.config.InstanceMemory = "1024000000"
}
if self.config.RootDiskSize == "" { if self.config.RootDiskSize == "" {
errs = packer.MultiErrorAppend( errs = packer.MultiErrorAppend(
errs, errors.New("A root disk size must be specified.")) errs, errors.New("A root disk size must be specified."))
} }
if self.config.CloneTemplate == "" {
self.config.CloneTemplate = "Other install media"
}
/* /*
if self.config.LocalIp == "" { if self.config.LocalIp == "" {
errs = packer.MultiErrorAppend( errs = packer.MultiErrorAppend(
@ -243,17 +258,6 @@ func (self *Builder) Prepare(raws ...interface{}) (params []string, retErr error
} }
*/ */
if len(self.config.PlatformArgs) == 0 {
pargs := make(map[string]string)
pargs["viridian"] = "false"
pargs["nx"] = "true"
pargs["pae"] = "true"
pargs["apic"] = "true"
pargs["timeoffset"] = "0"
pargs["acpi"] = "1"
self.config.PlatformArgs = pargs
}
if self.config.HTTPPortMin > self.config.HTTPPortMax { if self.config.HTTPPortMin > self.config.HTTPPortMax {
errs = packer.MultiErrorAppend( errs = packer.MultiErrorAppend(
errs, errors.New("the HTTP min port must be less than the max")) errs, errors.New("the HTTP min port must be less than the max"))