Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
31b5b66e
Commit
31b5b66e
authored
Nov 06, 2013
by
jctanner
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4776 from jlaska/ec2_wait_on_terminate
Honor wait on ec2 instance termination
parents
b6c1574f
2a5874b9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
1 deletions
+27
-1
library/cloud/ec2
+27
-1
No files found.
library/cloud/ec2
View file @
31b5b66e
...
@@ -533,6 +533,10 @@ def terminate_instances(module, ec2, instance_ids):
...
@@ -533,6 +533,10 @@ def terminate_instances(module, ec2, instance_ids):
"""
"""
# Whether to wait for termination to complete before returning
wait
=
module
.
params
.
get
(
'wait'
)
wait_timeout
=
int
(
module
.
params
.
get
(
'wait_timeout'
))
changed
=
False
changed
=
False
instance_dict_array
=
[]
instance_dict_array
=
[]
...
@@ -551,8 +555,30 @@ def terminate_instances(module, ec2, instance_ids):
...
@@ -551,8 +555,30 @@ def terminate_instances(module, ec2, instance_ids):
module
.
fail_json
(
msg
=
'Unable to terminate instance {0}, error: {1}'
.
format
(
inst
.
id
,
e
))
module
.
fail_json
(
msg
=
'Unable to terminate instance {0}, error: {1}'
.
format
(
inst
.
id
,
e
))
changed
=
True
changed
=
True
return
(
changed
,
instance_dict_array
,
terminated_instance_ids
)
# wait here until the instances are 'terminated'
if
wait
:
num_terminated
=
0
wait_timeout
=
time
.
time
()
+
wait_timeout
while
wait_timeout
>
time
.
time
()
and
num_terminated
<
len
(
terminated_instance_ids
):
response
=
ec2
.
get_all_instances
(
\
instance_ids
=
terminated_instance_ids
,
\
filters
=
{
'instance-state-name'
:
'terminated'
})
try
:
num_terminated
=
len
(
response
.
pop
()
.
instances
)
except
Exception
,
e
:
# got a bad response of some sort, possibly due to
# stale/cached data. Wait a second and then try again
time
.
sleep
(
1
)
continue
if
num_terminated
<
len
(
terminated_instance_ids
):
time
.
sleep
(
5
)
# waiting took too long
if
wait_timeout
<
time
.
time
()
and
num_terminated
<
len
(
terminated_instance_ids
):
module
.
fail_json
(
msg
=
"wait for instance termination timeout on
%
s"
%
time
.
asctime
())
return
(
changed
,
instance_dict_array
,
terminated_instance_ids
)
def
main
():
def
main
():
...
...
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