%PDF- %PDF-
Mini Shell

Mini Shell

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

�

i��d�U���ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZm
Z
mZmZmZmZmZddlmZddlmZmZmZmZddlmZmZddlmZddlm Z!dd	l"m#Z#d
�Z$idddddfd
�Z%Gd�d�Z&y)�N)�getpwuid)�	NO_PRESET�GENERIC_PRESETS�PRESETS_PATH�PresetDefaults�DESC�NOTE�OPTS)�PackageManager)�ImporterHelper�
import_module�get_human_readable�bold)�IndependentPlugin�ExperimentalPlugin)�
SoSOptions)�_sos)�fillc�L�d|z}	t|t�S#t$rYywxYw)Nzsos.policies.distros.%s)r
�Policy�ImportError)�name�
policy_fqnames  �7/usr/lib/python3/dist-packages/sos/policies/__init__.py�
import_policyrs0��-��4�M���]�F�3�3������s��	#�#T�c��d|vr|jd�Sddl}t|jj�}|j�D]4}t
|�D]$}	|	j|��s�|	||||��|d<�&�6tjdk7rtd��d|vr'|jjj�|d<|dS)N�policyr)�remote)�sysroot�init�
probe_runtime�remote_exec�linuxz%SoS is not supported on this platform)�get�sos.policies.distrosr�policies�distros�get_modulesr�check�sys�platform�	Exception�GenericLinuxPolicy)
�cacher r!r"r#�remote_check�sos�helper�modulers
          r�loadr4s����5���y�y��"�"��
�C�L�L�0�0�
1�F��$�$�&�B��#�F�+�	B�F��|�|�<�|�0�"(��t�7D�5@�#B��h��	B�B��|�|�w���?�@�@��u���,�,�.�.�A�A�C��h����?��c�\�eZdZdZed�ZdZdZdgZdZ	dZ
dZdZde
�iZeZdZd*d
�Zd+d�Zed��Zed
��Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd,d�Z d�Z!d�Z"d�Z#d�Z$d�Z%d�Z&d�Z'd�Z(d�Z)ed ��Z*		d-d!�Z+d"�Z,d#�Z-d,d$�Z.d%�Z/d&�Z0d.d'�Z1d	d	d	e2�fd(�Z3d+d)�Z4y	)/ra/Policies represent distributions that sos supports, and define the way
    in which sos behaves on those distributions. A policy should define at
    minimum a way to identify the distribution, and a package manager to allow
    for package based plugin enablement.

    Policies also control preferred ContainerRuntime()'s, upload support to
    default locations for distribution vendors, disclaimer text, and default
    presets supported by that distribution or vendor's products.

    Every Policy will also need at least one "tagging class" for plugins.

    :param sysroot: Set the sysroot for the system, if not /
    :type sysroot: ``str`` or ``None``

    :param probe_runtime: Should the Policy try to load a ContainerRuntime
    :type probe_runtime: ``bool``

    :param remote_exec:     If this policy is loaded for a remote node, use
                            this to facilitate executing commands via the
                            SoSTransport in use
    :type remote_exec:      ``SoSTranport.run_command()``

    :cvar distro: The name of the distribution the Policy represents
    :vartype distro: ``str``

    :cvar vendor: The name of the vendor producing the distribution
    :vartype vendor: ``str``

    :cvar vendor_urls: List of URLs for the vendor's website, or support portal
    :vartype vendor_urls: ``list`` of ``tuples`` formatted
        ``(``description``, ``url``)``

    :cvar vendor_text: Additional text to add to the banner message
    :vartype vendor_text: ``str``

    :cvar name_pattern: The naming pattern to be used for naming archives
                        generated by sos. Values of `legacy`, and `friendly`
                        are preset patterns. May also be set to an explicit
                        custom pattern, see `get_archive_name()`
    :vartype name_pattern: ``str``
    apThis command will collect system configuration and diagnostic information from this %(distro)s system.

For more information on %(vendor)s visit:

  %(vendor_urls)s

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.

%(changes_text)s

%(vendor_text)s
�Unknown)zExample URLzhttp://www.example.com/rz</usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin�legacyFNc�\�tjd�|_tjd�|_|j	�d|_||_t�|_tg|_
||_|js|j�||_
|jt�y)aJSubclasses that choose to override this initializer should call
        super() to ensure that they get the required platform bits attached.
        super(SubClass, self).__init__(). Policies that require runtime
        tests to construct PATH must call self.set_exec_path() after
        modifying PATH in their own initializer.r1�sos_uiN)�logging�	getLogger�soslog�ui_log�_parse_uname�case_idr"r�package_managerr�valid_subclassesr#�
set_exec_pathr �register_presetsr)�selfr r"r#s    r�__init__zPolicy.__init__}s����'�'��.����'�'��1����������*���-�/���!2� 3���&��������� �������o�.r5c��y)a�
        This function is responsible for determining if the underlying system
        is supported by this policy.

        If `remote` is provided, it should be the contents of os-release from
        a remote host, or a similar vendor-specific file that can be used in
        place of a locally available file.

        :returns: ``True`` if the Policy should be loaded, else ``False``
        :rtype: ``bool``
        F�)rErs  rr*zPolicy.check�s��r5c��t|d�sXg|_|jjD]8}t|d�s�|jj	|j���:t
t|j��S)a#This property is used to determine the list of forbidden paths
        set by the policy. Note that this property will construct a
        *cumulative* list based on all subclasses of a given policy.

        :returns: All patterns of policy forbidden paths
        :rtype: ``list``
        �_forbidden_paths�set_forbidden_paths)�hasattrrJ�	__class__�__mro__�extendrK�list�set)rE�clss  r�forbidden_pathszPolicy.forbidden_paths�sr���t�/�0�$&�D�!��~�~�-�-�
L���3� 5�6��)�)�0�0��1H�1H�1J�K�
L��C��-�-�.�/�/r5c�
�gd�S)z�Use this to *append* policy-specifc forbidden paths that apply to
        all plugins. Setting this classmethod on an invidual policy will *not*
        override subclass-specific paths
        )z*.eggz*.pycz*.pyoz*.swprH)rRs rrKzPolicy.set_forbidden_paths�s��
�	
r5c��|jS)z�Are we running inside a container?

        :returns: ``True`` if in a container, else ``False``
        :rtype: ``bool``
        )�
_in_container�rEs r�in_containerzPolicy.in_container�s���!�!�!r5c��y)z'
        Return the OS version
        NrHrWs r�dist_versionzPolicy.dist_version����	
r5c��ddlm}|S)zb
        Return the class object of the prefered archive format for this
        platform
        r)�TarFileArchive)�sos.archiver])rEr]s  r�get_preferred_archivezPolicy.get_preferred_archive�s
��
	/��r5c���|j�jd�d}|j}|jdj}d}djd�t
d�D��}|jdk(rd}|rd|znd}d	}n2|jd
k(rd}|rd|znd}|rd|znd}d
}n|j}|j|||||��}|jtj|��S)aq
        This function should return the filename of the archive without the
        extension.

        This uses the policy's `name_pattern` attribute to determine the name.
        There are two pre-defined naming patterns - `legacy` and `friendly`
        that give names like the following:

        * legacy - `sosreport-tux.123456-20171224185433`
        * friendly - `sosreport-tux-mylabel-123456-2017-12-24-ezcfcop.tar.xz`

        A custom name_pattern can be used by a policy provided that it
        defines name_pattern using a format() style string substitution.

        Usable substitutions are:

            * name  - the short hostname of the system
            * label - the label given by --label
            * case  - the case id given by --case-id or --ticker-number
            * rand  - a random string of 7 alpha characters

        Note that if a datestamp is needed, the substring should be set
        in `name_pattern` in the format accepted by ``strftime()``.

        :returns: A name to be used for the archive, as expanded from
                  the Policy `name_pattern`
        :rtype: ``str``
        �.r�cmdlineoptsrc3�bK�|]'}tjtj����)y�w�N)�random�choice�string�ascii_lowercase)�.0�xs  r�	<genexpr>z*Policy.get_archive_name.<locals>.<genexpr>�s����O��v�}�}�V�%;�%;�<�O�s�-/�r8zsosreport-{name}{case}{date}z
