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
c7b88d65
Commit
c7b88d65
authored
Jul 29, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazon/common: generic wait for state to wait for any state
parent
4773b487
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
18 deletions
+34
-18
builder/amazon/common/instance.go
builder/amazon/common/instance.go
+27
-13
builder/amazon/common/step_run_source_instance.go
builder/amazon/common/step_run_source_instance.go
+4
-3
builder/amazon/ebs/step_stop_instance.go
builder/amazon/ebs/step_stop_instance.go
+3
-2
No files found.
builder/amazon/common/instance.go
View file @
c7b88d65
...
...
@@ -11,17 +11,38 @@ import (
type
StateChangeConf
struct
{
Conn
*
ec2
.
EC2
Instance
*
ec2
.
Instance
Pending
[]
string
Refresh
func
()
(
interface
{},
string
,
error
)
StepState
map
[
string
]
interface
{}
Target
string
}
func
WaitForState
(
conf
*
StateChangeConf
)
(
i
*
ec2
.
Instance
,
err
error
)
{
func
InstanceStateRefreshFunc
(
conn
*
ec2
.
EC2
,
i
*
ec2
.
Instance
)
func
()
(
interface
{},
string
,
error
)
{
return
func
()
(
interface
{},
string
,
error
)
{
resp
,
err
:=
conn
.
Instances
([]
string
{
i
.
InstanceId
},
ec2
.
NewFilter
())
if
err
!=
nil
{
return
nil
,
""
,
err
}
i
=
&
resp
.
Reservations
[
0
]
.
Instances
[
0
]
return
i
,
i
.
State
.
Name
,
nil
}
}
func
WaitForState
(
conf
*
StateChangeConf
)
(
i
interface
{},
err
error
)
{
log
.
Printf
(
"Waiting for instance state to become: %s"
,
conf
.
Target
)
i
=
conf
.
Instance
for
i
.
State
.
Name
!=
conf
.
Target
{
for
{
var
currentState
string
i
,
currentState
,
err
=
conf
.
Refresh
()
if
err
!=
nil
{
return
}
if
currentState
==
conf
.
Target
{
return
}
if
conf
.
StepState
!=
nil
{
if
_
,
ok
:=
conf
.
StepState
[
multistep
.
StateCancelled
];
ok
{
return
nil
,
errors
.
New
(
"interrupted"
)
...
...
@@ -30,24 +51,17 @@ func WaitForState(conf *StateChangeConf) (i *ec2.Instance, err error) {
found
:=
false
for
_
,
allowed
:=
range
conf
.
Pending
{
if
i
.
State
.
Nam
e
==
allowed
{
if
currentStat
e
==
allowed
{
found
=
true
break
}
}
if
!
found
{
fmt
.
Errorf
(
"unexpected state '%s', wanted target '%s'"
,
i
.
State
.
Nam
e
,
conf
.
Target
)
fmt
.
Errorf
(
"unexpected state '%s', wanted target '%s'"
,
currentStat
e
,
conf
.
Target
)
return
}
var
resp
*
ec2
.
InstancesResp
resp
,
err
=
conf
.
Conn
.
Instances
([]
string
{
i
.
InstanceId
},
ec2
.
NewFilter
())
if
err
!=
nil
{
return
}
i
=
&
resp
.
Reservations
[
0
]
.
Instances
[
0
]
time
.
Sleep
(
2
*
time
.
Second
)
}
...
...
builder/amazon/common/step_run_source_instance.go
View file @
c7b88d65
...
...
@@ -62,12 +62,13 @@ func (s *StepRunSourceInstance) Run(state map[string]interface{}) multistep.Step
ui
.
Say
(
fmt
.
Sprintf
(
"Waiting for instance (%s) to become ready..."
,
s
.
instance
.
InstanceId
))
stateChange
:=
StateChangeConf
{
Conn
:
ec2conn
,
Instance
:
s
.
instance
,
Pending
:
[]
string
{
"pending"
},
Target
:
"running"
,
Refresh
:
InstanceStateRefreshFunc
(
ec2conn
,
s
.
instance
),
StepState
:
state
,
}
s
.
instance
,
err
=
WaitForState
(
&
stateChange
)
latestInstance
,
err
:=
WaitForState
(
&
stateChange
)
s
.
instance
=
latestInstance
.
(
*
ec2
.
Instance
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for instance (%s) to become ready: %s"
,
s
.
instance
.
InstanceId
,
err
)
state
[
"error"
]
=
err
...
...
@@ -96,8 +97,8 @@ func (s *StepRunSourceInstance) Cleanup(state map[string]interface{}) {
stateChange
:=
StateChangeConf
{
Conn
:
ec2conn
,
Instance
:
s
.
instance
,
Pending
:
[]
string
{
"pending"
,
"running"
,
"shutting-down"
,
"stopped"
,
"stopping"
},
Refresh
:
InstanceStateRefreshFunc
(
ec2conn
,
s
.
instance
),
Target
:
"running"
,
}
...
...
builder/amazon/ebs/step_stop_instance.go
View file @
c7b88d65
...
...
@@ -29,12 +29,13 @@ func (s *stepStopInstance) Run(state map[string]interface{}) multistep.StepActio
ui
.
Say
(
"Waiting for the instance to stop..."
)
stateChange
:=
awscommon
.
StateChangeConf
{
Conn
:
ec2conn
,
Instance
:
instance
,
Pending
:
[]
string
{
"running"
,
"stopping"
},
Target
:
"stopped"
,
Refresh
:
awscommon
.
InstanceStateRefreshFunc
(
ec2conn
,
instance
),
StepState
:
state
,
}
instance
,
err
=
awscommon
.
WaitForState
(
&
stateChange
)
instanceRaw
,
err
:=
awscommon
.
WaitForState
(
&
stateChange
)
instance
=
instanceRaw
.
(
*
ec2
.
Instance
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for instance to stop: %s"
,
err
)
state
[
"error"
]
=
err
...
...
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