Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

Commit

Permalink
Add get_vmnames_by_action in cloud.py Map, used for getting available…
Browse files Browse the repository at this point in the history
… vmnames from map file, call get_vmnames_by_action when use action option in cli with map file.
  • Loading branch information
wangqiang8511 committed Nov 7, 2013
1 parent d37fdb0 commit fc4935b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion saltcloud/cli.py
Expand Up @@ -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)

Expand Down
16 changes: 16 additions & 0 deletions saltcloud/cloud.py
Expand Up @@ -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
Expand Down

0 comments on commit fc4935b

Please sign in to comment.