<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import copy <EOL> import os <EOL> import collections <EOL> import logging <EOL> import tornado . gen <EOL> import salt . loader <EOL> import salt . fileclient <EOL> import salt . minion <EOL> import salt . crypt <EOL> import salt . transport <EOL> import salt . utils . url <EOL> import salt . utils . cache <EOL> from salt . exceptions import SaltClientError <EOL> from salt . template import compile_template <EOL> from salt . utils . dictupdate import merge <EOL> from salt . utils . odict import OrderedDict <EOL> from salt . version import __version__ <EOL> import salt . ext . six as six <EOL> log = logging . getLogger ( __name__ ) <EOL> def get_pillar ( opts , grains , minion_id , saltenv = None , ext = None , funcs = None , <EOL> pillar = None , pillarenv = None ) : <EOL> '''<STR_LIT>''' <EOL> ptype = { <EOL> '<STR_LIT>' : RemotePillar , <EOL> '<STR_LIT>' : Pillar <EOL> } . get ( opts [ '<STR_LIT>' ] , Pillar ) <EOL> log . debug ( '<STR_LIT>' ) <EOL> if opts [ '<STR_LIT>' ] : <EOL> log . info ( '<STR_LIT>' ) <EOL> log . debug ( '<STR_LIT>' . format ( ext ) ) <EOL> return PillarCache ( opts , grains , minion_id , saltenv , ext = ext , functions = funcs , <EOL> pillar = pillar , pillarenv = pillarenv ) <EOL> return ptype ( opts , grains , minion_id , saltenv , ext , functions = funcs , <EOL> pillar = pillar , pillarenv = pillarenv ) <EOL> def get_async_pillar ( opts , grains , minion_id , saltenv = None , ext = None , funcs = None , <EOL> pillar = None , pillarenv = None ) : <EOL> '''<STR_LIT>''' <EOL> ptype = { <EOL> '<STR_LIT>' : AsyncRemotePillar , <EOL> '<STR_LIT>' : AsyncPillar , <EOL> } . get ( opts [ '<STR_LIT>' ] , AsyncPillar ) <EOL> return ptype ( opts , grains , minion_id , saltenv , ext , functions = funcs , <EOL> pillar = pillar , pillarenv = pillarenv ) <EOL> class AsyncRemotePillar ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , opts , grains , minion_id , saltenv , ext = None , functions = None , <EOL> pillar = None , pillarenv = None ) : <EOL> self . opts = opts <EOL> self . opts [ '<STR_LIT>' ] = saltenv <EOL> self . ext = ext <EOL> self . grains = grains <EOL> self . minion_id = minion_id <EOL> self . channel = salt . transport . client . AsyncReqChannel . factory ( opts ) <EOL> if pillarenv is not None or '<STR_LIT>' not in self . opts : <EOL> self . opts [ '<STR_LIT>' ] = pillarenv <EOL> self . pillar_override = { } <EOL> if pillar is not None : <EOL> if isinstance ( pillar , dict ) : <EOL> self . pillar_override = pillar <EOL> else : <EOL> log . error ( '<STR_LIT>' ) <EOL> @ tornado . gen . coroutine <EOL> def compile_pillar ( self ) : <EOL> '''<STR_LIT>''' <EOL> load = { '<STR_LIT:id>' : self . minion_id , <EOL> '<STR_LIT>' : self . grains , <EOL> '<STR_LIT>' : self . opts [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : self . opts [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : self . pillar_override , <EOL> '<STR_LIT>' : '<STR_LIT:2>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> if self . ext : <EOL> load [ '<STR_LIT>' ] = self . ext <EOL> try : <EOL> ret_pillar = yield self . channel . crypted_transfer_decode_dictentry ( <EOL> load , <EOL> dictkey = '<STR_LIT>' , <EOL> ) <EOL> except : <EOL> log . exception ( '<STR_LIT>' ) <EOL> raise SaltClientError ( '<STR_LIT>' ) <EOL> if not isinstance ( ret_pillar , dict ) : <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( type ( ret_pillar ) . __name__ , ret_pillar ) <EOL> log . error ( msg ) <EOL> raise SaltClientError ( msg ) <EOL> raise tornado . gen . Return ( ret_pillar ) <EOL> class RemotePillar ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , opts , grains , minion_id , saltenv , ext = None , functions = None , <EOL> pillar = None , pillarenv = None ) : <EOL> self . opts = opts <EOL> self . opts [ '<STR_LIT>' ] = saltenv <EOL> self . ext = ext <EOL> self . grains = grains <EOL> self . minion_id = minion_id <EOL> self . channel = salt . transport . Channel . factory ( opts ) <EOL> if pillarenv is not None or '<STR_LIT>' not in self . opts : <EOL> self . opts [ '<STR_LIT>' ] = pillarenv <EOL> self . pillar_override = { } <EOL> if pillar is not None : <EOL> if isinstance ( pillar , dict ) : <EOL> self . pillar_override = pillar <EOL> else : <EOL> log . error ( '<STR_LIT>' ) <EOL> def compile_pillar ( self ) : <EOL> '''<STR_LIT>''' <EOL> load = { '<STR_LIT:id>' : self . minion_id , <EOL> '<STR_LIT>' : self . grains , <EOL> '<STR_LIT>' : self . opts [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : self . opts [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : self . pillar_override , <EOL> '<STR_LIT>' : '<STR_LIT:2>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> if self . ext : <EOL> load [ '<STR_LIT>' ] = self . ext <EOL> ret_pillar = self . channel . crypted_transfer_decode_dictentry ( load , <EOL> dictkey = '<STR_LIT>' , <EOL> ) <EOL> if not isinstance ( ret_pillar , dict ) : <EOL> log . error ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( type ( ret_pillar ) . __name__ , ret_pillar ) <EOL> ) <EOL> return { } <EOL> return ret_pillar <EOL> class PillarCache ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , opts , grains , minion_id , saltenv , ext = None , functions = None , <EOL> pillar = None , pillarenv = None ) : <EOL> self . opts = opts <EOL> self . grains = grains <EOL> self . minion_id = minion_id <EOL> self . ext = ext <EOL> self . functions = functions <EOL> self . pillar = pillar <EOL> self . pillarenv = pillarenv <EOL> if saltenv is None : <EOL> self . saltenv = '<STR_LIT>' <EOL> else : <EOL> self . saltenv = saltenv <EOL> self . cache = salt . utils . cache . CacheFactory . factory ( <EOL> self . opts [ '<STR_LIT>' ] , <EOL> self . opts [ '<STR_LIT>' ] , <EOL> minion_cache_path = self . _minion_cache_path ( minion_id ) ) <EOL> def _minion_cache_path ( self , minion_id ) : <EOL> '''<STR_LIT>''' <EOL> return os . path . join ( self . opts [ '<STR_LIT>' ] , '<STR_LIT>' , minion_id ) <EOL> def fetch_pillar ( self ) : <EOL> '''<STR_LIT>''' <EOL> log . debug ( '<STR_LIT>' . format ( self . ext ) ) <EOL> fresh_pillar = Pillar ( self . opts , <EOL> self . grains , <EOL> self . minion_id , <EOL> self . saltenv , <EOL> ext = self . ext , <EOL> functions = self . functions , <EOL> pillar = self . pillar , <EOL> pillarenv = self . pillarenv ) <EOL> return fresh_pillar . compile_pillar ( ) <EOL> def compile_pillar ( self , * args , ** kwargs ) : <EOL> log . debug ( '<STR_LIT>' . format ( self . minion_id , self . saltenv ) ) <EOL> log . debug ( '<STR_LIT>' . format ( self . cache . _dict ) ) <EOL> if self . minion_id in self . cache : <EOL> if self . saltenv in self . cache [ self . minion_id ] : <EOL> log . debug ( '<STR_LIT>' . format ( self . minion_id , self . saltenv ) ) <EOL> return self . cache [ self . minion_id ] [ self . saltenv ] <EOL> else : <EOL> fresh_pillar = self . fetch_pillar ( ) <EOL> self . cache [ self . minion_id ] [ self . saltenv ] = fresh_pillar <EOL> log . debug ( '<STR_LIT>' . format ( self . saltenv , self . minion_id ) ) <EOL> return fresh_pillar <EOL> else : <EOL> fresh_pillar = self . fetch_pillar ( ) <EOL> self . cache [ self . minion_id ] = { self . saltenv : fresh_pillar } <EOL> log . debug ( '<STR_LIT>' . format ( self . minion_id ) ) <EOL> log . debug ( '<STR_LIT>' . format ( self . cache . _dict ) ) <EOL> return fresh_pillar <EOL> class Pillar ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , opts , grains , minion_id , saltenv , ext = None , functions = None , <EOL> pillar = None , pillarenv = None ) : <EOL> self . minion_id = minion_id <EOL> self . actual_file_roots = opts [ '<STR_LIT>' ] <EOL> self . opts = self . __gen_opts ( opts , grains , saltenv = saltenv , ext = ext , pillarenv = pillarenv ) <EOL> self . client = salt . fileclient . get_file_client ( self . opts , True ) <EOL> if opts . get ( '<STR_LIT>' , '<STR_LIT>' ) == '<STR_LIT>' : <EOL> opts [ '<STR_LIT>' ] = grains <EOL> if functions is None : <EOL> utils = salt . loader . utils ( opts ) <EOL> if opts . get ( '<STR_LIT>' , '<STR_LIT>' ) == '<STR_LIT>' : <EOL> self . functions = salt . loader . minion_mods ( opts , utils = utils ) <EOL> else : <EOL> self . functions = salt . loader . minion_mods ( self . opts , utils = utils ) <EOL> else : <EOL> self . functions = functions <EOL> self . matcher = salt . minion . Matcher ( self . opts , self . functions ) <EOL> self . rend = salt . loader . render ( self . opts , self . functions ) <EOL> ext_pillar_opts = copy . deepcopy ( self . opts ) <EOL> ext_pillar_opts [ '<STR_LIT>' ] = self . actual_file_roots <EOL> if '<STR_LIT:id>' in opts : <EOL> ext_pillar_opts [ '<STR_LIT:id>' ] = opts [ '<STR_LIT:id>' ] <EOL> self . merge_strategy = '<STR_LIT>' <EOL> if opts . get ( '<STR_LIT>' ) : <EOL> self . merge_strategy = opts [ '<STR_LIT>' ] <EOL> self . ext_pillars = salt . loader . pillars ( ext_pillar_opts , self . functions ) <EOL> self . ignored_pillars = { } <EOL> self . pillar_override = { } <EOL> if pillar is not None : <EOL> if isinstance ( pillar , dict ) : <EOL> self . pillar_override = pillar <EOL> else : <EOL> log . error ( '<STR_LIT>' ) <EOL> def __valid_ext ( self , ext ) : <EOL> '''<STR_LIT>''' <EOL> if not isinstance ( ext , dict ) : <EOL> return { } <EOL> valid = set ( ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if any ( key not in valid for key in ext ) : <EOL> return { } <EOL> return ext <EOL> def __gen_opts ( self , opts_in , grains , saltenv = None , ext = None , pillarenv = None ) : <EOL> '''<STR_LIT>''' <EOL> opts = copy . deepcopy ( opts_in ) <EOL> opts [ '<STR_LIT>' ] = opts [ '<STR_LIT>' ] <EOL> opts [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if not grains : <EOL> opts [ '<STR_LIT>' ] = { } <EOL> else : <EOL> opts [ '<STR_LIT>' ] = grains <EOL> if '<STR_LIT>' not in opts : <EOL> opts [ '<STR_LIT>' ] = saltenv <EOL> opts [ '<STR_LIT:id>' ] = self . minion_id <EOL> if '<STR_LIT>' not in opts : <EOL> opts [ '<STR_LIT>' ] = pillarenv <EOL> if opts [ '<STR_LIT>' ] . startswith ( '<STR_LIT>' ) : <EOL> opts [ '<STR_LIT>' ] = opts [ '<STR_LIT>' ] <EOL> elif opts [ '<STR_LIT>' ] . startswith ( '<STR_LIT:/>' ) : <EOL> opts [ '<STR_LIT>' ] = salt . utils . url . create ( opts [ '<STR_LIT>' ] [ <NUM_LIT:1> : ] ) <EOL> else : <EOL> opts [ '<STR_LIT>' ] = salt . utils . url . create ( opts [ '<STR_LIT>' ] ) <EOL> if self . __valid_ext ( ext ) : <EOL> if '<STR_LIT>' in opts : <EOL> opts [ '<STR_LIT>' ] . append ( ext ) <EOL> else : <EOL> opts [ '<STR_LIT>' ] = [ ext ] <EOL> return opts <EOL> def _get_envs ( self ) : <EOL> '''<STR_LIT>''' <EOL> envs = set ( [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in self . opts : <EOL> envs . update ( list ( self . opts [ '<STR_LIT>' ] ) ) <EOL> return envs <EOL> def get_tops ( self ) : <EOL> '''<STR_LIT>''' <EOL> tops = collections . defaultdict ( list ) <EOL> include = collections . defaultdict ( list ) <EOL> done = collections . defaultdict ( list ) <EOL> errors = [ ] <EOL> try : <EOL> if self . opts [ '<STR_LIT>' ] : <EOL> tops [ self . opts [ '<STR_LIT>' ] ] = [ <EOL> compile_template ( <EOL> self . client . cache_file ( <EOL> self . opts [ '<STR_LIT>' ] , <EOL> self . opts [ '<STR_LIT>' ] <EOL> ) , <EOL> self . rend , <EOL> self . opts [ '<STR_LIT>' ] , <EOL> self . opts [ '<STR_LIT>' ] , <EOL> _pillar_rend = True <EOL> ) <EOL> ] <EOL> else : <EOL> for saltenv in self . _get_envs ( ) : <EOL> top = self . client . cache_file ( <EOL> self . opts [ '<STR_LIT>' ] , <EOL> saltenv <EOL> ) <EOL> if top : <EOL> tops [ saltenv ] . append ( <EOL> compile_template ( <EOL> top , <EOL> self . rend , <EOL> self . opts [ '<STR_LIT>' ] , <EOL> saltenv = saltenv , <EOL> _pillar_rend = True <EOL> ) <EOL> ) <EOL> except Exception as exc : <EOL> errors . append ( <EOL> ( '<STR_LIT>' <EOL> . format ( exc ) ) ) <EOL> log . error ( '<STR_LIT>' . format ( self . minion_id ) , <EOL> exc_info = True ) <EOL> for saltenv , ctops in six . iteritems ( tops ) : <EOL> for ctop in ctops : <EOL> if '<STR_LIT>' not in ctop : <EOL> continue <EOL> for sls in ctop [ '<STR_LIT>' ] : <EOL> include [ saltenv ] . append ( sls ) <EOL> ctop . pop ( '<STR_LIT>' ) <EOL> while include : <EOL> pops = [ ] <EOL> for saltenv , states in six . iteritems ( include ) : <EOL> pops . append ( saltenv ) <EOL> if not states : <EOL> continue <EOL> for sls in states : <EOL> if sls in done [ saltenv ] : <EOL> continue <EOL> try : <EOL> tops [ saltenv ] . append ( <EOL> compile_template ( <EOL> self . client . get_state ( <EOL> sls , <EOL> saltenv <EOL> ) . get ( '<STR_LIT>' , False ) , <EOL> self . rend , <EOL> self . opts [ '<STR_LIT>' ] , <EOL> saltenv = saltenv , <EOL> _pillar_rend = True <EOL> ) <EOL> ) <EOL> except Exception as exc : <EOL> errors . append ( <EOL> ( '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( sls , exc ) ) <EOL> done [ saltenv ] . append ( sls ) <EOL> for saltenv in pops : <EOL> if saltenv in include : <EOL> include . pop ( saltenv ) <EOL> return tops , errors <EOL> def merge_tops ( self , tops ) : <EOL> '''<STR_LIT>''' <EOL> top = collections . defaultdict ( OrderedDict ) <EOL> orders = collections . defaultdict ( OrderedDict ) <EOL> for ctops in six . itervalues ( tops ) : <EOL> for ctop in ctops : <EOL> for saltenv , targets in six . iteritems ( ctop ) : <EOL> if saltenv == '<STR_LIT>' : <EOL> continue <EOL> for tgt in targets : <EOL> matches = [ ] <EOL> states = OrderedDict ( ) <EOL> orders [ saltenv ] [ tgt ] = <NUM_LIT:0> <EOL> ignore_missing = False <EOL> for comp in ctop [ saltenv ] [ tgt ] : <EOL> if isinstance ( comp , dict ) : <EOL> if '<STR_LIT>' in comp : <EOL> matches . append ( comp ) <EOL> if '<STR_LIT>' in comp : <EOL> order = comp [ '<STR_LIT>' ] <EOL> if not isinstance ( order , int ) : <EOL> try : <EOL> order = int ( order ) <EOL> except ValueError : <EOL> order = <NUM_LIT:0> <EOL> orders [ saltenv ] [ tgt ] = order <EOL> if comp . get ( '<STR_LIT>' , False ) : <EOL> ignore_missing = True <EOL> if isinstance ( comp , six . string_types ) : <EOL> states [ comp ] = True <EOL> if ignore_missing : <EOL> if saltenv not in self . ignored_pillars : <EOL> self . ignored_pillars [ saltenv ] = [ ] <EOL> self . ignored_pillars [ saltenv ] . extend ( states . keys ( ) ) <EOL> top [ saltenv ] [ tgt ] = matches <EOL> top [ saltenv ] [ tgt ] . extend ( states ) <EOL> return self . sort_top_targets ( top , orders ) <EOL> def sort_top_targets ( self , top , orders ) : <EOL> '''<STR_LIT>''' <EOL> sorted_top = collections . defaultdict ( OrderedDict ) <EOL> for saltenv , targets in six . iteritems ( top ) : <EOL> sorted_targets = sorted ( targets , <EOL> key = lambda target : orders [ saltenv ] [ target ] ) <EOL> for target in sorted_targets : <EOL> sorted_top [ saltenv ] [ target ] = targets [ target ] <EOL> return sorted_top <EOL> def get_top ( self ) : <EOL> '''<STR_LIT>''' <EOL> tops , errors = self . get_tops ( ) <EOL> try : <EOL> merged_tops = self . merge_tops ( tops ) <EOL> except TypeError as err : <EOL> merged_tops = OrderedDict ( ) <EOL> errors . append ( '<STR_LIT>' ) <EOL> return merged_tops , errors <EOL> def top_matches ( self , top ) : <EOL> '''<STR_LIT>''' <EOL> matches = { } <EOL> for saltenv , body in six . iteritems ( top ) : <EOL> if self . opts [ '<STR_LIT>' ] : <EOL> if saltenv != self . opts [ '<STR_LIT>' ] : <EOL> continue <EOL> for match , data in six . iteritems ( body ) : <EOL> if self . matcher . confirm_top ( <EOL> match , <EOL> data , <EOL> self . opts . get ( '<STR_LIT>' , { } ) , <EOL> ) : <EOL> if saltenv not in matches : <EOL> matches [ saltenv ] = env_matches = [ ] <EOL> else : <EOL> env_matches = matches [ saltenv ] <EOL> for item in data : <EOL> if isinstance ( item , six . string_types ) and item not in env_matches : <EOL> env_matches . append ( item ) <EOL> return matches <EOL> def render_pstate ( self , sls , saltenv , mods , defaults = None ) : <EOL> '''<STR_LIT>''' <EOL> if defaults is None : <EOL> defaults = { } <EOL> err = '<STR_LIT>' <EOL> errors = [ ] <EOL> fn_ = self . client . get_state ( sls , saltenv ) . get ( '<STR_LIT>' , False ) <EOL> if not fn_ : <EOL> if sls in self . ignored_pillars . get ( saltenv , [ ] ) : <EOL> log . debug ( '<STR_LIT>' <EOL> '<STR_LIT>' . format ( sls , saltenv ) ) <EOL> return None , mods , errors <EOL> elif self . opts [ '<STR_LIT>' ] . get ( saltenv ) : <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( sls , saltenv ) <EOL> log . error ( msg ) <EOL> errors . append ( msg ) <EOL> else : <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' . format ( sls , saltenv ) ) <EOL> if self . opts . get ( '<STR_LIT>' , False ) is True : <EOL> msg += ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> else : <EOL> msg += ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( sls , saltenv ) <EOL> ) <EOL> log . debug ( msg ) <EOL> return None , mods , errors <EOL> state = None <EOL> try : <EOL> state = compile_template ( fn_ , <EOL> self . rend , <EOL> self . opts [ '<STR_LIT>' ] , <EOL> saltenv , <EOL> sls , <EOL> _pillar_rend = True , <EOL> ** defaults ) <EOL> except Exception as exc : <EOL> msg = '<STR_LIT>' . format ( <EOL> sls , exc <EOL> ) <EOL> log . critical ( msg ) <EOL> if self . opts . get ( '<STR_LIT>' , True ) : <EOL> errors . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( sls ) <EOL> ) <EOL> else : <EOL> errors . append ( msg ) <EOL> mods . add ( sls ) <EOL> nstate = None <EOL> if state : <EOL> if not isinstance ( state , dict ) : <EOL> msg = '<STR_LIT>' . format ( sls ) <EOL> log . error ( msg ) <EOL> errors . append ( msg ) <EOL> else : <EOL> if '<STR_LIT>' in state : <EOL> if not isinstance ( state [ '<STR_LIT>' ] , list ) : <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' . format ( sls ) ) <EOL> log . error ( msg ) <EOL> errors . append ( msg ) <EOL> else : <EOL> for sub_sls in state . pop ( '<STR_LIT>' ) : <EOL> if isinstance ( sub_sls , dict ) : <EOL> sub_sls , v = next ( six . iteritems ( sub_sls ) ) <EOL> defaults = v . get ( '<STR_LIT>' , { } ) <EOL> key = v . get ( '<STR_LIT:key>' , None ) <EOL> else : <EOL> key = None <EOL> if sub_sls not in mods : <EOL> nstate , mods , err = self . render_pstate ( <EOL> sub_sls , <EOL> saltenv , <EOL> mods , <EOL> defaults <EOL> ) <EOL> if nstate : <EOL> if key : <EOL> nstate = { <EOL> key : nstate <EOL> } <EOL> state = merge ( <EOL> state , <EOL> nstate , <EOL> self . merge_strategy , <EOL> self . opts . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> self . opts . get ( '<STR_LIT>' , False ) ) <EOL> if err : <EOL> errors += err <EOL> return state , mods , errors <EOL> def render_pillar ( self , matches , errors = None ) : <EOL> '''<STR_LIT>''' <EOL> pillar = copy . copy ( self . pillar_override ) <EOL> if errors is None : <EOL> errors = [ ] <EOL> for saltenv , pstates in six . iteritems ( matches ) : <EOL> mods = set ( ) <EOL> for sls in pstates : <EOL> pstate , mods , err = self . render_pstate ( sls , saltenv , mods ) <EOL> if err : <EOL> errors += err <EOL> if pstate is not None : <EOL> if not isinstance ( pstate , dict ) : <EOL> log . error ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( <EOL> sls , <EOL> '<STR_LIT:U+002CU+0020>' . join ( <EOL> [ '<STR_LIT>' . format ( e ) for e in errors ] <EOL> ) <EOL> ) <EOL> ) <EOL> continue <EOL> pillar = merge ( <EOL> pillar , <EOL> pstate , <EOL> self . merge_strategy , <EOL> self . opts . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> self . opts . get ( '<STR_LIT>' , False ) ) <EOL> return pillar , errors <EOL> def _external_pillar_data ( self , pillar , val , pillar_dirs , key ) : <EOL> '''<STR_LIT>''' <EOL> ext = None <EOL> if isinstance ( val , dict ) : <EOL> ext = self . ext_pillars [ key ] ( self . minion_id , pillar , ** val ) <EOL> elif isinstance ( val , list ) : <EOL> if key == '<STR_LIT>' : <EOL> ext = self . ext_pillars [ key ] ( self . minion_id , <EOL> val , <EOL> pillar_dirs ) <EOL> else : <EOL> ext = self . ext_pillars [ key ] ( self . minion_id , <EOL> pillar , <EOL> * val ) <EOL> else : <EOL> if key == '<STR_LIT>' : <EOL> ext = self . ext_pillars [ key ] ( self . minion_id , <EOL> val , <EOL> pillar_dirs ) <EOL> else : <EOL> ext = self . ext_pillars [ key ] ( self . minion_id , <EOL> pillar , <EOL> val ) <EOL> return ext <EOL> def ext_pillar ( self , pillar , pillar_dirs , errors = None ) : <EOL> '''<STR_LIT>''' <EOL> if errors is None : <EOL> errors = [ ] <EOL> if '<STR_LIT>' not in self . opts : <EOL> return pillar , errors <EOL> if not isinstance ( self . opts [ '<STR_LIT>' ] , list ) : <EOL> errors . append ( '<STR_LIT>' ) <EOL> log . critical ( errors [ - <NUM_LIT:1> ] ) <EOL> return pillar , errors <EOL> ext = None <EOL> if self . pillar_override and isinstance ( self . pillar_override , dict ) : <EOL> pillar = merge ( pillar , <EOL> self . pillar_override , <EOL> self . merge_strategy , <EOL> self . opts . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> self . opts . get ( '<STR_LIT>' , False ) ) <EOL> for run in self . opts [ '<STR_LIT>' ] : <EOL> if not isinstance ( run , dict ) : <EOL> errors . append ( '<STR_LIT>' ) <EOL> log . critical ( errors [ - <NUM_LIT:1> ] ) <EOL> return { } , errors <EOL> if run . keys ( ) [ <NUM_LIT:0> ] in self . opts . get ( '<STR_LIT>' , [ ] ) : <EOL> continue <EOL> for key , val in six . iteritems ( run ) : <EOL> if key not in self . ext_pillars : <EOL> log . critical ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( key ) <EOL> ) <EOL> continue <EOL> try : <EOL> ext = self . _external_pillar_data ( pillar , <EOL> val , <EOL> pillar_dirs , <EOL> key ) <EOL> except Exception as exc : <EOL> errors . append ( '<STR_LIT>' . format ( <EOL> key , exc ) ) <EOL> if ext : <EOL> pillar = merge ( <EOL> pillar , <EOL> ext , <EOL> self . merge_strategy , <EOL> self . opts . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> self . opts . get ( '<STR_LIT>' , False ) ) <EOL> ext = None <EOL> return pillar , errors <EOL> def compile_pillar ( self , ext = True , pillar_dirs = None ) : <EOL> '''<STR_LIT>''' <EOL> top , top_errors = self . get_top ( ) <EOL> if ext : <EOL> if self . opts . get ( '<STR_LIT>' , False ) or self . opts . get ( '<STR_LIT>' , False ) : <EOL> salt . utils . warn_until ( '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> self . opts [ '<STR_LIT>' ] , errors = self . ext_pillar ( { } , pillar_dirs ) <EOL> matches = self . top_matches ( top ) <EOL> pillar , errors = self . render_pillar ( matches , errors = errors ) <EOL> if self . opts . get ( '<STR_LIT>' , False ) : <EOL> pillar = merge ( self . opts [ '<STR_LIT>' ] , <EOL> pillar , <EOL> self . merge_strategy , <EOL> self . opts . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> self . opts . get ( '<STR_LIT>' , False ) ) <EOL> else : <EOL> pillar = merge ( pillar , <EOL> self . opts [ '<STR_LIT>' ] , <EOL> self . merge_strategy , <EOL> self . opts . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> self . opts . get ( '<STR_LIT>' , False ) ) <EOL> else : <EOL> matches = self . top_matches ( top ) <EOL> pillar , errors = self . render_pillar ( matches ) <EOL> pillar , errors = self . ext_pillar ( <EOL> pillar , pillar_dirs , errors = errors ) <EOL> else : <EOL> matches = self . top_matches ( top ) <EOL> pillar , errors = self . render_pillar ( matches ) <EOL> errors . extend ( top_errors ) <EOL> if self . opts . get ( '<STR_LIT>' , False ) : <EOL> mopts = dict ( self . opts ) <EOL> if '<STR_LIT>' in mopts : <EOL> mopts . pop ( '<STR_LIT>' ) <EOL> mopts [ '<STR_LIT>' ] = self . actual_file_roots <EOL> mopts [ '<STR_LIT>' ] = __version__ <EOL> pillar [ '<STR_LIT>' ] = mopts <EOL> if errors : <EOL> for error in errors : <EOL> log . critical ( '<STR_LIT>' . format ( error ) ) <EOL> pillar [ '<STR_LIT>' ] = errors <EOL> if self . pillar_override and isinstance ( self . pillar_override , dict ) : <EOL> pillar = merge ( pillar , <EOL> self . pillar_override , <EOL> self . merge_strategy , <EOL> self . opts . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> self . opts . get ( '<STR_LIT>' , False ) ) <EOL> return pillar <EOL> class AsyncPillar ( Pillar ) : <EOL> @ tornado . gen . coroutine <EOL> def compile_pillar ( self , ext = True , pillar_dirs = None ) : <EOL> ret = super ( AsyncPillar , self ) . compile_pillar ( ext = ext , pillar_dirs = pillar_dirs ) <EOL> raise tornado . gen . Return ( ret ) </s>
