github.phpd.cn/hashicorp/packer@v1.3.2/builder/virtualbox/common/shutdown_config.go (about) 1 package common 2 3 import ( 4 "fmt" 5 "time" 6 7 "github.com/hashicorp/packer/template/interpolate" 8 ) 9 10 type ShutdownConfig struct { 11 ShutdownCommand string `mapstructure:"shutdown_command"` 12 RawShutdownTimeout string `mapstructure:"shutdown_timeout"` 13 RawPostShutdownDelay string `mapstructure:"post_shutdown_delay"` 14 15 ShutdownTimeout time.Duration `` 16 PostShutdownDelay time.Duration `` 17 } 18 19 func (c *ShutdownConfig) Prepare(ctx *interpolate.Context) []error { 20 if c.RawShutdownTimeout == "" { 21 c.RawShutdownTimeout = "5m" 22 } 23 24 if c.RawPostShutdownDelay == "" { 25 c.RawPostShutdownDelay = "0s" 26 } 27 28 var errs []error 29 var err error 30 c.ShutdownTimeout, err = time.ParseDuration(c.RawShutdownTimeout) 31 if err != nil { 32 errs = append(errs, fmt.Errorf("Failed parsing shutdown_timeout: %s", err)) 33 } 34 35 c.PostShutdownDelay, err = time.ParseDuration(c.RawPostShutdownDelay) 36 if err != nil { 37 errs = append(errs, fmt.Errorf("Failed parsing post_shutdown_delay: %s", err)) 38 } 39 40 return errs 41 }