a >h@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.dcMseZdZdZdZdddddddgddgggddddddgdd gddddd dd dddgdddddgddgddddddddgggdd d d ddgddddddddddddddddLZfddZddZeddZ eddZ eddZ ddZ eddZ eddZd_dd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Zd;d<Zd=d>Zd?d@ZdAdBZ dCdDZ!dEdFZ"dGdHZ#dIdJZ$dKdLZ%dMdNZ&dOdPZ'dQdRZ(dSdTZ)dUdVZ*dWdXZ+dYdZZ,d[d\Z-d]d^Z.Z/S)` 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)Lall_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 transportverify 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.0irCrC:/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|] }|VqdSNrC)rEsrCrCrG z(SoSCollector.__init__..zFound cluster profiles: Exiting on user cancel))super__init__osumask client_listrAr* retrievedclusterrmanifest components add_sectionr? 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__rCrGrQsH       " 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 rNrg)Zsos.collector.clustersZ collectorrg _load_modulescommons)rrsospackageZsupported_clustersrgrVrCrCrGrfs zSoSCollector.load_clusterscCs2g}|jD]"}tj|r ||||q |S)z'Helper to import cluster and host types)__path__rRpathisdirextend_find_modules_in_path)clsrzZsubmodmodulesr|rCrCrGrws   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..) rRr|existssortedlistdirendswithsplitextr~_import_modules)rr|Z modulenamerZpyfilefname_modnamerCrCrGrs   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 ImportErrorprintru__name__inspectZ getmembersZisclasscopyremove)rrZmod_short_namemoduleermodrCrCrGrs    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),rC)rErFmrCrCrG rMz3SoSCollector.parse_node_strings..r[]rrv) r^r+ isinstancera enumerateappendlenrecompileescapelstriperror)rrr+nodeZidxsstartposidxZregrCrCrGrhs0    zSoSCollector.parse_node_stringsc Cs>|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||jddgddddS)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 hsectionsZhsecvaluerCrCrG 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 connectionsrON) rVZcleanuprdclose_all_connectionsrclog_warnrlrqrR_exit)rrmsgrforcerCrCrGrqs      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^r7rmaxrr*r`rrxrrrCrCrGre:s  zSoSCollector._parse_optionsc Csg}t|jjts |jjg|j_|jjr|jjD]r}|dd}|dddd}z|ddd}Wntyd}Yn0|t|||j|q0||j_dS)Nrrrv=True) rr^rrar IndexErrorrr ru)rrr^optionrVnamerrCrCrGriFs   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: rrvN) r^rrgroptionsrrV_validate_optionrrq)rroptmatchclustrrrCrCrGro[s"   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 %srv)trueonyesZfalseZoffnozUInvalid value for %s. Accepted values are: 'true', 'false', 'on', 'off', 'yes', 'no'.)rrr)opt_typeboolrqrrlower)rrrZclirvalrCrCrGrjs   zSoSCollector._validate_optioncCs|j|dS)z.Log info messages to both console and log fileN)sosloginforrrrCrCrGlog_infoszSoSCollector.log_infocCs|j|dS)z.Log warn messages to both console and log fileN)rZwarningrrCrCrGrszSoSCollector.log_warncCs|j|dS)z/Log error messages to both console and log fileN)rrrrCrCrGrdszSoSCollector.log_errorcCs0tdd}d|d|}|j|dS)z.Log debug message to both console and log filervz[sos_collector:z] N)rstackrdebug)rrrZcallerrCrCrGrjszSoSCollector.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) rIz<15Z30 z/ The following cluster options are available: rZ25z Option NameZ15Typez<10ZDefaultZ10Z DescriptionrMz+SoSCollector.list_options..keyz z, css|] }|VqdSrJrC)rEcrCrCrGrLrMz,SoSCollector.list_options..zh Options take the form of cluster.name=value E.G. "ovirt.no-database=True" or "pacemaker.offline=False" N)rlstdoutwriterrgZ cluster_namerrrrVrrkrrrr description)rrrVrrrrZ_optZoptlnrCrrGr'sD       "  zSoSCollector.list_optionscCst|jdS)z8Removes the temp directory and all collected sos reportsN)shutilrmtreerrrCrCrGdelete_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|]}ttjVqdSrJ)randomchoicestring lowercase)rErrCrCrGrLrMz1SoSCollector._get_archive_name..) r^r&rrstrftimeZnowrZascii_lowercaser NameErrorrjrkrange)rrZnstrZdterrZrandrCrCrG_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)rrZcomprrCrCrG_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 rRr|rkrhomeCOLLECTOR_CONFIG_DIRrOSErrorrjopenjsonloadr]r+r~)rrgrppathsrr|hf_grouprrCrCrG_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^r3r*rVrrarArRgetuidr|rkrrmakedirsrrrdumpchmod)rrZcfgZ group_pathrrrCrCrGwrite_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 rOrzkCannot become root without obtaining root password. Do not use --batch if you need to become root remotely.rvz,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+r@ZjbonzFCluster 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_commonsrxr^r/r0rjui_logr_fmt_msgr*batchr7rr-rBrprqrZ root_passwordrr rrcZpre_workconnect_to_primaryr,rRrrrZr[addressrYr+set_node_manifestgetattrrrgrVdetermine_clusterr9Zset_transport_typeZsetupZcluster_ssh_keyr6 get_nodesr3rrd)rrrrZ can_run_localr$Zskip_local_msggnamerrCrCrGpreps            "                   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...rvz1The following is a list of nodes to collect from:N rrzC Press ENTER to continue with these nodes, or press CTRL-C to quit rNrO)r%rrAr* connectedrqr`localr^r,rVstrict_node_listrxrr'inputrprcrepr)rrrrrCrCrG 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--rIzInitial sos cmd set to sos_cmd sos_optionsZinitial_sos_cmdN)r^rrrrr:r(rr7rcompression_typerrstriprjrxrZr[)rrr8r9kvrCrCrGconfigure_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...rvN) rr^r*rxr%rrcrjrq)rrrrCrCrGr(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 profilerVzCluster type set to N)rargvaluesrr*Z check_enabledrurrj issubclassrVrrrxr%r)rrZchecksrVZcnameZ remainingZrnamerCrCrGr,s6      zSoSCollector.determine_clustercCs(|jr$|j}|d||SgS)z>Collects the list of nodes from the determined cluster clusterz Node list: )rrVZ _get_nodesrj)rrr+rCrCrGget_nodes_from_clusters  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|VqdSrJrCrEnrCrCrGrL2rMz0SoSCollector.reduce_node_list..zNode list reduced to rA)r`rAr^r,rrVr3rbr*rasetrjrZr\)rrrFrCrCrCrGreduce_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 translaterrrrj)rrrZregexrrrCrCrGcompare_node_to_regex6s    ,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...rvzError parsing node list: z#Setting node list to --nodes optionc3s|]}|vVqdSrJrCrDrrCrGrLXrMz)SoSCollector.get_nodes..)*\?()rNc3s|]}|vVqdSrJrCrDrIrCrGrL^rMz*\?()/[]z Force adding r rrrrzCould not set UI spacing: )r*rVrqrAr^r+rHrArrcrjanyrr`rr3rErrrx TypeError ValueError)rrrr+rhostZ _node_maxrrCrIrGr-CsJ       $     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 rrv)r/N)rrxZ set_clusterrVr1rTrrZr+rYr*r+ disconnectrc)rrrclientrCrCrG_connect_to_nodess     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 rrNrOrvN) r%rr r&rr^r'r4rprqrc)rrZ disclaimerZ intro_msgr!rrCrCrGintros  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. rv)rsos_logsi)r^r'rqrVr'r/r>r/r6r archive_nameZ setup_archivearchiveZget_archive_path archive_pathrr?rrCrCrGexecutes$  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|dfqSrJrCrBfiltersrCrGrrMz(SoSCollector.collect..zPlease enter the password for @rr rv)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"rO)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_tmprrW)rsargscmdlinein_place hook_commonsrYzUploaded archive successfullyzUpload attempt failed: )3rDr*r)r`r1 intersectionrArVr3rTrr%rr^r0r7rrr"maprUZshutdownr,poprZ report_numrq_finalize_sos_cmd_collectrprchasattrZ_run_extra_cmdZcollect_extra_cmdrrUrcreate_cluster_archiverr<r=rrrarWrrsrbrcr[r) rrr+Z_nodesrrZnode_pwdZpoolZnpoolrfilesreZuploaderrCr\rGr?s              &       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_cmdrcrdr)rrrTrrCrCrGri*s zSoSCollector._finalize_sos_cmdc Csrz8|js|n|jjs"||jr6|jd7_Wn4tyl}z|d|WYd}~n d}~00dS)zRuns sos report on each nodervzError running sos report: N)r2Z sosreportr^r,rUrcrdrnrCrCrGrj4s zSoSCollector._collectcCs0|jD]$}|jr|d|j|qdS)zClose all sessions for nodeszClosing connection to N)rTr1rjr)rS)rrrTrCrCrGrAs 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 collectNFr`rT)rdrez$ERROR: unable to obfuscate reports: z"Creating archive of sos reports...r)rZ checksumsz.sha256rWzsos.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.r0rzCould not finalize archive: z. Data may still be available uncompressed at rz Archive error))rTZ file_listrr^rrrrarWr%rrZset_target_pathr[rcrrrZobfuscate_stringrRr|rkrYZadd_fileZget_new_checksumZ add_stringZ sos_log_fileZsos_ui_log_fileZadd_final_manifest_datar:Z_obfuscate_upload_passwords_nameZobfuscate_filefinalizebasenamereplacerenamerXrrZrq)rrr)Z arc_pathsrRrZdo_cleanreZcleanerrrrZchecksumZ_dirr final_nameZmap_namerrCrCrGrlHs     (               z#SoSCollector.create_cluster_archive)NrF)0r __module__ __qualname__rZdescZ arg_defaultsrQrf classmethodrwrrrhrrrqrerirorrrrdrjr'rrrrrr/r6r>r(r,rArErHr-rUrVr[r?rirjrrl __classcell__rCrCrtrGr(sO 2    ! a   (&  % 0!e  r)#rFrrrRrrrr_rrlrconcurrent.futuresrrpathlibrZshlexrZ sos.cleanerrZsos.collector.sosnoderZ sos.optionsr r Z sos.componentr Z sos.utilitiesr ryr Z sos.uploadrrrrCrCrCrG s.