#NEWLINE# def _command( self , node , method , params , wait = False ) : #NEWLINE# #INDENT# url = self . _get_command_url ( node ) #NEWLINE# body = self . _get_command_body ( method , params ) #NEWLINE# request_params = { #NEWLINE# #INDENT# 'wait' : str ( wait ) . lower ( ) , #NEWLINE# #UNINDENT# } #NEWLINE# LOG . debug ( 'Executing agent command %(method)s for node %(node)s' , { #NEWLINE# #INDENT# 'node' : node . uuid , #NEWLINE# 'method' : method , #NEWLINE# #UNINDENT# } ) #NEWLINE# try : #NEWLINE# #INDENT# response = self . session . post ( url , params = request_params , data = body ) #NEWLINE# #UNINDENT# except requests . RequestException as e : #NEWLINE# #INDENT# msg = ( _ ( 'Error invoking agent command %(method)s for node %(node)s. Error: %(error)s' ) % { #NEWLINE# #INDENT# 'method' : method , #NEWLINE# 'node' : node . uuid , #NEWLINE# 'error' : e , #NEWLINE# #UNINDENT# } ) #NEWLINE# LOG . error ( msg ) #NEWLINE# raise exception . IronicException ( msg ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# result = response . json ( ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# msg = ( _ ( 'Unable to decode response as JSON.\nRequest URL: %(url)s\nRequest body: "%(body)s"\nResponse status code: %(code)s\nResponse: "%(response)s"' ) % { #NEWLINE# #INDENT# 'response' : response . text , #NEWLINE# 'body' : body , #NEWLINE# 'url' : url , #NEWLINE# 'code' : response . status_code , #NEWLINE# #UNINDENT# } ) #NEWLINE# LOG . error ( msg ) #NEWLINE# raise exception . IronicException ( msg ) #NEWLINE# #UNINDENT# LOG . debug ( 'Agent command %(method)s for node %(node)s returned result %(res)s, error %(error)s, HTTP status code %(code)d' , { #NEWLINE# #INDENT# 'node' : node . uuid , #NEWLINE# 'method' : method , #NEWLINE# 'res' : result . get ( 'command_result' ) , #NEWLINE# 'error' : result . get ( 'command_error' ) , #NEWLINE# 'code' : response . status_code , #NEWLINE# #UNINDENT# } ) #NEWLINE# return result