Current File : //usr/lib/python3/dist-packages/sos/collector/__pycache__/sosnode.cpython-312.pyc
�

-�_g͗����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�F�|j�|_||_|d|_|j	�|d|_|d|_|d|_|d|_|jj|_	|jj|_
d|_d|_d|_
d|_i|_i|_|xs|jj"|_|jj&s1|jj(s|j$|j_|r||j_d|_d|_d|_g|_dgggg|dd�|_d	|_t7j8d
�|_t7j8d�|_|j?|�|_ |j@jBr|j@jBdk7|_	|j@jE|j$�|jK�|_|j@j|_|jr|jjLrd}|jNr�|r�|js|j@jQ�y|jr!|jS�rd|j_*|jjTr|jW�|jY�y#tF$r}|jId
|����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_optsrrrr�node_config_file�inherit_config_filer�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)r3�
local_sudo�
load_facts�errs       �7/usr/lib/python3/dist-packages/sos/collector/sosnode.py�__init__zSosNode.__init__,s����}�}��������M�*��	�� � �"��h�'����y�)��� ��-���"�=�1��� $�	�	� :� :���#'�9�9�#@�#@�� ���
���	������
�������!�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�+%K=�=	L �L�L c�H�|jr|jjSy)NT)rBrI�rOs rSrIzSosNode.connectedqs���?�?��?�?�,�,�,��c�8�|jj�y)zDWrapper to close the remote session via our transport agent
        N)rBrJrVs rSrJzSosNode.disconnectxs��	
���"�"�$rWc���|jdvrd|_t|j|�S|jjt
vr-t|jj|j|�S|jjdk7rG|j
d|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�
TRANSPORTSrFrr)rOr)s  rSrAzSosNode._load_remote_transport}s����<�<�5�5��D�J�!�$�,�,��8�8��9�9���*�,��d�i�i�1�1�2�4�<�<��I�I��9�9���&�(��N�N�F��9�9�&�&�'�)�
�,�D�I�I�,?�,?�@�@� ����w�7�7rWc�H�|jd|jdz�d��d|��S)N�<��z : )�	_hostnamer�rO�msgs  rS�_fmt_msgzSosNode._fmt_msg�s-���.�.��4�<�<�!�#3�"4�@� 4�5�S���>�>rWc�^�|js�|jr/tjj	�|_|jS|jd�}|ddk(rB|dj
d�D]+}|s�|j
d�}|d|j|d<�-|jS)Nz
env --null�statusr�output��=r`)r2r�os�environ�copy�run_command�split)rO�ret�ln�_vals    rS�env_varszSosNode.env_vars�s����~�~��z�z�!#�����!2����~�~���&�&�|�4���x�=�A�%�!�(�m�1�1�&�9�:��!�$�!�x�x��}��26�q�'����t�A�w�/�	:�
�~�~�rWc��||_|jjd|j�|jjd|jj�|jjd|j
d�|jjdd�|jjd|jj�y)	z>Set the manifest section that this node will write to
        r0�policy�sos_versionr�final_sos_commandrar\N)�manifest�	add_fieldrbr.�os_release_namer;rB�name)rOrxs  rS�set_node_manifestzSosNode.set_node_manifest�s���!��
��
�
���
�D�N�N�;��
�
����$�)�)�*C�*C�D��
�
���
�t�}�}�Y�/G�H��
�
��� 3�R�8��
�
����T�_�_�-A�-A�BrWc���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)rk�path�exists�	log_debugrl�getrVs rSrKzSosNode.check_in_container�sK���7�7�>�>�.�/��N�N�L�M��
�:�:�>�>�+�&�2��N�N�L�M��rWc���|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_rootrg)r�}r�zunable to retrieve auth tokenrhzHCould 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.rLrMr*r��get_container_auth�force_pull_imagernrFrE�restart_sos_container�log_info�sos_container_name)rO�cmd�resrps    rSrMzSosNode.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��(��+�s�8�}�<����'N�O�'��
�&�&�t�y�y�'F�'F�'H�15�'�7���x�=�A�%��M�M�"8�%)�Y�Y�%A�%A�$B�(�#L�M�����I�"%�h�-�� 2�3����N�N�A�!�(�m�_�.�
/��O�rWc�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_authfilerVs rSr�zSosNode.get_container_auth�s����9�9�"�"��9�9�%�%�i�0�I�I��	�	�'�'��	�	�+�+��
��y�y�!�!�)�,�B�B��I�I�'�'�G�4�9�9�+G�+G�
�	
rWc�^�	|jd|��|��}|ddk(S#t$rYywxYw)z3Checks for the presence of fname on the remote nodezstat r�rgrF)rnrE)rO�fnamer�r�s    rS�file_existszSosNode.file_exists�sC��	��"�"�U�5�'�?�i�"�H�C��x�=�A�%�%���	��	�s� �	,�,c�f�|jrd|jvr|jS|jS)NrZ)r0r(rVs rSrbzSosNode._hostname�s(���=�=�[��
�
�=��=�=� ��|�|�rWc�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)rOrd�regs   rS�_sanitize_log_msgzSosNode._sanitize_log_msg�s��P���v�v�c�,�c�2�2rWc�X�|jj|j|��y)z:Format a ui message that includes host name and formattingN)r@�inforercs  rS�ui_msgzSosNode.ui_msg�s����������s�+�,rWc��tj�dd}d|j�d|�d|��}|jj	|�y)z#Used to print and log info messagesr`��[�:�] N)�inspect�stackrbr?r��rOrd�caller�lmsgs    rSr�zSosNode.log_infosF�������#�A�&���4�>�>�"�!�F�8�2�c�U�3��������rWc��tj�dd}d|j�d|�d|��}|jj	|�y)z$Used to print and log error messagesr`r�r�r�r�N)r�r�rbr?�errorr�s    rSrFzSosNode.log_error	sF�������#�A�&���4�>�>�"�!�F�8�2�c�U�3�������$�rWc��|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�rbr?�debug)rOrdr�s   rSr�zSosNode.log_debugsV���$�$�S�)�������#�A�&���$�.�.�!��6�(�"�S�E�2�������#�rWc��|jjdtjjd��dk(}|jr|r|S|j
jrdt|���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
        �USERr&zsu -c zsudo -S )	r2r�rkrlrr*�become_rootrr)rOr��is_roots   rS�_format_cmdzSosNode._format_cmdsq���.�.�$�$�V�R�Z�Z�^�^�F�-C�D��N���:�:�'��J��9�9� � ��E�#�J�<�(�(��>�>��c�U�#�#��
rWc�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�rgrrh�-�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�joinrnr'ro�lenrEr�r;r�r(r*�primaryrFrI�check_sos_versionr<�_load_sos_plugins�_load_sos_presets)	rO�ver�rel�pkg�pkgs�_rRr��sosinfos	         rSrNzSosNode._load_sos_info#s�������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�rgrrhzname:r`r")r<rn�
splitlinesr'�
startswithror;�append)rOr�r��line�pnames     rSr�zSosNode._load_sos_presetsWs�������o�.�����s�$�$��G���x�=�A���H�
�0�0�2�
;���:�:�<�*�*�7�3� �J�J�w�/��2�8�8�:�E��M�M�)�,�3�3�E�:�
;�rWc�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_helpr;)rOr��ENABLED�DISABLED�ALL_OPTIONS�OPTIONS�PROFILES�	enablereg�disreg�optreg�proregs           rSr�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�!rWc��g}tj||tj�D]j}|j�D]U}|s(	|j	�x}r|j|d��-|j	d�}	|jd�|	D���W�l|S#t$r}|jd|���Yd}~�~d}~wwxYw)NrzError parsing sos help: �,c3�^K�|]%}|j�s�|j����'y�w�N)r')�.0�ps  rS�	<genexpr>z*SosNode._regex_sos_help.<locals>.<genexpr>}s����A�Q�q�w�w�y�q�w�w�y�A�s�-�-)	r��findall�Sr�ror�rEr��extend)
rO�regexr��is_listr��resultr��lsrR�rs
          rSr�zSosNode._regex_sos_helpqs������j�j������6�
	B�F��)�)�+�	
B���I�!%����-�2�-��J�J�r�!�u�-���
�
�3��A��J�J�A�!�A�A�	
B�
	B��
��%�I����)A�#��'G�H�H��I�s�&B�	B>� B9�9B>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 �: Nra)r�rB�	read_filerErF)rO�to_readrRs   rSr�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 ruTz/etc/os-release)�cache�sysroot�init�
probe_runtime�remote_exec�remote_checkzloaded policy z	 for hostz4Unable to determine host installation. Ignoring node)
rr�r)rzrr*r�rrBrnr�rFr
)rOr.s  rSrGzSosNode.determine_host_policy�s����:�:��M�M�%�d�l�l�8�&<�&L�&L�%M�N�
P��<�<��)�)��"�d�i�i�&7�&7�j�l�"&� $��� ;� ;�!%���0A�!B�D����M�M�N�4�+?�+?�*@�	�J�K��K����M�N�&�&rWc��	|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)r;rrErF)rOr��	_node_verrRs    rSr�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)rOr�s  rS�is_installedzSosNode.is_installed�s,���y�y���y�y�(�(�4�4�S�9��E�ErWc�(�|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)rIrr�rB�	reconnectr4rrEr.rL�format_container_commandr�rs�updatern)
rOr��timeout�	use_shellr�r��env�reconnectedrR�_cmd_envs
          rSrnzSosNode.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_pathrFr7�retrieve_sosreportr8rE�cleanup)rOrrRs   rSr#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"�r;)rO�presets  rS�_preset_existszSosNode._preset_exists��������y�1�1�1rWc�d��t�fd�|jd|jdfD��S)z/Verifies if the given plugin exists on the nodec3�&�K�|]}�|v���
y�wr��)r��s�plugins  �rSr�z)SosNode._plugin_exists.<locals>.<genexpr>�s�����E�1�6�Q�;�E���rr )�anyr;�rOrs `rS�_plugin_existszSosNode._plugin_exists�s;����E����y�)A�)-���z�)B�)D�E�E�	ErWc�$�||jdvS)z6Checks to see if the plugin is default enabled on noderrrs  rS�_check_enabledzSosNode._check_enabled�rrWc�$�||jdvS)z7Checks to see if the plugin is default disabled on noder rrs  rS�_check_disabledzSosNode._check_disabled�s������z�2�2�2rWc���|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)rorr!r*�enable_pluginsrr;)rO�opt�plugs   rS�_plugin_option_existszSosNode._plugin_option_exists�sq��
�y�y��~�a� ���"�"�4�(��� � ��&��D�I�I�4�4�4�����t�$��$�-�-�	�2�2�2�rWc�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��orOs  �rSr�z,SosNode._fmt_sos_opt_list.<locals>.<genexpr>s�����B�a�4�+>�+>�q�+A��B�s�!�!)r�)rOr*s` rS�_fmt_sos_opt_listzSosNode._fmt_sos_opt_lists����x�x�B�4�B�B�BrWc��||_y)zVExpose the node to the cluster profile determined for the
        environment
        N)r/)rOr/s  rS�set_clusterzSosNode.set_clusters����rWc���|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  �rSr�z2SosNode.update_cmd_from_cluster.<locals>.<genexpr>2s�����;��3�!�8�;�rrjN)r/�
sos_presetrr��sos_pluginsr#r�r�sos_plugin_optionsr�plugopts�check_node_is_primary�lock�set_primary_options�set_node_options)rOr%�optionr$s   @rS�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_pluginsr#r2rrVs rSr+zSosNode._assign_config_opts>su��
!����!7�!7�8��� ����!7�!7�8���"�4�9�9�#;�#;�<����T�Y�Y�/�/�0��
��4�9�9�+�+�,��rWc	��|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-13r[z--container-runtime=z
--namespaces=z4.5.2z--journal-size=z--low-priorityr#z--rar�rrjz-k c3� K�|]}|���y�wr�r)r�r)s  rSr�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 rwNzRequested 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=)0r;�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_priorityr8�replacerkrr.�sos_bin_pathr<rr2rror&rrr�r;r�r:�setr*rr�rxryr<rr#r!)rOr�label�sos_optsr$rrr)r*�plugs�not_only�only�skip�not_skip�skipln�not_on�enables                rS�finalize_sos_cmdzSosNode.finalize_sos_cmdIsE���-�-�	�*���(�(�*��� �	��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 reportrar�NzLabel for sos report set to r�z--labelz--namer�rrj)r/�get_node_labelr*rRr�r�r(ro)rOrR�lcmds   rSrAzSosNode.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��� � rWc�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 fromrarzFinal sos path: �/����collected_archiveN)	r.�sos_path_striprOror�r7�archiverxry)rOr�pstrips   rSr
zSosNode.finalize_sos_path�s}�����)�)����<�<���+�D��z�z�|�A����
�
�(���/�0���
��z�z�#��r�*����
�
��� 3�T�\�\�BrWc�|�|dk(ry|dk(rd|vry|dk(ryt|�dkDr|jd	�ddSd
|��S)Nrbz+sos report process received SIGKILL on noder`�sudozsudo attempt failed�z4sos report terminated unexpectedly. Check disk spacer�
zsos exited with code )r�ro)rO�rc�stdouts   rS�determine_sos_errorzSosNode.determine_sos_error�sV��
��8�@�
��7����,�
��9�I��v�;��?��<�<��%�a��*�*�&�r�d�+�+rWc��|jd�	d}d}d}|jjrd|jj��}n�|jjr}|jsXd|j
j
d�d�d�}|jj|jj|�d|��}nd|jj��}|r|j�d	|��|_
|j|j|jjd
d
d
|j��}|dd
k(�r;|dj�D]s}tj|d�r|j!�}|j#d�r|j
d�d}�O|j#d�s�a|j
�d}�u|r�|j$j'd|�t)|�dk(r|j$j'dd�|St)|�dk(r|j$j'dd�|S|j$j'dd�|S|j$j'dd�|S|j+|d|d�}|j-d|d�d|d���t/|��#t0$r|j3d��t.$r.}|j5d|���|jd |����d!}~wwxYw)"z2Run sos report and capture the resulting file pathzGenerating sos report...Fraz--config-file=z/tmp/rarbz.confr>T)rrr�r�rrgrrhz*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�r*r,r-rrrorB�copy_file_to_remote�config_filerrnrr1r��fnmatchr'r�rxryr�rmr�rErrFr�)rOrrp�config_file_arg�
remote_configr�r�rRs        rSrzSosNode.execute_sos_command�s������.�/�7	��D��H� �O��y�y�)�)�$2�4�9�9�3M�3M�2N�"O�����.�.��z�z�&+�D�K�K�,=�,=�c�,B�2�,F�+G�u�$M�M��O�O�7�7��	�	�-�-�%�'�)7�}�o�&F�O�)����)>�)>�(?�@�$��"&�,�,��q��0A�B����"�"�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�FJ7�0AJ7�+J7�;J7�J7�7AJ7�7#L�)L�Lc��|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 dirrarbzCopying remote z
 to local zAttempting to copy remote file �%, but it does not exist on filesystemFzFailed to retrieve r�N)rrkrr�ror�r�rB�
retrieve_filer�rE)rOr�destdir�destrRs     rSr~zSosNode.retrieve_file5s����+�+��#���w�w�|�|�G�T�Z�Z��_�R�%8�9��		�����%��
�
���v�Z��y�I�J����4�4�T�4�@�@��N�N�<�T�F�C;�;�
<����	��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
        rarar�zRefusing to remove path z0: appears to be incorrect and possibly dangerousFzRemoving file zrm -f Tr�rgrz!Attempting to remove remote file r}zFailed to remove r�N)r�ror�r�r�r�rnrE)rOrr�r��es     rS�remove_filezSosNode.remove_fileDs����w�w�t�z�z�|�$��	��4�:�:�c�?�#�q�(����!9�$��@E� E�F������%��
�
��t�f�5�6��t�f�o���&�&�s�d�&�;���8�}��)�)��N�N�>�t�f�E=�=�
>����	��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 sos report archive from the nodezFailed to make archive readableFzRetrieving sos report from zRetrieving sos report...Nz!Successfully collected sos reportrarbTzFailed to retrieve sos report)rr*r��make_archive_readabler7rErFr�r(r�r~r:r�ro)rOrprRs   rSrzSosNode.retrieve_sosreportZs����>�>�T�Y�Y�2�2�
��*�*�4�=�=�9�	
�
�
�3�D�L�L�>�B�C����.�/�	��$�$�T�]�]�3�C���K�K�;�<��N�N�!�!�$�-�-�"5�"5�c�":�2�">�?�����3�4����
����@�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)zvRemove the sos report 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)r7rr�r�rF)rO�removeds  rS�remove_sos_archivezSosNode.remove_sos_archivepsv���=�=� �D�J�J�
��d�m�m�+��N�N�2�4�=�=�/�BF�F�
G���"�"�4�=�=�1����N�N�8�9�rWc���|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�r7r�r.�set_cleanup_cmdrn)rO�extrs   rSrzSosNode.cleanupsm�����!��=�=�*�
���#�#�D�M�M�C�$7�8��
��)�)�+�+�-������W���5�rWc�$�|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: Nrarbz/Error collecting additional data from primary: )rr*r�r�rErFr�r~r:r�ror�)rO�	filenames�filenamerRrpr�rds       rS�collect_extra_cmdzSosNode.collect_extra_cmd�s��!�	$�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�rgrz6Exception while making %s readable. Return code was %s)rnrFrE)rO�filepathr�r�rds     rSr�zSosNode.make_archive_readable�sZ���8�*�%�����s�B�$��?���x�=�A���F�����s�h��H�
�6�6�7��rW)NNT)F)�r[FFN)5�__name__�
__module__�__qualname__rT�propertyrIrJrArersr|rKrMr�r�rbr�r�r�rFr�r�rNr�r�r�r�rGr�rrnr#rrrr!r&r*r,r8r+r\rAr
rmrr~r�rr�rr�r�rrWrSrr*sD��CG� �C�J����%�
8�"?�����C�
�&�P
������
3�-�� ���2�h;�P�"
��'�$�$F�IN�-1�&6�P�2�E�
2�3��"C�
�&4�P	-�BC�H!�(
C�
,�:�x
��,�,
:�	6�$�,rWr)ryr�r=rkr��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]rrrWrS�<module>r�sc�����	�	���0�1�F�9�3�>�A�A�,��(�
� ���
�B�BrW