#NEWLINE# def run_task( self , state_data , api , node_id , **kwargs ) : #NEWLINE# #INDENT# action = kwargs . pop ( 'action' ) #NEWLINE# payload = kwargs . pop ( 'payload' ) #NEWLINE# timeout = kwargs . get ( 'timeout' , 30 ) #NEWLINE# parent_task_id = None #NEWLINE# reply_data = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# adventure_globals = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# node = api . _model_get_by_id ( 'nodes' , node_id ) #NEWLINE# rollback_action = ( 'rollback_%s' % action ) #NEWLINE# if ( ( 'opencenter_agent_actions' in node [ 'attrs' ] ) and ( rollback_action in node [ 'attrs' ] [ 'opencenter_agent_actions' ] ) ) : #NEWLINE# #INDENT# reply_data [ 'rollback' ] = { #NEWLINE# #INDENT# 'primitive' : rollback_action , #NEWLINE# 'ns' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# if ( ( payload is not None ) and ( 'globals' in payload ) ) : #NEWLINE# #INDENT# parent_task_id = payload [ 'globals' ] . get ( 'parent_task_id' , None ) #NEWLINE# #UNINDENT# for ( k , v ) in adventure_globals . items ( ) : #NEWLINE# #INDENT# if ( not ( k in payload ) ) : #NEWLINE# #INDENT# payload [ k ] = v #NEWLINE# #UNINDENT# #UNINDENT# task_data = { #NEWLINE# #INDENT# 'node_id' : node_id , #NEWLINE# 'action' : action , #NEWLINE# 'payload' : payload , #NEWLINE# 'expires' : int ( ( time . time ( ) + timeout ) ) , #NEWLINE# #UNINDENT# } #NEWLINE# if ( parent_task_id is not None ) : #NEWLINE# #INDENT# task_data [ 'parent_id' ] = parent_task_id #NEWLINE# #UNINDENT# task = api . _model_create ( 'tasks' , task_data ) #NEWLINE# self . logger . debug ( ( 'added task as id %s' % task [ 'id' ] ) ) #NEWLINE# while ( task [ 'state' ] not in [ 'timeout' , 'cancelled' , 'done' ] ) : #NEWLINE# #INDENT# time . sleep ( 5 ) #NEWLINE# task = api . _model_get_by_id ( 'tasks' , task [ 'id' ] ) #NEWLINE# #UNINDENT# if ( task [ 'state' ] != 'done' ) : #NEWLINE# #INDENT# return self . _fail ( msg = 'task did not finish successfully' ) #NEWLINE# #UNINDENT# if ( ( 'result_code' in task [ 'result' ] ) and ( task [ 'result' ] [ 'result_code' ] == 0 ) ) : #NEWLINE# #INDENT# conslist = task [ 'result' ] [ 'result_data' ] . get ( 'consequences' , [ ] ) #NEWLINE# node = api . _model_get_by_id ( 'nodes' , node_id ) #NEWLINE# if ( 'opencenter_agent_actions' in node [ 'attrs' ] ) : #NEWLINE# #INDENT# if ( action in node [ 'attrs' ] [ 'opencenter_agent_actions' ] ) : #NEWLINE# #INDENT# agent_actions = 'opencenter_agent_actions' #NEWLINE# action_info = node [ 'attrs' ] [ agent_actions ] [ action ] #NEWLINE# direct_cons = action_info . get ( 'consequences' , [ ] ) #NEWLINE# for dcon in direct_cons : #NEWLINE# #INDENT# concrete = api . concrete_expression ( dcon , payload ) #NEWLINE# conslist += [ concrete ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for cons in conslist : #NEWLINE# #INDENT# api . apply_expression ( node_id , cons ) #NEWLINE# #UNINDENT# return self . _ok ( data = reply_data ) #NEWLINE# #UNINDENT# return self . _fail ( msg = 'Task failed' )