AnonSec Shell
Server IP : 85.193.89.191  /  Your IP : 18.119.167.191
Web Server : Apache
System : Linux 956367-cx40159.tmweb.ru 3.10.0-1160.105.1.el7.x86_64 #1 SMP Thu Dec 7 15:39:45 UTC 2023 x86_64
User : bitrix ( 600)
PHP Version : 8.1.27
Disable Function : NONE
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python2.7/site-packages/ansible/plugins/connection/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /lib/python2.7/site-packages/ansible/plugins/connection/network_cli.pyo
�
��\c@`s�ddlmZmZmZeZdZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlmZddlmZmZddlmZddlmZddlmZmZdd	lmZdd
lmZddlm Z m!Z!m"Z"yddl#m$Z$Wn*e%k
r`dd
l&m'Z'e'�Z$nXde(fd��YZ)defd��YZ*dS(i(tabsolute_importtdivisiontprint_functionsm
---
author: Ansible Networking Team
connection: network_cli
short_description: Use network_cli to run command on network appliances
description:
  - This connection plugin provides a connection to remote devices over the
    SSH and implements a CLI shell.  This connection plugin is typically used by
    network devices for sending and receiving CLi commands to network devices.
version_added: "2.3"
options:
  host:
    description:
      - Specifies the remote device FQDN or IP address to establish the SSH
        connection to.
    default: inventory_hostname
    vars:
      - name: ansible_host
  port:
    type: int
    description:
      - Specifies the port on the remote device to listening for connections
        when establishing the SSH connection.
    default: 22
    ini:
      - section: defaults
        key: remote_port
    env:
      - name: ANSIBLE_REMOTE_PORT
    vars:
      - name: ansible_port
  network_os:
    description:
      - Configures the device platform network operating system.  This value is
        used to load the correct terminal and cliconf plugins to communicate
        with the remote device
    vars:
      - name: ansible_network_os
  remote_user:
    description:
      - The username used to authenticate to the remote device when the SSH
        connection is first established.  If the remote_user is not specified,
        the connection will use the username of the logged in user.
      - Can be configured form the CLI via the C(--user) or C(-u) options
    ini:
      - section: defaults
        key: remote_user
    env:
      - name: ANSIBLE_REMOTE_USER
    vars:
      - name: ansible_user
  password:
    description:
      - Configures the user password used to authenticate to the remote device
        when first establishing the SSH connection.
    vars:
      - name: ansible_password
      - name: ansible_ssh_pass
  private_key_file:
    description:
      - The private SSH key or certificate file used to to authenticate to the
        remote device when first establishing the SSH connection.
    ini:
      - section: defaults
        key: private_key_file
    env:
      - name: ANSIBLE_PRIVATE_KEY_FILE
    vars:
      - name: ansible_private_key_file
  timeout:
    type: int
    description:
      - Sets the connection time, in seconds, for the communicating with the
        remote device.  This timeout is used as the default timeout value for
        commands when issuing a command to the network CLI.  If the command
        does not return in timeout seconds, the an error is generated.
    default: 120
  become:
    type: boolean
    description:
      - The become option will instruct the CLI session to attempt privilege
        escalation on platforms that support it.  Normally this means
        transitioning from user mode to C(enable) mode in the CLI session.
        If become is set to True and the remote device does not support
        privilege escalation or the privilege has already been elevated, then
        this option is silently ignored
      - Can be configured form the CLI via the C(--become) or C(-b) options
    default: False
    ini:
      - section: privilege_escalation
        key: become
    env:
      - name: ANSIBLE_BECOME
    vars:
      - name: ansible_become
  become_method:
    description:
      - This option allows the become method to be specified in for handling
        privilege escalation.  Typically the become_method value is set to
        C(enable) but could be defined as other values.
    default: sudo
    ini:
      - section: privilege_escalation
        key: become_method
    env:
      - name: ANSIBLE_BECOME_METHOD
    vars:
      - name: ansible_become_method
  host_key_auto_add:
    type: boolean
    description:
      - By default, Ansible will prompt the user before adding SSH keys to the
        known hosts file.  Since persistent connections such as network_cli run
        in background processes, the user will never be prompted.  By enabling
        this option, unknown host keys will automatically be added to the
        known hosts file.
      - Be sure to fully understand the security implications of enabling this
        option on production systems as it could create a security vulnerability.
    default: False
    ini:
      - section: paramiko_connection
        key: host_key_auto_add
    env:
      - name: ANSIBLE_HOST_KEY_AUTO_ADD
  persistent_connect_timeout:
    type: int
    description:
      - Configures, in seconds, the amount of time to wait when trying to
        initially establish a persistent connection.  If this value expires
        before the connection to the remote device is completed, the connection
        will fail
    default: 30
    ini:
      - section: persistent_connection
        key: connect_timeout
    env:
      - name: ANSIBLE_PERSISTENT_CONNECT_TIMEOUT
    vars:
      - name: ansible_connect_timeout
  persistent_command_timeout:
    type: int
    description:
      - Configures, in seconds, the amount of time to wait for a command to
        return from the remote device.  If this timer is exceeded before the
        command returns, the connection plugin will raise an exception and
        close
    default: 10
    ini:
      - section: persistent_connection
        key: command_timeout
    env:
      - name: ANSIBLE_PERSISTENT_COMMAND_TIMEOUT
    vars:
      - name: ansible_command_timeout
  persistent_buffer_read_timeout:
    type: float
    description:
      - Configures, in seconds, the amount of time to wait for the data to be read
        from Paramiko channel after the command prompt is matched. This timeout
        value ensures that command prompt matched is correct and there is no more data
        left to be received from remote host.
    default: 0.1
    ini:
      - section: persistent_connection
        key: buffer_read_timeout
    env:
      - name: ANSIBLE_PERSISTENT_BUFFER_READ_TIMEOUT
    vars:
      - name: ansible_buffer_read_timeout
N(tAnsibleConnectionFailure(tBytesIOtPY3(tcPickle(tto_list(tto_bytestto_text(tPlayContext(tNetworkConnectionBase(tcliconf_loadertterminal_loadertconnection_loader(tdisplay(tDisplaytAnsibleCmdRespRecvcB`seZRS((t__name__t
__module__(((sJ/usr/lib/python2.7/site-packages/ansible/plugins/connection/network_cli.pyR�st
ConnectioncB`s�eZdZdZeZd�Zd�Zd�Zded�Z
d�Zd�Zd�Z
dddeeed	�Zddeeeed
�Zd�Zd�Zd
�Zeed�Zdd�Zd�Zd�ZRS(s) CLI (shell) SSH connections on Paramiko tnetwork_clicO`s�tt|�j||||�d|_d|_d|_d|_d|_t	�|_
d|_d|_d|_
d|_|jjdkr�tjd�jtj�ndS(Nitparamiko(tsuperRt__init__tNonet
_ssh_shellt_matched_promptt_matched_cmd_promptt_matched_patternt_last_responsetlistt_historyt_command_responset	_terminaltcliconft
paramiko_connt
_play_contextt	verbositytloggingt	getLoggertsetLeveltDEBUG(tselftplay_contextt	new_stdintargstkwargs((sJ/usr/lib/python2.7/site-packages/ansible/plugins/connection/network_cli.pyR�s									cC`s4dtj�tj�f}|d|jj7}|S(Nsp=%s u=%s | s
paramiko [%s](tostgetpidtgetpasstgetuserR%tremote_addr(R+tname((sJ/usr/lib/python2.7/site-packages/ansible/plugins/connection/network_cli.pyt_get_log_channel�scC`s|jS(s*Returns the current prompt from the device(R(R+((sJ/usr/lib/python2.7/site-packages/ansible/plugins/connection/network_cli.pyt
get_prompt�scC`s&|jry�tjt|dd��}it|ddd�d6}x{d	D]s}|j|�tks{|j|�tkr�||||<qK|j|�dk	rKt||dd�||<qKqKW|j	|�SWq"t
k
rt|dd�}|j	d|�SXntt|�j
|||�SdS(
Nterrorstsurrogate_or_stricttcommandtprompttanswertsendonlytnewlinetprompt_retry_check(spromptsanswerssendonlysnewlinesprompt_retry_check(RtjsontloadsR	RtgettTruetFalseRtsendt
ValueErrorRRtexec_command(R+tcmdtin_datatsudoableR/tkey((sJ/usr/lib/python2.7/site-packages/ansible/plugins/connection/network_cli.pyRG�s	
*!
cC`st|�}tr*tj|dd�}ntj|�}t�}|j|�dg}|jj|jAr�|jtkr�|j	}|j
jd|�|jd�q�|j
j
�|jd�n||_t|d�r�|j�nt|d�r|j�n|S(	s7Updates the play context information for the connectiontencodingtbytess$updating play_context for connectiontpasswdsauthorizing connectionsdeauthorizing connectiont
reset_historytdisable_response_logging(RRRRAR
tdeserializeR%tbecomeRCtbecome_passR"t	on_becometappendton_unbecomethasattrRORP(R+tpc_dataR,tmessagest	auth_pass((sJ/usr/lib/python2.7/site-packages/ansible/plugins/connection/network_cli.pytupdate_play_contexts(	
		
	

cC`s�|js�|js!td��ntjd|jdt�tjd|jd�|_|jj	|j
��|jjdit|jj
o�|jj�d6�|j|j_|jj�}|jd�}tjd	d|�|jj�|_|jj|jd
��tj|j|�|_|jsBtd|j��ntjd|jd|�tj|j|�|_|jr�tjd
|jd|�|jj|j�ntjd|j�tt|�j�|jd|jj d|jj!d|jj"�tjdd|�|jj#�|jj$ru|jj%dkrutjdd|�|jj&}|jj'd|�ntjdd|�t|_(n|S(sG
        Connects to the remote device and starts the terminal
        ssUnable to automatically determine host network os. Please manually configure ansible_network_os value for this hostsnetwork_os is set to %stlog_onlyRs	/dev/nulltdirectt
look_for_keysthosts%ssh connection done, setting terminaltpersistent_command_timeoutsnetwork os %s is not supporteds(loaded terminal plugin for network_os %ss'loaded cliconf plugin for network_os %ss(unable to load cliconf for network_os %stpromptsR<R>sfiring event: on_open_shell()tenablesfiring event: on_becomeRNs)ssh connection has completed successfully()t	connectedt_network_osRRRCRRBR%R$t_set_log_channelR6tset_optionstbooltpasswordtprivate_key_filetforce_persistencet_connectt
get_optiontvvvvtsshtinvoke_shellRt
settimeoutR
R"RR#t_implementation_pluginsRURRtreceivetterminal_initial_prompttterminal_initial_answertterminal_inital_prompt_newlinet
on_open_shellRRt
become_methodRSRTt
_connected(R+RnR_RZ((sJ/usr/lib/python2.7/site-packages/ansible/plugins/connection/network_cli.pyRk%sF		4		!

cC`s�|jr�tjdd|jj�|jr�tjd�|jj�|jj�d|_tjd�|j
j�d|_
tjd�q�ntt|�j�dS(s;
        Close the active connection to the device
        s closing ssh connection to deviceR_sfiring event: on_close_shell()scli session is now closeds+ssh connection has been closed successfullyN(
RxRtdebugR%R4RR"ton_close_shelltcloseRR$RR(R+((sJ/usr/lib/python2.7/site-packages/ansible/plugins/connection/network_cli.pyR{\s		


	

	cC`s�d|_d|_t�}t}t}	d}
}|jj�}|jd�}
|j|
d�||
kr~|jj	|
�n|jd�}|j|d�x+t
r�|	rLyutjtj|j
�tjtj|�|jjd�}tjd�t}	tjtj|j�tj|
�Wq^tk
rH|jj	|�|jSXn|jjd�}|shPn|j|�|j�dkr�|j�dnd}|j|�|j|j��}|d7}|r�|r�|j||||t|�}|}
nY|rV|rV|rV|
d|krV|j||||||�rVtd|j��qVn|j|�r�|j�|_|j|j�}|j||�|_|dkr�|jj	|�|jSt
}	q�q�WdS(	s:
        Handles receiving of output from command
        iR`tpersistent_buffer_read_timeoutiis,For matched prompt '%s', answer is not validgN( RRRRRDRt
gettimeoutRlt_validate_timeout_valueRpRCtsignaltSIGALRMt_handle_buffer_read_timeoutt	setitimertITIMER_REALtrecvtalarmt_handle_command_timeoutRR!twritettelltseekt_striptreadt_handle_promptRt_find_prompttgetvalueRt	_sanitize(R+R:RaR<R>R?t	check_allR�thandledtcommand_prompt_matchedtmatched_prompt_windowtwindow_counttcache_socket_timeouttcommand_timeouttbuffer_read_timeouttdatatoffsettwindowtresp((sJ/usr/lib/python2.7/site-packages/ansible/plugins/connection/network_cli.pyRros`			
	


(


	"cC`s|rRtt|��}tt|��}	||	krRtd||	f��qRny`|jj|�|jjd|�|r�dS|j||||||�}
t|
dd�SWn^t	j
tfk
rtj
tj�d|jj�td|jj�|j�f��nXdS(sE
        Sends the command to the device in the opened shell
        s:Number of prompts (%s) is not same as that of answers (%s)s%s
NR8R9R_sAtimeout value %s seconds reached while trying to send command: %s(tlenRRR RURtsendallRrR	tsocketttimeouttAttributeErrorRRmt	tracebackt
format_excR%R4R}tstrip(R+R:R;R<R>R=R?R�t
prompt_lent
answer_lentresponse((sJ/usr/lib/python2.7/site-packages/ansible/plugins/connection/network_cli.pyRE�s cC`s3tjd|jd�d|jj�t��dS(NsQResponse received, triggered 'persistent_buffer_read_timeout' timer of %s secondsR|R_(RRmRlR%R4R(R+tsignumtframe((sJ/usr/lib/python2.7/site-packages/ansible/plugins/connection/network_cli.pyR��s	cC`s6d|jd�}tj|dt�t|��dS(Ns�command timeout triggered, timeout value is %s secs.
See the timeout setting options in the Network Debug and Troubleshooting Guide.R`R\(RlRRCR(R+R�R�tmsg((sJ/usr/lib/python2.7/site-packages/ansible/plugins/connection/network_cli.pyR��scC`s-x&|jjD]}|jd|�}q
W|S(s9
        Removes ANSI codes from device response
        t(R"tansi_retsub(R+R�tregex((sJ/usr/lib/python2.7/site-packages/ansible/plugins/connection/network_cli.pyR��scC`s@t}t|t�s'|g}t}nt|t�sB|g}ng|D]}tj|tj�^qI}	x�t|	�D]�\}
}|j|�}|rw|s�t	|�|
kr�||
n|d}
|j
jd|
�|r�|j
jd�q�n|j�|_
|r4|r4|r4|jd�|jd�tStSqwWtS(s%
        Matches the command prompt and responds

        :arg resp: Byte string containing the raw response from the remote
        :arg prompts: Sequence of byte strings that we consider prompts for input
        :arg answer: Sequence of Byte string to send back to the remote if we find a prompt.
                A carriage return is automatically appended to this string.
        :param prompt_retry_check: Bool value for trying to detect more prompts
        :param check_all: Bool value to indicate if all the values in prompt sequence should be matched or any one of
                          given prompt.
        :returns: True if a prompt was found in ``resp``. If check_all is True
                  will True only after all the prompt in the prompts list are matched. False otherwise.
        is%ss
(RDt
isinstanceRRCtretcompiletIt	enumeratetsearchR�RR�tgroupRtpop(R+R�RaR<R>R?R�t
single_prompttrt
prompts_regextindexR�tmatcht
prompt_answer((sJ/usr/lib/python2.7/site-packages/ansible/plugins/connection/network_cli.pyR��s,		(&

cC`svg}xZ|j�D]L}|r7|j�|j�ks|jj�|krRqn|j|�qWdj|�j�S(sS
        Removes elements from the response before returning to the caller
        s
(t
splitlinesR�RRUtjoin(R+R�R:tcleanedtline((sJ/usr/lib/python2.7/site-packages/ansible/plugins/connection/network_cli.pyR�	s3cC`sd}t}x}|jjD]o}|j|�rt}xQ|jjD]@}|j|�}|rA|}|j|_|j	�|_
PqAqAWqqW|s�xT|jjD]C}|j|�}|r�|j|_|j	�|_
|s�tSq�q�Wn|r�t|��ntS(sESearches the buffered response for a matching command prompt
        N(RRDR"tterminal_stderr_reR�RCtterminal_stdout_retpatternRR�RR(R+R�terrored_responsetis_error_messageR�R�((sJ/usr/lib/python2.7/site-packages/ansible/plugins/connection/network_cli.pyR�s.cC`s)|dkr%td||f��ndS(NisP'%s' timer value '%s' is invalid, value should be greater than or equal to zero.(R(R+R�t
timer_name((sJ/usr/lib/python2.7/site-packages/ansible/plugins/connection/network_cli.pyR~5sN(RRt__doc__t	transportRCthas_pipeliningRR6R7RRGR[RkR{RDRrRER�R�R�R�R�R�R~(((sJ/usr/lib/python2.7/site-packages/ansible/plugins/connection/network_cli.pyR�s&					7	K			'	!(+t
__future__RRRttypet
__metaclass__t
DOCUMENTATIONR2R@R'R�R0RR�R�tansible.errorsRtansible.module_utils.sixRRtansible.module_utils.six.movesRt)ansible.module_utils.network.common.utilsRtansible.module_utils._textRR	tansible.playbook.play_contextR
tansible.plugins.connectionRtansible.plugins.loaderRR
Rt__main__RtImportErrortansible.utils.displayRt	ExceptionRR(((sJ/usr/lib/python2.7/site-packages/ansible/plugins/connection/network_cli.pyt<module>s2�



Anon7 - 2022
AnonSec Team