%PDF- %PDF-
| Direktori : /lib/python3/dist-packages/sos/collector/transports/__pycache__/ | 
| Current File : //lib/python3/dist-packages/sos/collector/transports/__pycache__/control_persist.cpython-312.pyc | 
�
    i��dm!  �                   �r   � d dl Z d dlZd dlZd dlmZ d dlmZmZmZm	Z	m
Z
mZmZm
Z
 d dlmZ  G d� de�      Zy)�    N)�RemoteTransport)�InvalidPasswordException�TimeoutPasswordAuthException�PasswordRequestException�AuthPermissionDeniedException�ConnectionException�ConnectionTimeoutException�ControlSocketMissingException�"ControlPersistUnsupportedException)�sos_get_command_outputc                   �N   � e Zd ZdZdZd� 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                 ��   � g d�}t        j                  |t         j                  t         j                  ��      }|j                  �       \  }}|j	                  d�      }d|v sd|v rt
        �y)a  Checks 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                  �        | j                  d�       | j                  �d| j
                  ��| _        d| _        d}d}d}| j                  j                  dk7  rd| j                  j                  z  }| j                  j                  rd| j                  j                  z  }d	|�d
|�d| j                  �d
| j                  j                  �d| j
                  �d
�}t        j                  |d��      }dddddt        j                  g}|j                  |d��      }|dk(  rd}n�|dk(  r]|rUddt        j                  g}	|j!                  |�       |j                  |	d��      }
|
dk(  rd}n�|
dk(  rt"