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
a93668be
Commit
a93668be
authored
Jun 23, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #26 from mitchellh/digital-ocean-state-timeout
DigitalOcean: Add configuration for state timeout
parents
1da55ab4
15d42af4
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
61 additions
and
11 deletions
+61
-11
builder/digitalocean/builder.go
builder/digitalocean/builder.go
+18
-4
builder/digitalocean/builder_test.go
builder/digitalocean/builder_test.go
+32
-0
builder/digitalocean/step_droplet_info.go
builder/digitalocean/step_droplet_info.go
+2
-1
builder/digitalocean/step_power_off.go
builder/digitalocean/step_power_off.go
+1
-1
builder/digitalocean/step_snapshot.go
builder/digitalocean/step_snapshot.go
+1
-1
builder/digitalocean/wait.go
builder/digitalocean/wait.go
+3
-4
website/source/docs/builders/digitalocean.html.markdown
website/source/docs/builders/digitalocean.html.markdown
+4
-0
No files found.
builder/digitalocean/builder.go
View file @
a93668be
...
...
@@ -39,12 +39,14 @@ type config struct {
SSHPort
uint
`mapstructure:"ssh_port"`
SSHTimeout
time
.
Duration
EventDelay
time
.
Duration
StateTimeout
time
.
Duration
PackerDebug
bool
`mapstructure:"packer_debug"`
RawSnapshotName
string
`mapstructure:"snapshot_name"`
RawSSHTimeout
string
`mapstructure:"ssh_timeout"`
RawEventDelay
string
`mapstructure:"event_delay"`
RawStateTimeout
string
`mapstructure:"state_timeout"`
}
type
Builder
struct
{
...
...
@@ -104,6 +106,12 @@ func (b *Builder) Prepare(raws ...interface{}) error {
b
.
config
.
RawEventDelay
=
"5s"
}
if
b
.
config
.
RawStateTimeout
==
""
{
// Default to 3 minute timeouts waiting for
// desired state. i.e waiting for droplet to become active
b
.
config
.
RawStateTimeout
=
"3m"
}
// A list of errors on the configuration
errs
:=
make
([]
error
,
0
)
...
...
@@ -117,17 +125,23 @@ func (b *Builder) Prepare(raws ...interface{}) error {
errs
=
append
(
errs
,
errors
.
New
(
"an api_key must be specified"
))
}
t
imeout
,
err
:=
time
.
ParseDuration
(
b
.
config
.
RawSSHTimeout
)
sshT
imeout
,
err
:=
time
.
ParseDuration
(
b
.
config
.
RawSSHTimeout
)
if
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Failed parsing ssh_timeout: %s"
,
err
))
}
b
.
config
.
SSHTimeout
=
t
imeout
b
.
config
.
SSHTimeout
=
sshT
imeout
d
elay
,
err
:=
time
.
ParseDuration
(
b
.
config
.
RawEventDelay
)
eventD
elay
,
err
:=
time
.
ParseDuration
(
b
.
config
.
RawEventDelay
)
if
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Failed parsing event_delay: %s"
,
err
))
}
b
.
config
.
EventDelay
=
delay
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
// Parse the name of the snapshot
snapNameBuf
:=
new
(
bytes
.
Buffer
)
...
...
builder/digitalocean/builder_test.go
View file @
a93668be
...
...
@@ -253,6 +253,38 @@ func TestBuilderPrepare_EventDelay(t *testing.T) {
}
func
TestBuilderPrepare_StateTimeout
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
// Test default
err
:=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
if
b
.
config
.
RawStateTimeout
!=
"3m"
{
t
.
Errorf
(
"invalid: %d"
,
b
.
config
.
RawStateTimeout
)
}
// Test set
config
[
"state_timeout"
]
=
"5m"
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
// Test bad
config
[
"state_timeout"
]
=
"tubes"
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
}
func
TestBuilderPrepare_SnapshotName
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
...
...
builder/digitalocean/step_droplet_info.go
View file @
a93668be
...
...
@@ -11,11 +11,12 @@ type stepDropletInfo struct{}
func
(
s
*
stepDropletInfo
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
client
:=
state
[
"client"
]
.
(
*
DigitalOceanClient
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
c
:=
state
[
"config"
]
.
(
config
)
dropletId
:=
state
[
"droplet_id"
]
.
(
uint
)
ui
.
Say
(
"Waiting for droplet to become active..."
)
err
:=
waitForDropletState
(
"active"
,
dropletId
,
client
)
err
:=
waitForDropletState
(
"active"
,
dropletId
,
client
,
c
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for droplet to become active: %s"
,
err
)
state
[
"error"
]
=
err
...
...
builder/digitalocean/step_power_off.go
View file @
a93668be
...
...
@@ -34,7 +34,7 @@ func (s *stepPowerOff) Run(state map[string]interface{}) multistep.StepAction {
ui
.
Say
(
"Waiting for droplet to power off..."
)
err
=
waitForDropletState
(
"off"
,
dropletId
,
client
)
err
=
waitForDropletState
(
"off"
,
dropletId
,
client
,
c
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for droplet to become 'off': %s"
,
err
)
state
[
"error"
]
=
err
...
...
builder/digitalocean/step_snapshot.go
View file @
a93668be
...
...
@@ -26,7 +26,7 @@ func (s *stepSnapshot) Run(state map[string]interface{}) multistep.StepAction {
}
ui
.
Say
(
"Waiting for snapshot to complete..."
)
err
=
waitForDropletState
(
"active"
,
dropletId
,
client
)
err
=
waitForDropletState
(
"active"
,
dropletId
,
client
,
c
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for snapshot to complete: %s"
,
err
)
state
[
"error"
]
=
err
...
...
builder/digitalocean/wait.go
View file @
a93668be
...
...
@@ -8,7 +8,7 @@ import (
// waitForState simply blocks until the droplet is in
// a state we expect, while eventually timing out.
func
waitForDropletState
(
desiredState
string
,
dropletId
uint
,
client
*
DigitalOceanClient
)
error
{
func
waitForDropletState
(
desiredState
string
,
dropletId
uint
,
client
*
DigitalOceanClient
,
c
config
)
error
{
active
:=
make
(
chan
bool
,
1
)
go
func
()
{
...
...
@@ -36,9 +36,8 @@ func waitForDropletState(desiredState string, dropletId uint, client *DigitalOce
active
<-
true
}()
log
.
Printf
(
"Waiting for up to 3 minutes for droplet to become %s"
,
desiredState
)
duration
,
_
:=
time
.
ParseDuration
(
"3m"
)
timeout
:=
time
.
After
(
duration
)
log
.
Printf
(
"Waiting for up to %s for droplet to become %s"
,
c
.
RawStateTimeout
,
desiredState
)
timeout
:=
time
.
After
(
c
.
StateTimeout
)
ActiveWaitLoop
:
for
{
...
...
website/source/docs/builders/digitalocean.html.markdown
View file @
a93668be
...
...
@@ -64,6 +64,10 @@ Optional:
*
`ssh_username`
(string) - The username to use in order to communicate
over SSH to the running droplet. Default is "root".
*
`state_timeout`
(string) - The time to wait, as a duration string,
for a droplet to enter a desired state (such as "active") before
timing out. The default state timeout is "3m".
## Basic Example
Here is a basic example. It is completely valid as soon as you enter your
...
...
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