+
    i%  c                   sT    ^ RI t ^ RIt^ RIt^ RIHt ^ RIHtHtHt  ! R R]4      t	R# )i    N)RemoteTransport)is_executablesos_get_command_outputSoSTimeoutErrorc                   s   a a ] tR t^t oRtRtRtR t]R 4       t	R t
R tV 3R ltRV 3R	 lltR
 t]R 4       tR tR tRtVtV ;t# )OCTransporta)  
This transport leverages the execution of commands via a locally
available and configured ``oc`` binary for OCPv4 environments.

The location of the oc binary MUST be in the $PATH used by the locally
loaded SoS policy. Specifically this means that the binary cannot be in the
running user's home directory, such as ~/.local/bin.

OCPv4 clusters generally discourage the use of SSH, so this transport may
be used to remove our use of SSH in favor of the environment provided
method of connecting to nodes and executing commands via debug pods.

The debug pod created will be a privileged pod that mounts the host's
filesystem internally so that sos report collections reflect the host, and
not the container in which it runs.

This transport will execute within a temporary 'sos-collect-tmp' project
created by the OCP cluster profile. The project will be removed at the end
of execution.

In the event of failures due to a misbehaving OCP API or oc binary, it is
recommended to fallback to the control_persist transport by manually
setting the --transport option.
oczsos-collect-tmpc                s:    \        RV P                   RV 23/ VB # )zLFormat and run a command with `oc` in the project defined for our
execution
oc -n  )r   project)selfcmdZkwargss   &&,@/usr/lib/python3.14/site-packages/sos/collector/transports/oc.pyrun_ocZOCTransport.run_oc1   s-     &T\\N!C5)

 	
    c                sV    V P                  R V P                   24      pVR,          ^ 8H  # )z,wait --timeout=0s --for=condition=ready pod/statusr   pod_name)r	   up   & r   	connectedZOCTransport.connected:   s/    [[:4==/J
 (|q  r   c                 s   RRRRRRV P                   P                  R4      ^ ,           R2R	V P                  /R
RRRRRRRRRR//RRRRRRR//RRRRRRR//RRRRRRR//.RRRRV P                  P                  '       g   RMV P                  P                  RR .R!RR"R#R$/.R%/ R&RRR'R$/RRR'R/RRR'R/RRR'R/.R(R)R*R+^ /R,R*R-R*R.R*/
.R/V P                  P
                  '       d   R0MR1R2R3R4V P                   R5R*R6R*R7R*//# )8zBased on our template for the debug container, add the node-specific
items so that we can deploy one of these on each node we're collecting
from
ZkindZPodZ
apiVersionZv1metadatanameZ.z-sos-collectorZ	namespaceZpriorityClassNamezsystem-cluster-criticalZspecZvolumesZhostZhostPathpathZ/ZtypeZ	DirectoryZrunz/runZvarlogz/var/logz
machine-idz/etc/machine-idZFileZ
containerszsos-collector-tmpimagez&registry.redhat.io/rhel8/support-toolsZcommandz	/bin/bashenvZHOSTZvaluez/hostZ	resourcesZvolumeMountsZ	mountPathZsecurityContextZ
privilegedTZ	runAsUserZstdinZ	stdinOnceZttyZimagePullPolicyZAlwaysZIfNotPresentZrestartPolicyZNeverZnodeNameZhostNetworkZhostPIDZhostIPC)ZaddressZsplitr   Zoptsr   Zforce_pull_imager	      &r   get_node_pod_configZOCTransport.get_node_pod_configA   s    E$4<<--c2156nET\\  !:""C"K% ""F"K% ""J"K% ""$5"F%-<  3'+yy "J<@IIOO!'$  & '  $R& & +W
 !' +V
 !' +Z
 !' +->)$ *($',  #TtM')T " $		 : : :HDLLt44_PY
 Y	
r   c                s   \        R 4      '       g   R# V P                  4       pVR,          R,          V n        \        P                  ! V P
                  R7      w  q0n        \        VRRR7      ;_uu_ 4       p\        P                  ! W$4       RRR4       V P                  R	V P                   R