-%Y%m%d%H%M%S�friendlyz*sosreport-{name}{label}{case}{date}-{rand}�-z	-%Y-%m-%d)r�label�case�date�rand)�get_local_name�splitr@�commonsro�join�range�name_pattern�format�sanitize_filename�time�strftime)rErrprorqrr�nstrs       r�get_archive_namezPolicy.get_archive_name�s���:�"�"�$�*�*�3�/��2���|�|�����]�+�1�1�����w�w�O�e�A�h�O�O������(�1�D�!%�3��:�2�D�"�D�
�
�
�*�
,�?�D�!%�3��:�2�D�#(�C�%�K�b�E��D��$�$�D��{�{�������
���%�%�d�m�m�D�&9�:�:r5c��|SrdrH)rE�binarys  r�_get_pkg_name_for_binaryzPolicy._get_pkg_name_for_binarys���
r5c�2�|stj�S|Srd)�tempfile�
gettempdir)rE�opt_tmp_dirs  r�get_tmp_dirzPolicy.get_tmp_dirs����&�&�(�(��r5c��|jSrd)�default_scl_prefixrWs r�get_default_scl_prefixzPolicy.get_default_scl_prefixs���&�&�&r5c�p�t|�dkDr$|D]}t||jd�s�|cS|dS)azDetermine what subclass of a Plugin should be used based on the
        tagging classes assigned to the Plugin

        :param plugin_classes: The classes that the Plugin subclasses
        :type plugin_classes: ``list``

        :returns: The first tagging class that matches one of the Policy's
                  `valid_subclasses`
        :rtype: ``PluginDistroTag``
        �r)�len�
issubclassrB)rE�plugin_classes�ps   r�match_pluginzPolicy.match_pluginsI���~���"�#�
���a��!6�!6�q�!9�:��H�
��a� � r5c�l��tg|jz}|r
|tgz
}t�fd�|D��S)a#
        Verifies that the plugin_class should execute under this policy

        :param plugin_class: The tagging class being checked
        :type plugin_class: ``PluginDistroTag``

        :returns: ``True`` if the `plugin_class` is allowed by the policy
        :rtype: ``bool``
        c3�6�K�|]}t�|����y�wrd)r�)ri�class_�plugin_classs  �rrkz)Policy.validate_plugin.<locals>.<genexpr>8s �����/���l�F�3�/�s�)rrBr�any)rEr��experimentalrBs `  r�validate_pluginzPolicy.validate_plugin+sE���.�.��1F�1F�F����!3� 4�4���/�-�/�/�	/r5c��y)z>
        This function is called prior to collection.
        NrHrWs r�pre_workzPolicy.pre_work;r[r5c��y)zQ
        This function is called after the sosreport has been generated.
        NrHrWs r�	post_workzPolicy.post_workAr[r5c�8�|jj|�S)z�Wrapper to retrieve a package from the Policy's package manager

        :param pkg: The name of the package
        :type pkg: ``str``

        :returns: The first package that matches `pkg`
        :rtype: ``str``
        )rA�pkg_by_name)rE�pkgs  rr�zPolicy.pkg_by_nameGs���#�#�/�/��4�4r5c��tj�\}}}}}}||_||_||_|j�ddk(|_||_y)Nr��SMP)r,�uname�system�hostname�releasert�smp�machine)rEr��noder��versionr��	processors       rr?zPolicy._parse_unameRsQ��(0���(8�	&���w�	�'�9������
�����=�=�?�1�%��.�����r5c��||_y)z9Set common host data for the Policy to reference
        N)ru)rErus  r�set_commonszPolicy.set_commons[s����r5c�*�|tjd<y)N�PATH)�os�environ)rE�paths  r�	_set_PATHzPolicy._set_PATH`s��!��
�
�6�r5c�:�|j|j�yrd)r�r�rWs rrCzPolicy.set_exec_pathcs�����t�y�y�!r5c�0�tj�dk(S)z�This method should return true if the user calling the script is
        considered to be a superuser

        :returns: ``True`` if user is superuser, else ``False``
        :rtype: ``bool``
        r)r��getuidrWs r�is_rootzPolicy.is_rootfs���	�	��q� �!r5c��y)zRReturns the string name of the hashlib-supported checksum algorithm
        to use�sha256rHrWs r�get_preferred_hash_namezPolicy.get_preferred_hash_nameos��r5c	�l�|jd�|jd�|jdtd��dtd��d��|jd�d	d
