packer-cn/builder/virtualbox/common/shutdown_config.go

42 lines
987 B
Go
Raw Normal View History

2013-12-22 09:37:27 -08:00
package common
import (
"fmt"
"time"
2017-04-04 13:39:01 -07:00
"github.com/hashicorp/packer/template/interpolate"
2013-12-22 09:37:27 -08:00
)
type ShutdownConfig struct {
2016-10-11 23:43:50 +02:00
ShutdownCommand string `mapstructure:"shutdown_command"`
RawShutdownTimeout string `mapstructure:"shutdown_timeout"`
RawPostShutdownDelay string `mapstructure:"post_shutdown_delay"`
2013-12-22 09:37:27 -08:00
2016-10-11 23:43:50 +02:00
ShutdownTimeout time.Duration ``
PostShutdownDelay time.Duration ``
2013-12-22 09:37:27 -08:00
}
func (c *ShutdownConfig) Prepare(ctx *interpolate.Context) []error {
2013-12-22 09:37:27 -08:00
if c.RawShutdownTimeout == "" {
c.RawShutdownTimeout = "5m"
}
if c.RawPostShutdownDelay == "" {
c.RawPostShutdownDelay = "0s"
}
var errs []error
2013-12-22 09:37:27 -08:00
var err error
c.ShutdownTimeout, err = time.ParseDuration(c.RawShutdownTimeout)
if err != nil {
errs = append(errs, fmt.Errorf("Failed parsing shutdown_timeout: %s", err))
}
c.PostShutdownDelay, err = time.ParseDuration(c.RawPostShutdownDelay)
if err != nil {
errs = append(errs, fmt.Errorf("Failed parsing post_shutdown_delay: %s", err))
}
2013-12-22 09:37:27 -08:00
return errs
}