/usr/lib/python3/dist-packages/sos/collector/__pycache__
NameSizeModeActions
exceptions.cpython-310.pyc51830644editdlrm
sosnode.cpython-310.pyc290930644editdlrm
__init__.cpython-310.pyc444930644editdlrm
Edit: /usr/lib/python3/dist-packages/sos/collector/__pycache__/sosnode.cpython-310.pyc (29093B)
o G%@i͗@sddlZddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z ddl mZddlmZddlmZdd lmZdd lmZmZmZmZdd lmZeeeee d ZGd ddZdS)N)quote)load) InitSystem)JujuSSH)SSHControlPersist)LocalTransport) OCTransport)SaltStackMaster)CommandTimeoutExceptionConnectionExceptionUnsupportedHostExceptionInvalidTransportException)sos_parse_version)localcontrol_persistoc saltstackjujuc@seZdZ  dhddZeddZddZd d Zd d Zed dZ ddZ ddZ ddZ ddZ diddZeddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zdid.d/Zd0d1Zd2d3Zd4d5Zd6d7Z  djd:d;Zdd?Z d@dAZ!dBdCZ"dDdEZ#dFdGZ$dHdIZ%dJdKZ&dLdMZ'dNdOZ(dPdQZ)dRdSZ*dTdUZ+dVdWZ,dXdYZ-dZd[Z.d\d]Z/d^d_Z0d`daZ1dbdcZ2dddeZ3dfdgZ4dS)kSosNodeNTc Cs||_||_|d|_||d|_|d|_|d|_|d|_|jj |_ |jj |_ d|_ d|_ d|_ d|_i|_i|_|pF|jj|_|jjsU|jjsU|j|j_|r[||j_d|_d|_d|_g|_dgggg|dd|_d |_td |_td |_|||_ |j j!r|j j!d k|_z |j "|jWnt#y}z |$d |d}~ww|%|_ |j j|_|j r|jj&rd}|j'r|r|j s|j (dS|j r|)rd|j _*|j j*r|+|,dS)N cmdlineoptstmpdirhostlen need_sudo sos_optionsFsos_cmd)versionenableddisabledoptionspresetsr sosreportsossos_uirootzUnable to open remote session: )-stripaddresscommonsopts_assign_config_optsrrrrnode_config_fileinherit_config_filerhostclusterhostname sos_env_vars _env_varspassword _password nopasswd_sudosudo_pwsos_path retrievedhash_retrieved file_listsos_infosos_binlogging getLoggersoslogui_log_load_remote_transport _transport default_userconnect Exception log_errordetermine_host_policyno_local connected disconnectcheck_in_container containerizedcreate_sos_container_load_sos_info)selfr%r&r0 local_sudo load_factserrrP7/usr/lib/python3/dist-packages/sos/collector/sosnode.py__init__,sx                zSosNode.__init__cCs|jr|jjSdS)NT)r?rFrLrPrPrQrFqszSosNode.connectedcCs|jdS)zDWrapper to close the remote session via our transport agent N)r?rGrSrPrPrQrGxszSosNode.disconnectcCst|jdvrd|_t|j|S|jjtvrt|jj|j|S|jjdkr4|d|jjt|jjt|j|S)zDetermine the type of remote transport to load for this node, then return an instantiated instance of that transport ) localhostz 127.0.0.1Tautoz4Connection failed: unknown or unsupported transport ) r%rrr' transport TRANSPORTSrCr r)rLr&rPrPrQr>}s      zSosNode._load_remote_transportcCs|jd|jdd|S)N<z : ) _hostnamerrLmsgrPrPrQ_fmt_msgszSosNode._fmt_msgcCsp|js5|jrtj|_|jS|d}|ddkr5|ddD]}|s&q!|d}|d|j|d<q!|jS)Nz env --nullstatusroutput=rY)r/rosenvironcopy run_commandsplit)rLretln_valrPrPrQenv_varss   zSosNode.env_varscCs`||_|jd|j|jd|jj|jd|jd|jdd|jd|jjdS) z>Set the manifest section that this node will write to r-policy sos_versionrfinal_sos_commandrVN)manifest add_fieldrZr+os_release_namer8r?name)rLrorPrPrQset_node_manifests zSosNode.set_node_manifestcCs<tjdr |ddStjddur|ddSdS)zV Tries to identify if we are currently running in a container or not. z/run/.containerenvz/Found /run/.containerenv. Running in container.T containerNz/Found env var 'container'. Running in containerF)rbpathexists log_debugrcgetrSrPrPrQrHs   zSosNode.check_in_containercCs|jjru|jj|jj||jjd}|j|dd}|ddvri|ddkr@d|dvr3|d t d |dvr@|d t |j|j dd}|dd kr]| d |jj ddS|d|dt |d|dt dS)zJIf the host is containerized, create the container we'll be using )imageauth force_pullT need_rootr^)r}r~zunable to retrieve auth tokenr_zHCould not pull image. Provide either a username and password or authfilezunknown: Not foundz%Specified image not found on registryrzTemporary container z createdz(Could not start container after create: z$Could not create container on host: F) r+rIrJr'ryget_container_authforce_pull_imagererCrBrestart_sos_containerlog_infosos_container_name)rLcmdresrgrPrPrQrJsD        zSosNode.create_sos_containercCsB|jjr|jjd|jj|jjS|jjd|jjp|jjS)zrDetermine what the auth string should be to pull the image used to deploy our temporary container default) r' registry_userr+runtimesfmt_registry_credentialsregistry_passwordfmt_registry_authfileregistry_authfilecontainer_authfilerSrPrPrQrs  zSosNode.get_container_authFcCs8z|jd||d}|ddkWStyYdSw)z3Checks for the presence of fname on the remote nodezstat r|r^rF)rerB)rLfnamer}rrPrPrQ file_existss  zSosNode.file_existscCs|jr d|jvr |jS|jS)NrT)r-r%rSrPrPrQrZszSosNode._hostnamecCsd}t|d|S)zUAttempts to obfuscate sensitive information in log messages such as passwordsz>(?P(pass|key|secret|PASS|KEY|SECRET).*?=)(?P.*?\s)z\g****** )resub)rLr\regrPrPrQ_sanitize_log_msgszSosNode._sanitize_log_msgcCs|j||dS)z:Format a ui message that includes host name and formattingN)r=infor]r[rPrPrQui_msgszSosNode.ui_msgcC8tdd}d|jd|d|}|j|dS)z#Used to print and log info messagesrY[:] N)inspectstackrZr<rrLr\callerlmsgrPrPrQrzSosNode.log_infocCr)z$Used to print and log error messagesrYrrrrN)rrrZr<errorrrPrPrQrC rzSosNode.log_errorcCsB||}tdd}d|jd|d|}|j|dS)z$Used to print and log debug messagesrYrrrrN)rrrrZr<debug)rLr\rrPrPrQrws zSosNode.log_debugcCsR|jdtjddk}|jr|r|S|jjrdt|S|jr'd|S|S)zIf we need to provide a sudo or root password to a command, then here we prefix the command with the correct bits USERr#zsu -c zsudo -S ) r/rxrbrcrr' become_rootrr)rLris_rootrPrPrQ _format_cmds  zSosNode._format_cmdc Csd}d}|jjdur'|jj|jj}|dur&d|d}|dr&|d}n|j|jjddd}|ddkrC|d d \}}}|r{t |dd krR|d 7}z|d |dd7}Wnt yz}z| d |WYd}~nd}~ww||j d<|j dr| d|j dn|j|jjks|dd|_dS|drd|_|jd}|j|ddd}|ddkr||d |dr|dS)zLQueries the node for information about the installed version of sos N.rreleaseT use_containerr}r^rr_-z.0z#Unable to fully parse sos release: zsos version is z!sos is not installed on this nodeFz4.0z sos reportz -l3.6)r+container_version_commandpackage_manager pkg_version sos_pkg_namejoinrer$rflenrBrwr8rr%r'primaryrCrFcheck_sos_versionr9_load_sos_plugins_load_sos_presets) rLverrelpkgpkgs_rOrsosinforPrPrQrK#sN          zSosNode._load_sos_infocCsr|jd}|j|ddd}|ddkr5|dD]}|dr4|dd}|jd |qdSdS) Nz --list-presetsTrr^rr_zname:rYr)r9re splitlinesr$ startswithrfr8append)rLrrlinepnamerPrPrQrWs  zSosNode._load_sos_presetsc Csd}d}d}d}d}|d|}|d|}|d|} |dd} ||||jd<||||jd <|| ||jd <|| |d |jd <dS) 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 rrrTprofiles)_regex_sos_helpr8) rLrENABLEDDISABLED ALL_OPTIONSOPTIONSPROFILES enableregdisregoptregproregrPrPrQr`s    zSosNode._load_sos_pluginsc Csg}t||tjD]D}|D]=}|s>z|}r"||dWqty=}z|d|WYd}~qd}~ww|d} |dd| Dqq |S)NrzError parsing sos help: ,css |] }|r|VqdSN)r$).0prPrPrQ }sz*SosNode._regex_sos_help..) rfindallSrrfrrBrwextend) rLregexris_listrresultrlsrOrrPrPrQrqs     zSosNode._regex_sos_helpc Cs\z|d||j|WSty-}z|d|d|WYd}~dSd}~ww)z1Reads the specified file and returns the contentsz Reading file zException while reading : Nrn)rr? read_filerBrC)rLto_readrOrPrPrQrszSosNode.read_filec Csv|jr|d|jdj|jdSti|jjtd|jj | dd}|r4|d|jd|S| dt ) z[Attempts to identify the host installation against supported distributions zusing local policy rkTz/etc/os-release)cachesysrootinit probe_runtime remote_exec remote_checkzloaded policy z for hostz4Unable to determine host installation. Ignoring node) rrr&rqrr'rrr?rerrCr )rLr+rPrPrQrDs  zSosNode.determine_host_policyc CsTz|jd}t|t|kWSty)}z|d|WYd}~dSd}~ww)aChecks 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`` rzError checking sos version: NF)r8rrBrC)rLr _node_verrOrPrPrQrs zSosNode.check_sos_versioncCs|jsdS|jj|duS)z2Checks if a given package is installed on the nodeFN)r+r pkg_by_name)rLrrPrPrQ is_installedszSosNode.is_installedrUc Cs|js3|js3|dz|j|j}|s|dtWnty2}z |d|d}~ww|r?|jj r?|j |}|rF| |}|rP|j } | |}|j|||||S)aRuns 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 reconnectzFailed to reconnect to nodez!Error while trying to reconnect: N)rFrrwr? reconnectr1r rBr+rIformat_container_commandrrjupdatere) rLrtimeout use_shellr}renv reconnectedrO_cmd_envrPrPrQres.       zSosNode.run_commandc Csxz|}|r ||n|d|jr||_Wnty5}z|d|WYd}~nd}~ww|dS)z.Run an sos report on the node, then collect itz'Unable to determine path of sos archivezError during sos execution: N)execute_sos_commandfinalize_sos_pathrCr4retrieve_sosreportr5rBcleanup)rLrurOrPrPrQr s    zSosNode.sosreportcC||jdvS)z/Verifies if the given preset exists on the noderr8)rLpresetrPrPrQ_preset_existszSosNode._preset_existscs&tfdd|jd|jdfDS)z/Verifies if the given plugin exists on the nodec3|]}|vVqdSrrP)rspluginrPrQrz)SosNode._plugin_exists..rr)anyr8rLrrPrrQ_plugin_existss zSosNode._plugin_existscCr)z6Checks to see if the plugin is default enabled on noderrrrPrPrQ_check_enabledrzSosNode._check_enabledcCr)z7Checks to see if the plugin is default disabled on noderrrrPrPrQ_check_disabledrzSosNode._check_disabledcCsR|dd}||sdS||r||jjvrdS||r'||jdvSdS)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 notrrFrT)rfrrr'enable_pluginsrr8)rLoptplugrPrPrQ_plugin_option_existss    zSosNode._plugin_option_existscsdfdd|DS)z^Returns a comma delimited list for sos plugins that are confirmed to exist on the noderc3s|] }|r|VqdSrrrorSrPrQrsz,SosNode._fmt_sos_opt_list..)r)rLr'rPrSrQ_fmt_sos_opt_list szSosNode._fmt_sos_opt_listcCs ||_dS)zVExpose the node to the cluster profile determined for the environment N)r,)rLr,rPrPrQ set_clusters zSosNode.set_clustercs^|jjr|js |jj|_n |d|jjd|jjr.|jjD] }||jvr-|j|q |jjrG|jjD]|jvrF|jj|j<q6|jjro|jjD]t fdd|j Dsnd|jj}|j |qO|j |r|jj |j |WddS1swYdS|jj |j|WddS1swYdS)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. zCluster specified preset z> but user has also defined a preset. Using user specification.c3rrrPrrrPrQr2rz2SosNode.update_cmd_from_cluster..raN)r, sos_presetrr sos_pluginsrrrsos_plugin_optionsrplugoptscheck_node_is_primarylockset_primary_optionsset_node_options)rLroptionrPr rQupdate_cmd_from_clusters:           " "zSosNode.update_cmd_from_clustercCsJt|jj|_t|jj|_t|jj|_t|jj|_t|jj|_dS)zFrom the global opts configuration, assign those values locally to this node so that they may be acted on individually. N)listr' only_plugins skip_pluginsrrrrSrPrPrQr(>s zSosNode._assign_config_optscsjd}}|r|dt|d}g}dr0jjdkr0|dttjjdrGjjrG|dttjjdrnjj rU|d jj r^|d jj rn|d tjj d rjj r|d td jj jjr|dtd jjdrjjr|dttjjdsdr؈jjdkr|djjjjr|djjdrjjr|djjjjr|d|dtj jjj}jD]}j|}|d|d|r|ndq jrEfddjD}|rE|dtd d d!|Djrfjr\|d"tjn d#jd$j rÇfd%dj D}t!|t!j krt"t#j t#|}d&|d'$j } | r|d(t| |dd |_%&d)j%j'(d*j%d+Sj)rfd,dj)D} t!| t!j)krt"t#j)t#| } d-| d.$| } | r|d/t| j*r?fd0dj*D}t!|t!j*kr-t"t#j*t#|} d1| d2$|}|r?|d3t||dd |_%&d)j%j'(d*j%d+S)4zZUse host facts and compare to the cluster type to modify the sos command if neededr rz --threads=z3.7z--plugin-timeout=z3.8z--allow-system-changesz --no-env-varsz--since=z4.1z--skip-commands=rz --skip-files=z4.2z--cmd-timeout=z4.3z4.2-13rUz--container-runtime=z --namespaces=z4.5.2z--journal-size=z--low-priorityr z--rncs8g|]}|ddr|ddr|qS)rrra)rrfrrrSrPrQ s  z,SosNode.finalize_sos_cmd..z-k css|]}|VqdSrrPrrPrPrQrsz+SosNode.finalize_sos_cmd..z --preset=zRequested to enable preset z" but preset does not exist on nodecg|] }|r|qSrPrrrSrPrQrzRequested plugins z. were requested to be enabled but do not existz--only-plugins=zFinal sos command set to rmNcrrP)rrrSrPrQrrzRequested to skip plugins z%, but plugins are already not enabledz--skip-plugins=cs.g|]}|jvr|r|r|qSrP)rrrrrSrPrQrs zRequested to enable plugins z1, but plugins are already enabled or do not existz--enable-plugins=)+r8determine_sos_labelrrr'threadsrstrplugin_timeoutallow_system_changes no_env_varssince skip_commandsr skip_files cmd_timeoutcontainer_runtime namespaces journal_size low_priorityrreplacerbrur+ sos_bin_pathr9rrrrrwrrrsetr rrrorprr)rLrlabelsos_optsrrir'plugsnot_onlyonlyskipnot_skipskiplnnot_onenablerPrSrQfinalize_sos_cmdIs                $$   zSosNode.finalize_sos_cmdcCsd}||j|7}|jjr||s|jjnd|jj7}|s"dS|d||dr2d}nd}|jdd d|}|d |S) z?Determine what, if any, label should be added to the sos reportrnrNzLabel for sos report set to rz--labelz--namerrra)r,get_node_labelr'r0rwrr%rf)rLr0lcmdrPrPrQrs  zSosNode.determine_sos_labelcCs^|jj}|r ||d}|d}|d|||_|dd|_|jd|jdS)z\Use host facts to determine if we need to change the sos path we are retrieving fromrnrzFinal sos path: /collected_archiveN) r+sos_path_stripr-rfrr4archiverorp)rLrupstriprPrPrQrs  zSosNode.finalize_sos_pathcCsT|dkrdS|dkrd|vrdS|dkrdSt|dkr%|d ddSd |S) Nr>z+sos report process received SIGKILL on noderYsudozsudo attempt failedz4sos report terminated unexpectedly. Check disk spacer zsos exited with code )rrf)rLrcstdoutrPrPrQdetermine_sos_errors  zSosNode.determine_sos_errorc Cs |dzd}d}d}|jjrd|jj}n)|jjrA|js:d|jddd}|j|jj |d|}nd|jj }|rL|j d ||_ |j |j |jj d d d |j d }|d d kr|dD]$}t|drs|}|dr|dd}qg|dr|d}qg|r|jd|t|dkr|jdd|WSt|dkr|jdd|WS|jdd|WS|jdd|WS||d |d}|d|d d|dt|ty|dty}z|d||d |d!}~ww)"z2Run sos report and capture the resulting file pathzGenerating sos report...Frnz--config-file=z/tmp/r=r>z.confrT)rrr}rrr^rr_z*sosreport-*tar*)z sha256 z md5  rYzThe checksum is: rchecksum checksum_typemd5@sha256unknownzError running sos report. rc = z msg = zTimeout exceededz'Exception during sos report execution: zError running sos report: N)rr'r)r*rrrfr?copy_file_to_remote config_filerrerr.rfnmatchr$rrorprrHrwrBr rCr)rLrurJconfig_file_arg remote_configrrrOrPrPrQrs~             zSosNode.execute_sos_commandc Cs|jd}tj||dd}z$||r*|d|d||j||WS| d|dWdSt yS}z| d|d |WYd }~dSd }~ww) z7Copies the specified file from the host to our temp dirr=r>zCopying remote z to local zAttempting to copy remote file %, but it does not exist on filesystemFzFailed to retrieve rN) rrbrurrfrrr? retrieve_filerwrB)rLrudestdirdestrOrPrPrQrW5s  zSosNode.retrieve_filec Csd|}zAt|ddkr|d|dWdS||r=|d|d|}|j|d d }|d d kWS|d |dWdStyf}z|d|d|WYd}~dSd}~ww)z|Removes the spciefied file from the host. This should only be used after we have retrieved the file already rnr=rzRefusing to remove path z0: appears to be incorrect and possibly dangerousFzRemoving file zrm -f Tr|r^rz!Attempting to remove remote file rVzFailed to remove rN)rrfrrwrrrerB)rLrurrerPrPrQ remove_fileDs"  zSosNode.remove_filec Cs|js|jjrz||jWnty|dYdSw|d|j| dz| |j}WntyM}z ||WYd}~dSd}~ww|rc| d|j |j ddd S| d dS) z,Collect the sos report archive from the nodezFailed to make archive readableFzRetrieving sos report from zRetrieving sos report...Nz!Successfully collected sos reportr=r>TzFailed to retrieve sos report)rr'rmake_archive_readabler4rBrCrr%rrWr7rrf)rLrgrOrPrPrQrZs,      zSosNode.retrieve_sosreportcCsX|jdus|jr dSd|jvr|d|jddS||j}|s*|ddSdS)zvRemove the sos report archive from the node, since we have collected it and it would be wasted space otherwiseNr zNode sos report path z/ looks incorrect. Not attempting to remove pathzFailed to remove sos report)r4rrwr[rC)rLremovedrPrPrQremove_sos_archiveps  zSosNode.remove_sos_archivecCsP||jrdD] }||j|rnq |j}|r&|j|dddSdS)zz/Error collecting additional data from primary: ) rr'rr\rBrCrwrWr7rrfr[)rL filenamesfilenamerOrgrZr\rPrPrQcollect_extra_cmds2    zSosNode.collect_extra_cmdcCsHd|}|j|ddd}|ddkrdSd}||||dft)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)rr}r^rz6Exception while making %s readable. Return code was %s)rerCrB)rLfilepathrrr\rPrPrQr\s  zSosNode.make_archive_readable)NNT)F)rrUFFN)5__name__ __module__ __qualname__rRpropertyrFrGr>r]rjrsrHrJrrrZrrrrCrwrrKrrrrrDrrrer rrrrrr r rr(r:rrrHrrWr[rr^rrcr\rPrPrPrQr*st E    (   4   ((   < r)rSrr:rbrshlexr sos.policiesrsos.policies.init_systemsrsos.collector.transports.jujur(sos.collector.transports.control_persistrsos.collector.transports.localrsos.collector.transports.ocr"sos.collector.transports.saltstackr sos.collector.exceptionsr r r r sos.utilitiesrrWrrPrPrPrQs,