
    ~ g\;                     &   S SK r S SKrS SKrS SKJr  S SKJrJrJrJ	r	J
r
JrJrJrJrJr  S SKJrJrJr  S SKJr  S SKJr  S SKJr  S SKJr  S S	KJr  S
r " S S\5      r Sr!Sr"Sr# " S S\ 5      r$ " S S\$5      r% " S S\$5      r& " S S\ 5      r'g)    N)RedHatPlugin)
RHEL_PRESETSRHVRHELCBRHOSPRHOCPRH_CFMERH_SATELLITEAAPEDAAAPCONTROLLER)LinuxPolicyENV_HOST_SYSROOT
OS_RELEASE)RpmPackageManager)FlatpakPackageManager)MultiPackageManager)bold)_soszRed Hat Enterprise Linuxc                      ^  \ rS rSrSrSS/rSrSrSrSr	Sr
S	rS
rSrSrSr  SU 4S jjr\U 4S j5       rS rS rS rSrU =r$ )RedHatPolicy   Red Hat)zDistribution Websitezhttps://www.redhat.com/)zCommercial Supportzhttps://access.redhat.com/z/var/tmpFfriendlyN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/tokenc                   > [         TU ]  XUUS9  SU l        [        [        [
        /U R                  US9U l        U =R                  [        /-  sl        U R                  R                  U l        U R                  (       d5  [        R                  R                  S5        [        R                  " S5        U R!                  U R                  5      U l        U R                  (       a  SU l        OSU l        U =R"                  [$        R&                  S-   -  sl        U =R"                  [$        R&                  S	-   -  sl        U R(                  (       d  U R+                  5         U R-                  5         g )
Nsysrootinitprobe_runtimeremote_execF)primary	fallbackschrootr"   z'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)super__init__usrmover   r   r   r   package_managervalid_subclassesr   packagespkgssysstderrwriteexitcheck_usrmovePATHospathsepr"   set_exec_pathload_presetsselfr   r    r!   r"   	__class__s        =/usr/lib/python3/dist-packages/sos/policies/distros/redhat.pyr(   RedHatPolicy.__init__1   s   '4%0 	 	2 2)01||'	 ) 	,/((11	 yyJJFGHHQK))$))4<<6DIADI		RZZ"222			RZZ"333	     c                 $  > U [         La  [        [         U ]  U5        g UR                  S5        [        [
        [        [        S.nUR                  5        H6  u  p4[        SU 35      nUR                  SS US UR                  S 3SS	9  M8     g )
NzThis policy is a building block for all other Red Hat family distributions. You are likely looking for one of the distributions listed below.
)centosrhelredhatcoreosfedoraz	policies. z>8z<35z<30F)newline)r   r'   display_distro_helpadd_textCentOsPolicy
RHELPolicyRedHatCoreOSPolicyFedoraPolicyitemsr   os_release_name)clssectionsubssubcvaluesublnr:   s         r;   rE    RedHatPolicy.display_distro_helpS   s    l",8A,	
 #."	
  ::<KD9TF+,Er(5+e&;&;C%@A   (r=   c                     SU;  aE  [         R                  R                  S5      =(       a    [         R                  R                  S5      $ US   S   nUS   S:H  $ )a-  Test 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

filesystemz/binz/sbinversionr   3)r4   pathislink)r9   r-   filesys_versions      r;   r2   RedHatPolicy.check_usrmovel   sP     t#77>>&)EbggnnW.EE|,Y7q!S((r=   c                 v    / nS nU R                   (       a"  U H  nUR                  U" U5      5        M     U$ U$ )zMangle 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
c                     SS/nX;   a%  U [         R                  R                  SU SS  5      4$ [        R                  " SSU 5      4$ )Nz/bin/rpmz
/bin/mailxz/usrr&   z(^)(/s?bin)z\1/usr\2)r4   rX   joinresub)rX   
skip_pathss     r;   transform_path8RedHatPolicy.mangle_package_path.<locals>.transform_path   sJ     %l3J!bggll648<==FF>;=??r=   )r)   extend)r9   filespathsrb   fs        r;   mangle_package_path RedHatPolicy.mangle_package_path{   s=     	@ <<^A./ Lr=   c                 ,    U(       d  U R                   $ U$ N)_tmp_dir)r9   opt_tmp_dirs     r;   get_tmp_dirRedHatPolicy.get_tmp_dir   s    == r=   )r3   r*   r-   r)   NNTN)__name__
__module____qualname____firstlineno__vendorvendor_urlsrl   _in_containername_pattern
upload_urlupload_userdefault_container_runtimesos_pkg_namesos_bin_pathclient_identifier_urltoken_endpointr(   classmethodrE   r2   rh   rn   __static_attributes____classcell__r:   s   @r;   r   r      s    F;<K HMLJK (LLE8N ?C! D  0)2 r=   r   a[  
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.
zhttps://api.access.redhat.comzsftp://sftp.access.redhat.comc                   |   ^  \ rS rSrSrSrSr\rSr	\
" S\-   S-   5      r\rSrS	rS
r  SU 4S jjrS rS rSrU =r$ )rH      a   
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.
r   z/etc/redhat-releaser@   a  This command will collect diagnostic and configuration information from this %(os_release_name)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.
%(vendor_text)s
postNi   @c                 N   > [         TU ]  XUUS9  U R                  [        5        g Nr   )r'   r(   register_presetsr   r8   s        r;   r(   RHELPolicy.__init__   s-    '4%0 	 	2 	l+r=   c                      U R                   R                  S5      nU R                  US      S   n[        US   5      $ ! [         a     gf = f)Nzredhat-release*r   rV   F)r*   all_pkgs_by_name_regexr-   int	Exception)r9   rrpkgnames      r;   dist_versionRHELPolicy.dist_version   sZ    	%%<<=NOBii1&y1G wqz?" 		s   =A   
AAc                    S H>  nU R                   R                  U S3S5      (       d  M)  U R                  [        5      s  $    U R	                  S5      b  U R                  [
        5      $ U R	                  S5      b  U R                  [        5      $ U R	                  S5      b  U R                  [        5      $ U R	                  S5      c  U R	                  S5      b  U R                  [        5      $ U R	                  S	5      b  U R                  [        5      $ S
 H,  nU R	                  U5      c  M  U R                  [        5      s  $    U R                  [        5      $ )N)rescue	emergencyz.targetFzsatellite-commonzrhosp-releasecfmezovirt-enginevdsmzautomation-controller-server)zautomation-eda-controllerz automation-eda-controller-server)init_system
is_runningfind_presetr   pkg_by_namer   r   r
   r   r   r   r   )r9   targetpkgs      r;   probe_presetRHELPolicy.probe_preset   s=   -F**fXW+=uEE''++ . ./;##L11O,8##E**F#/##G,,N+7  (4##C((:;G##M228C$0''//8 %%r=    rp   )rq   rr   rs   rt   __doc__ru   os_release_fileRHEL_RELEASE_STRrL   os_release_id_disclaimer_textmsgRH_SFTP_HOST_upload_url_upload_method_device_token_max_size_requestr(   r   r   r   r   r   s   @r;   rH   rH      sr    4 F+O&OM
   ,, -C KNM">B!,
& &r=   rH   c                   *    \ rS rSrSrS/rSrSrSrSr	g)	rG   i  CentOS)Community Websitezhttps://www.centos.org/z/etc/centos-releasezCentOS Linuxr?   r   N)
rq   rr   rs   rt   ru   rv   r   rL   r   r   r   r=   r;   rG   rG     s    FCDK+O$OMr=   rG   c                      ^  \ rS rSrSrSr\" S\-   S-   5      rSr	Sr
SrS	rS
rSr  SU 4S jjr\SS j5       rS rSS jrS rSrU =r$ )rI   i  a  
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.
zRed Hat Enterprise Linux CoreOSzThis command will collect diagnostic and configuration information from this %(os_release_name)s system.

