HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ip-172-26-0-120 6.17.0-1009-aws #9~24.04.2-Ubuntu SMP Fri Mar 6 23:50:29 UTC 2026 x86_64
User: ubuntu (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/sos/collector/__pycache__/sosnode.cpython-312.pyc
�

O6uf\�����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)�sos_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
|����d}~wwxYw)N�cmdlineopts�tmpdir�hostlen�	need_sudo�sos_optionsF�sos_cmd)�version�enabled�disabled�options�presetsr�	sosreport�sos�sos_ui�rootzUnable to open remote session: )+�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__,sf���}�}��������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�<�S�E�B�C���	�s�5%K	�		K,�K'�'K,c�H�|jr|jjSy)NT)r@rG�rMs rQrGzSosNode.connectedns���?�?��?�?�,�,�,��c�8�|jj�y)zDWrapper to close the remote session via our transport agent
        N)r@rHrTs rQrHzSosNode.disconnectus��	
���"�"�$rUc���|jdvrd|_t|j|�S|jjt
j
�vr-t|jj|j|�S|jjdk7rG|jd|jj���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�autoz4Connection failed: unknown or unsupported transport )
r(rrr*�	transport�
TRANSPORTS�keysrDrr)rMr)s  rQr?zSosNode._load_remote_transportzs����<�<�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�F��9�9�&�&�'�)�
�,�D�I�I�,?�,?�@�@� ����w�7�7rUc�H�|jd|jdz�d��d|��S)N�<��z : )�	_hostnamer�rM�msgs  rQ�_fmt_msgzSosNode._fmt_msg�s-���.�.��4�<�<�!�#3�"4�@� 4�5�S���>�>rUc�^�|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_commandr`rZN)�manifest�	add_fieldrar,�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)rj�path�exists�	log_debugrk�getrTs rQrIzSosNode.check_in_container�sK���7�7�>�>�.�/��N�N�L�M��
�:�:�>�>�+�&�2��N�N�L�M��rUc���|jj�rI|jj|jj|j�|jj��}|j|d��}|ddvr�|ddk(r<d|dvr|jd	�t�d
|dvr|jd�t�|j|jj�d��}|ddk(r*|jd
|jj�d��y|jd|d���t�|jd|d���t�y)zJIf the host is containerized, create the container we'll be using
        )�image�auth�
force_pullT��	need_rootrf)r�}r�zunable to retrieve auth tokenrgzHCould not pull image. Provide either a username and password or authfilezunknown: Not foundz%Specified image not found on registryrzTemporary container z createdz(Could not start container after create: z$Could not create container on host: F)
r,rJrKr*r��get_container_auth�force_pull_imagermrDrC�restart_sos_container�log_info�sos_container_name)rM�cmd�resros    rQrKzSosNode.create_sos_container�sf���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�"8�%)�Y�Y�%A�%A�$B�(�#L�M���N�N�#M�&)�(�m�_�$6�7�#�O����E�"%�h�-�� 2�3���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|��|��}|ddk(S#t$rYywxYw)z3Checks for the presence of fname on the remote nodezstat r�rfrF)rmrC)rM�fnamer�r�s    rQ�file_existszSosNode.file_exists�sC��	��"�"�U�5�'�?�i�"�H�C��x�=�A�%�%���	��	�s� �	,�,c�f�|jrd|jvr|jS|jS)NrX)r.r(rTs rQrazSosNode._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)rMrc�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>�infordrbs  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�stackrar=r��rMrc�caller�lmsgs    rQr�zSosNode.log_infosF�������#�A�&���4�>�>�"�!�F�8�2�c�U�3��������rUc��tj�dd}d|j�d|�d|��}|jj	|�y)z$Used to print and log error messagesr_r�r�r�r�N)r�r�rar=�errorr�s    rQrDzSosNode.log_errorsF�������#�A�&���4�>�>�"�!�F�8�2�c�U�3�������$�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�rar=�debug)rMrcr�s   rQr�zSosNode.log_debugsV���$�$�S�)�������#�A�&���$�.�.�!��6�(�"�S�E�2�������#�rUc�p�|jjrdt|���S|jrd|��S|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 zsudo -S )r*�become_rootrr)rMr�s  rQ�_format_cmdzSosNode._format_cmds;���9�9� � ��E�#�J�<�(�(��>�>��c�U�#�#��
rUc�T�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�d��z
}||jd<|jdr"|jd|jd���n<|j|jj k(s|j#d�d|_y|j'd�rd|_|j(�d�}|j
|dd��}|ddk(r|j+|d	�|j'd�r|j-�y#t$r}|jd
|���Yd}~��d}~wwxYw)zLQueries the node for information about the installed version of sos
        N�.r�releaseT��
