%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__/saltstack.cpython-312.pyc

�

i��d���f�ddlZddlZddlZddlZddlmZddlmZmZddl	m
Z
mZGd�de�Zy)�N)�RemoteTransport)�ConnectionException�#SaltStackMasterUnsupportedException)�
is_executable�sos_get_command_outputc�r��eZdZdZdZd�Z	d�fd�	Zd�Zed��Z	d
d�Z
d
d�Zd	�Zed
��Z
d�Z�xZS)�SaltStackMasterz�
    A transport for collect that leverages SaltStack's Master Pub/Sub
    functionality to send commands to minions.

    This transport will by default assume the use cmd.shell module to
    execute commands on the minions.
    �	saltstackc�`�ttj|�j��dS)Nr)�list�json�loads�values)�self�json_outputs  �D/usr/lib/python3/dist-packages/sos/collector/transports/saltstack.py�_convert_output_jsonz$SaltStackMaster._convert_output_json!s$���D�J�J�{�+�2�2�4�5�a�8�8�c����tt|�|||||�}tjt
�5|j
|d�|d<ddd�|S#1swY|SxYw)z�
        Run a command on the remote host using SaltStack Master.
        If the output is json, convert it to a string.
        �outputN)�superr	�run_command�
contextlib�suppress�	Exceptionr)r�cmd�timeout�	need_root�env�get_pty�ret�	__class__s       �rrzSaltStackMaster.run_command$sd����O�T�6���)�S�'�3��
�
 �
 ��
+�	E� �5�5�c�(�m�D�C��M�	E��
�	E��
�s�A�Ac���d|�d|��}t|�}|ddk(rVd|j�d�}tjj	||jd��}t
j||�yy	)
zK
        Execute cp.push on the remote host using SaltStack Master
        �salt z	 cp.push �statusrz/var/cache/salt/master/minions/z/files�/TF)r�address�os�path�join�lstrip�shutil�move)r�node�fname�destr�res�cachedir�
cachedir_files        r�_salt_retrieve_filez#SaltStackMaster._salt_retrieve_file0so���d�V�9�U�G�,��$�S�)���x�=�A��8�����f�M�H��G�G�L�L��5�<�<��3D�E�M��K�K�
�t�,��rc�8�|jdd��}|ddk(S)z>Check if the remote host is responding using SaltStack Master.�echo Connected�
�rr%r)r)r�ups  r�	connectedzSaltStackMaster.connected=s)���
�
�.��
�
;���(�|�q� � rc�H�d}t|�}|ddk(r|ddk(St�)a�Checks to see if the local system supported SaltStack Master.

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

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

        Returns
            True if SaltStack Master is supported, else raise Exception
        zsalt-run manage.statusr%r)rr)r�passwordrr1s    r�_check_for_saltstackz$SaltStackMaster._check_for_saltstackCs4��'��$�S�)���x�=�A���x�=�A�%�%�5�5rc��td�s|jd�y	|j�|j	d�d}|j|d��}|d	d
k(S#t$r|jd��wxYw)aDConnect to the remote host using SaltStack Master.

        This method will attempt to connect to the remote host using SaltStack
        Master. If the connection fails, an exception will be raised.

        If the connection is successful, the connection will be stored in the
        self._connection attribute.
        �saltz salt command is not executable. Fz$Transport is not locally supported. z4Transport is locally supported and service running. r6�r8r%r)r�	log_errorr=r�log_infor)rr<r�results    r�_connectzSaltStackMaster._connectXs����V�$��N�N�=�>��	��%�%�'�	
�
�
�L�M����!�!�#�s�!�3���h��1�$�$��
#�	��N�N�A�B��	�s�A�A9c��y)NT�)rs r�_disconnectzSaltStackMaster._disconnectos��rc�,�d}d|�d|j�d�S)z7The remote execution command to use for this transport.z--out json --static --no-colorr$� z cmd.shell )r')r�	salt_argss  r�remote_execzSaltStackMaster.remote_execrs"��5�	��y�k��4�<�<�.��<�<rc�X�|jr|j|j||�SdS)a%Retrieve a file from the remote host using saltstack

        Parameters
            fname       The path to the file on the remote host
            dest        The path to the destination directory on the master

        Returns
            True if the file was retrieved, else False
        F)r:r4r')rr/r0s   r�_retrieve_filezSaltStackMaster._retrieve_filexs2���~�~�
�$�$�T�\�\�5�$�?�	
��	
r)r@FNF)N)�__name__�
__module__�__qualname__�__doc__�namerrr4�propertyr:r=rDrGrKrM�
__classcell__)r"s@rr	r	sa�����D�9�HM�
���!��!�
6�*%�.��=��=�

rr	)
rr
r(r,�sos.collector.transportsr�sos.collector.exceptionsrr�
sos.utilitiesrrr	rFrr�<module>rXs/����	�
�4�K�3�p
�o�p
r

Zerion Mini Shell 1.0