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

-�_g�����ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
m
Z
ddlmZddl
m
Z
ddlmZddlmZddlmZddlmZdd	lmZdd
lmZmZddlmZddlmZdd
lm Z dZ!Gd�de�Z"y)�N)�datetime)�ThreadPoolExecutor)�getpass)�Path)�quote)�fill)�
SoSCleaner)�SosNode)�
ClusterOption�str_to_bool)�SoSComponent)�bold)�__version__z/etc/sos/groups.dc	���eZdZdZdZidd�dd�dd�dd�dd�d	d
�dd�dg�d
d�dd
�dg�dg�dg�dd�dd�dd�dd�idd�dd�dg�dd�dd�d g�d!d�d"d�d#d�d$d�d%d�d&d�d'd(�d)d�d*d�d+d�d,g��id-d�d.d�d/d�d0d�d1d�d2g�d3d�d4d�d5g�d6d�d7d�d8d�d9d�d:d�d;d�d<d�d=d��id>g�d?g�d@g�dAd�dBdC�dDdE�dFdG�dHd
�dId�dJg�dKd�dLd�dMd�dNd�dOd�dPd
�dQd��d
dddddddR��Z�fdS�ZdT�ZedU��Z	edV��Z
edW��ZdX�ZedY��Z
edZ��Zd|d[�Zd\�Zd]�Zd^�Zd_�Zd`�Zda�Zdb�Zdc�Zdd�Zde�Zdf�Zdg�Zdh�Zdi�Zdj�Zdk�Zdl�Z dm�Z!dn�Z"do�Z#dp�Z$dq�Z%dr�Z&ds�Z'dt�Z(du�Z)dv�Z*dw�Z+dx�Z,dy�Z-dz�Z.d{�Z/�xZ0S)}�SoSCollectora�
    sos collect, or SoS Collector, is the formerly standalone sos-collector
    project, brought into sos natively in 4.0 and later.

    It is meant to collect sos reports from an arbitrary number of remote
    nodes, as well as the localhost, at the same time. These nodes may be
    either user defined, defined by some clustering software, or both.

    For cluster defined lists of nodes, cluster profiles exist that not only
    define how these node lists are generated but may also influence the
    sos report command run on nodes depending upon their role within the
    cluster.

    Nodes are connected to via a 'transport' which defaults to the use of
    OpenSSH's Control Persist feature. Other transport types are available, and
    may be specifically linked to use with a certain cluster profile (or, at
    minimum, a node within a certain cluster type even if that profile is not
    used).

    sos collect may be run from either a node within the cluster that is
    capable of enumerating/discovering the other cluster nodes, or may be run
    from a user's workstation and instructed to first connect to such a node
    via the --primary option. If run in the latter manner, users will likely
    want to use the --no-local option, as by default sos collect will also
    collect an sos report locally.

    Users should expect this command to result in a tarball containing one or
    more sos report archives on the system that sos collect was executed on.
    z8Collect an sos report from multiple nodes simultaneously�all_logsF�
alloptions�allow_system_changes�become_root�case_id�chroot�auto�clean�cluster_options�cluster_typeN�container_runtime�domains�disable_parsers�enable_plugins�encrypt_key��encrypt_pass�group�image�inherit_config_file�force_pull_imageT�skip_cleaning_files�jobs��journal_sizer�keywords�keyword_file�keep_binary_files�label�list_options�log_size�low_priority�map_file� /etc/sos/cleaner/default_mapping�primary�
namespaces�node_config_file�nodes�no_env_vars�no_local�
nopasswd_sudo�no_pkg_check�	no_update�only_plugins�password�password_per_node�plugopts�plugin_timeout�cmd_timeout�preset�
registry_user�registry_password�registry_authfile�
save_group�since�
skip_commands�
skip_files�skip_plugins�ssh_key�ssh_port��ssh_user�root�timeoutiX�	transport�verify�	usernames�upload�
upload_url�upload_directory�upload_user�upload_pass�
upload_method�upload_no_ssl_verify)�upload_protocol�upload_s3_endpoint�upload_s3_region�upload_s3_bucket�upload_s3_access_key�upload_s3_secret_key�upload_s3_object_prefixc����t�|�|||�tjd�g|_g|_d|_d|_d|_d|_	|jjjd�|jjj|_|jjdd�|jj!d�t#|j$dd�t'j(�|_	t-t'j.t'j(�d�D�chc]
}|d	d��c}�|_|j7�|j9�|_|j$j<s�	|j?�|jA�|jCdd
jEd�tFjHD�����|jCd|j:jK����|jM�yycc}w#t2$r|j5d
�dg|_Y��wxYw#tN$r|jQdd�YywxYw)N�?r�collectr�none�	node_list�sudo_pwr!r)zkCould not get a list of IP addresses from this hostnamne. This may indicate a DNS issue in your environmentz	127.0.0.1z
Executing � c3� K�|]}|���y�w�N�)�.0�ss  �8/usr/lib/python3/dist-packages/sos/collector/__init__.py�	<genexpr>z(SoSCollector.__init__.<locals>.<genexpr>�s����4I�1�Q�4I���zFound cluster profiles: �Exiting on user cancel�))�super�__init__�os�umask�client_listrgr4�	retrieved�clusterr�manifest�
components�add_sectionre�
collect_md�	add_field�add_list�setattr�opts�socket�gethostname�hostname�list�getaddrinfo�ip_addrs�	Exception�	log_error�_parse_options�
load_clusters�clustersr/�parse_node_strings�parse_cluster_options�	log_debug�join�sys�argv�keys�verify_cluster_options�KeyboardInterrupt�exit)�self�parser�parsed_args�cmdline_args�i�	__class__s     �roruzSoSCollector.__init__�s����
�����l�;�
�������������������� ���	
�
�
� � �,�,�Y�7��-�-�2�2�:�:������!�!�.�&�9���� � ��-�	��	�	�9�b�)��*�*�,��
�	*� �!'�!3�!3�F�4F�4F�4H�$�!O�"���!��Q��"��D�M�	
�����*�*�,��
��y�y�%�%�	
9��'�'�)��*�*�,�����C�H�H�4I����4I�,I�+J�K�L����.�t�}�}�/A�/A�/C�.D�E�G��+�+�-�&��"���	*�
�N�N�D�
�)�M�D�M�	*��*%�
9��	�	�2�C�8�
9�s7�/H%�3H �H%�
BI
� H%�%"I
�	I
�
I+�*I+c��ddl}|jj}i}|j|d�}|D]}|d|j�||d<�|S)zmLoads all cluster types supported by the local installation for
        future comparison and/or use
        rNr��)�sos.collector.clusters�	collectorr��
_load_modules�commons)r��sos�package�supported_clustersr�rzs      ror�zSoSCollector.load_clusters�sc��	&��-�-�(�(�����%�%�g�z�:���	F�G�-7�W�Q�Z����-E��w�q�z�*�	F�!�!�c��g}|jD]C}tjj|�s�#|j	|j||���E|S)z'Helper to import cluster and host types)�__path__rv�path�isdir�extend�_find_modules_in_path)�clsr��submod�modulesr�s     ror�zSoSCollector._load_modules�sP�����$�$�	H�D��w�w�}�}�T�"����s�8�8��v�F�G�	H��r�c�P�g}tjj|�r�ttj|��D]c}|jd�s�d|vr�tjj
|�\}}d|�d|��}|j|j|���e|S)aXGiven a path and a module name, find everything that can be imported
        and then import it

            path - the filesystem path of the package
            modulename - the name of the module in the package

        E.G. a path of 'clusters', and a modulename of 'ovirt' equates to
        importing sos.collector.clusters.ovirt
        z.py�__zsos.collector.�.)	rvr��exists�sorted�listdir�endswith�splitextr��_import_modules)r�r��
modulenamer��pyfile�fname�_�modnames        ror�z"SoSCollector._find_modules_in_path�s�����
�7�7�>�>�$�� ����D�!1�2�
=�����u�-���6�>���7�7�+�+�F�3���q�*�:�,�a��w�?�����s�2�2�7�;�<�
=��r�c��|jd�d}	t|t�t�|g�}tj|tj�}|j�D]}|ddvs�|j|��|S#t$r,}td|�d|jj���|�d}~wwxYw)z/Import and return all found classes in a moduler��z"Error while trying to load module z:  Nr)�SosHost�Cluster)
�split�
__import__�globals�locals�ImportError�printr��__name__�inspect�
getmembers�isclass�copy�remove)r�r��mod_short_name�module�er��mods       ror�zSoSCollector._import_modules�s���!���s�+�A�.��	�����F�H�~�>N�O�F�
�$�$�V�W�_�_�=���<�<�>�	$�C��1�v�/�/����s�#�	$�����	��6�w�i�@��k�k�*�*�+�-�
.��G��	�s�B	�		B>�'B9�9B>c���|jjsyg}t|jjt�s&|jjg|j_|jjD]�}t	|�D��cgc]
\}}|dk(s�|��}}}|jt
|��d}d}|D]]}	|}|||}	tjtj|	��d|	vrd|	vr�<|j|	jd��|}�_|t
|�k7s��|j||dzd���||j_ycc}}w#tj$rY��wxYw)arParses the given --nodes option(s) to properly format the regex
        list that we use. We cannot blindly split on ',' chars since it is a
        valid regex character, so we need to scan along the given strings and
        check at each comma if we should use the preceeding string by itself
        or not, based on if there is a valid regex at that index.
        N�,r�[�]r�)r�r7�
isinstancer��	enumerate�append�len�re�compile�escape�lstrip�error)
r�r7�noder��m�idxs�start�pos�idx�regs
          ror�zSoSCollector.parse_node_stringss@���y�y�������$�)�)�/�/�4�0�#�y�y���/�D�I�I�O��I�I�O�O�	+�D�"+�D�/�>�$�!�Q�Q�#�X�A�>�D�>��K�K��D�	�"��E��C��
��
��C��u�S�/�C��J�J�r�y�y��~�.��c�z�c��n� ��L�L����C��1��E�
��c�$�i�����T�#�a�%�&�\�*�%	+�& ��	�	���%?���x�x����s$�
E�E�7E �<"E � E6�5E6c	��|jdd�}|jdddd��|jddd	��|jd
ddd�
�|jddgd�d��|jddd��|jdddd��|jdtdd��|jdd d!dd"d#�$�|jd%dtd&�'�|jd(ddd)�
�|jd*d+dd,��|jd-d.dgd/�
�|jd0dd1��|jd2ddd3�
�|jd4tdd5��|jd6tdd7��|jd8dd9��|jd:gdd;d<�=�|jd>gdd?d@�=�|jdAddB��|jdCdD�}|jdEdFddGdH�$�|jdIdJ�K�|jdLdddM�N�|jdOtddP��|jdQdR�K�|jdSdTdUdVdW�X�|jdYddZ��|jd[dd\��|jd]d^�K�|jd_d`dadbtdc�d�|jdeddf��|jdgddh��|jdiddj��|jdkdldm�K�|jdndodptdq�'�|jdrdsddt��|jdudv�K�|jdwdxdydzdd{�|�|jd}dd~��|jddVd���|jd�dd���|jd�dd���|jd�d�td����|jd�ddd��
�|jd�ddd��
�|jd�ddd����|jd�d��K�|jd�tdd����|jd�dtd��'�|jd�ddd��
�|jd�dd���|jd�dd���|jd�dd���|jd�dd���|jd�dgd��d���|jd�ddd��N�|jd�dd���|jd�dd���|jd�dd���|jd�dd���|jd�dd���|jd�dd���|jd�dgd��d���|jd�d��}|jd�d�d�d�ddd����|jd�ddd�d��=�|jd�d�gdd¬��|jd�dgd�dŬƫ|jd�d�dgd�dʬƫ|jd�dgd�dͬƫ|jd�dd�dЬѫ|jd�ddd�dԬƫ|jd�d�d�dج|�|jd�d�gdd۬��y)�NzReport Passthru Optionsz0These options control how report is run on nodesz-az--alloptions�
store_truezEnable all sos report options)�action�helpz
--all-logszCollect logs regardless of sizez--allow-system-changesFz<Allow sos report to run commands that may alter system state)r��defaultr�z--chrootr!)r�always�neverz#chroot executed commands to SYSROOT)r��choicesr�z--container-runtimerzLDefault container runtime to use for collections. 'auto' for policy control.)r�r�z-ez--enable-pluginsr�z&Enable specific plugins for sos reportz--journal-sizerz!Limit the size of journals in MiB)�typer�r�z-kz--plugin-optionz
--plugoptsr@z&Plugin option as plugname.option=value)r��destr�z
--log-sizez7Limit the size of individual logs (not journals) in MiB)r�r�r�z--low-priorityzRun reports as low priorityz-nz--skip-pluginszSkip these pluginsz-oz--only-pluginszRun these plugins onlyz--namespaceszDlimit number of namespaces to collect output for - 0 means unlimitedz
--no-env-varsz&Do not collect env vars in sos reportsz--plugin-timeoutz#Set the global plugin timeout valuez
--cmd-timeoutz$Set the global command timeout valuez--sincezbEscapes archived files older than date. This will also affect --all-logs. Format: YYYYMMDD[HHMMSS]z--skip-commandsrIzdo not execute these commands)r�r�r�r�z--skip-filesrJzdo not collect these filesz--verifyz*perform pkg verification during collectionzCollector Optionsz.These options control how collect runs locallyz-bz--becomerzBecome root on the remote nodesz	--case-idzSpecify case number)r�z--inherit-config-filezKUse the config file from the collector for all nodes to use with sos report)r�r�r�z--node-config-filezCPath to an existing config file on the nodes to use with sos reportz--cluster-typez!Specify a type of cluster profilez-cz--cluster-optionrr�zVSpecify a cluster options used by a profile and takes the form of cluster.option=value)r�r�r�z--groupz Use a predefined group JSON filez--save-groupz%Save a resulting node list to a groupz--imagez;Specify the container image to use for containerized hosts.z--force-pull-imagez--pullT)TFzDForce pull the container image even if it already exists on the host)r�r�r�r�z--registry-userzBUsername to authenticate to the registry with for pulling an imagez--registry-passwordzBPassword to authenticate to the registry with for pulling an imagez--registry-authfilezJUse this authfile to provide registry authentication when pulling an imagez-iz	--ssh-keyzSpecify an ssh keyz-jz--jobsr)z%Number of concurrent nodes to collectz-lz--list-optionsz#List options available for profilesz--labelzAssign a label to the archivesz	--primaryz	--managerz--controllerr4z.Specify a primary node for cluster enumeration)r�r�r�z--nopasswd-sudozUse passwordless sudo on nodesz--nodeszDProvide a comma delimited list of nodes, or a regex to match againstz--no-pkg-checkz^Do not run package checks. Use this with --cluster-type if there are rpm or apt issues on nodez
--no-localz&Do not collect a report from localhostz-pz
--ssh-portzSpecify SSH port for all nodes)r�r�z
--passwordz"Prompt for user password for nodesz--password-per-nodez!Prompt for password for each nodez--presetzSpecify a sos preset to use)r��requiredr�z
--ssh-userz!Specify an SSH user. Default rootz	--timeoutz$Timeout for sos report on each node.)r�r�r�z--transportz"Remote connection transport to usez--uploadz+Upload archive to a policy-default locationz--upload-urlz&Upload the archive to specified serverz--upload-directoryz$Specify upload directory for archivez
--upload-userzUsername to authenticate withz
--upload-passzPassword to authenticate withz--upload-method)r�put�postz HTTP method to use for uploadingz--upload-no-ssl-verifyz'Disable SSL verification for upload urlz--upload-s3-endpointz#Endpoint to upload to for S3 bucketz--upload-s3-regionzRegion for the S3 bucketz--upload-s3-bucketz"Name of the S3 bucket to upload toz--upload-s3-access-keyzAccess key for the S3 bucketz--upload-s3-secret-keyzSecret key for the S3 bucketz--upload-s3-object-prefixzPrefix for the S3 object/keyz--upload-protocol)r�https�ftp�sftp�s3z$Manually specify the upload protocolzCleaner/Masking Optionsz7These options control how data obfuscation is performedz--cleanz	--cleanerz--maskrzObfuscate sensitive information)r�r�r�r�z--keep-binary-filesr-zGKeep unprocessable binary files in the archive instead of removing themz	--domainsrz$Additional domain names to obfuscatez--disable-parsersrzCDisable specific parsers, so that those elements are not obfuscated)r�r�r�r�z--skip-cleaning-filesz--skip-masking-filesr'zBList of files to skip/ignore during cleaning. Globs are supported.z
--keywordsr+zList of keywords to obfuscatez--keyword-filer,z&Provide a file a keywords to obfuscate)r�r�r�z--no-updater<z%Do not update the default cleaner mapz
--map-filer2r3z;Provide a previously generated mapping file for obfuscationz--usernamesrTzList of usernames to obfuscate)�add_argument_group�add_argument�int�strr)r�r��sos_grp�collect_grp�cleaner_grps     ro�add_parser_optionszSoSCollector.add_parser_options&s6	��
�+�+�%�>�
��	���T�>�,�"A�	�	C����\�,�"C�	�	E����5�l�%*�$8�	�	:�	���Z��%@�"G�	�	I�	���2�F�#L�	�	M�	���T�#5�h�"J�	�	L����-�C��"E�	�	G����T�#4�l�$,�:�"J�	�	L�	���\�1�3�#:�	�	;�	���-�l�%*�1N�	�	P����T�#3�H�"6�	�	8����T�#3�H�%'�":�	�	<�	���^�T�#C�	�	D�	���_�\�%*�"J�	�	L�	���/�c�4�"G�	�	I����_�3��"H�	�	J����Y��$>�	�	@�	���.��8�"1�"A�	�	C�	���^�R��".�">�	�	@�	���Z��"N�	�	P�
�/�/��<�
��	� � ��z�,�&3�&G�	!�	I�	� � ��3H� �I�� � �!8�%�(4�'M�	!�	N�	� � �!5�C�)-�'@�	!�	A�	� � �!1�&I�	!�	K�� � ��'9�&7��(>�	!�	@�
	� � ��D�&H�	!�	J�� � ���&M�	!�	O�� � ��(?�	!�	A�	� � �!5�x�)-�}�&1�'F�	!�	G�
	� � �!2�D�'K�	!�	L�	� � �!6��'K�	!�	L�	� � �!6��'M�	!�	N�	� � ��{�9M� �N�� � ��x���&M�	!�	O�� � ��'7��&K�	!�	M�� � ��&F�	!�	H�� � ��k�>�&/��'4�	!�	5�	� � �!2�<�&F�	!�	H�� � ��8�(L�	!�	N�	� � �!1�,�(?�	!�	A�	� � ��l�&N�	!�	P�� � ��|�#�&F�	!�	H�� � ��l�).�&J�	!�	L�	� � �!6�|�).�&I�	!�	K�	� � ��R�%�&C�	!�	E�� � ��&I�	!�	K�� � ��3��&L�	!�	N�� � ���S�&J�	!�	L�� � ��L�).�'1�	!�	2�	� � ���&N�	!�	P�� � �!5�t�&L�	!�	N�� � ��$�&E�	!�	G�� � ��$�&E�	!�	G�� � �!2�F�)@�&H�	!�	J�	� � �!9�5�(4�&O�	!�	#�	� � �!7��&K�	!�	M�� � �!5�t�&@�	!�	B�� � �!5�t�&J�	!�	L�� � �!9�4�&D�	!�	F�� � �!9�4�&D�	!�	F�� � �!<�d�&D�	!�	F�� � �!4�f�*0�&L�	!�	N��/�/�%�E�
��	� � ��K��&-�).�|�&G�	!�	I�	� � �!6��(4�;N�'I�	!�	J�	� � ��9�b�(0�&L�	!�	N�	� � �!4�X�)+�2C�(K�	!�	M�	� � �!8�!7��)+�2G�(H�	!�	J�
	� � ��h��&0�&E�	!�	G�	� � �!1�4�&4�&N�	!�	P�	� � ��|�).�[�&M�	!�	O�	� � ��J�)K�(?�	!�	A�	� � ��[�"�(0�&F�	!�	Hr�c��|jd�|j|j�ddddd�}|jd�|j�D]*\}}|jdd	�t	|�d
�|d��d�
��,y)NzSoS Collect Detailed HelpzInformation on cluster profileszSpecific profile informationz'Information on how connections are madezSpecific transport information)zcollect.clusterszcollect.clusters.$clusterzcollect.transportszcollect.transports.$transportz8The following help sections may be of further interest:
riz>8z<40z<30F)�newline)�	set_title�add_text�__doc__�itemsr)r��section�	hsections�hsec�values     ro�display_helpzSoSCollector.display_helps������5�6�������%�!B�)G�"K�-M�	
�	�	���G�	
�%�?�?�,�	�K�D�%�����r�(�4��:�c�*�5��+�6��
�
�	r�c�\�|jr|jj�|r|j|�	|j�|dk7r|j�|st
j|�ytj|�y#t$r|jd�Y�_wxYw)a�Used to terminate and ensure all cleanup is done, setting the exit
        code as specified if required.

        :param msg:     Log the provided message as an error
        :type msg:      ``str``

        :param error:   The exit code to use when terminating
        :type error:    ``int``

        :param force:   Use os.exit() to break out of nested threads if needed
        :type force:    ``bool``
        z/Warning: Failed to close all remote connectionsrsN)
