#NEWLINE# def log( self , log_type = None , nlogs = None , skip = None , filter = None , interval = None , timeout = None , extra_qs = None ) : #NEWLINE# #INDENT# self . __set_api_key ( ) #NEWLINE# self . __clear_response ( ) #NEWLINE# if ( interval is None ) : #NEWLINE# #INDENT# interval = _job_query_interval #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# interval = float ( interval ) #NEWLINE# if ( interval < 0 ) : #NEWLINE# #INDENT# raise ValueError #NEWLINE# #UNINDENT# #UNINDENT# except ValueError : #NEWLINE# #INDENT# raise PanXapiError ( ( 'Invalid interval: %s' % interval ) ) #NEWLINE# #UNINDENT# if ( timeout is not None ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# timeout = int ( timeout ) #NEWLINE# if ( timeout < 0 ) : #NEWLINE# #INDENT# raise ValueError #NEWLINE# #UNINDENT# #UNINDENT# except ValueError : #NEWLINE# #INDENT# raise PanXapiError ( ( 'Invalid timeout: %s' % timeout ) ) #NEWLINE# #UNINDENT# #UNINDENT# query = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# query [ 'type' ] = 'log' #NEWLINE# query [ 'key' ] = self . api_key #NEWLINE# if ( log_type is not None ) : #NEWLINE# #INDENT# query [ 'log-type' ] = log_type #NEWLINE# #UNINDENT# if ( nlogs is not None ) : #NEWLINE# #INDENT# query [ 'nlogs' ] = nlogs #NEWLINE# #UNINDENT# if ( skip is not None ) : #NEWLINE# #INDENT# query [ 'skip' ] = skip #NEWLINE# #UNINDENT# if ( filter is not None ) : #NEWLINE# #INDENT# query [ 'query' ] = filter #NEWLINE# #UNINDENT# if ( extra_qs is not None ) : #NEWLINE# #INDENT# query = self . __merge_extra_qs ( query , extra_qs ) #NEWLINE# #UNINDENT# response = self . __api_request ( query ) #NEWLINE# if ( not response ) : #NEWLINE# #INDENT# raise PanXapiError ( self . status_detail ) #NEWLINE# #UNINDENT# if ( not self . __set_response ( response ) ) : #NEWLINE# #INDENT# raise PanXapiError ( self . status_detail ) #NEWLINE# #UNINDENT# job = self . element_root . find ( './result/job' ) #NEWLINE# if ( job is None ) : #NEWLINE# #INDENT# raise PanXapiError ( 'no job element in type=log response' ) #NEWLINE# #UNINDENT# query = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# query [ 'type' ] = 'log' #NEWLINE# query [ 'action' ] = 'get' #NEWLINE# query [ 'key' ] = self . api_key #NEWLINE# query [ 'job-id' ] = job . text #NEWLINE# self . _log ( DEBUG2 , 'log job: %s' , job . text ) #NEWLINE# start_time = time . time ( ) #NEWLINE# while True : #NEWLINE# #INDENT# response = self . __api_request ( query ) #NEWLINE# if ( not response ) : #NEWLINE# #INDENT# raise PanXapiError ( self . status_detail ) #NEWLINE# #UNINDENT# if ( not self . __set_response ( response ) ) : #NEWLINE# #INDENT# raise PanXapiError ( self . status_detail ) #NEWLINE# #UNINDENT# status = self . element_root . find ( './result/job/status' ) #NEWLINE# if ( status is None ) : #NEWLINE# #INDENT# raise PanXapiError ( ( 'no status element in ' + 'type=log&action=get response' ) ) #NEWLINE# #UNINDENT# if ( skip . text == 'FIN' ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# self . _log ( DEBUG2 , 'job %s status %s' , job . text , status . text ) #NEWLINE# if ( ( timeout is not None ) and ( timeout != 0 ) and ( time . time ( ) > ( start_time + timeout ) ) ) : #NEWLINE# #INDENT# raise PanXapiError ( ( 'timeout waiting for ' + ( 'job %s completion' % job . text ) ) ) #NEWLINE# #UNINDENT# self . _log ( DEBUG2 , 'sleep %.2f seconds' , interval ) #NEWLINE# time . sleep ( interval )