Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
dcf140f9
Commit
dcf140f9
authored
Jun 10, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/digitalocean: more robust wait for pending
parent
0e0cd280
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
2 deletions
+91
-2
builder/digitalocean/config.go
builder/digitalocean/config.go
+6
-1
builder/digitalocean/step_power_off.go
builder/digitalocean/step_power_off.go
+10
-0
builder/digitalocean/step_shutdown.go
builder/digitalocean/step_shutdown.go
+13
-1
builder/digitalocean/step_snapshot.go
builder/digitalocean/step_snapshot.go
+13
-0
builder/digitalocean/wait.go
builder/digitalocean/wait.go
+49
-0
No files found.
builder/digitalocean/config.go
View file @
dcf140f9
...
...
@@ -64,8 +64,13 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
}
if
c
.
SnapshotName
==
""
{
def
,
err
:=
interpolate
.
Render
(
"packer-{{timestamp}}"
,
nil
)
if
err
!=
nil
{
panic
(
err
)
}
// Default to packer-{{ unix timestamp (utc) }}
c
.
SnapshotName
=
"packer-{{timestamp}}"
c
.
SnapshotName
=
def
}
if
c
.
DropletName
==
""
{
...
...
builder/digitalocean/step_power_off.go
View file @
dcf140f9
...
...
@@ -3,6 +3,7 @@ package digitalocean
import
(
"fmt"
"log"
"time"
"github.com/digitalocean/godo"
"github.com/mitchellh/multistep"
...
...
@@ -48,6 +49,15 @@ func (s *stepPowerOff) Run(state multistep.StateBag) multistep.StepAction {
return
multistep
.
ActionHalt
}
// Wait for the droplet to become unlocked for future steps
if
err
:=
waitForDropletUnlocked
(
client
,
dropletId
,
2
*
time
.
Minute
);
err
!=
nil
{
// If we get an error the first time, actually report it
err
:=
fmt
.
Errorf
(
"Error powering off droplet: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
return
multistep
.
ActionContinue
}
...
...
builder/digitalocean/step_shutdown.go
View file @
dcf140f9
...
...
@@ -65,7 +65,19 @@ func (s *stepShutdown) Run(state multistep.StateBag) multistep.StepAction {
err
=
waitForDropletState
(
"off"
,
dropletId
,
client
,
2
*
time
.
Minute
)
if
err
!=
nil
{
log
.
Printf
(
"Error waiting for graceful off: %s"
,
err
)
// If we get an error the first time, actually report it
err
:=
fmt
.
Errorf
(
"Error shutting down droplet: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
if
err
:=
waitForDropletUnlocked
(
client
,
dropletId
,
2
*
time
.
Minute
);
err
!=
nil
{
// If we get an error the first time, actually report it
err
:=
fmt
.
Errorf
(
"Error shutting down droplet: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
return
multistep
.
ActionContinue
...
...
builder/digitalocean/step_snapshot.go
View file @
dcf140f9
...
...
@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"log"
"time"
"github.com/digitalocean/godo"
"github.com/mitchellh/multistep"
...
...
@@ -27,6 +28,18 @@ func (s *stepSnapshot) Run(state multistep.StateBag) multistep.StepAction {
return
multistep
.
ActionHalt
}
// Wait for the droplet to become unlocked first. For snapshots
// this can end up taking quite a long time, so we hardcode this to
// 10 minutes.
if
err
:=
waitForDropletUnlocked
(
client
,
dropletId
,
10
*
time
.
Minute
);
err
!=
nil
{
// If we get an error the first time, actually report it
err
:=
fmt
.
Errorf
(
"Error shutting down droplet: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
// With the pending state over, verify that we're in the active state
ui
.
Say
(
"Waiting for snapshot to complete..."
)
err
=
waitForDropletState
(
"active"
,
dropletId
,
client
,
c
.
stateTimeout
)
if
err
!=
nil
{
...
...
builder/digitalocean/wait.go
View file @
dcf140f9
...
...
@@ -8,6 +8,55 @@ import (
"github.com/digitalocean/godo"
)
// waitForDropletUnlocked waits for the Droplet to be unlocked to
// avoid "pending" errors when making state changes.
func
waitForDropletUnlocked
(
client
*
godo
.
Client
,
dropletId
int
,
timeout
time
.
Duration
)
error
{
done
:=
make
(
chan
struct
{})
defer
close
(
done
)
result
:=
make
(
chan
error
,
1
)
go
func
()
{
attempts
:=
0
for
{
attempts
+=
1
log
.
Printf
(
"[DEBUG] Checking droplet lock state... (attempt: %d)"
,
attempts
)
droplet
,
_
,
err
:=
client
.
Droplets
.
Get
(
dropletId
)
if
err
!=
nil
{
result
<-
err
return
}
if
!
droplet
.
Locked
{
result
<-
nil
return
}
// Wait 3 seconds in between
time
.
Sleep
(
3
*
time
.
Second
)
// Verify we shouldn't exit
select
{
case
<-
done
:
// We finished, so just exit the goroutine
return
default
:
// Keep going
}
}
}()
log
.
Printf
(
"[DEBUG] Waiting for up to %d seconds for droplet to unlock"
,
timeout
/
time
.
Second
)
select
{
case
err
:=
<-
result
:
return
err
case
<-
time
.
After
(
timeout
)
:
return
fmt
.
Errorf
(
"Timeout while waiting to for droplet to unlock"
)
}
}
// waitForState simply blocks until the droplet is in
// a state we expect, while eventually timing out.
func
waitForDropletState
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment