diff --git a/saltcloud/cli.py b/saltcloud/cli.py index 6bcb3681..9031c6be 100644 --- a/saltcloud/cli.py +++ b/saltcloud/cli.py @@ -198,7 +198,7 @@ def run(self): self.config.get('map', None)): if self.config.get('map', None): log.info('Applying map from {0!r}.'.format(self.config['map'])) - names = mapper.delete_map(query='list_nodes') + names = mapper.get_vmnames_by_action(self.options.action) else: names = self.config.get('names', None) diff --git a/saltcloud/cloud.py b/saltcloud/cloud.py index be8439d7..fe570c40 100644 --- a/saltcloud/cloud.py +++ b/saltcloud/cloud.py @@ -923,6 +923,22 @@ def delete_map(self, query=None): query_map.pop(alias) return query_map + def get_vmnames_by_action(self, action): + query_map = self.interpolated_map("list_nodes") + matching_states = { + "start" : ["stopped"], + "stop" : ["running", "active"], + "reboot" : ["running", "active"], + } + vm_names = [] + for alias, drivers in query_map.iteritems(): + for driver, vms in drivers.iteritems(): + for vm_name, vm_details in vms.iteritems(): + if (vm_details != 'Absent') and \ + (vm_details['state'].lower() in matching_states[action]): + vm_names.append(vm_name) + return vm_names + def read(self): ''' Read in the specified map file and return the map structure