#NEWLINE# def _scan_sr( session , sr_ref = None , max_attempts = 4 ) : #NEWLINE# #INDENT# if sr_ref : #NEWLINE# #INDENT# @ utils . synchronized ( ( 'sr-scan-' + sr_ref ) ) #NEWLINE# def do_scan( sr_ref ) : #NEWLINE# #INDENT# LOG . debug ( 'Scanning SR %s' , sr_ref ) #NEWLINE# attempt = 1 #NEWLINE# while True : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# return session . call_xenapi ( 'SR.scan' , sr_ref ) #NEWLINE# #UNINDENT# except session . XenAPI . Failure as exc : #NEWLINE# #INDENT# with excutils . save_and_reraise_exception ( ) as ctxt : #NEWLINE# #INDENT# if ( exc . details [ 0 ] == 'SR_BACKEND_FAILURE_40' ) : #NEWLINE# #INDENT# if ( attempt < max_attempts ) : #NEWLINE# #INDENT# ctxt . reraise = False #NEWLINE# LOG . warning ( _LW ( 'Retry SR scan due to error: %s' ) , exc ) #NEWLINE# greenthread . sleep ( ( 2 ** attempt ) ) #NEWLINE# attempt += 1 #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# do_scan ( sr_ref )