
    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                         ej                  dej                         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                  d       ej                  dej                         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                         ej                  dej                        gZ ej                  d      Z	ddZ
d Zd Zd Zy)TerminalModulesN   [\r\n](?!\s*<)?(\x1b\S+)*[a-zA-Z_0-9]{1}[a-zA-Z0-9-_.]*[>|#](?:\s*)(\x1b\S+)*$s3   [\r\n]?[a-zA-Z0-9]{1}[a-zA-Z0-9-_.]*\(.+\)#(?:\s*)$s   % ?Errors   \nerror:(.*)s   ^% \w+s   % ?Bad secrets   invalid inputs    (?:incomplete|ambiguous) commands   connection timed outs   [^\r\n] not founds!   '[^']' +returned error code: ?\d+s   syntax errors   unknown commands   user not presents   invalid (.+?)at '\^' markers+   configuration not allowed .+ at '\^' markersC   [B|b]aud rate of console should be.* (\d*) to increase [a-z]* levels1   cannot apply non-existing acl policy to interfaces   Duplicate sequence numbers>   Cannot apply ACL to an interface that is a port-channel members    No corresponding (.+) configureds"   (.+)please specify sequence numberz^.*\((?!maint-mode).*\)#$Nc                    | j                         j                         j                  d      ry | j                  d      }t	        |d      j                         }d|v ry | j                         ry d|v rt        d      dd	i}|rt	        d
d      |d<   ||d<   d|d<   	 | j                  t        t        j                  |      d             | j                         }||j                         j                  d      st        d|z        y # t        $ r0}| j                         }t        d|d|j                        d }~ww xY w)N   #zshow privilegesurrogate_then_replaceerrors15Disabledz Feature privilege is not enabledcommandenablez(?i)[\r\n]?Password: $surrogate_or_strictpromptanswerTprompt_retry_check   enable#z?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stripendswith_exec_cli_commandr   validate_user_roler   r   jsondumpsmessage)selfpasswdoutcmdr   es         d/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/cisco/nxos/plugins/terminal/nxos.py	on_becomezTerminalModule.on_becomeG   sN   ##%..t4$$%56c":;AAC 3;""$*+MNN(##$=F[\CM"CM(,C$%	""8DJJsODY#Z[%%'F~V\\^%<%<Z%H.UX^^  &I ( 	%%'F*199& 	s   !A.D 	E	+EE	c                     | j                         }|y d|v r#| j                  d       | j                  d       y |j                  d      r| j                  d       y y )Ns   (configendexitr   )r   r   r   )r"   r   s     r'   on_unbecomezTerminalModule.on_unbecomel   s[    !!#>""5)""6*__Z(""6* )    c                 f    	 dD ]  }| j                  |        y # t        $ r t        d      w xY w)N)zterminal length 0zterminal width 511z!unable to set terminal parameters)r   r   )r"   r%   s     r'   on_open_shellzTerminalModule.on_open_shelly   sB    	PB ,&&s+,' 	P*+NOO	Ps    0c                 :   | j                   j                  j                  }| j                  d|z        }t	        |d      j                         }t        j                  d|t        j                        }|r%|j                  d      j                         }d|v ryyy )	Nzshow user-account %sr   r   zroles:(.+)$   znetwork-adminTF)_connection_play_contextremote_userr   r   r   researchMgroupsplit)r"   userr$   matchroless        r'   r   z!TerminalModule.validate_user_role   s    --99$$%;d%BCc":;AAC		.#rtt4KKN((*E%'	 r-   )N)__name__
__module____qualname__r5   compileterminal_stdout_reIr7   terminal_stderr_reterminal_config_promptr(   r,   r/   r    r-   r'   r   r       s   

^	
 	

JK	 	

< 

#RTT*

:rtt$

$%

$bdd+

7>

+RTT2

("$$/

89

#$

&'

'(

2BDD9

BC

SDD	
 	

H"$$O

0"$$7

NDD	
 	

7>

9244@5: (RZZ(DE#J+Pr-   r   )
__future__r   r   r   type__metaclass__r   r5   ansible.errorsr   ansible.module_utils._textr   r   Hansible_collections.ansible.netcommon.plugins.plugin_utils.terminal_baser	   r   rE   r-   r'   <module>rL      s2   & A @   	 3 8 ak\ kr-   