%PDF- %PDF-
Mini Shell

Mini Shell

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

�

i��dA>��D�ddlZddlmZddlmZddlmZGd�d�Zy)�N)�
ClusterOption)�bold)�Lockc���eZdZdZgZdZgZiZiZdZ	dZ
dZd�Ze
d��Ze
d��Ze
d	��Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd d�Zd�Zd�Zd�Z d�Z!d�Z"d�Z#d�Z$d�Z%d�Z&y)!�Clustera\This is the class that cluster profiles should subclass in order to
    add support for different clustering technologies and environments to
    sos-collector.

    A profile should at minimum define a package that indicates the node is
    configured for the type of cluster the profile is intended to serve and
    then additionally be able to return a list of enumerated nodes via the
    ``get_nodes()`` method


    :param commons: The commons dict containing system information. The same as
                    what is handed to ``Plugin()``
    :type commons: ``dict``


    :cvar option_list:  Options supported by the profile, and set by the
                        --cluster-option cmdline arg
    :vartype option_list: ``list`` of ``tuples``

    :cvar packages: What package(s) should this profile enable on
    :vartype packages: ``tuple``

    :cvar sos_plugins: Which plugins to forcibly enable for node reports
    :vartype sos_plugins: ``list``

    :cvar sos_options: Options to pass to report on every node
    :vartype sos_options: ``dict``

    :cvar sos_plugin_options: Plugin options to forcibly set for nodes
    :vartype sos_plugin_options: ``dict``

    :cvar sos_preset: A SoSReport preset to forcibly enable on nodes
    :vartype sos_preset: ``str``

    :cvar cluster_name: The name of the cluster type
    :vartype cluster_name: ``str``
    )�rNFc���d|_d|_|d|_|d|_|jj
g|_|jjD]7}|j
dk7s�|jj|j
��9d|_	t�|_tjd�|_tjd�|_g|_|j#�y)N�tmpdir�cmdlineoptsr�sos�sos_ui)�primary�cluster_ssh_keyr
�opts�	__class__�__name__�cluster_type�	__bases__�append�	node_listr�lock�logging�	getLogger�soslog�ui_log�options�_get_options)�self�commons�clss   �A/usr/lib/python3/dist-packages/sos/collector/clusters/__init__.py�__init__zCluster.__init__Es������#����h�'����M�*��	�!�^�^�4�4�5����>�>�+�+�	7�C��|�|�y�(��!�!�(�(����6�	7�����F��	��'�'��.����'�'��1����������c�f�|jr|jS|jj�S)z0Returns the cluster's name as a string.
        )�cluster_namer�lower)r s r!�namezCluster.nameUs,������#�#�#��|�|�!�!�#�#r#c
���|tur|j|�y|jd|jz�|jr8|jtjur|j|j�nh|jdjr>|jdtur)|j|jdj�n|jd�|jr6|jddjd�|jD��zd��|jr |jd	|jzd��|jrDdjd
�|jj�D���|jd����|jr6|jddjd
�|jD��zd��|jr<|j�dj�fd��D��}|jd|zd��|jr�|jd�}|jdt!d|j"z�z�|jt!dj%dddd��d��|jD]K}|d}t'|t(�r|rd}nd}dj%d|d||d�}|j|d���Myy)Nz %s Cluster Profile Detailed Help�z/
	Detailed help not available for this profile
