Current File : //usr/lib/python2.7/site-packages/sos/policies/__init__.pyc
�
u��ec
@�swddlmZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddlm
Z
ddlmZmZmZmZmZddlmZmZddlmZddlmZmZdd	lmZdd
lmZddl m!Z!dZ"yddl#Z#e$Z%Wne&k
ree'Z%nXd
d�Z(d�Z)ie*d�Z+de,fd��YZ-de-fd��YZ.de,fd��YZ/dZ0dZ1dZ2de,fd��YZ3dZ4dZ5dZ6ie3de4de5de6d e��e46Z7d!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/presetsicC�scdddddg}d}x0|dkrM|dkrM|d	7}|d
}qWd||||fS(NtBtKiBtMiBtGiBtTiBiiiig�@s%.*f%s((tsizet	precisiontsuffixestsuffixindex((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytget_human_readable$s
cC�s4d|}yt|t�SWntk
r/dSXdS(Nssos.policies.%s(RtPolicytImportErrortNone(tnamet
policy_fqname((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt
import_policy.s


cC�s�d|kr|jd�Sddl}t|j�}xM|j�D]?}x6t|�D](}|j�rT|d|�|d<qTqTWqAWd|kr�t�|d<n|dS(Ntpolicyi����tsysroot(tgettsos.policiesRtpoliciestget_modulesRtcheckt
GenericPolicy(tcacheR!tsosthelpertmoduleR ((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytload6s
t
InitSystemcB�sqeZdZdddd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
RS(s�Encapsulates an init system to provide service-oriented functions to
    sos.

    This should be used to query the status of services, such as if they are
    enabled or disabled on boot, or if the service is currently running.
    cC�sNi|_||_d|j|fp(d|_d|j|fpDd|_dS(Ns%s %s(tservicestinit_cmdRtlist_cmdt	query_cmd(tselfR/R0R1((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt__init__Os		cC�s1|jr-||jkr-|j|ddkStS(s'Check if given service name is enabled tconfigtenabled(R.tFalse(R2R((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt
is_enabledWscC�s1|jr-||jkr-|j|ddkStS(s*Check if a given service name is disabled R4tdisabled(R.R6(R2R((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytis_disabled]scC�s
||jkS(syChecks if the given service name exists on the system at all, this
        does not check for the service status
        (R.(R2R((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt
is_servicecscC�stS(s�Checks if the given service name is in a running state.

        This should be overridden by initsystems that subclass InitSystem
        (tTrue(R2R((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt
is_runningis	cC�sdS(s�This loads all services known to the init system into a dict.
        The dict should be keyed by the service name, and contain a dict of the
        name and service status
        N((R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytload_all_servicestscC�s@|jr<ytd|j|f�SWq<tk
r8dSXndS(sQuery an individual services%s %sN(R1Rt	ExceptionR(R2R((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt_query_service{s	
cC�s|S(s�Parses the output returned by the query command to make a
        determination of what the state of the service is

        This should be overriden by anything that subclasses InitSystem
        ((R2toutput((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytparse_query�scC�sDtj|tj�}g|jj�D]}|j|�r%|^q%S(s`Get a list of all services discovered on the system that match the
        given regex.
        (tretcompiletIR.tkeystmatch(R2tregextregts((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytget_service_names�scC�s�i|d6dd6dd6}||jkr.|Sd|j|krL|j|S|j|�}|dk	r�|j|d�|j|d<|d|j|d<|j|S|S(siReturns the status for the given service name along with the output
        of the query command
        RtmissingtstatustR@N(R.R?RRA(R2Rt_defaulttsvc((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytget_service_status�s
N(t__name__t
__module__t__doc__RR3R7R9R:R<R=R?RARJRP(((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR-Gs									tSystemdInitcB�s,eZd�Zd�Zd�Zd�ZRS(cC�s3tt|�jdddddd�|j�dS(NR/t	systemctlR0slist-unit-files --type=serviceR1RL(tsuperRTR3R=(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR3�s
cC�s>x7|j�D])}|j�jd�r
|j�dSq
WdS(NsActive:itunknown(t
splitlineststript
startswithtsplit(R2R@tline((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyRA�scC�s�t|j�j�d}xd|D]\}yB|jd�d}|j�d}i|d6|d6|j|<Wq tk
r{q Xq WdS(Nis.serviceiRR4(RR0RXR[R.t
IndexError(R2tsvcsR\RR4((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR=�s

cC�s|j|�}|ddkS(NRLtactive(RP(R2RRO((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR<�s(RQRRR3RAR=R<(((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyRT�s			
tPackageManagercB�s�eZdZdZdZdZdZdZdddddd�Z	d�Z
dd�Zd�Zd�Z
d�Zd�Zd	�Zd
�ZRS(sAEncapsulates a package manager. If you provide a query_command to the
    constructor it should print each package on the system in the following
    format::

        package name|package.version

    You may also subclass this class and provide a get_pkg_list method to
    build the list of packages and versions.
    cC�s|i|_g|_|r|nd|_|r3|nd|_|rH|nd|_|r]|nd|_|rx||_ndS(N(tpackagestfilesRt
query_commandtverify_commandt
verify_filtert
files_commandtchroot(R2RgRcRdReRf((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR3�s		cC�stj|j�j�|�S(s<
        Return a list of packages that match name.
        (tfnmatchtfiltertall_pkgsRE(R2R((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytall_pkgs_by_name�sicC�sDtj||�}g|j�j�D]}|j|�r%|^q%S(sB
        Return a list of packages that match regex_name.
        (RBRCRjRERF(R2t
regex_nametflagsRHtpkg((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytall_pkgs_by_name_regex�scC�s:|j|�}t|�dkr2|j|�dSdSdS(s<
        Return a single package that matches name.
        ii����N(RktlenR(R2Rt
pkgmatches((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytpkg_by_name�scC�s
|jr|j}t|ddd|j�j�}x�|D]�}d|krRq:nc|jd�dkr�|jd�\}}d}n0|jd�dkr�|jd�\}}}ni|d6|jd�d	6|j|<|r�|nd}||j|d
<q:Wn|jS(s�Returns a dictionary of packages in the following
        format::

            {'package_name': {'name': 'package_name',
                              'version': 'major.minor.version'}}

        ttimeoutiRgt|iiRt.tversiontreleaseN(RcRRgRXtcountR[RRa(R2tcmdtpkg_listRnRRvRw((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytget_pkg_lists$		
	cC�s"|js|j�|_n|jS(s0
        Return a list of all packages.
        (RaR{(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyRj s	cC�sE|jd�}|d\}}}dj|d �}||||fS(Nt-i����(R[tjoin(R2RntfieldsRvRwtarchR((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytpkg_nvra(scC�sP|jrI|jrI|j}t|ddd|j�}|j�|_n|jS(sF
        Returns a list of files known by the package manager
        RsiRg(RfRbRRgRX(R2RyRb((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt	all_files.s
	cC�s�|js
dS|j}tdt||��}|s8dSd}xp|D]h}x_|D]W}tg|jD]}||k^qe�r�qRnt|�r�|d7}n||7}qRWqEW|jd|S(s�build_verify_command(self, packages) -> 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_regextverify_listtverify_packagestpackage_listtpackagetf((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytbuild_verify_command8s		

(
N(RQRRRSRRcRdReRgRbR3RkRoRrR{RjR�R�R�(((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR`�s"			
				
tdesctnotetargstPresetDefaultscB�skeZdZdZdZdZe�Ze	Z
d�Zd�Zddde�d�Z
d�Zd�ZRS(s"Preset command line defaults.
    cC�s&d|j|j|jt|j�fS(seReturn a human readable string representation of this
            ``PresetDefaults`` object.
        s!name=%s desc=%s note=%s opts=(%s)(RR�R�tstrtopts(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt__str__wscC�s&d|j|j|jt|j�fS(sgReturn a machine readable string representation of this
            ``PresetDefaults`` object.
        s6PresetDefaults(name='%s' desc='%s' note='%s' opts=(%s)(RR�R�treprR�(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt__repr__~sRMcC�s(||_||_||_||_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(RR�R�R�(R2RR�R�R�((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR3�s
			cC�s�|jrtd��n|jj�}ii|jt6|jt6|t6|j	6}t
jj|�szt
j
|dd�ntt
jj||j	�d��}tj||�WdQXdS(s�Write this preset to disk in JSON notation.

            :param presets_path: the directory where the preset will be
                                 written.
        sCannot write built-in presettmodei�twN(tbuiltint	TypeErrorR�tdictR�tDESCR�tNOTEtOPTSRtostpathtexiststmakedirstopenR}tjsontdump(R2tpresets_pathtodicttpdicttpfile((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytwrite�s	+$cC�s#tjtjj||j��dS(N(R�tunlinkR�R}R(R2R�((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytdelete�sN(RQRRRSRRR�R�RR�R;R�R�R�R3R�R�(((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR�hs				tnonesDo not load a presets+Use to disable automatically loaded presetsRR�RcB�s�eZed�ZdZdZdZdZdZdZ	dZ
ie�d6Ze
ZeZdZd*d�Zd�Zd	�Zd
�Zeeeed�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d�Z"d�Z#ed�Z$d�Z%d�Z&d�Z'd�Z(d�Z)d�Z*d�Z+d�Z,d �Z-d*d!�Z.d*ed"�Z/d#�Z0ed$�Z1d%�Z2d&�Z3d*d'�Z4d*d*d*e5�d(�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/cC�sL|j�d|_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__.pyR3�s
		
	cC�stg|jS(N(RR�(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytget_valid_subclasses�scC�s
||_dS(N(R�(R2t
subclasses((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytset_valid_subclasses�scC�s
|`dS(N(R�(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytdel_valid_subclasses�ss/list of subclasses that this policy can processcC�stS(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&�scC�s|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_container�scC�s|jS(N(R�(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pythost_sysroot�scC�sdS(s'
        Return the OS version
        N((R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytdist_versionscC�sddlm}|S(sb
        Return the class object of the prefered archive format for this
        platform
        i����(tTarFileArchive(tsos.archiveR�(R2R�((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytget_preferred_archivescC�s|j�jd�d}|j}|jdj}d}djd�td�D��}|jdkr�d}|r|d|nd}d	}nS|jd
kr�d}|r�d|nd}|r�d|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().

        RuitcmdlineoptsRMcs�s!|]}tjtj�VqdS(N(trandomtchoicetstringtascii_lowercase(t.0tx((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pys	<genexpr>,siR�ssosreport-{name}{case}{date}s
-%Y%m%d%H%M%Stfriendlys*sosreport-{name}{label}{case}{date}-{rand}R|s	-%Y-%m-%dRtlabeltcasetdatetrand(tget_local_nameR[R�tcommonsR�R}trangetname_patterntformattsanitize_filenamettimetstrftime(R2RR�R�R�R�tnstr((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytget_archive_names,						cC�s|S(N((R2tbinary((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt_get_pkg_name_for_binaryFscC�s�|}|dkrd|}n|jd�r�y*|j|�}|jj�|d}Wntk
rv}dg}nX|ddgkr�d||f}q�n|S(	Ntgzips%s -2txzRvu0u5u2s%s -T%d(RZR�R�RjR>(R2tmethodtthreadsRyt
xz_packaget
xz_versionte((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytget_cmd_for_compress_methodIs

cC�s|stj�S|S(N(ttempfilet
gettempdir(R2topt_tmp_dir((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytget_tmp_dir[s
cC�s|jS(N(tdefault_scl_prefix(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytget_default_scl_prefix`scC�sHt|�dkr@x+|D] }t||jd�r|SqWn|dS(Nii(Rpt
issubclasstvalid_subclasses(R2tplugin_classestp((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytmatch_plugincs

c�s@tg|j}|r&|tg7}nt�fd�|D��S(sQ
        Verifies that the plugin_class should execute under this policy
        c3�s|]}t�|�VqdS(N(R�(R�tclass_(tplugin_class(s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pys	<genexpr>ts(RR�R	R�(R2R�texperimentalR�((R�s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytvalidate_pluginms
cC�sdS(s>
        This function is called prior to collection.
        N((R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytpre_workwscC�sdS(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}scC�s|jj|�S(N(R�Rr(R2Rn((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyRr�scC�s_tj�\}}}}}}||_||_||_|j�ddk|_||_dS(NitSMP(tplatformtunametsystemthostnameRwR[tsmptmachine(R2R�tnodeRwRvR�t	processor((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR��s			cC�s
||_dS(N(R�(R2R�((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytset_commons�scC�s|tjd<dS(NtPATH(R�tenviron(R2R�((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt	_set_PATH�scC�s|j|j�dS(N(R�R�(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR��scC�stj�dkS(seThis method should return true if the user calling the script is
        considered to be a superuseri(R�tgetuid(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytis_root�scC�sdS(sRReturns the string name of the hashlib-supported checksum algorithm
        to usetmd5((R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytget_preferred_hash_name�scC�s�|r|rtS|j�|r�|jtd�|dt�|jtd�t|j��|jtd�t|j�j�n|jtd�|dt�|r�|jd|j	�d|�|j�|jtd��n|j�dS(	Ns5Your sosreport has been generated and saved in:
  %s
talwayss Size	%ss	 Owner	%ss6Your sosreport build tree has been generated in:
  %s
R�s	s5Please send this file to your support representative.(
R6t_printt_R;Rtst_sizeRtst_uidtpw_nameR(R2tarchivet	directorytchecksumtarchivestat((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytdisplay_results�s"

cC�s8|s|jdjr4|r*t|�q4t�ndS(sSA wrapper around print that only prints if we are not running in
        quiet modeR�N(R�tquietR(R2tmsgR((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR�s
cC�s�|jdjrd}nd}d}|ji|jd6|jd6|jd6|jd6|jd	d	6|d
6}d}x1|j�D]#}|t||dt	�d
}q�W|S(sThis method is used to prepare the preamble text to display to
        the user in non-batch mode. If your policy sets self.distro that
        text will be substituted accordingly. You can also override this
        method to do something more complicated.R�s,Changes CAN be made to system configuration.s0No changes will be made to system configuration.iHtdistrotvendort
vendor_urltvendor_textttmpdirtchanges_textRMtreplace_whitespaces
(
R�tallow_system_changesRRRRRRXR
R6(R2Rtwidtht_msgt_fmtR\((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytget_msg�s	

!cC�s&|ri|_n|jj|�dS(sAdd new presets to this policy object.

            Merges the presets dictionary ``presets`` into this ``Policy``
            object, or replaces the current presets if ``replace`` is
            ``True``.

            ``presets`` should be a dictionary mapping ``str`` preset names
            to ``<class PresetDefaults>`` 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__.pyR��scC�s5x.|jj�D]}||kr|j|SqWdS(s�Find 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__.pytfind_preset�scC�s|jtS(s�Return 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_preset�sc	C�so|p|j}tjj|�s%dSxCtj|�D]2}tjj||�}t|��1}ytj|�}Wnt	k
r�w5nXWdQXx�|j
�D]�}t|dt��}||}t
|kr�|t
nd|_t|kr�|tnd|_t|krMx?tD]4}||tkrt|j||t|�qqWnt|_||j|<q�Wq5WdS(s�Load presets from disk.

            Read JSON formatted preset data from the specified path,
            or the default location at ``/var/lib/sos/presets``.

            :param presets_path: a directory containing JSON presets.
        NR�RM(R�R�R�R�tlistdirR}R�R�R,t
ValueErrorRER�RR�R�R�R�R�RtsetattrR�R6R�R(	R2R�tpreset_pathtpftpreset_dataR tpdtdatatarg((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytload_presetss*



%	c	C�s�|j}|std��n||jj�krFtd|��ntd|d|d|d|�}t|_||j|j<|j|�dS(s�Add a new on-disk preset and write it to the configured
            presets path.

            :param preset: the new PresetDefaults to add
        sPreset name cannot be emptys&A preset with name '%s' already existsRR�R�R�N(	R�R%RRER�R6R�RR�(R2RR�R�R�R�R ((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt
add_preset%s	!	cC�s|s||jj�kr/td|��n|j|}|jr[td|j��n|j|j�|jj|�dS(NsUnknown profile: '%s's"Cannot delete built-in preset '%s'(RRER%R�RR�R�tpop(R2RR ((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt
del_preset8s
	N(8RQRRRRRRRRR�R�R�R�RtPRESETS_PATHR�R6R�R�RR3R�R�R�tpropertyR�R&R�R�R�R�R�R�R�R�R�R�R�R�R�RrR�R�R�R�RRRRRR�R!R#R-RR.R0(((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR�sf											8					

													
		!R'cB�seZdZd�ZRS(s�This Policy will be returned if no other policy can be loaded. This
    should allow for IndependentPlugins to be executed on any systemcC�s|ji|jd6S(NR(RR�(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyRJs(RQRRRSR(((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR'FstLinuxPolicycB�smeZdZdZdZdZd Zd ZdZ	d Z
d Zd Zd Z
d Zd Zd Zd d d�Zd�Zd�Zd�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd d d�Z d�Z!d�Z"d�Z#d�Z$d d d�Z%d�Z&d�Z'd�Z(d�Z)d�Z*d d d d d�Z+RS(!sfThis policy is meant to be an abc class that provides common
    implementations used in Linux distrostLinuxRs/bin:/sbin:/usr/bin:/usr/sbinR�cC�sltt|�jd|�|j�|dk	r;||_n-tjjd�r\t	�|_nt
�|_dS(NR!s/run/systemd/system/(RVR3R3tinit_kernel_modulesRtinit_systemR�R�tisdirRTR-(R2R!tinit((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR3fs
cC�s�|jr|jSd}ytdd�}Wntk
rF||_|SX|j�}|jd�dkrqd}n|j�||_|S(NRs/proc/sys/crypto/fips_enabledtrt1itsha256(t_preferred_hash_nameR�tIOErrortreadtfindtclose(R2Rtfptfips_enabled((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyRqs	
		
	cC�sdyEtd��3}d}|j�}ttj||�d�SWdQXWnttfk
r_dSXdS(Ns/etc/inittabsid:(\d{1}):initdefault:ii(R�R>tintRBtfindallR]R=(R2RAtpatternttext((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytdefault_runlevel�s$cC�s|jS(N(Rw(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytkernel_version�scC�s|jS(N(R�(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt	host_name�scC�s|jS(N(R�(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt
is_kernel_smp�scC�s|jS(N(R�(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytget_arch�scC�s
|j�S(s)Returns the name usd in the pre_work step(RI(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR��scC�stjdd|�S(Ns[^-a-z,A-Z.0-9]RM(RBtsub(R2R((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR��scC�sHtddd�j�}g|D]}|j�dj�^q|_dS(sxObtain a list of loaded kernel modules to reference later for plugin
        enablement and SoSPredicate checks
        tlsmodRsiN(RRXR[RYtkernel_mods(R2tlinesR\((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR5�scC�s|jd}|jr|jnd}|j|_|j|_|j|_|j|_d|_|jr�|j	r�yb|r�||_nt
td�|�|_|js�|jr�|j
�|j�n|j�Wq�tk
r�|j��q�Xn|jr|j|_ndS(NR�RMsGPlease enter the case id that you are generating this report for [%s]: (R�R�t
upload_urltupload_usertupload_directorytupload_passtupload_passwordtupload_archive_nametbatchRRRtuploadtprompt_for_upload_usertprompt_for_upload_passwordRtKeyboardInterrupt(R2tcmdline_optstcaseid((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR��s0
	







	cC�sN|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__.pyRX�scC�s@|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__.pyRY�s
	
cC�sd||_|js$|j�|_n|js<td��n|j�}td|j��GH|�S(s�Entry 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
tupload_func((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pytupload_archive�s&			cC�s�i|jd6|jd6|jd6}|jdj|j�krR||jdjSd|jkrptd��n|jjd�\}}||j�kr�td|��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
        tftptsftpthttpsR�s://s#Must provide protocol in upload URLs(Unsupported or unrecognized protocol: %s(	t
upload_ftptupload_sftptupload_httpsR�tupload_protocolRERPR>R[(R2tprotstprotturl((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyRbs


cC�s=|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
cC�s|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`1scC�s
|j�S(s�Used 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__.pyRc7scC�s|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^=scC�s|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]CscC�std�std��nyddl}Wntk
rJtd��nXt}|sf|j�}n|s{|j�}n|j�jdd�}d||f}t	|j
d	�d
kr�|j|dd�}n|j|�}d
dd|j|j
g}|j|dd�}	|	d	kr(t}n�|	dkr�|j|�d
d|j|j
g}
|j|
dd�d	k}|s|j�td|j���qnl|	dkr�td|j���nG|	dkr�td|j���n"|	d
krtd|j��n|s5|j�td|j���nd|j|j�f}|j|�d|j|j
dg}|j|dd�}
|
d	kr�|jd �tS|
dkr�td!��nW|
dkr�td"|j��n5|
dkrtd#|j��ntd$|j��dS(%s�Attempts 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 supportedi����NsESFTP 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 directoryi�tbyesTimeout 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_cmdtput_expectstput_success((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyRjIs�
	


	
	
cC�s|jjd�dS(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``
        R�i����(RUR[(R2((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR��scC�s%tj|j�d|d|j��S(s�If 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_put�scC�siS(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_headers�scC�sQi|jjd�d||j�fd6}tj|j�d|d|j��S(s�If 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
        R�i����tfileRbRq(RR[R�RptpostR`Ru(R2R
Rb((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt_upload_https_post�s
c	C�s�tstd��nt|jd���}|jdjdkrL|j}n|jdj}|dkrz|j|�}n|j|�}|j	dkr�|j	dkr�|j	dkr�td	��ntd
|j	|j
f��ntSWdQXdS(s=Attempts to upload the archive to an HTTPS location.
        s7Unable to upload due to missing python requests librarytrbR�tautoR�i�i�i�s/Authentication failed: invalid user credentialssPOST request returned %s: %sN(tREQUESTS_LOADEDR>R�RUR�t
upload_methodt_upload_methodR�R�tstatus_codetreasonR;(R2tarcR�R9((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyRk�s c	C�sayddl}ddl}Wntk
r;td��nX|sQ|j�}n|dkrltd��n|jdd�}|s�|j�}n|s�|j�}n|s�|j	p�|j
}nyA|j|||dd�}|s�td	��n|j|�Wn�|j
k
r*td
|��n�|jk
rMtd|��n�|jk
r�}t|�j�d}	|	d
kr�td|��n|	dkr�td|��n|	dkr�td|��ntdt|���nXyQt|jd��+}
|jd|jjd�d|
�WdQX|j�tSWntk
r\td��nXdS(skAttempts to upload the archive to either the policy defined or user
        provided FTP location.
        i����Nsmissing 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: %sR�sSTOR %sR�scould not open archive file(tftplibtsocketRR>R`RRR^R]RRt_upload_directorytFTPtcwdRstgaierrort
error_permR�R[R�RUt
storbinarytquitR;R=(R2RoRRsRtR�R�tsessionterrterrnot_arcfile((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyRi�sZ




N(,RQRRRSRRR�RR8RvR�R_RaR�R<RPRQRTR3RRGRHRIRJRKR�R�R5R�RXRYReRbRuR`RcR^R]RjR�R�R�R�RkRi(((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyR3NsR											&				0	
				l	
				(;t
__future__RR�RBR�R�R�RhR�R�R�RtpwdRt
sos.utilitiesRRRRRtsos.pluginsRR	R)R
RRRttextwrapR
tsixRt	six.movesRR1RpR;R�RR6RRRR,tobjectR-RTR`R�R�R�R�R"tNO_PRESET_DESCtNO_PRESET_NOTER�RR'R3(((s9/usr/lib/python2.7/site-packages/sos/policies/__init__.pyt<module>sX(



	b"�C��