Sindbad~EG File Manager

Current Path : /lib/python3.6/site-packages/sos/policies/distros/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/sos/policies/distros/__pycache__/redhat.cpython-36.pyc

3

3[Tf�`�@sRddlZddlZddlZddlZddlmZddlmZddlm	Z	m
Z
mZmZm
Z
mZmZmZmZddlmZmZddlmZddlmZddlmZdd	lmZdd
lmZyddl Z dZ!Wne"k
r�dZ!YnXd
Z#dZ$Gdd�de�Z%dZ&dZ'dZ(Gdd�de%�Z)Gdd�de)�Z*Gdd�de)�Z+Gdd�de)�Z,Gdd�de%�Z-dS)�N)�DeviceAuthorizationClass)�RedHatPlugin)	�RHEL_PRESETS�RHV�RHEL�CB�RHOSP�RHOCP�RH_CFME�RH_SATELLITE�AAPEDA)�LinuxPolicy�ENV_HOST_SYSROOT)�RpmPackageManager)�FlatpakPackageManager)�MultiPackageManager)�bold)�_sosTFz/etc/os-releasezRed Hat Enterprise Linuxcs�eZdZdZdZddgZdZdZdZd	Z	d	Z
d
ZdZdZ
d
ZdZd�fdd�	Zed dd��Ze�fdd��Zdd�Zdd�Zdd�Z�ZS)!�RedHatPolicyzRed Hat�Distribution Website�https://www.redhat.com/�Commercial Support�https://access.redhat.com/z/var/tmpFZfriendlyN�podman�sosz	/usr/sbinzVhttps://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/auth/devicezPhttps://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/tokenTcs�tt|�j||||d�d|_tttg|j|d�|_|j	t
g7_	|jj|_|jsjt
jjd�t
jd�|j|j�|_|jr�d|_nd|_|jtjd7_|jtjd	7_|js�|j�|j�dS)
N)�sysroot�init�
probe_runtime�remote_execF)ZprimaryZ	fallbacks�chrootrz'Could not obtain installed package list�z/usr/sbin:/usr/bin:/root/binz'/sbin:/bin:/usr/sbin:/usr/bin:/root/binz/usr/local/binz/usr/local/sbin)�superr�__init__�usrmoverrrr�package_managerZvalid_subclassesrZpackages�pkgs�sys�stderr�write�exit�
check_usrmove�PATH�os�pathseprZ
set_exec_pathZload_presets)�selfrrrr)�	__class__��/usr/lib/python3.6/redhat.pyr"9s.


zRedHatPolicy.__init__�cCsdS)a�This method checks to see if we are running on Red Hat. It must be
        overriden by concrete subclasses to return True when running on a
        Fedora, RHEL or other Red Hat distribution or False otherwise.

        If `remote` is provided, it should be the contents of a remote host's
        os-release, or comparable, file to be used in place of the locally
        available one.
        Fr0)�cls�remoter0r0r1�check[s
zRedHatPolicy.checkcsx|tk	rtt|�j|�dS|jd�ttttd�}x>|D]6}td|�}|jdd�|d�||j	d��dd	�q:WdS)
Nz�This policy is a building block for all other Red Hat family distributions. You are likely looking for one of the distributions listed below.
)ZcentosZrhelZredhatcoreosZfedorazpolicies.%s� z>8z<35z<30F)�newline)
rr!�display_distro_helpZadd_text�CentOsPolicy�
RHELPolicy�RedHatCoreOSPolicy�FedoraPolicyr�distro)r3ZsectionZsubsZsubcZsubln)r/r0r1r8gs
z RedHatPolicy.display_distro_helpcCsDd|kr tjjd�otjjd�S|dd}|ddkr<dSdSd	S)
aqTest whether the running system implements UsrMove.

            If the 'filesystem' package is present, it will check that the
            version is greater than 3. If the package is not present the
            '/bin' and '/sbin' paths are checked and UsrMove is assumed
            if both are symbolic links.

            :param pkgs: a packages dictionary
        Z
filesystemz/binz/sbin�versionr�3TFN)r,�path�islink)r.r%Zfilesys_versionr0r0r1r*�s
zRedHatPolicy.check_usrmovecCs:g}dd�}|jr2x|D]}|j||��qW|S|SdS)a2Mangle paths for post-UsrMove systems.

            If the system implements UsrMove, all files will be in
            '/usr/[s]bin'. This method substitutes all the /[s]bin
            references in the 'files' list with '/usr/[s]bin'.

            :param files: the list of package managed files
        cSs:ddg}||kr*|tjjd|dd��fStjdd|�fS)Nz/bin/rpmz
/bin/mailxz/usrr z(^)(/s?bin)z\1/usr\2)r,r@�join�re�sub)r@Z
skip_pathsr0r0r1�transform_path�sz8RedHatPolicy.mangle_package_path.<locals>.transform_pathN)r#�extend)r.�files�pathsrE�fr0r0r1�mangle_package_path�s	
z RedHatPolicy.mangle_package_pathcCs|s
|jS|S)N)�_tmp_dir)r.Zopt_tmp_dirr0r0r1�get_tmp_dir�szRedHatPolicy.get_tmp_dir)rr)rr)NNTN)r2)�__name__�
__module__�__qualname__r=�vendor�vendor_urlsrKZ
_in_containerZname_pattern�
upload_url�upload_userZdefault_container_runtimeZsos_pkg_nameZsos_bin_path�client_identifier_url�token_endpointr"�classmethodr5r8r*rJrL�
__classcell__r0r0)r/r1r%s,!ra[
Any information provided to %(vendor)s will be treated in accordance with the published support policies at:

  %(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.

No changes will be made to system configuration.
zhttps://api.access.redhat.comzsftp://sftp.access.redhat.comcs�eZdZdZeZdZeded�Z	e
ZdZdZ
d%�fdd	�	Zed&dd��Zd
d�Zdd�Zdd�Zdd�Zd'dd�Zdd�Zdd�Zdd�Z�fdd�Z�fdd �Zd!d"�Zd#d$�Z�ZS)(r:at
    The RHEL policy is used specifically for Red Hat Enterprise Linux, of
    any release, and not forks or derivative distributions. For example, this
    policy will be loaded for any RHEL 8 installation, but will not be loaded
    for CentOS Stream 8 or Red Hat CoreOS, for which there are separate
    policies.

    Plugins activated by installed packages will only be activated if those
    packages are installed via RPM (dnf/yum inclusive). Packages installed by
    other means are not considered by this policy.

    By default, --upload will be directed to using the SFTP location provided
    by Red Hat for technical support cases. Users who provide login credentials
    for their Red Hat Customer Portal account will have their archives uploaded
    to a user-specific directory.

    If users provide those credentials as well as a case number, --upload will
    instead attempt to directly upload archives to the referenced case, thus
    streamlining the process of providing data to technical support engineers.

    If either or both of the credentials or case number are omitted or are
    incorrect, then a temporary anonymous user will be used for upload to the
    SFTP server, and users will need to provide that information to their
    technical support engineer. This information will be printed at the end of
    the upload process for any sos report execution.
    zRed HataThis command will collect diagnostic and configuration information from this %(distro)s system and installed applications.

An archive containing the collected information will be generated in %(tmpdir)s and may be provided to a %(vendor)s support representative.
z%(vendor_text)s
�postNTcs&tt|�j||||d�|jt�dS)N)rrrr)r!r:r"Zregister_presetsr)r.rrrr)r/r0r1r"�szRHELPolicy.__init__r2c
Csx|r|j|kStjjt�sdSttd��F}x>|D]6}|jd�r0|jd�\}}|jd�}|j|j�r0dSq0WWdQRXdS)a�Test to see if the running host is a RHEL installation.

            Checks for the presence of the "Red Hat Enterprise Linux"
            release string at the beginning of the NAME field in the
            `/etc/os-release` file and returns ``True`` if it is
            found, and ``False`` otherwise.

            :returns: ``True`` if the host is running RHEL or ``False``
                      otherwise.
        F�r�NAME�=z"'TN)	r=r,r@�exists�
OS_RELEASE�open�
startswith�split�strip)r3r4rI�line�name�valuer0r0r1r5�s




zRHELPolicy.checkcCs8|jdjr|jjtd��|js4t|_|jjd�dS)N�cmdlineoptszVThe option --upload-user has been deprecated in favour of device authorization in RHELz&No case id provided, uploading to SFTP)�commonsrS�ui_log�info�_�case_id�RH_SFTP_HOSTrR)r.r0r0r1�prompt_for_upload_users
z!RHELPolicy.prompt_for_upload_usercCs |jdjr|jjtd��dS)NrezVThe option --upload-pass has been deprecated in favour of device authorization in RHEL)rfZupload_passrgrhri)r.r0r0r1�prompt_for_upload_passwords
z%RHELPolicy.prompt_for_upload_passwordcCsj|jr|jS|jdjr$|jdjS|jdjdkr8tS|jdjsT|jjd�tSd}t||jSdS)NreZsftpz&No case id provided, uploading to SFTPz /support/v1/cases/%s/attachments)rRrfZupload_protocolrkrjrgrh�RH_API_HOST)r.Zrh_case_apir0r0r1�get_upload_url"szRHELPolicy.get_upload_urlcCsdj|j�}d|iS)Nz	Bearer {}Z
Authorization)�format�
_device_token)r.Zstr_authr0r0r1�_get_upload_https_auth0sz!RHELPolicy._get_upload_https_authcCsfd|jjd�d||j�fi}t|j|j�}|j�|_|jj	d|j
����tj|j
�||j�|d�S)z�If upload_https() needs to use requests.post(), use this method.

        Policies should override this method instead of the base upload_https()

        :param archive:     The open archive file object
        �file�/r z/Device authorized correctly. Uploading file to )rG�headers�verify���)rcr`�_get_upload_headersrrTrU�get_access_tokenrqrgrh�get_upload_url_string�requestsrXrorr)r.�archivervrG�RHELAuthr0r0r1�_upload_https_post4s
