
    ~ g*                    P   S r SSKrSSKrSSKrSSKrSSKrSSKrSSKJrJr  SSK	r	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JrJrJrJrJrJr  SSKJ r J!r!  S r"S r#S	 r$\RJ                  " S
\RL                  5      r'Sr( " S S5      r) " S S5      r* " S S5      r+ " S S5      r, " S S5      r- " S S\-5      r. " S S\-5      r/ " S S\-5      r0 " S S\-5      r1 " S S\-5      r2 " S  S!\-5      r3 " S" S#\-5      r4 " S$ S%\-5      r5 " S& S'\-5      r6S)S( jr7g)*z:This exports methods available for use by plugins for sos     N)timesleep)datetime)sos_get_command_outputimport_modulegrepfileobjtailis_executableTIMEOUT_DEFAULTpath_exists
path_isdirpath_isfilepath_islinklistdir	path_joinboldfile_is_binaryrecursive_dict_values_by_key)P_FILEP_LINKc                      [        U5       n[        R                  " XR                  5       [        R                  5      sSSS5        $ ! , (       d  f       g= f! [
         a    / s $ f = f)z=Return a list of all non overlapping matches in the string(s)N)r	   refindallread	MULTILINEAttributeError)regexfnamefs      =/usr/lib/python3/dist-packages/sos/report/plugins/__init__.pyregex_findallr"   &   sE    U^q::eVVXr||< ^^ 	s.   A 3A
 	A 

AA A A*)A*c                     [         R                  " SSU 5      n[         R                  " SSU5      n[         R                  " SSU5      R                  S5      nUSU nU$ )	Nz^/(usr/|)(bin|sbin)/ z[^\w\-\.\/]+_/.z ._-r   )r   substrip)commandname_maxmanglednames      r!   _mangle_commandr-   /   sV    &&0"g>K&&#{;K&&sK066v>Ka)K    c                     [         R                  S4[         R                  S4[         R                  S4[         R                  S4/nU H$  nUS   " U R
                  5      (       d  M  US   s  $    g)zxreturn a string indicating the type of special node represented by
the stat buffer st (block, character, fifo, socket).
zblock devicezcharacter devicez
named pipesocketr      r$   )statS_ISBLKS_ISCHRS_ISFIFOS_ISSOCKst_mode)st_typests      r!   
_node_typer;   7   si    
 
~&	)*	%	!	F Q4

Q4K  r.   z!----(?:-| )BEGIN.*?----(?:-| )ENDz-----SCRUBBEDc                       \ rS rSrSrSrSr/ r/ r/ r	/ r
/ rSS jrS rS rS rS	 rS
 rS rS rS rS rS rS rS rS rS rS/ / / / / 0 4S jrSrg)SoSPredicateK   ae  A class to implement collection predicates.

A predicate gates the collection of data by an sos plugin. For any
`add_cmd_output()`, `add_copy_spec()` or `add_journal()` call, the
passed predicate will be evaulated and collection will proceed if
the result is `True`, and not otherwise.

Predicates may be used to control conditional data collection
without the need for explicit conditional blocks in plugins.

:param owner:       The ``Plugin`` object creating the predicate
:type owner:        ``Plugin``

:param dry_run:     Is sos running in dry_run mode?
:type dry_run:      ``bool``

:param kmods:       Kernel module name(s) to check presence of
:type kmods:        ``list``, or ``str`` of single name

:param services:    Service name(s) to check if running
:type services:     ``list``, or ``str`` of single name

:param packages:    Package name(s) to check presence of
:type packages:     ``list``, or ``str`` of single name

:param cmd_outputs: Command to run, with output string to check
:type cmd_outputs:  ``list`` of ``dict``s, or single ``dict`` taking form
                    {'cmd': <command to run>,
                    'output': <string that output should contain>}
:param arch:        Architecture(s) that the local system is matched
                    against
:type arch:         ``list``, or ``str`` of single architecture

:param required:    For each parameter provided, should the checks
                    require all items, no items, or any items provided
:type required:     ``dict``, with keys matching parameter names and values
                    being either 'any', 'all', or 'none. Default 'any'.

NFc                    SnSU R                    S3nU R                  nU(       a  U Vs/ s H  otU-  PM	     snOUnUSSR                  U5       S3-  nU R                  nU(       a  U V	s/ s H  oU	-  PM	     sn	OUnUSSR                  U5       S3-  nU R                  n
U(       a  U
 Vs/ s H  oU-  PM	     snOU
n
USSR                  U
5       S3-  nU R
                   Vs/ s H"  nS	US
-   SXLS
   -   SUS-   SXLS   -   S3	PM$     nnUSSR                  U5       S3-  nU R                  nU(       a  U Vs/ s H  oU-  PM	     snOUnUSSR                  U5       S3-  nX%-   U-   $ s  snf s  sn	f s  snf s  snf s  snf )zdReturn a string representation of this SoSPredicate with
optional prefix, suffix and value quoting.
z"%s"zdry_run=, zkmods=[,z], z
services=[z
packages=[z{ cmd: outputz }zcmdoutputs=[zarches=[])dry_runkmodsjoinservicespackagescmd_outputsarch)selfquoteprefixsuffixquotespstrrG   krI   spkgsp	cmdoutput
cmdoutputsarchesas                   r!   __strSoSPredicate.__str   s    $,,r*

/4U+U!U+%'#((5/*#..==5:11QJ1*SXXh/044}}-2D)Dq
D)*SXXd^,C00
 "--
 .	 &5.!Fu-=$=#>b !Fx-@$@#AF- 	 

 	,sxx
34C8816f-f1*f-F(388F+,A..}v%%- , 2 *
 .s   E3,E8.E=')FFc                 "    U R                  5       $ )zlReturn a string representation of this SoSPredicate.

"dry_run=False, kmods=[], services=[], cmdoutputs=[]"
_SoSPredicate__strrM   s    r!   __str__SoSPredicate.__str__   s    
 zz|r.   c                 $    U R                  SSSS9$ )zReturn a machine readable string representation of this
SoSPredicate.

"SoSPredicate(dry_run=False, kmods=[], services=[], cmdoutputs=[])"
TzSoSPredicate())rN   rO   rP   r^   r`   s    r!   __repr__SoSPredicate.__repr__   s     zz_SzIIr.   c                     US:X  a  [        U5      $ US:X  a  [        U5      $ US:X  a  [        U5      (       + $ [        SU 35      e)zHelper to simplify checking the state of the predicate's evaluations
against the setting of the required state of that evaluation
anyallnonez7predicate requires must be 'any', 'all', or 'none' not )rh   ri   
ValueError)rM   itemsrequireds      r!   _check_required_state"SoSPredicate._check_required_state   sX     uu:uu:v5z>!*
 	
r.   c                     U R                   U   nUS:w  a  U R                  U   R                  U5        gU R                  U   R                  U5        g)zHelper to direct failed predicates to provide the proper messaging
based on the required check type

    :param test:      The type of check we're doing, e.g. kmods, arch
    :param item:      The string of what failed
rj   N)rm   _failedappend
_forbidden)rM   testitem_reqs       r!   _failed_or_forbidden!SoSPredicate._failed_or_forbidden   sG     }}T"6>LL%%d+OOD!((.r.   c                 Z   U R                   (       a   U R                  R                  S5      (       a  g/ nU R                    HJ  nU R                  R                  U5      nUR	                  U5        U(       a  M8  U R                  SU5        ML     U R                  XR                  S   5      $ )Nallow_system_changesTrG   )rG   _owner
get_optionis_module_loadedrr   rw   rn   rm   )rM   _kmodskmodress       r!   _eval_kmodsSoSPredicate._eval_kmods   s    zzT[[334JKKJJD++..t4CMM#3))'48	  ))&--2HIIr.   c                    U R                   (       d  g/ nU R                    HJ  nU R                  R                  U5      nUR                  U5        U(       a  M8  U R	                  SU5        ML     U R                  XR                  S   5      $ )NTrI   )rI   r{   is_service_runningrr   rw   rn   rm   )rM   _svcssvcr   s       r!   _eval_servicesSoSPredicate._eval_services   sp    }}==C++005CLL3))*c:	 ! ))%z1JKKr.   c                    U R                   (       d  g/ nU R                    HJ  nU R                  R                  U5      nUR                  U5        U(       a  M8  U R	                  SU5        ML     U R                  XR                  S   5      $ )NTrJ   )rJ   r{   is_installedrr   rw   rn   rm   )rM   _pkgspkgr   s       r!   _eval_packagesSoSPredicate._eval_packages   sp    }}==C++**3/CLL3))*c:	 ! ))%z1JKKr.   c                     SU;  d  SU;  a  g[        US   5      nUS   S:w  a  gUS   R                  5        H  nUS   U;   d  M    g   g)z*Does 'cmd' output contain string 'output'?rB   rD   Fstatusr   T)r   
splitlines)rM   
cmd_outputresultlines       r!   _eval_cmd_outputSoSPredicate._eval_cmd_output   s`    
"hj&@'
5(9:(q 8$//1D(#t+ 2 r.   c                    U R                   (       d  g/ nU R                    HK  nU R                  U5      nUR                  U5        U(       a  M.  U R                  SUS    SUS    35        MM     U R	                  XR
                  S   5      $ )NTrK   rB   rC   rD   )rK   r   rr   rw   rn   rm   )rM   _cmdsrB   r   s       r!   _eval_cmd_outputsSoSPredicate._eval_cmd_outputs  s    ##C'',CLL3))!5zl"S]O4	 $ ))%}1MNNr.   c                    U R                   (       d  gU R                  R                  R                  5       nSSR	                  U R                   5       S3nU R
                  S   S:X  a;  [        R                  " X!5      (       a  U R                  S   R                  U5        gg[        R                  " X!5      (       a  gU R                  S   R                  U5        g)	NT(?:|rd   rL   rj   architectureF)rL   r{   policyget_archrH   rm   r   matchrs   rr   rq   )rM   _archr   s      r!   
_eval_archSoSPredicate._eval_arch  s    yy
 ""++-chhtyy)*!,== F*xx%%/66u=88E!!^$++E2r.   c                     SnSnU R                   R                  5        H8  u  p4U(       d  M  [        U5      nXUSR                  S U 5       5      4-  -  nM:     U$ )zLReturn a string informing user what caused the predicate to fail
evaluation
r$   zrequired %s missing: %s.r@   c              3   $   #    U  H  ov   M     g 7fN .0vs     r!   	<genexpr>.SoSPredicate._report_failed.<locals>.<genexpr>3       ,<1Q   )rq   rl   setrH   rM   msg_substrkeyvals        r!   _report_failedSoSPredicate._report_failed)  s^     ,**,HCc(Cc499,<,<#<===C	 -
 
r.   c                     SnSnU R                   R                  5        H8  u  p4U(       d  M  [        U5      nXUSR                  S U 5       5      4-  -  nM:     U$ )zhReturn a string informing the user that a forbidden condition exists
which caused the predicate to fail
r$   zforbidden %s '%s' found.r@   c              3   $   #    U  H  ov   M     g 7fr   r   r   s     r!   r   1SoSPredicate._report_forbidden.<locals>.<genexpr>@  r   r   )rs   rl   r   rH   r   s        r!   _report_forbiddenSoSPredicate._report_forbidden6  s^     ,--/HCc(Cc499,<,<#<===C	 0
 
r.   c                     U R                  5       U R                  5       U R                  (       a  SOS/nSR                  U5      R	                  5       $ )zmUsed by `Plugin()` to obtain the error string based on if the reason
was a failed check or a forbidden check
z	(dry run)r$    )r   r   rF   rH   lstriprM   r   s     r!   report_failureSoSPredicate.report_failureC  sG    
 !""$<<KR

 xx}##%%r.   c                    [        U R                  U R                  U R                  U R                  U R
                  U R                  /5      (       d  gU R                  5       =(       aU    U R                  5       =(       a>    U R                  5       =(       a'    U R                  5       =(       a    U R                  5       =(       a    U R                  (       + $ )z#Predicate evaluation hook.
        T)rh   rG   rI   rJ   rK   rL   rF   r   r   r   r   r   r`   s    r!   __bool__SoSPredicate.__bool__N  s    
 DJJt}}d>N>NIIt||- . .!!# #(;(;(= #$$&#+/+A+A+C#"% $	&r.   c	           	      $   Xl         [        U5      U l        [        U5      U l        [        U5      U l        [        U5      U l        [        U[        5      (       d  U/nX`l        X R                   R                  S   R                  -  U l	        SSSSSS.U l
        U R                  R                  UR                  5        V	V
s0 s H  u  pX   U R                  U	   :w  d  M  X_M      sn
n	5        / / / / / S.U l        / / / / / S.U l        gs  sn
n	f )z-Initialise a new SoSPredicate object
        cmdlineoptsrh   )rG   rI   rJ   rK   rL   )rG   rI   rJ   rK   r   N)r{   listrG   rI   rJ   rL   
isinstancerK   commonsrF   rm   updaterl   rq   rs   )rM   ownerrF   rG   rI   rJ   rK   rL   rm   rS   r   s              r!   __init__SoSPredicate.__init__\  s    %[
XXJ	+t,,&-K&!4!4]!C!K!KK"'U(-u>%^^-
-TQK4==++ AD-
 	 RR

 RR

s   D
#D
)
rq   rs   r{   rL   rK   rF   rG   rJ   rm   rI   )Fr$   r$   )__name__
__module____qualname____firstlineno____doc__r{   rF   rG   rI   rJ   rK   rL   r_   ra   re   rn   rw   r   r   r   r   r   r   r   r   r   r   r   __static_attributes__r   r.   r!   r=   r=   K   s    &P F G E H H K D&@J
/JLL
O&	&& ',2"2
r.   r=   c                   $    \ rS rSrSrS rS rSrg)
SoSCommandiz  a  A class to represent a command to be collected.

A SoSCommand() object is instantiated for each command handed to an
_add_cmd_output() call, so that we no longer need to pass around a very
long tuple to handle the parameters.

Any option supported by _add_cmd_output() is passed to the SoSCommand
object and converted to an attribute. SoSCommand.__dict__ is then passed to
_get_command_output_now() for each command to be collected.
c                 :    U R                   R                  U5        g r   )__dict__r   )rM   kwargss     r!   r   SoSCommand.__init__  s    V$r.   c                 t    SR                  S [        U R                  R                  5       5       5       5      $ )zIReturn a human readable string representation of this SoSCommand
        r@   c              3   4   #    U  H  u  pU S U 3v   M     g7f)=Nr   )r   paramr   s      r!   r   %SoSCommand.__str__.<locals>.<genexpr>  s$      86 /;uE7!C5)6s   )rH   sortedr   rl   r`   s    r!   ra   SoSCommand.__str__  s4     yy 8 3 3 568 8 	8r.   r   N)r   r   r   r   r   r   ra   r   r   r.   r!   r   r   z  s    	%8r.   r   c                   Z    \ rS rSrSrSrSrSrSrSr	Sr
S/rSr  SS jrS rS rS	 rS
rg)	PluginOpti  a  This is used to define options available to plugins. Plugins will need
to define options alongside their distro-specific classes in order to add
support for user-controlled changes in Plugin behavior.

:param name:        The name of the plugin option
:type name:         ``str``

:param default:     The default value of the option
:type default:      Any

:param desc:        A short description of the effect of the option
:type desc:         ``str``

:param long_desc:   A detailed description of the option. Will be used by
                    `sos info`
:type long_desc:    ``str``

:param val_type:    The type of object the option accepts for values. If
                    not provided, auto-detect from the type of ``default``
