<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import logging <EOL> import salt . utils <EOL> log = logging . getLogger ( __name__ ) <EOL> def __virtual__ ( ) : <EOL> '''<STR_LIT>''' <EOL> if __grains__ [ '<STR_LIT>' ] == '<STR_LIT>' and salt . utils . which ( '<STR_LIT>' ) : <EOL> return '<STR_LIT>' <EOL> return ( False , '<STR_LIT>' ) <EOL> def exec_action ( module , action , module_parameter = None , action_parameter = None , state_only = False ) : <EOL> '''<STR_LIT>''' <EOL> out = __salt__ [ '<STR_LIT>' ] ( <EOL> '<STR_LIT>' . format ( <EOL> module , module_parameter or '<STR_LIT>' , action , action_parameter or '<STR_LIT>' ) , <EOL> python_shell = False <EOL> ) <EOL> out = out . strip ( ) . split ( '<STR_LIT:\n>' ) <EOL> if out [ <NUM_LIT:0> ] . startswith ( '<STR_LIT>' ) : <EOL> return False <EOL> if state_only : <EOL> return True <EOL> if len ( out ) < <NUM_LIT:1> : <EOL> return False <EOL> if len ( out ) == <NUM_LIT:1> and not out [ <NUM_LIT:0> ] . strip ( ) : <EOL> return False <EOL> return out <EOL> def get_modules ( ) : <EOL> '''<STR_LIT>''' <EOL> modules = [ ] <EOL> module_list = exec_action ( '<STR_LIT>' , '<STR_LIT:list>' , action_parameter = '<STR_LIT>' ) <EOL> if not module_list : <EOL> return None <EOL> for module in module_list : <EOL> if module not in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:version>' ] : <EOL> modules . append ( module ) <EOL> return modules <EOL> def get_target_list ( module ) : <EOL> '''<STR_LIT>''' <EOL> exec_output = exec_action ( module , '<STR_LIT:list>' ) <EOL> if not exec_output : <EOL> return None <EOL> target_list = [ ] <EOL> if isinstance ( exec_output , list ) : <EOL> for item in exec_output : <EOL> target_list . append ( item . split ( None , <NUM_LIT:1> ) [ <NUM_LIT:0> ] ) <EOL> return target_list <EOL> return None <EOL> def get_current_target ( module , module_parameter = None , action_parameter = None ) : <EOL> '''<STR_LIT>''' <EOL> result = exec_action ( module , '<STR_LIT>' , module_parameter = module_parameter , action_parameter = action_parameter ) [ <NUM_LIT:0> ] <EOL> if not result : <EOL> return None <EOL> if result == '<STR_LIT>' : <EOL> return None <EOL> return result <EOL> def set_target ( module , target , module_parameter = None , action_parameter = None ) : <EOL> '''<STR_LIT>''' <EOL> if action_parameter : <EOL> action_parameter = '<STR_LIT>' . format ( action_parameter , target ) <EOL> else : <EOL> action_parameter = target <EOL> if module not in get_modules ( ) : <EOL> log . error ( '<STR_LIT>' . format ( module ) ) <EOL> return False <EOL> exec_result = exec_action ( module , '<STR_LIT>' , module_parameter = module_parameter , action_parameter = action_parameter , state_only = True ) <EOL> if exec_result : <EOL> return exec_result <EOL> return False </s>
