%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/sos/collector/transports/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/sos/collector/transports/__pycache__/control_persist.cpython-312.pyc

�

i��dm!��r�ddlZddlZddlZddlmZddlmZmZmZm	Z	m
Z
mZmZm
Z
ddlmZGd�de�Zy)�N)�RemoteTransport)�InvalidPasswordException�TimeoutPasswordAuthException�PasswordRequestException�AuthPermissionDeniedException�ConnectionException�ConnectionTimeoutException�ControlSocketMissingException�"ControlPersistUnsupportedException)�sos_get_command_outputc�N�eZdZdZdZd�Zd
d�Zd�Zed��Z	ed��Z
d�Zy	)�SSHControlPersista�
    A transport for collect that leverages OpenSSH's ControlPersist
    functionality which uses control sockets to transparently keep a connection
    open to the remote host without needing to rebuild the SSH connection for
    each and every command executed on the node.

    This transport will by default assume the use of SSH keys, meaning keys
    have already been distributed to target nodes. If this is not the case,
    users will need to provide a password using the --password or
    --password-per-node option, depending on if the password to connect to all
    nodes is the same or not. Note that these options prevent the use of the
    --batch option, as they require user input.
    �control_persistc���gd�}tj|tjtj��}|j�\}}|j	d�}d|vsd|vrt
�y)aChecks to see if the local system supported SSH ControlPersist.

        ControlPersist allows OpenSSH to keep a single open connection to a
        remote host rather than building a new session each time. This is the
        same feature that Ansible uses in place of paramiko, which we have a
        need to drop in sos-collector.

        This check relies on feedback from the ssh binary. The command being
        run should always generate stderr output, but depending on what that
        output reads we can determine if ControlPersist is supported or not.

        For our purposes, a host that does not support ControlPersist is not
        able to run sos-collector.

        Returns
            True if ControlPersist is supported, else raise Exception.
        )�sshz-o�ControlPersist)�stdout�stderr�utf-8zBad configuration optionzUsage:T)�
subprocess�Popen�PIPE�communicate�decoder)�self�ssh_cmd�cmd�out�errs     �J/usr/lib/python3/dist-packages/sos/collector/transports/control_persist.py�_check_for_control_persistz,SSHControlPersist._check_for_control_persist-s]��$2�����w�z���&0�o�o�7���?�?�$���S��j�j��!��%��,��C��4�4��c��	|j�|jd�|j�d|j
��|_d|_d}d}d}|jjdk7rd|jjz}|jjrd|jjz}d	|�d
|�d|j�d
|jj�d|j
�d
�}tj|d��}dddddtjg}|j|d��}|dk(rd}n�|dk(r]|rUddtjg}	|j!|�|j|	d��}
|
dk(rd}n�|
dk(rt"�|
dk(r�t$�t&�|dk(rt(�|dk(r*t+|j
|jj��|dk(rt+|j
��|dk(rt,�t/d|j0z��|rNt2j4j7|j�st8�|j;d |jz�yy#t$r|jd��wxYw)!a0
        Using ControlPersist, create the initial connection to the node.

        This will generate an OpenSSH ControlPersist socket within the tmp
        directory created or specified for sos-collector to use.

        At most, we will wait 30 seconds for a connection. This involves a 15
        second wait for the initial connection attempt, and a subsequent 15
        second wait for a response when we supply a password.

        Since we connect to nodes in parallel (using the --threads value), this
        means that the time between 'Connecting to nodes...' and 'Beginning
        collection of sosreports' that users see can be up to an amount of time
        equal to 30*(num_nodes/threads) seconds.

        Returns
            True if session is successfully opened, else raise Exception
        zYOpenSSH ControlPersist is not locally supported. Please update your OpenSSH installation.z,Opening SSH session to create control socketz/.sos-collector-�F�z-p%s z-i%szssh � zT -oControlPersist=600 -oControlMaster=auto -oStrictHostKeyChecking=no -oControlPath=�@z "echo Connected"r)�encoding�	Connectedz	password:z.*Permission denied.*z.* port .*: No route to hostz.*Could not resolve hostname.*�)�timeoutrT�z$Permission denied, please try again.����z!Unknown error, client returned %sz)Successfully created control socket at %s)r!r�	log_error�log_info�tmpdir�address�control_pathr�opts�ssh_port�ssh_key�ssh_user�pexpect�spawn�TIMEOUT�expect�sendlinerrrrrr	�	Exception�before�os�path�existsr
�	log_debug)r�password�	connectedr8r7r�res�connect_expects�index�pass_expects�
pass_indexs           r �_connectzSSHControlPersist._connectHsS��&	��+�+�-�
	
�
�
�D�E�7;�{�{�7;�|�|�E�������	������9�9����#�����!3�!3�3�H��9�9����t�y�y�0�0�0�G��(/�'/�'+�'8�'8�'+�y�y�'9�'9�'+�|�|�
5���m�m�C�'�2��
��$�+�-��O�O�

���
�
�?�B�
�7���A�:��I�
�a�Z�� �;��O�O� ��
���X�&� �Z�Z��b�Z�A�
���?� $�I��1�_�3�2��1�_�6�6�.�.�
�a�Z�/�/�
�a�Z�%�d�l�l�D�I�I�4F�4F�G�G�
�a�Z�%�d�l�l�3�3�
�a�Z�,�,��?�#�*�*�L�M�M���7�7�>�>�$�"3�"3�4�3�3��N�N�F�!�.�.�/�
0����U2�	��N�N�F�
G��	�s�I�I9c��tjj|j�r!	tj|j�y|j
d�y#t
$r}|j
d|z�Yd}~yd}~wwxYw)NTz!Could not disconnect properly: %sFz?Control socket not present when attempting to terminate session)rArBrCr5�remover?rD)rrs  r �_disconnectzSSHControlPersist._disconnect�sl��
�7�7�>�>�$�+�+�,�
��	�	�$�+�+�,��	
���+�	,���
����B�S�H�I���
�s�A�	B�&A?�?Bc�T�tjj|j�S)a�Check if the SSH control socket exists

        The control socket is automatically removed by the SSH daemon in the
        event that the last connection to the node was greater than the timeout
        set by the ControlPersist option. This can happen for us if we are
        collecting from a large number of nodes, and the timeout expires before
        we start collection.
        )rArBrCr5�rs r rFzSSHControlPersist.connected�s���w�w�~�~�d�/�/�0�0r"c��|js8d|j�d|jj�d|j��|_|jS)Nzssh -oControlPath=r&r')rr5r6r9r4rQs r �remote_execzSSHControlPersist.remote_exec�s9���|�|��!�!�4�9�9�#5�#5�t�|�|��D�L��|�|�r"c
��d|j�d|jj�d|j�d|�d|��
}t	|�}|ddk(S)Nz/usr/bin/scp -oControlPath=r&r'�:�statusr)r5r6r9r4r)r�fname�destrrGs     r �_retrieve_filez SSHControlPersist._retrieve_file�sC�����t�y�y�1�1�4�<�<���
��%�S�)���8�}��!�!r"N)r$)�__name__�
__module__�__qualname__�__doc__�namer!rLrO�propertyrFrSrY�r"r rrsL����D��6_�B	,��	1��	1�����"r"r)rAr:r�sos.collector.transportsr�sos.collector.exceptionsrrrrrr	r
r�
sos.utilitiesrrr`r"r �<module>rds8��
���4�J�J�J�1�q"��q"r"

Zerion Mini Shell 1.0