use_containerr�rfrrg�-�z.0z#Unable to fully parse sos release: zsos version is z!sos is not installed on this nodeFz4.0z
sos reportz -l�3.6)r,�container_version_command�package_manager�pkg_version�sos_pkg_name�joinrmr'rn�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���
L���3�9�9�S�>�!�,�-�.�.��$'��
�
�i� ��=�=��#��M�M�O�D�M�M�)�,D�+E�F�G��<�<�4�9�9�#4�#4�4����B�C�"�D�N���!�!�%�(�'�D�L�����c�"���"�"�3�d�d�"�K���8���!��"�"�7�8�#4�5��!�!�%�(��"�"�$���1�
L����!D�S�E�J�K�K��
L�s�0G?�?	H'�H"�"H'c�L�|j�d�}|j|dd��}|ddk(ry|dj�D]b}|j�j	d�s�#|jd�dj�}|jd	j|��dyy)
Nz --list-presetsTr�rfrrgzname:r_r")r:rm�
splitlinesr'�
startswithrnr9�append)rMr�r��line�pnames     rQr�zSosNode._load_sos_presetsSs�������o�.�����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_plugins\s���@��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�z�g}tj||tj�D]f}|j�D]Q}|s$	|j	|j�d��)|jd�}|jd�|D���S�h|S#t$r}|jd|���Yd}~�zd}~wwxYw)NrzError parsing sos help: �,c3�^K�|]%}|j�s�|j����'y�w�N)r')�.0�ps  rQ�	<genexpr>z*SosNode._regex_sos_help.<locals>.<genexpr>xs����A�Q�q�w�w�y�q�w�w�y�A�s�-�-)	r��findall�Sr�r�rnrCr��extend)	rM�regexr��is_listr��resultr�rP�rs	         rQr�zSosNode._regex_sos_helpms������j�j������6�		B�F��)�)�+�
B���I��
�
�4�:�:�<��?�3��
�
�3��A��J�J�A�!�A�A�
B�		B��
��%�I����)A�#��'G�H�H��I�s�"B�	B:�B5�5B:c��	|jd|���|jj|�S#t$r!}|j	d|�d|���Yd}~yd}~wwxYw)z1Reads the specified file and returns the contentsz
Reading file zException while reading �: Nr`)r�r@�	read_filerCrD)rM�to_readrPs   rQr�zSosNode.read_file{s\��	��M�M�M�'��3�4��?�?�,�,�W�5�5���	��N�N�5�g�Y�b���F�G���	�s�.1�	A�A�Ac
��|jr:|jd|jdj���|jdSt	i|j
jt�d|jj|jd���}|r!|jd|j�d��|S|jd�t�)	z[Attempts to identify the host installation against supported
        distributions
        zusing local policy rtTz/etc/os-release)�cache�sysroot�init�
probe_runtime�remote_exec�remote_checkzloaded policy z	 for hostz4Unable to determine host installation. Ignoring node)
rr�r)ryrr*r�rr@rmr�rDr
)rMr,s  rQrEzSosNode.determine_host_policy�s����:�:��M�M�%�d�l�l�8�&<�&C�&C�%D�E�
G��<�<��)�)��"�d�i�i�&7�&7�j�l�"&� $��� ;� ;�!%���0A�!B�D����M�M�N�4�;�;�-�y�A�B��K����M�N�&�&rUc��	|jd}t|�t|�k\S#t$r}|jd|���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``
        rzError checking sos version: NF)r9rrCrD)rMr��	_node_verrPs    rQr�zSosNode.check_sos_version�sR��	��
�
�i�0�I�$�Y�/�3D�S�3I�I�I���	��N�N�9�#��?�@���	�s�%(�	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�(�|js]|jsQ|jd�	|jj	|j
�}|s|jd�t�	|r1|jjr|jj|�}|r|j|�}|r|j}	|	j|�}|jj|||||�S#t$r}|jd|����d}~wwxYw)a�Runs a given cmd, either via the SSH session or locally

        :param cmd:     The full command to be run
        :type cmd:      ``str``

        :param timeout: Time in seconds to wait for `cmd` to complete
        :type timeout:  ``int``

        :param use_shell: If a shell is needed to run `cmd`, set to True
        :type use_shell:  ``bool`` or ``auto`` for transport-determined

        :param use_container: Run this command in a container *IF* the host
                              is a containerized host
        :type use_container: ``bool``

        :param env: Pass environment variables to set for this `cmd`
        :type env:  ``dict``
        z-Node is disconnected, attempting to reconnectzFailed to reconnect to nodez!Error while trying to reconnect: N)rGrr�r@�	reconnectr2rrCr,rJ�format_container_commandr�rr�updaterm)
rMr��timeout�	use_shellr�r��env�reconnectedrP�_cmd_envs
          rQrmzSosNode.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���}�}�H��/�/�#�&�C����*�*�3���C�+4�6�	6���
����!B�3�%�H�I���
�s�>C.�.	D�7D�Dc�&�	|j�}|r|j|�n|jd�|jr|j	�|_|j�y#t$r}|jd|���Yd}~�3d}~wwxYw)z.Run an sos report on the node, then collect itz'Unable to determine path of sos archivezError during sos execution: N)�execute_sos_command�finalize_sos_pathrDr5�retrieve_sosreportr6rC�cleanup)rMr~rPs   rQr#zSosNode.sosreport�s���		A��+�+�-�D���&�&�t�,����H�I��}�}�!%�!8�!8�!:���	
������	A��N�N�9�#��?�@�@��	A�s�AA)�)	B�2B�Bc�$�||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 noderr
rs  rQ�_check_enabledzSosNode._check_enabled�rrUc�$�||jdvS)z7Checks to see if the plugin is default disabled on noder r
rs  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)rnrrr*�enable_pluginsrr9)rM�opt�plugs   rQ�_plugin_option_existszSosNode._plugin_option_exists�sq��
�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���|jjrQ|js|jj|_n)|jd|jj�d��|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.
        zCluster specified preset z> 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�;�rriN)r-�
sos_presetrr��sos_pluginsrr�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����
�
�9�!%���!8�!8� 9�:L�L�M��<�<�#�#����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�]�]�;�;� #�u�A�d�l�l�&E�&E�c�&J�%K�L�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_pluginsrr.rrTs rQr+zSosNode._assign_config_opts9su��
!����!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
�����|jd�rP|jjr:|j
dtt|jj�����|jd�r�|jjr|j
d	�|jjr|j
d
�|jjr1|j
dt|jj����|jd�r�|jjr@|j
d
tdj|jj�����|jjr@|j
dtdj|jj�����|jd�rP|jjr:|j
dtt|jj�����|jd�s|jd�r|jj dk7r(|j
d|jj ���|jj"r(|j
d|jj"���|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������|j@rb|jC|j@�r(|j
d"t|j@����n|jEd#|j@�d$��|jF�r%|jFD�cgc]}|j;|�s�|��}}tI|�tI|jF�k7r?tKtM|jF�tM|�z
�}	|jEd%|	�d&��|jO|jF�}
|
r|j
d't|
����|�ddj|���|_(|jSd(|jP���|jTjWd)|jP�y*|jXr�|jXD�cgc]}|j[|�s�|��}}tI|�tI|jX�k7r?tKtM|jX�tM|�z
�}|jEd+|�d,��|jO|�}
|
r|j
d-t|
����|j\r�|j\D�cgc]4}||jXvr$|j_|�r|j;|�r|��6}}tI|�tI|j\�k7r?tKtM|j\�tM|�z
�}|jEd.|�d/��|jO|�}|r|j
d0t|����|�ddj|���|_(|jSd(|jP���|jTjWd)|jP�y*cc}wcc}wcc}wcc}w)1zZUse host facts and compare to the cluster type to modify the sos
        command if neededr� r��z
--threads=z3.7z--plugin-timeout=z3.8z--allow-system-changesz
--no-env-varsz--since=z4.1z--skip-commands=r�z
--skip-files=z4.2z--cmd-timeout=z4.3z4.2-13rYz--container-runtime=z
--namespaces=z4.5.2z--journal-size=z--low-priorityr#z--r`r�rriz-k c3� K�|]}|���y�wr�r)r�r%s  rQr�z+SosNode.finalize_sos_cmd.<locals>.<genexpr>�s����4E�1�Q�4E�s�z	--preset=zRequested to enable preset z" but preset does not exist on nodezRequested plugins z. were requested to be enabled but do not existz--only-plugins=zFinal sos command set to rvNzRequested to skip plugins z%, but plugins are already not enabledz--skip-plugins=zRequested to enable plugins z1, but plugins are already enabled or do not existz--enable-plugins=)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_priorityr4�replacerjr~r,�sos_bin_pathr:rr.rrnr"rrr�r7r�r6�setr&rr�rwrxr8rrr)rMr�label�sos_optsr rqr%r*�plugs�not_only�only�skip�not_skip�skipln�not_on�enables                rQ�finalize_sos_cmdzSosNode.finalize_sos_cmdDsE���-�-�	�*���(�(�*��� �	��5��<�.��2�G����!�!�%�(��y�y� � �A�%����*�U�3�t�y�y�7H�7H�3I�-J�,K� L�M��!�!�%�(��y�y�'�'����'��c�$�)�)�2J�2J�.K�(L�'M�N�P��!�!�%�(��y�y�-�-���� 8�9��y�y�$�$�����0��y�y������(�5������+A�*B� C�D��!�!�%�(��y�y�&�&���� 2�#(����$�)�)�2I�2I�)J�#K�"L�!N�O��y�y�#�#����#�E�#�(�(�4�9�9�3G�3G�*H�$I�#J�K���!�!�%�(��y�y�$�$����$�U�3�t�y�y�/D�/D�+E�%F�$G�H��
�!�!�%�(�D�,B�,B�8�,L��y�y�*�*�f�4����*�4�9�9�+F�+F�*G�H���y�y�#�#����#�D�I�I�$8�$8�#9�:���!�!�'�*��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�����#�e�C�H�H�4E��4E�,E�&F�%G� H�I��;�;��"�"�4�;�;�/����)�E�$�+�+�,>�+?� @�A����!<�T�[�[�M�J?� ?�@���� $� 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�����!3�H�:�>@� @�A��)�)�$�*;�*;�<�D�����/�%��+�� ?�@�%�Y�a�����(:�';�<�D�L��M�M�5�d�l�l�^�D�E��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�����!;�H�:�FA� A�B��+�+�D�1�F�����/�%��-�� A�B����#�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�����!=�f�X�FM� M�N��+�+�D�1�F�����"3�E�&�M�?� C�D�!��!�C�H�H�X�$6�#7�8����
�
�1�$�,�,��@�A��
�
��� 3�T�\�\�B��kE��M��L��Ls%�Ab:�b?�.b?�c�c�9c	c��d}||jj|�z
}|jjr5||s|jj�nd|jj��z
}|sy|j	d|���|jd�rd}n%d}|jjd�d	�d|��}|�d
|��S)z?Determine what, if any, label should be added to the sos reportr`r�NzLabel for sos report set to r�z--labelz--namer�rri)r-�get_node_labelr*rNr�r�r(rn)rMrN�lcmds   rQr=zSosNode.determine_sos_label�s�����
����,�,�T�2�2���9�9�?�?��%������)��t�y�y���/�0�
2�E������5�e�W�=�>��!�!�%�(��D��D��|�|�)�)�#�.�q�1�2�!�E�7�;�E���q��� � rUc�2�|jj}|r|j|d�}|j�d}|j	d|���||_|jd�d|_|jjd|j�y)z\Use host facts to determine if we need to change the sos path
        we are retrieving fromr`rzFinal sos path: �/����collected_archiveN)	r,�sos_path_striprKrnr�r5�archiverwrx)rMr~�pstrips   rQr	zSosNode.finalize_sos_path�s}�����)�)����<�<���+�D��z�z�|�A����
�
�(���/�0���
��z�z�#��r�*����
�
��� 3�T�\�\�BrUc�|�|dk(ry|dk(rd|vry|dk(ryt|�dkDr|jd	�ddSd
|��S)Nr^z+sos report process received SIGKILL on noder_�sudozsudo attempt failed�z4sos report terminated unexpectedly. Check disk spacer�
zsos exited with code )r�rn)rM�rc�stdouts   rQ�determine_sos_errorzSosNode.determine_sos_error�sV��
��8�@�
��7����,�
��9�I��v�;��?��<�<��%�a��*�*�*�2�$�/�/rUc�\�|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)rrr�r�rrfrrgz*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�rmrr*rr/r��fnmatchr'r�rnrwrxr�rir�rCrrDr�)rMr~rlr�r�rPs      rQrzSosNode.execute_sos_command�s�����.�/�(	��D��H��"�"�4�<�<�+/�9�9�+<�+<�-1�-1�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�-����H�
�� H�I���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|�d��y#t$r!}|jd|�d	|���Yd
}~yd
}~wwxYw)z7Copies the specified file from the host to our temp dirr]r^zCopying remote z
 to local zAttempting to copy remote file �%, but it does not exist on filesystemFzFailed to retrieve r�N)rrjr~r�rnr�r�r@�
retrieve_filer�rC)rMr~�destdir�destrPs     rQrvzSosNode.retrieve_file"s����+�+��#���w�w�|�|�G�T�Z�Z��_�R�%8�9��
	�����%��
�
���v�Z��y�I�J����4�4�T�4�@�@����!@���G?� ?�@����	��N�N�0���b���>�?���	�s�AB�B�	C�&C�Cc��dj|j��}	t|jd��dkr|jd|�d��y|j	|�r4|jd|���d|��}|j
|d	�
�}|ddk(S|jd
|�d��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
        r`r]r�zRefusing to remove path z0: appears to be incorrect and possibly dangerousFzRemoving file zrm -f Tr�rfrz!Attempting to remove remote file ruzFailed to remove r�N)r�rnr�r�r�r�rmrC)rMr~r�r��es     rQ�remove_filezSosNode.remove_file2s����w�w�t�z�z�|�$��	��4�:�:�c�?�#�q�(����!9�$��@E� E�F������%��
�
��t�f�5�6��t�f�o���&�&�s�d�&�;���8�}��)�)����!B�4�&�IA� A�B����	��N�N�.�t�f�B�q�c�:�;���	�s$�2B/�AB/�B/�/	C�8C�Cc�\�|js|jjr	|j|j�|jd|j���|jd�	|j|j�}|rI|jd�|jj|jjd�d�y	|jd
�y#t
$r|j
d�YywxYw#t
$r}|j
|�Yd}~yd}~wwxYw)z+Collect the sosreport archive from the nodezFailed to make archive readableFzRetrieving sos report from zRetrieving sos report...Nz!Successfully collected sos reportr]r^TzFailed to retrieve sos report)rr*r��make_archive_readabler5rCrDr�r(r�rvr8r�rn)rMrorPs   rQr
zSosNode.retrieve_sosreportIs����>�>�T�Y�Y�2�2�
��*�*�4�=�=�9�	
�
�
�3�D�L�L�>�B�C����.�/�	��$�$�T�]�]�3�C���K�K�;�<��N�N�!�!�$�-�-�"5�"5�c�":�2�">�?���K�K�7�8���!�
����@�A��
���	��N�N�3����	�s)�C'�/D�'D�D�	D+�D&�&D+c���|j�|jryd|jvr |jd|j�d��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#zNode sos report path z/ looks incorrect. Not attempting to remove pathzFailed to remove sos report)r5rr�r{rD)rM�removeds  rQ�remove_sos_archivezSosNode.remove_sos_archive`sv���=�=� �D�J�J�
��d�m�m�+��N�N�2�4�=�=�/�BF�F�
G���"�"�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_cmdrm)rM�extrs   rQrzSosNode.cleanuposm�����!��=�=�*�
���#�#�D�M�M�C�$7�8��
��)�)�+�+�-������W���5�rUc�$�|D]�}	|js|jjr	|j|�|j|�}|r?|jj|jd�d�|j|�n|jd|�����y#t$r5}|jd|���|j
d|�d|���Yd}~��d}~wwxYw#t$r!}d|��}|j|�Yd}~��d}~wwxYw)z4Collect the file created by a cluster outside of soszUnable to retrieve file zFailed to make file z readable: Nr]r^z/Error collecting additional data from primary: )rr*r�r}rCrDr�rvr8r�rnr{)rM�	filenames�filenamerProrzrcs       rQ�collect_extra_cmdzSosNode.collect_extra_cmdzs��!�	$�H�
$��>�>�T�Y�Y�%:�%:�!��2�2�8�<��(�(��2����N�N�)�)�(�.�.��*=�b�*A�B��$�$�X�.��N�N�%=�h�Z�#H�I��	$��
%�!����)A�(��'L�M����)=�h�Z�H4�47�5�(:�;� ��	!���
$�G��s�K�����s�#�#��
$�s@�"C%�B$�A&C%�$	C"�-+C�C%�C"�"C%�%	D�.D
�
Dc��d|��}|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 �
T)rr�rfrz6Exception while making %s readable. Return code was %s)rmrDrC)rM�filepathr�r�rcs     rQr}zSosNode.make_archive_readable�sZ���8�*�%�����s�B�$��?���x�=�A���J�C��N�N�3�(�C��M�!:�:�;��OrU)NNT)F)�rYFFN)5�__name__�
__module__�__qualname__rR�propertyrGrHr?rdrrr{rIrKr�r�rar�r�r�rDr�r�rLr�r�r�r�rEr�r�rmr#rrrrr"r&r(r4r+rXr=r	rirrvr{r
r�rr�r}rrUrQrr*sD��CG� �@"�D����%�
8�"?�����C�
�'�R������
3�-�� ���2�h;�P�"��'�$�$F�IN�-1�&6�P�2�E�
2�3��"C�
�&4�P	-�BC�H!�(
C�0�+�Z� �.�.
:�	6�$�,
rUr)rsr�r;rjr��shlexr�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�,��(�
� ���
�s
�s
rU