forked from hashicorp/packer
/
shutdown_config.go
41 lines (32 loc) · 987 Bytes
/
shutdown_config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package common
import (
"fmt"
"time"
"github.com/mitchellh/packer/template/interpolate"
)
type ShutdownConfig struct {
ShutdownCommand string `mapstructure:"shutdown_command"`
RawShutdownTimeout string `mapstructure:"shutdown_timeout"`
RawPostShutdownDelay string `mapstructure:"post_shutdown_delay"`
ShutdownTimeout time.Duration ``
PostShutdownDelay time.Duration ``
}
func (c *ShutdownConfig) Prepare(ctx *interpolate.Context) []error {
if c.RawShutdownTimeout == "" {
c.RawShutdownTimeout = "5m"
}
if c.RawPostShutdownDelay == "" {
c.RawPostShutdownDelay = "0s"
}
var errs []error
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))
}
return errs
}