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
da4dfbcd
Commit
da4dfbcd
authored
Jun 19, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/digitalocean: Properly return errors
parent
868bb9c6
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
39 additions
and
9 deletions
+39
-9
builder/digitalocean/builder.go
builder/digitalocean/builder.go
+5
-0
builder/digitalocean/step_connect_ssh.go
builder/digitalocean/step_connect_ssh.go
+10
-3
builder/digitalocean/step_create_droplet.go
builder/digitalocean/step_create_droplet.go
+2
-1
builder/digitalocean/step_create_ssh_key.go
builder/digitalocean/step_create_ssh_key.go
+2
-1
builder/digitalocean/step_droplet_info.go
builder/digitalocean/step_droplet_info.go
+5
-2
builder/digitalocean/step_power_off.go
builder/digitalocean/step_power_off.go
+5
-1
builder/digitalocean/step_snapshot.go
builder/digitalocean/step_snapshot.go
+10
-1
No files found.
builder/digitalocean/builder.go
View file @
da4dfbcd
...
@@ -184,6 +184,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
...
@@ -184,6 +184,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
b
.
runner
.
Run
(
state
)
b
.
runner
.
Run
(
state
)
// If there was an error, return that
if
rawErr
,
ok
:=
state
[
"error"
];
ok
{
return
nil
,
rawErr
.
(
error
)
}
if
_
,
ok
:=
state
[
"snapshot_name"
];
!
ok
{
if
_
,
ok
:=
state
[
"snapshot_name"
];
!
ok
{
log
.
Println
(
"Failed to find snapshot_name in state. Bug?"
)
log
.
Println
(
"Failed to find snapshot_name in state. Bug?"
)
return
nil
,
nil
return
nil
,
nil
...
...
builder/digitalocean/step_connect_ssh.go
View file @
da4dfbcd
...
@@ -2,6 +2,7 @@ package digitalocean
...
@@ -2,6 +2,7 @@ package digitalocean
import
(
import
(
gossh
"code.google.com/p/go.crypto/ssh"
gossh
"code.google.com/p/go.crypto/ssh"
"errors"
"fmt"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/communicator/ssh"
"github.com/mitchellh/packer/communicator/ssh"
...
@@ -26,7 +27,9 @@ func (s *stepConnectSSH) Run(state map[string]interface{}) multistep.StepAction
...
@@ -26,7 +27,9 @@ func (s *stepConnectSSH) Run(state map[string]interface{}) multistep.StepAction
keyring
:=
&
ssh
.
SimpleKeychain
{}
keyring
:=
&
ssh
.
SimpleKeychain
{}
err
:=
keyring
.
AddPEMKey
(
privateKey
)
err
:=
keyring
.
AddPEMKey
(
privateKey
)
if
err
!=
nil
{
if
err
!=
nil
{
ui
.
Say
(
fmt
.
Sprintf
(
"Error setting up SSH config: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Error setting up SSH config: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -87,7 +90,9 @@ ConnectWaitLoop:
...
@@ -87,7 +90,9 @@ ConnectWaitLoop:
// We connected. Just break the loop.
// We connected. Just break the loop.
break
ConnectWaitLoop
break
ConnectWaitLoop
case
<-
timeout
:
case
<-
timeout
:
ui
.
Error
(
"Timeout while waiting to connect to SSH."
)
err
:=
errors
.
New
(
"Timeout waiting for SSH to become available."
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
case
<-
time
.
After
(
1
*
time
.
Second
)
:
case
<-
time
.
After
(
1
*
time
.
Second
)
:
if
_
,
ok
:=
state
[
multistep
.
StateCancelled
];
ok
{
if
_
,
ok
:=
state
[
multistep
.
StateCancelled
];
ok
{
...
@@ -103,7 +108,9 @@ ConnectWaitLoop:
...
@@ -103,7 +108,9 @@ ConnectWaitLoop:
}
}
if
err
!=
nil
{
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error connecting to SSH: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Error connecting to SSH: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
...
builder/digitalocean/step_create_droplet.go
View file @
da4dfbcd
...
@@ -27,8 +27,9 @@ func (s *stepCreateDroplet) Run(state map[string]interface{}) multistep.StepActi
...
@@ -27,8 +27,9 @@ func (s *stepCreateDroplet) Run(state map[string]interface{}) multistep.StepActi
// Create the droplet based on configuration
// Create the droplet based on configuration
dropletId
,
err
:=
client
.
CreateDroplet
(
name
,
c
.
SizeID
,
c
.
ImageID
,
c
.
RegionID
,
sshKeyId
)
dropletId
,
err
:=
client
.
CreateDroplet
(
name
,
c
.
SizeID
,
c
.
ImageID
,
c
.
RegionID
,
sshKeyId
)
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error creating droplet: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
...
builder/digitalocean/step_create_ssh_key.go
View file @
da4dfbcd
...
@@ -46,8 +46,9 @@ func (s *stepCreateSSHKey) Run(state map[string]interface{}) multistep.StepActio
...
@@ -46,8 +46,9 @@ func (s *stepCreateSSHKey) Run(state map[string]interface{}) multistep.StepActio
// Create the key!
// Create the key!
keyId
,
err
:=
client
.
CreateKey
(
name
,
pub_sshformat
)
keyId
,
err
:=
client
.
CreateKey
(
name
,
pub_sshformat
)
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error creating temporary SSH key: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
...
builder/digitalocean/step_droplet_info.go
View file @
da4dfbcd
package
digitalocean
package
digitalocean
import
(
import
(
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
)
)
...
@@ -15,16 +16,18 @@ func (s *stepDropletInfo) Run(state map[string]interface{}) multistep.StepAction
...
@@ -15,16 +16,18 @@ func (s *stepDropletInfo) Run(state map[string]interface{}) multistep.StepAction
ui
.
Say
(
"Waiting for droplet to become active..."
)
ui
.
Say
(
"Waiting for droplet to become active..."
)
err
:=
waitForDropletState
(
"active"
,
dropletId
,
client
)
err
:=
waitForDropletState
(
"active"
,
dropletId
,
client
)
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for droplet to become active: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
// Set the IP on the state for later
// Set the IP on the state for later
ip
,
_
,
err
:=
client
.
DropletStatus
(
dropletId
)
ip
,
_
,
err
:=
client
.
DropletStatus
(
dropletId
)
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error retrieving droplet ID: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
...
builder/digitalocean/step_power_off.go
View file @
da4dfbcd
package
digitalocean
package
digitalocean
import
(
import
(
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
"log"
"log"
...
@@ -25,6 +26,8 @@ func (s *stepPowerOff) Run(state map[string]interface{}) multistep.StepAction {
...
@@ -25,6 +26,8 @@ func (s *stepPowerOff) Run(state map[string]interface{}) multistep.StepAction {
err
:=
client
.
PowerOffDroplet
(
dropletId
)
err
:=
client
.
PowerOffDroplet
(
dropletId
)
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error powering off droplet: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -32,8 +35,9 @@ func (s *stepPowerOff) Run(state map[string]interface{}) multistep.StepAction {
...
@@ -32,8 +35,9 @@ func (s *stepPowerOff) Run(state map[string]interface{}) multistep.StepAction {
ui
.
Say
(
"Waiting for droplet to power off..."
)
ui
.
Say
(
"Waiting for droplet to power off..."
)
err
=
waitForDropletState
(
"off"
,
dropletId
,
client
)
err
=
waitForDropletState
(
"off"
,
dropletId
,
client
)
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for droplet to become 'off': %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
...
builder/digitalocean/step_snapshot.go
View file @
da4dfbcd
package
digitalocean
package
digitalocean
import
(
import
(
"errors"
"fmt"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
...
@@ -18,6 +19,8 @@ func (s *stepSnapshot) Run(state map[string]interface{}) multistep.StepAction {
...
@@ -18,6 +19,8 @@ func (s *stepSnapshot) Run(state map[string]interface{}) multistep.StepAction {
ui
.
Say
(
fmt
.
Sprintf
(
"Creating snapshot: %v"
,
c
.
SnapshotName
))
ui
.
Say
(
fmt
.
Sprintf
(
"Creating snapshot: %v"
,
c
.
SnapshotName
))
err
:=
client
.
CreateSnapshot
(
dropletId
,
c
.
SnapshotName
)
err
:=
client
.
CreateSnapshot
(
dropletId
,
c
.
SnapshotName
)
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error creating snapshot: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -25,6 +28,8 @@ func (s *stepSnapshot) Run(state map[string]interface{}) multistep.StepAction {
...
@@ -25,6 +28,8 @@ func (s *stepSnapshot) Run(state map[string]interface{}) multistep.StepAction {
ui
.
Say
(
"Waiting for snapshot to complete..."
)
ui
.
Say
(
"Waiting for snapshot to complete..."
)
err
=
waitForDropletState
(
"active"
,
dropletId
,
client
)
err
=
waitForDropletState
(
"active"
,
dropletId
,
client
)
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for snapshot to complete: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -32,6 +37,8 @@ func (s *stepSnapshot) Run(state map[string]interface{}) multistep.StepAction {
...
@@ -32,6 +37,8 @@ func (s *stepSnapshot) Run(state map[string]interface{}) multistep.StepAction {
log
.
Printf
(
"Looking up snapshot ID for snapshot: %s"
,
c
.
SnapshotName
)
log
.
Printf
(
"Looking up snapshot ID for snapshot: %s"
,
c
.
SnapshotName
)
images
,
err
:=
client
.
Images
()
images
,
err
:=
client
.
Images
()
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error looking up snapshot ID: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -45,7 +52,9 @@ func (s *stepSnapshot) Run(state map[string]interface{}) multistep.StepAction {
...
@@ -45,7 +52,9 @@ func (s *stepSnapshot) Run(state map[string]interface{}) multistep.StepAction {
}
}
if
imageId
==
0
{
if
imageId
==
0
{
ui
.
Error
(
"Couldn't find snapshot to get the image ID. Bug?"
)
err
:=
errors
.
New
(
"Couldn't find snapshot to get the image ID. Bug?"
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
...
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