#NEWLINE# def _check_compound_minions( self , expr , delimiter , greedy , pillar_exact = False ) : #NEWLINE# #INDENT# '\n        Return the minions found by looking via compound matcher\n        ' #NEWLINE# log . debug ( '_check_compound_minions({0}, {1}, {2}, {3})' . format ( expr , delimiter , greedy , pillar_exact ) ) #NEWLINE# if ( ( not isinstance ( expr , six . string_types ) ) and ( not isinstance ( expr , ( list , tuple ) ) ) ) : #NEWLINE# #INDENT# log . error ( 'Compound target that is neither string, list nor tuple' ) #NEWLINE# return [ ] #NEWLINE# #UNINDENT# mlist = [ ] #NEWLINE# for fn_ in salt . utils . isorted ( os . listdir ( os . path . join ( self . opts [ 'pki_dir' ] , self . acc ) ) ) : #NEWLINE# #INDENT# if ( ( not fn_ . startswith ( '.' ) ) and os . path . isfile ( os . path . join ( self . opts [ 'pki_dir' ] , self . acc , fn_ ) ) ) : #NEWLINE# #INDENT# mlist . append ( fn_ ) #NEWLINE# #UNINDENT# #UNINDENT# minions = set ( mlist ) #NEWLINE# log . debug ( 'minions: {0}' . format ( minions ) ) #NEWLINE# if self . opts . get ( 'minion_data_cache' , False ) : #NEWLINE# #INDENT# ref = { #NEWLINE# #INDENT# 'G' : self . _check_grain_minions , #NEWLINE# 'P' : self . _check_grain_pcre_minions , #NEWLINE# 'I' : self . _check_pillar_minions , #NEWLINE# 'J' : self . _check_pillar_pcre_minions , #NEWLINE# 'L' : self . _check_list_minions , #NEWLINE# 'N' : None , #NEWLINE# 'S' : self . _check_ipcidr_minions , #NEWLINE# 'E' : self . _check_pcre_minions , #NEWLINE# 'R' : self . _all_minions , #NEWLINE# #UNINDENT# } #NEWLINE# if pillar_exact : #NEWLINE# #INDENT# ref [ 'I' ] = self . _check_pillar_exact_minions #NEWLINE# ref [ 'J' ] = self . _check_pillar_exact_minions #NEWLINE# #UNINDENT# results = [ ] #NEWLINE# unmatched = [ ] #NEWLINE# opers = [ 'and' , 'or' , 'not' , '(' , ')' ] #NEWLINE# if isinstance ( expr , six . string_types ) : #NEWLINE# #INDENT# words = expr . split ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# words = expr #NEWLINE# #UNINDENT# for word in words : #NEWLINE# #INDENT# target_info = parse_target ( word ) #NEWLINE# if ( word in opers ) : #NEWLINE# #INDENT# if results : #NEWLINE# #INDENT# if ( ( results [ ( - 1 ) ] == '(' ) and ( word in ( 'and' , 'or' ) ) ) : #NEWLINE# #INDENT# log . error ( 'Invalid beginning operator after "(": {0}' . format ( word ) ) #NEWLINE# return [ ] #NEWLINE# #UNINDENT# if ( word == 'not' ) : #NEWLINE# #INDENT# if ( not ( results [ ( - 1 ) ] in ( '&' , '|' , '(' ) ) ) : #NEWLINE# #INDENT# results . append ( '&' ) #NEWLINE# #UNINDENT# results . append ( '(' ) #NEWLINE# results . append ( str ( set ( minions ) ) ) #NEWLINE# results . append ( '-' ) #NEWLINE# unmatched . append ( '-' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( word == 'and' ) : #NEWLINE# #INDENT# results . append ( '&' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( word == 'or' ) : #NEWLINE# #INDENT# results . append ( '|' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( word == '(' ) : #NEWLINE# #INDENT# results . append ( word ) #NEWLINE# unmatched . append ( word ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( word == ')' ) : #NEWLINE# #INDENT# if ( ( not unmatched ) or ( unmatched [ ( - 1 ) ] != '(' ) ) : #NEWLINE# #INDENT# log . error ( 'Invalid compound expr (unexpected right parenthesis): {0}' . format ( expr ) ) #NEWLINE# return [ ] #NEWLINE# #UNINDENT# results . append ( word ) #NEWLINE# unmatched . pop ( ) #NEWLINE# if ( unmatched and ( unmatched [ ( - 1 ) ] == '-' ) ) : #NEWLINE# #INDENT# results . append ( ')' ) #NEWLINE# unmatched . pop ( ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# log . error ( 'Unhandled oper in compound expr: {0}' . format ( expr ) ) #NEWLINE# return [ ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( word == 'not' ) : #NEWLINE# #INDENT# results . append ( '(' ) #NEWLINE# results . append ( str ( set ( minions ) ) ) #NEWLINE# results . append ( '-' ) #NEWLINE# unmatched . append ( '-' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( word == '(' ) : #NEWLINE# #INDENT# results . append ( word ) #NEWLINE# unmatched . append ( word ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# log . error ( 'Expression may begin with binary operator: {0}' . format ( word ) ) #NEWLINE# return [ ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( target_info and target_info [ 'engine' ] ) : #NEWLINE# #INDENT# if ( 'N' == target_info [ 'engine' ] ) : #NEWLINE# #INDENT# log . error ( 'Detected nodegroup expansion failure of "{0}"' . format ( word ) ) #NEWLINE# return [ ] #NEWLINE# #UNINDENT# engine = ref . get ( target_info [ 'engine' ] ) #NEWLINE# if ( not engine ) : #NEWLINE# #INDENT# log . error ( 'Unrecognized target engine "{0}" for target expression "{1}"' . format ( target_info [ 'engine' ] , word ) ) #NEWLINE# return [ ] #NEWLINE# #UNINDENT# engine_args = [ target_info [ 'pattern' ] ] #NEWLINE# if ( target_info [ 'engine' ] in ( 'G' , 'P' , 'I' , 'J' ) ) : #NEWLINE# #INDENT# engine_args . append ( ( target_info [ 'delimiter' ] or ':' ) ) #NEWLINE# #UNINDENT# engine_args . append ( True ) #NEWLINE# results . append ( str ( set ( engine ( * engine_args ) ) ) ) #NEWLINE# if ( unmatched and ( unmatched [ ( - 1 ) ] == '-' ) ) : #NEWLINE# #INDENT# results . append ( ')' ) #NEWLINE# unmatched . pop ( ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# results . append ( str ( set ( self . _check_glob_minions ( word , True ) ) ) ) #NEWLINE# if ( unmatched and ( unmatched [ ( - 1 ) ] == '-' ) ) : #NEWLINE# #INDENT# results . append ( ')' ) #NEWLINE# unmatched . pop ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# results . extend ( [ ')' for item in unmatched ] ) #NEWLINE# results = ' ' . join ( results ) #NEWLINE# log . debug ( 'Evaluating final compound matching expr: {0}' . format ( results ) ) #NEWLINE# try : #NEWLINE# #INDENT# return list ( eval ( results ) ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# log . error ( 'Invalid compound target: {0}' . format ( expr ) ) #NEWLINE# return [ ] #NEWLINE# #UNINDENT# #UNINDENT# return list ( minions )