
    ~ g͗                         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  S SKJr  S SK	J
r
  S SKJr  S SKJr  S SKJr  S SKJr  S S	KJr  S S
KJrJrJrJr  S SKJr  \\\\\S.r " S S5      rg)    N)quote)load)
InitSystem)JujuSSH)SSHControlPersist)LocalTransport)OCTransport)SaltStackMaster)CommandTimeoutExceptionConnectionExceptionUnsupportedHostExceptionInvalidTransportException)sos_parse_version)localcontrol_persistoc	saltstackjujuc                   p   \ rS rSr  S5S jr\S 5       rS rS rS r	\S 5       r
S	 rS
 rS rS rS6S jr\S 5       rS rS rS rS rS rS rS rS rS rS6S jrS rS rS rS r  S7S 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, r.S- r/S. r0S/ r1S0 r2S1 r3S2 r4S3 r5S4r6g)8SosNode*   Nc                    UR                  5       U l        X l        US   U l        U R	                  5         US   U l        US   U l        US   U l        US   U l        U R                  R                  U l	        U R                  R                  U l
        SU l        S U l        S U l        S U l        0 U l        0 U l        U=(       d    U R                  R"                  U l        U R                  R&                  (       d6  U R                  R(                  (       d  U R$                  U R                  l        U(       a  X@R                  l        S U l        SU l        SU l        / U l        S / / / / US   S.U l        S	U l        [6        R8                  " S
5      U l        [6        R8                  " S5      U l        U R?                  U5      U l         U R@                  RB                  (       a  U R@                  RB                  S:g  U l         U R@                  RE                  U R$                  5        U RK                  5       U l        U R@                  R                  U l        U R                  (       a  U R                  RL                  (       a  SnU RN                  (       a  U(       a  U R                  (       d  U R@                  RQ                  5         g U R                  (       a&  U RS                  5       (       a  SU R                  l*        U R                  RT                  (       a  U RW                  5         U RY                  5         g ! [F         a  nU RI                  SU 35        e S nAff = f)Ncmdlineoptstmpdirhostlen	need_sudosos_optionsFsos_cmd)versionenableddisabledoptionspresetsr   	sosreportsossos_uirootzUnable to open remote session: )-stripaddresscommonsopts_assign_config_optsr   r   r   r   node_config_fileinherit_config_filer   hostclusterhostnamesos_env_vars	_env_varspassword	_passwordnopasswd_sudosudo_pwsos_path	retrievedhash_retrieved	file_listsos_infosos_binlogging	getLoggersoslogui_log_load_remote_transport
_transportdefault_userconnect	Exception	log_errordetermine_host_policyno_local	connected
disconnectcheck_in_containercontainerizedcreate_sos_container_load_sos_info)selfr)   r*   r4   
local_sudo
load_factserrs          7/usr/lib/python3/dist-packages/sos/collector/sosnode.py__init__SosNode.__init__,   s   }}M*	  "h'y) -"=1 $		 : :#'99#@#@ 
	!7TYY%7%7yy&&tyy/@/@ $DII *II#y)
 #''.''155g> ??''!__99VCDN	OO##DNN3 ..0	00::$)),,J>>j99**,zz**,,.3DII+yy&&))+!+  	NN<SEBC	s   %L> >
