2013-12-22 12:37:27 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
2015-05-27 17:01:08 -04:00
|
|
|
|
|
|
|
"github.com/mitchellh/packer/template/interpolate"
|
2013-12-22 12:37:27 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type ShutdownConfig struct {
|
2016-10-11 17:43:50 -04:00
|
|
|
ShutdownCommand string `mapstructure:"shutdown_command"`
|
|
|
|
RawShutdownTimeout string `mapstructure:"shutdown_timeout"`
|
2016-10-02 13:08:32 -04:00
|
|
|
RawPostShutdownDelay string `mapstructure:"post_shutdown_delay"`
|
2013-12-22 12:37:27 -05:00
|
|
|
|
2016-10-11 17:43:50 -04:00
|
|
|
ShutdownTimeout time.Duration ``
|
2016-10-02 13:08:32 -04:00
|
|
|
PostShutdownDelay time.Duration ``
|
2013-12-22 12:37:27 -05:00
|
|
|
}
|
|
|
|
|
2015-05-27 17:01:08 -04:00
|
|
|
func (c *ShutdownConfig) Prepare(ctx *interpolate.Context) []error {
|
2013-12-22 12:37:27 -05:00
|
|
|
if c.RawShutdownTimeout == "" {
|
|
|
|
c.RawShutdownTimeout = "5m"
|
|
|
|
}
|
|
|
|
|
2016-10-02 13:08:32 -04:00
|
|
|
if c.RawPostShutdownDelay == "" {
|
|
|
|
c.RawPostShutdownDelay = "0s"
|
|
|
|
}
|
|
|
|
|
2015-05-27 17:01:08 -04:00
|
|
|
var errs []error
|
2013-12-22 12:37:27 -05: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))
|
|
|
|
}
|
|
|
|
|
2016-10-02 13:08:32 -04:00
|
|
|
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 12:37:27 -05:00
|
|
|
return errs
|
|
|
|
}
|