ddd
�}|jd�}|jd�|D])}|jdj	d|||�d���+y)NzSoS Policiesz�Policies help govern how SoS operates on across different distributions of Linux. They control aspects such as plugin enablement, $PATH determination, how/which package managers are queried, default upload specifications, and more.z0When SoS intializes most functions, for example z
sos reportz and zsos collecta�, one of the first operations is to determine the correct policy to load for the local system. Policies will determine the proper package manager to use, any applicable container runtime(s), and init systems so that SoS and report plugins can properly function for collections. Generally speaking a single policy will map to a single distribution; for example there are separate policies for Debian, Ubuntu, RHEL, and Fedora.zRIt is currently not possible for users to directly control which policy is loaded.z*The Google Cloud-Optimized OS distributionzThe Debian distributionz=Red Hat family distributions, not necessarily including forkszUbuntu/Canonical distributions)zpolicies.coszpolicies.debianzpolicies.redhatzpolicies.ubuntuzSee Alsoz9For more information on distribution policies, see below
z{:>8}{:<20}{:<30}� F)�newline)�	set_title�add_textr�add_sectionry)rE�section�pols�seealso�pols     r�display_helpzPolicy.display_helpts������.�)����
7�	
�	����L�!�4�
�#6�
8�
	
�	���
 �	
�I�8�!3�?�
���%�%�j�1�����H�	
��	,�C����0�7�7��S�$�s�)�L�%*�
�
,�	,r5c��|s|sy|r'|jjtd|����|r�|jjtd|�d���|jjtdt|j�����|jjtdt|j�j����n(|jjtd|�d���|rT|jjd|j��d	|���|jjtd
��yy)ahDisplay final information about a generated archive

        :param archive: The name of the archive that was generated
        :type archive: ``str``

        :param directory: The build directory for sos if --build was used
        :type directory: ``str``

        :param checksum: The checksum of the archive
        :type checksum: ``str``

        :param archivestat: stat() information for the archive
        :type archivestat: `os.stat_result`

        :param map_file: If sos clean was invoked, the location of the mapping
                         file for this run
        :type map_file: ``str``
        Fz3
A mapping of obfuscated elements is available at
	z2
Your sosreport has been generated and saved in:
	�
z Size	z Owner	z2Your sosreport build tree has been generated in:
	r��	z7
Please send this file to your support representative.
N)	r>�info�_r�st_sizer�st_uid�pw_namer�)rE�archive�	directory�checksum�archivestat�map_files      r�display_resultszPolicy.display_results�sH��2�y����K�K�����!�
�$�%�
�
��K�K����� �	��%�&�
�
�K�K����G�.�{�/B�/B�C�D�E�F�
�
�K�K����H�X�k�&8�&8�9�A�A�B�C�D�
�
�K�K�����"��2�'�(�
���K�K���q��!=�!=�!?� @��8�*�M�N��K�K����M�N�
�r5c�:�|jdjrd}nd}d}|j|j|j|j�|j|jd|d�z}d}|j�D]}|t||d�	�zd
z}�|S)aUThis method is used to prepare the preamble text to display to
        the user in non-batch mode. If your policy sets self.distro that
        text will be substituted accordingly. You can also override this
        method to do something more complicated.

        :returns: Formatted banner message string
        :rtype: ``str``
        rbz,Changes CAN be made to system configuration.z0No changes will be made to system configuration.�H�tmpdir)�distro�vendor�vendor_urls�vendor_textr��changes_textrF)�replace_whitespacer�)	ru�allow_system_changes�msgr�r��_fmt_vendor_urlsr��
splitlinesr)rEr��width�_msg�_fmt�lines      r�get_msgzPolicy.get_msg�s����<�<�
�&�;�;�I�L�M�L����x�x�T�[�[�D�K�K�*.�*?�*?�*A�*.�*:�*:�%)�\�\�(�%;�+7�	9�9��
���O�O�%�	M�D��$�t�U�u�E�E��L�D�	M��r5c	���t|jD�cgc]}t|d���c}��dj�fd�|jD��Scc}w)z�Formats all items in the ``vendor_urls`` class attr into a usable
        string for the banner message.

        :returns:   Formatted string of URLS
        :rtype:     ``str``
        rr�c3�R�K�|]}dj|d�|d����� y�w)z	{desc:<{width}} : {url}rr�)�descr��urlN)ry)ri�ur�s  �rrkz*Policy._fmt_vendor_urls.<locals>.<genexpr>�s8�������5�;�;���d�%�Q�q�T�<�;��s�$')�maxr�r�rv)rE�vr�s  @rr�zPolicy._fmt_vendor_urls�sQ�����(8�(8�9�1�S��1��Y�9�:���y�y��"&�"2�"2���	��:s�Ac�L�|ri|_|jj|�y)aAdd new presets to this policy object.

            Merges the presets dictionary ``presets`` into this ``Policy``
            object, or replaces the current presets if ``replace`` is
            ``True``.

            ``presets`` should be a dictionary mapping ``str`` preset names
            to ``<class PresetDefaults>`` objects specifying the command
            line defaults.

            :param presets: dictionary of presets to add or replace
            :param replace: replace presets rather than merge new presets.
        N)�presets�update)rEr��replaces   rrDzPolicy.register_presets�s ����D�L������G�$r5c�n�|jj�D]}||k(s�	|j|cSy)z�Find a preset profile matching the specified preset string.

            :param preset: a string containing a preset profile name.
            :returns: a matching PresetProfile.
        N)r��keys)rE�preset�matchs   r�find_presetzPolicy.find_presets;���\�\�&�&�(�	+�E�����|�|�E�*�*�	+�r5c�(�|jtS)z�Return a ``PresetDefaults`` object matching the runing host.

            Stub method to be implemented by derived policy classes.

            :returns: a ``PresetDefaults`` object.
        )r�rrWs r�probe_presetzPolicy.probe_presets���|�|�I�&�&r5c	���|xs|j}tjj|�sytj|�D]�}tjj||�}t