M"MM"c                 R    U R                   (       a  U R                   R                  $ g)NT)rC   rJ   rP   s    rT   rJ   SosNode.connectedq   s    ????,,,    c                 8    U R                   R                  5         g)zDWrapper to close the remote session via our transport agent
        N)rC   rK   rX   s    rT   rK   SosNode.disconnectx   s     	""$rZ   c                    U R                   S;   a  SU l        [        U R                   U5      $ U R                  R                  [
        ;   a.  [
        U R                  R                     " U R                   U5      $ U R                  R                  S:w  aG  U R                  SU R                  R                   35        [        U R                  R                  5      e[        U R                   U5      $ )zuDetermine the type of remote transport to load for this node, then
return an instantiated instance of that transport
)	localhostz	127.0.0.1Tautoz4Connection failed: unknown or unsupported transport )	r)   r   r   r+   	transport
TRANSPORTSrG   r   r   )rP   r*   s     rT   rB   SosNode._load_remote_transport}   s     <<55DJ!$,,8899*,dii1124<<II99&(NNF99&&') ,DII,?,?@@ w77rZ   c                 F    U R                   SU R                  S-    3 SU 3$ )N<   z : )	_hostnamer   rP   msgs     rT   _fmt_msgSosNode._fmt_msg   s+    ..4<<!#3"4 45S>>rZ   c                    U R                   (       d  U R                  (       a/  [        R                  R	                  5       U l         U R                   $ U R                  S5      nUS   S:X  aJ  US   R                  S5       H2  nU(       d  M  UR                  S5      nUS   U R                   US   '   M4     U R                   $ )Nz
env --nullstatusr   output =re   )r3   r   osenvironcopyrun_commandsplit)rP   retln_vals       rT   env_varsSosNode.env_vars   s    ~~zz!#!2 ~~ &&|4x=A%!(m11&9!$!xx}26q'tAw/	 :
 ~~rZ   c                    Xl         U R                   R                  SU R                  5        U R                   R                  SU R                  R                  5        U R                   R                  SU R
                  S   5        U R                   R                  SS5        U R                   R                  SU R                  R                  5        g)	z>Set the manifest section that this node will write to
        r1   policysos_versionr   final_sos_command r`   N)manifest	add_fieldrf   r/   os_release_namer<   rC   name)rP   r   s     rT   set_node_manifestSosNode.set_node_manifest   s     !
DNN;$))*C*CDt}}Y/GH 3R8T__-A-ABrZ   c                     [         R                  R                  S5      (       a  U R                  S5        g[         R                  R                  S5      b  U R                  S5        gg)zF
Tries to identify if we are currently running in a container or not.
z/run/.containerenvz/Found /run/.containerenv. Running in container.T	containerz/Found env var 'container'. Running in containerF)rp   pathexists	log_debugrq   getrX   s    rT   rL   SosNode.check_in_container   sN     77>>.//NNLM::>>+&2NNLMrZ   c                    U R                   R                  (       GaH  U R                   R                  U R                  R                  U R                  5       U R                  R                  S9nU R                  USS9nUS   S;   a  US   S:X  a@  SUS   ;   a  U R                  S	5        [        eS
US   ;   a  U R                  S5        [        eU R                  U R                   R                  5       SS9nUS   S:X  a*  U R                  SU R                   R                   S35        gU R                  SUS    35        [        eU R                  SUS    35        [        eg)zJIf the host is containerized, create the container we'll be using
        )imageauth
force_pullT	need_rootrl   )r   }   r   zunable to retrieve auth tokenrm   zHCould not pull image. Provide either a username and password or authfilezunknown: Not foundz%Specified image not found on registryr   zTemporary container z createdz(Could not start container after create: z$Could not create container on host: F)r/   rM   rN   r+   r   get_container_authforce_pull_imagers   rG   rF   restart_sos_containerlog_infosos_container_name)rP   cmdresru   s       rT   rN   SosNode.create_sos_container   si    99"""))00iioo,,.9955 1 C
 ""3$"7C8}(x=C'6#h-G7 (+s8}<'NO'
 &&tyy'F'F'H15 ' 7x=A%MM"8%)YY%A%A$B(#L MI"%h- 2 3NNA!(m_. /OrZ   c                    U R                   R                  (       aQ  U R                  R                  S   R	                  U R                   R                  U R                   R
                  5      $ U R                  R                  S   R                  U R                   R                  =(       d    U R                  R                  5      $ )zbDetermine what the auth string should be to pull the image used to
deploy our temporary container
default)	r+   registry_userr/   runtimesfmt_registry_credentialsregistry_passwordfmt_registry_authfileregistry_authfilecontainer_authfilerX   s    rT   r   SosNode.get_container_auth   s     99""99%%i0II		''		++  yy!!),BBII''G499+G+G
 	
rZ   c                 Z     U R                  SU 3US9nUS   S:H  $ ! [         a     gf = f)z3Checks for the presence of fname on the remote nodezstat r   rl   r   F)rs   rF   )rP   fnamer   r   s       rT   file_existsSosNode.file_exists   sC    	""U5'?i"HCx=A%% 		s    
**c                 t    U R                   (       a  SU R                   ;  a  U R                   $ U R                  $ )Nr^   )r1   r)   rX   s    rT   rf   SosNode._hostname   s(    ==[=== ||rZ   c                 6    Sn[         R                  " USU5      $ )zMAttempts to obfuscate sensitive information in log messages such as
passwordsz>(?P<var>(pass|key|secret|PASS|KEY|SECRET).*?=)(?P<value>.*?\s)z\g<var>****** )resub)rP   rh   regs      rT   _sanitize_log_msgSosNode._sanitize_log_msg   s     Pvvc,c22rZ   c                 X    U R                   R                  U R                  U5      5        g)z:Format a ui message that includes host name and formattingN)rA   infori   rg   s     rT   ui_msgSosNode.ui_msg   s    s+,rZ   c                     [         R                  " 5       S   S   nSU R                   SU SU 3nU R                  R	                  U5        g)z#Used to print and log info messagesre      [:] N)inspectstackrf   r@   r   rP   rh   callerlmsgs       rT   r   SosNode.log_info  sF    #A&4>>"!F82cU3rZ   c                     [         R                  " 5       S   S   nSU R                   SU SU 3nU R                  R	                  U5        g)z$Used to print and log error messagesre   r   r   r   r   N)r   r   rf   r@   errorr   s       rT   rG   SosNode.log_error	  sF    #A&4>>"!F82cU3$rZ   c                     U R                  U5      n[        R                  " 5       S   S   nSU R                   SU SU 3nU R                  R                  U5        g)z$Used to print and log debug messagesre   r   r   r   r   N)r   r   r   rf   r@   debug)rP   rh   r   s      rT   r   SosNode.log_debug  sV    $$S)#A&$..!6("SE2#rZ   c                 0   U R                   R                  S[        R                  R                  S5      5      S:H  nU R                  (       a	  U(       a  U$ U R
                  R                  (       a  S[        U5       3$ U R                  (       a  SU 3$ U$ )zrIf we need to provide a sudo or root password to a command, then
here we prefix the command with the correct bits
USERr'   zsu -c zsudo -S )	r3   r   rp   rq   r   r+   become_rootr   r   )rP   r   is_roots      rT   _format_cmdSosNode._format_cmd  sq     ..$$VRZZ^^F-CDN::'J99  E#J<((>>cU##
rZ   c                    SnSnU R                   R                  c`  U R                   R                  R                  U R                   R                  5      nUb#  SR                  US   5      nUS   (       a  US   nOSU R                  U R                   R                  SSS9nUS   S:X  a%  US	   R                  5       R                  S
5      u  pQnU(       a>  [        UR                  S5      5      S:X  a  US-  n US
UR                  S5      S    3-  nXR                  S'   U R                  S   (       a"  U R                  SU R                  S    35        O=U R                  U R                  R                   :X  d  U R#                  S5        SU l        gU R'                  S5      (       a  SU l        U R(                   S3nU R                  USSS9nUS   S:X  a  U R+                  US	   5        U R'                  S5      (       a  U R-                  5         g! [         a  nU R                  SU 35         SnAGN&SnAff = f)zLQueries the node for information about the installed version of sos
        N.r   releaseTuse_containerr   rl   r   rm   -   z.0z#Unable to fully parse sos release: zsos version is z!sos is not installed on this nodeFz4.0z
sos reportz -l3.6)r/   container_version_commandpackage_managerpkg_versionsos_pkg_namejoinrs   r(   rt   lenrF   r   r<   r   r)   r+   primaryrG   rJ   check_sos_versionr=   _load_sos_plugins_load_sos_presets)	rP   verrelpkgpkgs_rS   r   sosinfos	            rT   rO   SosNode._load_sos_info#  s    99..6))++77		8N8NOChhs9~.y>i.C ##DII$G$G26$ $ HDH~""8n224::3?399S>"a' tL399S>!,-.. $'i ==#MMODMM),D+EFG<<499#4#44 BC"DN!!%(('DLc"""3dd"K8!""78#45!!%((""$1  L!DSEJKKLs   :H 
H? H::H?c                 X   U R                    S3nU R                  USSS9nUS   S:X  a  US   R                  5        Hi  nUR                  5       R	                  S5      (       d  M)  UR                  S5      S   R                  5       nU R                  S	   R                  U5        Mk     g g )
Nz --list-presetsTr   rl   r   rm   zname:re   r#   )r=   rs   
splitlinesr(   
startswithrt   r<   append)rP   r   r   linepnames        rT   r   SosNode._load_sos_presetsW  s    o.s$$Gx=AH002::<**733 JJw/288:EMM),33E: 3 rZ   c                 J   SnSnSnSnSnUS-   U-   nUS-   U-   nUS-   U-   n	US-   S-   n
U R                  Xq5      U R                  S'   U R                  X5      U R                  S	'   U R                  X5      U R                  S
'   U R                  XS5      U R                  S'   g )Nz,The following plugins are currently enabled:z-The following plugins are currently disabled:z4The following options are available for ALL plugins:z+The following plugin options are available:z	Profiles:z(.*?)z

