%PDF- %PDF-
Mini Shell

Mini Shell

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

�

i��ds�����ddlZddlZddlZddlZddlZddlmZddlmZddl	m
Z
ddlmZddl
mZddlmZddlmZdd	lmZdd
lmZmZmZmZddlmZeeeeed�ZGd
�d�Zy)�N)�quote)�load)�
InitSystem)�JujuSSH)�SSHControlPersist)�LocalTransport)�OCTransport)�SaltStackMaster)�CommandTimeoutException�ConnectionException�UnsupportedHostException�InvalidTransportException)�
parse_version)�local�control_persist�oc�	saltstack�jujuc�`�eZdZ		d3d�Zed��Zd�Zd�Zd�Zed��Z	d�Z
d	�Zd
�Zd�Z
d4d�Zed
��Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd4d�Zd�Zd�Zd�Zd�Z		d5d�Zd�Zd�Z d�Z!d �Z"d!�Z#d"�Z$d#�Z%d$�Z&d%�Z'd&�Z(d'�Z)d(�Z*d)�Z+d*�Z,d+�Z-d,�Z.d-�Z/d.�Z0d/�Z1d0�Z2d1�Z3d2�Z4y)6�SosNodeNc���|j�|_||_|d|_|j	�|d|_|d|_|d|_|d|_d|_	d|_
d|_d|_i|_
i|_|xs|jj|_|jj"s1|jj$s|j |j_|r||j_d|_d|_d|_g|_dgggg|dd�|_d	|_t3j4d
�|_t3j4d�|_|j;|�|_|j<j>r|j<j>dk7|_	|j<jA|j �|jG�|_
|j<j|_|jr|jjHrd}|jJr�|r�|js|j<jM�y|jr!|jO�rd|j_(|jjPr|jS�|jU�yyy#tB$r}|jEd
|z��d}~wwxYw)N�cmdlineopts�tmpdir�hostlen�	need_sudo�sos_optionsF�sos_cmd)�version�enabled�disabled�options�presetsr�	sosreport�sos�sos_ui�rootz!Unable to open remote session: %s)+�strip�address�commons�opts�_assign_config_optsrrrrr�host�cluster�hostname�sos_env_vars�	_env_vars�password�	_password�
nopasswd_sudo�sudo_pw�sos_path�	retrieved�hash_retrieved�	file_list�sos_info�sos_bin�logging�	getLogger�soslog�ui_log�_load_remote_transport�
_transport�default_user�connect�	Exception�	log_error�determine_host_policy�no_local�	connected�
disconnect�check_in_container�
containerized�create_sos_container�_load_sos_info)�selfr(r)r1�
local_sudo�
load_facts�errs       �7/usr/lib/python3/dist-packages/sos/collector/sosnode.py�__init__zSosNode.__init__*sd���}�}��������M�*��	�� � �"��h�'����y�)��� ��-���"�=�1�����
���	������
�������!�7�T�Y�Y�%7�%7����y�y�&�&�t�y�y�/@�/@� $���D�I�I��� *�D�I�I����
����#������������y�)�

��
�#����'�'��.����'�'��1����5�5�g�>����?�?�'�'�!�_�_�9�9�V�C�D�N�	��O�O�#�#�D�N�N�3��.�.�0��	����0�0��
��:�:�$�)�)�,�,��J��>�>�j��9�9����*�*�,���z�z��*�*�,�.3�D�I�I�+��y�y�&�&��)�)�+����!�)�>���	��N�N�>��D�E���	�s�5%K	�		K,�K'�'K,c�H�|jr|jjSy)NT)r@rG�rMs rQrGzSosNode.connectedls���?�?��?�?�,�,�,��c�8�|jj�y)zDWrapper to close the remote session via our transport agent
        N)r@rHrTs rQrHzSosNode.disconnectss��	
���"�"�$rUc���|jdvrd|_t|j|�S|jjt
j
�vr-t|jj|j|�S|jjdk7rG|jd|jjz�t|jj��t|j|�S)z�Determine the type of remote transport to load for this node, then
        return an instantiated instance of that transport
        )�	localhostz	127.0.0.1T�autoz6Connection failed: unknown or unsupported transport %s)
r(rrr*�	transport�
TRANSPORTS�keysrDrr)rMr)s  rQr?zSosNode._load_remote_transportxs����<�<�5�5��D�J�!�$�,�,��8�8�
�Y�Y�
 �
 �J�O�O�$5�
5��d�i�i�1�1�2�4�<�<��I�I�
�Y�Y�
 �
 �F�
*��N�N�H��)�)�%�%�&�
�,�D�I�I�,?�,?�@�@� ����w�7�7rUc�V�dj|j|jdz|�S)Nz{:<{}} : {}�)�format�	_hostnamer�rM�msgs  rQ�_fmt_msgzSosNode._fmt_msg�s$���#�#�D�N�N�D�L�L�1�4D�c�J�JrUc�^�|js�|jr/tjj	�|_|jS|jd�}|ddk(rB|dj
d�D]+}|s�|j
d�}|d|j|d<�-|jS)Nz
env --null�statusr�output��=r^)r0r�os�environ�copy�run_command�split)rM�ret�ln�_vals    rQ�env_varszSosNode.env_vars�s����~�~��z�z�!#�����!2����~�~���&�&�|�4���x�=�A�%�!�(�m�1�1�&�9�:��!�$�!�x�x��}��26�q�'����t�A�w�/�	:�
�~�~�rUc��||_|jjd|j�|jjd|jj�|jjd|j
d�|jjdd�|jjd|jj�y)	z>Set the manifest section that this node will write to
        r.�policy�sos_versionr�final_sos_command�rZN)�manifest�	add_fieldr`r,�distror9r@�name)rMrws  rQ�set_node_manifestzSosNode.set_node_manifest�s���!��
