From 05acb7b46139553d5be92fdecd2fbf7faee6af5c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 14 Jul 2013 21:20:29 +0900 Subject: [PATCH] builder/digitalocean: unexport calcaulted settings --- builder/digitalocean/builder.go | 15 +++++++++------ builder/digitalocean/step_connect_ssh.go | 4 ++-- builder/digitalocean/step_create_droplet.go | 2 +- builder/digitalocean/step_power_off.go | 2 +- builder/digitalocean/wait.go | 4 +--- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/builder/digitalocean/builder.go b/builder/digitalocean/builder.go index 1f0ebfae7..d03459987 100644 --- a/builder/digitalocean/builder.go +++ b/builder/digitalocean/builder.go @@ -40,9 +40,6 @@ type config struct { SnapshotName string SSHUsername string `mapstructure:"ssh_username"` SSHPort uint `mapstructure:"ssh_port"` - SSHTimeout time.Duration - EventDelay time.Duration - StateTimeout time.Duration PackerDebug bool `mapstructure:"packer_debug"` @@ -50,6 +47,12 @@ type config struct { RawSSHTimeout string `mapstructure:"ssh_timeout"` RawEventDelay string `mapstructure:"event_delay"` 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 { @@ -162,19 +165,19 @@ func (b *Builder) Prepare(raws ...interface{}) error { if err != nil { 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) if err != nil { 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) if err != nil { 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 snapNameBuf := new(bytes.Buffer) diff --git a/builder/digitalocean/step_connect_ssh.go b/builder/digitalocean/step_connect_ssh.go index 591a02482..c25923201 100644 --- a/builder/digitalocean/step_connect_ssh.go +++ b/builder/digitalocean/step_connect_ssh.go @@ -97,8 +97,8 @@ func (s *stepConnectSSH) Run(state map[string]interface{}) multistep.StepAction connected <- nil }() - log.Printf("Waiting up to %s for SSH connection", config.SSHTimeout) - timeout := time.After(config.SSHTimeout) + log.Printf("Waiting up to %s for SSH connection", config.sshTimeout) + timeout := time.After(config.sshTimeout) ConnectWaitLoop: for { diff --git a/builder/digitalocean/step_create_droplet.go b/builder/digitalocean/step_create_droplet.go index d4e538f30..1cbf16724 100644 --- a/builder/digitalocean/step_create_droplet.go +++ b/builder/digitalocean/step_create_droplet.go @@ -60,7 +60,7 @@ func (s *stepCreateDroplet) Cleanup(state map[string]interface{}) { // Otherwise we get "pending event" errors, even though there isn't // one. log.Printf("Sleeping for %v, event_delay", c.RawEventDelay) - time.Sleep(c.EventDelay) + time.Sleep(c.eventDelay) err := client.DestroyDroplet(s.dropletId) diff --git a/builder/digitalocean/step_power_off.go b/builder/digitalocean/step_power_off.go index 750cb8578..8d0bb340c 100644 --- a/builder/digitalocean/step_power_off.go +++ b/builder/digitalocean/step_power_off.go @@ -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 // one. 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 err := client.PowerOffDroplet(dropletId) diff --git a/builder/digitalocean/wait.go b/builder/digitalocean/wait.go index 85394e414..75ad01f9d 100644 --- a/builder/digitalocean/wait.go +++ b/builder/digitalocean/wait.go @@ -17,9 +17,7 @@ func waitForDropletState(desiredState string, dropletId uint, client *DigitalOce attempts += 1 log.Printf("Checking droplet status... (attempt: %d)", attempts) - _, status, err := client.DropletStatus(dropletId) - if err != nil { log.Println(err) break @@ -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) - timeout := time.After(c.StateTimeout) + timeout := time.After(c.stateTimeout) ActiveWaitLoop: for {