zRHELPolicy._upload_https_postcCs|j�jt�rddd�SiS)NZfalsezno-cache)Z	isPrivatez
cache-control)ror_rn)r.r0r0r1rxMs
zRHELPolicy._get_upload_headerscCs*|j�jt�rdS|j�jt�r$dS|jS)NzRed Hat Customer PortalzRed Hat Secure FTP)ror_rnrkrR)r.r0r0r1rzRs
z RHELPolicy.get_upload_url_stringcCs>|jjd�d}|jr$d|j|f}|jr:tjj|j|�}|S)z�The RH SFTP server will only automatically connect file uploads to
        cases if the filename _starts_ with the case number
        rtr z%s_%srw)Zupload_archive_namer`rjZupload_directoryr,r@rB)r.Zfnamer0r0r1�_get_sftp_upload_nameYsz RHELPolicy._get_sftp_upload_namecs�tjd�d|j�kr$tt|�j�Sts0td��d}d}|js�yt	|j
|j�}Wn:tk
r�}zdt|�krz|j
jd�WYdd}~XnX|j�|_|jr�|j
jd|j����td}d}|j�r8|j�}tj||d	d
�}|jdk�rtj|j�d}tj|j�d
}n*|j
jd|j�d|j����|j
jd�n~ddi}tj|tj|�d	d�}	|	jdk�r�tj|	j�}
|
d}|
d
}|j
jtd|�d���n|j
jd|	j�d|	j����|�r�|�r�tt|�j||d�Std��dS)z�Override the base upload_sftp to allow for setting an on-demand
        generated anonymous login for the RH SFTP server if a username and
        password are not given
        z//r zPpython3-requests is not installed and is required for obtaining SFTP auth token.Nzend user deniedz:Device token authorization has been cancelled by the user.z/Device authorized correctly. Uploading file to z/support/v2/sftp/token�
)ru�timeout��Zusername�tokenz$DEBUG: auth attempt failed (status: z): zUUnable to retrieve Red Hat auth token using provided credentials. Will try anonymous.ZisAnonymousT)�datar�zUser z^ used for anonymous upload. Please inform your support engineer so they may retrieve the data.z)DEBUG: anonymous request failed (status: )�userZpasswordz1Could not retrieve valid or anonymous credentials)rkr`ror!r:�upload_sftp�REQUESTS_LOADED�	ExceptionrqrrTrU�strrgrhryrzrnrrr{rXZstatus_code�json�loads�text�debug�error�dumpsri)r.Z_tokenZ_userr}�eZurl�retruZadataZanonZresp)r/r0r1r�dsX
zRHELPolicy.upload_sftpcs�y@|jr.|jjt�r.|j�s(|j�r.t|_tt|�j|�}Wnht	k
r�}zLd}|jjt�sf�n2|j
jtd|�dt����t|_tt|�j|�}WYdd}~XnX|S)zOverride the base upload_archive to provide for automatic failover
        from RHCP failures to the public RH dropbox
        Fz0Upload to Red Hat Customer Portal failed due to z	. Trying N)
