�
u��ec
@s�ddlmZddlZddlZddlZddlZddlZddlmZddl m
Z
mZddlm
Z
mZmZddlmZddlmZejd�ZyddlZeZWnek
r�eZnXd Zy
eZWnek
rnXd
e
fd��YZdZ d
Z!ede�Z"ede�Z#edede�Z$dddgZ%dddgZ&dZ'dZ(dZ)dZ*e'Z+dZ,dZ-dZ.dZ/eddd d!g�Z0d"Z1d#Z2d$Z3d%Z4ededd&g�Z5d'Z6d(Z7ededed)e%de&�Z8d*Z9d+Z:d,Z;d-Z<ied.e(d/e)d0e;d1e"�e(6ed.e*d/e+�e*6ed.e,d/e-d1e0�e,6ed.e.d/e/d0e<d1e$�e.6ed.e1d/e2d0e;d1e"�e16ed.e3d/e4d0e;d1e5�e36ed.e6d/e7d0e9d1e8�e66Z=d2Z>d3Z?d4Z@d5efd6��YZAd7eAfd8��YZBd9ZCd:ZDd;ZEied.eCd/eEd0e;d1e"�eC6ZFd<eAfd=��YZGd>eAfd?��YZHd@eGfdA��YZIdBefdC��YZJdS(Di����(tprint_functionN(tDeviceAuthorizationClass(tPlugintRedHatPlugin(tLinuxPolicytPackageManagertPresetDefaults(t_sos(t
SoSOptionstsoss/etc/os-releasetRedHatPolicycBs�eZdZdZdZdZdZdZdZdZ ddgZ
eZd Z
d
ZdZdZdZdZd
Zdd�Zed��Zd�Zd�Zd�Zd�Zd�ZRS(tCentOSshttps://www.centos.org/s/etc/redhat-releases/var/tmps7rpm -qa --queryformat "%{NAME}|%{VERSION}|%{RELEASE}\n"srpm -qalsrpm -Vt debuginfos-develt/s/opt/rhtfriendlysVhttps://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/auth/devicesPhttps://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/tokencCsJtt|�jd|�d|_t|_|rG|j�||_n|j�}td|j d|j
d|jd|jd|�|_
tg|_|j
j�|_|js�tdd tj�tjd
�n|j|j�|_|jr�d|_n d|_|jtjd
7_|jtjd7_|j�|j�dS(Ntsysroottt
query_commandtverify_commandt
verify_filtert
files_commandtchroots'Could not obtain installed package listtfileis/usr/sbin:/usr/bin:/root/bins'/sbin:/bin:/usr/sbin:/usr/bin:/root/bins/usr/local/bins/usr/local/sbin(tsuperR
t__init__t
ticket_numbertFalsetusrmovet_container_initt
_host_sysrootRt _rpmq_cmdt _rpmv_cmdt_rpmv_filtert
_rpmql_cmdtpackage_managerRtvalid_subclassestall_pkgstpkgstprinttsyststderrtexitt
check_usrmovetPATHtostpathsept
set_exec_pathtload_presets(tselfR((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyRAs2
cCstS(s�This method checks to see if we are running on CentOS Linux. It must be
overriden by concrete subclasses to return True when running on a
Fedora, CentOS, RHEL or other CentOS distribution or False otherwise.(R(tcls((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pytcheckfscCsXd|kr.tjjd�o-tjjd�S|dd}|ddkrPtStSdS(sqTest 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
t
filesystems/bins/sbintversionit3N(R,tpathtislinktTrueR(R0R%tfilesys_version((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyR*ms
"cCsHg}d�}|jr@x!|D]}|j||��qW|S|SdS(s2Mangle 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
cSsKddg}||kr5|tjjd|d�fStjdd|�fS(Ns/bin/rpms
/bin/mailxs/usris(^)(/s?bin)s\1/usr\2(R,R6tjointretsub(R6t
skip_paths((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyttransform_path�sN(Rtextend(R0tfilestpathsR>tf((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pytmangle_package_path}s
cCs�ttjkr1tjtdkr1t|_q1nttjkrStjt|_n|joh|jdk}|r�tjj|j|j �}||_ n|r�|jSdS(s�Check if sos is running in a container and perform container
specific initialisation based on ENV_HOST_SYSROOT.
tdockertociR
(RDREN(t
ENV_CONTAINERR,tenvironR8t
_in_containertENV_HOST_SYSROOTRR6tabspatht_tmp_dirtNone(R0tuse_sysrootthost_tmp_dir((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyR�scCs�ddlm}m}g}|d|dtd|d|dddt�}|j�\}}|rf|Sxj|j�d D]X}y|jd
d �\} }
Wntk
r�qwX|
dkrw|jt| ��qwqwW|S(Ni����(tPopentPIPEs"LC_ALL=C /sbin/chkconfig --list %stshelltstdoutR(tbufsizet close_fdsit:ton( t
subprocessRORPR8tcommunicatetsplitt
IndexErrortappendtint(R0tnameRORPtrettptoutterrttabstrunleveltonoff((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pytrunlevel_by_service�s&
cCs|s
|jS|S(N(RK(R0topt_tmp_dir((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pytget_tmp_dir�sN(t__name__t
__module__tdistrotvendort
vendor_urlt_redhat_releaseRKRR!RR RRHRtdefault_scl_prefixtname_patternRLt
upload_urltupload_usertclient_identifier_urlttoken_endpointRtclassmethodR2R*RCRReRg(((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyR
,s0% t containertHOSTtverifytall_logstboottstoragetsystemsboot.all-images=onsrpm.rpmva=onsrpm.rpmdb=onsCentOS LinuxtrhvtVirtualizationtrheltrhospsOpenStack PlatformtocpsOpenShift Container Platformtplugoptssprocess.lsof=offs#networking.ethtool_namespaces=Falsesnetworking.namespaces=200tcfmet
CloudFormst satellitet Satellites
apache.log=ontcantboots(For use when normal system startup failstprofiless9Data collection will be limited to a boot-affecting scopes$This preset may increase report sizes(This preset may increase report run times1This preset may increase report size and run timeR]tdesctnotetoptssZ
Any information provided to %(vendor)s will be treated in accordance with the published support policies at:
%(vendor_url)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.
shttps://api.access.redhat.comssftp://sftp.access.redhat.comt
RHELPolicycBs�eZeZdZdZeded�Ze Z
dZdZ
dd�Zed��Zd�Zd�Zd �Zd
�Zed�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�ZRS(Rshttps://wiki.centos.org/supportsThis 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.
s%(vendor_text)s
tpostcCs*tt|�jd|�|jt�dS(NR(RR�Rtregister_presetstrhel_presets(R0R((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyR!scCs�tjjt�stSttd��d}xZ|D]R}|jd�r/|jd�\}}|jd�}|j|j �r�t
Sq/q/WWdQXtS(s�Test to see if the running host is a RHEL installation.
Checks for the presence of the "CentOS 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.
trtNAMEt=s"'N(R,R6texistst
OS_RELEASERtopent
startswithRYtstripRjR8(R1RBtlineR]tvalue((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyR2%s
cCsL|jdjr&tjtd��n|jsHt|_tjd�ndS(NtcmdlineoptssVThe option --upload-user has been deprecated in favour of device authorization in RHELs&No case id provided, uploading to SFTP(tcommonsRqtloggertinfot_tcase_idtRH_SFTP_HOSTRp(R0((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pytprompt_for_upload_user=s cCs*|jdjr&tjtd��ndS(NR�sVThe option --upload-pass has been deprecated in favour of device authorization in RHEL(R�tupload_passR�R�R�(R0((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pytprompt_for_upload_passwordHscCs�|jr|jS|jdjr.|jdjS|jdjdkrHtS|jdjsitjd�tSd}t||jSdS(NR�tsftps&No case id provided, uploading to SFTPs /support/v1/cases/%s/attachments(RpR�tupload_protocolR�R�R�R�tRH_API_HOST(R0trh_case_api((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pytget_upload_urlQs
cCsdj|j�}i|d6S(Ns Bearer {}t
Authorization(tformatt
_device_token(R0tstr_auth((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyt_get_upload_https_auth_scCs�i|jjd�d||j�fd6}t|j|j�}|j�|_tj dj
|j���tj
|j�d|d|j�d|�S(s�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
R
i����Rs1Device authorized correctly. Uploading file to {}R@theadersRw(R]RYt_get_upload_headersRRrRstget_access_tokenR�R�R�R�tget_upload_url_stringtrequestsR�R�R�(R0tarchiveRwR@tRHELAuth((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyt_upload_https_postcscCs+|j�jt�r'idd6dd6SiS(Ntfalset isPrivatesno-caches
cache-control(R�R�R�(R0((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyR�zscCs9|j�jt�rdS|j�jt�r2dS|jS(NsCustomer PortalsRed Hat Secure FTP(R�R�R�R�Rp(R0((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyR�s
cCs4|jjd�d}|jr0d|j|fS|S(s�The RH SFTP server will only automatically connect file uploads to
cases if the filename _starts_ with the case number
R
i����s%s_%s(tupload_archive_nameRYR�(R0tfname((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyt_get_sftp_upload_name�s cCs$tjd�d|j�kr2tt|�j�StsGtd��nd}d}|j s�yt
|j|j�}Wn5tk
r�}dt
|�kr�tjd�q�q�X|j�|_ n|j r�tjdj|j���ntd}d}|j rr|j�}tj|d|d d
�}|jdkretj|j�d}tj|j�d
}q�td�nwitd6}tj|dtj|�d d
�} | jdkr�tj| j�}
|
d}|
d
}td|�n|r|rtt|�jd|d|�Std��dS(s�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
s//isOpython-requests is not installed and is required for obtaining SFTP auth token.send user denieds:Device token authorization has been cancelled by the user.s1Device authorized correctly. Uploading file to {}s/support/v2/sftp/tokenR�ttimeouti
i�tusernamettokensUUnable to retrieve Red Hat auth token using provided credentials. Will try anonymous.tisAnonymoustdatasHUsing anonymous user %s for upload. Please inform your support engineer.tusertpasswords1Could not retrieve valid or anonymous credentialsN(R�RYR�RR�tupload_sftptREQUESTS_LOADEDt ExceptionRLR�RRrRststrR�R�R�R�R�R�R�R�R�tstatus_codetjsontloadsttextR&R8tdumps(R0t_tokent_userR�teturlR^R�tadatatanontresp((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyR��sP
$
cCs�y]|jrD|jjt�rD|j�s8|j�rDt|_ntt|�j|�}Wnft k
r�}t
}|jjt�s��q�td|tf�t|_tt|�j|�}nX|S(sOverride the base upload_archive to provide for automatic failover
from RHCP failures to the public RH dropbox
s5Upload to Customer Portal failed due to %s. Trying %s(RpR�R�tget_upload_usertget_upload_passwordR�RR�tupload_archiveR�RR&(R0R�tuploadedR�((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyR��s cCs�y�|jjd�}|j|dd}|ddkr>dS|ddkrRdS|dd krfd
S|ddkrzdS|dd
kr�dSWntk
r�nXtS(Nsredhat-release*iR4t4it5Servert5Clientit6it7it8i(R�R�(R"tall_pkgs_by_name_regexR%R�R(R0trrtpkgname((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pytdist_version�s
cCs�x7ddgD])}|jjd|�r
|jt�Sq
W|jd�dk r\|jt�S|jd�dk r~|jt�S|jd�dk r�|jt�S|jd�dk s�|jd�dk r�|jt �S|jt
�S( Ntrescuet emergencys %s.targetssatellite-commons
rhosp-releaseR�sovirt-enginetvdsm(tinit_systemt
is_runningtfind_presettCBtpkg_by_nameRLtRH_SATELLITEtRHOSPtRH_CFMEtRHVtRHEL(R0ttarget((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pytprobe_preset�s
N(RhRitRHEL_RELEASE_STRRjRkRlR�tdisclaimer_texttmsgR�t_upload_urlRLR�t_upload_methodRRtR2R�R�R�R�R8R�R�R�R�R�R�R�R�(((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyR�s, ? tCentOsPolicycBseZdZdZdZRS(Rshttps://www.centos.org/(RhRiRjRkRl(((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyR�statomictAtomicsAtomic HosttRedHatAtomicPolicycBsFeZdZeded�Zdd�Zed��Z d�Z
RS(sAtomic Hosts�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.
s%(vendor_text)s
cCs*tt|�jd|�|jt�dS(NR(RR�RR�tatomic_presets(R0R((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyR#scCs�t}ttjkr|Stjt|j}tjj|�sCtSy:x3t|d�j�j �D]}|t
|kO}qbWWntk
r�nX|S(NR�(RRIR,RGRmR6R�R�treadt
splitlinestATOMIC_RELEASE_STRtIOError(R1R�thost_releaseR�((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyR2's"
cCs)|jd�r|jt�S|jt�S(Nsatomic-openshift(R�R�tRHOCPtATOMIC(R0((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyR�6s
N(RhRiRjR�R�R�RLRRtR2R�(((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyR�stRedHatCoreOSPolicycBsFeZdZeded�Zdd�Zed��Z d�Z
RS(tCoreOSs�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.
s%(vendor_text)s
cCstt|�jd|�dS(NR(RR�R(R0R((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyRHscCst}ttjkr|Stjt|j}y:x3t|d�j�j�D]}|d|kO}qLWWntk
rznX|S(NR�R( RRIR,RGRmR�R�R�R�(R1tcoreosR�R�((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyR2Ks"
cCs
|jt�S(N(R�R�(R0((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyR�XsN(RhRiRjR�R�R�RLRRtR2R�(((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyR�=s
tCentOsAtomicPolicycBseZdZdZdZRS(sCentOS Atomic HostRshttps://www.centos.org/(RhRiRjRkRl(((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyR^stFedoraPolicycBs>eZdZdZdZdd�Zed��Zd�Z RS(tFedorasthe Fedora Projectshttps://fedoraproject.org/cCstt|�jd|�dS(NR(RRR(R0R((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyRjscCstjjd�S(sXThis method checks to see if we are running on Fedora. It returns
True or False.s/etc/fedora-release(R,R6tisfile(R1((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyR2mscCs0|jd�p|jd�d}t|d�S(Nsfedora-releasesfedora-release-.*i����R4(R�R�R\(R0tpkg((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pytfedora_versionssN(
RhRiRjRkRlRLRRtR2R(((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyRds(Kt
__future__RR�R,R'R;tloggingtsos.policies.authRtsos.pluginsRRtsos.policiesRRRR RR�Rt getLoggerR�R�R8R�tImportErrorRR�t raw_inputtinputt NameErrorR
RFRIt_opts_verifyt_opts_all_logst_opts_all_logs_verifyt_cb_profilest_cb_plugoptsR�R�tRHV_DESCR�t RHEL_DESCR�t
RHOSP_DESCR�t
RHOCP_DESCt
RHOSP_OPTSR�tRH_CFME_DESCR�tRH_SATELLITE_DESCtSAT_OPTSR�tCB_DESCtCB_OPTStCB_NOTEt NOTE_SIZEt NOTE_TIMEtNOTE_SIZE_TIMER�R�R�R�R�R�R�R�tATOMIC_DESCR�R�R�RR(((s7/usr/lib/python2.7/site-packages/sos/policies/redhat.pyt<module>s�
�
%�
%! |