#NEWLINE# def check_switch_credentials( credentials ) : #NEWLINE# #INDENT# 'Check switch credentials format is correct.' #NEWLINE# if ( not credentials ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# if ( not isinstance ( credentials , dict ) ) : #NEWLINE# #INDENT# raise exception . InvalidParameter ( ( 'credentials %s is not dict' % credentials ) ) #NEWLINE# #UNINDENT# for key in credentials : #NEWLINE# #INDENT# if ( key not in [ 'version' , 'community' ] ) : #NEWLINE# #INDENT# raise exception . InvalidParameter ( ( 'unrecognized key %s in credentials %s' % ( key , credentials ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# for key in [ 'version' , 'community' ] : #NEWLINE# #INDENT# if ( key not in credentials ) : #NEWLINE# #INDENT# raise exception . InvalidParameter ( ( 'there is no %s field in credentials %s' % ( key , credentials ) ) ) #NEWLINE# #UNINDENT# key_check_func_name = ( '_check_switch_credentials_%s' % key ) #NEWLINE# this_module = globals ( ) #NEWLINE# if ( key_check_func_name in this_module ) : #NEWLINE# #INDENT# this_module [ key_check_func_name ] ( credentials [ key ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# logging . debug ( 'function %s is not defined' , key_check_func_name )