r    r!   r"   Tprofiles)_regex_sos_helpr<   )rP   r   ENABLEDDISABLEDALL_OPTIONSOPTIONSPROFILES	enableregdisregoptregproregs              rT   r   SosNode._load_sos_plugins`  s    @BL?g%0	G#k17"X-G#f,#'#7#7	#Ki $($8$8$Ij!#'#7#7#Hi $($8$8$$Oj!rZ   c                    / n[         R                  " X[         R                  5       Hz  nUR                  5        Hc  nU(       d0   UR	                  5       =n(       a  UR                  US   5        M8  M:  UR	                  S5      n	UR                  S U	 5       5        Me     M|     U$ ! [         a  nU R                  SU 35         S nAM  S nAff = f)Nr   zError parsing sos help: ,c              3   n   #    U  H+  oR                  5       (       d  M  UR                  5       v   M-     g 7fN)r(   ).0ps     rT   	<genexpr>*SosNode._regex_sos_help.<locals>.<genexpr>}  s      A!Qwwyyqwwyy!s   55)	r   findallSr   rt   r   rF   r   extend)
rP   regexr   is_listr   resultr   lsrS   rs
             rT   r   SosNode._regex_sos_helpq  s    jj6F))+I!%-2-JJr!u- .
 

3AJJA!AA , 7 
 % I)A#'GHHIs   +B((