24       \        RV P                   24      pVR,          ^ 8w  g   RV P                   R2VR,          9  d/   V P                  R4       V P                  RVR,           24       R# V P                  RV P                   R24        V P                  RV P                   R2^(R7      pVR,          ^ 8X  g   V P                  R4       R#  R#   + '       g   i     EL; i  \         d    T P                  R4        R# \         d    pT P                  RT 24        Rp?R# Rp?ii ; i)r   Fr   r   )ZdirZwzutf-8)ZencodingNz"Starting sos collector container 'Z'zoc create -f r   zpod/z createdoutputz Unable to deploy sos collect podzDebug pod deployment failed: zPod 'z=' successfully deployed, waiting for pod to enter ready statezwait --for=condition=Ready pod/z --timeout=30stimeoutz"Pod not available after 30 secondsz'Timeout while polling for pod readinessz)Error while waiting for pod to be ready: T)r   r   r   tempfileZmkstempZtmpdirpod_tmp_confZopenjsonZdump	log_debugr   Z	log_errorr   r   Z	Exception)r	   ZpasswordZpodconfZfdZcfileZoutr   Zerrs   &&      r   _connectZOCTransport._connect   s   T"" **,
+F3 ( 0 0T[[ A"cG,,IIg% -;DMM?!LM$D--./
 MQDx"@H#NN=>NN:3x=/JKt}}o .6 6 	7	>t}}o N- - &(  )B h<1$CD % ? -,,0  	NNDE 	NNFseLM	s1   7F
A F 
F	G&=G&G&G!!G&c                s   < VP                  R 4      '       d    RV P                   RV P                   RV 2# \        SV `  V4      # )r   r    exec --request-timeout=0 z -- chroot /host )Z
startswithr   r   super_format_cmd_for_exec)r	   r
   	__class__s   &&r   r&   Z OCTransport._format_cmd_for_exec   sJ    >>$T\\N*D}}o%6se= >w+C00r   c                sL   < V'       d
   V^
,          p\         SV `  WVVRR7      # )i
   F)	use_shell)r%   run_command)r	   r
   r   Z	need_rootr   r(   r'   s   &&&&&&r   r)   ZOCTransport.run_command   s3     rMG w"3#&% # 9 	9r   c                sB   \         P                  P                  V P                  4      '       d!   \         P                  ! V P                  4       V P                  R V P                   24      pRVR,          9  d$   V P                  RV P                   RV 24       R# R# )zdelete pod Zdeletedr   zCalling delete on pod 'z
' failed: FT)osr   Zexistsr    Zunlinkr   r   r"   )r	   Zremovedr   r   _disconnectZOCTransport._disconnect   s|    77>>$++,,IId''(++DMM?;<GH--NN4T]]O:%Y( )r   c                s<    R V P                    RV P                   R2# )r   r$   z -- /bin/bash -c)r   r   r   r   r   remote_execZOCTransport.remote_exec   s&    &@==/!13 	4r   c           
     s    V P                  R RR7      pRVR,          9   d   RMRpV P                  RV RV RV P                   R	V 2^R
7      pVR,          ^ 8H  # )cp --retriesTZstderrunknown flagr    --retries=5cp r   :r   r   r   r	   ZfnameZdestZresultZflagsr
      &&&   r   _copy_file_to_remoteZ OCTransport._copy_file_to_remote   sk    ^D9$x(88mkkCwawaavF"$  &8}!!r   c           
     s    V P                  R RR7      pRVR,          9   d   RMRpV P                  RV RV P                   R	V RV 24      pVR
,          ^ 8H  # )r-   Tr.   r/   r   r0   r1   r2   r   r3   r   r   r4   r5   r   _retrieve_fileZOCTransport._retrieve_file   sa    ^D9$x(88mkkCwaawavFG8}!!r   )r   r    )i   FNF)Z__name__Z
__module__Z__qualname__Z__firstlineno__Z__doc__r   r   r   Zpropertyr   r   r#   r&   r)   r+   r,   r6   r7   Z__static_attributes__Z__classdictcell__Z__classcell__)r'   Z__classdict__s   @@r   r   r      sn     2 DG
 ! !^
@(T1	9 4 4"" "r   r   )
r!   r   r*   Zsos.collector.transportsr    Zsos.utilitiesr   r   r   r   ) r   r   <module>r8      s+      	 4, ,c"/ c"r   