
    Vh                     j    d dl mZmZmZ eZd dlZd dlZd dlm	Z	 d dl
mZmZ d dlmZ  G d de      Zy)    )absolute_importdivisionprint_functionN)AnsibleConnectionFailure)to_bytesto_text)TerminalBasec                      e Zd Z ej                  d       ej                  d      gZ ej                  d       ej                  d       ej                  d       ej                  dej                         ej                  dej                         ej                  dej                         ej                  d	ej                         ej                  d
       ej                  d       ej                  dej                         ej                  dej                         ej                  d       ej                  d       ej                  d      gZ ej                  d      Zd Z	ddZ
d Zy)TerminalModules4   [\r\n]?[\w+\-\.:\/\[\]]+(?:\([^\)]+\)){,3}(?:>|#) ?$s'   \[\w+\@[\w\-\.]+(?: [^\]])\] ?[>#\$] ?$s   % ?Errors   % User not presents   % ?Bad secrets   invalid inputs    (?:incomplete|ambiguous) commands   connection timed outs&   [^\r\n]+ not found(?! in current VLAN)s!   '[^']' +returned error code: ?\d+s#   [^\r\n](?<! shell )\/bin\/(?:ba)?shs   % More than \d+ OSPF instances   % Subnet [0-9a-f.:/]+ overlapss3   Maximum number of pending sessions has been reacheds!   % Prefix length must be less thans7   % Cannot change mode; remove all members and try again.z^.+\(config(-.*)?\)#$c                 f    	 dD ]  }| j                  |        y # t        $ r t        d      w xY w)N)s   terminal length 0s   terminal width 512z!unable to set terminal parameters)_exec_cli_commandr   )selfcmds     c/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/arista/eos/plugins/terminal/eos.pyon_open_shellzTerminalModule.on_open_shell?   sB    	PD ,&&s+,' 	P*+NOO	Ps    0Nc                    | j                         j                  d      ry ddi}|rt        dd      |d<   ||d<   d	|d
<   	 | j                  t	        t        j                  |      d             | j                         }||j                  d      st        d|z        y # t        $ r0}| j                         }t        d|d|j                        d }~ww xY w)N   #commandenablez[\r\n]?[Pp]assword: $surrogate_or_strict)errorspromptanswerTprompt_retry_checkz?failed to elevate privilege to enable mode still at prompt [%s]z7unable to elevate privilege to enable mode, at prompt [z] with error: )	_get_promptendswithr   r   r   jsondumpsr   message)r   passwdr   r   es        r   	on_becomezTerminalModule.on_becomeF   s    &&t,(##(,CM #CM(,C$%	""C1FG %%'F~V__T%:.UX^^  &; ( 	%%'F*199& 	s   A B# #	C,+CCc                     | j                         }|y d|v r#| j                  d       | j                  d       y |j                  d      r| j                  d       y y )Ns   (configs   ends   disabler   )r   r   r   )r   r   s     r   on_unbecomezTerminalModule.on_unbecomec   s[    !!#>""6*"":.__T""":. #    )N)__name__
__module____qualname__recompileterminal_stdout_reIterminal_stderr_reterminal_config_promptr   r"   r$    r%   r   r   r   !   sM   

KL

>? 	

< 

)*

$%

$bdd+

7>

+RTT2

=rttD

89

:;

4bdd;

5rtt<

JK

89

G	
#, (RZZ(@AP:/r%   r   )
__future__r   r   r   type__metaclass__r   r)   ansible.errorsr   ansible.module_utils._textr   r   Hansible_collections.ansible.netcommon.plugins.plugin_utils.terminal_baser	   r   r/   r%   r   <module>r6      s2   ( A @   	 3 8 aM/\ M/r%   