rRr_rnZget_upload_userZget_upload_passwordrkr!r:�upload_archiver�rgr�ri)r.r|Zuploadedr�)r/r0r1r��s

"zRHELPolicy.upload_archivecCsDy*|jjd�}|j|dd}t|d�Stk
r>YnXdS)Nzredhat-release*rr>F)r$�all_pkgs_by_name_regexr%�intr�)r.ZrrZpkgnamer0r0r1�dist_version�szRHELPolicy.dist_versioncCs�x(dD] }|jjd|d�r|jt�SqW|jd�dk	rB|jt�S|jd�dk	rZ|jt�S|jd�dk	rr|jt�S|jd�dk	s�|jd	�dk	r�|jt�Sx$d
D]}|j|�dk	r�|jt	�Sq�W|jt
�S)N�rescue�	emergencyz	%s.targetFzsatellite-commonz
rhosp-releaseZcfmezovirt-engineZvdsm�automation-eda-controller� automation-eda-controller-server)r�r�)r�r�)Zinit_systemZ
is_running�find_presetr�pkg_by_namerrr
rrr)r.�target�pkgr0r0r1�probe_preset�s"




zRHELPolicy.probe_preset)NNTN)r2)T)rMrNrO�__doc__�RHEL_RELEASE_STRr=rPri�disclaimer_text�msgrkZ_upload_urlZ_upload_methodrqr"rVr5rlrmrorrr~rxrzrr�r�r�r�rWr0r0)r/r1r:�s0	
Lr:c@seZdZdZdZdgZdS)r9ZCentOS�Community Website�https://www.centos.org/N)r�r�)rMrNrOr=rPrQr0r0r0r1r9�sr9c@seZdZdZdZddgZdS)�CloudLinuxPolicyZ
CloudLinux�Distribution Website�https://www.cloudlinux.com/�Commercial SupportN)r�r�)r�r�)rMrNrOr=rPrQr0r0r0r1r��sr�csveZdZdZdZeded�ZdZdZ	dZ
dZd	Zd
Z
d�fdd
�	Zeddd��Zdd�Zddd�Zdd�Z�ZS)r;aB
    Red Hat CoreOS is a containerized host built upon Red Hat Enterprise Linux
    and as such this policy is built on top of the RHEL policy. For users, this
    should be entirely transparent as any behavior exhibited or influenced on
    RHEL systems by that policy will be seen on RHCOS systems as well.

    The one change is that this policy ensures that sos collect will deploy a
    container on RHCOS systems in order to facilitate sos report collection,
    as RHCOS discourages non-default package installation via rpm-ostree which
    is used to maintain atomicity for RHCOS nodes. The default container image
    used by this policy is the support-tools image maintained by Red Hat on
    registry.redhat.io.

    Note that this policy is only loaded when sos is directly run on an RHCOS
    node - if sos collect uses the `oc` transport (the default transport that
    will be attempted by the ocp cluster profile), then the policy loaded
    inside the launched pod will be RHEL. Again, this is expected and will not
    impact how sos report collections are performed.
    zRed Hat CoreOSz�This command will collect diagnostic and configuration information from this %(distro)s system.