rz�cleanupr��close_all_connectionsr��log_warnr�r�rv�_exit)r��msgr��forces    ror�zSoSCollector.exits����<�<��L�L� � �"���N�N�3��	M��&�&�(��C�<�
�L�L�N���H�H�U�O��H�H�U�O���	M��M�M�K�L�	M�s�B�B+�*B+c	��|j|jjdk7|jtt	|jj
�t	|j��|jd�|_y)zxFrom commandline options, defaults, etc... build a set of commons
        to hand to other collector mechanisms
        rP)�cmdlineopts�	need_sudo�tmpdir�hostlen�policyN)	r�rOr�maxr�r4r�rr��r�s ror�zSoSCollector._parse_options9sV��
 �9�9����+�+�v�5��k�k��3�t�y�y�0�0�1�3�t�}�}�3E�F��k�k�
��r�c	�P�g}t|jjt�s&|jjg|j_|jjr�|jjD]�}|j	d�d}|j	d�dj	d�d}	|j	d�dj	�d}|j
t|||j|����||j_y#t
$rd}Y�HwxYw)Nr�rr��=�True)	r�r�rr�r��
IndexErrorr�rr�)r�r��optionrz�namer	s      ror�z"SoSCollector.parse_cluster_optionsEs������$�)�)�3�3�T�:�)-���)B�)B�(C�D�I�I�%��9�9�$�$��)�)�3�3�

�� �,�,�s�+�A�.���|�|�C�(��+�1�1�#�6�q�9��#�#�L�L��-�a�0�6�6�8��;�E�
���!�$��u����H��

�%)��	�	�!��"�#�"�E�#�s�7%D�D%�$D%c��|jjr�|jjD]{}d}|jj�D]Z\}}|jD]F}|j
|j
k(s�|j|k(s�-d}|j||�|_�Z�\�}s-|jdj�d|j
��d�yyy)z+Verify that requested cluster options existFTz!Unknown cluster option provided: r�r�N)
r�rr�r�optionsrrz�_validate_optionr	r�)r��opt�match�clustr	rs      ror�z#SoSCollector.verify_cluster_optionsZs����9�9�$�$��y�y�0�0�
"����$(�M�M�$7�$7�$9�"�L�E�5�"'�-�-�"���8�8�v�{�{�2�s�{�{�e�7K�$(�E�(,�(=�(=�f�c�(J�C�I�!�	"�"�
"���	�	�=� �[�[�M��3�8�8�*�6�78�:��%r�c�h�|jtk(s]|j|jk(s8d}|j||j|j|jfzd�|jS|jj�}|dvr!d}|j||jzd�|dvS)aCChecks to make sure that the option given on the CLI is valid.
        Valid in this sense means that the type of value given matches what a
        cluster profile expects (str for str, bool for bool, etc).

        For bool options, this will also convert the string equivalent to an
        actual boolean value
        z.Invalid option type for %s. Expected %s got %sr�)�true�on�yes�false�off�nozUInvalid value for %s. Accepted values are: 'true', 'false', 'on', 'off', 'yes', 'no'.)r'r(r))�opt_type�boolr�rr	�lower)r�r��clir�vals     ror"zSoSCollector._validate_optionis������4�'��#�#�s�|�|�3�F���	�	�#����7�+;�+;�S�\�\� J�J�A�N��9�9���i�i�o�o����A�A�8�C��I�I�c�C�H�H�n�a�(��+�+�+r�c�:�|jj|�y)z.Log info messages to both console and log fileN)�soslog�info�r�rs  ro�log_infozSoSCollector.log_info~s��������r�c�:�|jj|�y)z.Log warn messages to both console and log fileN)r3�warningr5s  rorzSoSCollector.log_warn�s�������C� r�c�:�|jj|�y)z/Log error messages to both console and log fileN)r3r�r5s  ror�zSoSCollector.log_error�s�������#�r�c�~�tj�dd}d|�d|��}|jj|�y)z.Log debug message to both console and log filer��z[sos_collector:z] N)r��stackr3�debug)r�r�callers   ror�zSoSCollector.log_debug�s;�������#�A�&����x�r�#��/�������#�r�c
����tjjd�tjjd�t|j�D]A}tjjd|d�d|j|j
d�d���Ci�|jj
�D]�\}}|jD]u}|j�vr|�|j<�!|jD]F}|�|jjvs��|jjj|��H�w��tjjd�tjjddd	�dd
d�ddd
�ddd�ddd�d��t��fd���D]�}�|}ddjd�t|j�D��d	�d|jd�d|jjd
�dt|j�d
�d|j d
�d�}tjj|���tjjd�y)z&Display options for available clustersz;
The following clusters are supported by this installation
z@Use the short name with --cluster-type or cluster options (-c)

