id$RddlZddlZddlZddlmZddlmZmZmZGddeZ y)N)RemoteTransport) is_executablesos_get_command_outputSoSTimeoutErrorcxeZdZdZdZdZdZedZdZ dZ fdZ d fd Z d Z ed Zd ZxZS) OCTransportaq 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. oczsos-collect-tmpc :td|jd|fi|S)z\Format and run a command with `oc` in the project defined for our execution oc -n  )rproject)selfcmdkwargss =/usr/lib/python3/dist-packages/sos/collector/transports/oc.pyrun_oczOCTransport.run_oc1s%&!\\3 /   cN|jd|jz}|ddk(S)Nz.wait --timeout=0s --for=condition=ready pod/%sstatusrrpod_name)rups r connectedzOCTransport.connected:s- [[ )&+/)*,"&%)#M')V!% : :H!( LL#_PY Y rcHtdsy|j}|dd|_tj|j \}|_t|d5}tj||ddd|jd|jztd|j z}|d d k7sd |jz|d vr)|jd |jd|d zy|jd|jz |jd|jzd}|d d k(s|jdy y#1swYxYw#t$r|jdYyt$r}|jd|zYd}~yd}~wwxYw)Nr FrDr)dirwz%Starting sos collector container '%s'zoc create -f %srrzpod/%s createdoutputz Unable to deploy sos collect podzDebug pod deployment failed: %szDPod '%s' successfully deployed, waiting for pod to enter ready statez/wait --for=condition=Ready pod/%s --timeout=30s()timeoutz"Pod not available after 30 secondsz'Timeout while polling for pod readinessz+Error while waiting for pod to be ready: %sT)rrLrtempfilemkstemptmpdir pod_tmp_confopenjsondump log_debugr log_errorrr Exception)rpasswordpodconffdcfileoutrerrs r_connectzOCTransport._connectsT"**, +F3 ( 0 0T[[ AD  "c] &e IIgu % & >NO$  1 1 1  MQ "2T]]"BH # NN= > NN>$ ||T]]C9 :[$>$++ , IId'' (++o => GH- - NN"mmW6 7rc<d|jd|jdS)Nr rez -- /bin/bash -c)r rrKs r remote_execzOCTransport.remote_execs<<0 1rc |jdd}d|dvrdnd}|jd|d |jd |d |}|d d k(S) Nz cp --retriesT)stderrz unknown flagrPz --retries=5zcp r :rrr)rfnamedestresultflagsrs r_retrieve_filezOCTransport._retrieve_filesX^D9$x(88mkk"DMM5$@A8}!!r)FNF)__name__ __module__ __qualname____doc__rr rpropertyrrLrcrhrlrurwr __classcell__)ris@rrrsn2 DG !! ^ @)VB BF! @11"rr) rXrSrqsos.collector.transportsr sos.utilitiesrrrrrrrs+  4,,^"/^"r