Skip to content

Commit c47aa8b

Browse files
author
Clark Perkins
committed
Fixed a bug that deleted all the hosts in a cluster
1 parent 53f4ecd commit c47aa8b

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
'psutil>=2.1',
9393
'PyYAML>=3.10',
9494
'requests>=2.4',
95-
'salt>=2015.8.8,<2015.9',
95+
'salt>=2015.8.8,!=2015.8.8.2,<2015.9',
9696
'six>=1.6',
9797
]
9898

stackdio/api/stacks/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1599,7 +1599,7 @@ def destroy_hosts(stack_id, host_ids=None, delete_hosts=True, delete_security_gr
15991599
else:
16001600
logger.info('Destroying complete stack: {0!r}'.format(stack))
16011601

1602-
result = salt_cloud.destroy_map(stack.generate_cloud_map(), parallel=parallel)
1602+
result = salt_cloud.destroy_map(stack.generate_cloud_map(), hosts, parallel=parallel)
16031603

16041604
# Error checking?
16051605
for profile, provider in result.items():

stackdio/api/stacks/utils.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def launch_map(self, cloud_map, **kwargs):
258258

259259
return salt.utils.cloud.simple_types_filter(ret)
260260

261-
def destroy_map(self, cloud_map, **kwargs):
261+
def destroy_map(self, cloud_map, hosts, **kwargs):
262262
"""
263263
Destroy the named VMs
264264
"""
@@ -278,7 +278,7 @@ def destroy_map(self, cloud_map, **kwargs):
278278
)
279279

280280
try:
281-
ret = self._do_destroy(mapper)
281+
ret = self._do_destroy(mapper, hosts)
282282
# It worked
283283
destroyed = True
284284
except ExtraData as e:
@@ -303,12 +303,14 @@ def destroy_map(self, cloud_map, **kwargs):
303303

304304
return ret
305305

306-
def _do_destroy(self, mapper):
306+
def _do_destroy(self, mapper, hosts):
307307
"""
308308
Here's where the destroying actually happens
309309
"""
310310
dmap = mapper.delete_map()
311311

312+
hostnames = [host.hostname for host in hosts]
313+
312314
# This is pulled from the salt-cloud ec2 driver code.
313315
msg = 'The following VMs are set to be destroyed:\n'
314316
names = set()
@@ -317,8 +319,9 @@ def _do_destroy(self, mapper):
317319
for driver, vms in drivers.items():
318320
msg += ' {0}:\n'.format(driver)
319321
for name in vms:
320-
msg += ' {0}\n'.format(name)
321-
names.add(name)
322+
if name in hostnames:
323+
msg += ' {0}\n'.format(name)
324+
names.add(name)
322325

323326
if names:
324327
logger.info(msg)

0 commit comments

Comments
 (0)