%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/modules/disk.pyo

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZddlZddlZddlZddlZddlmZidd6Zeje�Zejjjd	�dk	Zejjjd
�dk	Zd�Z d�Z!d
�Z"dd�Z#dd�Z$dd�Z%ejj&jjd�dd��Z'd�Z(d�Z)dd�Z*d�Z+ejj&jjd�ejj&jjd�ddde,d���Z-ejj&jj.ddg�d��Z/ejj&j0e�e1d��Z2ejj&j0e�dd��Z3ejj&j0e�dd ��Z4ddd!�Z5ejj&j0e�d"d#dd$��Z6d%�Z7d&�Z8d'�Z9d(�Z:dS()u,
Module for managing disks and blockdevices
i(tabsolute_importtprint_functiontunicode_literalsN(tsix(tzip(tCommandExecutionErroruformatuformat_uhdparmuiostatcC@s tjjj�rtdfStS(u)
    Only work on POSIX-like systems
    u$This module doesn't work on Windows.(tsalttutilstplatformt
is_windowstFalsetTrue(((s5/usr/lib/python2.7/site-packages/salt/modules/disk.pyt__virtual__$s
cC@s�|j�rtj|�Sy�idd6dd6dd6dd6d	d
6dd6d
d6dd6}|d|j�kr�tj|d �}|tj||d�}|Stj|�SWntk
r�|SXdS(u�
    Convert a string to a number, allowing for a K|M|G|T postfix, 32.8K.
    Returns a decimal number if the string is a real number,
    or the string unchanged otherwise.
    u10E3uKu10E6uMu10E9uGu10E12uTu10E15uPu10E18uEu10E21uZu10E24uYi����N(tisdigittdecimaltDecimaltkeyst
ValueError(ttexttpostPrefixestv((s5/usr/lib/python2.7/site-packages/salt/modules/disk.pyt_parse_numbers-s
>
cC@s_d}|dkr|Sd}x<|D]4}||krB||7}q#tdj|���q#W|S(u'
    Sanitize flags passed into df
    uuauBuhuHuiukuluPutuTuxuvuInvalid flag passed to {0}N(uauBuhuHuiukuluPutuTuxuv(tNoneRtformat(targstcallertflagstallowedtflag((s5/usr/lib/python2.7/site-packages/salt/modules/disk.pyt_clean_flagsBs

c	C@s�t|d�}tjjd�rhtddkrhtjd�tjd�dkrdtjd�niStddkr�d	}nHtdd
ks�tddkr�d}ntdd
kr�d}nd}|r�|dj|�7}ni}t	d|dt
�j�}d*}x�|D]�}|s&qn|j
d�r;qn|rR|d|}n|j�}t|�dkr||}qnd*}xRt|�dkr�|dj�r�dj|d|d�|d<|jd�q�Wt|�dkr�qny�tddkrki|dd6|dd6|dd6|dd6|dd 6|d!d"6|d#d$6|d%d&6||d'<nEi|dd6|dd(6|dd6|dd6|dd 6||d!<Wqtk
r�tjd)�i}qXqW|S(+u�
    Return usage information for volumes mounted on this minion

    .. versionchanged:: 2019.2.0

        Default for SunOS changed to 1 kilobyte blocks

    CLI Example:

    .. code-block:: bash

        salt '*' disk.usage
    u
disk.usageu	/etc/mtabukerneluLinuxudf cannot run without /etc/mtabuvirtual_subtypeuLXCu�df command failed and LXC detected. If you are running a Docker container, consider linking /proc/mounts to /etc/mtab or consider running Docker with -privilegedudf -PuOpenBSDuAIXudf -kPuSunOSudf -kudfu -{0}ucmd.runtpython_shellu
Filesystemu iiu{0} {1}iuDarwinu
filesystemu
512-blocksuusediu	availableiucapacityiuiusediuifreeiu%iusediu	1K-blocksu&Problem parsing disk usage informationN(Rtostpathtisfilet
__grains__tlogterrortgetRt__salt__R
t
splitlinesRt
startswithtsplittlenR
tpopt
IndexError(RRtcmdtrettouttoldlinetlinetcomps((s5/usr/lib/python2.7/site-packages/salt/modules/disk.pytusageTsp#
	 		
&

cC@s�t|d�}tddkr(d}nd}|rJ|dj|�7}ni}td|dt�j�}xu|D]m}|jd	�r�qsn|j�}|s�qsny
tdd
krit|d�t|d�d
6|dd6|dd6|dd6|dd6||d<n�tddkrmi|dd
6|dd6|dd6|dd6|dd6||d<nEi|dd
6|dd6|dd6|dd6|dd6||d<Wqst	t
fk
r�tjd�i}qsXqsW|S(u�
    Return inode usage information for volumes mounted on this minion

    CLI Example:

    .. code-block:: bash

        salt '*' disk.inodeusage
    udisk.inodeusageukerneluAIXudf -iudf -iPu -{0}ucmd.runRu
FilesystemuOpenBSDiiuinodesuusedufreeiuuseiu
filesystemiiiiiu'Problem parsing inode usage information(
RR"RR&R
R'R(R)tintR,RR#R$(RRR-R.R/R1R2((s5/usr/lib/python2.7/site-packages/salt/modules/disk.pyt
inodeusage�sN
	

cC@s�tddkrd}n/tddks9tddkrBd}nd}i}td|d	t�j�}x
|D]}|s�qqn|jd
�r�qqn|j�}xRt|�dkr�|dj�r�d
j|d|d�|d<|j	d�q�Wt|�dkrqqny;tddkr9|d||d<n|d||d<Wqqt
k
rrtjd�i}qqXqqW|r�||kr�tjd|�i}n|r�||S|S(u�
    Return partition information for volumes mounted on this minion

    CLI Example:

    .. code-block:: bash

        salt '*' disk.percent /var
    ukerneluLinuxudf -PuOpenBSDuAIXudf -kPudfucmd.runRu
Filesystemiiu{0} {1}iuDarwiniiiu&Problem parsing disk usage informationuFProblem parsing disk usage information: Partition '%s' does not exist!(
R"R&R
R'R(R)R*R
RR+R,R#R$(RR-R.R/R1R2((s5/usr/lib/python2.7/site-packages/salt/modules/disk.pytpercent�sB
	 	
&

	ublkidc
C@sd}|rd|}ni}tdd|dt�}|ddkrM|Sx�|dj�D]�}|spq^n|j�}|dd	 }i}tjd
|jd�d�}xRtt|�gd�D]7\}}	|jd�jd�}|	jd
�||<q�W|||<q^W|S(u�
    Return block device attributes: UUID, LABEL, etc. This function only works
    on systems where blkid is available.

    CLI Example:

    .. code-block:: bash

        salt '*' disk.blkid
        salt '*' disk.blkid /dev/sda
    uu ucmd.run_allublkidRuretcodeiustdouti����u"*"iu=u"(	R&R
R'R)tret	partitionRtitertstrip(
tdeviceRR.tblkid_resultR1R2tinfotdevice_attributestkeytvalue((s5/usr/lib/python2.7/site-packages/salt/modules/disk.pytblkids&

&c	K@sidd6dd6dd6dd6}d	}g}x�|D]�}||kr5||}|dkry|j|jd
d��n
|jd�||d
ks�||tkr�|dj|�7}q�|dj|||�7}q5q5Wdj||�}td|dt�j�}t||�S(ud
    Set attributes for the specified device

    CLI Example:

    .. code-block:: bash

        salt '*' disk.tune /dev/sda1 read-ahead=1024 read-write=True

    Valid options are: ``read-ahead``, ``filesystem-read-ahead``,
    ``read-only``, ``read-write``.

    See the ``blockdev(8)`` manpage for a more complete description of these
    options.
    usetrau
read-aheadusetfraufilesystem-read-aheadusetrou	read-onlyusetrwu
read-writeuusetugetugetrouTrueu--{0} u
--{0} {1} ublockdev {0}{1}ucmd.runR(tappendtreplaceRRR&R
R'tdump(	R;tkwargst	kwarg_maptoptsRR?tswitchR-R/((s5/usr/lib/python2.7/site-packages/salt/modules/disk.pyttune4s$




 !cC@svdj|�}ytd|dt�}Wntjk