An archive containing the collected information will be generated in %(tmpdir)s and may be provided to a %(vendor)s support representative.
z%(vendor_text)s
Trz&registry.redhat.io/rhel8/support-toolsz/hostz
rpm -q sosz/var/lib/kubelet/config.jsonNcstt|�j||||d�dS)N)rrrr)r!r;r")r.rrrr)r/r0r1r"!szRedHatCoreOSPolicy.__init__r2cCs�|rd|kSd}ttjkr|Stjtt}y<t|d��(}x |j�j�D]}|d|kO}qHWWdQRXWntk
r|YnX|S)NZCoreOSFrYzRed Hat Enterprise Linux CoreOS)rr,�environr]r^�read�
splitlines�IOError)r3r4ZcoreosZhost_releaseZhfilerbr0r0r1r5's
zRedHatCoreOSPolicy.checkcCs
|jt�S)N)r�r	)r.r0r0r1r�9szRedHatCoreOSPolicy.probe_presetFc
CsL|p|j}|rdnd}|j�d|j�d|j�d|�d|�d|p@d�d|��
S)Nz
--pull=alwaysr2z run -di --name zE --privileged --ipc=host --net=host --pid=host -e HOST=/host -e NAME=z
 -e IMAGE=r6zr -v /run:/run -v /var/log:/var/log -v /etc/machine-id:/etc/machine-id -v /etc/localtime:/etc/localtime -v /:/host )�container_image�container_runtime�sos_container_name)r.ZimageZauthZ
