#NEWLINE# def _sysfs_parse( path , base_attr = None , stats = False , config = False , internals = False , options = False ) : #NEWLINE# #INDENT# "\n    Helper function for parsing BCache's SysFS interface\n    " #NEWLINE# result = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# intfs = __salt__ [ 'sysfs.interfaces' ] ( path ) #NEWLINE# del intfs [ 'w' ] #NEWLINE# binkeys = [ ] #NEWLINE# if internals : #NEWLINE# #INDENT# binkeys . extend ( [ 'inter_ro' , 'inter_rw' ] ) #NEWLINE# #UNINDENT# if config : #NEWLINE# #INDENT# binkeys . append ( 'config' ) #NEWLINE# #UNINDENT# if stats : #NEWLINE# #INDENT# binkeys . append ( 'stats' ) #NEWLINE# #UNINDENT# bintf = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for key in binkeys : #NEWLINE# #INDENT# bintf [ key ] = [ ] #NEWLINE# #UNINDENT# for intf in intfs [ 'r' ] : #NEWLINE# #INDENT# if intf . startswith ( 'internal' ) : #NEWLINE# #INDENT# key = 'inter_ro' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( 'stats' in intf ) : #NEWLINE# #INDENT# key = 'stats' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# key = 'inter_ro' #NEWLINE# #UNINDENT# #UNINDENT# if ( key in bintf ) : #NEWLINE# #INDENT# bintf [ key ] . append ( intf ) #NEWLINE# #UNINDENT# #UNINDENT# for intf in intfs [ 'rw' ] : #NEWLINE# #INDENT# if intf . startswith ( 'internal' ) : #NEWLINE# #INDENT# key = 'inter_rw' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# key = 'config' #NEWLINE# #UNINDENT# if ( key in bintf ) : #NEWLINE# #INDENT# bintf [ key ] . append ( bresult ) #NEWLINE# #UNINDENT# #UNINDENT# if ( base_attr is not None ) : #NEWLINE# #INDENT# for intf in bintf . keys ( ) : #NEWLINE# #INDENT# bintf [ intf ] = [ sintf for sintf in bintf [ intf ] if ( sintf not in base_attr ) ] #NEWLINE# #UNINDENT# bintf [ 'base' ] = base_attr #NEWLINE# #UNINDENT# mods = { #NEWLINE# #INDENT# 'stats' : [ 'internal/bset_tree_stats' , 'writeback_rate_debug' , 'metadata_written' , 'nbuckets' , 'written' , 'average_key_size' , 'btree_cache_size' ] , #NEWLINE# #UNINDENT# } #NEWLINE# for ( modt , modlist ) in mods . items ( ) : #NEWLINE# #INDENT# found = [ ] #NEWLINE# if ( modt not in bintf ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# for mod in modlist : #NEWLINE# #INDENT# for intflist in bintf . values ( ) : #NEWLINE# #INDENT# if ( mod in intflist ) : #NEWLINE# #INDENT# found . append ( mod ) #NEWLINE# intflist . remove ( mod ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# bintf [ modt ] += found #NEWLINE# #UNINDENT# bintflist = [ intf for iflist in bintf . values ( ) for intf in iflist ] #NEWLINE# result . update ( __salt__ [ 'sysfs.read' ] ( bintflist , path ) ) #NEWLINE# for strlist in ( 'writeback_rate_debug' , 'internal/bset_tree_stats' , 'priority_stats' ) : #NEWLINE# #INDENT# if ( strlist in result ) : #NEWLINE# #INDENT# listres = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for line in result [ strlist ] . split ( '\n' ) : #NEWLINE# #INDENT# ( key , val ) = line . split ( ':' , 1 ) #NEWLINE# val = val . strip ( ) #NEWLINE# try : #NEWLINE# #INDENT# val = int ( val ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# val = float ( val ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# listres [ key . strip ( ) ] = val #NEWLINE# #UNINDENT# result [ strlist ] = listres #NEWLINE# #UNINDENT# #UNINDENT# if ( not options ) : #NEWLINE# #INDENT# for sellist in ( 'cache_mode' , 'cache_replacement_policy' , 'errors' ) : #NEWLINE# #INDENT# if ( sellist in result ) : #NEWLINE# #INDENT# result [ sellist ] = re . search ( '\\[(.+)\\]' , result [ sellist ] ) . groups ( ) [ 0 ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for boolkey in ( 'running' , 'writeback_running' , 'congested' ) : #NEWLINE# #INDENT# if ( boolkey in result ) : #NEWLINE# #INDENT# result [ boolkey ] = bool ( result [ boolkey ] ) #NEWLINE# #UNINDENT# #UNINDENT# bresult = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for ( iftype , intflist ) in bintf . items ( ) : #NEWLINE# #INDENT# ifres = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for intf in intflist : #NEWLINE# #INDENT# if ( intf in result ) : #NEWLINE# #INDENT# ifres [ intf ] = result . pop ( intf ) #NEWLINE# #UNINDENT# #UNINDENT# if len ( ifres ) : #NEWLINE# #INDENT# bresult [ iftype ] = ifres #NEWLINE# #UNINDENT# #UNINDENT# return bresult