rB}tSX|ddkrWtStjd||d�tSdS(	u}
    Remove the filesystem information

    CLI Example:

    .. code-block:: bash

        salt '*' disk.wipe /dev/sda1
    u
wipefs -a {0}ucmd.run_allRuretcodeiuError wiping device %s: %sustderrN(RR&R
t
subprocesstCalledProcessErrorRR#R$(R;R-R/terr((s5/usr/lib/python2.7/site-packages/salt/modules/disk.pytwipe[scC@sdj|�}i}g|j�D]}|jd�r"|d^q"}td|dt�}|ddkr�g|dj�D]}|r~|^q~}d}	x&|D]}||||	<|	d	}	q�W|r�i}
x|D]}|||
|<q�W|
S|SntSd
S(u�
    Return all contents of dumpe2fs for a specified device

    CLI Example:
    .. code-block:: bash

        salt '*' disk.dump /dev/sda1
    u�blockdev --getro --getsz --getss --getpbsz --getiomin --getioopt --getalignoff --getmaxsect --getsize --getsize64 --getra --getfra {0}u--iucmd.run_allRuretcodeiustdoutiN(RR)R(R&R
R'(R;RR-R.tcRGR/R1tlinestcountttemp_rettarg((s5/usr/lib/python2.7/site-packages/salt/modules/disk.pyRDrs$		2)

cC@s[dj|�}ytd|dt�}Wntjk
rB}tSX|ddkrWtSdS(uw
    Resizes the filesystem.

    CLI Example:
    .. code-block:: bash

        salt '*' disk.resize2fs /dev/sda1
    u
resize2fs {0}ucmd.run_allRuretcodeiN(RR&R
RJRKR(R;R-R/RL((s5/usr/lib/python2.7/site-packages/salt/modules/disk.pyt	resize2fs�s	usyncumkfsuext4cC@sbddtj|�g}|dk	r�|d dkrS|jdtj|�g�q�|dkr�|jddj|�g�q�n|dk	r�|d dkr�|jdd	j|�g�q�n|r|d dkr�|jd
�q|dkr|jd�qn|jtj|��td|d
t�dk}tddd
t�dk}t||g�S(u}
    Format a filesystem onto a device

    .. versionadded:: 2016.11.0

    device
        The device in which to create the new filesystem

    fs_type
        The type of filesystem to create

    inode_size
        Size of the inodes

        This option is only enabled for ext and xfs filesystems

    lazy_itable_init
        If enabled and the uninit_bg feature is enabled, the inode table will
        not be fully initialized by mke2fs.  This speeds up filesystem
        initialization noticeably, but it requires the kernel to finish
        initializing the filesystem  in  the  background  when  the filesystem
        is first mounted.  If the option value is omitted, it defaults to 1 to
        enable lazy inode table zeroing.

        This option is only enabled for ext filesystems

    force
        Force mke2fs to create a filesystem, even if the specified device is
        not a partition on a block special device. This option is only enabled
        for ext and xfs filesystems

        This option is dangerous, use it with caution.

    CLI Example:

    .. code-block:: bash

        salt '*' disk.format /dev/sdX1
    umkfsu-tiuextu-iuxfsusize={0}u-Eulazy_itable_init={0}u-Fu-fucmd.retcodetignore_retcodeiusyncN(	Rt	text_typeRtextendRRBR&Rtall(R;tfs_typet
inode_sizetlazy_itable_inittforceR-tmkfs_successtsync_success((s5/usr/lib/python2.7/site-packages/salt/modules/disk.pytformat_�s$.""ulsblkudfcC@s7tjjjd�rftddj|��j�}t|�dkrf|dj�}|rc|Sqfntjjjd�r3t	ddkr�t
jjd�r�tdd	j|��j�}t|�d
kr0|d
}|r�|Sq0q3tddj|��j�}t|�dkr3|d}|r0|Sq3ndS(
u�
    Return the filesystem name of the specified device

    .. versionadded:: 2016.11.0

    device
        The name of the device

    CLI Example:

    .. code-block:: bash

        salt '*' disk.fstype /dev/sdX1
    ulsblkucmd.runulsblk -o fstype {0}iudfukerneluAIXu/usr/sysv/bin/dfu/usr/sysv/bin/df -n {0}iu	df -T {0}u(
RRR twhichR&RR'R*R:R"RR!R)(R;t	lsblk_outRXtdf_out((s5/usr/lib/python2.7/site-packages/salt/modules/disk.pytfstype�s&
"



cC@srdj|�}td|�}|ddkrjdj||d�}|rZt|��qjtj|�n|dS(uT
    Execute hdparm
    Fail hard when required
    return output when possible
    u
hdparm {0}ucmd.run_alluretcodeiu{0}: {1}ustderrustdout(RR&RR#twarning(RtfailhardR-tresulttmsg((s5/usr/lib/python2.7/site-packages/salt/modules/disk.pyt_hdparmsc
	C@s1d}|dkr|}n't|ttf�rBdj|�}nt|ttf�sc|g}ni}x�|D]�}|jd�s�dj|�}ni}xtdj||�t�j	�D]\}|j
