%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/modules/ps.pyc

�
���^c@@sGdZddlmZmZmZddlZddlZddlZddlZ	ddl
mZmZddl
Z	ddlmZy4ddljjZeZeedd,�d-kZWnek
r�eZnXd�Zd	�Zd
�Zd�Zd�Zd
�Zd�Z ddd�Z!d�Z"dd�Z$dd�Z%dded�Z&ded�Z'ded�Z(ed�Z)d�Z*d�Z+ed�Z,d�Z-ed�Z.d �Z/d!�Z0dd"�Z1dd#�Z2dd$�Z3d%�Z4d&�Z5e	jj6j7j8d'�d(��Z9e	jj6j7j8d)�d*��Z:d+�Z;dS(.u�
A salt interface to psutil, a system and process library.
See http://code.google.com/p/psutil.

:depends:   - psutil Python module, version 0.3.0 or later
            - python-utmp package (optional)
i(tabsolute_importtunicode_literalstprint_functionN(tSaltInvocationErrortCommandExecutionError(tsixuversion_infoicC@s9tstdfStjdkr#tStdjtj�fS(NuCThe ps module cannot be loaded: python module psutil not installed.iiuaThe ps execution module cannot be loaded: the psutil python module version {0} is less than 0.3.0(iii(t
HAS_PSUTILtFalsetpsutiltversion_infotTruetformat(((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pyt__virtual__"s

	cC@sQy,tjjjtr!|j�n|j�SWntjtjfk
rLgSXdS(uq
    Returns the cmdline of a Process instance.

    It's backward compatible with < 2.0 versions of psutil.
    N(	tsalttutilstdatatdecodetPSUTIL2tcmdlineRt
NoSuchProcesstAccessDenied(tproc((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pyt_get_proc_cmdline2s,cC@sQy,tjjjtr!|j�n|j�SWntjtjfk
rLdSXdS(uu
    Returns the create_time of a Process instance.

    It's backward compatible with < 2.0 versions of psutil.
    N(
R
RRRRtcreate_timeRRRtNone(R((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pyt_get_proc_create_time>s,cC@sQy,tjjjtr!|j�n|j�SWntjtjfk
rLgSXdS(un
    Returns the name of a Process instance.

    It's backward compatible with < 2.0 versions of psutil.
    N(	R
RRRRtnameRRR(R((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pyt_get_proc_nameJs,cC@sQy,tjjjtr!|j�n|j�SWntjtjfk
rLdSXdS(up
    Returns the status of a Process instance.

    It's backward compatible with < 2.0 versions of psutil.
    N(
R
RRRRtstatusRRRR(R((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pyt_get_proc_statusVs,cC@sTy,tjjjtr!|j�n|j�SWn!tjtjt	fk
rOdSXdS(ur
    Returns the username of a Process instance.

    It's backward compatible with < 2.0 versions of psutil.
    N(R
RRRRtusernameRRRtKeyErrorR(R((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pyt_get_proc_usernamebs,cC@s|jS(um
    Returns the pid of a Process instance.

    It's backward compatible with < 2.0 versions of psutil.
    (tpid(R((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pyt
_get_proc_pidnsiicC@s�g}i}x�tj�D]{}y%tj|�}|j�\}}Wn?tk
ro|j�\}}}}ntjk
r�qnX||||<qWtj|�t�}	x�t	j
|�D]�\}}
y|j�\}}Wn?tk
r|j�\}}}}ntjk
r!q�nX||}||
}|	j||f�q�WxEtt
t|	���D]+\}
\}}|r�|
|kr�Pntt|��dkr�t|�}nt|�}i|d6t|�d6t|�d6t|�d6t|�d6id6id6}x7t	j
|j�j��D]\}}||d|<q,Wx7t	j
|j�j��D]\}}||d|<qfW|j|�qfW|S(	u*
    Return a list of top CPU consuming processes during the interval.
    num_processes = return the top N CPU consuming processes
    interval = the number of seconds to sample CPU usage over

    CLI Examples:

    .. code-block:: bash

        salt '*' ps.top

        salt '*' ps.top 5 10
    iucmduuserustatusupiducreate_timeucpuumem(RtpidstProcesst	cpu_timest
ValueErrorRttimetsleeptsetRt	iteritemstaddt	enumeratetreversedtsortedtlenRRR RR"Rt_asdicttmemory_infotappend(t
num_processestintervaltresulttstart_usageR!tprocesstusertsystemt_tusagetstarttnowtdifftidxRtinfotkeytvalue((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pyttopwsT

	


+





((cC@s
tj�S(u�
    Return a list of process ids (PIDs) for all running processes.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.get_pid_list
    (RR#(((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pytget_pid_list�s
cC@sUy tj|�}|j|�SWn.tjtjtfk
rP}t|��nXdS(u�
    Return a dictionary of information for a process id (PID).

    CLI Example:

    .. code-block:: bash

        salt '*' ps.proc_info 2322
        salt '*' ps.proc_info 2322 attrs='["pid", "name"]'

    pid
        PID of process to query.

    attrs
        Optional list of desired process attributes.  The list of possible
        attributes can be found here:
        http://pythonhosted.org/psutil/#psutil.Process
    N(RR$tas_dictRRtAttributeErrorR(R!tattrsRtexc((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pyt	proc_info�s
icC@s:ytj|�j|�tSWntjk
r5tSXdS(u�
    Kill a process by PID.

    .. code-block:: bash

        salt 'minion' ps.kill_pid pid [signal=signal_number]

    pid
        PID of process to kill.

    signal
        Signal to send to the process. See manpage entry for kill
        for possible values. Default: 15 (SIGTERM).

    **Example:**

    Send SIGKILL to process with PID 2000:

    .. code-block:: bash

        salt 'minion' ps.kill_pid 2000 signal=9
    N(RR$tsend_signalR
RR(R!tsignal((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pytkill_pid�s
cC@s�g}x�tj�D]�}|r:|djt|��kn|t|�k}|dkr^tn|t|�k}|r|ry$|j|�|j	t
|��Wq�tjk
r�q�XqqW|s�dSi|d6SdS(u�
    Kill processes matching a pattern.

    .. code-block:: bash

        salt '*' ps.pkill pattern [user=username] [signal=signal_number] \
                [full=(true|false)]

    pattern
        Pattern to search for in the process list.

    user
        Limit matches to the given username. Default: All users.

    signal
        Signal to send to the process(es). See manpage entry for kill
        for possible values. Default: 15 (SIGTERM).

    full
        A boolean value indicating whether only the name of the command or
        the full command line should be matched against the pattern.

    **Examples:**

    Send SIGHUP to all httpd processes on all 'www' minions:

    .. code-block:: bash

        salt 'www.*' ps.pkill httpd signal=1

    Send SIGKILL to all bash processes owned by user 'tom':

    .. code-block:: bash

        salt '*' ps.pkill bash signal=9 user=tom
    u ukilledN(Rtprocess_itertjoinRRRR
R RJR2R"R(tpatternR8RKtfulltkilledRt
name_matcht
user_match((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pytpkill�s&!$
cC@s�g}x�tj�D]}|r:|djt|��kn|t|�k}|dkr^tn|t|�k}|r|r|jt	|��qqW|p�dS(u9
    Return the pids for processes matching a pattern.

    If full is true, the full command line is searched for a match,
    otherwise only the name of the command is searched.

    .. code-block:: bash

        salt '*' ps.pgrep pattern [user=username] [full=(true|false)]

    pattern
        Pattern to search for in the process list.

    user
        Limit matches to the given username. Default: All users.

    full
        A boolean value indicating whether only the name of the command or
        the full command line should be matched against the pattern.

    **Examples:**

    Find all httpd processes on all 'www' minions:

    .. code-block:: bash

        salt 'www.*' ps.pgrep httpd

    Find all bash processes owned by user 'tom':

    .. code-block:: bash

        salt '*' ps.pgrep bash user=tom
    u N(
RRMRNRRRR
R R2R"(ROR8RPtprocsRRRRS((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pytpgrep1s$!$g�������?cC@s4|r!ttj|t��}ntj|�}|S(uN
    Return the percent of time the CPU is busy.

    interval
        the number of seconds to sample CPU usage over
    per_cpu
        if True return an array of CPU percent busy for each CPU, otherwise
        aggregate all percents into one number

    CLI Example:

    .. code-block:: bash

        salt '*' ps.cpu_percent
    (tlistRtcpu_percentR
(R4tper_cpuR5((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pyRX_scC@sV|r7gtjt�D]}t|j��^q}nttj|�j��}|S(uF
    Return the percent of time the CPU spends in each state,
    e.g. user, system, idle, nice, iowait, irq, softirq.

    per_cpu
        if True return an array of percents for each CPU, otherwise aggregate
        all percents into one number

    CLI Example:

    .. code-block:: bash

        salt '*' ps.cpu_times
    (RR%R
tdictR0(RYttimesR5((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pyR%vs1cC@s:tjdkr$d}t|��nttj�j��S(u
    .. versionadded:: 2014.7.0

    Return a dict that describes statistics about system memory usage.

    .. note::

        This function is only available in psutil version 0.6.0 and above.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.virtual_memory
    iiu;virtual_memory is only available in psutil 0.6.0 or greater(iii(RR	RRZtvirtual_memoryR0(tmsg((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pyR\�scC@s:tjdkr$d}t|��nttj�j��S(u
    .. versionadded:: 2014.7.0

    Return a dict that describes swap memory statistics.

    .. note::

        This function is only available in psutil version 0.6.0 and above.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.swap_memory
    iiu8swap_memory is only available in psutil 0.6.0 or greater(iii(RR	RRZtswap_memoryR0(R]((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pyR^�scC@s2gtj|�D]}t|j��^q}|S(uK
    Return a list of disk partitions and their device, mount point, and
    filesystem type.

    all
        if set to False, only return local, physical partitions (hard disk,
        USB, CD/DVD partitions).  If True, return all filesystems.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.disk_partitions
    (Rtdisk_partitionsRZR0(tallt	partitionR5((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pyR_�s+cC@sttj|�j��S(u�
    Given a path, return a dict listing the total available space as well as
    the free space, and used space.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.disk_usage /home
    (RZRt
disk_usageR0(tpath((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pyRb�scC@s8t|�}x%|D]}|jt|d��qW|S(u�
    Return a list of disk partitions plus the mount point, filesystem and usage
    statistics.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.disk_partition_usage
    u
mountpoint(R_tupdateRb(R`R5Ra((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pytdisk_partition_usage�s
cC@sQtjdkr$d}t|��nytj�jSWntk
rLtjSXdS(u�
    Return the total number of bytes of physical memory.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.total_physical_memory
    iiu;virtual_memory is only available in psutil 0.6.0 or greaterN(iii(RR	RR\ttotalRFtTOTAL_PHYMEM(R]((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pyttotal_physical_memory�s

cC@s*ytj�SWntk
r%tjSXdS(un
    Return the number of CPUs.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.num_cpus
    N(Rt	cpu_countRFtNUM_CPUS(((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pytnum_cpuss

cC@s�yttj��}Wn#tk
r;ttj��}nX|r�tjj|�}y|j|�SWq�tk
r�}tdj	|���q�Xn|S(u�
    Return the boot time in number of seconds since the epoch began.

    CLI Example:

    time_format
        Optionally specify a `strftime`_ format string. Use
        ``time_format='%c'`` to get a nicely-formatted locale specific date and
        time (i.e. ``Fri May  2 19:08:32 2014``).

        .. _strftime: https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior

        .. versionadded:: 2014.1.4

    .. code-block:: bash

        salt '*' ps.boot_time
    uInvalid format string: {0}(
tintRt	boot_timeRFtdatetimet
fromtimestamptstrftimet	TypeErrorRR(ttime_formattb_timeRH((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pyRms
cC@sV|sttj�j��Stjdt�}||krNt||j��StSdS(u�
    Return network I/O statistics.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.network_io_counters

        salt '*' ps.network_io_counters interface=eth0
    tpernicN(RZRtnet_io_countersR0R
R(t	interfacetstats((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pytnetwork_io_counters5scC@sV|sttj�j��Stjdt�}||krNt||j��StSdS(u�
    Return disk I/O statistics.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.disk_io_counters

        salt '*' ps.disk_io_counters device=sda1
    tperdiskN(RZRtdisk_io_countersR0R
R(tdeviceRw((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pyRzKscC@sy3tj�}g|D]}t|j��^qSWn�tk
ry�ddl}g}x�tr�|jj�}|dkr�|S|ddkr[|d}t
|t�r�|d}n|ji|dd6|dd6|d	6|d
d6�q[q[WWqt
k
rtSXnXdS(ul
    Return logged-in users.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.get_users
    iNiiiunameiuterminalustartediuhost(RtusersRZR0RFtutmpR
t
utmpaccesstgetutentRt
isinstancettupleR2tImportErrorR(trecstxR}R5trectstarted((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pyt	get_usersas&
'
	

!
cC@s@tj|�}tdd|�}g}|j||g�|S(u�
    Retrieve the lsof information of the given process name.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.lsof apache2
    ucmd.runulsof -c (Rt	text_typet__salt__textend(Rt
sanitize_namet
lsof_infostret((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pytlsof�s

unetstatcC@s~tj|�}tdd�}g}g}x9|j�D]+}|j|�dkr8|j|�q8q8W|j||g�|S(u�
    Retrieve the netstat information of the given process name.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.netstat apache2
    ucmd.rununetstat -napi����(RR�R�t
splitlinestfindR2R�(RR�t
netstat_infostfound_infosR�R@((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pytnetstat�susscC@s~tj|�}tdd�}g}g}x9|j�D]+}|j|�dkr8|j|�q8q8W|j||g�|S(u�
    Retrieve the ss information of the given process name.

    CLI Example:

    .. code-block:: bash

        salt '*' ps.ss apache2

    .. versionadded:: 2016.11.6

    ucmd.runuss -neapi����(RR�R�R�R�R2R�(RR�tss_infosR�R�R@((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pytss�scC@s�tj|�}tj|�}tjd�}tdd�}g}g}d}x[|j�D]M}|j|�}	|	dk	r\|j|�s�|d7}|j|�q�q\q\Wtj|�d}
g}|j	|||
g�|S(u
    Retrieve information corresponding to a "ps aux" filtered
    with the given pattern. It could be just a name or a regular
    expression (using python search from "re" module).

    CLI Example:

    .. code-block:: bash

        salt '*' ps.psaux www-data.+apache2
    usalt.+ps.psaux.+ucmd.runups auxiiu occurence(s).N(
RR�tretcompileR�R�tsearchRR2R�(RR�ROtsalt_exception_patterntps_auxR�R�tnb_linesR@tfoundt	pid_count((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pytpsaux�s"
((ii(<t__doc__t
__future__RRRR'RnR�tsalt.utils.dataR
tsalt.exceptionsRRtsalt.utils.decorators.pathtsalt.extRtsalt.utils.psutil_compatRt
psutil_compatRR
RtgetattrRR�RRRRRRR R"RCRDRRIRLRTRVRXR%R\R^R_RbReRhRkRmRxRzR�R�t
decoratorsRctwhichR�R�R�(((s3/usr/lib/python2.7/site-packages/salt/modules/ps.pyt<module>sX

								>	
7.					#	"	!!

Zerion Mini Shell 1.0