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

57 lines
1.9 KiB
Go
Raw Normal View History

2013-12-22 12:37:27 -05:00
package common
import (
"fmt"
"time"
2017-04-04 16:39:01 -04:00
"github.com/hashicorp/packer/template/interpolate"
2013-12-22 12:37:27 -05:00
)
type ShutdownConfig struct {
// The command to use to gracefully shut down the
// machine once all the provisioning is done. By default this is an empty
// string, which tells Packer to just forcefully shut down the machine unless a
// shutdown command takes place inside script so this may safely be omitted. If
// one or more scripts require a reboot it is suggested to leave this blank
// since reboots may fail and specify the final shutdown command in your
// last script.
ShutdownCommand string `mapstructure:"shutdown_command" required:"false"`
// The amount of time to wait after executing the
// shutdown_command for the virtual machine to actually shut down. If it
// doesn't shut down in this time, it is an error. By default, the timeout is
// 5m or five minutes.
RawShutdownTimeout string `mapstructure:"shutdown_timeout" required:"false"`
// The amount of time to wait after shutting
// down the virtual machine. If you get the error
// Error removing floppy controller, you might need to set this to 5m
// or so. By default, the delay is 0s or disabled.
RawPostShutdownDelay string `mapstructure:"post_shutdown_delay" required:"false"`
2013-12-22 12:37:27 -05:00
2016-10-11 17:43:50 -04:00
ShutdownTimeout time.Duration ``
PostShutdownDelay time.Duration ``
2013-12-22 12:37:27 -05:00
}
func (c *ShutdownConfig) Prepare(ctx *interpolate.Context) []error {
2013-12-22 12:37:27 -05:00
if c.RawShutdownTimeout == "" {
c.RawShutdownTimeout = "5m"
}
if c.RawPostShutdownDelay == "" {
c.RawPostShutdownDelay = "0s"
}
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))
}
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
}