|�5}	tj|�}	ddd�j�D]�}t|t���}||}t|vr	|tnd|_t|vr	|tnd|_t"|vr/|t"D]#}t%|j&||t"|��%d|_||j*|<����y#t$rYddd���wxYw#1swY��xYw)z�Load presets from disk.

            Read JSON formatted preset data from the specified path,
            or the default location at ``/var/lib/sos/presets``.

            :param presets_path: a directory containing JSON presets.
        N)�optsrF)�presets_pathr�r��exists�listdirrv�open�jsonr4�
ValueErrorr�rrrr�r	�noter
�setattrr��builtinr�)	rEr��preset_path�pf�preset_datar��pd�data�args	         r�load_presetszPolicy.load_presets$sA��$�8�t�'8�'8���w�w�~�~�l�+���:�:�l�3�	*�K��'�'�,�,�|�[�A�K��k�"�
�b��"&�)�)�B�-�K�
�&�*�*�,�

*��#�F���>��"�6�*��(,���$�t�*�"���(,���$�t�*�"����4�<�#�D�z�?�������d�4�j��o�>�?�"��
�')����V�$�

*�	*��"���	
�
���
�
�s*�4E�6E�	E�E�E�E�E$	c�
�|j}|std��||jj�vrtd|z��t	||||��}d|_||j|j<|j|�y)z�Add a new on-disk preset and write it to the configured
            presets path.

            :param preset: the new PresetDefaults to add
        zPreset name cannot be emptyz&A preset with name '%s' already exists)rr�r�r�FN)r�r�r�r�rrr�write)rErr�r�r�r�r�s       r�
add_presetzPolicy.add_presetDsy���(�(����:�;�;��4�<�<�$�$�&�&��E��L�M�M��T��4�d�K�����$*����V�[�[�!����\�"r5c�.�|r||jj�vrtd|z��|j|}|jrtd|jz��|j|j�|jj|�y)NzUnknown profile: '%s'z"Cannot delete built-in preset '%s')r�r�r�rr�deleter��pop)rErr�s   r�
del_presetzPolicy.del_presetWs����t�4�<�<�#4�#4�#6�6��4�t�;�<�<����d�#���>�>��A�#�[�[�)�*�
*�	�
�
�d�'�'�(�������r5)NTN)r)F)NNrd)5�__name__�
__module__�__qualname__�__doc__r�r�r�r�r�r�r�r�rxrr�rr�rVrFr*�propertyrS�classmethodrKrXrZr_r~r�r�r�r�r�r�r�r�r?r�r�rCr�r�r�r�r�r�rDr�r�rrr
rrHr5rrr6sA��(�T�
��C�"�F�
�F�=�>�K��K�I�D����L��>�#�$�G��L��M�/�&��
0��
0��

��

�"�
��6;�v��
'�!�(/� 
�
�	5���
"�"�"��
�(,��(,�TIM�!%�6�p�0�%�$�'�*�@#��D�z�|�#�&r5r)'r;r�r,r{r�r�rergr+�pwdr�sos.presetsrrrrrr	r
�sos.policies.package_managersr�
sos.utilitiesrr
rr�sos.report.pluginsrr�sos.optionsrr1rr��textwraprrr4rrHr5r�<module>rsq���	�����
�
�
��;�;�;�8�!�!�D�"�����4�d�$����.l�lr5

Zerion Mini Shell 1.0