��
�
���
�D�N�N�;��
�
����$�)�)�*:�*:�;��
�
���
�t�}�}�Y�/G�H��
�
��� 3�R�8��
�
����T�_�_�-A�-A�BrUc���tjjd�r|jd�ytjjd��|jd�yy)zV
        Tries to identify if we are currently running in a container or not.
        z/run/.containerenvz/Found /run/.containerenv. Running in container.T�	containerz/Found env var 'container'. Running in containerF)ri�path�exists�	log_debugrj�getrTs rQrIzSosNode.check_in_container�sK���7�7�>�>�.�/��N�N�L�M��
�:�:�>�>�+�&�2��N�N�L�M��rUc���|jj�rH|jj|jj|j�|jj��}|j|d��}|ddvr�|ddk(r<d|dvr|jd	�t�d
|dvr|jd�t�|j|jj�d��}|ddk(r)|jd
|jjz�y|jd|dz�t�|jd|dz�t�y)zJIf the host is containerized, create the container we'll be using
        )�image�auth�
force_pullT��	need_rootre)r�}r�zunable to retrieve auth tokenrfzHCould not pull image. Provide either a username and password or authfilezunknown: Not foundz%Specified image not found on registryrzTemporary container %s createdz*Could not start container after create: %sz&Could not create container on host: %sN)
r,rJrKr*r��get_container_auth�force_pull_imagerlrDrC�restart_sos_container�log_info�sos_container_name)rM�cmd�resrns    rQrKzSosNode.create_sos_container�s`���9�9�"�"��)�)�0�0��i�i�o�o��,�,�.��9�9�5�5�1��C�
�"�"�3�$�"�7�C��8�}��(��x�=�C�'�6�#�h�-�G����7��(��-��X��>����'N�O�'��
�&�&�t�y�y�'F�'F�'H�15�'�7���x�=�A�%��M�M�"B�$(�I�I�$@�$@�#A�B���N�N�#O�%(��]�$3�4�#�O����G�!$�X�� /�0���G#rUc�x�|jjrQ|jjdj	|jj|jj
�S|jjdj
|jjxs|jj�S)zrDetermine what the auth string should be to pull the image used to
        deploy our temporary container
        �default)	r*�
registry_userr,�runtimes�fmt_registry_credentials�registry_password�fmt_registry_authfile�registry_authfile�container_authfilerTs rQr�zSosNode.get_container_auth�s����9�9�"�"��9�9�%�%�i�0�I�I��	�	�'�'��	�	�+�+��
�
�9�9�%�%�i�0�F�F��	�	�+�+�K�t�y�y�/K�/K��
rUc�^�	|jd|z|��}|ddk(S#t$rYywxYw)z3Checks for the presence of fname on the remote nodezstat %sr�rerF)rlrC)rM�fnamer�r�s    rQ�file_existszSosNode.file_exists�sB��	��"�"�9�u�#4�	�"�J�C��x�=�A�%�%���	��	�s� �	,�,c�f�|jrd|jvr|jS|jS)NrX)r.r(rTs rQr`zSosNode._hostname�s(���=�=�[��
�
�=��=�=� ��|�|�rUc�4�d}tj|d|�S)zUAttempts to obfuscate sensitive information in log messages such as
        passwordsz>(?P<var>(pass|key|secret|PASS|KEY|SECRET).*?=)(?P<value>.*?\s)z\g<var>****** )�re�sub)rMrb�regs   rQ�_sanitize_log_msgzSosNode._sanitize_log_msg�s��P���v�v�c�,�c�2�2rUc�X�|jj|j|��y)z:Format a ui message that includes host name and formattingN)r>�inforcras  rQ�ui_msgzSosNode.ui_msg�s����������s�+�,rUc��tj�dd}d|j�d|�d|��}|jj	|�y)z#Used to print and log info messagesr^��[�:�] N)�inspect�stackr`r=r��rMrb�caller�lmsgs    rQr�zSosNode.log_info�s9�������#�A�&��#�~�~�v�s�;��������rUc��tj�dd}d|j�d|�d|��}|jj	|�y)z$Used to print and log error messagesr^r�r�r�r�N)r�r�r`r=�errorr�s    rQrDzSosNode.log_errors9�������#�A�&��#�~�~�v�s�;�������$�rUc��|j|�}tj�dd}d|j�d|�d|��}|jj|�y)z$Used to print and log debug messagesr^r�r�r�r�N)r�r�r�r`r=�debug)rMrbr�s   rQr�zSosNode.log_debugsI���$�$�S�)�������#�A�&��"�n�n�f�c�:�������#�rUc�p�|jjrdt|�zS|jrd|zS|S)z�If we need to provide a sudo or root password to a command, then
        here we prefix the command with the correct bits
        zsu -c %sz