riz<15�30�
z/
The following cluster options are available:

r��25zOption Name�15�Typez<10�Default�10�Description�<c�"���|jSrk)rz)�x�_optss �ro�<lambda>z+SoSCollector.list_options.<locals>.<lambda>�s����a��0@�0@�r���keyz  z, c3� K�|]}|���y�wrkrl)rm�cs  rorpz,SoSCollector.list_options.<locals>.<genexpr>�s����>�Q�q�>�rqzh
Options take the form of cluster.name=value
E.G. "ovirt.no-database=True" or "pacemaker.offline=False"
N)r��stdout�writer�r��cluster_namerr!rrzr�r�r-r�r�r	�description)	r�rzr�r	r#r%�_opt�optlnrKs	        @ror/zSoSCollector.list_options�s8���	�
�
���*�	+��
�
���,�	-��d�m�m�,�	�G��J�J����G�C�=��$�-�-��"8�"E�"E�b�!I��L�
�	�
���
�
�+�+�-�	B�H�A�u��}�}�
B���8�8�5�(�&)�E�#�(�(�O�!$���B�� ��c�h�h��(?�(?�?�!�#�(�(�O�3�3�:�:�5�A�B�	
B�	B�	�
�
���M�N��
�
����	�"�~�Q�}�R�0��&���Q�y��n�A��Q��r�
#�	
�
�5�&@�A�	$�D���+�C��T�Y�Y�>�&����*=�>�>�r�B�!��8�8�B�-�q����!6�!6�s� ;�1��s�y�y�>�#�&�a�����'<�B�@�
�

�J�J���U�#�	$�	�
�
���7�	8r�c�B�tj|j�y)z8Removes the temp directory and all collected sos reportsN)�shutil�rmtreerrs ro�delete_tmp_dirzSoSCollector.delete_tmp_dir�s���
�
�d�k�k�"r�c��d}|jjr|d|jj��z
}|jjr|d|jj��z
}tjtj
�d�}	tjt_djd�td�D��}|�d|�d|��S#t$r}|jd|���Yd}~�Md}~wwxYw)	z(Generates a name for the tarball archivez
sos-collector�-z%Y-%m-%dz#Could not cast to ascii_lowercase: Nr!c3�bK�|]'}tjtj����)y�wrk)�random�choice�string�	lowercase)rmrJs  rorpz1SoSCollector._get_archive_name.<locals>.<genexpr>�s����I�1�v�}�}�V�%5�%5�6�I�s�-/�)
r�r.rr�strftime�nowr`�ascii_lowercasera�	NameErrorr�r��range)r��nstr�dt�err�rands     ro�_get_archive_namezSoSCollector._get_archive_name�s������9�9�?�?��a��	�	���(�)�)�D��9�9����a��	�	�)�)�*�+�+�D�
�
�
�x�|�|�~�z�
:��	H�%�5�5�F���w�w�I��a��I�I����q���A�d�V�$�$��	�	H��N�N�@���F�G�G��	H�s�C�	C;�C6�6C;c�t�|j�|_d}|jdz|jzdz|zS)zvReturns the path, including filename, of the tarball we build
        that contains the collected sos reports
        �gz�/z.tar.)rl�arc_namer)r��comprs  ro�_get_archive_pathzSoSCollector._get_archive_path�s;���.�.�0��
����{�{�S� �4�=�=�0�7�:�U�B�Br�c�`�d}d}|j�D]}|t||d��zdz}�|S)N�Pr!F)�replace_whitespacerA)�
splitlinesr)r�r�width�_fmt�lines     ro�_fmt_msgzSoSCollector._fmt_msg�sA�������N�N�$�	M�D��$�t�U�u�E�E��L�D�	M��r�c	��|jj}|tjj	tj�d|���tjj	t|�g}d}|D]%}tjj|�s�#|}n|�td|����|jd|���t|dd��5}tj|�}dD]=}||s�	|jd	|�d
||�d��t|j|||��?|dr@|jd
|d�d��|jjj!|d�ddd�y#1swYyxYw)a�
        Attempts to load the host group specified on the command line.
        Host groups are defined via JSON files, typically saved under
        /etc/sos/groups.d/, although users can specify a full filepath
        on the commandline to point to one existing anywhere on the system

        Host groups define a list of nodes and/or regexes and optionally the
        primary and cluster-type options.
        z.config/sos/groups.d/Nzno group definition for zLoading host group �r�utf-8��encoding)r4rzSetting option 'z' to 'z'per host groupr7zAdding �
 to node list)r�r#rvr�r�r�home�COLLECTOR_CONFIG_DIRr��OSErrorr��open�json�loadr�r7r�)r��grp�pathsr�r��hf�_grouprNs        ro�_load_group_configzSoSCollector._load_group_config�si���i�i�o�o����G�G�L�L�����(=�c�U�&C�D��G�G�L�L�-�s�3�
�����	�D��w�w�~�~�d�#����	��=��4�S�E�:�;�;����,�U�G�4�5�
�%��w�
/�		8�2��Y�Y�r�]�F�2�
9���#�;��N�N�%5�c�U�&����
�N4�$4�5��D�I�I�s�F�3�K�8�	
9�
�g���������(9��G�H��	�	���&�&�v�g��7�		8�		8�		8�s� E5�0A<E5�5E>c�j�|jj|jj|jjdt|j�d�}tj�dk7rJtjjtj�d�}tj|d��nt}tjj||d�}t|dd�	�5}t!j"||�d
d
d
�tj$|d�|S#1swY�!xYw)a
        Saves the results of this run of sos collect to a host group file
        on the system so it can be used later on.

        The host group will save the options primary, cluster_type, and nodes
        as determined by sos collect prior to execution of sos reports.
        r)rr4rr7z.config/sos/groups.dT)�exist_okr�wr}r~Ni�)r�rGr4rzrr�rgrv�getuidr�r�rr��makedirsr�r�r��dump�chmod)r��cfg�
group_pathr�r�s     ro�write_host_groupzSoSCollector.write_host_groups����I�I�(�(��y�y�(�(� �L�L�5�5�a�8��$�.�.�)�	
���9�9�;�!�������d�i�i�k�3I�J�J��K�K�
�T�2�-�J������Z��V��5��
�%��w�
/�	�2��I�I�c�2��	�
��������	�	�s�2D)�)D2c��|jj|j�|jjsS|jj
s=|j
d�d}|jj|j|��	|jjs,|jj
rr|jjr\|jjsF|j
d�d|jj�d�}t|��|j_|jdr�|jjs�|jjs�|jjs]|jj
sG|j
d�d	|jj�d
�}t|��|j_n;|jjs%|jj|j_|jj$r�|jjd
k(s�|jjrd}|j#|d�|j
d�d|jj�d�}t|��|j_d|jd<n"|j)d�d|j_|jj*r	|j-�	|jj1�|jjr"|j3�d|j_n�	d}d}d}|jj4s�t7j8�dk7r�|jjs�|jjsCd}t|�}|dk(r_|jj|�d}d|j_d}n.|jj|�d}d|j_t;d|j||��|_
|j<j?d |jj@�|j<jCd!�|j<jDjC|jj@�|jjGtI|j<jD|jj@��|jjJr�|jjJd"k(r|jLd#|_'nC|jL|jjJ|_'|jjJ|_%|j|jN_
n|jQ�|jN�+|jjDsd$}|j#|d�nN|jN�B|jjDr,|j)d%�|jLd#|_'d"|_%|j<j?d&|jJ�|jNr�|jN|j_'|jjRd'k(r)|jNjU�|j_)|jNjW�|jNjXrd|jjZsN|j
d(|jNjX�d)��|jNjX|j_-|j]�|jj^r?|jj^}	|ja�}|j)d*|�d+|���yy#t $r|j#dd�Y���wxYw#t.$r9}d|jj*�d|��}|j#|d�Yd}~��3d}~wwxYw#t $r|j#dd�Y��>wxYw#t.$r1}|j
d|���|j#dd�Yd}~��Pd}~wwxYw#t.$r!}|jcd,|�d|���Yd}~yd}~wwxYw)-Nz)password not specified, assuming SSH keyszgsos collect ASSUMES that SSH keys are installed on all nodes unless the --password option is provided.
z&password specified, not using SSH keysz"Provide the SSH password for user �: )�promptrz3non-root user specified, will request sudo passwordz=A non-root user has been provided. Provide sudo password for z on remote nodes: z
Exiting on user cancel
rsrPzkCannot become root without obtaining root password. Do not use --batch if you need to become root remotely.r�z,non-root user asking to become root remotelyzUser z5 will attempt to become root. Provide root password: FzSOption to become root but ssh user is root. Ignoring request to change user on nodezCould not load specified group �Exiting on user cancel
Tz�Local sos report generation forcibly skipped due to lack of root privileges.
Either use --nopasswd-sudo, run as root, or do not use --batch so that you will be prompted for a password
rz8Enter local sudo password to generate local sos report: r!�	localhost)�
local_sudo�
load_factsz(Unable to determine local installation: zsUnable to determine local installation. Use the --no-local option if localhost should not be included.
Aborting...
r4r7rf�jbonzFCluster type could not be determined and no nodes provided
Aborting...zCluster type could not be determined, but --nodes is provided. Attempting to continue using JBON cluster type and the node listrrzUpdating SSH key to z per clusterz
Wrote group 'z' to zCould not save group )2r�set_commonsr�r�r>r?r��ui_logr4rzr4�batchrOrr:rhr�r�r�
root_passwordr6r#r�r��pre_work�connect_to_primaryr9rvr�r
r~r�addressr}r7�set_node_manifest�getattrrr�rz�determine_clusterrR�set_transport_type�setup�cluster_ssh_keyrL�	get_nodesrGr�r�)r�rrj�
can_run_localr��skip_local_msg�gnamer�s        ro�prepzSoSCollector.preps�����������-��	�	�"�"��	�	�+�+��N�N�F�G�G�C��K�K���T�]�]�3�/�0�	9����#�#��	�	�(C�(C�(,�	�	�(9�(9� �I�I�O�O����G�H�;��)�)�,�,�-�R�1��%,�C�%8��	�	�"����k�*�4�9�9�3J�3J� �I�I�O�O��y�y�)�)�$�)�)�2M�2M��N�N�$3�4�+�+/�9�9�+=�+=�*>�?%�%�C�)0�s�(;�D�I�I�%��9�9�2�2�,0�I�I�,>�,>��	�	�)��9�9� � ��9�9�%�%��/��9�9�?�?�6�C��I�I�c�1�%����M�N��t�y�y�1�1�2�37�7��*1��*=��	�	�'�,1����[�)��
�
�I�J�(-��	�	�%��9�9�?�?�
"��'�'�)�	7��K�K� � �"��9�9����#�#�%�!%�D�I�I�� 
9� $�
�!�
�0���	�	�*�*��	�	��q�0@�04�	�	�0G�0G��9�9�?�?� .��%,�S�\�
�%��+� �K�K�,�,�^�<�,1�M�15�D�I�I�.�)-�J����(�(��8�(-�
�-1��	�	�*�&�{�D�L�L�2<�2?� A���	
���!�!�)�T�\�\�-A�-A�B����#�#�G�,������)�)�$�,�,�*>�*>�?����&�&�w�t���/D�/D�/3�|�|�/C�/C�(E�	F��9�9�!�!��y�y�%�%��/�#�}�}�V�4���#�}�}�T�Y�Y�-C�-C�D���$(�I�I�$:�$:��!�#'�<�<�D�L�L� �
�"�"�$��<�<���	�	���#�C��I�I�c�1��
�\�\�
!�d�i�i�o�o��M�M�;�
<� �=�=��0�D�L� &�D�����!�!�.�$�2C�2C�D��<�<�#'�<�<�D�L�L� ��y�y�"�"�f�,�&*�l�l�&E�&E�&G��	�	�#��L�L��� ��|�|�+�+��y�y�(�(��N�N�.�t�|�|�/K�/K�.L�M&�&�'�)-���(D�(D�D�I�I�%������9�9����I�I�(�(�E�
G��-�-�/���
�
�
�e�W�E�%��A�B�	 ��_!�	9��I�I�2�C�8�	9��.�
"�8������8I���� ���	�	�#�q�!�!��
"��!�	7��I�I�0�#�6�	7��D�
9����I�"%�� (�)��	�	�5�67�9�9��
9��h�
G����!6�u�g�R��u�E�F�F��
G�sn�F_#�?`�a
�#C.a,�:'b)�#`�`�	a�.a�a�
a)�(a)�,	b&�5&b!�!b&�)	c�2c�cc��|jjd�|js(|jjs|jdd�|jjd�|jjr�|jj��|jjr|jjsZ|jjsD|jjd|jjd|jd�d����t|j�D]2}|jjd|d|jd�d�����4|jjd�|jjs(	td	�|jjd�yy#t $r|jd
d�Yyt"$r%}|jt%|�d�Yd}~yd}~wwxYw)zuPrints a list of nodes to collect from, if available. If no nodes
        are discovered or provided, abort.
        r!zGNo nodes were detected, or nodes do not have sos installed.
Aborting...r�z1The following is a list of nodes to collect from:N�	rHrzC
Press ENTER to continue with these nodes, or press CTRL-C to quit
rrrs)r�r4rgr4�	connectedr�r��localr�r9rz�strict_node_listr�r�r��inputr�r��repr)r�r�r�s   ro�
display_nodeszSoSCollector.display_nodes�s���	
��������~�~�d�l�l�&<�&<��I�I�0�12�
4�	
�����L�M��<�<�!�!�d�l�l�&;�&;�&G��\�\�'�'�D�I�I�,>�,>��|�|�4�4���� � �����.�.�q����i�1H�0I��.I�J�K���4�>�>�*�	E�D��K�K���r�$�q����i�)@�(A��&A�!B�C�D�	E�	
��������y�y���
&��)�*���� � ��$�	��
%�
9��	�	�2�C�8��
&��	�	�$�q�'�1�%�%��
&�s�&G�H�H�&H�Hc��d}i}|jjr"t|jj�|d<|jjrd|d<|jjrd|d<|jj
rd|d<|jjr+tt|jj��|d<|jjr"t|jj�|d<|jjr"t|jj�|d	<|jjd
k7r"t|jj�|d<|j�D]\}}|d|�d
|�d
�z
}�|j�}|jd|���d|jd<||jd<|jj!d|�y)z:Configures the sos report command that is run on the nodeszsosreport --batch zcase-idr!rzall-logsrSzlog-size�sysrootrrzcompression-typez--rizInitial sos cmd set to �sos_cmd�sos_options�initial_sos_cmdN)r�rrrrrSr0r�r�r�compression_typer�rstripr�r�r~r)r�r�r��k�vs     ro�configure_sos_cmdzSoSCollector.configure_sos_cmd�s���&�����9�9���%*�4�9�9�+<�+<�%=�K�	�"��9�9���(*�K��%��9�9���&(�K�
�#��9�9���$&�K��!��9�9���&+�C��	�	�0B�0B�,C�&D�K�
�#��9�9���%*�4�9�9�+<�+<�%=�K�	�"��9�9���$)�$�)�)�*:�*:�$;�K��!��9�9�%�%��/�.3�D�I�I�4N�4N�.O�K�*�+��%�%�'�	%�D�A�q���A�3�a��s�!�}�$�G�	%��.�.�"�����0��	�:�;�"6����Y��&1����]�#����!�!�"3�W�=r�c�B�	t|jj|j�|_|jjd|jj�d��y#t$r0}|jd|���|jdd�Yd}~yd}~wwxYw)zgIf run with --primary, we will run cluster checks again that
        instead of the localhost.
        z