C2CCc                      U R                  SU 35        U R                  R                  U5      $ ! [         a!  nU R	                  SU SU 35         SnAgSnAff = f)z1Reads the specified file and returns the contentszReading file zException while reading : Nr~   )r   rC   	read_filerF   rG   )rP   to_readrS   s      rT   r  SosNode.read_file  s\    	MMM'34??,,W55 	NN5gYbFG	s   .1 
AAAc           
         U R                   (       a:  U R                  SU R                  S   R                   35        U R                  S   $ [	        0 U R
                  R                  [        5       SU R                  R                  U R                  S5      S9nU(       a!  U R                  SUR                   S35        U$ U R                  S5        [        e)	zKAttempts to identify the host installation against supported
distributions
zusing local policy r{   Tz/etc/os-release)cachesysrootinitprobe_runtimeremote_execremote_checkzloaded policy z	 for hostz4Unable to determine host installation. Ignoring node)r   r   r*   r   r   r+   r  r   rC   rs   r  rG   r   )rP   r/   s     rT   rH   SosNode.determine_host_policy  s     ::MM%dll8&<&L&L%MNP<<))"dii&7&7jl"& $ ; ;!%0A!BD MMN4+?+?*@	JKKMN&&rZ   c                      U R                   S   n[        U5      [        U5      :  $ ! [         a  nU R                  SU 35         SnAgSnAff = f)aX  Checks to see if the sos installation on the node is AT LEAST the
given ver. This means that if the installed version is greater than
ver, this will still return True

:param ver: Version number we are trying to verify is installed
:type ver:  ``str``

:returns:   True if installed version is at least ``ver``, else False
:rtype:     ``bool``
r   zError checking sos version: NF)r<   r   rF   rG   )rP   r   	_node_verrS   s       rT   r   SosNode.check_sos_version  sR    	i0I$Y/3DS3III 	NN9#?@	s   %( 
AAAc                 t    U R                   (       d  gU R                   R                  R                  U5      SL$ )z2Checks if a given package is installed on the nodeFN)r/   r   pkg_by_name)rP   r   s     rT   is_installedSosNode.is_installed  s,    yyyy((44S9EErZ   c                 l   U R                   (       dg  U R                  (       dV  U R                  S5         U R                  R	                  U R
                  5      nU(       d  U R                  S5        [        e U(       a6  U R                  R                  (       a  U R                  R                  U5      nU(       a  U R                  U5      nU(       a  U R                  n	U	R                  U5      nU R                  R                  XXFU5      $ ! [         a  nU R                  SU 35        e SnAff = f)a9  Runs a given cmd, either via the SSH session or locally

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

:param timeout: Time in seconds to wait for `cmd` to complete
:type timeout:  ``int``

:param use_shell: If a shell is needed to run `cmd`, set to True
:type use_shell:  ``bool`` or ``auto`` for transport-determined

:param use_container: Run this command in a container *IF* the host
                      is a containerized host
:type use_container: ``bool``

:param env: Pass environment variables to set for this `cmd`
:type env:  ``dict``
z-Node is disconnected, attempting to reconnectzFailed to reconnect to nodez!Error while trying to reconnect: N)rJ   r   r   rC   	reconnectr5   r   rF   r/   rM   format_container_commandr   rx   updaters   )
rP   r   timeout	use_shellr   r   envreconnectedrS   _cmd_envs
             rT   rs   SosNode.run_command  s    ( ~~djjNNJK"oo77G"NN#@A-- # TYY44))44S9C""3'C}}H//#&C**3+46 	6  !B3%HIs   AD 
D3D..D3c                 <    U R                  5       nU(       a  U R                  U5        OU R                  S5        U R                  (       a  U R	                  5       U l        U R                  5         g! [         a  nU R                  SU 35         SnAN4SnAff = f)z.Run an sos report on the node, then collect itz'Unable to determine path of sos archivezError during sos execution: N)execute_sos_commandfinalize_sos_pathrG   r8   retrieve_sosreportr9   rF   cleanup)rP   r   rS   s      rT   r$   SosNode.sosreport  s    		A++-D&&t,HI}}!%!8!8!: 	  	ANN9#?@@	As   A A3 3
B=BBc                 $    XR                   S   ;   $ )z/Verifies if the given preset exists on the noder#   r<   )rP   presets     rT   _preset_existsSosNode._preset_exists      y111rZ   c                 f   ^ [        U4S jU R                  S   U R                  S   4 5       5      $ )z/Verifies if the given plugin exists on the nodec              3   .   >#    U  H
  nTU;   v   M     g 7fr    )r   splugins     rT   r   )SosNode._plugin_exists.<locals>.<genexpr>  s       E )D16Q; )D   r    r!   )anyr<   rP   r8  s    `rT   _plugin_existsSosNode._plugin_exists  s;     Ey)A)-z)B)D E E 	ErZ   c                 $    XR                   S   ;   $ )z6Checks to see if the plugin is default enabled on noder    r/  r<  s     rT   _check_enabledSosNode._check_enabled  r3  rZ   c                 $    XR                   S   ;   $ )z7Checks to see if the plugin is default disabled on noder!   r/  r<  s     rT   _check_disabledSosNode._check_disabled  s    z222rZ   c                    UR                  S5      S   nU R                  U5      (       d  gU R                  U5      (       a  X R                  R                  ;  a  gU R                  U5      (       a  XR                  S   ;   $ g)zAttempts to verify that the given option is available on the node.
Note that we only get available options for enabled plugins, so if a
plugin has been force-enabled we cannot validate if the plugin option
is correct or notr   r   Fr"   T)rt   r=  rC  r+   enable_pluginsr@  r<   )rP   optplugs      rT   _plugin_option_existsSosNode._plugin_option_exists  sv    
 yy~a ""4((  &&II444t$$--	222 rZ   c                 :   ^  SR                  U 4S jU 5       5      $ )zVReturns a comma delimited list for sos plugins that are confirmed
to exist on the noder   c              3   X   >#    U  H  nTR                  U5      (       d  M  Uv   M!     g 7fr   )r=  )r   orP   s     rT   r   ,SosNode._fmt_sos_opt_list.<locals>.<genexpr>  s      B4a4+>+>q+A4s   *	*)r   )rP   r+   s   ` rT   _fmt_sos_opt_listSosNode._fmt_sos_opt_list  s     xxB4BBBrZ   c                     Xl         g)zFExpose the node to the cluster profile determined for the
environment
N)r0   )rP   r0   s     rT   set_clusterSosNode.set_cluster  s	     rZ   c                 ,  ^ U R                   R                  (       aV  U R                  (       d  U R                   R                  U l        O)U R                  SU R                   R                   S35        U R                   R                  (       aI  U R                   R                   H/  nXR
                  ;  d  M  U R
                  R                  U5        M1     U R                   R                  (       aU  U R                   R                   H;  mTU R                  ;  d  M  U R                   R                  T   U R                  T'   M=     U R                   R                  (       a|  U R                   R                   Hb  m[        U4S jU R                   5       5      (       a  M)  T SU R                   R                  T    3nU R                  R                  U5        Md     U R                   R                  U 5      (       a;  U R                   R                     U R                   R                  U 5        SSS5        gU R                   R                     U R                   R                  U 5        SSS5        g! , (       d  f       g= f! , (       d  f       g= f)a  This is used to modify the sos report command run on the nodes.
By default, sos report is run without any options, using this will
allow the profile to specify what plugins to run or not and what
options to use.

This will NOT override user supplied options.
zCluster specified preset z> but user has also defined a preset. Using user specification.c              3   .   >#    U  H
  nTU;   v   M     g 7fr   r6  )r   rM  rG  s     rT   r   2SosNode.update_cmd_from_cluster.<locals>.<genexpr>2  s     ;]3!8]r:  ro   N)r0   
sos_presetr0  r   sos_pluginsrF  r   r   sos_plugin_optionsr;  plugoptscheck_node_is_primarylockset_primary_optionsset_node_options)rP   rH  optionrG  s      @rT   update_cmd_from_clusterSosNode.update_cmd_from_cluster  s    <<"";;"ll559!%!8!8 9 :LL M <<##00222''..t4 1 <<##||//d...,0LL,D,DS,ID$$S) 0
 <<**||66;T]];;; #uAdll&E&Ec&J%KLFMM((0 7 <<--d33""006 #" ""--d3 #" #" #"s   I4J4
J
Jc                 l   [        U R                  R                  5      U l        [        U R                  R                  5      U l        [        U R                  R                  5      U l        [        U R                  R
                  5      U l        [        U R                  R                  5      U l        g)zxFrom the global opts configuration, assign those values locally
to this node so that they may be acted on individually.
N)listr+   only_pluginsskip_pluginsrF  rZ  r0  rX   s    rT   r,   SosNode._assign_config_opts>  su    
 !!7!78 !7!78"499#;#;<TYY//0499++,rZ   c           	      @   U R                   S   nU R                  5       nU(       a  U S[        U5       S3n/ nU R                  S5      (       aT  U R                  R
                  S:w  a:  UR                  S[        [        U R                  R
                  5      5       35        U R                  S5      (       aU  U R                  R                  (       a:  UR                  S[        [        U R                  R                  5      5       35        U R                  S5      (       a  U R                  R                  (       a  UR                  S	5        U R                  R                  (       a  UR                  S
5        U R                  R                  (       a1  UR                  S[        U R                  R                  5       35        U R                  S5      (       a  U R                  R                  (       a@  UR                  S[        SR                  U R                  R                  5      5       35        U R                  R                  (       a@  UR                  S[        SR                  U R                  R                  5      5       35        U R                  S5      (       aU  U R                  R                  (       a:  UR                  S[        [        U R                  R                  5      5       35        U R                  S5      (       d  U R                  S5      (       a  U R                  R                   S:w  a(  UR                  SU R                  R                    35        U R                  R"                  (       a(  UR                  SU R                  R"                   35        U R                  S5      (       ao  U R                  R$                  (       a(  UR                  SU R                  R$                   35        U R                  R&                  (       a  UR                  S5        U R)                  5         UR+                  S[,        R.                  R                  U R0                  R2                  U R4                  5      5      nU R6                   H2  nU R6                  U   nUR                  SU SU(       a  UOS 35        M4     U R8                  (       a  U R8                   Vs/ s HY  nU R;                  UR=                  S5      S   5      (       d  M-  U R?                  UR=                  S5      S   5      (       d  MW  UPM[     nnU(       a3  UR                  S [        SR                  S! U 5       5      5       35        U R@                  (       ag  U RC                  U R@                  5      (       a(  UR                  S"[        U R@                  5       35        OU RE                  S#U R@                   S$35        U RF                  (       Ga3  U RF                   Vs/ s H  o`R;                  U5      (       d  M  UPM     nn[I        U5      [I        U RF                  5      :w  a?  [K        [M        U RF                  5      [M        U5      -
  5      n	U RE                  S%U	 S&35        U RO                  U RF                  5      n
U
(       a  UR                  S'[        U
5       35        U SSR                  U5       3U l(        U RS                  S(U RP                   35        U RT                  RW                  S)U RP                  5        g*U RX                  (       a  U RX                   Vs/ s H  o`R[                  U5      (       d  M  UPM     nn[I        U5      [I        U RX                  5      :w  a?  [K        [M        U RX                  5      [M        U5      -
  5      nU RE                  S+U S,35        U RO                  U5      nU(       a  UR                  S-[        U5       35        U R\                  (       a  U R\                   Vs/ s HF  nX`RX                  ;  d  M  U R_                  U5      (       d  M,  U R;                  U5      (       d  MD  UPMH     nn[I        U5      [I        U R\                  5      :w  a?  [K        [M        U R\                  5      [M        U5      -
  5      nU RE                  S.U S/35        U RO                  U5      nU(       a  UR                  S0[        U5       35        U SSR                  U5       3U l(        U RS                  S(U RP                   35        U RT                  RW                  S)U RP                  5        g*s  snf s  snf s  snf s  snf )1zRUse host facts and compare to the cluster type to modify the sos
command if neededr    r      z
--threads=z3.7z--plugin-timeout=z3.8z--allow-system-changesz--no-env-varsz--since=z4.1z--skip-commands=r   z--skip-files=z4.2z--cmd-timeout=z4.3z4.2-13r_   z--container-runtime=z--namespaces=z4.5.2z--journal-size=z--low-priorityr$   z--r~   r   r   ro   z-k c              3   $   #    U  H  ov   M     g 7fr   r6  )r   rM  s     rT   r   +SosNode.finalize_sos_cmd.<locals>.<genexpr>  s     4E1Qs   z	--preset=zRequested to enable preset z" but preset does not exist on nodezRequested plugins z. were requested to be enabled but do not existz--only-plugins=zFinal sos command set to r}   NzRequested to skip plugins z%, but plugins are already not enabledz--skip-plugins=zRequested to enable plugins z1, but plugins are already enabled or do not existz--enable-plugins=)0r<   determine_sos_labelr   r   r+   threadsr   strplugin_timeoutallow_system_changesno_env_varssinceskip_commandsr   
skip_filescmd_timeoutcontainer_runtime
namespacesjournal_sizelow_priorityr`  replacerp   r   r/   sos_bin_pathr=   r   rZ  r=  rt   rI  r0  r1  r   rd  r   rc  setrO  r   r   r   r   re  r@  rF  rC  )rP   r   labelsos_optsrG  rw   rM  r+   plugsnot_onlyonlyskipnot_skipskiplnnot_onenables                   rT   finalize_sos_cmdSosNode.finalize_sos_cmdI  sl    --	*((* 	5<.2G !!%((yy  A%*U3tyy7H7H3I-J,K LM !!%((yy'''c$))2J2J.K(L'MNP !!%((yy-- 89yy$$0yy(5+A*B CD!!%((yy&& 2#($))2I2I)J#K"L!N Oyy###E#((4993G3G*H$I#JK !!%((yy$$$U3tyy/D/D+E%F$GH
 !!%((D,B,B8,L,Lyy**f4*499+F+F*GH yy###DII$8$8#9: !!'**yy%%/$))2H2H1I JKyy%% 01$$&//GGLL//>

 ##C##C(DOObQtt&<=> $ ==#}} E}!**1773<?; 221773<?C }D E #eCHH4E4E,E&F%G HI;;""4;;//)E$++,>+? @A!<T[[M J?  ? @  $ 1 1L 115H5H5KQ 1EL5zS!2!233D$5$5 6U CD!3H: >@  @ A))$*;*;<D/%+ ?@%Ya(:';<DLMM5dll^DEMM##$7F#00K0!4G4G4JA0DK4yC 1 122D$5$5 6T BC!;H: FA  A B++D1F/%- AB#22 L2! 1 11 ,,Q/ 484G4G4J 2D L 4yC 3 344c$"5"56TBC!=fX FM  M N++D1F"3E&M? CD!!CHHX$6#781$,,@A 3T\\BkE M LLsB   5,f%&ff)ff-f
fff6ffc                    SnXR                   R                  U 5      -  nU R                  R                  (       a9  X(       d  U R                  R                   OSU R                  R                   3-  nU(       d  gU R	                  SU 35        U R                  S5      (       a  SnO%SnU R                  R                  S5      S	    SU 3nU S
U 3$ )z?Determine what, if any, label should be added to the sos reportr~   r   NzLabel for sos report set to r   z--labelz--namer   r   ro   )r0   get_node_labelr+   r}  r   r   r)   rt   )rP   r}  lcmds      rT   rl  SosNode.determine_sos_label  s    ,,T2299??%)tyy/02E 5eW=>!!%((DD||))#.q12!E7;Eq  rZ   c                 :   U R                   R                  nU(       a  UR                  US5      nUR                  5       S   nU R	                  SU 35        Xl        UR                  S5      S   U l        U R                  R                  SU R                  5        g)zTUse host facts to determine if we need to change the sos path
we are retrieving fromr~   r   zFinal sos path: /collected_archiveN)	r/   sos_path_striprz  rt   r   r8   archiver   r   )rP   r   pstrips      rT   r*  SosNode.finalize_sos_path  s{     ))<<+Dzz|A(/0zz#r* 3T\\BrZ   c                     US:X  a  gUS:X  a  SU;   a  gUS:X  a  g[        U5      S:  a  UR                  S	5      SS $ S
U 3$ )Nr  z+sos report process received SIGKILL on nodere   sudozsudo attempt failed   z4sos report terminated unexpectedly. Check disk spacer   
zsos exited with code )r   rt   )rP   rcstdouts      rT   determine_sos_errorSosNode.determine_sos_error  sV    8@7,9Iv;?<<%a**&rd++rZ   c           	      x   U R                  S5         SnSnSnU R                  R                  (       a  SU R                  R                   3nOU R                  R                  (       a  U R                  (       dX  SU R
                  R                  S5      S    S3nU R                  R                  U R                  R                  U5        SU 3nOSU R                  R                   3nU(       a  U R                   S	U 3U l
        U R                  U R                  U R                  R                  S
S
S
U R                  S9nUS   S:X  GaX  US   R                  5        H  n[        R                  " US5      (       a  UR!                  5       nUR#                  S5      (       a  UR                  S5      S   nM[  UR#                  S5      (       d  Ms  UR                  5       S   nM     U(       a  U R$                  R'                  SU5        [)        U5      S:X  a  U R$                  R'                  SS5        U$ [)        U5      S:X  a  U R$                  R'                  SS5        U$ U R$                  R'                  SS5         U$ U R$                  R'                  SS5         U$ U R+                  US   US   5      nU R-                  SUS    SUS    35        [/        U5      e! [0         a    U R3                  S5        e [.         a.  nU R5                  SU 35        U R                  S U 35        e S!nAff = f)"z2Run sos report and capture the resulting file pathzGenerating sos report...Fr~   z--config-file=z/tmp/r  r  z.confrh  T)r"  r#  r   r   r$  rl   r   rm   z*sosreport-*tar*)z sha256	z md5		re   zThe checksum is: r   checksum    checksum_typemd5@   sha256unknownzError running sos report. rc = z msg = zTimeout exceededz'Exception during sos report execution: zError running sos report: N)r   r+   r-   r.   r   r   rt   rC   copy_file_to_remoteconfig_filer   rs   r"  r2   r   fnmatchr(   r   r   r   r   r  r   rF   r   rG   r   )rP   r   r  config_file_argremote_configr   r   rS   s           rT   r)  SosNode.execute_sos_command  s   ./7	DH Oyy))$24993M3M2N"O..zz&+DKK,=,=c,B2,F+Gu$MMOO77		--%' )7}o&FO ))>)>(?@ $"&,,q0AB""4<<+/99+<+<-1-115'+'8'8 # :C 8}!M446Dt-?@@#zz|'>??#'::d#3A#6)<==#'::<? 7 MM++JA8}*//G K X",//J K //K K MM++OYG K	 ..s8}c(mL@"%h-H H In$& 	NN-. 	MMCC5IJKK4SE:;	s8   F=K& A&K& ;,K& (K& K& &A K& &%L9)L44L9c                    U R                   S-   n[        R                  R                  X!R	                  S5      S   5      n U R                  U5      (       a2  U R                  SU SU 35        U R                  R                  X5      $ U R                  SU S35        g! [         a!  nU R                  SU S	U 35         S
nAgS
nAff = f)z7Copies the specified file from the host to our temp dirr  r  zCopying remote z
 to local zAttempting to copy remote file %, but it does not exist on filesystemFzFailed to retrieve r  N)r   rp   r   r   rt   r   r   rC   retrieve_filer   rF   )rP   r   destdirdestrS   s        rT   r  SosNode.retrieve_file5  s    ++#ww||GZZ_R%89		%%vZyIJ44T@@NN<TF C; ; < 	NN0b>?	s   AB  
B   
C*CCc                    SR                  UR                  5       5      n [        UR                  S5      5      S::  a  U R                  SU S35        gU R	                  U5      (       a1  U R                  SU 35        SU 3nU R                  US	S
9nUS   S:H  $ U R                  SU S35        g! [         a!  nU R                  SU SU 35         SnAgSnAff = f)zlRemoves the spciefied file from the host. This should only be used
after we have retrieved the file already
r~   r  r   zRefusing to remove path z0: appears to be incorrect and possibly dangerousFzRemoving file zrm -f Tr   rl   r   z!Attempting to remove remote file r  zFailed to remove r  N)r   rt   r   r   r   r   rs   rF   )rP   r   r   r   es        rT   remove_fileSosNode.remove_fileD  s     wwtzz|$	4::c?#q(!9$ @E  E F%%tf56tfo&&sd&;8}))NN>tf E= = > 	NN.tfBqc:;	s$   3B2 AB2 B2 2
C<CCc                 ~   U R                   (       d  U R                  R                  (       a   U R                  U R                  5        U R                  SU R                   35        U R                  S5         U R                  U R                  5      nU(       aI  U R                  S5        U R                  R                  U R                  R                  S5      S   5        g	U R                  S
5        g! [
         a    U R                  S5         gf = f! [
         a  nU R                  U5         SnAgSnAff = f)z,Collect the sos report archive from the nodezFailed to make archive readableFzRetrieving sos report from zRetrieving sos report...Nz!Successfully collected sos reportr  r  TzFailed to retrieve sos report)r   r+   r   make_archive_readabler8   rF   rG   r   r)   r   r  r;   r   rt   )rP   ru   rS   s      rT   r+  SosNode.retrieve_sosreportZ  s    >>TYY22**4==9 	3DLL>BC./	$$T]]3C KK;<NN!!$--"5"5c":2">?34  @A  	NN3	s)   C6 9D 6DD
D<!D77D<c                 
   U R                   b  U R                  (       a  gSU R                   ;  a   U R                  SU R                    S35        gU R                  U R                   5      nU(       d  U R	                  S5        gg)znRemove the sos report archive from the node, since we have
collected it and it would be wasted space otherwiseNr$   zNode sos report path z/ looks incorrect. Not attempting to remove pathzFailed to remove sos report)r8   r   r   r  rG   )rP   removeds     rT   remove_sos_archiveSosNode.remove_sos_archivep  sv     == DJJ dmm+NN24==/ BF F G""4==1NN89 rZ   c                    U R                  5         U R                  (       a.  S H(  nU R                  U R                  U-   5      (       d  M(    O   U R                  R	                  5       nU(       a  U R                  USS9  gg)z<Remove the sos archive from the node once we have it locally)z.sha256z.md5Tr   N)r  r8   r  r/   set_cleanup_cmdrs   )rP   extr,  s      rT   r,  SosNode.cleanup  sk    !==*##DMMC$788 + ))++-W5 rZ   c                 P   U H  n U R                   (       d  U R                  R                  (       a   U R                  U5        U R                  U5      nU(       a@  U R                  R                  UR                  S5      S   5        U R                  U5        M  U R                  SU 35        M     g! [         a6  nU R                  SU 35        U R                  SU SU 35         SnAM  SnAff = f! [         a"  nSU 3nU R                  U5         SnAGM  SnAff = f)z4Collect the file created by a cluster outside of soszUnable to retrieve file zFailed to make file z readable: Nr  r  z/Error collecting additional data from primary: )r   r+   r   r  rF   rG   r   r  r;   r   rt   r  )rP   	filenamesfilenamerS   ru   r  rh   s          rT   collect_extra_cmdSosNode.collect_extra_cmd  s   !H$>>TYY%:%:!228< ((2NN))(..*=b*AB$$X.NN%=hZ#HI "
 % !)A('LM)=hZ H4475(: ; 	!  $GsKs##$sG   ,C9B6AC9C96
C6 +C1+C91C66C99
D%D  D%c                     SU 3nU R                  USSS9nUS   S:X  a  gSnU R                  XAUS   4-  5        [        e)zUsed to make the given archive world-readable, which is slightly
better than changing the ownership outright.

This is only used when we're not connecting as root.
z
chmod o+r 
   T)r"  r   rl   r   z6Exception while making %s readable. Return code was %s)rs   rG   rF   )rP   filepathr   r   rh   s        rT   r  SosNode.make_archive_readable  sX     8*%sB$?x=AFsH667rZ   )"r3   r5   rC   r)   r  r0   r*   rJ   rF  r;   r:   r/   r   r1   r.   r   r   r   r-   rd  r+   rZ  r0  r9   re  r=   r   r2   r<   r   r8   r@   r   rA   )NNT)F)   r_   FFN)7__name__
__module____qualname____firstlineno__rU   propertyrJ   rK   rB   ri   rx   r   rL   rN   r   r   rf   r   r   r   rG   r   r   rO   r   r   r   r  rH   r   r  rs   r$   r1  r=  r@  rC  rI  rO  rR  r`  r,   r  rl  r*  r  r)  r  r  r+  r  r,  r  r  __static_attributes__r6  rZ   rT   r   r   *   sD   CG CJ  %
8"?  C
&P
  
3- 2h;P"'$$F IN-1&6P2E
23"C
&4P	-BCH!(
C
,:x,,:	6$,rZ   r   )r  r   r>   rp   r   shlexr   sos.policiesr   sos.policies.init_systemsr   sos.collector.transports.jujur   (sos.collector.transports.control_persistr   sos.collector.transports.localr   sos.collector.transports.ocr	   "sos.collector.transports.saltstackr
   sos.collector.exceptionsr   r   r   r   sos.utilitiesr   ra   r   r6  rZ   rT   <module>r     sc       	 	   0 1 F 9 3 >A A , (
 
B BrZ   