sudo -S %s)r*�become_rootrr)rMr�s  rQ�_format_cmdzSosNode._format_cmds7���9�9� � ���c�
�*�*��>�>��#�%�%��
rUc�V�d}d}|jj�Z|jjj|jj�}|�udj|d�}|dr\|d}nV|j
|jjdd��}|ddk(r&|d	j�jd
�\}}}|r=t|jd��dk(r|dz
}	|d
|jd�dzz
}||jd<|jdr"|jd|jdz�n<|j|jj k(s|j#d�d|_y|j'd�rd|_d|j(z}|j
|dd��}|ddk(r|j+|d	�|j'd�r|j-�yy#t$r}|jd|z�Yd}~��d}~wwxYw)zLQueries the node for information about the installed version of sos
        N�.r�releaseT��
use_containerr�rerrf�-��.0�-%sz%Unable to fully parse sos release: %szsos version is %sz!sos is not installed on this nodeFz4.0z
sos reportz%s -l�3.6)r,�container_version_command�package_manager�pkg_version�sos_pkg_name�joinrlr'rm�lenrCr�r9r�r(r*�primaryrDrG�check_sos_versionr:�_load_sos_plugins�_load_sos_presets)	rM�ver�rel�pkg�pkgs�_rPr��sosinfos	         rQrLzSosNode._load_sos_infos�������9�9�.�.�6��)�)�+�+�7�7��	�	�8N�8N�O�C����h�h�s�9�~�.���y�>��i�.�C��#�#�D�I�I�$G�$G�26�$�$�H�D��H�~��"�"�8�n�2�2�4�:�:�3�?���3����3�9�9�S�>�"�a�'��t���
N��u�s�y�y��~�a�0�0�0��$'��
�
�i� ��=�=��#��M�M�-��
�
�i�0H�H�I��<�<�4�9�9�#4�#4�4����B�C�"�D�N���!�!�%�(�'�D�L�����$���"�"�3�d�d�"�K���8���!��"�"�7�8�#4�5��!�!�%�(��"�"�$�)��-�
N����F��L�M�M��
N�s�0H�	H(�	H#�#H(c�L�d|jz}|j|dd��}|ddk(ry|dj�D]b}|j�j	d�s�#|jd�dj�}|jd	j|��dyy)
Nz%s --list-presetsTr�rerrfzname:r^r")r:rl�
splitlinesr'�
startswithrmr9�append)rMr�r��line�pnames     rQr�zSosNode._load_sos_presetsOs���!�D�L�L�0�����s�$�$��G���x�=�A���H�
�0�0�2�
;���:�:�<�*�*�7�3� �J�J�w�/��2�8�8�:�E��M�M�)�,�3�3�E�:�
;�rUc�R�d}d}d}d}d}|dz|z}|dz|z}|dz|z}	|dzdz}
|j||�|jd<|j||�|jd	<|j|	|�|jd
<|j|
|d�|jd<y)
Nz,The following plugins are currently enabled:z-The following plugins are currently disabled:z4The following options are available for ALL plugins:z+The following plugin options are available:z	Profiles:z(.*?)z

rr r!T�profiles)�_regex_sos_helpr9)rMr��ENABLED�DISABLED�ALL_OPTIONS�OPTIONS�PROFILES�	enablereg�disreg�optreg�proregs           rQr�zSosNode._load_sos_pluginsXs���@��B��L��?�����g�%��0�	��G�#�k�1���7�"�X�-���G�#�f�,��#'�#7�#7�	�7�#K��
�
�i� �$(�$8�$8���$I��
�
�j�!�#'�#7�#7���#H��
�
�i� �$(�$8�$8���$�$O��
�
�j�!rUc�D�g}tj||tj�D]f}|j�D]Q}|s$	|j	|j�d��)|jd�}|jd�|D���S�h|S#t$rY�cwxYw)Nr�,c3�^K�|]%}|j�s�|j����'y�w�N)r')�.0�ps  rQ�	<genexpr>z*SosNode._regex_sos_help.<locals>.<genexpr>ts����A�Q�q�w�w�y�q�w�w�y�A�s�-�-)r��findall�Sr�r�rmrC�extend)rM�regexr��is_listr��resultr��rs        rQr�zSosNode._regex_sos_helpis������j�j������6�		B�F��)�)�+�
B�����
�
�4�:�:�<��?�3��
�
�3��A��J�J�A�!�A�A�
B�		B��
��%����s�"B�	B�Bc��	|jd|z�|jj|�S#t$r!}|j	d|�d|���Yd}~yd}~wwxYw)z1Reads the specified file and returns the contentszReading file %szException while reading �: Nrv)r�r@�	read_filerCrD)rM�to_readrPs   rQr�zSosNode.read_filewsR��	��M�M�+�g�5�6��?�?�,�,�W�5�5���	��N�N�w��L�M���	�s�.1�	A�A�Ac
��|jr:|jd|jdjz�|jdSt	i|j
jt�d|jj|jd���}|r |jd|jz�|S|jd�t�)z[Attempts to identify the host installation against supported
        distributions
        zusing local policy %srsTz/etc/os-release)�cache�sysroot�init�
probe_runtime�remote_exec�remote_checkzloaded policy %s for hostz4Unable to determine host installation. Ignoring node)
rr�r)ryrr*r�rr@rlr�rDr
)rMr,s  rQrEzSosNode.determine_host_policy�s����:�:��M�M�1� �L�L��2�9�9�:�
;��<�<��)�)��"�d�i�i�&7�&7�j�l�"&� $��� ;� ;�!%���0A�!B�D����M�M�5����C�D��K����M�N�&�&rUc�����fd�}||�}	t�jd�}t|�}||k\S#t$r}�jd|z�Yd}~yd}~wwxYw)a�Checks to see if the sos installation on the node is AT LEAST the
        given ver. This means that if the installed version is greater than
        ver, this will still return True

        :param ver: Version number we are trying to verify is installed
        :type ver:  ``str``

        :returns:   True if installed version is at least ``ver``, else False
        :rtype:     ``bool``
        c�8��	|jd�d}d}d|vr)d|jd�djd�dz}t|jd��dk(r|dz
}||zS#t$r#}�jd|�d	|���|cYd}~Sd}~wwxYw)
Nr�rrv���r�r�r�zUnable to format 'z': )rmr�rCr�)r��_fver�_relrPrMs    �rQ�_format_versionz2SosNode.check_sos_version.<locals>._format_version�s����
��	�	�#��q�)�����#�:�����3���!3�!9�!9�#�!>�q�!A�A�D��u�{�{�3�'�(�A�-��T�M�E��t�|�#���
����c�3�G�H��
��
�s�A)A-�-	B�6B�B�BrzError checking sos version: %sNF)rr9rCrD)rMr�r�_ver�	_node_ver�	_test_verrPs`      rQr�zSosNode.check_sos_version�sf���
	��s�#��	�%�d�m�m�I�&>�?�I�%�d�+�I��	�)�)���	��N�N�;�c�A�B���	�s�'8�	A�A�Ac�j�|jsy|jjj|�duS)z2Checks if a given package is installed on the nodeFN)r,r��pkg_by_name)rMr�s  rQ�is_installedzSosNode.is_installed�s,���y�y���y�y�(�(�4�4�S�9��E�ErUc�4�|js]|jsQ|jd�	|jj	|j
�}|s|jd�t�	|r1|jjr|jj|�}|r|j|�}d|vrd}|r|j}	|	j|�}|jj|||||�S#t$r}|jd|z��d}~wwxYw)a�Runs a given cmd, either via the SSH session or locally

        Arguments:
            cmd - the full command to be run
            timeout - time in seconds to wait for the command to complete
            get_pty - If a shell is absolutely needed to run a command, set
                      this to True
            need_root - if a command requires root privileges, setting this to
                        True tells sos-collector to format the command with
                        sudo or su - as appropriate and to input the password
            use_container - Run this command in a container *IF* the host is
                            containerized
        z-Node is disconnected, attempting to reconnectzFailed to reconnect to nodez#Error while trying to reconnect: %sN�atomicT)rGrr�r@�	reconnectr2rrCr,rJ�format_container_commandr�rq�updaterl)
rMr��timeout�get_ptyr�r��env�reconnectedrP�_cmd_envs
          rQrlzSosNode.run_command�s����~�~�d�j�j��N�N�J�K�
�"�o�o�7�7����G��"��N�N�#@�A�-�-�#��T�Y�Y�4�4��)�)�4�4�S�9�C���"�"�3�'�C��s�?��G���}�}�H��/�/�#�&�C����*�*�3���C�+2�4�	4���
����D�s�J�K���
�s�>C4�4	D�=D�Dc���	|j�}|r|j|�n|jd�|jr|j	�|_|j�y#t$rY�wxYw)z.Run an sos report on the node, then collect itz'Unable to determine path of sos archiveN)�execute_sos_command�finalize_sos_pathrDr5�retrieve_sosreportr6rC�cleanup)rMr~s  rQr#zSosNode.sosreport�si��		��+�+�-�D���&�&�t�,����H�I��}�}�!%�!8�!8�!:���	
������	��	�s�AA)�)	A5�4A5c�$�||jdvS)z/Verifies if the given preset exists on the noder"�r9)rM�presets  rQ�_preset_existszSosNode._preset_exists��������y�1�1�1rUc�d��t�fd�|jd|jdfD��S)z/Verifies if the given plugin exists on the nodec3�&�K�|]}�|v���
y�wr��)r��s�plugins  �rQr�z)SosNode._plugin_exists.<locals>.<genexpr>�s�����E�1�6�Q�;�E���rr )�anyr9�rMrs `rQ�_plugin_existszSosNode._plugin_exists�s;����E����y�)A�)-���z�)B�)D�E�E�	ErUc�$�||jdvS)z6Checks to see if the plugin is default enabled on noderrr"s  rQ�_check_enabledzSosNode._check_enabled�rrUc�$�||jdvS)z7Checks to see if the plugin is default disabled on noder rr"s  rQ�_check_disabledzSosNode._check_disabled�s������z�2�2�2rUc���|jd�d}|j|�sy|j|�r||jjvry|j|�r||jdvSy)z�Attempts to verify that the given option is available on the node.
        Note that we only get available options for enabled plugins, so if a
        plugin has been force-enabled we cannot validate if the plugin option
        is correct or notr�rFr!T)rmr#r'r*�enable_pluginsr%r9)rM�opt�plugs   rQ�_plugin_option_existszSosNode._plugin_option_existssq��
�y�y��~�a� ���"�"�4�(��� � ��&��D�I�I�4�4�4�����t�$��$�-�-�	�2�2�2�rUc�8��dj�fd�|D��S)z^Returns a comma delimited list for sos plugins that are confirmed
        to exist on the noder�c3�F�K�|]}�j|�s�|���y�wr�)r#)r��orMs  �rQr�z,SosNode._fmt_sos_opt_list.<locals>.<genexpr>s�����B�a�4�+>�+>�q�+A��B�s�!�!)r�)rMr*s` rQ�_fmt_sos_opt_listzSosNode._fmt_sos_opt_lists����x�x�B�4�B�B�BrUc��||_y)zVExpose the node to the cluster profile determined for the
        environment
        N)r-)rMr-s  rQ�set_clusterzSosNode.set_clusters����rUc���|jjrP|js|jj|_n(|jd|jjz�|jjrE|jjD],}||j
vs�|j
j
|��.|jjrP|jjD]7��|jvs�|jj�|j�<�9|jjrs|jjD]Z�t�fd�|jD��r�"��d|jj���}|jj
|��\|jj|�r;|jj5|jj|�ddd�y|jj5|jj|�ddd�y#1swYyxYw#1swYyxYw)a+This is used to modify the sos report command run on the nodes.
        By default, sos report is run without any options, using this will
        allow the profile to specify what plugins to run or not and what
        options to use.

        This will NOT override user supplied options.
        zYCluster specified preset %s but user has also defined a preset. Using user specification.c3�&�K�|]}�|v���
y�wr�r)r�r/r*s  �rQr�z2SosNode.update_cmd_from_cluster.<locals>.<genexpr>:s�����;��3�!�8�;�r rhN)r-�
sos_presetrr��sos_pluginsr)r�r�sos_plugin_optionsr!�plugopts�check_node_is_primary�lock�set_primary_options�set_node_options)rMr+�optionr*s   @rQ�update_cmd_from_clusterzSosNode.update_cmd_from_clusters�����<�<�"�"��;�;�"�l�l�5�5����
�
�L� $��� 7� 7�8�9��<�<�#�#����0�0�
5���t�2�2�2��'�'�.�.�t�4�
5��<�<�#�#��|�|�/�/�
J���d�.�.�.�,0�L�L�,D�,D�S�,I�D�$�$�S�)�
J�
�<�<�*�*��|�|�6�6�
1���;�T�]�]�;�;�(+�(,���(G�(G��(L�N�F��M�M�(�(��0�	
1��<�<�-�-�d�3����"�"�
7����0�0��6�
7�
7����"�"�
4����-�-�d�3�
4�
4�
7�
7��
4�
4�s�#I�I�I�Ic�l�t|jj�|_t|jj�|_t|jj�|_t|jj
�|_t|jj�|_y)z�From the global opts configuration, assign those values locally
        to this node so that they may be acted on individually.
        N)�listr*�only_plugins�skip_pluginsr)r8rrTs rQr+zSosNode._assign_config_optsGsu��
!����!7�!7�8��� ����!7�!7�8���"�4�9�9�#;�#;�<����T�Y�Y�/�/�0��
��4�9�9�+�+�,��rUc	��|jd}|j�}|r|�dt|��d�}g}|jd�rS|jj
dk7r:|j
dtt|jj
��z�|jd�rP|jjr:|j
dtt|jj��z�|jd�r�|jjr|j
d	�|jjr|j
d
�|jjr1|j
dt|jj�z�|jd�r�|jjr@|j
d
tdj|jj��z�|jjr@|j
dtdj|jj��z�|jd�rP|jjr:|j
dtt|jj��z�|jd�s|jd�r|jj dk7r(|j
d|jj z�|jj"r(|j
d|jj"z�|jd�re|jj$r(|j
d|jj$���|jj&r|j
d�|j)�|j+dt,j.j|j0j2|j4��}|j6D],}|j6|}|j
d|�d|r|nd����.|j8r�|j8D�cgc]J}|j;|j=d�d�r%|j?|j=d�d�r|��L}}|r3|j
d tdjd!�|D���z�|j@ra|jC|j@�r(|j
d"t|j@�z�n|jEd#|j@z�|jF�r$|jFD�cgc]}|j;|�s�|��}}tI|�tI|jF�k7r>tKtM|jF�tM|�z
�}	|jEd$|	z�|jO|jF�}
|
r|j
d%t|
�z�|�ddj|���|_(|jSd&|jPz�|jTjWd'|jP�y(|jXr�|jXD�cgc]}|j[|�s�|��}}tI|�tI|jX�k7r>tKtM|jX�tM|�z
�}|jEd)|z�|jO|�}
|
r|j
d*t|
�z�|j\r�|j\D�cgc]4}||jXvr$|j_|�r|j;|�r|��6}}tI|�tI|j\�k7r>tKtM|j\�tM|�z
�}|jEd+|z�|jO|�}|r|j
d,t|�z�|�ddj|���|_(|jSd&|jPz�|jTjWd'|jP�y(cc}wcc}wcc}wcc}w)-zZUse host facts and compare to the cluster type to modify the sos
        command if neededr� r��z--threads=%sz3.7z--plugin-timeout=%sz3.8z--allow-system-changesz
--no-env-varsz
--since=%sz4.1z--skip-commands=%sr�z--skip-files=%sz4.2z--cmd-timeout=%sz4.3z4.2-13rYz--container-runtime=%sz--namespaces=%sz4.5.2z--journal-size=z--low-priorityr#z--rvr�rrhz-k %sc3� K�|]}|���y�wr�r)r�r/s  rQr�z+SosNode.finalize_sos_cmd.<locals>.<genexpr>�s����8I�q��8I�s�z--preset=%sz?Requested to enable preset %s but preset does not exist on nodezBRequested plugins %s were requested to be enabled but do not existz--only-plugins=%szFinal sos command set to %sruNzARequested to skip plugins %s, but plugins are already not enabledz--skip-plugins=%szORequested to enable plugins %s, but plugins are already enabled or do not existz--enable-plugins=%s)0r9�determine_sos_labelrr�r*�threadsr��str�plugin_timeout�allow_system_changes�no_env_vars�since�
skip_commandsr��
skip_files�cmd_timeout�container_runtime�
namespaces�journal_size�low_priorityr>�replacerir~r,�sos_bin_pathr:rr8r#rmr,rrr�rAr�r@�setr0rr�rwrxrBr%r)r')rMr�label�sos_optsr*rpr/r*�plugs�not_only�only�skip�not_skip�skipln�not_on�enables                rQ�finalize_sos_cmdzSosNode.finalize_sos_cmdRs����-�-�	�*���(�(�*���")�5��<�8�G����!�!�%�(��y�y� � �A�%������s�4�9�9�;L�;L�7M�1N� N�O��!�!�%�(��y�y�'�'���� 5�"'��D�I�I�,D�,D�(E�"F�!G�H��!�!�%�(��y�y�-�-���� 8�9��y�y�$�$�����0��y�y�������u�T�Y�Y�_�_�/E� E�F��!�!�%�(��y�y�&�&����(��c�h�h�t�y�y�'>�'>�?�@�B���y�y�#�#����%��s�x�x��	�	�8L�8L�/M�)N�O���!�!�%�(��y�y�$�$���� 2�"'��D�I�I�,A�,A�(B�"C�!D�E��!�!�%�(�D�,B�,B�8�,L��y�y�*�*�f�4����,�t�y�y�/J�/J�J���y�y�#�#����%��	�	�(<�(<�<���!�!�'�*��y�y�%�%����/�$�)�)�2H�2H�1I� J�K��y�y�%�%���� 0�1��$�$�&��/�/���G�G�L�L����/�/����>�
��
�#�#�	?�C��#�#�C�(�D��O�O�b���Q�t�t��&<�=�>�	?��=�=�#�}�}�E�!��*�*�1�7�7�3�<��?�;��2�2�1�7�7�3�<��?�C��E�D�E������%����8I�D�8I�0I�*J� J�K��;�;��"�"�4�;�;�/����
��d�k�k�0B� B�C���� 3�59�[�[� A�B���� $� 1� 1�L�1�T�5H�5H��5K�Q�L�E�L��5�z�S��!2�!2�3�3���D�$5�$5� 6��U�� C�D����� :�<D� E�F��)�)�$�*;�*;�<�D����� 3�e�D�k� A�B�&-�s�x�x��/A�B�D�L��M�M�7�$�,�,�F�G��M�M�#�#�$7����F�����#�0�0�K�!�D�4G�4G��4J�A�K�D�K��4�y�C�� 1� 1�2�2���D�$5�$5� 6��T�� B�C����� 5�7?� @�A��+�+�D�1�F����� 3�e�F�m� C�D����#�2�2�L�!��� 1� 1�1��,�,�Q�/�D�4G�4G��4J��L�D�L��4�y�C�� 3� 3�4�4��c�$�"5�"5�6��T��B�C����� E�GM� N�O��+�+�D�1�F����� 5��f�
� E�F�")�3�8�8�H�+=�>����
�
�3�d�l�l�B�C��
�
��� 3�T�\�\�B��kE��M��L��Ls%�Ab6�b;�-b;�c�c�9cc��d}||jj|�z
}|jjr7||sd|jjznd|jjzz
}|sy|j	d|z�|jd�rd}n%d}|jjd	�d
�d|��}|�d|��S)
z?Determine what, if any, label should be added to the sos reportrvz%sr�NzLabel for sos report set to %sr�z--labelz--namer�rr�rh)r-�get_node_labelr*rXr�r�r(rm)rMrX�lcmds   rQrGzSosNode.determine_sos_label�s�����
����,�,�T�2�2���9�9�?�?��E�d�T�Y�Y�_�_�,� �4�9�9�?�?�2�
4�E������7�%�?�@��!�!�%�(��D��D�#�|�|�1�1�#�6�q�9�5�A�E���&�&rUc�2�|jj}|r|j|d�}|j�d}|j	d|z�||_|jd�d|_|jjd|j�y)z\Use host facts to determine if we need to change the sos path
        we are retrieving fromrvrzFinal sos path: %s�/r��collected_archiveN)	r,�sos_path_striprUrmr�r5�archiverwrx)rMr~�pstrips   rQrzSosNode.finalize_sos_path�s{�����)�)����<�<���+�D��z�z�|�A����
�
�*�T�1�2���
��z�z�#��r�*����
�
��� 3�T�\�\�BrUc�|�|dk(ry|dk(rd|vry|dk(ryt|�dkDr|jd	�ddSd
|zS)Nr�z+sos report process received SIGKILL on noder^�sudozsudo attempt failed�z4sos report terminated unexpectedly. Check disk spacer�
zsos exited with code %s)r�rm)rM�rc�stdouts   rQ�determine_sos_errorzSosNode.determine_sos_error�sT��
��8�@�
��7����,�
��9�I��v�;��?��<�<��%�a��*�*�,�r�1�1rUc�\�|jd�	d}d}|j|j|jjddd|j
��}|ddk(�r;|dj
�D]s}tj|d�r|j�}|jd	�r|jd
�d}�O|jd�s�a|j�d
}�u|r�|jjd|�t|�dk(r|jjdd�|St|�dk(r|jjdd�|S|jjdd�|S|jjdd�|S|j|d|d�}|jd|d�d|d���t!|��#t"$r|j%d��t $r.}|j'd|���|jd|����d}~wwxYw)z2Run sos report and capture the resulting file pathzGenerating sos report...FT)rr
r�r�rrerrfz*sosreport-*tar*)z sha256	z md5	�	r^zThe checksum is: r��checksum� �
checksum_type�md5�@�sha256�unknownzError running sos report. rc = z msg = zTimeout exceededz'Exception during sos report execution: zError running sos report: N)r�rlrr*rr/r��fnmatchr'r�rmrwrxr�rrr�rCrrDr�)rMr~rur�r�rPs      rQrzSosNode.execute_sos_commands�����.�/�'	��D��H��"�"�4�<�<�+/�9�9�+<�+<�+/�4�15�'+�'8�'8�	#�:�C�
�8�}��!���M�4�4�6�3�D����t�-?�@�#�z�z�|�����'>�?�#'�:�:�d�#3�A�#6�����)<�=�#'�:�:�<��?��
3���M�M�+�+�J��A��8�}��*��
�
�/�/���G��K��X��"�,��
�
�/�/���J��K��
�
�/�/���K��K�
�M�M�+�+�O�Y�G��K�	�.�.�s�8�}�c�(�m�L�����"%�h�-��X�� @�A���n�$��&�	��N�N�-�.���	��M�M�C�C�5�I�J��K�K�4�S�E�:�;���	�s8�B?G�AG�2+G�G�<G�AG�#H+�=)H&�&H+c��|jdz}tjj||j	d�d�}	|j|�r3|j
d|�d|���|jj||�S|jd|z�y#t$r!}|jd|�d|���Yd	}~yd	}~wwxYw)
z7Copies the specified file from the host to our temp dirrgr�zCopying remote z
 to local zFAttempting to copy remote file %s, but it does not exist on filesystemFzFailed to retrieve r�N)rrir~r�rmr�r�r@�
retrieve_filer�rC)rMr~�destdir�destrPs     rQr~zSosNode.retrieve_file0s����+�+��#���w�w�|�|�G�T�Z�Z��_�R�%8�9��	�����%��
�
�#�W�.�/����4�4�T�4�@�@���� >�@D� E�F����	��N�N�$��D�E���	�s�AB�B�	C�%C�Cc��dj|j��}	t|jd��dkr|jd|z�y|j	|�r4|jd|z�d|z}|j
|d�	�}|d
dk(S|jd|z�y#t$r!}|jd
|�d|���Yd}~yd}~wwxYw)z|Removes the spciefied file from the host. This should only be used
        after we have retrieved the file already
        rvrgr�zJRefusing to remove path %s: appears to be incorrect and possibly dangerousFzRemoving file %szrm -f %sTr�rerzHAttempting to remove remote file %s, but it does not exist on filesystemzFailed to remove r�N)r�rmr�r�r�r�rlrC)rMr~r�r��es     rQ�remove_filezSosNode.remove_fileAs����w�w�t�z�z�|�$��	��4�:�:�c�?�#�q�(���� B�DH� I�J������%��
�
�0�4�7�8� �4�'���&�&�s�d�&�;���8�}��)�)���� >�@D� E�F����	��N�N��a�@�A���	�s$�1B-�AB-�B-�-	C�6C�Cc���|jr�|js|jjr	|j	|j�|jd|jz�|jd�	|j|j�}|rI|jd�|jj|jjd�d�y	|jd
�y|jj�r|jj�}nF|j j#�D�cgc]}|j$s�|j%���!c}d}|j&j)d|j�d|���|j
d
|z�y#t
$r|j
d�YywxYw#t
$r}|j
|�Yd}~yd}~wwxYwcc}w)z+Collect the sosreport archive from the nodezFailed to make archive readableFzRetrieving sos report from %szRetrieving sos report...Nz!Successfully collected sos reportrgr�TzFailed to retrieve sos reportzFailed to run sos report on r�zFailed to run sos report. %s)r5rr*r��make_archive_readablerCrDr�r(r�r~r8r�rm�stderr�readrq�	readlinesr'r=r�)rMrnrPr��xs     rQrzSosNode.retrieve_sosreportXs����=�=��~�~����!6�!6�!��.�.�t�}�}�=�
�M�M�9�D�L�L�H�I��K�K�2�3�
��(�(����7������?�@����%�%�d�m�m�&9�&9�#�&>�r�&B�C�����;�<���{�{���!��K�K�$�$�&��(,���(=�(=�(?�K�1�1�7�7�Q�W�W�Y�K�B�O���K�K���8<���a�H�
J��N�N�9�A�=�>���5!�!��N�N�#D�E� �!���
����s�#���
��Ls5�F.�;G�G5�G5�.G�
G�	G2�G-�-G2c���|j�|jryd|jvr|jd|jz�y|j|j�}|s|j	d�yy)zuRemove the sosreport archive from the node, since we have
        collected it and it would be wasted space otherwiseNr#zFNode sos report path %s looks incorrect. Not attempting to remove pathzFailed to remove sos report)r5rr�r�rD)rM�removeds  rQ�remove_sos_archivezSosNode.remove_sos_archivezsp���=�=� �D�J�J�
��d�m�m�+��N�N�7�9=���G�
H���"�"�4�=�=�1����N�N�8�9�rUc���|j�|jr'dD]"}|j|j|z�s�"n|jj	�}|r|j|d��yy)z<Remove the sos archive from the node once we have it locally)z.sha256z.md5Tr�N)r�r5r�r,�set_cleanup_cmdrl)rM�extrs   rQrzSosNode.cleanup�sm�����!��=�=�*�
���#�#�D�M�M�C�$7�8��
��)�)�+�+�-������W���5�rUc�$�|D]�}	|js|jjr	|j|�|j|�}|r?|jj|jd�d�|j|�n|jd|z���y#t$r5}|jd|z�|j
d|�d|���Yd}~��d}~wwxYw#t$r!}d|z}|j|�Yd}~��d}~wwxYw)z4Collect the file created by a cluster outside of soszUnable to retrieve file %szFailed to make file z readable: Nrgr�z1Error collecting additional data from primary: %s)rr*r�r�rCrDr�r~r8r�rmr�)rM�	filenames�filenamerPrnr�rbs       rQ�collect_extra_cmdzSosNode.collect_extra_cmd�s���!�	$�H�
$��>�>�T�Y�Y�%:�%:�!��2�2�8�<��(�(��2����N�N�)�)�(�.�.��*=�b�*A�B��$�$�X�.��N�N�#?�(�#J�K��	$��
%�!����'C�h�'N�O����*2�C�(9�:� ��	!���
$�I�A�M�����s�#�#��
$�s@�"C%�B$�A&C%�$	C"�-+C�C%�C"�"C%�%	D�.D
�
Dc��d|z}|j|dd��}|ddk(ryd}|j|||dfz�t�)z�Used to make the given archive world-readable, which is slightly
        better than changing the ownership outright.

        This is only used when we're not connecting as root.
        zchmod o+r %s�
T)rr�rerz6Exception while making %s readable. Return code was %s)rlrDrC)rM�filepathr�r�rbs     rQr�zSosNode.make_archive_readable�sX���x�'�����s�B�$��?���x�=�A���J�C��N�N�3�(�C��M�!:�:�;��OrU)NNT)F)�FFFN)5�__name__�
__module__�__qualname__rR�propertyrGrHr?rcrqr{rIrKr�r�r`r�r�r�rDr�r�rLr�r�r�r�rEr�rrlr#rr#r%r'r,r0r2r>r+rbrGrrrrr~r�rr�rr�r�rrUrQrr(sG��CG� �@"�D����%�
8�"K�����C�
�& �P������
3�-�� ���1%�f;�P�"��'�$"�HF�FK�-1�%4�N�2�E�
2�3��"C�
�'4�R	-�CC�J'�(
C�2�*�X�"�. �D
:�	6�$�,
rUr)r|r�r;rir��pipesr�sos.policiesr�sos.policies.init_systemsr�sos.collector.transports.jujur�(sos.collector.transports.control_persistr�sos.collector.transports.localr�sos.collector.transports.ocr	�"sos.collector.transports.saltstackr
�sos.collector.exceptionsrrr
r�
sos.utilitiesrr[rrrUrQ�<module>r�sc�����	�	���0�1�F�9�3�>�A�A�(��(�
� ���
�O�OrU

Zerion Mini Shell 1.0