Connected to z, determining cluster type...z#Failed to connect to primary node: z.Could not connect to primary node. Aborting...r�N)	r
r�r4r�r�r4r�r�r�)r�r�s  ror�zSoSCollector.connect_to_primary�s���	K�"�4�9�9�#4�#4�d�l�l�C�D�L��K�K���}�T�Y�Y�->�->�,?�@/�/�
0���	K��N�N�@���D�E��I�I�F��J�J��	K�s�A"A%�%	B�.&B�Bc	�"�t|jj��}|jj�D�]N}|j|�|j|_|j�s�7|jj}|jd|�d��|D]�}t|j|j�s�$|jj}|jd|�d��|j|_|j�s�q|jd|�d|�d��|}n||_
|j�|_|j|jd<|jjd	|j���y
y
)a@This sets the cluster type and loads that cluster's cluster.

        If no cluster type is matched and no list of nodes is provided by
        the user, then we abort.

        If a list of nodes is given, this is not run, however the cluster
        can still be run if the user sets a --cluster-type manually
        zInstallation matches z, checking for layered profileszLayered profile z found. Checking installationz*Installation matches both layered profile z and base profile z), setting cluster type to layered profilerzzCluster type set to N)r�r��valuesr�r4�
check_enabledr�r�r��
issubclassrzrrr�r�r4)r��checksrz�cname�	remaining�rnames      ror�zSoSCollector.determine_cluster�sw���d�m�m�*�*�,�-���}�}�+�+�-�	�G��M�M�'�"�"�l�l�G�O��$�$�&��)�)�2�2�����!6�u�g�>2� 2�3�!'�"�I�!�)�"5�"5�w�7H�7H�I� )� 3� 3� <� <�����)9�%��A?�(?�@�,0�L�L�	�)�$�2�2�4� �N�N�,6�6;�W�<N�.3�W�5=�,=�>�'0�G�!�"� '���$+�L�L�N��!�*.�,�,����Y�'���� � �*�4�+<�+<�*=�>�@��3	r�c�~�|jr0|jj�}|jd|���|SgS)z>Collects the list of nodes from the determined cluster clusterzNode list: )rrz�
_get_nodesr�)r�r7s  ro�get_nodes_from_clusterz#SoSCollector.get_nodes_from_cluster!s:������L�L�+�+�-�E��N�N�[���0�1��L��	r�c�"�|j|jvr;|jjr%|jj	|j�|j
js;|jD],}||jvs�|jj	|��.|j�q|j
js[|jD]L}||jj|jjfvs�2|jj	|��Nttd�|jD���|_|jd|j���|jjd|j�y)zSReduce duplicate entries of the localhost and/or primary node
        if applicableNc3�&K�|]	}|s�|���y�wrkrl)rm�ns  rorpz0SoSCollector.reduce_node_list.<locals>.<genexpr>8s����!A��q�!�!A�s��zNode list reduced to rg)r�rgr�r9r�rzr�r�r4r��setr�r~r�)r�r�r�s   ro�reduce_node_listzSoSCollector.reduce_node_list)s ��
�M�M�T�^�^�+��	�	�0B�0B��N�N�!�!�$�-�-�0��|�|�,�,��]�]�
-������&��N�N�)�)�!�,�
-�
�<�<�#�D�L�L�,I�,I��^�^�
-������.�.��	�	�0A�0A�B�B��N�N�)�)�!�,�
-��c�!A�T�^�^�!A�A�B������.�t�~�~�.>�?�@���� � ��d�n�n�=r�c��|jjD]0}	tj|�}t	j
||�ry�2y#tj$r#}d}|j||||fz�Yd}~�ed}~wwxYw)z�Compares a discovered node name to a provided list of nodes from
        the user. If there is not a match, the node is removed from the listTz0Error comparing %s to provided node regex %s: %sNF)r�r7�fnmatch�	translater�r$r�r�)r�r��regexrjrs     ro�compare_node_to_regexz"SoSCollector.compare_node_to_regex<s����Y�Y�_�_�	9�E�
9��)�)�%�0���8�8�E�4�(��)�	9����8�8�
9�H�����s�d�E�3�%7�7�8�8��
9�s�+A�B�A<�<Bc����|js |jsd}|j|d�	|j�}|jj
r5|D]/�|j
��s�|jj���1n||_|jj
ro|jj
D]V�t�fd�d	D��r��|jvs�'|jd
��d��|jj���X|js�|jjd�d
}|jD]5�|�jd�d
k(s�|jj���7|jjs%|jj|j�|j!�	t#t%|jt"���}t%||j&d�|j&d<y#t$r�}|jd|���|jd�|jj
|_|jD]2�t�fd�dD��s�|jj���4Yd}~��d}~wwxYw#t(t*f$r}|jd|���Yd}~yd}~wwxYw)z4 Sets the list of nodes to collect sos reports from zaCould not determine a cluster type and no list of nodes or primary node was provided.
Aborting...r�zError parsing node list: z#Setting node list to --nodes optionc3�&�K�|]}|�v���
y�wrkrl�rmr�r�s  �rorpz)SoSCollector.get_nodes.<locals>.<genexpr>^s�����J�Q�q�D�y�J���)�*�\�?�(�)roNc3�&�K�|]}|�v���
y�wrkrlr�s  �rorpz)SoSCollector.get_nodes.<locals>.<genexpr>ds�����6�Q�q�D�y�6�r�z*\?()/[]z
Force adding r�r�rrMrzCould not set UI spacing: )r4rzr�r�r�r7r�rgr�r�r��anyr�r�r�r�r�r�rr��	TypeError�
ValueError)r�rr7r��host�	_node_maxrjr�s       @ror�zSoSCollector.get_nodesIsN����|�|�D�L�L�F�C�
�I�I�c�1��	0��/�/�1�E��y�y���!�4�D��1�1�$�7����-�-�d�3�4�"'����9�9�?�?��	�	���
0���6�+�6�6���t�~�~�-��N�N�]�4�&�
�#F�G��N�N�)�)�$�/�
0��|�|��=�=�&�&�s�+�A�.�D����
0���4�:�:�c�?�1�-�-��N�N�)�)�$�/�
0��<�<�0�0����%�%�d�m�m�4�����	?��C����C�8�9�I�&)�)�T�\�\�)�5L�&M�D�L�L��#��9�	0��N�N�6�q�c�:�;��N�N�@�A�!�Y�Y�_�_�D�N����
0���J�*I�J�J��N�N�)�)�$�/�
0��		0��:�:�&�	?��N�N�7��u�=�>�>��	?�s=�<H�,%H�A
J3�	J0�$A#J+�J+�+J0�3K �K�K c��	t|d|j|d��}|j|j�|jrv|j
j
|�|jjj|d�|jt|jj|d��y|j�y#t$rYywxYw)z�Try to connect to the node, and if we can add to the client list to
        run sos report on

        Positional arguments
            node - a tuple specifying (address, password). If no password, set
                   to None
        rr�)r>N)r
r��set_clusterrzr�rxr�r~r7r}r�r��
disconnectr�)r�r��clients   ro�_connect_to_nodezSoSCollector._connect_to_nodeys���	��T�!�W�d�l�l�T�!�W�E�F����t�|�|�,����� � �'�'��/����%�%�1�1�$�q�'�:��(�(�����1F�1F�15�a��*:�;��!�!�#���	��	�s�B:C�=C�	C�Cc���d}|jjdt�d��|j||jz�}|jj|�d}|j
js(	t|�|jjd�y	y	#t$r|jdd�Yy	t$r}|j|d�Yd	}~y	d	}~wwxYw)
zmPrint the intro message and prompts for a case ID if one is not
        provided on the command line
        ahThis utility is used to collect sos reports from multiple nodes simultaneously. Remote connections are made and/or maintained to those nodes via well-known transport protocols such as SSH.

An archive of sos report tarballs collected from the nodes will be generated in %s and may be provided to an appropriate support representative.

The generated archive may contain data considered sensitive and its content should be reviewed by the originating organization before being passed to any third party.

No configuration changes will be made to the system running this utility or remote systems that it connects to.
z
sos collect (version z)
z,
Press ENTER to continue, or CTRL-C to quit
r!rrrsr�N)r�r4rrzrr�r�r�r�r�r�)r��
disclaimer�	intro_msgr�r�s     ro�introzSoSCollector.intro�s����
�	
�����2�;�-�s�C�D��M�M�*�t�{�{�":�;�	�������#�A���y�y���
 ��f�
���� � ��$���%�
9��	�	�2�C�8��
 ��	�	�!�Q����
 �s�8&B � C!�=C!�C�C!c��|jjr |j�|j�|j�|jjr(|jj
r|jdd�|j
�|j�|j�|j�|_
|j|j��|jj�|_|jjdd�|j!�|j�y)Nz�
sos-collector was called with incompatible options --batch and --password.
If you need to use --password, please omit batch mode.
r�)r�sos_logsi�)r�r/r�r�r�r>r�r�r�rl�archive_name�
setup_archive�archive�get_archive_path�archive_pathr�rers ro�executezSoSCollector.execute�s����9�9�!�!������I�I�K��
�
���9�9�?�?�t�y�y�1�1��I�I�-��	
�	
��� ��	�	������ �2�2�4������� 1� 1��2� �L�L�9�9�;��������j�%�0������	�	�r�c�|
�t|jj|jjg�}|jjr_|jt|j��s|jjs%|jj|j�|jjd�|jD�cgc]}||vs�|df��
}}|jjrLg}|D]C}d|jj�d|d�d�}t!|�}|j|d|f��E|}	t#|jj$�}|j'|j(|d��|j+d	�
�|jj,r7|jdjdk(r|jj/d�t1|j�|_|j2dk(r|j5dd�n=|j2dk(r.|jdjdk(r|j5d
d�|jjd|j2�d|jj$�d��t#|jj$�}	|	j'|j6|jd��|	j+d	�
�t#|jj$�}|j'|j8|jd��|j+d	�
�t?|jd�rR|jjd�|jjA�}|r|jjC|�d}|jE||jF|j2fz�|jI�|jFdkDr|jK�|_&nd}|j5|d�|jjNr|jPjS�s|jjTrB	|jPjW|jL�|jjd�yycc}w#t:$r|j5ddd	��Y���t<$r$}
d|
��}|j5|dd	��Yd}
~
���d}
~
wwxYw#t<$r(}
|jjYd|
���Yd}
~
yd}
~
wwxYw)zY For each node, start a collection thread and then tar all
        collected sos reports z
Connecting to nodes...NzPlease enter the password for �@rr�r�)�	chunksizeT)�waitr�zNo nodes connected. Aborting...z�Collection would only gather from localhost due to failure to either enumerate or connect to cluster nodes. Assuming single collection from localhost is not desired.
Aborting...z*
Beginning collection of sos reports from z  nodes, collecting a maximum of z concurrently
r�rs)rzCould not connect to nodes: �
run_extra_cmdz/Collecting additional data from primary node...z+
Successfully captured %s of %s sos reportsz4No sos reports were collected, nothing to archive...zUploaded archive successfullyzUpload attempt failed: )-r�r4r�r�r��intersectionrgrzr�rxr�r�r4r�r?rOrrr(�mapr��shutdownr9�popr��
report_numr��_finalize_sos_cmd�_collectr�r��hasattr�_run_extra_cmd�collect_extra_cmdr6ryr
�create_cluster_archiverprUr�get_upload_urlr]�upload_archiver�)r��filtersr�r7�_nodesr�r�node_pwd�pool�npoolrj�filess            rorezSoSCollector.collect�s7���t�|�|�+�+�T�\�\�-B�-B�C�D���<�<�!�!��%�%�c�$�.�.�&9�:��\�\�2�2����#�#�D�L�L�1������3�4�$(�N�N�G�q�a�w�6F�!�T��G��G��9�9�&�&��F��
3��7��	�	�8J�8J�7K�1��q�'��"�&��"�3�<���
�
�t�A�w��1�2�	
3�
�E�&	*�%�d�i�i�n�n�5�D��H�H�T�*�*�E�Q�H�?��M�M�t�M�$��	�	�"�"��$�$�Q�'�/�/�;�>�� � �$�$�Q�'�!�$�"2�"2�3�D�O����!�#��	�	�;�Q�?����A�%��#�#�A�&�.�.�+�=��I�I�&�()��
�K�K���J� $���0�1#�#'�9�9�>�>�"2�/�C�
D�'�t�y�y�~�~�6�E��I�I�d�,�,�d�.>�.>�!�I�L��N�N��N�%�%�d�i�i�n�n�5�D��H�H�T�]�]�D�$4�$4��H�B��M�M�t�M�$��4�<�<��1��K�K���N�O��L�L�/�/�1�E�����.�.�u�5�<���
�
�c�T�^�^�T�_�_�=�=�>��"�"�$��>�>�A�� �7�7�9�D�M�H�C��I�I�c�1���I�I������!;�!;�!=��	�	�,�,�
C����*�*�4�=�=�9���� � �!@�A�-��EH��Z!�	C��I�I�0�#�T�I�B��	*�0���6�C��I�I�c�1�D�I�)�)��	*��.�
C����!�!�$;�C�5�"A�B�B��
C�sD�	R6�R6�	HR;�4AT
�;T�T�#T�T�
	T;�T6�6T;c��	|j�y#t$r+}|jd|j�d|���Yd}~yd}~wwxYw)z�Calls finalize_sos_cmd() on each node so that we have the final
        command before we thread out the actual execution of sos
        z#Could not finalize sos command for r�N)�finalize_sos_cmdr�r�r��r�r�rjs   rorzSoSCollector._finalize_sos_cmd#sL��	7��#�#�%���	7��N�N�@�$�n�n�-�R��u�6�
7�
7��	7�s��	A�!A�Ac�$�	|js|j�n&|jjs|j�|jr|xjdz
c_yy#t
$r}|j
d|���Yd}~yd}~wwxYw)zRuns sos report on each noder�zError running sos report: N)r��	sosreportr�r9ryr�r�rs   rorzSoSCollector._collect-sv��		?��<�<�� � �"��y�y�)�)��$�$�&�������!�#�� ���	?��N�N�7��u�=�>�>��	?�s�A$A(�(	B�1B
�
Bc��|jD]=}|js�|jd|j���|j	��?y)zClose all sessions for nodeszClosing connection to N)rxr�r�r�r�)r�r�s  ror
z"SoSCollector.close_all_connections:sE���&�&�	$�F�������!7����7G�H�I��!�!�#�	$r�c��
�d}g}|jD]$}|jD]}|j|���&d}|jjr�|j
|j|j|j|jd�}	|jjd�td|��}|j|j�|j�\}}d}	|j!d�|D]�}|j#d	�d
}	|rj%|	�}	t&j(j+|j|�}
|j,j/|
|	��|s�tj1|�}|s��t&j(j+d|j#d	�d
�}
|
d
z
}
|j,j3||
���|j,j/|j4t&j(j+dd���|j,j/|j6t&j(j+dd���|j�/|j,j9|jj:�|j=�|r�t&j(j+|j|j,j>�}jAt&j(j+|dd�d��|jAt&j(j+|dd�d��|jAt&j(j+|dd�d��|j,jC|jj:�}
t&j(j+|jt&j(jE|
��}|r!j%|jGdd��}t'jH|
|�|rzj%t&j(j+|j|jJ�d���}t'jH||�|jjd|���|jLjd|���|jjd�|jjd|�d��|S#t$r)}|jjd|���Yd}~��Nd}~wwxYw#t$r.}d|�d|jN��}|jQ|d�Yd}~yd}~wwxYw) zcCalls for creation of tar archive then cleans up the temporary
        files created by sos collectNF)rr�sys_tmpr!r{r!T)�in_place�hook_commonsz$ERROR: unable to obfuscate reports: z"Creating archive of sos reports...ro���)r��	checksumsz.sha256r�zsos.logzui.log)�
short_name�sos_reportsz
manifest.jsonz.tarz-obfuscated.tar�_private_mapz2A mapping of obfuscated elements is available at
	zArchive created as zP
The following archive has been created. Please provide it to your support team.r�rAzCould not finalize archive: z.

Data may still be available uncompressed at r�z
Archive error))rx�	file_listr�r�rrrrr{r�r4r	�set_target_pathr�r�r�r6r��obfuscate_stringrvr�r�r��add_file�get_new_checksum�
add_string�sos_log_file�sos_ui_log_file�add_final_manifest_datar��_obfuscate_upload_passwords�_name�obfuscate_file�finalize�basename�replace�renamer�r3r�r�)r�r2�	arc_pathsr�r��do_cleanr�cleanerrjr�r�checksum�_dirrp�
final_name�map_namers                 rorz#SoSCollector.create_cluster_archiveAs������	��$�$�	(�D����
(��� � ��'�
(�	(����9�9�?�?��+�+��+�+��<�<��9�9� �M�M��L�
P���� � ��$�$�d�2>�@���'�'����4�&-�o�o�&7�#��)���E	#��M�M�>�?�"�
@���{�{�3�'��+���"�3�3�D�9�D��w�w�|�|�D�K�K��7�����%�%�d��%�6��&�7�7��>�H��!�w�w�|�|�K����S�9I�"�9M�N���	�)�����/�/��$�?�
@�
�L�L�!�!�$�"3�"3�')�w�w�|�|�J�	�'J�
"�
L��L�L�!�!�$�"6�"6�')�w�w�|�|�J��'I�
"�
K��}�}�(����4�4��I�I�.�.��
�,�,�.���w�w�|�|�D�K�K����1C�1C�D���&�&��G�G�L�L��z�9�=�(�'���&�&��G�G�L�L��z�8�<�'�'���&�&��G�G�L�L��}�o�F�.�'��
�|�|�,�,�T�Y�Y�-G�-G�H�H������d�l�l�B�G�G�4D�4D�X�4N�O�J��$�5�5��&�&�v�/@�A��
�
�I�I�h�
�+��#�3�3��G�G�L�L����$(�$5�$5�#6�l�!C�E����	�	�(�H�-���� � �"4�4<�:�"?�@�
�K�K���2�:�,�?�@��K�K���G�
H��K�K���r�*��R�0�1����E�
P����!�!�$H���"N�O�O��
P��F�	#�1�#��70�04�0A�0A�/B�D�C��I�I�c�1��"��	#�s?�AT�$BT9�+T9�?NT9�	T6�
T1�1T6�9	U0�$U+�+U0)NrF)1r��
__module__�__qualname__r�desc�arg_defaultsrur��classmethodr�r�r�r�r�r
r�r�r�r�r"r6rr�r�r/rZrlrrrzr�r�r�r�r�r�r�r�r�r�r�r�r�r�rerrr
r�
__classcell__)r�s@rorr(s!����<F�D�L��E�L��e�L�	��L�	�u�	L�
	�5�L�	�&�
L�	��L�	�2�L�	��L�	�V�L�	�2�L�	�2�L�	�"�L�	�r�L�	��L� 	��!L�"	��#L�$	�u�%L�&	�D�'L�(	�r�)L�*	��+L�,	��-L�.	�B�/L�0	��1L�2	�U�3L�4	��5L�6	��7L�8	�A�9L�:	��;L�<	�6�=L�>	�2�?L�@	�d�AL�B	�D�CL�D	��EL�F	�u�GL�H	�E�IL�J	��KL�L	��ML�N	�U�OL�P	��QL�R	�E�SL�T	�U�UL�V	�B�WL�X	�$�YL�Z	�t�[L�\	�"�]L�^	��_L�`	�T�aL�b	�T�cL�d	�b�eL�f	��gL�h	��iL�j	�b�kL�l	��mL�n	�2�oL�p	�B�qL�r	�F�sL�t	�3�uL�v	�V�wL�x	�%�yL�z	�R�{L�|	�%�}L�~	�d�L�@	�D�AL�B	�t�CL�D	�t�EL�F	��GL�H	��IL�J"�"� � � $� $�#'�WL�L�\09�d
"���������,�
��
� �B�^H��^H�@����&�<

�)�*
:�,�*�!���&8�P#�%�"C��$8�L�4SG�j&�@>�>
K�#�J�>�&�.?�`�, �B�6VC�p7�?�$�a#r�r)#r�r�r�rvr^r�r`r�rXr�r�concurrent.futuresrr�pathlibr�shlexr�textwrapr�sos.cleanerr	�sos.collector.sosnoder
�sos.optionsrr�
sos.componentr
�
sos.utilitiesrr�rr�rrlr�ro�<module>rEs]�����	�
�	�
�
�
�
��1�����"�)�2�&���*��z#�<�z#r