�}t|�dks�||dkr�q�nd|kr5|jdd�\}}t
jd	d|�}n*d
|kr�|jd
d�\}}nq�|j
�j�jdd�}|j
�}g}	t
jd
|�r�|jd�}|	jt|d��|	j|dj
d��n-i}
x�t
jd|j
��D]�}|j
�}yt|�}|	j|�Wqtk
r�d
|kr�|jd
d�\}}|j
�}|j
�}t|�r�||
|<q�q�t|�r�|	j|�q�qXqWt|
�r�|	j|
�nt|	�dkr�q�nt|	�dkr|	d}	n|	||<q�W|||<qpW|S(u�
    Retrieve all info's for all disks
    parse 'em into a nice dict
    (which, considering hdparms output, is quite a hassle)

    .. versionadded:: 2016.3.0

    CLI Example:
    .. code-block:: bash

        salt '*' disk.hdparms /dev/sda
    uaAbBcCdgHiJkMmNnQrRuWuu/devu/dev/{0}u-{0} {1}iu:iu is$u=u u_u
[0-9]+ \(.*\)u()u[/,]N(Rt
isinstancetlistttupletjoinR(RRgR
R'R:R*R)R7tsubtlowerRCtmatchRBR4t	Exception(
tdisksRt	all_parmsR/tdiskt	disk_dataR1R?tvalstrvalstvaldicttvaltdeep_key((s5/usr/lib/python2.7/site-packages/salt/modules/disk.pythdparms$sj	
("

cC@s`i}x�t|d�j�D]t\}}|j�d\}}}||ksYd|krmi|d6||<qi|d6|d6||d6||<qW|d
kr�|Sx�|j�D]�\}}y|dt|�}WnQtk
r(d|kr)t|jd��}d||d}|d:}q)nX|dkrB|d}ntd	j||��q�Wd
S(u�
    Get/set Host Protected Area settings

    T13 INCITS 346-2001 (1367D) defines the BEER (Boot Engineering Extension Record)
    and PARTIES (Protected Area Run Time Interface Extension Services), allowing
    for a Host Protected Area on a disk.

    It's often used by OEMS to hide parts of a disk, and for overprovisioning SSD's

    .. warning::
        Setting the HPA might clobber your data, be very careful with this on active disks!

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt '*' disk.hpa /dev/sda
        salt '*' disk.hpa /dev/sda 5%
        salt '*' disk.hpa /dev/sda 10543256
    uNiudisabledutotaluvisibleuhiddenu%idu'--yes-i-know-what-i-am-doing -Np{0} {1}N(	RytitemstvaluesRR4RoR:RgR(Rptsizethpa_dataRrtdatatvisiblettotaltstatus((s5/usr/lib/python2.7/site-packages/salt/modules/disk.pythpaqs."

cC@sg|jd�sd|}ndj|�}td|dd�}|ddkrdt|d��nt|d	j��}g}x\|D]T}|jd
�r�tjd|j��}g|dD]}|j	�^q�}Pq�q�W|dk	rg|D]}||kr
|nd
^q�}ni}	xA|D]9}tjd|�sBPntjd|j�dt|��}t
|d�}
|dk	r�|
|kr�q&ntt||d��}y|d
=Wntk
r�nXx�|D]~}||}yt
|�}WnQtk
rFy,g|jd�D]}
t
|
�^q}WqGtk
rBqGXnX|||<q�W||	|
<q&W|	S(u�
    Fetch SMART attributes
    Providing attributes will deliver only requested attributes
    Providing values will deliver only requested values for attributes

    Default is the Backblaze recommended
    set (https://www.backblaze.com/blog/hard-drive-smart-stats/):
    (5,187,188,197,198)

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt '*' disk.smart_attributes /dev/sda
        salt '*' disk.smart_attributes /dev/sda attributes=(5,187,188,197,198)
    u/dev/usmartctl --attributes {0}ucmd.run_alltoutput_logleveluquieturetcodeiustderrustdoutuID#u\s+iu_u[\s]*\dtmaxsplitu N(R(RR&RR9R'R7R)R:RmRRnR*R4tdictRRo(tdevt
attributesR{R-tsmart_resulttfieldsR1R?tfieldt
smart_attrtattrR~RwR@((s5/usr/lib/python2.7/site-packages/salt/modules/disk.pytsmart_attributes�sP

#.
$



,
iicC@sjtjjj�r"t|||�Stjjj�rDt|||�Stjjj�rft|||�SdS(u�
    Gather and return (averaged) IO stats.

    .. versionadded:: 2016.3.0

    .. versionchanged:: 2016.11.4
        Added support for AIX

    CLI Example:

    .. code-block:: bash

        salt '*' disk.iostat 1 5 disks=sda
    N(	RRRtis_linuxt
_iostat_linuxt
is_freebsdt_iostat_fbsdtis_aixt_iostat_aix(tintervalRPRp((s5/usr/lib/python2.7/site-packages/salt/modules/disk.pytiostat�scC@s`gt|�D]4}tt|�t|�jtjd���^q
}tt||��}|S(u�
    Transpose collected data, average it, stomp it in dict using header

    Use Decimals so we can properly calc & round, convert to float 'caus' we can't transmit Decimals over 0mq
    u.01(RtfloattsumR*tquantizeRRR�(theadertstatststat((s5/usr/lib/python2.7/site-packages/salt/modules/disk.pyt
_iostats_dict
sGcC@s�|dkr!dj||�}nHt|tj�rKdj|||�}ndj||dj|��}g}tjt�}g}g}d}t	t
d|dd�j��}	x�|	D]�}
|
jd�s�q�nt
|�s�|
j�d	}nx�|
tk	r�t|	t�}
|
s)|
d
j�r-Pn|
j�}
|
d
}g|
d	D]}tj|�^qN}
t
|
�|kr�t
|
�}n||j|
�q�Wq�Wi}|t
|�kr_||}|d
|!}xt|j�D]f\}}
t
|
d
�|kr�g|
D]}||^q}g|
D]}|d
|!^q%||<q�q�Wt||�|d<nx-|j�D]\}}
t||
�||<qlW|S(
u[
    Tested on FreeBSD, quite likely other BSD's only need small changes in cmd syntax
    uiostat -xC -w {0} -c {1} uiostat -x -w {0} -c {1} {2}u i�ucmd.run_stdoutR�uquietudeviceiiusysN(RRRhRtstring_typesRktcollectionstdefaultdictRiR9R&R'R(R*R)R
tnexttisalnumRRRBRzR�(R�RPRpt
iostat_cmdt	sys_statst	dev_statst
sys_headert
dev_headerth_lenR.R1RrtxR�tiostatsR�((s5/usr/lib/python2.7/site-packages/salt/modules/disk.pyR�sL"

&

+cC@sM|dkr!dj||�}nHt|tj�rKdj|||�}ndj||dj|��}g}tjt�}g}g}t	t
d|dd�j��}xB|D]:}	|	jd�r+t
|�s�t|	j�d�}ngt|�j�D]}
tj|
�^q}	|j|	�q�|	jd	�r�t
|�s_t|	j�d�}nx�|	tk	r�t|t�}	|	s�|	d
j�r�Pn|	j�}	|	d
}g|	dD]}
tj|
�^q�}||j|�qbWq�q�Wi}
t
|�rt||�|
d<nx-|j�D]\}}t||�|
|<q&W|
S(Nuiostat -x {0} {1} uiostat -xd {0} {1} {2}u ucmd.run_stdoutR�uquietuavg-cpu:iuDevice:iusys(RRRhRR�RkR�R�RiR9R&R'R(R*RjR)R�RRRBR
R�R�Rz(R�RPRpR�R�R�R�R�R.R1R�RrR�R�((s5/usr/lib/python2.7/site-packages/salt/modules/disk.pyR�MsB"
.
&cC@s6tjd�|dkr.dj||�}nHt|tj�rXdj|||�}ndjdj|�||�}i}d}g}d}d}tj	t
�}	xtd|�j�D]�}
|
s�|
j
d�s�|
j
d�r�q�ntjd	|
�s�|
jd
�}|dj�}|d}|d}|dj�}||	j�kr�g|	|<t|	|�}|	|ji�i|	|||<||	|||d
<g|	|||d<q�q�nd
|
kr]|
jd
�}
|
dj�}|
dj�}||	|dj�kr�i|	|d|<||	|d|d
<g|	|d|d<q�q�|
j�}
g|
D]}t|�^qq}|	|d|dj|�q�Wi}x|	j�D]q\}}i||<xX|D]P}xG|j�D]9}||d
}||d}t||�|||<q�Wq�Wq�W|S(u?
    AIX support to gather and return (averaged) IO stats.
    uDGM disk iostat entryuiostat -dD {0} {1} uiostat -dD {0} {1} {2}u uucmd.runuSystemu-----------u\su:iiufieldsustatsN(R#tdebugRRRhRR�RkR�R�RiR&R'R(R7RnR)RR*RBtlstripRRzR�(R�RPRpR�R.tprocnR�t	disk_namet	disk_modeR�R1t	dsk_compst
dsk_firstsR2R�R�R�Rrt
list_modestmodes((s5/usr/lib/python2.7/site-packages/salt/modules/disk.pyR�xsb
$%


 !

#(;t__doc__t
__future__RRRtloggingRRJR7R�Rtsalt.extRtsalt.ext.six.movesRtsalt.utils.decoratorsRtsalt.utils.decorators.pathtsalt.utils.pathtsalt.utils.platformtsalt.exceptionsRt__func_alias__t	getLoggert__name__R#RR R_Rt
HAS_HDPARMt
HAS_IOSTATRRRR3R5R6t
decoratorsRARIRMRDRSR
R^t	which_binRbtdependsRRgRyR�R�R�R�R�R�R�(((s5/usr/lib/python2.7/site-packages/salt/modules/disk.pyt<module>sf
				O:1%	'		>'*L7I		8	+

Zerion Mini Shell 1.0