:type val_type:     A single type or a ``list`` of types
r$   NFc                     Xl         X l        X0l        X@l        U R                  U l        Ub  [        U[        5      (       d  U/nOUR                  /nXPl        g r   )	namedefaultdesc	long_descvaluer   r   	__class__val_type)rM   r   r   r   r   r   s         r!   r   PluginOpt.__init__  sO    		"\\
h--$:))*H r.   c                     SU R                    3SU R                   S3SU R                   3SU R                   3/nSSR	                  U5      -   S-   $ )	Nzname=zdesc=''zvalue=zdefault=(r@   rd   )r   r   r   r   rH   )rM   rl   s     r!   ra   PluginOpt.__str__  s^    DII;dii[#TZZL!t||n%	
 TYYu%%++r.   c                 "    U R                  5       $ r   )ra   r`   s    r!   re   PluginOpt.__repr__  s    ||~r.   c                 P  ^ [        S5      U R                  ;   a  [        T5      U l        g [	        U4S jU R                   5       5      (       d  / nU R                   Hq  nUc  M  UR
                  S:X  a  UR                  S5        M+  UR
                  S:X  a  UR                  S5        MN  UR
                  S:X  d  M`  UR                  S5        Ms     [        S	U R                   S
U R                   SSR                  U5       S[        T5      R
                   35      eTU l        g )Nr$   c              3   <   >#    U  H  n[        TU5      v   M     g 7fr   )r   )r   _tr   s     r!   r   &PluginOpt.set_value.<locals>.<genexpr>  s     ?2:c2&&s   boolz boolean true/false (on/off, etc)strzstring (no spaces)intzinteger valueszPlugin option 'r'   z' takes r@   z, not )typer   r   r   rh   r   rr   	Exceptionpluginr   rH   )rM   r   validr:   s    `  r!   	set_valuePluginOpt.set_value  s    8t}}$SDJ????E]]9::'LL!CDZZ5(LL!56ZZ5(LL!12 # !$++a		{(99U#$F49+=+=*>@  
r.   )r   r   r   r   r   r   )	undefinedNr$   r$   N)r   r   r   r   r   r   r   enabledr   r   r   r   r   r   ra   re   r   r   r   r.   r!   r   r     sM    , DGGDIEvHFJL!,r.   r   c                      \ rS rSrSrSrSrSrSrSr	Sr
SrSrSrSrSr\r\rSr0 r0 r/ rSrSrSrSrS rS	 rS
 rS rS rSS jr S r!\"S 5       r#\"S 5       r$S r%S r&\'S 5       r(\'S 5       r)\'S 5       r*\'S 5       r+S r,S r-S r.S r/S r0S r1S r2S r3S r4S  r5S! r6S" r7S# r8S$ r9S% r:S& r;S' r<S( r=SS) jr>SS* jr?SS+ jr@SS, jrAS- rBSS. jrCS/ rDS0 rES1 rFS2 rGS3 rHS4 rIS5 rJS6 rKS7 rLS8 rMS9 rNSS: jrOS; rPS< rQSS= jrRS> rSS? rTS@ rUSA rVSSSBS/ S4SC jrWSSSBSSSS/ / / SDS4SE jrXSSSBSSSS/ SDS4
SF jrYSG rZSSSBSSSS/ SSS4SH jr[SSSSBSBSSSSSSSS/ SDSSSSS4SI jr\SJ r]SK r^SSL jr_SM r`SN raSSO jrbSP rcSS/ 4SQ jrdSSSSBSBSSSSSSS/ SDSSSSS4SR jreSSSSBSBSSSSSSSS/ S4SS jrf    SST jrgSU rhSV riSSW jrjSX rkSSY jrlSZ rmSS[ jrnSS\ jroSS] jrpSS^ jrqSS_ jrrS` rsSa rtSb ruSc rv    SSd jrwSe rxSf rySg rzSh r{Si r|Sj r}Sk r~Sl r\GR                  S/ 4Sm j5       rSn rSo rSp rSq rSr rSs rSt rSu rSv rSw rSx rSy rSz rS{ rS| rS} rS~ rS rS rS rSS jrSS jrSrg)Plugini  a  This is the base class for sos report plugins. Plugins should subclass
this and set the class variables where applicable.

:param commons:     A set of information that is shared internally so that
                    plugins may access the same dataset. This is provided
                    automatically by sos
:type commons:      ``dict``

Each `Plugin()` subclass should also subclass at least one tagging class,
e.g. ``RedHatPlugin``, to support that distribution. If different
distributions require different collections, each distribution should have
its own subclass of the Plugin that also subclasses the tagging class for
their respective distributions.

:cvar plugin_name:  The name of the plugin, will be returned by `name()`
:vartype plugin_name: ``str``

:cvar packages:     Package name(s) that, if installed, enable this plugin
:vartype packages:  ``tuple``

:cvar files:        File path(s) that, if present, enable this plugin
:vartype files:     ``tuple``

:cvar commands:     Executables that, if present, enable this plugin
:vartype commands:  ``tuple``

:cvar kernel_mods:  Kernel module(s) that, if loaded, enable this plugin
:vartype kernel_mods: ``tuple``

:cvar services:     Service name(s) that, if running, enable this plugin
:vartype services:  ``tuple``

:cvar architectures: Architecture(s) this plugin is enabled for. Defaults
                     to 'none' to enable on all arches.
:vartype architectures: ``tuple``, or ``None``

:cvar profiles:     Name(s) of profile(s) this plugin belongs to
:vartype profiles:  ``tuple``

:cvar plugin_timeout: Timeout in seconds for this plugin as a whole
:vartype plugin_timeout: ``int``

:cvar cmd_timeout:  Timeout in seconds for individual commands
:vartype cmd_timeout:   ``int``
Nr   r&   F<no description available>c                   ^  / T l         / T l        [        5       T l        / T l        ST l        UT l        / T l        [        5       T l        / T l	        / T l
        / T l        0 T l        US   T l        US   T l        US   T l        S T l        US   R"                  T l        US   R$                  T l        0 T l        / T l        ST R                  ;   a  T R                  S   O[*        R,                  " S5      T l        T R                  R1                  T R3                  5       5        T R                   H%  nT R5                  5       T R                  U   l        M'     T R8                   H1  nT R5                  5       Ul        UT R                  UR4                  '   M3     [;        U 4S j[=        T R>                  5       5       5      T l         T RC                  [E        T 5      5        g )	Nr$   sysrootr   devicesr   soslogsosc              3   F   >#    U  H  nTR                  U5      v   M     g 7fr   )is_snap_installedr   r   rM   s     r!   r   "Plugin.__init__.<locals>.<genexpr>K  s#      
3FCD""3''3F   !)#copied_filesexecuted_commandsr   	_env_varsalertscustom_textr   forbidden_paths
copy_pathscontainer_copy_pathscopy_stringscollect_cmdsoptionsr  r   r  manifest
skip_filesskip_commandsdefault_environment_tail_files_listlogging	getLoggerr  r   get_default_plugin_optsr   r   option_listrh   r   rJ   is_snapset_predicater=   )rM   r   poptopts   `   r!   r   Plugin.__init__(  s   !#!%$&!y)h'y)!-0;;$]3AA#%  "08DLL0Hdll8,""5) 	 	D88:;LLD(,		DLL% !##CCJ%(DLL" $
  
373F
 

 	<-.r.   c           	      b    [        SS[        SS9[        SS[        SS9[        SS[        S	S9S
.$ )Ntimeoutz7Timeout in seconds for plugin to finish all collections)r   r   r   cmd-timeoutz4Timeout in seconds for individual commands to finishpostprocTz(Enable post-processing of collected data)r)  r+  r,  )r   r   r   r`   s    r!   r!  Plugin.get_default_plugin_optsR  sF     2N %rCK "D4?
 	
r.   c                    Xl         U R                   R                  SS5        U R                   R                  SS5        U R                   R                  SS5        U R                   R                  SS5        U R                   R                  SS5        U R                   R                  SS5        U R                   R                  SS5        U R                   R                  S	S5        U R                   R                  S
S5        U R                   R                  SU R                  5        U R                   R                  SS5        U R                   R                  SU R                  5        U R                   R	                  S/ 5        U R                   R	                  S/ 5        U R                   R                  S0 5        U R                   R                  S0 5        U R                   R	                  S/ 5        g)zPass in a manifest object to the plugin to write to

:param manifest: The manifest that the plugin will add metadata to
:type manifest: ``SoSManifest``

start_timer$   end_timerun_timesetup_start	setup_end
setup_timepostproc_startpostproc_endpostproc_timer)  timeout_hitFcommand_timeoutcommandsfilesstrings
containerscollectionsN)r  	add_fieldr)  
cmdtimeoutadd_list)rM   r  s     r!   set_plugin_manifestPlugin.set_plugin_manifestb  sg    !b1
B/
B/r2R0b1 0"534	4<<8u5 14??Cz2.w+	2.b1}b1r.   c                     [        U[        5      (       d  [        S5      eXl        U R	                  SU R                   35        g)z
Specify a collection of environment variables that should always be
passed to commands being executed by this plugin.

:param env_vars:    The environment variables and their values to set
:type env_vars:     ``dict{ENV_VAR_NAME: ENV_VAR_VALUE}``
z:Environment variables for Plugin must be specified by dictz0Default environment for all commands now set to N)r   dict	TypeErrorr  
_log_debugrM   env_varss     r!   set_default_cmd_environment"Plugin.set_default_cmd_environment|  sI     (D))L  $, J3346 	7r.   c                     [        U[        5      (       d  [        S5      eU R                  SU S35        U R                  R                  U5        g)z
Add or modify a specific environment variable in the set of default
environment variables used by this Plugin.

:param env_vars:    The environment variables to add to the current
                    set of env vars in use
:type env_vars:     ``dict``
z,Environment variables must be added via dictzAdding z to default environmentN)r   rE  rF  rG  r  r   rH  s     r!   add_default_cmd_environment"Plugin.add_default_cmd_environment  sG     (D))JKK'(+BCD  ''1r.   c                     Uc  U R                   $ [        U[        5      (       d  [        S5      eU R                   R	                  5       nUR                  U5        U$ )z
Get the merged set of environment variables for a command about to be
executed by this plugin.

:returns: The set of env vars to use for a command
:rtype: ``dict``
z'Command env vars must be passed as dict)r  r   rE  rF  copyr   )rM   env_envs      r!   _get_cmd_environmentPlugin._get_cmd_environment  sS     ;+++#t$$EFF'',,.Cr.   c                    Sn U R                  U5      n[        U R                  U5      5      nUc  UnO/Ub  US:X  a  U[        :X  a  UnO[        U5      nOUb	  US:  a  UnOgUb  US:  a  U$ U$ ! [         a    Us $ f = f)a  
Get the timeout value for either the plugin or a command, as
determined by either the value provided via the
plugin.timeout or plugin.cmd-timeout option, the global timeout or
cmd-timeout options, or the default value set by the plugin or the
collection, in that order of precendence.

:param optname: The name of the cmdline option being checked, either
                'plugin_timeout' or 'timeout'
:type optname:  ``str``

:param plugoptname: The name of the plugin option name being checked,
                    either 'timeout' or 'cmd-timeout'
:type plugoptname: ``str``

:param default_timeout: The timeout to default to if determination is
                        inconclusive or hits an error
:type default_timeout:  ``int``

:returns: The timeout value in seconds
:rtype:   ``int``
Nr*  )r|   r   r   rk   )rM   optnameplugoptnamedefault_timeout_timeoutopt_timeoutown_timeouts          r!   timeout_from_optionsPlugin.timeout_from_options  s    . 	#//'2Kdook:;K"&([B->/1.H";/H([2-=& HrMO	  	#""	#s"   0A1 A1 A1 A1 1B ?B c                 @    U R                  SSU R                  5      nU$ )zReturns either the default plugin timeout value, the value as
provided on the commandline via -k plugin.timeout=value, or the value
of the global --plugin-timeout option.
plugin_timeoutr)  )r\  r_  )rM   rY  s     r!   r)  Plugin.timeout  s(     ,,-=y-1-@-@Br.   c                 @    U R                  SSU R                  5      nU$ )zReturns either the default command timeout value, the value as
provided on the commandline via -k plugin.cmd-timeout=value, or the
value of the global --cmd-timeout option.
cmd_timeoutr+  )r\  rb  )rM   _cmdtimeouts     r!   r@  Plugin.cmdtimeout  s(     //}040@0@Br.   c                     SU l         U R                  R                  S[        R                  " 5       5        U R                  R                  SS5        g )NTr0  r8  )_timeout_hitr  r?  r   nowr`   s    r!   set_timeout_hitPlugin.set_timeout_hit  s8     
HLLN;t4r.   c                     U R                   $ )a   
Checks to see if the plugin has hit its timeout.

This is set when the sos.collect_plugin() method hits a timeout and
terminates the thread. From there, a Popen() call can still continue to
run, and we need to manually terminate it. Thus, check_timeout() should
only be called in sos_get_command_output().

Since sos_get_command_output() is not plugin aware, this method is
handed to that call to use as a polling method, to avoid passing the
entire plugin object.

