#NEWLINE# def run( self , msg ) : #NEWLINE# #INDENT# method = msg [ 'method' ] #NEWLINE# url = msg [ 'url' ] #NEWLINE# params = msg [ 'params' ] #NEWLINE# payload = msg [ 'data' ] #NEWLINE# reply = ET . Element ( 'reply' ) #NEWLINE# logging . debug ( ( '@%s %s' % ( method , url ) ) ) #NEWLINE# try : #NEWLINE# #INDENT# if ( method in [ 'GET' , 'DELETE' ] ) : #NEWLINE# #INDENT# method_func = eval ( ( 'requests.' + method . lower ( ) ) ) #NEWLINE# response = method_func ( url , headers = params , auth = self . auth ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( method in [ 'POST' , 'PUT' , 'PATCH' ] ) : #NEWLINE# #INDENT# method_func = eval ( ( 'requests.' + method . lower ( ) ) ) #NEWLINE# response = method_func ( url , data = json . dumps ( payload ) , headers = params , auth = self . auth ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# reply . text = ( 'Invalid Rest Method ' + method ) #NEWLINE# logging . error ( reply . text ) #NEWLINE# return reply #NEWLINE# #UNINDENT# #UNINDENT# msg = ( '@%s %s %s\n' % ( method , url , ( 'OK' if response . ok else 'ERROR' ) ) ) #NEWLINE# msg += ( ( 'Status Code: ' + str ( response . status_code ) ) + '\n' ) #NEWLINE# if response . content : #NEWLINE# #INDENT# msg += ( 'Content: ' + response . content ) #NEWLINE# #UNINDENT# #UNINDENT# except : #NEWLINE# #INDENT# logging . exception ( 'Restconf Request Aborted : ' ) #NEWLINE# msg = ( '@%s %s %s\n' % ( method , url , 'ABORTED' ) ) #NEWLINE# msg += ( 'Content: ' + 'Exception while running request, please verify' ) #NEWLINE# msg += 'device restconf ip, port, authentication parameters !!' #NEWLINE# #UNINDENT# reply . text = msg #NEWLINE# logging . debug ( msg ) #NEWLINE# return reply