force_pullZ_imageZ_pullr0r0r1�create_sos_container>s
z'RedHatCoreOSPolicy.create_sos_containercCs
d|jS)Nzpodman rm --force %s)r�)r.r0r0r1�set_cleanup_cmdNsz"RedHatCoreOSPolicy.set_cleanup_cmd)NNTN)r2)NNF)rMrNrOr�r=rir�r�Z
containerizedr�r�Zsos_path_stripZcontainer_version_commandZcontainer_authfiler"rVr5r�r�r�rWr0r0)r/r1r;�s"
r;csHeZdZdZdZdZddgZd�fd
d�	Zedd
d��Z	dd�Z
�ZS)r<aj
    The policy for Fedora based systems, regardless of spin/edition. This
    policy is based on the parent Red Hat policy, and thus will only check for
    RPM packages when considering packaged-based plugin enablement. Packages
    installed by other sources are not considered.

    There is no default --upload location for this policy. If users need to
    upload an sos report archive from a Fedora system, they will need to
    provide the location via --upload-url, and optionally login credentials
    for that location via --upload-user and --upload-pass (or the appropriate
    environment variables).
    ZFedorazthe Fedora Project�Community Website�https://fedoraproject.org/�Community Forums�%https://discussion.fedoraproject.org/NTcstt|�j||||d�dS)N)rrrr)r!r<r")r.rrrr)r/r0r1r"gszFedoraPolicy.__init__r2cCs|r|j|kStjjd�S)zXThis method checks to see if we are running on Fedora. It returns
        True or False.z/etc/fedora-release)r=r,r@�isfile)r3r4r0r0r1r5ms
zFedoraPolicy.checkcCs$|jd�p|jd�d}t|d�S)Nzfedora-releasezfedora-release-.*r r>rw)r�r�r�)r.r�r0r0r1�fedora_versionws
zFedoraPolicy.fedora_version)r�r�)r�r�)NNTN)r2)rMrNrOr�r=rPrQr"rVr5r�rWr0r0)r/r1r<Rs	r<).r�r,r&rCZsos.policies.authrZsos.report.pluginsrZsos.presets.redhatrrrrrr	r
rrZsos.policies.distrosr
rZ!sos.policies.package_managers.rpmrZ%sos.policies.package_managers.flatpakrZsos.policies.package_managersrZ
sos.utilitiesrrrrir{r��ImportErrorr]r�rr�rnrkr:r9r�r;r<r0r0r0r1�<module>s>,
,
W

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists