
    Vh%                    p    d dl mZ d dlZd dlmZ d dlmZmZ d dlm	Z	 d dl
mZ  e       Z G d de      Zy)	    )annotationsN)
ActionBase)AnsibleActionFailAnsibleConnectionFailure)
merge_hash)Displayc                  j     e Zd Z ed      ZdZed        Zed        Zed        Z	d Z
d fd	Z xZS )	ActionModule)pathstatetablenoflushcountersmodprobe
ip_versionwaitTc                    d|  d| d| dS )NzThis module doesn't support async>0 and poll>0 when its 'state' param is set to 'restored'. To enable its rollback feature (that needs the module to run asynchronously on the remote), please set task attribute 'poll' (=) to 0, and 'async' (=9) to a value >2 and not greater than 'ansible_timeout' (=) (recommended). 	task_poll
task_asyncmax_timeouts      s/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/action/iptables_state.py"msg_error__async_and_poll_not_zeroz/ActionModule.msg_error__async_and_poll_not_zero   s/     "{"8 E##.-/?	A	B    c                    d|  d| d| dS )Na  Attempts to restore iptables state without rollback in case of mistake may lead the ansible controller to loose access to the hosts and never regain it before fixing firewall rules through a serial console, or any other way except SSH. Please set task attribute 'poll' (=r   r   r   r   r   s      r   $msg_warning__no_async_is_no_rollbackz1ActionModule.msg_warning__no_async_is_no_rollback!   s5    H IR{ S#$]^i]j k		r   c                    d|  d| d| dS )NzYou attempt to restore iptables state with rollback in case of mistake, but with settings that will lead this rollback to happen AFTER that the controller will reach its own timeout. Please set task attribute 'poll' (=r   r   r   r   r   s      r   'msg_warning__async_greater_than_timeoutz4ActionModule.msg_warning__async_greater_than_timeout+   s.     1* >##.-/?	A	Br   c           	     B   | j                   j                         }||_        d|_        d|_        | j
                  j                  j                  |j                  || j                  | j                  | j                  | j                  | j
                        }|j                  d   dk(  r|j                  |      S t        t        d|            D ]K  }|j                  |      }|j                  dd      dk(  r |S t        j                   t#        d|             M S )	z
        Retrieve results of the asynchronous task, and display them in place of
        the async wrapper results (those with the ansible_job_id key).
        zansible.builtin.async_statusr   )task
connectionplay_contextloadertemplarshared_loader_objmodecleanup)	task_vars   finished)_taskcopyargsaction	async_val_shared_loader_objaction_loaderget_connection_play_context_loader_templarrunrangemaxtimesleepmin)selfasync_status_argsr,   timeoutasync_statusasync_actiondummyasync_results           r   _async_resultzActionModule._async_result4   s   
 zz(-<!"..<<@@lt?O?O++DLL$--"55 A 7
 V$	1##i#88 3q'?+ 	(E'++i+@L
A.!3  JJs1g'		( r   c                    d| _         d| _        t        t        |   ||      }~|j                  d      s| j                  j                  xr | j                  j                   }| j                  j                  }| j                  j                  }| j                  j                  }| j                  j                  j                  }| j                  j                  }	i }
d }d }|	j                  dd       dk(  r|s)|st        j!                  | j#                  |||             n|rt%        | j'                  |||            ||kD  r(|s&t        j!                  | j)                  |||             | j+                  dd      }||	d<   | d	|	d
<   t-        d      }
d|	d
    }d|	d
    d}t/        ||      }t1        || j3                  |	||            }d
|	v rb|j                  dd       |
d<   |
d   t%        d      t1        || j5                  |
|d            }| j7                  || j8                        }|d   s	 | j                  j;                          t?        |      D ];  }tA        jB                  d       dz  }	 | j7                  || j8                        } n t1        || j5                  |
|            }dD ]  }|j                  |      s||=  |j                  di       j                  d      r(dD ]#  }|d   d   j                  |      s|d   d   |= % d|
d<   | j5                  |
|d      }s/| jG                  | j                  jH                  jJ                         |S # t<        $ r Y "w xY w# tD        $ r Y 'w xY w)NTskippedr   restored	async_dirz~/.ansible_async)default_timeoutz/iptables.state_backstatus)r*   zrm -f ztouch z.starter)module_argsr,   
wrap_asyncansible_job_idjidzUnable to get 'ansible_job_id'.r   )sudoabler.   r-   )rS   results_filestartedr.   
invocationrQ   )rO   rN   
_async_dirrT   r+   r*   )&_supports_check_mode_supports_asyncsuperr
   r;   r6   r/   r3   r7   has_native_asyncpollr8   
check_moderC   r1   displaywarningr   r   r    r"   get_shell_optiondictr=   r   _execute_modulerH   _low_level_execute_commandDEFAULT_SUDOABLEresetAttributeErrorr<   r>   r?   r   _remove_tmp_path_shelltmpdir)rA   tmpr,   resultrR   r   r   r_   r   rQ   rB   starter_cmdconfirm_cmdrL   remaining_timerF   key	__class__s                    r   r;   zActionModule.runN   s   $(!#|T.sI>zz)$ --Wd6F6F6W6W2WJ 

I--J++66J**88@@K**//K "KKw-;!%(O(O%&')) * +D,U,U!"#-% & &
 "K/
(T(T%&')) * !% 5 5kK] 5 ^I
 /9K
+.7[+HK((,((;%$*;w+?*@"AK$*;w+?*@"IK%([%AN  (<(<`i  wA(<  )B  CF +%+1::6F+M!%($U+3+,MNN $FD,>,>?PR[]^,_`
 77dNcNc7d j)((..0 "'{!3 %

1&!+
%$($C$CKZ^ZoZo$C$pE!% (0B0BCTV_ao0pqF U (Czz#"3K( ::lB/33MBI I!,/>BB3G &| 4] CC HI -6!&)**+<iK!!$"2"2"9"9"@"@AG *   8 %$%s$    M0 N 0	M=<M= 	NN)NN)__name__
__module____qualname__	frozenset_VALID_ARGSrf   staticmethodr   r    r"   rH   r;   __classcell__)rr   s   @r   r
   r
      se     opKB B   B B4x xr   r
   )
__future__r   r>   ansible.plugins.actionr   ansible.errorsr   r   ansible.utils.varsr   ansible.utils.displayr   r`   r
   r   r   r   <module>r      s.    #  - F ) )
)t: tr   