An archive containing the collected information will be generated in %(tmpdir)s and may be provided to a %(vendor)s support representative.
r   Tr   z&registry.redhat.io/rhel8/support-toolsz/hostz
rpm -q sosz/var/lib/kubelet/config.jsonc                 $   > [         TU ]  XUUS9  g r   r'   r(   r8   s        r;   r(   RedHatCoreOSPolicy.__init__4      '4%0 	 	2r=   c                 n   U(       a  SU;   $ Sn[         [        R                  ;  a  U$ [        R                  [            [        -   n [	        USSS9 nUR                  5       R                  5        H  nX R                  U;   -  nM     S S S 5        U$ ! , (       d  f       U$ = f! [         a     U$ f = f)NCoreOSFrzutf-8)encoding)	r   r4   environr   openread
splitlinesrL   IOError)rM   remotecoreoshost_releasehfilelines         r;   checkRedHatCoreOSPolicy.check:  s     v%%2::-Mzz"23j@	lC':e!JJL335D11T99F 6 ;  ;:   		s0   B& 7B
B& 
B#B& #B& &
B43B4c                 ,    U R                  [        5      $ rk   )r   r	   r9   s    r;   r   RedHatCoreOSPolicy.probe_presetM  s     &&r=   c                     U=(       d    U R                   nU(       a  SOSnU R                   SU R                   SU R                   SU SU SU=(       d    S SU 3$ )Nz--pull=always z run -di --name zE --privileged --ipc=host --net=host --pid=host -e HOST=/host -e NAME=z
 -e IMAGE=rC   zr -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)r9   imageauth
force_pull_image_pulls         r;   create_sos_container'RedHatCoreOSPolicy.create_sos_containerR  sy    .$..#-2%%& '--. /../ 0HAeW %
 zrl!F8	%	
r=   c                      SU R                    3$ )Nzpodman rm --force )r   r   s    r;   set_cleanup_cmd"RedHatCoreOSPolicy.set_cleanup_cmdb  s    #D$;$;#<==r=   r   rp   )r   )NNF)rq   rr   rs   rt   r   rL   r   r   r   containerizedr   r   sos_path_stripcontainer_version_commandcontainer_authfiler(   r   r   r   r   r   r   r   r   s   @r;   rI   rI     s    ( 8O
   ,, -C M >ON ,7>B!2  $'

 > >r=   rI   c                   R   ^  \ rS rSrSrSrSS/rSrSrSr	  SU 4S	 jjr
S
 rSrU =r$ )rJ   if  aB  
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).
zthe Fedora Project)r   zhttps://fedoraproject.org/)zCommunity Forumsz%https://discussion.fedoraproject.org/z/etc/fedora-releasezFedora LinuxrB   c                 $   > [         TU ]  XUUS9  g r   r   r8   s        r;   r(   FedoraPolicy.__init__|  r   r=   c                     U R                  S5      =(       d    U R                  R                  S5      S   n[        US   5      $ )Nzfedora-releasezfedora-release-.*rV   )r   r*   r   r   )r9   r   s     r;   fedora_versionFedoraPolicy.fedora_version  sK    /0 )  77#%%') 	 3y>""r=   r   rp   )rq   rr   rs   rt   r   ru   rv   r   rL   r   r(   r   r   r   r   s   @r;   rJ   rJ   f  sB     "F;EK ,O$OM>B!2# #r=   rJ   )(r4   r.   r_   sos.report.pluginsr   sos.presets.redhatr   r   r   r   r   r	   r
   r   r   r   sos.policies.distrosr   r   r   !sos.policies.package_managers.rpmr   %sos.policies.package_managers.flatpakr   sos.policies.package_managersr   sos.utilitiesr   r   r   r   r   r   r   RH_API_HOSTr   rH   rG   rI   rJ   r   r=   r;   <module>r      s    
 
 	 +/ / / K J ? G =   . y; yz
 ..X& X&v: U> U>p #<  #r=   