z%Enabled by the following packages: %sz, c3� K�|]}|���y�w�N�)�.0�ps  r!�	<genexpr>z'Cluster.display_help.<locals>.<genexpr>qs����4�!�A�4���F��newlinez!Uses the following sos preset: %sc3�2K�|]\}}d|�d|�����y�w)z--� Nr,)r-�k�vs   r!r/z'Cluster.display_help.<locals>.<genexpr>|s ����O�t�q�!��1�#�Q�q�c�l�O�s�z Sets the following sos options: z!Enables the following plugins: %sc3� K�|]}|���y�wr+r,)r-�plugs  r!r/z'Cluster.display_help.<locals>.<genexpr>�s����=�T�D�=�r0c3�2�K�|]}|�d�|�����y�w)�=Nr,)r-�opt�_optss  �r!r/z'Cluster.display_help.<locals>.<genexpr>�s�����J�S��U�3�Z�8�J�s�z%Sets the following plugin options: %szAvailable cluster optionsz2These options may be toggled or changed using '%s'z-c %s.$option=$valuez
{:<4}{:<20}{:<30}{:<20}
r4zOption Name�Default�DescriptionzTrue/Onz	False/Offz{:<4}{:<20}{:<30}{:<20}r�)r�display_self_help�	set_titler%�__doc__�add_text�__mro__�packages�join�
sos_preset�sos_options�items�sos_plugins�sos_plugin_options�option_list�add_sectionrr�format�
isinstance�bool)r �sectionr�optsecr;�val�_lnr<s       @r!�display_helpzCluster.display_help]s�����'�>��!�!�'�*�����<��,�,�-�	.��;�;�3�;�;�g�o�o�=����S�[�[�)�
�[�[��^�
#�
#����A��g�(E����S�[�[��^�3�3�4����D�
��<�<����7��)�)�4�s�|�|�4�4�5��
�
��>�>����3�c�n�n�D��
�
�
�?�?��I�I�O�s���7L�7L�7N�O�O�E����?��w�G�H��?�?����3��)�)�=�S�_�_�=�=�>��
�
��!�!��*�*�E��9�9�J�E�J�J�D����7�$�>��
�
�
�?�?��(�(�)D�E�F��O�O�D��-����<�=�>�
�
�O�O�D�-�4�4���	�=�B��!�
�
�
���	
4���!�f���c�4�(��'��)��/�6�6�s�C��F�C�7:�1�v�?������U��3�	
4�r#c	��|jd�|jd�|jd�ddlm}ddl}|j|j
|�d�}|jd�|jdjd	d
d�d�
�|D]D}td|dz�}|jdjd	||dj�d�
��Fy)Nz*SoS Collect Cluster Profiles Detailed Helpz�
Cluster profiles are used to represent different clustering technologies or platforms. Profiles define how cluster nodes are discovered, and optionally filtered, for default executions of collector.z�Cluster profiles are enabled similarly to SoS report plugins; usually by package, command, or configuration file presence. Clusters may also define default transports for SoS collect.r)�SoSCollector�clustersz6The following cluster profiles are locally available:
z{:>8}{:<40}{:<30}r4�Namer>Fr1zcollect.clusters.%sr))
rArC�
sos.collectorrW�inspect�
_load_modules�	getmodulerNrr%)r rQrWr[rX�cluster�_secs       r!r@zCluster.display_self_help�s������F�G����
�	
�	���
K�	
�	/���-�-�g�.?�.?��.D�.8�:��	���E�	
�	����&�&�s�F�M�B��	�	
� �	�G��-���
�:�;�D����#�*�*�3��g�a�j�6M�6M�N��
�
�	r#c	��|jD]M}t|d|dj|d|j|d��}|jj|��Oy)zALoads the options defined by a cluster and sets the default valuerr)r?)r'�opt_type�valuer^�descriptionN)rLrrrrr)rr;�options   r!rzCluster._get_options�s]���#�#�	(�C�"��A���Q��9I�9I�),�Q���9J�9J�/2�1�v�7�F�
�L�L����'�		(r#c�,�d|jd�d|��S)N�[rz] )r�r�msgs  r!�_fmt_msgzCluster._fmt_msg�s�� �-�-�a�0�#�6�6r#c�X�|jj|j|��y)zUsed to print info messagesN)r�inforirgs  r!�log_infozCluster.log_info�s����������s�+�,r#c�:�|jj|�y)zUsed to print error messagesN)r�errorrgs  r!�	log_errorzCluster.log_error�s�������#�r#c�X�|jj|j|��y)zUsed to print debug messagesN)r�debugrirgs  r!�	log_debugzCluster.log_debug�s�������$�-�-��,�-r#c�X�|jj|j|��y)zUsed to print warning messagesN)r�warningrirgs  r!�log_warnzCluster.log_warn�s�������D�M�M�#�.�/r#c��|jjD]8}|j|k(s�|j|jvs�,|j
cS|jD]}|j|k(s�|j
cSy)a
        This is used to by clusters to check if a cluster option was
        supplied to sos collect

        :param option: The name of the option to fetch
        :type option: ``str``

        :returns: The value of the requested option if it exists, or ``False``
        F)r�cluster_optionsr'r^rrbr)rrdr;s   r!�
get_optionzCluster.get_option�st���9�9�,�,�	!�C��x�x�6�!�c�k�k�T�5F�5F�&F��y�y� �	!��<�<�	!�C��x�x�6�!��y�y� �	!�r#c��||_y)a�Some clusters generate and/or deploy well-known and consistent
        SSH keys across environments. If this is the case, the cluster profile
        may call this command so that subsequent node connections will use that
        key rather than prompting the user for one or a password.

        Note this will only function if collector is being run locally on the
        primary node.
        N)r)r�keys  r!�add_default_ssh_keyzCluster.add_default_ssh_key�s�� #��r#c��y)a
If there is a need to set specific options on ONLY the non-primary
        nodes in a collection, override this method in the cluster profile
        and do that here.

        :param node:        The non-primary node
        :type node:         ``SoSNode``
        Nr,�r�nodes  r!�set_node_optionszCluster.set_node_options���	
r#c��y)a`The default connection type used by sos collect is to leverage the
        local system's SSH installation using ControlPersist, however certain
        cluster types may want to use something else.

        Override this in a specific cluster profile to set the ``transport``
        option according to what type of transport should be used.
        �control_persistr,�rs r!�set_transport_typezCluster.set_transport_type
s��!r#c��y)aIf there is a need to set specific options in the sos command being
        run on the cluster's primary nodes, override this method in the cluster
        profile and do that here.

        :param node:       The primary node
        :type node:        ``SoSNode``
        Nr,r}s  r!�set_primary_optionszCluster.set_primary_optionsr�r#c�H�|j|jjk(S)a�In the event there are multiple primaries, or if the collect command
        is being run from a system that is technically capable of enumerating
        nodes but the cluster profiles needs to specify primary-specific
        options for other nodes, override this method in the cluster profile

        :param node:        The node for the cluster to check
        :type node:         ``SoSNode``
        )�addressrr}s  r!�check_node_is_primaryzCluster.check_node_is_primarys���|�|�t�|�|�3�3�3�3r#c��|jjdu}|jj||||��}|dr|djdd�|d<|S)a�Used to retrieve command output from a (primary) node in a cluster

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

        :param need_root: Does the command require root privileges
        :type need_root: ``bool``

        :param timeout:  Amount of time to allow cmd to run in seconds
        :type timeout: ``int``

        :returns: The output and status of `cmd`
        :rtype: ``dict``
        F)�get_pty�	need_root�timeout�outputz	Password:r)r�local�run_command�replace)r�cmdr�r��pty�ress      r!�exec_primary_cmdzCluster.exec_primary_cmd)s`���l�l� � �E�)���l�l�&�&�s�C�9�/6�'�8���x�=���M�1�1�+�r�B�C��M��
r#c��y)z�
        This MAY be used by a cluster to do prep work in case there are
        extra commands to be run even if a node list is given by the user, and
        thus get_nodes() would not be called
        Nr,r�s r!�setupz
Cluster.setup?s��	
r#c�`�|jD]}|jj|�s�yy)a�
        This may be overridden by clusters

        This is called by sos collect on each cluster type that exists, and
        is meant to return True when the cluster type matches a criteria
        that indicates that is the cluster type is in use.

        Only the first cluster type to determine a match is run

        :returns: ``True`` if the cluster profile should be used, or ``False``
        :rtype: ``bool``
        TF)rEr�is_installed)r�pkgs  r!�
check_enabledzCluster.check_enabledGs1���=�=�	�C��|�|�(�(��-��	�r#c��y)z�
        This may be overridden by clusters

        Perform any necessary cleanup steps required by the cluster profile.
        This helps ensure that sos does make lasting changes to the environment
        in which we are running
        Nr,r�s r!�cleanupzCluster.cleanupYr�r#c��y)aB
        This MUST be overridden by a cluster profile subclassing this class

        A cluster should use this method to return a list or string that
        contains all the nodes that a report should be collected from

        :returns: A list of node FQDNs or IP addresses
        :rtype: ``list`` or ``None``
        Nr,r�s r!�	get_nodeszCluster.get_nodescs��	
r#c�|�	|j�S#t$r }|jd|z�gcYd}~Sd}~wwxYw)NzFailed to get node list: %s)�format_node_list�	Exceptionrr)r�es  r!�
_get_nodeszCluster._get_nodesos=��	��(�(�*�*���	��N�N�8�1�<�=��I��	�s��	;�6�;�;c�`�|j|�}|jjd|�|S)aE
        Used by ``SosNode()`` to retrieve the appropriate label from the
        cluster as set by ``set_node_label()`` in the cluster profile.

        :param node: The name of the node to get a label for
        :type node: ``str``

        :returns: The label to use for the node's report
        :rtype: ``str``
        �label)�set_node_label�manifest�	add_field)rr~r�s   r!�get_node_labelzCluster.get_node_labelvs-���#�#�D�)���
�
�����/��r#c��y)z�This may be overridden by clusters profiles subclassing this class

        If there is a distinction between primaries and nodes, or types of
        nodes, then this can be used to label the sosreport archive differently
        rr,r}s  r!r�zCluster.set_node_label�s��r#c���	|j�}t|t�r!|D�cgc]}|s�|j	���}}nKt|t
�r-|D�cgc]!}|j
d�j	���#}}ntd|����tt|��}|D]%}|jd�s�|j|��'|S#t$r}td|����d}~wwxYwcc}wcc}w)z�
        Format the returned list of nodes from a cluster into a known
        format. This being a list that contains no duplicates

        :returns: A list of nodes, without extraneous entries from cmd output
        :rtype: ``list``
        z#Cluster failed to enumerate nodes: N�,z'Cluster returned unexpected node list: )�-�_�(�)rf�]�/�\)
r�r�rO�list�strip�str�split�set�
startswith�remove)r�nodes�err�nrr~s      r!r�zCluster.format_node_list�s���	I��N�N�$�E��e�T�"�,1�7�q�Q�����7�I�7�
��s�
#�7<�=�!������+�+�-�=�I�=��E�e�W�M�N�N���Y��(�	��	'�D����H�I�� � ��&�	'�����	I��A�#��G�H�H��	I��8��=s'�C�C-�C-�&C2�	C*�C%�%C*c��g}	|j�}|rTt|t�s|g}|D]<}|j�}|j	|�d|vs�)|j	|dz��>|S#t
$rY|SwxYw)a(
        Ensures that any files returned by a cluster's run_extra_cmd()
        method are properly typed as a list for iterative collection. If any
        of the files are an additional sosreport (e.g. the ovirt db dump) then
        the md5 sum file is automatically added to the list
        �	sosreportz.md5)�
run_extra_cmdrOr�r�r�AttributeError)r�filesr��
extra_files    r!�_run_extra_cmdzCluster._run_extra_cmd�s�����	��$�$�&�C��!�#�t�,��%�C�"%�:�J�!+�!1�!1�!3�J��L�L��,�"�j�0����Z�&�%8�9�	:�����	����	�s�AA,�A,�,	A9�8A9)F�)'r�
__module__�__qualname__rBrLrErJrHrKrGr%�strict_node_listr"�classmethodr'rUr@rrirlrorrrurxr{rr�r�r�r�r�r�r�r�r�r�r�r�r�r,r#r!rrs���$�L�K��H��K��K����J��L���� �$��$��D4��D4�L����B(�7�-��.�0��(	#�
�!�
�	4��,
��$
�

��
���0r#r)r�sos.optionsr�
sos.utilitiesr�	threadingrrr,r#r!�<module>r�s���%���g�gr#

Zerion Mini Shell 1.0