uec @swddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl m Z ddlmZmZmZmZmZddlmZmZddlmZddlmZmZdd lmZdd lmZdd l m!Z!d Z"yddl#Z#e$Z%Wne&k ree'Z%nXd dZ(dZ)ie*dZ+de,fdYZ-de-fdYZ.de,fdYZ/dZ0dZ1dZ2de,fdYZ3dZ4dZ5dZ6ie3de4de5de6d ee46Z7d!e,fd"YZ8d#e8fd$YZ9d%e8fd&YZ:dS('i(twith_statementN(tgetpass(tgetpwuid(tImporterHelpert import_modulet shell_outtsos_get_command_outputt is_executable(tIndependentPlugintExperimentalPlugin(t_sos(t SoSOptionst _arg_names(tfill(tprint_(tinputs/var/lib/sos/presetsicCscdddddg}d}x0|dkrM|dkrM|d 7}|d }qWd ||||fS( NtBtKiBtMiBtGiBtTiBiiiig@s%.*f%s((tsizet precisiontsuffixest suffixindex((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytget_human_readable$s  cCs4d|}yt|tSWntk r/dSXdS(Nssos.policies.%s(RtPolicyt ImportErrortNone(tnamet policy_fqname((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt import_policy.s   cCsd|kr|jdSddl}t|j}xM|jD]?}x6t|D](}|jrT|d||dx7|jD])}|jjdr |jdSq WdS(NsActive:itunknown(t splitlineststript startswithtsplit(R2R@tline((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyRAscCst|jjd}xd|D]\}yB|jdd}|jd}i|d6|d6|j| str Generate a command to verify the list of packages given in ``packages`` using the native package manager's verification tool. The command to be executed is returned as a string that may be passed to a command execution routine (for e.g. ``sos_get_command_output()``. :param packages: a string, or a list of strings giving package names to be verified. :returns: a string containing an executable command that will perform verification of the given packages. :returntype: str or ``NoneType`` RMt N(RdRRoRitmaptanyReRp(R2Ratby_regext verify_listtverify_packagest package_listtpackagetf((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytbuild_verify_command8s    (  N(RQRRRSRRcRdReRgRbR3RkRoRrR{RjRRR(((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR`s"       tdesctnotetargstPresetDefaultscBskeZdZdZdZdZeZe Z dZ dZ dddedZ dZdZRS(s"Preset command line defaults. cCs&d|j|j|jt|jfS(seReturn a human readable string representation of this ``PresetDefaults`` object. s!name=%s desc=%s note=%s opts=(%s)(RRRtstrtopts(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt__str__wscCs&d|j|j|jt|jfS(sgReturn a machine readable string representation of this ``PresetDefaults`` object. s6PresetDefaults(name='%s' desc='%s' note='%s' opts=(%s)(RRRtreprR(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt__repr__~sRMcCs(||_||_||_||_dS(stInitialise a new ``PresetDefaults`` object with the specified arguments. :param name: The name of the new preset :param desc: A description for the new preset :param note: Note for the new preset :param opts: Options set for the new preset :returns: The newly initialised ``PresetDefaults`` N(RRRR(R2RRRR((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR3s   cCs|jrtdn|jj}ii|jt6|jt6|t6|j 6}t j j |szt j |ddntt j j||j d}tj||WdQXdS(sWrite this preset to disk in JSON notation. :param presets_path: the directory where the preset will be written. sCannot write built-in presettmodeitwN(tbuiltint TypeErrorRtdictRtDESCRtNOTEtOPTSRtostpathtexiststmakedirstopenR}tjsontdump(R2t presets_pathtodicttpdicttpfile((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytwrites +$cCs#tjtjj||jdS(N(RtunlinkRR}R(R2R((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytdeletesN(RQRRRSRRRRR RR;RRRR3RR(((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyRhs    tnonesDo not load a presets+Use to disable automatically loaded presetsRRRcBseZedZdZdZdZdZdZdZ dZ ie d6Z e ZeZdZd*dZdZd Zd Zeeeed Zd Zd ZdZdZdZdZdZdZ dZ!dZ"dZ#edZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,d Z-d*d!Z.d*ed"Z/d#Z0ed$Z1d%Z2d&Z3d*d'Z4d*d*d*e5d(Z6dd)Z7RS(+soThis command will collect system configuration and diagnostic information from this %(distro)s system. For more information on %(vendor)s visit: %(vendor_url)s 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. %(changes_text)s %(vendor_text)s tUnknownshttp://www.example.com/RMs</usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bintlegacyt/cCsL|jd|_t|_g|_|j||_|jt dS(sJSubclasses that choose to override this initializer should call super() to ensure that they get the required platform bits attached. super(SubClass, self).__init__(). Policies that require runtime tests to construct PATH must call self.set_exec_path() after modifying PATH in their own initializer.N( t _parse_unameRtcase_idR`tpackage_managert_valid_subclassest set_exec_patht _host_sysroottregister_presetstGENERIC_PRESETS(R2R!((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR3s      cCstg|jS(N(RR(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytget_valid_subclassesscCs ||_dS(N(R(R2t subclasses((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytset_valid_subclassesscCs |`dS(N(R(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytdel_valid_subclassesss/list of subclasses that this policy can processcCstS(s| This function is responsible for determining if the underlying system is supported by this policy. (R6(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR&scCs|jS(sH Returns True if sos is running inside a container environment. (t _in_container(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt in_containerscCs|jS(N(R(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt host_sysrootscCsdS(s' Return the OS version N((R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt dist_versionscCsddlm}|S(sb Return the class object of the prefered archive format for this platform i(tTarFileArchive(t sos.archiveR(R2R((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytget_preferred_archivesc Cs|jjdd}|j}|jdj}d}djdtdD}|jdkrd}|r|d|nd}d }nS|jd krd }|rd |nd}|rd |nd}d }n |j}|jd|d|d|d|d|}|j t j |S(s This function should return the filename of the archive without the extension. This uses the policy's name_pattern attribute to determine the name. There are two pre-defined naming patterns - 'legacy' and 'friendly' that give names like the following: legacy - 'sosreport-tux.123456-20171224185433' friendly - 'sosreport-tux-mylabel-123456-2017-12-24-ezcfcop.tar.xz' A custom name_pattern can be used by a policy provided that it defines name_pattern using a format() style string substitution. Usable substitutions are: name - the short hostname of the system label - the label given by --label case - the case id given by --case-id or --ticker-number rand - a random string of 7 alpha characters Note that if a datestamp is needed, the substring should be set in the name_pattern in the format accepted by strftime(). Ruit cmdlineoptsRMcss!|]}tjtjVqdS(N(trandomtchoicetstringtascii_lowercase(t.0tx((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pys ,siRssosreport-{name}{case}{date}s -%Y%m%d%H%M%Stfriendlys*sosreport-{name}{label}{case}{date}-{rand}R|s -%Y-%m-%dRtlabeltcasetdatetrand( tget_local_nameR[RtcommonsRR}tranget name_patterntformattsanitize_filenamettimetstrftime(R2RRRRRtnstr((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytget_archive_names,      cCs|S(N((R2tbinary((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt_get_pkg_name_for_binaryFscCs|}|dkrd|}n|jdry*|j|}|jj|d}Wntk rv}dg}nX|ddgkrd||f}qn|S( Ntgzips%s -2txzRvu0u5u2s%s -T%d(RZRRRjR>(R2tmethodtthreadsRyt xz_packaget xz_versionte((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytget_cmd_for_compress_methodIs    cCs|stjS|S(N(ttempfilet gettempdir(R2t opt_tmp_dir((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt get_tmp_dir[s cCs|jS(N(tdefault_scl_prefix(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytget_default_scl_prefix`scCsHt|dkr@x+|D] }t||jdr|SqWn|dS(Nii(Rpt issubclasstvalid_subclasses(R2tplugin_classestp((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt match_plugincs   cs@tg|j}|r&|tg7}ntfd|DS(sQ Verifies that the plugin_class should execute under this policy c3s|]}t|VqdS(N(R(Rtclass_(t plugin_class(s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pys ts(RRR R(R2Rt experimentalR((Rs9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytvalidate_pluginms cCsdS(s> This function is called prior to collection. N((R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytpre_workwscCsdS(sQ This function is called after the sosreport has been generated. N((R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt post_work}scCs|jj|S(N(RRr(R2Rn((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyRrscCs_tj\}}}}}}||_||_||_|jddk|_||_dS(NitSMP(tplatformtunametsystemthostnameRwR[tsmptmachine(R2RtnodeRwRvRt processor((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyRs    cCs ||_dS(N(R(R2R((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt set_commonsscCs|tjd`` objects specifying the command line defaults. :param presets: dictionary of presets to add or replace :param replace: replace presets rather than merge new presets. N(tpresetstupdate(R2Rtreplace((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyRs cCs5x.|jjD]}||kr|j|SqWdS(sFind a preset profile matching the specified preset string. :param preset: a string containing a preset profile name. :returns: a matching PresetProfile. N(RRER(R2tpresetRF((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt find_presets cCs |jtS(sReturn a ``PresetDefaults`` object matching the runing host. Stub method to be implemented by derived policy classes. :returns: a ``PresetDefaults`` object. (Rt NO_PRESET(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt probe_presetsc Cso|p |j}tjj|s%dSxCtj|D]2}tjj||}t|1}ytj|}Wnt k rw5nXWdQXx|j D]}t |dt }||}t |kr|t nd|_t|kr|tnd|_t|krMx?tD]4}||tkrt|j||t|qqWnt|_||j|tintRBtfindallR]R=(R2RAtpatternttext((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytdefault_runlevels $cCs|jS(N(Rw(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytkernel_versionscCs|jS(N(R(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt host_namescCs|jS(N(R(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt is_kernel_smpscCs|jS(N(R(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytget_archscCs |jS(s)Returns the name usd in the pre_work step(RI(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyRscCstjdd|S(Ns[^-a-z,A-Z.0-9]RM(RBtsub(R2R((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyRscCsHtdddj}g|D]}|jdj^q|_dS(sxObtain a list of loaded kernel modules to reference later for plugin enablement and SoSPredicate checks tlsmodRsiN(RRXR[RYt kernel_mods(R2tlinesR\((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR5scCs|jd}|jr|jnd}|j|_|j|_|j|_|j|_d|_|j r|j ryb|r||_nt t d||_|j s|jr|j |jn|jWqtk r|jqXn|jr|j|_ndS(NRRMsGPlease enter the case id that you are generating this report for [%s]: (RRt upload_urlt upload_usertupload_directoryt upload_passtupload_passwordtupload_archive_nametbatchRRRtuploadtprompt_for_upload_usertprompt_for_upload_passwordRtKeyboardInterrupt(R2t cmdline_optstcaseid((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyRs0                 cCsN|j rJ|j|jkrJd|j}tt||_ndS(sdShould be overridden by policies to determine if a user needs to be provided or not s#Please provide upload user for %s: N(tget_upload_passwordtget_upload_usert _upload_usertget_upload_urlRRRQ(R2R((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyRXs cCs@|j r<|j r<|jr<d|j}t||_ndS(ssShould be overridden by policies to determine if a password needs to be provided for upload or not s+Please provide the upload password for %s: N(RTt_upload_passwordRQR(R2R((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyRYs   cCsd||_|js$|j|_n|js<tdn|j}td|jGH|S(sEntry point for sos attempts to upload the generated archive to a policy or user specified location. Curerntly there is support for HTTPS, SFTP, and FTP. HTTPS uploads are preferred for policy-defined defaults. Policies that need to override uploading methods should override the respective upload_https(), upload_sftp(), and/or upload_ftp() methods and should NOT override this method. In order to enable this for a policy, that policy needs to implement the following: Required: Class Attrs: _upload_url The default location to use. Note these MUST include protocol header _upload_user Default username, if any else None _upload_password Default password, if any else None Optional: Class Attrs: _upload_directory Default FTP server directory, if any Methods: prompt_for_upload_user() Determines if sos should prompt for a username or not. get_upload_user() Determines if the default or a different username should be used get_upload_https_auth() Format authentication data for HTTPS uploads get_upload_url_string() If you want your policy to print a string other than the default URL for your vendor/distro, override this method s;No upload destination provided by policy or by --upload-urlsAttempting upload to %s(RURPR`R>t_determine_upload_typeRtget_upload_url_string(R2R t upload_func((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytupload_archives&    cCsi|jd6|jd6|jd6}|jdj|jkrR||jdjSd|jkrptdn|jjd\}}||jkrtd|n||S(sBased on the url provided, determine what type of upload to attempt. Note that this requires users to provide a FQDN address, such as https://myvendor.com/api or ftp://myvendor.com instead of myvendor.com/api or myvendor.com tftptsftpthttpsRs://s#Must provide protocol in upload URLs(Unsupported or unrecognized protocol: %s( t upload_ftpt upload_sftpt upload_httpsRtupload_protocolRERPR>R[(R2tprotstprotturl((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyRbs   cCs=|s|j}n|s*|j}ntjj||S(s?Formats the user/password credentials using basic auth (R^R]trequeststautht HTTPBasicAuth(R2tusertpassword((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytget_upload_https_auth's cCs|jp|jS(sxHelper function to determine if we should use the policy default upload url or one provided by the user (RPt _upload_url(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR`1scCs |jS(sUsed by distro policies to potentially change the string used to report upload location from the URL to a more human-friendly string (R`(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyRc7scCs|jp|jS(syHelper function to determine if we should use the policy default upload user or one provided by the user (RQR_(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR^=scCs|jp|jS(s}Helper function to determine if we should use the policy default upload password or one provided by the user (RTRa(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR]CscCstdstdnyddl}Wntk rJtdnXt}|sf|j}n|s{|j}n|jjdd}d||f}t |j d d kr|j |d d }n|j |}d dd|j |j g}|j|dd} | d kr(t}n| dkr|j|d d|j |j g} |j| ddd k}|s |jtd|jq nl| dkrtd|jnG| dkrtd|jn"| d kr td|jn|s5|jtd|jnd|j|jf} |j| d|j |j dg} |j| dd} | d kr|jd tS| dkrtd!nW| dkrtd"|jn5| dkrtd#|jntd$|jdS(%sAttempts to upload the archive to an SFTP location. Due to the lack of well maintained, secure, and generally widespread python libraries for SFTP, sos will shell-out to the system's local ssh installation in order to handle these uploads. Do not override this method with one that uses python-paramiko, as the upstream sos team will reject any PR that includes that dependency. RgsSFTP is not locally supportediNsESFTP upload requires python-pexpect, which is not currently installedssftp://RMs%sftp -oStrictHostKeyChecking=no %s@%siitencodingsutf-8usftp>u password:uConnection refusedRsiiuPermission deniedi s%Incorrect username or password for %sis)Connection refused by %s. Incorrect port?is#Timeout hit trying to connect to %ss.Unexpected error trying to connect to sftp: %ss Unable to connect via SFTP to %ss put %s %su100%uNo such file or directoryitbyesTimeout expired while uploadingsUnknown error during upload: %ss)Unable to write archive to destination %ss#Unexpected response from server: %s(RR>tpexpectRR6R^R]R`RRCt __version__tspawntTIMEOUTtEOFtexpectR;tsendlineR@RctbeforeRUt_get_sftp_upload_name(R2RsRtRytsftp_connectedtsftp_urltsftp_cmdtrett sftp_expectstidxt pass_expectstput_cmdt put_expectst put_success((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyRjIs                     cCs|jjddS(sIf a specific file name pattern is required by the SFTP server, override this method in the relevant Policy. Otherwise the archive's name on disk will be used :returns: Filename as it will exist on the SFTP server :rtype: ``str`` Ri(RUR[(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyRscCs%tj|jd|d|jS(sIf upload_https() needs to use requests.put(), use this method. Policies should override this method instead of the base upload_https() Positional arguments: :param archive: The open archive file object R+Rq(RptputR`Ru(R2R ((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt_upload_https_putscCsiS(sJDefine any needed headers to be passed with the POST request here ((R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt_get_upload_headersscCsQi|jjdd||jfd6}tj|jd|d|jS(sIf upload_https() needs to use requests.post(), use this method. Policies should override this method instead of the base upload_https() Positional arguments: :param archive: The open archive file object RitfileRbRq(RR[RRptpostR`Ru(R2R Rb((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt_upload_https_posts c Cststdnt|jd}|jdjdkrL|j}n|jdj}|dkrz|j|}n|j|}|j dkr|j dkr|j dkrtd ntd |j |j fnt SWd QXd S( s=Attempts to upload the archive to an HTTPS location. s7Unable to upload due to missing python requests librarytrbRtautoRiiis/Authentication failed: invalid user credentialssPOST request returned %s: %sN( tREQUESTS_LOADEDR>RRURt upload_methodt_upload_methodRRt status_codetreasonR;(R2tarcRR9((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyRks    c Csayddl}ddl}Wntk r;tdnX|sQ|j}n|dkrltdn|jdd}|s|j}n|s|j}n|s|j p|j }nyA|j |||dd}|std n|j |Wn|j k r*td |n|jk rMtd |n|jk r}t|jd } | d krtd|n| dkrtd|n| dkrtd|ntdt|nXyQt|jd+} |jd|jjdd| WdQX|jtSWntk r\tdnXdS(skAttempts to upload the archive to either the policy defined or user provided FTP location. iNsmissing python ftplib librarysIno FTP server specified by policy, use --upload-url to specify a locationsftp://RMRsis3connection failed, did you set a user and password?s"timeout hit while connecting to %ssunable to connect to %sit503scould not login as '%s't530sinvalid password for user '%s't550s$could not set upload directory to %ss%error trying to establish session: %sRsSTOR %sRscould not open archive file(tftplibtsocketRR>R`RRR^R]RRt_upload_directorytFTPtcwdRstgaierrort error_permRR[RRUt storbinarytquitR;R=( R2RoR RsRtRRtsessionterrterrnot_arcfile((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyRisZ          N(,RQRRRSRRRRR8RvRR_RaRR<RPRQRTR3RRGRHRIRJRKRRR5RRXRYReRbRuR`RcR^R]RjRRRRRkRi(((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR3NsR         & 0     l   (;t __future__RRRBRRRRhRRRRtpwdRt sos.utilitiesRRRRRt sos.pluginsRR R)R RR R ttextwrapR tsixRt six.movesRR1RpR;RRR6RRRR,tobjectR-RTR`RRRRR"tNO_PRESET_DESCtNO_PRESET_NOTERRR'R3(((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytsX         (     b"C