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
3503e968
Commit
3503e968
authored
Jun 19, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazonebs: Return proper errors
parent
867e9d1c
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
32 additions
and
3 deletions
+32
-3
builder/amazonebs/builder.go
builder/amazonebs/builder.go
+5
-0
builder/amazonebs/step_connect_ssh.go
builder/amazonebs/step_connect_ssh.go
+10
-3
builder/amazonebs/step_create_ami.go
builder/amazonebs/step_create_ami.go
+4
-0
builder/amazonebs/step_keypair.go
builder/amazonebs/step_keypair.go
+2
-0
builder/amazonebs/step_run_source_instance.go
builder/amazonebs/step_run_source_instance.go
+4
-0
builder/amazonebs/step_security_group.go
builder/amazonebs/step_security_group.go
+2
-0
builder/amazonebs/step_stop_instance.go
builder/amazonebs/step_stop_instance.go
+5
-0
No files found.
builder/amazonebs/builder.go
View file @
3503e968
...
@@ -155,6 +155,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
...
@@ -155,6 +155,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 there are no AMIs, then just return
// If there are no AMIs, then just return
if
_
,
ok
:=
state
[
"amis"
];
!
ok
{
if
_
,
ok
:=
state
[
"amis"
];
!
ok
{
return
nil
,
nil
return
nil
,
nil
...
...
builder/amazonebs/step_connect_ssh.go
View file @
3503e968
...
@@ -2,6 +2,7 @@ package amazonebs
...
@@ -2,6 +2,7 @@ package amazonebs
import
(
import
(
gossh
"code.google.com/p/go.crypto/ssh"
gossh
"code.google.com/p/go.crypto/ssh"
"errors"
"fmt"
"fmt"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
"github.com/mitchellh/multistep"
...
@@ -27,7 +28,9 @@ func (s *stepConnectSSH) Run(state map[string]interface{}) multistep.StepAction
...
@@ -27,7 +28,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
}
}
...
@@ -85,7 +88,9 @@ ConnectWaitLoop:
...
@@ -85,7 +88,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
{
...
@@ -101,7 +106,9 @@ ConnectWaitLoop:
...
@@ -101,7 +106,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/amazonebs/step_create_ami.go
View file @
3503e968
...
@@ -42,6 +42,8 @@ func (s *stepCreateAMI) Run(state map[string]interface{}) multistep.StepAction {
...
@@ -42,6 +42,8 @@ func (s *stepCreateAMI) Run(state map[string]interface{}) multistep.StepAction {
createResp
,
err
:=
ec2conn
.
CreateImage
(
createOpts
)
createResp
,
err
:=
ec2conn
.
CreateImage
(
createOpts
)
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error creating AMI: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -57,6 +59,8 @@ func (s *stepCreateAMI) Run(state map[string]interface{}) multistep.StepAction {
...
@@ -57,6 +59,8 @@ func (s *stepCreateAMI) Run(state map[string]interface{}) multistep.StepAction {
for
{
for
{
imageResp
,
err
:=
ec2conn
.
Images
([]
string
{
createResp
.
ImageId
},
ec2
.
NewFilter
())
imageResp
,
err
:=
ec2conn
.
Images
([]
string
{
createResp
.
ImageId
},
ec2
.
NewFilter
())
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error querying images: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
...
builder/amazonebs/step_keypair.go
View file @
3503e968
...
@@ -23,6 +23,8 @@ func (s *stepKeyPair) Run(state map[string]interface{}) multistep.StepAction {
...
@@ -23,6 +23,8 @@ func (s *stepKeyPair) Run(state map[string]interface{}) multistep.StepAction {
log
.
Printf
(
"temporary keypair name: %s"
,
keyName
)
log
.
Printf
(
"temporary keypair name: %s"
,
keyName
)
keyResp
,
err
:=
ec2conn
.
CreateKeyPair
(
keyName
)
keyResp
,
err
:=
ec2conn
.
CreateKeyPair
(
keyName
)
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error creating temporary keypair: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
...
builder/amazonebs/step_run_source_instance.go
View file @
3503e968
...
@@ -31,6 +31,8 @@ func (s *stepRunSourceInstance) Run(state map[string]interface{}) multistep.Step
...
@@ -31,6 +31,8 @@ func (s *stepRunSourceInstance) Run(state map[string]interface{}) multistep.Step
ui
.
Say
(
"Launching a source AWS instance..."
)
ui
.
Say
(
"Launching a source AWS instance..."
)
runResp
,
err
:=
ec2conn
.
RunInstances
(
runOpts
)
runResp
,
err
:=
ec2conn
.
RunInstances
(
runOpts
)
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error launching source instance: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -41,6 +43,8 @@ func (s *stepRunSourceInstance) Run(state map[string]interface{}) multistep.Step
...
@@ -41,6 +43,8 @@ func (s *stepRunSourceInstance) Run(state map[string]interface{}) multistep.Step
ui
.
Say
(
"Waiting for instance to become ready..."
)
ui
.
Say
(
"Waiting for instance to become ready..."
)
s
.
instance
,
err
=
waitForState
(
ec2conn
,
s
.
instance
,
[]
string
{
"pending"
},
"running"
)
s
.
instance
,
err
=
waitForState
(
ec2conn
,
s
.
instance
,
[]
string
{
"pending"
},
"running"
)
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for instance to become ready: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
...
builder/amazonebs/step_security_group.go
View file @
3503e968
...
@@ -44,6 +44,8 @@ func (s *stepSecurityGroup) Run(state map[string]interface{}) multistep.StepActi
...
@@ -44,6 +44,8 @@ func (s *stepSecurityGroup) Run(state map[string]interface{}) multistep.StepActi
ui
.
Say
(
"Authorizing SSH access on the temporary security group..."
)
ui
.
Say
(
"Authorizing SSH access on the temporary security group..."
)
if
_
,
err
:=
ec2conn
.
AuthorizeSecurityGroup
(
groupResp
.
SecurityGroup
,
perms
);
err
!=
nil
{
if
_
,
err
:=
ec2conn
.
AuthorizeSecurityGroup
(
groupResp
.
SecurityGroup
,
perms
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error creating temporary security group: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
...
builder/amazonebs/step_stop_instance.go
View file @
3503e968
package
amazonebs
package
amazonebs
import
(
import
(
"fmt"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
...
@@ -17,6 +18,8 @@ func (s *stepStopInstance) Run(state map[string]interface{}) multistep.StepActio
...
@@ -17,6 +18,8 @@ func (s *stepStopInstance) Run(state map[string]interface{}) multistep.StepActio
ui
.
Say
(
"Stopping the source instance..."
)
ui
.
Say
(
"Stopping the source instance..."
)
_
,
err
:=
ec2conn
.
StopInstances
(
instance
.
InstanceId
)
_
,
err
:=
ec2conn
.
StopInstances
(
instance
.
InstanceId
)
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error stopping instance: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -27,6 +30,8 @@ func (s *stepStopInstance) Run(state map[string]interface{}) multistep.StepActio
...
@@ -27,6 +30,8 @@ func (s *stepStopInstance) Run(state map[string]interface{}) multistep.StepActio
instance
.
State
.
Name
=
"stopping"
instance
.
State
.
Name
=
"stopping"
instance
,
err
=
waitForState
(
ec2conn
,
instance
,
[]
string
{
"running"
,
"stopping"
},
"stopped"
)
instance
,
err
=
waitForState
(
ec2conn
,
instance
,
[]
string
{
"running"
,
"stopping"
},
"stopped"
)
if
err
!=
nil
{
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for instance to stop: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
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