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

�

i��d�$��R�ddlZddlZddlZddlmZddlmZmZmZGd�de�Z	y)�N)�RemoteTransport)�
is_executable�sos_get_command_output�SoSTimeoutErrorc�x��eZdZdZdZdZd�Zed��Zd�Z	d�Z
�fd�Z		d
�fd	�	Zd
�Z
ed��Zd�Z�xZS)�OCTransportaq
    This transport leverages the execution of commands via a locally
    available and configured ``oc`` binary for OCPv4 environments.

    The location of the oc binary MUST be in the $PATH used by the locally
    loaded SoS policy. Specifically this means that the binary cannot be in the
    running user's home directory, such as ~/.local/bin.

    OCPv4 clusters generally discourage the use of SSH, so this transport may
    be used to remove our use of SSH in favor of the environment provided
    method of connecting to nodes and executing commands via debug pods.

    The debug pod created will be a privileged pod that mounts the host's
    filesystem internally so that sos report collections reflect the host, and
    not the container in which it runs.

    This transport will execute within a temporary 'sos-collect-tmp' project
    created by the OCP cluster profile. The project will be removed at the end
    of execution.

    In the event of failures due to a misbehaving OCP API or oc binary, it is
    recommended to fallback to the control_persist transport by manually
    setting the --transport option.
    �oczsos-collect-tmpc�:�td|j�d|��fi|��S)z\Format and run a command with `oc` in the project defined for our
        execution
        �oc -n � )r�project)�self�cmd�kwargss   �=/usr/lib/python3/dist-packages/sos/collector/transports/oc.py�run_oczOCTransport.run_oc1s%��&�!�\�\�3�/�
��
�	
�c�N�|jd|jz�}|ddk(S)Nz.wait --timeout=0s --for=condition=ready pod/%s�statusr�r�pod_name)r�ups  r�	connectedzOCTransport.connected:s-��
�[�[�<�t�}�}�L�
���(�|�q� � rc��ddd|jjd�dz|jd�ddd	d
d�d�d
dd
d�d�ddd
d�d�dddd�d�gd|jjsdn|jjdgddd�giddd�d
dd�ddd�ddd�gddd�dddd�
g|jj
rdndd |jdddd!�d"�S)#z�Based on our template for the debug container, add the node-specific
        items so that we can deploy one of these on each node we're collecting
        from
        �Pod�v1z%s-sos-collector�.r)�name�	namespacezsystem-cluster-critical�host�/�	Directory)�path�type)r�hostPath�runz/run�varlogz/var/logz
machine-idz/etc/machine-id�Filezsos-collector-tmpz&registry.redhat.io/rhel8/support-toolsz	/bin/bash�HOSTz/host)r�value)r�	mountPathT)�
privileged�	runAsUser)
r�image�command�env�	resources�volumeMounts�securityContext�stdin�	stdinOnce�tty�Always�IfNotPresent�Never)�volumes�
containers�imagePullPolicy�
restartPolicy�nodeName�hostNetwork�hostPID�hostIPC)�kind�
apiVersion�metadata�priorityClassName�spec)�address�splitr
�optsr.�force_pull_image�rs r�get_node_pod_configzOCTransport.get_node_pod_configAsg����*�T�\�\�-?�-?��-D�Q�-G�G�!�\�\��";�!'�$'�$/�%��!&�$*�$/�%��!)�$.�$/�%��!-�$5�$*�%��-�@!4�'+�y�y���"J�<@�I�I�O�O�'�$�
)/�)0�� �&(�)/�-4��
).�-3��
)1�-7��
)5�->��)�&+/�)*�,�"&�%)�#�M'�)�V!%�	�	� :� :�H��!(� �L�L�#���_P�Y
�Y	
rc�H�td�sy|j�}|dd|_tj|j
��\}|_t|d�5}tj||�ddd�|jd|jz�td|jz�}|d	d
k7sd|jz|dvr)|jd
�|jd|dz�y|jd|jz�	|jd|jzd��}|d	d
k(s|jd�y	y#1swY��xYw#t$r|jd�Yyt$r}|jd|z�Yd}~yd}~wwxYw)Nr	FrDr)�dir�wz%Starting sos collector container '%s'zoc create -f %srrzpod/%s created�outputz Unable to deploy sos collect podzDebug pod deployment failed: %szDPod '%s' successfully deployed, waiting for pod to enter ready statez/wait --for=condition=Ready pod/%s --timeout=30s�()�timeoutz"Pod not available after 30 secondsz'Timeout while polling for pod readinessz+Error while waiting for pod to be ready: %sT)rrLr�tempfile�mkstemp�tmpdir�pod_tmp_conf�open�json�dump�	log_debugr�	log_errorrr�	Exception)r�password�podconf�fd�cfile�outr�errs        r�_connectzOCTransport._connect�s����T�"���*�*�,���
�+�F�3��
� (� 0� 0�T�[�[� A���D��
�"�c�]�	&�e��I�I�g�u�%�	&����>����N�O�$��� 1� 1�1�
��
��M�Q��"2�T�]�]�"B��H�
�#��N�N�=�>��N�N�<�s�8�}�L�M�����+�-1�]�]�;�	<�	����N�#�}�}�-�&(��)�B��h�<�1�$����C�D��%��A	&�	&��0�	��N�N�D�E���	��N�N�H� �!�
"���	�s*�E�9E�E�F!�;F!�F�F!c���|jd�rd|j�d|j�d|��Stt|�|�S)Nr	r� exec --request-timeout=0 z -- chroot /host )�
startswithr
r�superr�_format_cmd_for_exec)rr�	__class__s  �rrhz OCTransport._format_cmd_for_exec�s:����>�>�$���|�|�T�]�]�C�9�
:��[�$�<�S�A�Arc�@��|r|dz
}tt|�||||d�S)N�
F)rgr�run_command)rrrR�	need_rootr0�get_ptyris      �rrlzOCTransport.run_command�s4�����r�M�G��[�$�3�C��)�47��@�	@rc�"�tjj|j�rtj|j�|jd|jz�}d|dvr"|jd|j�d|���yy)Nz
delete pod %s�deletedrPzCalling delete on pod 'z
' failed: FT)�osr#�existsrV�unlinkrrrZ)r�removeds  r�_disconnectzOCTransport._disconnect�sn��
�7�7�>�>�$�+�+�,��I�I�d�'�'�(��+�+�o��
�
�=�>���G�H�-�-��N�N�"�m�m�W�6�
7��rc�<�d|j�d|j�d�S)Nrrez -- /bin/bash -c)r
rrKs r�remote_execzOCTransport.remote_exec�s���<�<����0�	1rc
��|jdd��}d|dvrdnd}|jd|�d	|j�d
|�d	|���}|ddk(S)
Nzcp --retriesT)�stderrzunknown flagrP�z--retries=5zcp r�:rrr)r�fname�dest�result�flagsrs      r�_retrieve_filezOCTransport._retrieve_file�sX�����^�D��9��$��x�(8�8��m���k�k�"�D�M�M�5�$�@�A���8�}��!�!r)�FNF)�__name__�
__module__�__qualname__�__doc__rr
r�propertyrrLrcrhrlrurwr��
__classcell__)ris@rrrsn����2�D��G�
��!��!�^
�@)�VB�BF�!�	@���1��1�"rr)
rXrSrq�sos.collector.transportsr�
sos.utilitiesrrrr�rr�<module>r�s+����	�4�,�,�^"�/�^"r

Zerion Mini Shell 1.0