Skip to content

Commit fcc5ceb

Browse files
committed
Merge pull request #387 from opdemand/ignore-missing-instance
Swallow errors when destroying EC2 instances that no longer exist
2 parents e3d3ed2 + ad3028d commit fcc5ceb

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

provider/ec2.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,17 @@ def destroy_node(node):
147147
region = node['params'].get('region', 'us-east-1')
148148
conn = _create_ec2_connection(node['creds'], region)
149149
if provider_id:
150-
conn.terminate_instances([provider_id])
151-
i = conn.get_all_instances([provider_id])[0].instances[0]
152-
while(True):
153-
time.sleep(2)
154-
i.update()
155-
if i.state == "terminated":
156-
break
150+
try:
151+
conn.terminate_instances([provider_id])
152+
i = conn.get_all_instances([provider_id])[0].instances[0]
153+
while(True):
154+
time.sleep(2)
155+
i.update()
156+
if i.state == "terminated":
157+
break
158+
except EC2ResponseError as e:
159+
if e.code not in ('InvalidInstanceID.NotFound',):
160+
raise
157161

158162

159163
def _create_ec2_connection(creds, region):

0 commit comments

Comments
 (0)