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
2011e098
Commit
2011e098
authored
Aug 27, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #339 from mitchellh/do-soft-shutdown
builder/digitalocean: send a "shutdown" before snapshotting
parents
03cdac30
315d4ce5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
8 deletions
+66
-8
builder/digitalocean/api.go
builder/digitalocean/api.go
+9
-0
builder/digitalocean/builder.go
builder/digitalocean/builder.go
+1
-0
builder/digitalocean/step_power_off.go
builder/digitalocean/step_power_off.go
+7
-8
builder/digitalocean/step_shutdown.go
builder/digitalocean/step_shutdown.go
+49
-0
No files found.
builder/digitalocean/api.go
View file @
2011e098
...
...
@@ -115,6 +115,15 @@ func (d DigitalOceanClient) PowerOffDroplet(id uint) error {
return
err
}
// Shutsdown a droplet. This is a "soft" shutdown.
func
(
d
DigitalOceanClient
)
ShutdownDroplet
(
id
uint
)
error
{
path
:=
fmt
.
Sprintf
(
"droplets/%v/shutdown"
,
id
)
_
,
err
:=
NewRequest
(
d
,
path
,
url
.
Values
{})
return
err
}
// Creates a snaphot of a droplet by it's ID
func
(
d
DigitalOceanClient
)
CreateSnapshot
(
id
uint
,
name
string
)
error
{
path
:=
fmt
.
Sprintf
(
"droplets/%v/snapshot"
,
id
)
...
...
builder/digitalocean/builder.go
View file @
2011e098
...
...
@@ -206,6 +206,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
SSHWaitTimeout
:
5
*
time
.
Minute
,
},
new
(
common
.
StepProvision
),
new
(
stepShutdown
),
new
(
stepPowerOff
),
new
(
stepSnapshot
),
}
...
...
builder/digitalocean/step_power_off.go
View file @
2011e098
...
...
@@ -32,15 +32,14 @@ func (s *stepPowerOff) Run(state map[string]interface{}) multistep.StepAction {
return
multistep
.
ActionHalt
}
ui
.
Say
(
"Waiting for droplet to power off
..."
)
log
.
Println
(
"Waiting for poweroff event to complete
..."
)
err
=
waitForDropletState
(
"off"
,
dropletId
,
client
,
c
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for droplet to become 'off': %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
// This arbitrary sleep is because we can't wait for the state
// of the droplet to be 'off', as stepShutdown should already
// have accomplished that, and the state indicator is the same.
// We just have to assume that this event will process quickly.
log
.
Printf
(
"Sleeping for %v, event_delay"
,
c
.
RawEventDelay
)
time
.
Sleep
(
c
.
eventDelay
)
return
multistep
.
ActionContinue
}
...
...
builder/digitalocean/step_shutdown.go
0 → 100644
View file @
2011e098
package
digitalocean
import
(
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
"time"
)
type
stepShutdown
struct
{}
func
(
s
*
stepShutdown
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
client
:=
state
[
"client"
]
.
(
*
DigitalOceanClient
)
c
:=
state
[
"config"
]
.
(
config
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
dropletId
:=
state
[
"droplet_id"
]
.
(
uint
)
// Sleep arbitrarily before sending the request
// 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
)
err
:=
client
.
ShutdownDroplet
(
dropletId
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error shutting down droplet: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
ui
.
Say
(
"Waiting for droplet to shutdown..."
)
err
=
waitForDropletState
(
"off"
,
dropletId
,
client
,
c
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for droplet to become 'off': %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
return
multistep
.
ActionContinue
}
func
(
s
*
stepShutdown
)
Cleanup
(
state
map
[
string
]
interface
{})
{
// no cleanup
}
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