a G%@i@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z ddl m Z ddlmZddlmZddlmZddlmZdd lmZmZdd lmZdd lmZdd lmZdd lm Z dZ!GdddeZ"dS)N)datetime)ThreadPoolExecutor)getpass)Path)quote) SoSCleaner)SosNode) ClusterOption str_to_bool) SoSComponent)bold) __version__) SoSUploadz/etc/sos/groups.dcNseZdZdZdZdddddddgddgggddddddgdd gddddd dd dddgdddddgddgddddddddgggdd d d dddgddddddddddddddddMZfddZddZeddZ eddZ eddZ ddZ eddZ eddZd`d d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9Zd:d;Zdd?Zd@dAZdBdCZ dDdEZ!dFdGZ"dHdIZ#dJdKZ$dLdMZ%dNdOZ&dPdQZ'dRdSZ(dTdUZ)dVdWZ*dXdYZ+dZd[Z,d\d]Z-d^d_Z.Z/S)a SoSCollectora sos collect, or SoS Collector, is the formerly standalone sos-collector project, brought into sos natively in 4.0 and later. It is meant to collect sos reports from an arbitrary number of remote nodes, as well as the localhost, at the same time. These nodes may be either user defined, defined by some clustering software, or both. For cluster defined lists of nodes, cluster profiles exist that not only define how these node lists are generated but may also influence the sos report command run on nodes depending upon their role within the cluster. Nodes are connected to via a 'transport' which defaults to the use of OpenSSH's Control Persist feature. Other transport types are available, and may be specifically linked to use with a certain cluster profile (or, at minimum, a node within a certain cluster type even if that profile is not used). sos collect may be run from either a node within the cluster that is capable of enumerating/discovering the other cluster nodes, or may be run from a user's workstation and instructed to first connect to such a node via the --primary option. If run in the latter manner, users will likely want to use the --no-local option, as by default sos collect will also collect an sos report locally. Users should expect this command to result in a tarball containing one or more sos report archives on the system that sos collect was executed on. z8Collect an sos report from multiple nodes simultaneouslyFautoNTr /etc/sos/cleaner/default_mappingrootiX obfuscate)Mall_logs alloptionsZallow_system_changes become_rootcase_idchrootcleancluster_options cluster_typeZcontainer_runtimedomainsdisable_parsersZenable_pluginsZ encrypt_keyZ encrypt_passgroupZimageZinherit_config_fileZforce_pull_imageskip_cleaning_filesjobsZ journal_sizekeywords keyword_filekeep_binary_fileslabel list_optionslog_sizeZ low_prioritymap_fileprimaryZ namespacesZnode_config_filenodesZ no_env_varsno_local nopasswd_sudoZ no_pkg_check no_updateZ only_pluginspasswordpassword_per_nodeplugoptsZplugin_timeoutZ cmd_timeoutpresetZ registry_userZregistry_passwordZregistry_authfile save_groupZsince skip_commands skip_filesZ skip_pluginsssh_keyZssh_portssh_usertimeout transporttreat_certificatesverify usernamesuploadZ upload_urlZupload_directoryZ upload_userZ upload_passZ upload_methodZupload_no_ssl_verifyZupload_protocolupload_s3_endpointZupload_s3_regionZupload_s3_bucketZupload_s3_access_keyZupload_s3_secret_keyZupload_s3_object_prefixZ upload_targetcsjt|||tdg|_g|_d|_d|_d|_d|_ |j j d|j j j |_|jdd|jdt|jddt|_z$td d ttdD|_Wn$ty|d d g|_Yn0|||_|jjsfzT|| |!d d"ddt#j$D|!d|j%|&Wn t'yd|(ddYn0dS)N?rcollectrnone node_listsudo_pwrcSsh|]}|ddqS)rr.0irErE:/usr/lib/python3.9/site-packages/sos/collector/__init__.py sz(SoSCollector.__init__..zkCould not get a list of IP addresses from this hostnamne. This may indicate a DNS issue in your environmentz 127.0.0.1z Executing  css|] }|VqdSNrE)rGsrErErI z(SoSCollector.__init__..zFound cluster profiles: Exiting on user cancel))super__init__osumask client_listrCr+ retrievedclusterrmanifest components add_sectionrA collect_md add_fieldadd_listsetattroptssocketZ gethostnamehostnamelistZ getaddrinfoip_addrs Exception log_error_parse_options load_clustersclustersr(parse_node_stringsparse_cluster_options log_debugjoinsysargvkeysverify_cluster_optionsKeyboardInterruptexit)selfparserZ parsed_argsZ cmdline_args __class__rErIrSsH       " zSoSCollector.__init__cCsDddl}|jj}i}||d}|D]}|d|j||d<q$|S)zmLoads all cluster types supported by the local installation for future comparison and/or use rNri)Zsos.collector.clustersZ collectorri _load_modulescommons)rtsospackageZsupported_clustersrirXrErErIrhs zSoSCollector.load_clusterscCs2g}|jD]"}tj|r ||||q |S)z'Helper to import cluster and host types)__path__rTpathisdirextend_find_modules_in_path)clsr|Zsubmodmodulesr~rErErIrys   zSoSCollector._load_modulescCsng}tj|rjtt|D]J}|ds.qd|vr8qtj|\}}d|d|}|||q|S)aXGiven a path and a module name, find everything that can be imported and then import it path - the filesystem path of the package modulename - the name of the module in the package E.G. a path of 'clusters', and a modulename of 'ovirt' equates to importing sos.collector.clusters.ovirt z.py__zsos.collector..) rTr~existssortedlistdirendswithsplitextr_import_modules)rr~Z modulenamerZpyfilefname_modnamerErErIrs   z"SoSCollector._find_modules_in_pathc Cs|dd}zt|tt|g}Wn@tyf}z(td|d|jj|WYd}~n d}~00t |tj }| D]}|ddvr~| |q~|S)z/Import and return all found classes in a modulerz"Error while trying to load module z: Nr)ZSosHostCluster) split __import__globalslocals ImportErrorprintrw__name__inspectZ getmembersZisclasscopyremove)rrZmod_short_namemoduleermodrErErIrs    zSoSCollector._import_modulesc Cs|jjs dSg}t|jjts,|jjg|j_|jjD]}ddt|D}|t|d}d}|D]j}zL|}|||}tt |d|vrd|vrWqd|| d|}Wqdtj yYqdYqd0qd|t|kr4|||ddq4||j_dS) arParses the given --nodes option(s) to properly format the regex list that we use. We cannot blindly split on ',' chars since it is a valid regex character, so we need to scan along the given strings and check at each comma if we should use the preceeding string by itself or not, based on if there is a valid regex at that index. NcSsg|]\}}|dkr|qS),rE)rGrHmrErErI rOz3SoSCollector.parse_node_strings..r[]rrx) r`r, isinstancerc enumerateappendlenrecompileescapelstriperror)rtr,nodeZidxsstartposidxZregrErErIrjs0    zSoSCollector.parse_node_stringsc CsV|dd}|jddddd|jddd d|jd dd d d |jddgddd|jdddd|jddddd|jdtddd|jdd d!dd"d#d$|jd%dtd&d'|jd(dd d)d |jd*d+dd,d|jd-d.dgd/d |jd0dd1d|jd2dd d3d |jd4tdd5d|jd6tdd7d|jd8dd9d|jd:gdd;dgdd?d@d=|jdAddBd|dCdD}|jdEdFddGdHd$|jdIdJdK|jdLd ddMdN|jdOtddPd|jdQdRdK|jdSdTdUdVdWdX|jdYddZd|jd[dd\d|jd]d^dK|jd_d`dadbtdcdd|jdeddfd|jdgddhd|jdiddjd|jdkdldmdK|jdndodptdqd'|jdrdsddtd|jdudvdK|jdwdxdydzdd{d||jd}dd~d|jddVdd|jdddd|jdddd|jddtdd|jddd dd |jddd dd |jddd dd|jdddK|jdtd dd|jddtdd'|jddd dd |jdddd|jdddd|jdddd|jdddd|jddgddd|jdd dddN|jdddd|jdddd|jdddd|jdddd|jdddd|jdddd|jddgddd|dd}|jddddd ddd|jdd dddd=|jddgddd|jddgdddƍ|jdddgdddƍ|jddgdddƍ|jdddddэ|jddd dddƍ|jddddd||jddgddd|jddgdޢddddS)NzReport Passthru Optionsz0These options control how report is run on nodesz-az --alloptions store_truezEnable all sos report options)actionhelpz --all-logszCollect logs regardless of sizez--allow-system-changesFz8z<40z<30F)newline)Z set_titleadd_text__doc__itemsr )rsectionZ hsectionsZhsecvaluerErErI display_helps  zSoSCollector.display_helpcCsv|jr|j|r||z |WntyF|dYn0|dkrX||sht|n t |dS)aUsed to terminate and ensure all cleanup is done, setting the exit code as specified if required. :param msg: Log the provided message as an error :type msg: ``str`` :param error: The exit code to use when terminating :type error: ``int`` :param force: Use os.exit() to break out of nested threads if needed :type force: ``bool`` z/Warning: Failed to close all remote connectionsrQN) rXZcleanuprfclose_all_connectionsrelog_warnrnrsrT_exit)rtmsgrforcerErErIrs&s      zSoSCollector.exitcCs8|j|jjdk|jtt|jjt|j|jd|_dS)zxFrom commandline options, defaults, etc... build a set of commons to hand to other collector mechanisms r)Z cmdlineopts need_sudotmpdirhostlenpolicyN) r`r8rmaxrr+rbrrzrtrErErIrgDs  zSoSCollector._parse_optionsc Csg}t|jjts |jjg|j_|jjr|jjD]r}|dd}|dddd}z|ddd}Wntyd}Yn0|t|||j|q0||j_dS)Nrrrx=True) rr`rrcr IndexErrorrr rw)rtr`optionrXnamerrErErIrkPs   z"SoSCollector.parse_cluster_optionscCs|jjr|jjD]T}d}|jD]@\}}|jD]0}|j|jkr0|j|kr0d}||||_q"q0q"q|s| d|jd|jddS)z+Verify that requested cluster options existFTz!Unknown cluster option provided: rrxN) r`rriroptionsrrX_validate_optionrrs)rtoptmatchclustrrrErErIrqes"   z#SoSCollector.verify_cluster_optionscCsl|jtks<|j|jks6d}|||j|j|jfd|jS|j}|dvrdd}|||jd|dvS)aCChecks to make sure that the option given on the CLI is valid. Valid in this sense means that the type of value given matches what a cluster profile expects (str for str, bool for bool, etc). For bool options, this will also convert the string equivalent to an actual boolean value z.Invalid option type for %s. Expected %s got %srx)trueonyesZfalseZoffnozUInvalid value for %s. Accepted values are: 'true', 'false', 'on', 'off', 'yes', 'no'.)rrr)opt_typeboolrsrrlower)rtrZclirvalrErErIrts   zSoSCollector._validate_optioncCs|j|dS)z.Log info messages to both console and log fileN)sosloginfortrrErErIlog_infoszSoSCollector.log_infocCs|j|dS)z.Log warn messages to both console and log fileN)rZwarningrrErErIrszSoSCollector.log_warncCs|j|dS)z/Log error messages to both console and log fileN)rrrrErErIrfszSoSCollector.log_errorcCs0tdd}d|d|}|j|dS)z.Log debug message to both console and log filerxz[sos_collector:z] N)rstackrdebug)rtrZcallerrErErIrlszSoSCollector.log_debugc stjdtjdt|jD]*}tjd|dd|j|jddq"i|jD]X\}}|jD]H}|jvr||j<qj|j D]&}||jj vr|jj |qqjq\tjdtjddd dd d dd d ddddddd tfdddD]l}|}dd ddt|j Dd d|jd d|j j d dt|jd d|jd d }tj|q tjddS)z&Display options for available clustersz; The following clusters are supported by this installation z@Use the short name with --cluster-type or cluster options (-c) rKz<15Z30 z/ The following cluster options are available: rZ25z Option NameZ15Typez<10ZDefaultZ10Z DescriptionrOz+SoSCollector.list_options..keyz z, css|] }|VqdSrLrE)rGcrErErIrNrOz,SoSCollector.list_options..zh Options take the form of cluster.name=value E.G. "ovirt.no-database=True" or "pacemaker.offline=False" N)rnstdoutwriterriZ cluster_namerrrrXrrmrrrr description)rtrXrrrrZ_optZoptlnrErrIr(sD       "  zSoSCollector.list_optionscCst|jdS)z8Removes the temp directory and all collected sos reportsN)shutilrmtreerrrErErIdelete_tmp_dirszSoSCollector.delete_tmp_dirc Csd}|jjr|d|jj7}|jjr8|d|jj7}ttd}z tjt_Wn4t y}z| d|WYd}~n d}~00d ddt d D}|d|d|S) z(Generates a name for the tarball archivez sos-collector-z%Y-%m-%dz#Could not cast to ascii_lowercase: Nrcss|]}ttjVqdSrL)randomchoicestring lowercase)rGrrErErIrNrOz1SoSCollector._get_archive_name..) r`r'rrstrftimeZnowrZascii_lowercaser NameErrorrlrmrange)rtZnstrZdterrZrandrErErI_get_archive_names &zSoSCollector._get_archive_namecCs&||_d}|jd|jd|S)zvReturns the path, including filename, of the tarball we build that contains the collected sos reports gz/z.tar.)rarc_namer)rtZcomprrErErI_get_archive_paths zSoSCollector._get_archive_pathc Cs(|jj}|tjtd|tjt|g}d}|D]}tj|r8|}qRq8|durht d|| d|t |ddd}t |}dD]:}||r| d |d ||d t|j|||q|d r| d |d d|jj|d Wdn1s0YdS)a Attempts to load the host group specified on the command line. Host groups are defined via JSON files, typically saved under /etc/sos/groups.d/, although users can specify a full filepath on the commandline to point to one existing anywhere on the system Host groups define a list of nodes and/or regexes and optionally the primary and cluster-type options. z.config/sos/groups.d/Nzno group definition for zLoading host group rutf-8encoding)r+rzSetting option 'z' to 'z'per host groupr,zAdding to node list)r`r!rTr~rmrhomeCOLLECTOR_CONFIG_DIRrOSErrorrlopenjsonloadr_r,r)rtgrppathsrr~hf_grouprrErErI_load_group_configs,     zSoSCollector._load_group_configcCs|jj|jj|jjdt|jd}tdkrRtj t d}tj |ddnt}tj ||d}t|ddd }t||Wd n1s0Yt|d |S) a Saves the results of this run of sos collect to a host group file on the system so it can be used later on. The host group will save the options primary, cluster_type, and nodes as determined by sos collect prior to execution of sos reports. r)rr+rr,z.config/sos/groups.dT)exist_okrwr r Ni)r`r4r+rXrrcrCrTgetuidr~rmrrmakedirsrrrdumpchmod)rtZcfgZ group_pathrrrErErIwrite_host_groups   * zSoSCollector.write_host_groupc Cs |j|j|jjs>|jjs>|dd}|j| |z|jjsX|jjr|jj r|jj s|dd|jj d}t |d|j_|jdr|jjs|jj s|jjs|jjs|dd |jj d }t |d|j_n|jjs|jj|j_Wn ty|d d Yn0|jjr|jj d ksz|jj rFd}||d|dd|jj d}t |d|j_d|jd<n|dd|j_|jjrz |WnFty}z,d|jjd|}||dWYd}~n d}~00z|jWn ty|dd Yn0|jj r6|d|j_nzd}d}d}|jjstdkr|jjs|jj sd}t |}|dkr|j|d}d|j_d}n|j|d}d|j_td|j||d|_ WnBty}z(|d||ddWYd}~n d}~00|jd |j j |j!d!|jj"!|j j |j #t$|jj"|j j |jj%r|jj%d"kr|j&d#|_'n|j&|jj%|_'|jj%|_%|j |j'_ n|(|j'dur|jj"sd$}||dn2|j'dur|jj"r|d%|j&d#|_'d"|_%|jd&|j%|j'r|j'|j _'|jj)d'krL|j'*|j_)|j'+|j'j,r|jj-s|d(|j'j,d)|j'j,|j_-|.|jj/r|jj/}z"|0}|d*|d+|Wn<ty}z"|1d,|d|WYd}~n d}~00dS)-Nz)password not specified, assuming SSH keyszgsos collect ASSUMES that SSH keys are installed on all nodes unless the --password option is provided. z&password specified, not using SSH keysz"Provide the SSH password for user : )promptrz3non-root user specified, will request sudo passwordz=A non-root user has been provided. Provide sudo password for z on remote nodes: z Exiting on user cancel rQrzkCannot become root without obtaining root password. Do not use --batch if you need to become root remotely.rxz,non-root user asking to become root remotelyzUser z5 will attempt to become root. Provide root password: FzSOption to become root but ssh user is root. Ignoring request to change user on nodezCould not load specified group Exiting on user cancel TzLocal sos report generation forcibly skipped due to lack of root privileges. Either use --nopasswd-sudo, run as root, or do not use --batch so that you will be prompted for a password rz8Enter local sudo password to generate local sos report: r localhost) local_sudoZ load_factsz(Unable to determine local installation: zsUnable to determine local installation. Use the --no-local option if localhost should not be included. Aborting... r+r,rBZjbonzFCluster type could not be determined and no nodes provided Aborting...zCluster type could not be determined, but --nodes is provided. Attempting to continue using JBON cluster type and the node listrrzUpdating SSH key to z per clusterz Wrote group 'z' to zCould not save group )2rZ set_commonsrzr`r0r1rlui_logr_fmt_msgr+batchr8rr.rDrrrsrZ root_passwordrr!rreZpre_workconnect_to_primaryr-rTrrr\r]addressr[r,set_node_manifestgetattrrrirXdetermine_clusterr:Zset_transport_typeZsetupZcluster_ssh_keyr7 get_nodesr4r!rf)rtrrZ can_run_localr&Zskip_local_msggnamerrErErIprep s            "                   zSoSCollector.prepc Cs8|jd|js&|jjs&|dd|jd|jjr|jjdur|jjrV|jj s|j j s|jd|jjd|j dt |jD]$}|jd|d|j dq|jd|jjs4ztd |jdWnRty|d d Yn6ty2}z|t|dWYd}~n d}~00dS) zuPrints a list of nodes to collect from, if available. If no nodes are discovered or provided, abort. rzGNo nodes were detected, or nodes do not have sos installed. Aborting...rxz1The following is a list of nodes to collect from:N rrzC Press ENTER to continue with these nodes, or press CTRL-C to quit rPrQ)r'rrCr+ connectedrsrblocalr`r-rXstrict_node_listrzrr)inputrrrerepr)rtrrrErErI display_nodess0  "   zSoSCollector.display_nodescCsd}i}|jjr t|jj|d<|jjr0d|d<|jjr@d|d<|jjrPd|d<|jjrltt|jj|d<|jjrt|jj|d<|jj rt|jj |d <|jj d krt|jj |d <| D]\}}|d |d |d 7}q| }| d|d|jd<||jd<|jd|dS)z:Configures the sos report command that is run on the nodeszsosreport --batch zcase-idrrzall-logsr<zlog-sizesysrootrrzcompression-typez--rKzInitial sos cmd set to sos_cmd sos_optionsZinitial_sos_cmdN)r`rrrrr<r)rr9rcompression_typerrstriprlrzr\r])rtr:r;kvrErErIconfigure_sos_cmds2   zSoSCollector.configure_sos_cmdc Cstz.t|jj|j|_|jd|jjdWn@tyn}z(|d||ddWYd}~n d}~00dS)zgIf run with --primary, we will run cluster checks again that instead of the localhost. z Connected to z, determining cluster type...z#Failed to connect to primary node: z.Could not connect to primary node. Aborting...rxN) rr`r+rzr'rrerlrs)rtrrErErIr*s zSoSCollector.connect_to_primaryc Cst|j}|jD]}|||j|_|r|jj}|d|d|D]\}t |j|jrT|jj}|d|d|j|_|rT|d|d|d|}qqT||_ | |_ |j |j d<|jd |j qqd S) a@This sets the cluster type and loads that cluster's cluster. If no cluster type is matched and no list of nodes is provided by the user, then we abort. If a list of nodes is given, this is not run, however the cluster can still be run if the user sets a --cluster-type manually zInstallation matches z, checking for layered profileszLayered profile z found. Checking installationz*Installation matches both layered profile z and base profile z), setting cluster type to layered profilerXzCluster type set to N)rcrivaluesrr+Z check_enabledrwrrl issubclassrXrrrzr'r)rtZchecksrXZcnameZ remainingZrnamerErErIr.s6      zSoSCollector.determine_clustercCs(|jr$|j}|d||SgS)z>Collects the list of nodes from the determined cluster clusterz Node list: )rrXZ _get_nodesrl)rtr,rErErIget_nodes_from_cluster%s  z#SoSCollector.get_nodes_from_clustercCs|j|jvr"|jjr"|j|j|jjsL|jD]}||jvr0|j|q0|jdur|jjs|jD]$}||jj|jjfvrd|j|qdt t dd|jD|_| d|j|j d|jdS)zSReduce duplicate entries of the localhost and/or primary node if applicableNcss|]}|r|VqdSrLrErGnrErErIrN<rOz0SoSCollector.reduce_node_list..zNode list reduced to rC)rbrCr`r-rrXr5rdr+rcsetrlr\r^)rtrHrErErErIreduce_node_list-s   zSoSCollector.reduce_node_listc Cst|jjD]f}z"t|}t||r,WdSWqtjyl}z$d}|||||fWYd}~qd}~00qdS)zCompares a discovered node name to a provided list of nodes from the user. If there is not a match, the node is removed from the listTz0Error comparing %s to provided node regex %s: %sNF)r`r,fnmatch translaterrrrl)rtrZregexrrrErErIcompare_node_to_regex@s    ,z"SoSCollector.compare_node_to_regexc s|js|jsd}||dz<|}|jjrP|D]|r2|jq2n||_Wnvt y}z^| d|| d|jj|_|jD]&t fdddDr|j qWYd}~n d}~00|jjr(|jjD]Dt fd dd Drq|jvr| d d |jq|js|j d d}|jD]&|d dkrF|j qF|jjs|j|j |z,tt|jtd}t||jd|jd<Wn:ttfy}z| d|WYd}~n d}~00dS)z4 Sets the list of nodes to collect sos reports from zaCould not determine a cluster type and no list of nodes or primary node was provided. Aborting...rxzError parsing node list: z#Setting node list to --nodes optionc3s|]}|vVqdSrLrErFrrErIrNbrOz)SoSCollector.get_nodes..)*\?()rNc3s|]}|vVqdSrLrErFrKrErIrNhrOz*\?()/[]z Force adding rrrrrzCould not set UI spacing: )r+rXrsrCr`r,rJrCrrerlanyrrbrr5rGrrrz TypeError ValueError)rtrr,rhostZ _node_maxrrErKrIr/MsJ       $     zSoSCollector.get_nodescCsznt|d|j|dd}||j|jrd|j||jj |d| t |jj|dn| Wnt yYn0dS)zTry to connect to the node, and if we can add to the client list to run sos report on Positional arguments node - a tuple specifying (address, password). If no password, set to None rrx)r0N)rrzZ set_clusterrXr3rVrr\r,r[r,r- disconnectre)rtrclientrErErI_connect_to_node}s     zSoSCollector._connect_to_nodec Csd}|jdtd|||j}|j|d}|jjszt||jdWnLtyv| ddYn0t y}z| |dWYd }~n d }~00d S) zmPrint the intro message and prompts for a case ID if one is not provided on the command line ahThis utility is used to collect sos reports from multiple nodes simultaneously. Remote connections are made and/or maintained to those nodes via well-known transport protocols such as SSH. An archive of sos report tarballs collected from the nodes will be generated in %s and may be provided to an appropriate support representative. The generated archive may contain data considered sensitive and its content should be reviewed by the originating organization before being passed to any third party. No configuration changes will be made to the system running this utility or remote systems that it connects to. z sos collect (version z) z, Press ENTER to continue, or CTRL-C to quit rrPrQrxN) r'rr r(rr`r)r6rrrsre)rtZ disclaimerZ intro_msgr#rrErErIintros  zSoSCollector.introcCs|jjr||||jjr<|jjr<|dd|||| |_ |j |j d|j |_|j dd||dS)Nz sos-collector was called with incompatible options --batch and --password. If you need to use --password, please omit batch mode. rx)rsos_logsi)r`r(rsrXr)r0r@r1r8r archive_nameZ setup_archivearchiveZget_archive_path archive_pathrrArrErErIexecutes$  zSoSCollector.executec sTt|jj|jjg|jjrBt|js4|jjsB|j |j|j dfdd|jD}|j jrg}|D]8}d|j jd|dd}t|}| |d|fqr|}zt|j j}|j|j|dd |jd d |j jr|j djd kr|j dt|j |_|jdkr,|d dn*|jdkrV|j djd krV|dd|j d|jd|j jdt|j j}|j|j|j dd |jd d t|j j}|j|j|j dd |jd d Wnbty|jddd dYn@ty2}z&d|}|j|dd dWYd}~n d}~00t|jdrj|j d|j } | rj|j!| d}|"||j#|jf|$|j#dkr|%|_&nd}||d|j j's|j j(rPzN|j)|j*|j+|j |j,d} t-|j.|j/|j0d | |j&d} | 1|j dWn8tyN}z|j 2d|WYd}~n d}~00dS)zY For each node, start a collection thread and then tar all collected sos reports z Connecting to nodes...csg|]}|vr|dfqSrLrErDfiltersrErIrrOz(SoSCollector.collect..zPlease enter the password for @rr"rx)Z chunksizeT)waitr%zNo nodes connected. Aborting...zCollection would only gather from localhost due to failure to either enumerate or connect to cluster nodes. Assuming single collection from localhost is not desired. Aborting...z* Beginning collection of sos reports from z nodes, collecting a maximum of z concurrently r$rQ)rzCould not connect to nodes: NZ run_extra_cmdz/Collecting additional data from primary node...z+ Successfully captured %s of %s sos reportsz4No sos reports were collected, nothing to archive...rrsys_tmprrY)ruargscmdlinein_place hook_commonsr[zUploaded archive successfullyzUpload attempt failed: )3rFr+r+rbr3 intersectionrCrXr5rVrr'rr`r1r8rrr#maprWZshutdownr-poprZ report_numrs_finalize_sos_cmd_collectrrrehasattrZ_run_extra_cmdZcollect_extra_cmdrrWrcreate_cluster_archiver r>r?rrrcrYrrurdrer]r) rtr,Z_nodesrrZnode_pwdZpoolZnpoolrfilesrgZuploaderrEr^rIrAs              &       zSoSCollector.collectc CsNz |Wn<tyH}z$|d|jd|WYd}~n d}~00dS)zCalls finalize_sos_cmd() on each node so that we have the final command before we thread out the actual execution of sos z#Could not finalize sos command for r"N)Zfinalize_sos_cmdrerfr+rtrVrrErErIrk4s zSoSCollector._finalize_sos_cmdc Csrz8|js|n|jjs"||jr6|jd7_Wn4tyl}z|d|WYd}~n d}~00dS)zRuns sos report on each noderxzError running sos report: N)r4Z sosreportr`r-rWrerfrprErErIrl>s zSoSCollector._collectcCs0|jD]$}|jr|d|j|qdS)zClose all sessions for nodeszClosing connection to N)rVr3rlr+rU)rtrVrErErIrKs z"SoSCollector.close_all_connectionsc Csd}g}|jD]}|jD]}||qqd}|jjr|j|j|j|j|jd}z8|j dt d|d}| |j| \}}d}Wn6ty}z|j d|WYd}~n d}~00z |d|D]}|d d } |r|| } tj|j|} |jj| | d |r||} | rtjd |d d } | d 7} |j| | q|jj|jtjddd |jj|jtjddd |jdur|j|jj||r tj|j|jj} | tj| dd| tj| dd| tj| dd|jj!dd} tj|jtj"| }|rJ||#dd}t$| ||r|tj|j|j%d}t$|||j d||j& d||j d|j d|d|WSty}z,d|d|j'}|(|dWYd}~dSd}~00dS) zcCalls for creation of tar archive then cleans up the temporary files created by sos collectNFrbrT)rfrgz$ERROR: unable to obfuscate reports: z"Creating archive of sos reports...r)rZ checksumsz.sha256rYzsos.logzui.logZ sos_reportsz manifest.json)methodz.tarz-obfuscated.tarZ _private_mapz2A mapping of obfuscated elements is available at zArchive created as zP The following archive has been created. Please provide it to your support team.r2rzCould not finalize archive: z. Data may still be available uncompressed at rz Archive error))rVZ file_listrr`rrrrcrYr'rrZset_target_pathr]rerrrZobfuscate_stringrTr~rmr[Zadd_fileZget_new_checksumZ add_stringZ sos_log_fileZsos_ui_log_fileZadd_final_manifest_datar<Z_obfuscate_upload_passwords_nameZobfuscate_filefinalizebasenamereplacerenamerZrr\rs)rtr*Z arc_pathsrTrZdo_cleanrgZcleanerrrrZchecksumZ_dirr  final_nameZmap_namerrErErIrnRs     (               z#SoSCollector.create_cluster_archive)NrF)0r __module__ __qualname__rZdescZ arg_defaultsrSrh classmethodryrrrjrrrsrgrkrqrrrrfrlr(rrr rr!r1r8r@r*r.rCrGrJr/rWrXr]rArkrlrrn __classcell__rErErvrIr(sP 2    ! j   (&  % 0!e  r)#rHrrrTrrrrarrnrconcurrent.futuresrrpathlibrZshlexrZ sos.cleanerrZsos.collector.sosnoderZ sos.optionsr r Z sos.componentr Z sos.utilitiesr r{r Z sos.uploadrrrrErErErI s.