2014-04-06 13:21:22 -04:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
2015-05-27 16:49:31 -04:00
|
|
|
|
|
|
|
"github.com/mitchellh/packer/template/interpolate"
|
2014-04-06 13:21:22 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type ShutdownConfig struct {
|
|
|
|
ShutdownCommand string `mapstructure:"shutdown_command"`
|
|
|
|
RawShutdownTimeout string `mapstructure:"shutdown_timeout"`
|
|
|
|
|
|
|
|
ShutdownTimeout time.Duration ``
|
|
|
|
}
|
|
|
|
|
2015-05-27 16:49:31 -04:00
|
|
|
func (c *ShutdownConfig) Prepare(ctx *interpolate.Context) []error {
|
2014-04-06 13:21:22 -04:00
|
|
|
if c.RawShutdownTimeout == "" {
|
|
|
|
c.RawShutdownTimeout = "5m"
|
|
|
|
}
|
|
|
|
|
2015-05-27 16:49:31 -04:00
|
|
|
var errs []error
|
2014-04-06 13:21:22 -04: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))
|
|
|
|
}
|
|
|
|
|
|
|
|
return errs
|
|
|
|
}
|