Skip to content

Commit 5ce8a38

Browse files
author
Gabriel Monroy
committed
only terminate node if provider_id exists
1 parent ccd60e2 commit 5ce8a38

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

celerytasks/ec2.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,14 @@ def terminate_node(node_id, creds, params, provider_id):
126126
region = params.get('region', 'us-east-1')
127127
conn = create_ec2_connection(
128128
region, creds['access_key'], creds['secret_key'])
129-
conn.terminate_instances([provider_id])
130-
i = conn.get_all_instances([provider_id])[0].instances[0]
131-
while(True):
132-
time.sleep(2)
133-
i.update()
134-
if i.state == "terminated":
135-
break
129+
if provider_id:
130+
conn.terminate_instances([provider_id])
131+
i = conn.get_all_instances([provider_id])[0].instances[0]
132+
while(True):
133+
time.sleep(2)
134+
i.update()
135+
if i.state == "terminated":
136+
break
136137
# pull the node from the database
137138
node = Node.objects.get(uuid=node_id)
138139
chef_id = node.id

0 commit comments

Comments
 (0)