Skip to content

Commit

Permalink
Make the salt-cloud actions output more verbose and helpful
Browse files Browse the repository at this point in the history
Fixes #10157
  • Loading branch information
rallytime committed Jan 22, 2016
1 parent 119f025 commit 6fa952f
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions salt/cloud/__init__.py
Expand Up @@ -1436,6 +1436,7 @@ def do_action(self, names, kwargs):
Perform an action on a VM which may be specific to this cloud provider
'''
ret = {}
invalid_functions = {}
names = set(names)

for alias, drivers in six.iteritems(self.map_providers_parallel()):
Expand All @@ -1444,14 +1445,15 @@ def do_action(self, names, kwargs):
for driver, vms in six.iteritems(drivers):
if not names:
break
valid_function = True
fun = '{0}.{1}'.format(driver, self.opts['action'])
if fun not in self.clouds:
log.info(
six.u('\'{0}()\' is not available. Not actioning...').format(
fun
)
)
continue
valid_function = False
for vm_name, vm_details in six.iteritems(vms):
if not names:
break
Expand All @@ -1462,6 +1464,14 @@ def do_action(self, names, kwargs):
)
)
continue

# Build the dictionary of invalid functions with their associated VMs.
if valid_function is False:
if invalid_functions.get(fun) is None:
invalid_functions.update({fun: []})
invalid_functions[fun].append(vm_name)
continue

with context.func_globals_inject(
self.clouds[fun],
__active_provider_name__=':'.join([alias, driver])
Expand All @@ -1488,10 +1498,33 @@ def do_action(self, names, kwargs):
)
names.remove(vm_name)

# Set the return information for the VMs listed in the invalid_functions dict.
missing_vms = set()
if invalid_functions:
ret['Invalid Actions'] = invalid_functions
invalid_func_vms = set()
for key, val in six.iteritems(invalid_functions):
invalid_func_vms = invalid_func_vms.union(set(val))

# Find the VMs that are in names, but not in set of invalid functions.
missing_vms = names.difference(invalid_func_vms)
if missing_vms:
ret['Not Found'] = list(missing_vms)
ret['Not Actioned/Not Running'] = list(names)

if not names:
return ret

# Don't return missing VM information for invalid functions until after we've had a
# Chance to return successful actions. If a function is valid for one driver, but
# Not another, we want to make sure the successful action is returned properly.
if missing_vms:
return ret

# If we reach this point, the Not Actioned and Not Found lists will be the same,
# But we want to list both for clarity/consistency with the invalid functions lists.
ret['Not Actioned/Not Running'] = list(names)
ret['Not Found'] = list(names)
return ret

def do_function(self, prov, func, kwargs):
Expand Down Expand Up @@ -2325,5 +2358,3 @@ def _destroy_multiprocessing(*args, **kw):

def _create_multiprocessing(*args, **kw):
return communicator(create_multiprocessing)(*args[0], **kw)

#

0 comments on commit 6fa952f

Please sign in to comment.