:returns: ``True`` if timeout has been hit, else ``False``
:rtype: ``bool``

)rf  r`   s    r!   check_timeoutPlugin.check_timeout  s    "    r.   c                 p    U R                   (       a  U R                   $ U R                  R                  5       $ )z[Get the name of the plugin

:returns: The name of the plugin, in lowercase
:rtype: ``str``
)plugin_namer   lower)clss    r!   r   Plugin.name  s(     ????"||!!##r.   c                 d    U R                   c  U R                  U5        g U R                  U5        g r   )rn  display_self_helpdisplay_plugin_help)rp  sections     r!   display_helpPlugin.display_help  s(    ??"!!'*##G,r.   c                    SSK Jn  UR                  U R                  R	                  5        SU R
                   35        Sn SnU R                  S   nU[        :w  a  UR                  (       a  UR                  nU R                  (       a  X@R                  -  nUR                  SU(       a  UOU 35        [        U R                  U R                  U R                  U R                  U R                   U R"                  /5      (       d  UR                  S5        OS	 HD  n[%        XS 5      (       d  M  UR                  S
U SSR'                  [%        X5      5       3SS9  MF     [%        U S5      (       a3  UR                  SSR'                  S U R"                   5       5       3SS9  U R(                  (       a3  UR                  SSR'                  S U R(                   5       5       3SS9  [+        U S5      (       a3  UR                  SSR'                  S U R,                   5       5       3SS9  U R.                  [        R.                  La  UR                  S5        U R0                  (       d  g UR3                  S5      nUR                  S[5        SU R                   S35       S35        UR                  [5        SSS S S! S"S# S$S! 35      SS9  S%nU R0                   H  n	U	R6                  n
U
b  U
S:X  a  S&n
[9        U	R6                  [:        5      (       a  U	R6                  (       a  S'n
OS(n
SS U	R<                  S! U
S# U	R>                  S! 3nUR                  [@        RB                  " XUS)9SS9  U	RD                  (       d  M  US*-
  nS+nUR                  [@        RB                  " U	RD                  UUUS,9SS9  M     g ! [         a    S n GN9f = f)-Nr   )TERMSIZEz Plugin Information - z8
Detailed information is not available for this plugin.
r$   r1   z
    z)This plugin is always enabled by default.)rJ   r:  r;  kernel_modsrI   zEnabled by rC   r@   Fnewliner=  z+Enabled by containers with names matching: c              3   $   #    U  H  ov   M     g 7fr   r   )r   cs     r!   r   -Plugin.display_plugin_help.<locals>.<genexpr>7  s      ;NqNr   z%Enabled with the following profiles: c              3   $   #    U  H  ov   M     g 7fr   r   )r   rV   s     r!   r   r  >  s     51Qr   verify_packagesz)
Verfies packages (when using --verify): c              3   $   #    U  H  ov   M     g 7fr   r   )r   r   s     r!   r   r  F  s     @,?SS,?r   zThis plugin performs post-processing on potentially sensitive collections. Disabling post-processing may leave sensitive data in plaintext.zPlugin Optionsz/These options may be toggled or changed using 'z-k z.option_name=$valuer   
r   z<4zOption Namez<20Default<30Descriptionz6                                                      z
None/UnsetzTrue/Onz	False/Off)widthsubsequent_indent
   z        )r  initial_indentr  )#sos.helpry  	set_titlern  title
short_desc__mro__r  r   r   add_textrh   rJ   r:  r;  rz  rI   r=  getattrrH   profileshasattrr  r,  r"  add_sectionr   r   r   r   r   r   textwrapfillr   )rp  ru  ry  missing_doc_sctrigoptsec
opt_indentr&  _def_ln_sizespaces                 r!   rt  Plugin.display_plugin_help  s   %S__22455K ^^,. 	/N	D++a.Cf}{{{{# 	6$$G!<=>CLL#,,		3??LL#..2 3 3HI%3d++$$%dV2dii8J.K-LM % % % sL))  Ayy ;CNN ;;<>! !  <<79955568   3)**<99@C,?,?@@AC   <<v.6 $$%56s3??++>?@AD	
 	Bs2h}S1)C"3') + 	 	
 
??C;;D|trz##++t,,;;$D&DHSXXcN4*SXXcNCCOOc0:<  
 }}} 2MM#--u1649; "	   ' #y  	D	s   AO OOc                 F   UR                  S5        UR                  S[        S5       S35        UR                  S5      nUR                  S5        UR                  S[        S5       S	[        S
5       S35        UR                  S[        S5       S35        UR                  S5      nUR                  S[        S5       S[        S5       S35        UR                  S5      nSSS.nUR                  SSR	                  S UR                  5        5       5      -  SS9  g )NzSoS Plugin Detailed Helpz;Plugins are what define what collections occur for a given z
sos reporta   execution. Plugins are generally representative of a single system component (e.g. kernel), package (e.g. podman), or similar construct. Plugins will typically specify multiple files or directories to copy, as well as commands to execute and collect the output of for further analysis.zPlugin EnablementzPlugins will be automatically enabled based on one of several triggers - a certain package being installed, a command or file existing, a kernel module being loaded, etc...z:Plugins may also be enabled or disabled by name using the z-e $namez or z-n $namez options respectively.zCertain plugins may only be available for specific distributions or may behave differently on different distributions based on how the component for that plugin is installed or how it operates. When using zsos help report.plugins.$pluginzY, help will be displayed for the version of the plugin appropriate for your distribution.zUsing Plugin OptionszMany plugins support additional options to enable/disable or in some other way modify the collections it makes. Plugin options are set using the z#-k $plugin_name.$option_name=$valuez syntax. Options that are on/off toggles may exclude setting a value, which will be interpreted as enabling that option.

See specific plugin help sections or zsos report -lz& for more information on these optionszSee AlsozHelp for a specific $pluginz$Information on distribution policies)zreport.plugins.$pluginpolicieszLAdditional relevant information may be available in these help sections:

%sr  c              3   <   #    U  H  u  pS S US US 3v   M     g7f)r   z>8r  Nr   )r   secr   s      r!   r   +Plugin.display_self_help.<locals>.<genexpr>  s,      /!.IC r(3s)D:.!.s   Fr{  )r  r  r   r  rH   rl   )rp  ru  subsecr  seealso_alsos         r!   rs  Plugin.display_self_helpz  sh   45IL!" #	
 $$%89=	

 	HJ T*%5$66LN	

 	   ABC D	
 $$%;<!!%&K!L M N1 26o1F0G H00	
 %%j1&C>
 	#%)YY /!&/ &  	 	
r.   c                 j    SU R                  5        SUR                  SS5      R                  5        3$ )Nz[plugin:z] utf-8replace)r   encodedecoder   s     r!   _format_msgPlugin._format_msg  s5    499;-r::gy188:;= 	>r.   c                 X    U R                   R                  U R                  U5      5        g r   )r  errorr  r   s     r!   
_log_errorPlugin._log_error      $**3/0r.   c                 X    U R                   R                  U R                  U5      5        g r   )r  warningr  r   s     r!   	_log_warnPlugin._log_warn  s    D,,S12r.   c                 X    U R                   R                  U R                  U5      5        g r   )r  infor  r   s     r!   	_log_infoPlugin._log_info  s    ))#./r.   c                 X    U R                   R                  U R                  U5      5        g r   )r  debugr  r   s     r!   rG  Plugin._log_debug  r  r.   c                     U R                  5       (       d  U$ U R                  (       a8  UR                  U R                  5      (       a  U[        U R                  5      S $ U$ )zRemove the configured sysroot from a filesystem path

:param path:    The filesystem path to strip sysroot from
:type path: ``str``

:returns: The stripped filesystem path
:rtype: ``str``
N)use_sysrootr  
startswithlenrM   paths     r!   strip_sysrootPlugin.strip_sysroot  sM     !!K<<DOODLL99DLL)*++r.   c                 v    U R                   [        R                  R                  [        R                  5      :g  $ )zDetermine if the configured sysroot needs to be used

:returns: ``True`` if sysroot is not `/`, else ``False``
:rtype: ``bool``
)r  osr  abspathsepr`   s    r!   r  Plugin.use_sysroot  s$     ||rwwrvv666r.   c                     U R                   =(       d    SnXR                  R                  5       /n[        R                  R                  U5      U:H  $ )zCheck if sysroot is within the archive's temp directory

:returns: ``True`` if sysroot is in the archive's temp directory, else
          ``False``
:rtype: ``bool``
r&   )r  archiveget_tmp_dirr  r  commonprefix)rM   _sysrootpathss      r!   tmp_in_sysrootPlugin.tmp_in_sysroot  sA     <<&3<<3356ww##E*h66r.   c                 d    [        U R                  R                  R                  U5      5      S:  $ )zIs the package $package_name installed?

:param package_name:    The name of the package to check
:type package_name:     ``str``

:returns: ``True`` id the package is installed, else ``False``
:rtype: ``bool``
r   )r  r   package_managerall_pkgs_by_name)rM   package_names     r!   r   Plugin.is_installed  s+     ++<<\JKaO	
r.   c                 r    U R                   R                  R                  U5      nUSL=(       a    US   S:H  $ )zIs the snap package $package_name installed?

:param package_name:    The name of the package to check
:type package_name:     ``str``

:returns: ``True`` if the snap package is installed, else ``False``
:rtype: ``bool``
Npkg_managersnap)r   r  pkg_by_name)rM   r  r   s      r!   r  Plugin.is_snap_installed  s7     kk))55lC$?3}#5#??r.   c                 L    U R                   R                  R                  U5      $ )zDoes the service $name exist on the system?

:param name:    The name of the service to check
:type name:     ``str``

:returns: ``True`` if service is present on the system, else ``False``
:rtype: ``bool``
)r   init_system
is_servicerM   r   s     r!   r  Plugin.is_service        {{&&11$77r.   c                 L    U R                   R                  R                  U5      $ )zIs the service $name enabled?

:param name:    The name of the service to check
:type name:     ``str``

:returns: ``True if service is enabled on the system, else ``False``
:rtype: ``bool``
)r   r  
is_enabledr  s     r!   is_service_enabledPlugin.is_service_enabled  r  r.   c                 L    U R                   R                  R                  U5      $ )zIs the service $name disabled?

:param name:    The name of the service to check
:type name:     ``str``

:returns: ``True`` if service is disabled on the system, else ``False``
:rtype: ``bool``
)r   r  is_disabledr  s     r!   is_service_disabledPlugin.is_service_disabled  s     {{&&22488r.   c                 L    U R                   R                  R                  U5      $ )zIs the service $name currently running?

:param name:    The name of the service to check
:type name:     ``str``

:returns: ``True`` if the service is running on the system, else
          ``False``
:rtype: ``bool``
)r   r  
is_runningr  s     r!   r   Plugin.is_service_running!  s     {{&&11$77r.   c                 R    U R                   R                  R                  U5      S   $ )zReturn the reported status for service $name

:param name:    The name of the service to check
:type name:     ``str``

:returns: The state of the service according to the init system
:rtype: ``str``
r   )r   r  get_service_statusr  s     r!   r  Plugin.get_service_status-  s$     {{&&99$?IIr.   c                 L    U R                   R                  R                  U5      $ )zGet all service names matching regex

:param regex:    A regex to match service names against
:type regex:    ``str``

:returns: All service name(s) matching the given `regex`
:rtype: ``list``
)r   r  get_service_namesrM   r   s     r!   r  Plugin.get_service_names8  s     {{&&88??r.   c                     Xl         g)zSet or clear the default predicate for this plugin.

:param pred:    The predicate to use as the default for this plugin
:type pred:     ``SoSPredicate``
N)	predicaterM   preds     r!   r$  Plugin.set_predicateC  s	     r.   c                     Xl         g)a(  Set or clear the default predicate for command collection for this
plugin. If set, this predecate takes precedence over the `Plugin`
default predicate for command and journal data collection.

:param pred:    The predicate to use as the default command predicate
:type pred:     ``SoSPredicate``
N)cmd_predicater  s     r!   set_cmd_predicatePlugin.set_cmd_predicateK  s
     "r.   c                 d    Ub  U$ U(       a  U R                   b  U R                   $ U R                  $ )a.  Get the current default `Plugin` or command predicate.

:param cmd:     If a command predicate is set, should it be used.
:type cmd:      ``bool``

:param pred:    An optional predicate to pass if no command or plugin
                predicate is set
:type pred:     ``SoSPredicate``

:returns:   `pred` if neither a command predicate or plugin predicate
            is set. The command predicate if one is set and `cmd` is
            ``True``, else the plugin default predicate (which may be
            ``None``).
:rtype:     ``SoSPredicate`` or ``None``
)r  r  rM   rB   r  s      r!   get_predicatePlugin.get_predicateU  s3      K4%%1%%%~~r.   c                 >    U R                  XS9nUb  [        U5      $ g)aq  Test the current predicate and return its value.

:param cmd: ``True`` if the predicate is gating a command or
            ``False`` otherwise.
:param pred: An optional predicate to override the current
             ``Plugin`` or command predicate.

:returns: ``True`` or ``False`` based on predicate evaluation, or
          ``False`` if no predicate
:rtype: ``bool``
rB   r  F)r  r   r  s      r!   test_predicatePlugin.test_predicatek  s*     !!c!5:r.   c                     Uc  [        U 5      nSU SUR                  5        3nU(       a  US-  nU R                  U5        g)a  Log that a command was skipped due to predicate evaluation.

Emit a warning message indicating that a command was skipped due
to predicate evaluation. If ``kmods`` or ``services`` are ``True``
then the list of expected kernel modules or services will be
included in the log message. If ``allow_changes`` is ``True`` a
message indicating that the missing data can be collected by using
the "--allow-system-changes" command line option will be included.

:param cmd:     The command that was skipped
:type cmd:      ``str``

:param pred:    The predicate that caused the command to be skipped
:type pred:     ``SoSPredicate``

:param changes: Is the `--allow-system-changes` enabled
:type changes:  ``bool``
Nzskipped command '': z3 Use '--allow-system-changes' to enable collection.)r=   r   r  )rM   rB   r  changesr   s        r!   log_skipped_cmdPlugin.log_skipped_cmd|  sI    & <%D!#c$*=*=*?)@AHHCsr.   c                     U R                   (       d  gU R                  SU 35        U(       a  [         SU 3O[        nU R                  U[        U5      $ )a  Remove certificate and key output archived by sos report.
Any matching instances are replaced with: '-----SCRUBBED' and this
function does not take a regexp or substituting string.

:param cmd: The name of the binary to scrub certificate output from
:type cmd:  ``str``

:param desc: An identifier to add to the `SCRUBBED` header line
:type desc: ``str``

:returns: Number of replacements made
:rtype: ``int``
r   z/Scrubbing certs and keys for commands matching r   )r  rG  _cert_replacedo_cmd_output_sub
_certmatch)rM   rB   r   r  s       r!   do_cmd_private_subPlugin.do_cmd_private_sub  sR     %%=cUC	E 04]O1TF+%%c:w??r.   c           	      2   SU-   S-   n[        US5      (       a  UR                  OUnU R                  SU SU SU S35        U R                  (       d  gSn U R                   H  nUS	   c  M  US
   S:X  a  U R	                  SUS    S35        M.  [
        R
                  " US   U5      (       d  MO  [        R                  R                  U R                  S   US	   5      nU R                  SU S35        U R                  R                  U5      n	[        R                  " X#U	R                  5       5      u  pU(       d  M  U R                  R                  X5        M     U$ ! [          a(  nSnU R#                  UWS   U4-  5        Sn SnAU$ SnAff = f)a  Apply a regexp substitution to command output archived by sos

This is used to obfuscate sensitive information captured by command
output collection via plugins.

:param cmd: The command name/binary name for collected output that
            needs to be obfuscated. Internally globbed with a leading
            and trailing `*`
:type cmd:  ``str``

:param regexp: A regex to match the contents of the command output
               against
:type regexp: ``str`` or compile ``re`` object

:param subst: The substitution string used to replace matches from
              `regexp`
:type subst: ``str``

:returns: Number of replacements made
:rtype: ``int``
*patternsubstituting 'z' for 'z' in commands matching 'r   r   Nfilebinaryyesz3Cannot apply regex substitution to binary output: 'exerB   cmddirzapplying substitution to '-regex substitution failed for '%s' with: '%s')r  r  rG  r  r  fnmatchr  r  rH   r   r  	open_filer   subnr   
add_stringr   r  )rM   rB   regexpsubstglobstrr  replacementscalledr  readabler   er   s                r!   r  Plugin.do_cmd_output_sub  s   , )c/$+FI$>$>&..FUG77) 4y	 %%	 00&>)(#u,NN $006ua$A B??6%='::77<<X(>vODOO&@a$HI#||55d;H+-77x}},8(F#|//= 1* 	  	 ACOOC6%=!"445L		 s&   AE$ 3BE$ E$ $
F.FFc                 \   U R                  SU 35        [        R                  " U5      R                  nU(       a  [         SU 3O[        nU R
                   Vs/ s H  oS" US   5      (       d  M  UPM     nnU H(  nUS   nU(       d  M  U R                  U[        U5        M*     gs  snf )aq  Scrub certificate/key/etc information from files collected by sos.

Files matching the provided pathregex are searched for content that
resembles certificate, ssh keys, or similar information. Any matches
are replaced with "-----SCRUBBED $desc" where `desc` is a description
of the specific type of content being replaced, e.g.
"-----SCRUBBED RSA PRIVATE KEY" so that support representatives can
at least be informed of what type of content it was originally.

:param pathregex: A string or regex of a filename to match against
:type pathregex: ``str``

:param desc: A description of the replaced content
:type desc: ``str``
z,Scrubbing certs and keys for paths matching r   srcpathdstpathN)rG  r   compiler   r  r  do_file_subr  )	rM   	pathregexr   r   r  r    	file_listir  s	            r!   do_file_private_subPlugin.do_file_private_sub  s      	F$+' 	(

