#NEWLINE# def run_plugin( self , force = False ) : #NEWLINE# #INDENT# '\n        Run plugin, save result and schedule next run\n\n        :param force: forced run\n        :type force: bool\n        ' #NEWLINE# if self . params [ 'Command' ] : #NEWLINE# #INDENT# command = ( self . params [ 'Command' ] % self . escape ( dict ( self . params ) ) ) #NEWLINE# try : #NEWLINE# #INDENT# result = self . run_command ( command , self . params [ 'Timeout' ] ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# lg . error ( ( 'Plugin %s: %s' % ( self . name , e ) ) ) #NEWLINE# result = Result ( ) #NEWLINE# result . set_status ( 'ERROR' ) #NEWLINE# result . add_error ( e ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if self . params [ 'Module' ] : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# result = self . run_module ( self . params [ 'Module' ] ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# lg . error ( ( 'Plugin %s: %s' % ( self . name , e ) ) ) #NEWLINE# result = Result ( ) #NEWLINE# result . set_status ( 'ERROR' ) #NEWLINE# result . add_error ( re . sub ( '^\n' , '' , ( '%s' % e ) . strip ( ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# lg . error ( ( 'Plugin %s: no Command or Module to execute!' % self . name ) ) #NEWLINE# result = Result ( ) #NEWLINE# result . set_status ( 'ERROR' ) #NEWLINE# result . add_error ( 'No Command or Module to execute!' ) #NEWLINE# #UNINDENT# #UNINDENT# if self . params [ 'Action' ] : #NEWLINE# #INDENT# lg . debug ( ( 'Plugin %s: executing action' % self . name ) ) #NEWLINE# if self . params [ 'Action' ] [ 'Command' ] : #NEWLINE# #INDENT# params = dict ( self . params , ** result . result ) #NEWLINE# params = self . escape ( params ) #NEWLINE# try : #NEWLINE# #INDENT# action = self . run_command ( ( self . params [ 'Action' ] [ 'Command' ] % params ) , timeout = self . params [ 'Action' ] [ 'Timeout' ] ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# lg . error ( ( 'Plugin %s: %s' % ( self . name , e ) ) ) #NEWLINE# action = Result ( ) #NEWLINE# action . set_status ( 'ERROR' ) #NEWLINE# action . add_error ( e ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if self . params [ 'Action' ] [ 'Module' ] : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# action = self . run_module ( self . params [ 'Action' ] [ 'Module' ] , result = result ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# lg . error ( ( 'Plugin %s: %s' % ( self . name , e ) ) ) #NEWLINE# action = Result ( ) #NEWLINE# action . set_status ( 'ERROR' ) #NEWLINE# action . add_error ( e ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# lg . error ( ( 'Plugin %s: no Action Command or Module to execute!' % self . name ) ) #NEWLINE# action = Result ( ) #NEWLINE# action . set_status ( 'ERROR' ) #NEWLINE# action . add_error ( 'No Command or Module to execute!' ) #NEWLINE# #UNINDENT# #UNINDENT# result . set_action ( action ) #NEWLINE# #UNINDENT# result . set_forced ( force ) #NEWLINE# try : #NEWLINE# #INDENT# self . result = result . get_result ( ) #NEWLINE# #UNINDENT# except ValidationError as e : #NEWLINE# #INDENT# lg . error ( ( 'Plugin %s: ValidationError: %s' % ( self . name , e ) ) ) #NEWLINE# result = Result ( ) #NEWLINE# result . set_status ( 'ERROR' ) #NEWLINE# result . add_error ( ( 'ValidationError: %s' % e ) ) #NEWLINE# result . set_forced ( force ) #NEWLINE# self . result = result . get_result ( ) #NEWLINE# #UNINDENT# lg . info ( ( 'Plugin %s result: %s' % ( self . name , result . get_result ( ) ) ) )