Provide helpful error when using actions with a mapfile

Fixes #22699
This commit is contained in:
rallytime 2015-07-28 16:10:37 -06:00
parent 823f0ce350
commit f91edf3a33
2 changed files with 16 additions and 6 deletions

View File

@ -1632,11 +1632,18 @@ class Map(Cloud):
for alias, drivers in query_map.items():
for driver, vms in drivers.items():
for vm_name, vm_details in vms.items():
if (vm_details != 'Absent') and \
(
vm_details['state'].lower() in
matching_states[action]
):
# Only certain actions are support in to use in this case. Those actions are the
# "Global" salt-cloud actions defined in the "matching_states" dictionary above.
# If a more specific action is passed in, we shouldn't stack-trace - exit gracefully.
try:
state_action = matching_states[action]
except KeyError:
log.error(
'The use of \'{0}\' as an action is not supported in this context. '
'Only \'start\', \'stop\', and \'reboot\' are supported options.'.format(action)
)
raise SaltCloudException()
if (vm_details != 'Absent') and (vm_details['state'].lower() in state_action):
vm_names.append(vm_name)
return vm_names

View File

@ -195,7 +195,10 @@ class SaltCloud(parsers.SaltCloudParser):
self.config.get('map', None)):
if self.config.get('map', None):
log.info('Applying map from {0!r}.'.format(self.config['map']))
names = mapper.get_vmnames_by_action(self.options.action)
try:
names = mapper.get_vmnames_by_action(self.options.action)
except SaltCloudException:
return []
else:
names = self.config.get('names', None)