<s> '''<STR_LIT>''' <EOL> import logging <EOL> import traceback <EOL> log = logging . getLogger ( __name__ ) <EOL> def update ( name , params , ** kw ) : <EOL> '''<STR_LIT>''' <EOL> ret = { '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT:result>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' . format ( name , params ) } <EOL> _default = object ( ) <EOL> reg_obj = __salt__ [ '<STR_LIT>' . format ( name ) ] ( ) <EOL> reg = __salt__ [ '<STR_LIT>' ] ( name ) <EOL> sync = False <EOL> if params is None : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = { } <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> return ret <EOL> for param , value in params . items ( ) : <EOL> gparam = '<STR_LIT>' . format ( reg_obj [ '<STR_LIT>' ] , param ) <EOL> if reg . get ( gparam , _default ) != value : <EOL> sync = True <EOL> if sync : <EOL> try : <EOL> cret = __salt__ [ '<STR_LIT>' ] ( name , params ) <EOL> ret [ '<STR_LIT>' ] = cret <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> except Exception , ex : <EOL> trace = traceback . format_exc ( ) <EOL> ret [ '<STR_LIT>' ] = ( <EOL> '<STR_LIT>' . format ( <EOL> ex , trace ) ) <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> return ret <EOL> def toggle ( name , sls = None , slss = None , status = True ) : <EOL> if ( not sls ) and ( not slss ) : <EOL> return { '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT:result>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> if slss is None : <EOL> slss = [ ] <EOL> if sls and ( not sls in slss ) : <EOL> slss . append ( sls ) <EOL> return update ( name , dict ( [ ( a , status ) for a in slss ] ) ) <EOL> def present ( name , sls = None , slss = None , ** kw ) : <EOL> return toggle ( name , sls = sls , slss = slss , status = True ) <EOL> def absent ( name , sls = None , slss = None , ** kw ) : <EOL> return toggle ( name , sls = sls , slss = slss , status = False ) </s>
