Merge pull request #25807 from rallytime/fix-22699

Provide helpful error when using actions with a mapfile
This commit is contained in:
Thomas S Hatch 2015-07-29 09:30:15 -06:00
commit 72b3633383
2 changed files with 17 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,11 @@ 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 as exc:
msg = 'There was an error actioning virtual machines.'
self.handle_exception(msg, exc)
else:
names = self.config.get('names', None)