9%++/3]O1TF+ $ 1 1I 11U1Y<5HQ 1	IAY<DT:w7	  Js   B)2B)c                     U R                  U5      nU R                  SU S35        U R                  [        US5      (       a  SU SU S3UR                  -  OU5        U(       d  gU R                  R                  XBU5      nU$ ! [         aZ  nUR                  [        R                  :X  a  SnU R                  UW-  5        OSnU R                  UWU4-  5        Sn S	nAU$ S	nAff = f)
a  Apply a regexp substitution to a file archived by sos report.

:param srcpath: Path in the archive where the file can be found
:type srcpath: ``str``

:param regexp:  A regex to match the contents of the file
:type regexp: ``str`` or compiled ``re`` object

:param subst: The substitution string to be used to replace matches
              within the file
:type subst: ``str``

:returns: Number of replacements made
:rtype: ``int``
zsubstituting scrpath 'r   r  r  z' for '%s' in 'r   z-file '%s' not collected, substitution skippedr  N)
_get_dest_for_srcpathrG  r  r  r  r/  OSErrorerrnoENOENTr  )rM   r,  r#  r$  r  r&  r)  r   s           r!   r/  Plugin.do_file_sub  s     	--g6DOO4WIQ?@OO07	0J0J -UG?4&J$nn-!') <<33D%HL   		 ww%,,&Ed
+EtQi0L		s   A%B (B 
C*AC%%C*c                 l    [        U[        5      (       a  U/nU H  nU R                  USS5        M     g)a4  Obfuscate Basic_AUTH URL credentials in all files in the given
list. Proxy setting without protocol is ignored, since that is
not recommended setting and obfuscating that one can hit false
positives.

:param pathspecs: A filepath to obfuscate credentials in
:type pathspecs: ``str`` or a ``list`` of strings
zhttp(s)?://\S+:\S+@zhttp\1://******:******@N)r   r   do_path_regex_sub)rM   	pathspecsr  s      r!   do_paths_http_subPlugin.do_paths_http_sub(  s:     i%%"ID"",.HJ r.   c                 
   [        US5      (       d  [        R                  " U5      nUR                  nU R                   Vs/ s H  oT" US   5      (       d  M  UPM     nnU H  nU R                  US   X#5        M     gs  snf )a  Apply a regexp substituation to a set of files archived by
sos. The set of files to be substituted is generated by matching
collected file pathnames against `pathexp`.

:param pathexp: A regex to match filenames within the archive
:type pathexp: ``str`` or compiled ``re`` object

:param regexp: A regex to match against the contents of each file
:type regexp: ``str`` or compiled ``re`` object

:param subst: The substituion string to be used to replace matches
:type subst: ``str``
r   r,  N)r  r   r.  r   r  r/  )rM   pathexpr#  r$  r   r    r1  r  s           r!   r<  Plugin.do_path_regex_sub7  ss     w((jj)G $ 1 1I 11U1Y<5HQ 1	IDT)_f<  Js   B B c                     [        X5      $ r   )r"   )rM   r   r   s      r!   do_regex_find_allPlugin.do_regex_find_allL  s    U**r.   c           
         [         R                  " U5      n[         R                  R                  [         R                  R	                  U5      U5      n[         R                  R                  U5      nU R                  U5      (       a  U R                  SU SU 35        g [         R                  R                  U5      (       a  [         R                  R                  [         R                  R	                  U5      5      n[         R                  R                  X%S9nU R                  5       (       a-  U[        [         R                  [         R                  -   5      S  nU R                  SU SU S35        OUnU R                  SU SU S	U R                  U5       35        U R!                  U5      nU R"                  R%                  Xg5        U R                  U5      (       a  U R                  S
U S35        g U R&                  R)                  UUSUS.5         [         R*                  " U5        U R                  SU SU S35        XA:w  aH  UR1                  U R2                  5      =(       a    U R4                  R6                  n	U R9                  XIS9  g U R                  S
U S35        g ! [,         a4  nUR.                  S:X  a  U R                  S
U S35         S nAg  S nANS nAff = f)Nskipping excluded path 'z' as symlink destination from )startzmade link target 'z' relative as 'r   zcopying link 'z' pointing to 'z' with isdir=zlink 'z' is a directory, skipping...r  )r,  r-  symlinkpointsto(   z3' is part of a file system loop, skipping target...znormalized link target 'z' as 'forcez&' points to itself, skipping target...)r  readlinkr  rH   dirnamenormpath_is_skipped_pathrG  isabsrealpathrelpathr  r  r  pardirr   r  r  add_linkr  rr   r2   r7  r8  r  r  r   _in_container_do_copy_path)
rM   r,  linkdestdestabsdestrealdirreldestr-  r)  rM  s
             r!   _copy_symlinkPlugin._copy_symlinkO  s   ;;w'ww||BGGOOG4h? ''""4(  ))OO6wi @007y: ; 77=="" gg&&rwww'?@Gggooho>G!!!#bffryy&8"9":;OO0
 ;  'y+ , G.	
 K&&*oog&>%?A 	B $$W-g/??7##OOfXJ.KLM  W-4-2.6"8 	9	GGG 	28*F7)1MN  ''5 /[[.. w4OOfXJ /( ( )%  	ww"}&	 2; !; < 	s   J. .
K,8%K''K,c                     U R                  U5       HK  nU R                  SU SU S35        [        R                  R	                  X5      nU R                  U5        MM     g ! [         a  nUR                  [        R                  :X  d  [        R                  (       a  SnU R                  SU SU 35         S nAg UR                  [        R                  :X  a  SnU R                  SU S	U S35         S nAg e S nAff = f)
Nzrecursively adding 'z' from 'r   zPermission deniedz_copy_dir: 'z' z)Too many levels of symbolic links copyingz_copy_dir: z ')r   rG  r  r  rH   rX  r7  r8  EPERMEACCESr  ELOOPr  )rM   r,  r   r  r)  r   s         r!   	_copy_dirPlugin._copy_dir  s    	W-"6tf =$$+9A!/ 0ww||G2""4(	 .
  		ww%++%)gYb>?ww%++%A+cU"WIQ ?@		s%   A A# #
D-AC<>8C<;C<<Dc                     U R                  5       (       a  U R                  U5      nU R                   H  nXS   :X  d  M  US   s  $    g )Nr,  r-  )r  r   r  )rM   r,  copieds      r!   r6  Plugin._get_dest_for_srcpath  sJ    nnW-G''F++i(( ( r.   c                 B   ^ [        U4S jU R                   5       5      $ )Nc              3   R   >#    U  H  n[         R                  " UT5      v   M     g 7fr   r   r   )r   forbidr  s     r!   r   ,Plugin._is_forbidden_path.<locals>.<genexpr>  s#      
1EvBHHVT""1E   $')rh   r  r  s    `r!   _is_forbidden_pathPlugin._is_forbidden_path  s#     
151E1E
 
 	
r.   c                 V   ^ [        U4S jU R                  R                   5       5      $ )Nc              3   R   >#    U  H  n[         R                   " TU5      v   M     g 7fr   )r  )r   fpr  s     r!   r   3Plugin._is_policy_forbidden_path.<locals>.<genexpr>  s#      
0K"GOOD"%%0Krn  )rh   r   r  r  s    `r!   _is_policy_forbidden_path Plugin._is_policy_forbidden_path  s'     
040K0K
 
 	
r.   c                 d    U R                    H   n[        R                  " X5      (       d  M     g   g)zCheck if the given path matches a user-provided specification to
ignore collection of via the ``--skip-files`` option

:param path:    The filepath being collected
:type path: ``str``

:returns: ``True`` if file should be skipped, else ``False``
TF)r  r  )rM   r  
_skip_paths      r!   rQ  Plugin._is_skipped_path  s)     //Jt00 * r.   c                     [         R                  " UR                  5      n[         R                  " UR                  5      nUR                  nU R
                  R                  X[         R                  " X45      5        g r   )r  majorst_rdevminorr7   r  add_nodemakedev)rM   r  r8   dev_majdev_minmodes         r!   
_copy_nodePlugin._copy_node  sL    ((2::&((2::&zzd"**W*FGr.   c                    U R                   (       a  gU R                  U5      (       a  U R                  SU S35        gU(       d  UnU R                  5       (       a  U R	                  U5      n [
        R                  " U5      n[        R                  " UR                  5      (       a  U R                  U5        g[        R                  " UR                  5      (       an  [
        R                  " U[
        R                  5      (       aD  U R!                  U5      (       d  U R"                  R%                  U5        gU R'                  U5        g[        R(                  " UR                  5      (       dZ  [        R                  " UR                  5      (       d5  [+        U5      nU R                  SU SU S35        U R-                  X$5        gU R                  SU SU S35        UR                  S	-  (       d  U R"                  R/                  S
U5        OU R"                  R1                  XUS9  U R2                  R5                  UUSS.5        g! [         a    U R                  SU S35         gf = f)zCopy file or directory to the destination tree. If a directory, then
everything below it is recursively copied. A list of copied files are
saved for use later in preparing a report.
Nskipping forbidden path 'r   failed to stat 'z	creating z node at archive:'zcopying path 'z' to archive:'i$  r$   rL  no)r,  r-  rI  )rf  ro  rG  r  r  r  lstatr7  r  r2   S_ISLNKr7   r^  S_ISDIRaccessR_OKr   r  add_dirrd  S_ISREGr;   r  r"  add_filer  rr   )rM   r,  rZ  rM  r8   ntypes         r!   rX  Plugin._do_copy_path  s   
 ""7++OO7yBCD%%d+D	'"B
 <<

##w'<<

##		'277(C(C<<(($$T*NN7# RZZ((DLL,D,DrNEOOiw.@aHIOOD% 	.	vQGH zzE!LL##B-LL!!'u!=  "
 	 M  	NN-gYa89	s   /I I32I3c                 R   [        U[        5      (       a  U/nU R                  5       (       a   U Vs/ s H  o R                  U5      PM     nnU HO  nU R	                  SU S35        SU;   a  [
        R                  " U5      nU R                  R                  U5        MQ     gs  snf )zSpecify a path, or list of paths, to not copy, even if it's part of
an ``add_copy_spec()`` call

:param forbidden: A filepath to forbid collection from
:type forbidden: ``str`` or a ``list`` of strings
zadding forbidden path 'r   r  N)	r   r   r  r   r  r  	translater  rr   )rM   	forbiddenr    rl  s       r!   add_forbidden_pathPlugin.add_forbidden_path  s     i%%"I4=>Iq*II>FNN4VHA>?f} !**62  ''/   ?s   B$c                     XR                   ;   a    U R                   U   R                  U5        gg! [         a  nU R                  U5        e SnAff = f)a(  Set the named option to value. Ensure the original type of the
option value is preserved

:param optioname: The name of the option to set
:type optioname: ``str``

:param value: The value to set the option to

:returns: ``True`` if the option is successfully set, else ``False``
:rtype: ``bool``
TNF)r  r   r   r  )rM   
optionnamer   errs       r!   
set_optionPlugin.set_option  sS     %Z(2259   $s   1 
AAAc                     SnX;   a  [        U R                  S   U5      $ XR                  ;   a1  U R                  U   nU(       a  UR                  b  UR                  $ U$ U$ )a  Retrieve the value of the requested option, searching in order:
parameters passed from the command line, set via `set_option()`, or the
global_plugin_options dict.

`optionname` may be iterable, in which case this function will return
the first match.

:param optionname: The name of the option to retrieve the value of
:type optionname: ``str``

:param default: Optionally provide a default value to return if no
                option matching `optionname` is found. Default 0

:returns: The value of `optionname` if found, else `default`
)all_logsrz   rb  journal_sizelog_sizer_  sinceverifyr   )r  r   r  r   )rM   r  r   global_optionsr&  s        r!   r|   Plugin.get_option1  s_    "

 '4<<6
CC%,,z*Ccii3yy Nr.   c                 :    U R                   R                  U5        g r   )r  r   )rM   r  s     r!   _add_copy_pathsPlugin._add_copy_pathsQ  s    z*r.   c                     U H#  n[        X   [        5      (       d  M  X   /X'   M%     U R                  R                  U5        g)a  Apply a tag to a file matching a given regex, for use when a file
is copied by a more generic copyspec.

:param tagdict: A dict containing the filepatterns to match and the
                tag(s) to apply to those files
:type tagdict: ``dict``

`tagdict` takes the form `{file_pattern: tag}`, E.G. to match all bond
devices from /proc/net/bonding with the tag `bond`, use
`{'/proc/net/bonding/bond.*': ['bond']}`
N)r   r   filetagsr   )rM   tagdictr   s      r!   add_file_tagsPlugin.add_file_tagsT  s=     E'.#..").!1  	W%r.   c                     / nU R                   R                  5        H3  u  p4[        R                  " X15      (       d  M"  UR	                  U5        M5     U$ )zGet the tags that should be associated with a file matching a given
regex

:param fname:   A regex for filenames to be matched against
:type fname: ``str``

:returns:   The tag(s) associated with `fname`
:rtype: ``list`` of strings
)r  rl   r   r   extend)rM   r   tagsr   r   s        r!   get_tags_for_filePlugin.get_tags_for_filee  sD     ++-HCxx##C  . r.   c                 j   U R                   R                  5        H  u  pU/ US.n/ nU R                   HF  n[        R                  " XS   5      (       d  M#  UR                  US   R                  S5      5        MH     U(       d  Ml  XCS'   U R                  R                  R                  U5        M     g)zAfter file collections have completed, retroactively generate
manifest entries to apply tags to files copied by generic copyspecs
specificationfiles_copiedr  r,  r-  r&   r  N)	r  rl   r  r   r   rr   r   r  r;  )rM   
file_regextagmanifest_datamatched_filescfiles         r!   generate_copyspec_tagsPlugin.generate_copyspec_tagsu  s      $}}224OJ!+ "M
 M**88Ji(899!((y)9)@)@)EF + }0=n-##**=9  5r.   Tc                   ^^^^^ SmU R                  S5      (       a  U R                  S5      m[        R                  " S5      m[        R                  " SU R                  S5       S35      mU R	                  US9(       d&  U R                  SU S	U R                  US9 S
35        gUc  U R                  S5      nU R                  S5      (       a  SnU(       a  US-  nU(       d  g[        U[        5      (       a  U/n[        U[        5      (       a  U/nS nS mUUUUU4S jn	U GH$  n
U
(       a  [        U
5      (       d    gU(       dI  U R                  5       (       a  U R                  U
5      n
U R                  U
5      n[        U5      S:X  a  Ml  OU
/n/ n[        U5      S:X  aF  U" US   5      nU(       a  UR                  U5        UR                  U R                  US   5      5        UR                  U5        [        [!        U5      5      nU(       a  [        U[        5      (       a  U/nU H  nU R#                  U5      (       d  M  SnU(       aU  SU
 3nU R%                  UUS9nUS   S:X  a   ['        US   5      nUU:  a  SnOU R+                  SU
 SU SUS    35        My  U R,                  R                  XX/U45        U R                  SU
 SU S 35        M     GM  T(       d  T(       a  [        [/        X5      5      nUR1                  TSS!9  SnSn/ nU GH  nUU R2                  ;   a  U R+                  S"U S 35        M+  U R5                  U5      (       a  U R+                  S#U S 35        MX  U R7                  U5      (       a  U R+                  S$U S 35        M  U R9                  U5      (       a  U R+                  S%U S 35        M  U(       a  U R                  S&U S'35        M   [:        R<                  " U5      [<        R>                     nUU-  nU(       a  UU:  a  SnU(       a  [E        U5      (       a  U R                  S*U S+35        GM;  U R                  S*U S,35        UU-   U-
  nU RF                  R                  UU45        UR                  URI                  S-5      5        GM  GM  UR                  URI                  S-5      5        U RK                  U/5        U=(       a    UU:H  nGM     U(       a  GM  U RL                  (       d  GM  U RL                  RN                  R                  U
UUS..5        GM'     g! [(         a    U R                  SU
 SU S35         GMC  f = f! [@         a5    U RC                  U5      (       a  Sn GNU R                  S(U S)35         GM  f = f)/a)  Add a file, directory, or globs matching filepaths to the archive

:param copyspecs: Files, directories, or globs matching filepaths
:type copyspecs: ``str`` or a ``list`` of strings

:param sizelimit: Limit the total size of collections from `copyspecs`
                  to this size in MB
:type sizelimit: ``int``

:param maxage: Collect files with `mtime` not older than this many
               hours
:type maxage: ``int``

:param tailit: Should a file that exceeds `sizelimit` be tail'ed to fit
               the remaining space to meet `sizelimit`
:type tailit: ``bool``

:param pred: A predicate to gate if `copyspecs` should be collected
:type pred: ``SoSPredicate``

:param tags: A tag or set of tags to add to the metadata information
             for this collection
:type tags: ``str`` or a ``list`` of strings

:param container: Container(s) from which this file should be copied
:type container: ``str`` or a ``list`` of strings

`copyspecs` will be expanded and/or globbed as appropriate. Specifying
a directory here will cause the plugin to attempt to collect the entire
directory, recursively.

If `container` is specified, `copyspecs` may only be explicit paths,
not globs as currently container runtimes do not support glob expansion
as part of the copy operation.

Note that `sizelimit` is applied to each `copyspec`, not each file
individually. For example, a copyspec of
``['/etc/foo', '/etc/bar.conf']`` and a `sizelimit` of 25 means that
sos will collect up to 25MB worth of files within `/etc/foo`, and will
collect the last 25MB of `/etc/bar.conf`.
Nr  z".*((\.(zip|gz|bz2|xz))|[-.][\d]+)$^etcz/*r  zskipped copy spec 'z' due to predicate (rd   r  r  i   Fc                     U R                  S5      (       a  gU R                  S5      S   nUR                  SS5      nUR                  S5      (       a  UR                  SS5      $ g)	zGenerate a tag to add for a single file copyspec

This tag will be set to the filename, minus any extensions
except for special extensions like .conf or .log, which will be
mangled to _conf or similar.
)z/procz/sysNr&   r*  -r%   )z.confz.logz.txtr'   )r  splitr  endswith)r   _fnames     r!   get_filename_tag.Plugin.add_copy_spec.<locals>.get_filename_tag  s`      122[[%b)F^^C-F899~~c3//r.   c                 b     [         R                  R                  U 5      $ ! [         a     gf = f)z{Files should be sorted in most-recently-modified order, so
that we collect the newest data first before reaching the limit.r   )r  r  getmtimer7  )r  s    r!   r  &Plugin.add_copy_spec.<locals>.getmtime  s.    ww''-- s   ! 
..c                    > TR                  U 5      b  TR                  U 5      b  gT" U 5      n[        R                  " U5      nT(       a  UT:  d  T(       a  [        5       U-
  TS-  :  a  gg)z_When --since is passed, or maxage is coming from the
plugin, we need to filter out older files Ti  F)searchr   fromtimestampr   )r  filetimefiledatetimeconfigfile_patternr  logarchive_patternmaxager  s      r!   time_filter)Plugin.add_copy_spec.<locals>.time_filter  sg    
 $**408"))$/;~H#11(;L<%/DF8OfTk9r.   r   r1   zstat -c %s 	containerr   rD   Tzunable to determine size of 'z' in container 'z'. Skipping collection.z	stat of 'z' failed, skipping collection: zadded collection of '' from container 'r   )r   reversezskipping redundant file 'r  z skipping policy forbidden path 'rG  z
skipping 'z' over size limitr  z', skippingzFile 'z8' is over size limit and is binary. Skipping collection.zI' is over size limit, will instead tail the file during collection phase.r&   r  )(r|   r   r.  r   r  r  r  r   r   r  r  _expand_copy_specrr   r  r  r   r   container_existsexec_cmdr   rk   rG  r  filtersortr  ro  ru  rQ  r  r2   ST_SIZEr7  r   r   r  r   r  r  r;  )rM   	copyspecs	sizelimitr  tailitr  r  r  r  r  copyspecr;  
_spec_tags_speccon_tailrB   retconsizecurrent_sizelimit_reached_manifest_files_file	file_sizeadd_sizer  r  r  r  s      `                     @@@@r!   add_copy_specPlugin.add_copy_spec  s   V ??7##OOG,EZZ(MNZZ1T^^E-B,C2(FG"""-NN0 <  $ 2 2 2 =>aA B
3I??:&&I$Ii%%"IdC  6D			 	 "HX##%%#~~h7H..x8u:? # "
J5zQ(q2%%e,!!$"8"8q"BCd#c*o.Ji--!*I$C0055 !E  !,H:6"mmC3m?x=A-
)*-c(m*<#*Y#6,0E !OO"+H:5EcU K@#&x=/!34 %--44	*E NN/z :5#= %J VK78JJ8TJ2L!M ODOO+OO&?wa$HI**511OO&?wa$HI11%88OO:5'CE((//OO&>ugQ$GH NNZw6G#HI	! "t|| <I 	)	!9$(M)%00 NN"( 0? !? %$UG ,E E $-y#8<#G--44eX5FG'..u||C/@A " $**5<<+<=((%1 &/%L<93LMm p 9===MM''..)1(7 *0 K "T E $. ) $&CH: N669U ;2%2!"
 !))l  ! ''..$%	)9%'LM !s*   :U8'U>"U;:U;>"V=#V=<V=r  c                 2  ^ / n[        U[        5      (       a  U/n[        U[        5      (       a  U/n[        U R                  U5      nU
(       aG  [        U
[        5      (       a  U
/n
U V^s/ s H!  m[	        U4S jU
 5       5      (       d  M  TPM#     nnU(       aG  [        U[        5      (       a  U/nU V^s/ s H!  m[	        U4S jU 5       5      (       a  M  TPM#     nnUR                  U5        U R                  UUUXEUXxU	XUS9  gs  snf s  snf )a  Run a command or list of commands against devices discovered during
sos initialization.

Any commands specified by cmd will be iterated over the list of the
specified devices. Commands passed to this should include a '%(dev)s'
variable for substitution.

:param cmds:    The command(s) to run against the list of devices
:type cmds:     ``str`` or a ``list`` of strings

:param devices: The device paths to run `cmd` against. This should be
                either a list of devices/device paths or a key in the
                devices dict discovered by sos during initialization.
:type devices:  ``str`` or a ``list`` of devices or device paths.

:param timeout: Timeout in seconds to allow each `cmd` to run
:type timeout: ``int``

:param sizelimit: Maximum amount of output to collect, in MB
:type sizelimit: ``int``

:param chroot: Should sos chroot the command(s) being run
:type chroot: ``bool``

:param runat: Set the filesystem location to execute the command from
:type runat: ``str``

:param env: Set environment variables for the command(s) being run
:type env: ``dict``

:param binary: Is the output collected going to be binary data
:type binary: ``bool``

:param prepend_path: The leading path for block device names
:type prepend_path: ``str`` or ``None``

:param whitelist: Limit the devices the `cmds` will be run against to
                  devices matching these item(s)
:type whitelist: ``list`` of ``str``

:param blacklist: Do not run `cmds` against devices matching these
                  item(s)
:type blacklist: ``list`` of ``str``

:param subdir:  Write the command output to this subdir within the
                Plugin directory
:type subdir:   ``str``
c              3   X   >#    U  H  n[         R                  " S U 3T5      v   M!     g7fz(.*)?Nrk  )r   wlds     r!   r   (Plugin.add_device_cmd.<locals>.<genexpr>  %     GYrE",22Y   '*c              3   X   >#    U  H  n[         R                  " S U 3T5      v   M!     g7fr  rk  )r   blr  s     r!   r   r    r  r  )
r)  r  chrootrunatrQ  r  prepend_pathr  prioritysubdirN)r   r   r   r  rh   r  _add_device_cmd)rM   cmdsr  r)  r  r  r  rQ  r  r  	whitelist	blacklistr  r  r  	_dev_tags_devsr  s                    `r!   add_device_cmdPlugin.add_device_cmd  s   j 	dC  6Dgs##iG,T\\7C)S))&K	 % I1GYGG E I )S))&K	 % I1GYGG E I 	T5''0u!$,"+v 	 	OIIs   .DD<DDc                 L   [        U[        5      (       a  U/n[        U[        5      (       a  U/nU=(       d    U R                  S5      nU HT  nU HK  nU/nUR                  U
5        U	(       a  U R	                  X5      nUSU0-  nU R                  UUXEXgUXUS9
  MM     MV     g)zCRun a command against all specified devices on the system.
        r  dev)
rB   r)  r  r  r  rQ  r  r  r  r  N)r   r   r|   r  r   _add_cmd_output)rM   r  r  r)  r  r  r  rQ  r  r  r  r  r  rB   devicer  _cmds                    r!   r   Plugin._add_device_cmd  s    
 dC  6Dgs##iG<!<	C!#H	  &!^^LAFeV_,$$w/8+0&*3,2	 % 4 " r.   c                 Z   SU;   a  UR                  S5      O
[        U 5      nSU;  a  SUS'   SU;  a  SUS'   [        [        S0 UD6SS5      (       d)  U R	                  S5      (       d	  US   S	:X  a
  S	US'   S
US'   SU;   a  UR                  S5        [        S0 UD6nU R                  S[        U5       35        U R                   HJ  n[        R                  " UR                  U5      (       d  M+  U R                  SUR                   S35          g   U R                  S
US9(       a]  U R                  R                  U5        Sn[        USS5      b  SUR                   S3nU R                  SUR                   SU 35        gU R                  UR                  X#R                   S9  g)z?Internal helper to add a single command to the collection list.r  r  r  r  Fsnap_cmdr  r  r   Tto_filezpacked command: zskipping excluded command 'r   Nr  r$   runas	, as the  userzadded cmd output 'r  r   )popr=   r  r   r|   rG  r   r  r  rB   r  r  rr   r  r  r  r  )rM   r   r  soscmd	_skip_cmdusers         r!   r
  Plugin._add_cmd_output  s    &,v%5vzz&!<;MV#!#F:F" %F9
,V,j%@@OOJ''6++>!+C"#F; $F9JJz"%f%*3v;-89++I
 vzz955"=fjj\ KL , 4d3$$V,Dvw-9"6<<.6NN/

|1TFCD  T>> Jr.   c                    [        U[        5      (       a  U/nU(       a)  U Vs/ s H  nU R                  XS9(       d  M  UPM     nnO)U Vs/ s H  oR                  U5      (       d  M  UPM     nnU(       d  SU(       a  SOS 3nOSnU H(  nU R	                  U(       a  SOS SU S	U 3XEXgXXUS
9
  M*     gs  snf s  snf )a]  
Used as a way to standardize our collections of directory listings,
either as an output of `ls` or `tree` depending on if the `tree`
parameter is set to `True`.

This is ultimately a wrapper around `add_cmd_output()` and supports
several, but not all, of the options for that method.

:param paths:   The path(s) to collect a listing for
:type paths:     ``str`` or a ``list`` of ``str``s

:param tree:    Collect output with `tree` instead of `ls`
:type tree:     ``bool`` (default: False)

:param recursive:   Recursively list directory contents with `ls`
:type recursive:    ``bool`` (default: False)
r  alZRr$   lptreelsz -r   )	r  rQ  r  r  r  r  r  r  suggest_filenameN)r   r   container_path_existsr   add_cmd_output)rM   r  r  	recursiver  rQ  r  r  r  r  r  r  r   rV   r  r  s                   r!   add_dir_listingPlugin.add_dir_listing  s    * eS!!GE % I1///G E IE !&=1)9)9!)<QE=9C"56GGD!6t,Bwiq?)I!1	    I >s   B9 B9B>*B>c                    [        U[        5      (       a  U/n[        U5      S:  a  U(       d  U(       a  U R                  S5        U
c  U R	                  S5      n
Uc  U R                  SS9nU Hc  nSnU(       a9  UnUU4nU R                  UU5      nU(       d  U R                  SU SU S	35        ME  U R                  UUX4XVUXU
XUXUUUUUUS
9  Me     g)a&
  Run a program or a list of programs and collect the output

Output will be limited to `sizelimit`, collecting the last X amount
of command output matching `sizelimit`. Unless `suggest_filename` is
set, the file that the output is saved to will match the command as
it was executed, and will be saved under `sos_commands/$plugin`

:param cmds: The command(s) to execute
:type cmds: ``str`` or a ``list`` of strings

:param suggest_filename: Override the name of the file output is saved
                         to within the archive
:type suggest_filename: ``str``

:param root_symlink: If set, create a symlink with this name in the
                     archive root
:type root_symlink: ``str``

:param timeout: Timeout in seconds to allow each `cmd` to run for
:type timeout: ``int``

:param stderr: Should stderr output be collected
:type stderr: ``bool``

:param chroot: Should sos chroot the `cmds` being run
:type chroot: ``bool``

:param runat: Run the `cmds` from this location in the filesystem
:type runat: ``str``

:param env: Set environment variables for the `cmds` being run
:type env: ``dict``

:param binary: Is the command expected to produce binary output
:type binary: ``bool``

:param sizelimit: Maximum amount of output in MB to save
:type sizelimit: ``int``

:param pred: A predicate to gate if `cmds` should be collected or not
:type pred: ``SoSPredicate``

:param subdir: Save output to this subdirectory, within the plugin's
               directory under sos_commands
:type subdir: ``str``

:param changes: Do `cmds` have the potential to change system state
:type changes: ``int``

:param foreground: Should the `cmds` be run in the foreground, with an
                   attached TTY
:type foreground: ``bool``

:param tags: A tag or set of tags to add to the metadata entries for
             the `cmds` being run
:type tags: ``str`` or a ``list`` of strings

:param priority:  The priority with which this command should be run,
                  lower values will run before higher values
:type priority: ``int``

:param cmd_as_tag: Should the command string be automatically formatted
                   to a tag?
:type cmd_as_tag: ``bool``

:param container: Run the specified `cmds` inside a container with this
                  ID or name
:type container:  ``str``

:param to_file: Should command output be written directly to a new
                file rather than stored in memory?
:type to_file:  ``bool``

:param runas: Run the `cmd` as the `runas` user
:type runas: ``str``

:param snap_cmd: Are the commands being run from a snap?
:type snap_cmd: ``bool``
r1   z.ambiguous filename or symlink for command listNr  T)rB   zSkipping command 'z' as the requested container 'z' does not exist.)rB   r   root_symlinkr)  stderrr  r  rQ  r  r  r  r  r  r  
foregroundr  
cmd_as_tagr  container_cmdr  r  )	r   r   r  r  r|   r  fmt_container_cmdrG  r
  )rM   r  r   r'  r)  r(  r  r  rQ  r  r  r  r  r  r)  r  r  r*  r  r  r  r  rB   r+  ocmds                            r!   r"  Plugin.add_cmd_output6  s   l dC  6Dt9q=.,NNKL
3I<%%$%/DC M!%y 1,,Y<OO&8 ?<<E; G1%1 2   S;K.:(.U%(9&*)0*2z)0',x ! A r.   c                     U H#  n[        X   [        5      (       d  M  X   /X'   M%     U R                  R                  U5        g)aR  Retroactively add tags to any commands that have been run by this
plugin that match a given regex

:param tagdict: A dict containing the command regex and associated tags
:type tagdict: ``dict``

`tagdict` takes the form of {cmd_regex: tags}, for example to tag all
commands starting with `foo` with the tag `bar`, use
{'foo.*': ['bar']}
N)r   r   cmdtagsr   )rM   r  rB   s      r!   add_cmd_tagsPlugin.add_cmd_tags  s<     C',,, '~  	G$r.   c                     U R                   R                  5        H$  u  p#[        R                  " X!5      (       d  M"  Us  $    / $ )zGet the tag(s) that should be associated with the given command

:param cmd: The command that tags should be applied to
:type cmd: ``str``

:returns: Any tags associated with the command
:rtype: ``list``
)r0  rl   r   r   )rM   rB   r   r   s       r!   get_tags_for_cmdPlugin.get_tags_for_cmd  s8     **,HCxx!!
 - 	r.   c                    [         R                  R                  U R                  R	                  5       SU R                  5       5      nU(       a  [         R                  R                  X15      nU(       a  [         R                  " USS9  U$ )ay  Get the path where this plugin will save command output

:param name: Optionally specify a filename to use as part of the
             command output path
:type name: ``str`` or ``None``

:param make: Attempt to create the command output path
:type make: ``bool``

:returns: The path where the plugin will write command output data
          within the archive
:rtype: ``str``
sos_commandsT)exist_ok)r  r  rH   r  r  r   makedirs)rM   r   makecmd_output_paths       r!   get_cmd_output_pathPlugin.get_cmd_output_path  s]     '',,t||'?'?'A'5tyy{D ggll?AOKK$7r.   c                     [        U/UQ76 $ )a  Grep through file(s) for a specific string or regex

:param regexp: The string or regex to search for
:type regexp: ``str``

:param fnames: Paths to grep through
:type fnames: ``str``, ``list`` of string, or open file objects

:returns: Lines matching `regexp`
:rtype: ``str``
)r   )rM   r#  fnamess      r!   	file_grepPlugin.file_grep  s     F$V$$r.   c                 L    U R                   R                  5       n[        X5      $ r   )r  r+   r-   )rM   r  r+   s      r!   r-   Plugin._mangle_command  s    <<((*s--r.   c                 6   U R                  5       nU(       a  USU 3-  n[        R                  R                  U R                  S   U5      nU R                  U5      n[        R                  R                  [        R                  R                  U R                  R                  5       XE5      5      (       a  SnU R                  R                  5       n SU 3nUn	U[        U	5      [        U5      -   :  a  U	SU[        U	5      -
  [        U5      -
   n	X-   n	[        R                  R                  [        R                  R                  U R                  R                  5       XI5      5      (       d  U	nOUS-  nM  [        R                  R                  XE5      $ )z@The internal function to build up a filename based on a command.r&   r  r1   r'   N)r   r  r  rH   r   r-   existsr  r  r+   r  )
rM   r  r  
plugin_diroutdiroutfnincr+   rP   newfns
             r!   _make_command_filenamePlugin._make_command_filename  sP    YY[
AfX,&Jdll84jA$$S) 77>>"'',,t||'?'?'A'-6 7 7C||,,.HSEc%jV44!"DHSZ$7F$CEEww~~bggll4<<3K3K3M39'B C C!Eq  ww||F**r.   c                     [        U[        5      (       d  U/nU H<  nU R                  R                  X"R	                  5       UR                  5       /5        M>     g)a_  Add an environment variable to the list of to-be-collected env vars.

Collected environment variables will be saved to an `environment` file
in the archive root, and any variable specified for collection will be
collected in lowercase, uppercase, and the form provided

:param name: The name of the environment variable to collect
:type name: ``str``
N)r   r   r  r   upperro  )rM   r   rQ  s      r!   add_env_varPlugin.add_env_var	  sG     $%%6DC NN!!3		SYY["AB	 r.   c                 z   U R                  SUS9(       d#  U R                  SU R                  US9 S35        gU(       a  SOSn[        R                  R                  X`R                  5       U5      n[        U[        5      (       a  U/nU R                  R                  XU45        U R                  S	U S
35        g)as  Add a string to the archive as a file

:param content: The string to write to the archive
:type content: ``str``

:param filename: The name of the file to write `content` to
:type filename: ``str``

:param pred: A predicate to gate if the string should be added to the
             archive or not
:type pred: ``SoSPredicate``

:param plug_dir: Should the string be saved under the plugin's dir in
                 sos_commands/? If false, save to sos_strings/
:type plug_dir: ``bool``

:param tags: A tag or set of tags to add to the manifest entry for this
             collection
:type tags: ``str`` or a ``list`` of strings
Fr  z!skipped string due to predicate (r  rd   Nr7  sos_stringszadded string as 'r   )r  r  r  r  r  rH   r   r   r   r  rr   rG  )rM   contentfilenamer  plug_dirr  sos_dirs          r!   add_string_as_filePlugin.add_string_as_file	  s    . ""u4"8NN #11t1<=Q@ A$,.-77<<h?dC  6D  'T!:;+H:Q78r.   c                    U R                   (       a  gUc  U R                  n/ n[        U[        5      (       a  U/nUR	                  U5        UR	                  U R                  U5      5        U(       a'  UR                  [        R                  " SSU5      5        [        [        U5      5      nU R                  U5      nU(       d  U R                  S   R                  S:X  a  U R                  nOSnU(       a  U R                  X+5      nOU R                  X5      nU[!        U R                  S   5      S-   S nU(       an  U R#                  SU S	35        U R$                  R'                  U[(        5        [*        R,                  R/                  U R$                  R1                  5       U5      nOS
n[3        5       n[5        XUUUUXU R6                  UUUUS9n[3        5       nUU-
  nUS   S:X  a;  SU SU S3nU R9                  U5        U(       a  SU 3n U R#                  U U  35        UR;                  S5      S   UR;                  S5      SS UU(       a  UOSUS   US   UUUUUS.n!US   S:X  d	  US   S:X  a  U(       as  US:w  am  U R                  S   R                  S:w  aP  U R=                  SUR;                  5       S    SU S35        [5        XS
UXU
U R6                  UUS9
n[3        5       U-
  nU R#                  SU S35        US   S;   a8  U R>                  (       a'  U R>                  R@                  R                  U!5        U$ U R#                  SUR;                  5       S    S U S!U S"35        US   (       az  U R=                  SUR;                  5       S    S#35        Un"URC                  S$S%5      S&-   nU(       a6  U R$                  R'                  U[(        S'S(9n#[*        RD                  " UU#5        U(       dF  U	(       a   U R$                  RG                  US)   U5        OU R$                  RI                  US)   U5        US   (       a  [*        R,                  R/                  U R$                  R1                  5       U5      n$[*        R,                  R/                  U R$                  R1                  5       W"5      n%[*        R,                  RK                  U$U%5      n&U&RC                  S*S+S5      n&U R$                  RM                  U&U"5        U(       a  U R$                  RM                  UU5        U RN                  R                  UUU	(       a  S,OS-S..5        U(       a8  [*        R,                  R/                  U R$                  R1                  5       U5      OS+US/'   U R>                  (       aV  UU!S0'   UU!S1'   U R>                  R@                  R                  U!5        U(       a   U RQ                  U!RS                  5       U5        U$ )2ab  Execute a command and save the output to a file for inclusion in the
report.

Positional Arguments:
    :param cmd:                 The command to run

Keyword Arguments:
    :param suggest_filename:    Filename to use when writing to the
                                archive
    :param root_symlink:        Create a symlink in the archive root
    :param timeout:             Time in seconds to allow a cmd to run
    :param stderr:              Write stderr to stdout?
    :param chroot:              Perform chroot before running cmd?
    :param runat:               Run the command from this location,
                                overriding chroot
    :param env:                 Dict of env vars to set for the cmd
    :param binary:              Is the output in binary?
    :param sizelimit:           Maximum size in MB of output to save
    :param subdir:              Subdir in plugin directory to save to
    :param changes:             Does this cmd potentially make a change
                                on the system?
    :param foreground:          Run the `cmd` in the foreground with a
                                TTY
    :param tags:                Add tags in the archive manifest
    :param cmd_as_tag:          Format command string to tag
    :param to_file:             Write output directly to file instead
                                of saving in memory
    :param tac:                 Reverse log lines order
    :param runas:               Run the `cmd` as the `runas` user

:returns:       dict containing status, output, and filename in the
                archive for the executed cmd

Nz[^\w\.]+r%   r   alwaysr  r1   collecting 'z' output directly to diskF)r)  r(  r  chdirrQ  r  r  pollerr)  r  tacr  r   |   z	command 'z' timed out after rT   z3 - output up until the timeout may be available at r   r   	truncated)r*   
parametersexecfilepathr`  return_coder  r/  r0  r1  r  ~      r&   z' not found in z - re-trying in host root)	r)  r  r\  rQ  r  r  r]  r  r^  zcould not run 'z': command not found)re  rf  zcollected output of '' in z
 (changes=rd   z' was truncatedr7  rR  .tailedTrL  rD   z../r$   r  r  )rB   r  r  rT  rc  r1  )*rf  r@  r   r   r  r4  rr   r   r(   r   r   rS  r   r  r  rK  r  rG  r  
check_pathr   r  r  rH   get_archive_pathr   r   rk  r  r  r  r  r:  r  rename
add_binaryr"  rT  rV  r  _add_container_cmd_to_manifestrP  )'rM   rB   r   r'  r)  r(  r  r  rQ  r  r  r  r  r)  r  r  r*  r  r^  r+  r  _tagsrR  rootrH  outfn_stripout_filerH  r   endr1  warnr   manifest_cmdlinkfnrZ  _outfn_path
_link_pathrpaths'                                          r!   _collect_cmd_outputPlugin._collect_cmd_outputC	  sT   R ?ooGdC  6DTT**3/0LLS#67SZ ((-T\\-0778C<<DD//0@IE//<ECX 679:;OOl3%/HIJLL##E62ww||DLL$A$A$CUKHH'T&%%*#U	
 f;(s"se#5gYa@DNN4 L"4&/ yy~a())C.,!(d,!(+  
 (s"fX&6#&=<<.55ANNYsyy{1~.>o&*V+D$F G3U%)#118F
  $v~HOOocU2FGH h:-==MM**11,?!M/		A/?uXJ$WIQ0 	1 +NN2399;q>2B C' ' (FMM.-@9LE||..ufD.I		(D)''x(8%@''x(8%@+ '',,t||'D'D'FNKdll&C&C&EvNJGGOOK<EMM%Q/ELL!!%0LL!!%6 	%%c;:@d'L 	M EJBGGLL668%@ 	z
 ==',L$'/L$MM"")),733L4E4E4G4ACr.   c                     U R                  SUS9(       d  U R                  XUS9  SSSS.$ U R                  XUXEXgXXXUS9$ )a  Execute a command and save the output to a file for inclusion in the
report, then return the results for further use by the plugin

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

:param suggest_filename:    Filename to use when writing to the
                            archive
:param suggest_filename: ``str``

:param root_symlink:        Create a symlink in the archive root
:type root_symlink: ``bool``

:param timeout:             Time in seconds to allow a cmd to run
:type timeout: ``int``

:param stderr:              Write stderr to stdout?
:type stderr: ``bool``

:param chroot:              Perform chroot before running cmd?
:type chroot: ``bool``

:param runat:               Run the command from this location,
                            overriding chroot
:type runat: ``str``

:param env:                 Environment vars to set for the cmd
:type env: ``dict``

:param binary:              Is the output in binary?
:type binary: ``bool``

:param sizelimit:           Maximum size in MB of output to save
:type sizelimit: ``int``

:param subdir:              Subdir in plugin directory to save to
:type subdir: ``str``

:param changes:             Does this cmd potentially make a change
                            on the system?
:type changes: ``bool``

:param foreground:          Run the `cmd` in the foreground with a TTY
:type foreground: ``bool``

:param tags:                Add tags in the archive manifest
:type tags: ``str`` or a ``list`` of strings

:param runas:               Run the `cmd` as the `runas` user
:type runas: ``str``

:returns:       `cmd` exit status, output, and the filepath within the
                archive output was saved to
:rtype: ``dict``
Tr  r  Nr$   )r   rD   rT  )r   r'  r)  r(  r  r  rQ  r  r  r)  r  r  r  )r  r  ry  )rM   rB   r   r'  r)  r(  r  r  rQ  r  r  r  r  r)  r  r  r  s                    r!   collect_cmd_outputPlugin.collect_cmd_output	  sl    z ""t$"7  G <  ''6iE	 ( 
 	
r.   c                    SSS.nU R                  SUS9(       d  U$ Uc  U R                  nU(       d  U R                  S   R                  S:X  a  U R                  nOSnU R                  U5      nU
(       al  U R                  5       c  U R                  SU S	U
 S
35        U$ U R                  U
5      (       a  U R                  XU5      nOU R                  SU S	U
 S35        [        XUXWUXUS9	$ )a  Execute a command right now and return the output and status, but
do not save the output within the archive.

Use this method in a plugin's setup() if command output is needed to
build subsequent commands added to a report via add_cmd_output().

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

:param timeout:             Time in seconds to allow a cmd to run
:type timeout: ``int``

:param stderr:              Write stderr to stdout?
:type stderr: ``bool``

:param chroot:              Perform chroot before running cmd?
:type chroot: ``bool``

:param runat:               Run the command from this location,
                            overriding chroot
:type runat: ``str``

:param env:                 Environment vars to set for the cmd
:type env: ``dict``

:param binary:              Is the output in binary?
:type binary: ``bool``

:param pred:                A predicate to gate execution of the `cmd`
:type pred: ``SoSPredicate``

:param foreground:          Run the `cmd` in the foreground with a TTY
:type foreground: ``bool``

:param container:           Execute this command in a container with
                            this name
:type container: ``str``

:param quotecmd:            Whether the cmd should be quoted.
:type quotecmd: ``bool``

:param runas:               Run the `cmd` as the `runas` user
:type runas: ``str``

:returns:                   Command exit status and output
:rtype: ``dict``
Nr$   )r   rD   Tr  r   rZ  zCannot run cmd 'z' in container z: no runtime detected on host.z: no such container is running.)r)  r  r\  r  rQ  r)  r(  r  )r  r@  r   r  r  rS  _get_container_runtimer  r  r,  r   )rM   rB   r)  r(  r  r  rQ  r  r  r)  r  quotecmdr  _defaultro  rR  s                   r!   r  Plugin.exec_cmdE
  s   f #b1""t$"7O?ooGT\\-0778C<<DD((-**,4!1#o"+,J L M$$Y//,,YXF!1#o"+,K M N &c4,1d1;,13 	3r.   c                     XR                   R                  ;  a  / / S.U R                   R                  U'   U R                   R                  U   S   R                  UUUS.5        g)a  Adds a file collection to the manifest for a particular container
and file path.

:param container:   The name of the container
:type container:    ``str``

:param path:        The filename from the container filesystem
:type path:         ``str``

:param arcpath:     Where in the archive the file is written to
:type arcpath:      ``str``

:param tags:        Metadata tags for this collection
:type tags:         ``str`` or ``list`` of strings
r;  r:  r;  r  N)r  r=  rr   )rM   r  r  arcpathr  s        r!   _add_container_file_to_manifest&Plugin._add_container_file_to_manifest
  s]      MM444<>B2ODMM$$Y/  +G4;;!#=
 	r.   c                 L   Uu  p4X@R                   R                  ;  a  / / S.U R                   R                  U'   X1S'   UR                  S5      S   US'   UR                  S5      SS US'   S	U S
U R                  5        3nSUS    3nU R	                  U5      nU SU 3nU R
                  R                  U[        5      (       a/  [        R                  " X`R
                  R                  U5      5        XS'   U R                   R                  U   S   R                  U5        g)aK  Adds a command collection to the manifest for a particular container
and creates a symlink to that collection from the relevant
sos_containers/ location

:param manifest:    The manifest entry for the command
:type manifest:     ``dict``

:param contup:      A tuple of (original_cmd, container_name)
:type contup:       ``tuple``
r  rb  r   r   r*   r1   Nra  sos_containers/z/sos_commands/z../../../../rc  r&   r:  )r  r=  r  r   r-   r  ri  r   r  rI  	dest_pathrr   )	rM   r  contuprB   r  _cdir_outloccmdfnconlnks	            r!   rm  %Plugin._add_container_cmd_to_manifest
  s     MM444<>B2ODMM$$Y/!iinQ/!$3!3!)N499;-H *!5 67$$S)7!E7#
 <<""6622JJw 6 6v >?%  +J7>>xHr.   c                 8   UcC  SU R                   R                  R                  5       ;   a  U R                   R                  S   $  g[        U R                   R                  R                  5       5       H#  nX:X  d  M
  U R                   R                  U   s  $    g)zZBased on policy and request by the plugin, return a usable
ContainerRuntime if one exists
Nr   )r   runtimeskeysr   )rM   runtimepol_runtimes      r!   r  Plugin._get_container_runtime
  s     ?DKK005577{{++I66 8   $DKK$8$8$=$=$?@);;//<<  A r.   c                     U R                  5       nUb+  UR                  U5      =(       d    UR                  U5      SL$ g)a  If a container runtime is present, check to see if a container with
a given name is currently running

:param name:    The name or ID of the container to check presence of
:type name: ``str``

:returns: ``True`` if `name` exists, else ``False``
:rtype: ``bool``
NF)r  r  get_container_by_namerM   r   _runtimes      r!   r  Plugin.container_exists
  sH     ..0--d3 E2248DFr.   c                     U R                  5       nUbB  UR                  US9nU Vs/ s H%  n[        R                  " XS   5      (       d  M#  UPM'     sn$ / $ s  snf )aL  Get a list of all container names and ID matching a regex

:param regex:   The regular expression to match
:type regex:    ``str``

:param get_all: Return all containers found, even terminated ones
:type get_all:  ``bool``

:returns:   All container IDs and names matching ``regex``
:rtype:     ``list`` of ``tuples`` as (id, name)
get_allr1   )r  get_containersr   r   )rM   r   r  r  _containersr~  s         r!   get_all_containers_by_regex"Plugin.get_all_containers_by_regex
  sZ     ..0"11'1BK*D{!bhhud.CA{DD	 Es   "AAc                 L    U R                  5       nUb  UR                  U5      $ g)zGet the container ID for a specific container

:param name:    The name of the container
:type name: ``str``

:returns: The ID of the container if it exists
:rtype: ``str`` or ``None``
N)r  r  r  s      r!   r  Plugin.get_container_by_name
  s,     ..011$77r.   c                 n    U R                  US9nUb"  U(       a  UR                  SS9$ UR                  $ / $ )a  Return a list of all container IDs from the ``Policy``
``ContainerRuntime``

If `runtime` is not provided, use the ``Policy`` default

:param runtime:     The container runtime to use, if not the default
                    runtime detected and loaded by the ``Policy``
:type runtime: ``str``

:param get_all:     Return all containers known to the `runtime`, even
                    those that have terminated
:type get_all: ``bool``

:returns: All container IDs found by the ``ContainerRuntime``
:rtype: ``list``
r  Tr  )r  r  r=  )rM   r  r  r  s       r!   r  Plugin.get_containers  sE    " ..w.?..t.<<&&&	r.   c                 B    U R                  US9nUb  UR                  $ / $ )a  Return a list of all image names from the Policy's
ContainerRuntime

If `runtime` is not provided, use the Policy default. If the specified
`runtime` is not loaded, return empty.

:param runtime:     The container runtime to use, if not using the
                    default runtime detected by the ``Policy``
:type runtime: ``str``

:returns: A list of container images known to the `runtime`
:rtype: ``list``
r  )r  imagesrM   r  r  s      r!   get_container_imagesPlugin.get_container_images$  s,     ..w.???"	r.   c                 B    U R                  US9nUb  UR                  $ / $ )a  Return a list of all volume names from the Policy's
ContainerRuntime

If `runtime` is not provided, use the Policy default. If the specified
`runtime` is not loaded, return empty.

:param runtime:     The container runtime to use, if not using the
                    default runtime detected by the ``Policy``
:type runtime: ``str``

:returns: A list of container volumes known to the `runtime`
:rtype: ``list``
r  )r  volumesr  s      r!   get_container_volumesPlugin.get_container_volumes7  s.     ..w.?###	r.   c                     U R                  5       nUbc  [        U[        5      (       a  U/nU HD  nU R                  XR5      nU H*  nUR	                  US   5      nU R
                  " U40 UD6  M,     MF     gg)a,  Helper to get the ``logs`` output for a given container or list
of container names and/or regexes.

Supports passthru of add_cmd_output() options

:param containers:   The name of the container to retrieve logs from,
                     may be a single name or a regex
:type containers:    ``str`` or ``list`` of strs

:param get_all:     Should non-running containers also be queried?
                    Default: False
:type get_all:      ``bool``

:param kwargs:      Any kwargs supported by ``add_cmd_output()`` are
                    supported here
Nr1   )r  r   r   r  get_logs_commandr"  )	rM   r=  r  r   r  r  _cons_conrB   s	            r!   add_container_logsPlugin.add_container_logsJ  s|    " ..0*c**(\
'	88L!D"33DG<C''6v6 " (  r.   c                 t    U R                  U5      (       a"  U R                  5       nUR                  XU5      $ g)a  Format a command to be executed by the loaded ``ContainerRuntime``
in a specified container

:param container:   The name of the container to execute the `cmd` in
:type container: ``str``

:param cmd:         The command to run within the container
:type cmd: ``str``

:param quotecmd:    Whether the cmd should be quoted.
:type quotecmd: ``bool``

:returns: The command to execute so that the specified `cmd` will run
          within the `container` and not on the host
:rtype: ``str``
r$   )r  r  r,  )rM   r  rB   r  r  s        r!   r,  Plugin.fmt_container_cmde  s9    "   ++224H--ihGGr.   c                 2    XR                   R                  ;   $ )zDetermine whether specified module is loaded or not

:param module_name: Name of kernel module to check for presence
:type module_name: ``str``

:returns: ``True`` if the module is loaded, else ``False``
:rtype: ``bool``
)r   rz  )rM   module_names     r!   r}   Plugin.is_module_loaded{  s     kk5555r.   c                 :    U R                   R                  U5        g)zAdd an alert to the collection of alerts for this plugin. These
will be displayed in the report

:param alertstring: The text to add as an alert
:type alertstring: ``str``
N)r  rr   )rM   alertstrings     r!   	add_alertPlugin.add_alert  s     	;'r.   c                 .    U =R                   U-  sl         g)zAppend text to the custom text that is included in the report. This
is freeform and can include html.

:param text:    The text to include in the report
:type text:     ``str``
N)r  )rM   texts     r!   add_custom_textPlugin.add_custom_text  s     	D r.   c                     [        U[        5      (       a  U/nU R                  R                  R                  nU(       d  U R                  S5        gU H  nU R                  " U SU 340 UD6  M     g)a*  Collect service status information based on the ``InitSystem`` used

:param services: Service name(s) to collect statuses for
:type services: ``str`` or a ``list`` of strings

:param kwargs:   Optional arguments to pass to add_cmd_output
                 (timeout, predicate, suggest_filename,..)

zFCannot add service output, policy does not define an InitSystem to useNr   )r   r   r   r  	query_cmdrG  r"  )rM   rI   r   queryservices        r!   add_service_statusPlugin.add_service_status  sl     h$$ zH''11OO 4 5G5'7) 4??  r.   c                    SnSnSnSnSnSnSnSnS	nUS
:X  d  U R                  S5      (       a  S
nOU=(       d    U R                  S5      n[        U[        5      (       a  U/n[        U[        5      (       a  U/nO	U(       d  / nU(       a%  U H  nUUU-  -  nUR                  SU 35        M!     U	(       a  UUU	-  -  nU
(       a  UU-  nU(       a  US-  nU(       a  US:X  a  SnUS:X  a  SnUUU-  -  nU=(       d    U R                  S5      nU(       a  UUU-  -  nU(       a  UUU-  -  nU(       a  UUU-  -  nU(       a  UUU-  -  nUnSnUS
:  a  U S3nSnU R	                  SU 35        U R                  XUSUUXUS9	  g)ai  Collect journald logs from one of more units.

:param units:   Which journald units to collect
:type units: ``str`` or a ``list`` of strings

:param boot:    A boot index using the journalctl syntax. The special
                values 'this' and 'last' are also accepted.
:type boot: ``str``

:param since:   Start time for journal messages
:type since: ``str``

:param until:   End time forjournal messages
:type until: ``str``

:param lines: The maximum number of lines to be collected
:type lines: ``int``

:param allfields: Include all journal fields regardless of size or
                  non-printable characters
:type allfields: ``bool``

:param output:  Journalctl output control string, for example "verbose"
:type output: ``str``

:param timeout: An optional timeout in seconds
:type timeout: ``int``

:param identifier: An optional message identifier
:type identifier: ``str``

:param catalog: Augment lines with descriptions from the system catalog
:type catalog: ``bool``

:param sizelimit: Limit to the size of output returned in MB.
                  Defaults to the value of --log-size.
:type sizelimit: ``int``
zjournalctl --no-pager z
 --unit %sz
 --boot %sz --since '%s'z --until %sz --lines %sz --output %sz --identifier %sz
 --catalogr   r  r  journal_z --allthisr$   lastz-1r  Fz
 --reverseTzcollecting journal: )	rB   r)  r^  r  r   r  r  r  r  N)r|   r   r   rr   rG  r
  )rM   unitsbootr  untillines	allfieldsrD   r)  
identifiercatalogr  r  r  r  journal_cmdunit_optboot_opt	since_opt	until_opt	lines_opt
output_optidentifier_optcatalog_optr  unitr   r^  s                               r!   add_journalPlugin.add_journal  s   T /#	!	!	#
+">T__Z88H CDOON$CHeS!!GEdC  6DDx$.htf-.  >J66K;&K8#Kv~v~8d?*K119u,,K9u,,K9u,,K:..Ka<(M4KC.{m<=!$dU'/d&. 	 	0r.   c           	        ^ ^ UU 4S jm[         R                  " U[         R                  5      (       a>  T R                  U5      (       a(  T R	                  U5      (       a  T R                  US5      n[        R                  " USS9n/ nU Hz  n T R                  U5      (       a`  T R	                  U5      (       aH  UR                  U5        UR                  T" [         R                  R                  US5      5      5        Mx  Mz  M|     UR                  U5        [        [        U5      5      $ ! [         a    UR                  U5         M  f = f)Nc           	        > / n[         R                   " U 5      n U  H  n TR                  U5      (       d  TR                  U5      (       a  UR                  U5        MC  TR	                  U5      (       a?  TR                  U5      (       a)  UR                  T" TR                  US5      5      5        M  UR                  U5        M     [        [        U5      5      $ ! [         a     M  f = f)Nr  )globr   r   rr   r   r   r  r   PermissionErrorr   r   )r  found_pathsr  _Plugin__expandrM   s      r!   __expand*Plugin._expand_copy_spec.<locals>.__expand!  s    KIIe$E''--1A1A$1G1G#**40..4<<3E3E#**8DNN44M+NO#**40 " K()) '  s   =CAC4C
C+*C+r  T)r#  )r  r  r  r   r   r   r  remover  r  rH   r  r   r   )rM   r  expandedrecursed_files_pathr  s   `    @r!   r  Plugin._expand_copy_spec   s   	*, IIh((T__X-F-FX&&~~h4H99X6E
'??5))dll5.A.A OOE*"))(277<<s3K*LM	 /B)  	'CM"" # ' &	's   A2D..EEc                     [        U R                  SS9 H)  nU R                  SU S35        U R                  U5        M+     U R	                  5         g )NT)r  zcollecting path 'r   )r   r  r  rX  r  r  s     r!   _collect_copy_specsPlugin._collect_copy_specsL  sI    4??D9DNN.tfA67t$ : 	##%r.   c           
         U R                   (       d  gU R                  5       nU(       d  U R                  S5        gUR                  5       (       d  U R                  S5        gU R                    H  nUu  p4pVnU R                  SU SU S35        SU SUR	                  S5       3nU R
                  R                  U[        5        U R
                  R                  U5      n	UR                  X4X(       a  UOSS	9n
U R                  U
S
S9nUS   S:X  a:  U(       a  U R
                  R                  US   U5        U R                  X4X5        M  U R                  SU SU SUS    35        M     g)a  Copy any requested files from containers here. This is done
separately from normal file collection as this requires the use of
a container runtime.

This method will iterate over self.container_copy_paths which is a set
of 5-tuples as (container, path, sizelimit, stdout, tags).
NzDCannot collect container based files - no runtime is present/active.zYLoaded runtime '%s' does not support copying files from containers. Skipping collections.r[  r  r   r  r&   )r  r  )r)  r   r   rD   zerror copying 'r  )r  r  r  check_can_copyr   r  ri  r   r  get_copy_commandr  r"  r  )rM   rtr  r  r  r  r  r  arcdestrZ  cpcmdcprets               r!   _collect_container_copy_specs$Plugin._collect_container_copy_specsR  so    ((((*NN 0 1  ""NN J K//F17.Cy$NN\$/A#aHI'uAdkk#.>-?@GLL##GV4<<))'2D''49D ( E MM%M4EX!# LL++E(OWE44SN 7##&%s5?*; = >) 0r.   c                 R   U R                   R                  S S9  U R                    H}  nU R                  S[        U5       35        Sn[	        USS 5      b  SUR
                   S3nU R                  SUR                   S	U 35        U R                  " S
0 UR                  D6  M     g )Nc                     U R                   $ r   )r  )xs    r!   <lambda>&Plugin._collect_cmds.<locals>.<lambda>}  s    QZZr.   )r   zunpacked command: r$   r  r  r  zcollecting output of 'r   r   )
r  r  rG  r   r  r  r  rB   ry  r   )rM   r  r  s      r!   _collect_cmdsPlugin._collect_cmds|  s    #78''FOO0V>?Dvw-9"6<<.6NN3FJJ<qGH$$7v7 (r.   c                 l   U R                    GH#  u  pU R                  SU S35        UnUS   [        R                  :X  a  UR	                  [        R                  5      nUR                  [        R                  R                  S5      S-   nU R                  [        X5      U5        [        R                  R                  S[        R                  R                  U5      5      n[        R                  R                  USU R                  5       U5      nU R                  R                  Xa5        GM&     g )Nzcollecting tail of 'z' due to size limitr   r'   rh  r&   rR  )r  r  r  r  r   r  r  rW  r
   rT  rO  rH   r   r  rV  )rM   r  r  	file_namestrfilerel_path	link_paths          r!   _collect_tailed_filesPlugin._collect_tailed_files  s     11LENN1%8KLMI|rvv%%,,RVV4	!!"''++s3i?  ##D$6@wwsBGGOOE,BCHX}%)YY[';ILL!!)3 2r.   c                    U R                    H  u  pnU R                  (       a    g U R                  SU S35         U R                  R	                  X5        UR                  S5      S   R                  SS5      nUUS.U R                  R                  U'   M     g ! [         a"  nU R                  SU S	U 35         S nAM  S nAff = f)
Nzcollecting string as 'r   r&   r*  r'   r%   )r  r  zcould not add string 'r  )r  rf  r  r  r"  r  r  r  r<  r   rG  )rM   stringr  r  _namer)  s         r!   _collect_stringsPlugin._collect_strings  s    '+'8'8#Ft  NN3I;a@AL'':!,R088cB% 0%%e, (9  L"83qc JKKLs   AB
C&CCc                 |     U R                  5         g! [         a  nU R                  SU 35         SnAgSnAff = f)a  Kick off manual collections performed by the plugin. These manual
collections are anything the plugin collects outside of existing
files and/or command output. Anything the plugin manually compiles or
constructs for data that is included in the final archive.

Plugins will need to define these collections by overriding the
``collect()`` method, similar to how plugins define their own
``setup()`` methods.
z!Error during plugin collections: N)collectr   r  )rM   r  s     r!   _collect_manualPlugin._collect_manual  s:    	GLLN 	GOO?uEFF	Gs    
;6;c                     g)a  If a plugin needs to manually compile some data for a collection,
that should be specified here by overriding this method.

These collections are run last during a plugin's execution, and as such
are more likely to be interrupted by timeouts than file or command
output collections.
Nr   r`   s    r!   r  Plugin.collect      r.   c              #   X  #     [        5       nU R                  XS9nU R                  R                  U[        5        U R                  R                  U5      n[        USSS9 nU R                  SU 35        Uv   SSS5        [        5       nX-
  n	U R                  SU SU	 35        [        U[        5      (       a  U/nU R                  R                  R                  UUUS	.5        g! , (       d  f       Nu= f! [         a!  n
U R                  S
U SU
 35         Sn
A
gSn
A
ff = f7f)a^  Handles creating and managing files within a plugin's subdirectory
within the archive, and is intended to be used to save manually
compiled data generated during a plugin's ``_collect_manual()`` step
of the collection phase.

Plugins should call this method using a ``with`` context manager.

:param fname:       The name of the file within the plugin directory
:type fname:        ``str``

:param subdir:      If needed, specify a subdir to write the file to
:type subdir:       ``str``

:param tags:        Tags to be added to this file in the manifest
:type tags:         ``str`` or ``list`` of ``str``
)r  wr  encodingzmanual collection file opened: Nzmanual collection 'z' finished in )r   rc  r  zError with collection file 'r  )r   rK  r  ri  r   r  openrG  r  r   r   r  r>  rr   r   )rM   r   r  r  rH  _pfnamer
  r  rr  runr  s              r!   collection_filePlugin.collection_file  s    $	KFE11%1GGLL##GV4LL**73EeS73u"A% IJ 4 &C+CNN0~cUKL$$$vMM%%,,#.  43  	KNN9%C5IJJ	KsH   D*AC< #C+<A.C< *D*+
C95C< <
D'D"D*"D''D*c                 8   [        5       nU R                  5         U R                  5         U R                  5         U R	                  5         U R                  5         U R                  5         U R                  SU R                  5        S[        5       U-
   35        g)zCollect the data for a plugin.zcollected plugin 'rg  N)	r   r  r  r  r  r  r  rG  r   )rM   rH  s     r!   collect_pluginPlugin.collect_plugin  s}      "**,""$,TYY[M6E>*, 	-r.   c                 <     U R                   $ ! [         a     gf = f)z8This function will return the description for the pluginr  )r  r   r`   s    r!   get_descriptionPlugin.get_description  s#    	0??" 	0/	0s    
c           	      8   [        U R                  U R                  U R                  U R                  U R
                  U R                  U R                  /5      (       Ga<  [        U R                  [        5      (       a  U R                  /U l        [        U R                  [        5      (       a  U R                  /U l        [        U R                  [        5      (       a  U R                  /U l        [        U R                  [        5      (       a  U R                  /U l        [        U R
                  [        5      (       a  U R
                  /U l        U R                  U R                  U R                  U R                  U R
                  U R                  5      $ g)aI  This method will be used to verify that a plugin should execute
given the condition of the underlying environment.

The default implementation will return True if none of class.files,
class.packages, nor class.commands is specified. If any of these is
specified the plugin will check for the existence of any of the
corresponding paths, packages or commands and return True if any
are present.

For plugins with more complex enablement checks this method may be
overridden.

:returns:   ``True`` if the plugin should be run for this system, else
            ``False``
:rtype: ``bool``
T)rh   r;  rJ   r:  rz  rI   r=  architecturesr   r   _check_plugin_triggersr`   s    r!   check_enabledPlugin.check_enabled  s    $ 

DMM4==$:J:Jt0B0BD E E$**c**"jj\
$----!%$----!%$**C00$($4$4#5 $----!%..tzz/3}}/3}}/3}}/3	@ @ r.   c                   ^  [        XX4U/5      (       d  T R                  5       $ [        U 4S jU 5       5      =(       d    [        U 4S jU 5       5      =(       ds    [        U 4S jU 5       5      =(       dW    [        U 4S jT R                   5       5      =(       d1    [        U 4S jU 5       5      =(       d    [        U 4S jU 5       5      =(       a    T R                  5       $ )Nc              3   F   >#    U  H  nTR                  U5      v   M     g 7fr   )r   )r   r   rM   s     r!   r   0Plugin._check_plugin_triggers.<locals>.<genexpr>(  s     @%T%%e,,%r  c              3   F   >#    U  H  nTR                  U5      v   M     g 7fr   )r   r  s     r!   r   r*  )  s     ?hsD%%c**hr  c              3   P   >#    U  H  n[        UTR                  5      v   M     g 7fr   )r   r  )r   rB   rM   s     r!   r   r*  *  s     IM#t||44s   #&c              3   F   >#    U  H  nTR                  U5      v   M     g 7fr   )r}   )r   modrM   s     r!   r   r*  +  s!     K:J3D))#..:Jr  c              3   F   >#    U  H  nTR                  U5      v   M     g 7fr   )r  )r   r   rM   s     r!   r   r*  ,  s     =HSDOOC((Hr  c              3   F   >#    U  H  nTR                  U5      v   M     g 7fr   )r  )r   cntrrM   s     r!   r   r*  -  s     GJDD))$//Jr  )rh   check_is_architecturerz  )rM   r;  rJ   r:  rI   r=  s   `     r!   r%  Plugin._check_plugin_triggers!  s     EXDEE--//@%@@ H?h??HIIIH K$:J:JKKH =H==	H
 GJGG- **,	.r.   c                     U R                   c  gSSR                  U R                   5       S3n[        R                  " XR                  R                  5       5      $ )a  Checks whether or not the system is running on an architecture that
the plugin allows. If not architecture is set, assume plugin can run
on all arches.

:returns:   ``True`` if the host's architecture allows the plugin to
            run, else ``False``
:rtype: ``bool``
Tr   r   rd   )r$  rH   r   r   r   r   r  s     r!   r2  Plugin.check_is_architecture0  sM     %chht112315xx{{33566r.   c                     g)zoThis decides whether a plugin should be automatically loaded or
only if manually specified in the command line.Tr   r`   s    r!   default_enabledPlugin.default_enabled>  s     r.   c                    U R                    H=  nU R                  U5      (       d  M  U R                  U5        U R                  U5        M?     U R                   H/  nU R                  U5      (       d  M  U R                  SU 35        M1     g)zBased on the class attrs defined for plugin enablement, add a
standardized set of collections before we call the plugin's own setup()
method.
zmodinfo N)rI   r  r  r  rz  r}   r"  )rM   r  r   s      r!   add_default_collectionsPlugin.add_default_collectionsC  su     }}Gw''''0  ) % $$D$$T**##htf$56 %r.   c                 L    U R                  [        U R                  5      5        g)zCollect the list of files declared by the plugin. This method
may be overridden to add further copy_specs, forbidden_paths, and
external programs if required.
N)r  r   r;  r`   s    r!   setupPlugin.setupR  s    
 	4

+,r.   c                 T   [        U S5      (       dH  [        U S5      (       a6  U R                  (       a%  U R                   Vs/ s H  oS-   PM	     snU l        Og U R                  R                  nUR                  U R                  5      nU(       a  U R                  U5        g g s  snf )Nr  rJ   $)r  rJ   r  r   r  build_verify_commandr"  )rM   rV   pm
verify_cmds       r!   setup_verifyPlugin.setup_verifyY  s    t.//tZ((T]]9='GAC'G$[[((,,T-A-AB

+  (Hs   B%c                 (    U R                  SU 3US9$ )ax  Check if a path exists inside a container before
collecting a dir listing

:param path:    The canonical path for a specific file/directory
                in a container
:type path:     ``str``

:param container: The container where to check for the path
:type container: ``str``

:returns:       True if the path exists in the container, else False
:rtype:         ``bool``
ztest -e r  )r  )rM   r  r  s      r!   r!  Plugin.container_path_existsf  s     }}xv.)}DDr.   c                 ,    [        XR                  5      $ )a,  Helper to call the sos.utilities wrapper that allows the
corresponding `os` call to account for sysroot

:param path:        The canonical path for a specific file/directory
:type path:         ``str``


:returns:           True if the path exists in sysroot, else False
:rtype:             ``bool``
)r   r  r  s     r!   r   Plugin.path_existsv       4..r.   c                 ,    [        XR                  5      $ )a#  Helper to call the sos.utilities wrapper that allows the
corresponding `os` call to account for sysroot

:param path:        The canonical path for a specific file/directory
:type path:         ``str``


:returns:           True if the path is a dir, else False
:rtype:             ``bool``
)r   r  r  s     r!   r   Plugin.path_isdir  s     $--r.   c                 ,    [        XR                  5      $ )a$  Helper to call the sos.utilities wrapper that allows the
corresponding `os` call to account for sysroot

:param path:        The canonical path for a specific file/directory
:type path:         ``str``


:returns:           True if the path is a file, else False
:rtype:             ``bool``
)r   r  r  s     r!   r   Plugin.path_isfile  rJ  r.   c                 ,    [        XR                  5      $ )a$  Helper to call the sos.utilities wrapper that allows the
corresponding `os` call to account for sysroot

:param path:        The canonical path for a specific file/directory
:type path:         ``str``


:returns:           True if the path is a link, else False
:rtype:             ``bool``
)r   r  r  s     r!   r   Plugin.path_islink  rJ  r.   c                 ,    [        XR                  5      $ )a$  Helper to call the sos.utilities wrapper that allows the
corresponding `os` call to account for sysroot

:param path:        The canonical path for a specific file/directory
:type path:         ``str``


:returns:           Contents of path, if it is a directory
:rtype:             ``list``
)r   r  r  s     r!   r   Plugin.listdir  s     t\\**r.   c                 4    [        U/UQ7SU R                  06$ )a~  Helper to call the sos.utilities wrapper that allows the
corresponding `os` call to account for sysroot

:param path:    The leading path passed to os.path.join()
:type path:     ``str``

:param p:       Following path section(s) to be joined with ``path``,
                an empty parameter will result in a path that ends with
                a separator
:type p:        ``str``
r  )r   r  )rM   r  rV   s      r!   r   Plugin.path_join  s     884<<88r.   c                     g)zLPerform any postprocessing. To be replaced by a plugin if required.
        Nr   r`   s    r!   r,  Plugin.postproc  r  r.   c                 "   SnSn [         R                   " U5      nU HK  n[        U R                  U5      SSS9 nUR                  5       R	                  5       nX;   a  SnSSS5        MM     U$ ! , (       d  f       M`  = f! [
         a     gf = f)zChecks if a named process is found in /proc/[0-9]*/cmdline.

:param process:     The name of the process
:type process:      ``str``

:returns: ``True`` if the process exists, else ``False``
:rtype: ``bool``
F/proc/[0-9]*/cmdlinerr  r  TN)r  r  r   r   r)   IOError)rM   processr   cmd_line_globcmd_line_pathsr  pfilecmd_lines           r!   check_process_by_namePlugin.check_process_by_name  s     .		!YY}5N&$...#*,/4$zz|113H*!%	, , ' , ,
  		s(   5B &A/!B /
A>	9B 
BBc                 v   / nSn[         R                   " U5      nU Hu  n [        USSS9 nUR                  5       R                  S5      n[        R
                  " X5      (       a#  UR                  UR                  S5      S   5        SSS5        Mw     U$ ! , (       d  f       M  = f! [         a     M  f = f)	zGet a list of all PIDs that match a specified name

:param process:     The name or regex of the process the get PIDs for
:type process:  ``str``

:returns: A list of PIDs
:rtype: ``list``
rX  rY  r  r   r&      N)	r  r  r   r)   r   r   rr   r  rZ  )rM   r[  pidsr\  r]  r  r    r_  s           r!   get_process_pidsPlugin.get_process_pids  s     .=1"D$g6! vvx~~f5Hxx22DJJsOA$67 76 #  76  s/   B*AB
B*
B'	"B*'B**
B87B8c           
      ^   / nU R                  U5      nU HC  n [        R                  " [        U5      [        R
                  5        UR                  U5        ME     [        [        [        U5      S5      5        U$ ! [         a%  nU R                  SU SU SU 35         SnAM  SnAff = f)a  
Send a SIGUSR1 to the pid(s) associated with the specified process
name. Callers should be aware that a 1-second delay per signalled pid,
up to 5 seconds at most, is expected as to allow sufficient time for
the signalled process(es) to react to the received signal.

:param process: The name or regex pattern of the process(es) to signal
:type process:  ``str``

:returns:   A list of pids that were successfully signalled
:rtype:     ``list``
zFailed to signal pid z for 'r  N   )rf  r  killr   signalSIGUSR1rr   r   rG  r   minr  )rM   r[  	signalledre  pidr  s         r!   signal_process_usr1Plugin.signal_process_usr1  s     	$$W-CC&..1  %  	c#i.!$%  +C5wis3%H s   ?A==
B,B''B,c                     Uc7  U R                   S   R                  (       a  U R                   S   R                  nU R                  U R                   S   S   X5      $ )Nr   
namespacesnetwork)r   rs  filter_namespaces)rM   
ns_patternns_maxs      r!   get_network_namespacesPlugin.get_network_namespaces  sR    >dll=9DD\\-0;;F%%dll<&@&K&0: 	:r.   c                 p   / nSnU(       a3  SSR                  UR                  5       5      R                  SS5       S3nU Hq  nU(       a&  [        [        R
                  " XV5      5      (       d  M0  UR                  U5        U(       d  MJ  [        U5      U:X  d  M[  U R                  SU S35          U$    U$ )	zFilter a list of namespaces by regex pattern or max number of
namespaces (options originally present in the networking plugin.)
Nr   z$|r  z.*z$)z&Limiting namespace iteration to first z namespaces found)	rH   r  r  r   r   r   rr   r  r  )rM   ns_listrv  rw  out_nsr  nss          r!   ru  Plugin.filter_namespaces  s      dii
 0 0 23;;CFGrJ B$rxx'<"="=MM"
 vv;&(NN $//5h6G$I J  r.   )r  r  rf  r  r  r  r:  r   r  r  r  r  r  r  r  r  r;  r  r#  rz  r  r  rJ   r   r  rI   r  r  r  r  r  r   )FN)F)r$   )NF)r   )NT)NTTNNFNFFFN)NNNNNFNNNNNNNr  )NN)r   r   r   r   r   rn  rJ   r;  r:  rz  rI   r=  r$  r  r  r  r   r_  rb  rf  r0  r  r"  r#  r  r  r  r   r!  rB  rJ  rM  rS  r\  propertyr)  r@  rh  rk  classmethodr   rv  rt  rs  r  r  r  r  rG  r  r  r  r   r  r  r  r  r   r  r  r$  r   r  r  r  r  r  r3  r/  r>  r<  rD  r^  rd  r6  ro  ru  rQ  r  rX  r  r  r|   r  r  r  r  r  r  r   r
  r$  r"  r1  r4  r<  r@  r-   rK  rO  rW  ry  r|  r  r  rm  r  r  r  r  r  r  r  r  r,  r}   r  r  r  r  r  r  r  r  r  r  r  r  
contextlibcontextmanagerr  r  r!  r&  r%  r2  r7  r:  r=  rD  r!  r   r   r   r   r   r   r,  r`  rf  rp  rx  ru  r   r   r.   r!   r  r    s   ,\ KHEHKHJMGHG$N!KLGHKG IM-J(/T
 247 2 *X    5
!& $ $ - - c cJ 6
 6
p>
13017
7

@	8	8	9
8	J	@","8@06p86#JJ=*+A)F$



H:x0**@+&" :$ 26d!2yv 59D"$D$(B"2 "4OOb 6:T#4T%%)R4.KB +05 DtDtt)-)V 59$($t"$D!%D$R "u$D5qAf% .%.+8C$ :> "#9J 9=).#'Dd#(D$)e"%'E5 %U$tl 8<(-t"&t4T"'4d#(U4 "$J
X ?C:>=BO3b0IB $0&&76,	6(!@. DH8<;?CEn0`*#X&(>T84LG ,0r $K $KL
-0)V.7
7-,E /.//+9.,8:r.   r  c                       \ rS rSrSrSrg)PluginDistroTagi5  zThe base tagging class for distro-specific classes used to signify that
a Plugin is written for that distro.

Use IndependentPlugin for plugins that are distribution agnostic
r   Nr   r   r   r   r   r   r   r.   r!   r  r  5  s    r.   r  c                       \ rS rSrSrSrg)RedHatPlugini=  z/Tagging class for Red Hat's Linux distributionsr   Nr  r   r.   r!   r  r  =      9r.   r  c                       \ rS rSrSrSrg)UbuntuPluginiA  zTagging class for Ubuntu Linuxr   Nr  r   r.   r!   r  r  A      (r.   r  c                       \ rS rSrSrSrg)DebianPluginiE  zTagging class for Debian Linuxr   Nr  r   r.   r!   r  r  E  r  r.   r  c                       \ rS rSrSrSrg)
SuSEPluginiI  z*Tagging class for SuSE Linux distributionsr   Nr  r   r.   r!   r  r  I  s    4r.   r  c                       \ rS rSrSrSrg)OpenEulerPluginiM  z/Tagging class for openEuler linux distributionsr   Nr  r   r.   r!   r  r  M  r  r.   r  c                       \ rS rSrSrSrg)	CosPluginiQ  z(Tagging class for Container-Optimized OSr   Nr  r   r.   r!   r  r  Q  s    2r.   r  c                       \ rS rSrSrSrg)IndependentPluginiU  z6Tagging class for plugins that can run on any platformr   Nr  r   r.   r!   r  r  U  s    @r.   r  c                       \ rS rSrSrSrg)ExperimentalPluginiY  z=Tagging class that indicates that this plugin is experimentalr   Nr  r   r.   r!   r  r  Y  s    Gr.   r  c                       \ rS rSrSrSrg)AzurePlugini]  zTagging class for Azure Linuxr   Nr  r   r.   r!   r  r  ]  s    'r.   r  c                 >    SU  3nU(       d  [         4n[        X!5      $ )zImport name as a module and return a list of all classes defined in that
module. superclasses should be a tuple of valid superclasses to import,
this defaults to (Plugin,).
zsos.report.plugins.)r  r   )r   superclassesplugin_fqnames      r!   import_pluginr  a  s%    
 *$0My55r.   r   )8r   r  r  r  r   rk  r2   r   r   r  r  r8  r  r   sos.utilitiesr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   sos.archiver   r   r"   r-   r;   r.  DOTALLr  r  r=   r   r   r  r  r  r  r  r  r  r  r  r  r  r  r   r.   r!   <module>r     s)   B  	  	        9 9 9 9 9 '  ZZ;RYYG
l
 l
^	8 8,N NbQ1 Q1hb :? :)? ))? )5 5:o :3 3A AH H(/ (6r.   