Commit 05acb7b4 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/digitalocean: unexport calcaulted settings

parent 51206a49
...@@ -40,9 +40,6 @@ type config struct { ...@@ -40,9 +40,6 @@ type config struct {
SnapshotName string SnapshotName string
SSHUsername string `mapstructure:"ssh_username"` SSHUsername string `mapstructure:"ssh_username"`
SSHPort uint `mapstructure:"ssh_port"` SSHPort uint `mapstructure:"ssh_port"`
SSHTimeout time.Duration
EventDelay time.Duration
StateTimeout time.Duration
PackerDebug bool `mapstructure:"packer_debug"` PackerDebug bool `mapstructure:"packer_debug"`
...@@ -50,6 +47,12 @@ type config struct { ...@@ -50,6 +47,12 @@ type config struct {
RawSSHTimeout string `mapstructure:"ssh_timeout"` RawSSHTimeout string `mapstructure:"ssh_timeout"`
RawEventDelay string `mapstructure:"event_delay"` RawEventDelay string `mapstructure:"event_delay"`
RawStateTimeout string `mapstructure:"state_timeout"` RawStateTimeout string `mapstructure:"state_timeout"`
// These are unexported since they're set by other fields
// being set.
sshTimeout time.Duration
eventDelay time.Duration
stateTimeout time.Duration
} }
type Builder struct { type Builder struct {
...@@ -162,19 +165,19 @@ func (b *Builder) Prepare(raws ...interface{}) error { ...@@ -162,19 +165,19 @@ func (b *Builder) Prepare(raws ...interface{}) error {
if err != nil { if err != nil {
errs = append(errs, fmt.Errorf("Failed parsing ssh_timeout: %s", err)) errs = append(errs, fmt.Errorf("Failed parsing ssh_timeout: %s", err))
} }
b.config.SSHTimeout = sshTimeout b.config.sshTimeout = sshTimeout
eventDelay, err := time.ParseDuration(b.config.RawEventDelay) eventDelay, err := time.ParseDuration(b.config.RawEventDelay)
if err != nil { if err != nil {
errs = append(errs, fmt.Errorf("Failed parsing event_delay: %s", err)) errs = append(errs, fmt.Errorf("Failed parsing event_delay: %s", err))
} }
b.config.EventDelay = eventDelay b.config.eventDelay = eventDelay
stateTimeout, err := time.ParseDuration(b.config.RawStateTimeout) stateTimeout, err := time.ParseDuration(b.config.RawStateTimeout)
if err != nil { if err != nil {
errs = append(errs, fmt.Errorf("Failed parsing state_timeout: %s", err)) errs = append(errs, fmt.Errorf("Failed parsing state_timeout: %s", err))
} }
b.config.StateTimeout = stateTimeout b.config.stateTimeout = stateTimeout
// Parse the name of the snapshot // Parse the name of the snapshot
snapNameBuf := new(bytes.Buffer) snapNameBuf := new(bytes.Buffer)
......
...@@ -97,8 +97,8 @@ func (s *stepConnectSSH) Run(state map[string]interface{}) multistep.StepAction ...@@ -97,8 +97,8 @@ func (s *stepConnectSSH) Run(state map[string]interface{}) multistep.StepAction
connected <- nil connected <- nil
}() }()
log.Printf("Waiting up to %s for SSH connection", config.SSHTimeout) log.Printf("Waiting up to %s for SSH connection", config.sshTimeout)
timeout := time.After(config.SSHTimeout) timeout := time.After(config.sshTimeout)
ConnectWaitLoop: ConnectWaitLoop:
for { for {
......
...@@ -60,7 +60,7 @@ func (s *stepCreateDroplet) Cleanup(state map[string]interface{}) { ...@@ -60,7 +60,7 @@ func (s *stepCreateDroplet) Cleanup(state map[string]interface{}) {
// Otherwise we get "pending event" errors, even though there isn't // Otherwise we get "pending event" errors, even though there isn't
// one. // one.
log.Printf("Sleeping for %v, event_delay", c.RawEventDelay) log.Printf("Sleeping for %v, event_delay", c.RawEventDelay)
time.Sleep(c.EventDelay) time.Sleep(c.eventDelay)
err := client.DestroyDroplet(s.dropletId) err := client.DestroyDroplet(s.dropletId)
......
...@@ -20,7 +20,7 @@ func (s *stepPowerOff) Run(state map[string]interface{}) multistep.StepAction { ...@@ -20,7 +20,7 @@ func (s *stepPowerOff) Run(state map[string]interface{}) multistep.StepAction {
// Otherwise we get "pending event" errors, even though there isn't // Otherwise we get "pending event" errors, even though there isn't
// one. // one.
log.Printf("Sleeping for %v, event_delay", c.RawEventDelay) log.Printf("Sleeping for %v, event_delay", c.RawEventDelay)
time.Sleep(c.EventDelay) time.Sleep(c.eventDelay)
// Poweroff the droplet so it can be snapshot // Poweroff the droplet so it can be snapshot
err := client.PowerOffDroplet(dropletId) err := client.PowerOffDroplet(dropletId)
......
...@@ -17,9 +17,7 @@ func waitForDropletState(desiredState string, dropletId uint, client *DigitalOce ...@@ -17,9 +17,7 @@ func waitForDropletState(desiredState string, dropletId uint, client *DigitalOce
attempts += 1 attempts += 1
log.Printf("Checking droplet status... (attempt: %d)", attempts) log.Printf("Checking droplet status... (attempt: %d)", attempts)
_, status, err := client.DropletStatus(dropletId) _, status, err := client.DropletStatus(dropletId)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
break break
...@@ -37,7 +35,7 @@ func waitForDropletState(desiredState string, dropletId uint, client *DigitalOce ...@@ -37,7 +35,7 @@ func waitForDropletState(desiredState string, dropletId uint, client *DigitalOce
}() }()
log.Printf("Waiting for up to %s for droplet to become %s", c.RawStateTimeout, desiredState) log.Printf("Waiting for up to %s for droplet to become %s", c.RawStateTimeout, desiredState)
timeout := time.After(c.StateTimeout) timeout := time.After(c.stateTimeout)
ActiveWaitLoop: ActiveWaitLoop:
for { for {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment