%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/btrfs.pyc

�
���^c@@sKdZddlmZmZmZddlZddlZddlZddlZ	ddl
Z	ddlmZddl
mZd�Zd�Zd�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zeed�Zd�Z d�Z!d�Z"d�Z#ddd�Z%dS(u)
Module for managing BTRFS file systems.
i(tabsolute_importtprint_functiontunicode_literalsN(tCommandExecutionError(tsixcC@s&tjjj�o%tjd�dkS(u)
    Only work on POSIX-like systems
    ukerneluLinux(tsalttutilstplatformt
is_windowst
__grains__tget(((s6/usr/lib/python2.7/site-packages/salt/modules/btrfs.pyt__virtual__%scC@sQtdd�}|jd�r2t|d��ni|djdd�dd6S(	uk
    Return BTRFS version.

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.version
    ucmd.run_allubtrfs --versionustderrustdoutu ii����uversion(t__salt__R
Rtsplit(tout((s6/usr/lib/python2.7/site-packages/salt/modules/btrfs.pytversion,s
cC@si}xg|jd�D]}|r|^qd D]�}|jd�r�tjdd|�}g|jd�D]}|j�^qm\}}|dkr�|p�d|d<||d	<q3n|jd
�r3tjd|j��}|d}i|dd
6|dd6|dd6||<q3q3W|S(u'
    Parse BTRFS device info data.
    u
i����uLabel:u	Label:\s+uuuuid:unoneulabeluuuidu	devidu\s+iu	device_idiusizeiuusedN(R
t
startswithtretsubtstriptNone(tdatatrettlinettkntlabeltuuid_tdev_datatdev_id((s6/usr/lib/python2.7/site-packages/salt/modules/btrfs.pyt_parse_btrfs_info<s 3.

cC@s:tddj|��}tjjj|�t|d�S(u~
    Get BTRFS filesystem information.

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.info /dev/sda1
    ucmd.run_allubtrfs filesystem show {0}ustdout(RtformatRRtfsutilst_verify_runR(tdeviceR((s6/usr/lib/python2.7/site-packages/salt/modules/btrfs.pytinfoUs
cC@s@tdd�}tjjj|�tjjj|ddd�S(u�
    Get known BTRFS formatted devices on the system.

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.devices
    ucmd.run_allublkid -o exportustdouttfs_typeubtrfs(RRRRR t
_blkid_output(R((s6/usr/lib/python2.7/site-packages/salt/modules/btrfs.pytdeviceses
cC@sHtddj|��}i|d6|dd6|dp<td6td6S(u/
    Defragment only one BTRFS mountpoint.
    ucmd.run_allu"btrfs filesystem defragment -f {0}umount_pointustderrupassedulogurange(RRtFalse(t
mountpointR((s6/usr/lib/python2.7/site-packages/salt/modules/btrfs.pyt_defragment_mountpointusc	C@s_tjjj|�}tjjjd�}|rX|j|�rXtdj|���ng}|r�x�||D]}|jt	|d��qoWn�t
}xBtj|�D]1}x(|D] }||dkr�t
}Pq�q�Wq�Wt	|�}|r|drd|dkrd|d<n|sNt
|d<tjj|�rA|pDt
|d<n|j|�|S(	u�
    Defragment mounted BTRFS filesystem.
    In order to defragment a filesystem, device should be properly mounted and writable.

    If passed a device name, then defragmented whole filesystem, mounted on in.
    If passed a moun tpoint of the filesystem, then only this mount point is defragmented.

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.defragment /dev/sda1
        salt '*' btrfs.defragment /path/on/filesystem
    ubtrfsuDevice "{0}" is not mountedumount_pointupassedurange ioctl not supportedulogu<Range ioctl defragmentation is not supported in this kernel.urange(RRRt
_is_devicet_get_mountsR
RRtappendR(R&Rt
itervaluestTruetostpathtexists(	R/t	is_devicetmountstresulttmount_pointt
is_mountpointtmountpointstmpnttd_res((s6/usr/lib/python2.7/site-packages/salt/modules/btrfs.pyt
defragment�s,
"

%
cC@s�tdd�}tjjj|�i}xkg|djd�D]'}d|kr@tjdd|�^q@D](}|jdd�\}}|||<qkW|S(	u�
    List currently available BTRFS features.

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.mkfs_features
    ucmd.run_allumkfs.btrfs -O list-allustderru
u - u\s+u i(RRRRR R
RR(RRRtoptiontdescription((s6/usr/lib/python2.7/site-packages/salt/modules/btrfs.pytfeatures�s
HcC@s/i}x"|jd�dD]
}gtjdd|�jdd�D]}|j�rB|j�^qB}t|�dkrtjdd|d	�jdd
�j�}|dkr|djd
�}|d	j�||<|djdd�jd�}|d|dj||d	�<q'|d||<qqW|S(u
    Parse usage/overall.
    u
iu\s+u u:iu[()]uiu_ufree_estimateduglobal_reserveu(u)u: u{0}_{1}(ufree_estimateduglobal_reserve(R
RRRtlentreplacetlowerR(trawRRtitemtkeysettkeytsubk((s6/usr/lib/python2.7/site-packages/salt/modules/btrfs.pyt_usage_overall�sF+!cC@s�d�}|jd�}|djd�\}}}|jdd�jdd�j�}i}i||<x7||gD])}||j||jdd���quWx>|d	D]2}||j|tjd
d|j����q�W|S(u
    Parse usage/specific.
    cS@stt|jd��g�S(Nu:(tdictttupleR
(tval((s6/usr/lib/python2.7/site-packages/salt/modules/btrfs.pyt<lambda>�su
iu u,u_u:uiu\s+(R
R>R?tupdateRRR(R@tget_keytsectiontsizetusedRRHR%((s6/usr/lib/python2.7/site-packages/salt/modules/btrfs.pyt_usage_specific�s	$
'0cC@ssi}xf|jd�dD]Q}tjdd|j��jd�}t|�dkr|d||d<qqW|S(u"
    Parse usage/unallocated.
    u
iu\s+u ii(R
RRRR=(R@RRRB((s6/usr/lib/python2.7/site-packages/salt/modules/btrfs.pyt_usage_unallocated�s$cC@s�tddj|��}tjjj|�i}xr|djd�D]]}|jd�rnt|�|d<qF|jd�r�t	|�|d<qF|j
t|��qFW|S(	u�
    Show in which disk the chunks are allocated.

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.usage /your/mountpoint
    ucmd.run_allubtrfs filesystem usage {0}ustdoutu

u	Overall:
uoverallu
Unallocated:
uunallocated(RRRRRR R
RRERPRJRO(R/RRRL((s6/usr/lib/python2.7/site-packages/salt/modules/btrfs.pytusage�s
cO@s�|std��ntjjjd�}x5|D]-}|j|�r1tdj|���q1q1Wdg}|jd�}|jd�}t|�dkr�|r�|jd�n|r|jd	�qn>|r�|jd
j|��n|r|jdj|��nx�d(d)d*d+d,d-d.gD]r\}}|dkrb||krbdj|d�|d<n|j|�r$|jdj||j|���q$q$W|jd�r�|jdj|jd�t	kr�t
j�p�|jd���n|jd�r|jd�n|jd �s*|jd!�n|j|�t
d"d#j|��}	tjjj|	�i|	d$d%6}
|
jt
d&|d'��|
S(/u2
    Create a file system on the specified device. By default wipes out with force.

    General options:

    * **allocsize**: Specify the BTRFS offset from the start of the device.
    * **bytecount**: Specify the size of the resultant filesystem.
    * **nodesize**: Node size.
    * **leafsize**: Specify the nodesize, the tree block size in which btrfs stores data.
    * **noforce**: Prevent force overwrite when an existing filesystem is detected on the device.
    * **sectorsize**: Specify the sectorsize, the minimum data block allocation unit.
    * **nodiscard**: Do not perform whole device TRIM operation by default.
    * **uuid**: Pass UUID or pass True to generate one.


    Options:

    * **dto**: (raid0|raid1|raid5|raid6|raid10|single|dup)
               Specify how the data must be spanned across the devices specified.
    * **mto**: (raid0|raid1|raid5|raid6|raid10|single|dup)
               Specify how metadata must be spanned across the devices specified.
    * **fts**: Features (call ``salt <host> btrfs.features`` for full list of available features)

    See the ``mkfs.btrfs(8)`` manpage for a more complete description of corresponding options description.

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.mkfs /dev/sda1
        salt '*' btrfs.mkfs /dev/sda1 noforce=True
    uNo devices specifiedubtrfsu"Device "{0}" should not be mountedu
mkfs.btrfsudtoumtoiu	-d singleu	-m singleu-d {0}u-m {0}u-luleafsizeu-Lulabelu-Ouftsu-Au	allocsizeu-bu	bytecountu-nunodesizeu-su
sectorsizeu'{0}'u{0} {1}uuuidu-U {0}u	nodiscardu-Kunoforceu-fucmd.run_allu ustdoutulogu
btrfs.infoi(u-luleafsize(u-Lulabel(u-Oufts(u-Au	allocsize(u-bu	bytecount(u-nunodesize(u-su
sectorsize(RRRRR*R
RR=R+R-tuuidtuuid1textendRtjoinR RJ(R%tkwargsR2R!tcmdtdtotmtoRCR:RR((s6/usr/lib/python2.7/site-packages/salt/modules/btrfs.pytmkfssJ!
		)C
cC@s4|dkrrtjjj|�s9tdj|���ntjjjd�j|�s�tdj|���q�ngt|�dks�|ddks�|dd	ks�t	j
d
d|dd �r�td
j|���ntddj||��}tjjj|�i|dd6}|j
td|��|S(uY
    Resize filesystem.

    General options:

    * **mountpoint**: Specify the BTRFS mountpoint to resize.
    * **size**: ([+/-]<newsize>[kKmMgGtTpPeE]|max) Specify the new size of the target.

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.resize /mountpoint size=+1g
        salt '*' btrfs.resize /dev/sda1 size=max
    umaxu)Mountpoint "{0}" should be a valid deviceubtrfsuDevice "{0}" should be mountediiu-+i����ukKmMgGtTpPeEu\duiu?Unknown size: "{0}". Expected: [+/-]<newsize>[kKmMgGtTpPeE]|maxucmd.run_allubtrfs filesystem resize {0} {1}ustdoutulogu
btrfs.info(RRRR)RRR*R
R=RRRR RJ(R'RMRR((s6/usr/lib/python2.7/site-packages/salt/modules/btrfs.pytresizees"-cC@seidd6dd6dd6dd6d	d
6dd6d
d6dd6}|jtddj|��dd�S(u�
    Check an ext2/ext3/ext4 file system.

    This is forced check to determine a filesystem is clean or not.
    NOTE: Maybe this function needs to be moved as a standard method in extfs module in a future.
    u	No errorsiuFilesystem errors correctediuSystem should be rebootediu"Filesystem errors left uncorrectediuOperational erroriuUsage or syntax erroriuFsck canceled by user requesti uShared-library errori�ucmd.run_allufsck -f -n {0}uretcodeu
Unknown error(R
RR(R!tmsgs((s6/usr/lib/python2.7/site-packages/salt/modules/btrfs.pyt	_fsck_ext�s
c
C@s�tdd�}tjjj|�tjjj|d�}|j|�sctdj|���n||dd kr�td	j|||d���ntjjj	||d�j|id!d
6g�djd
�}|dkr�td
��ntjjjtddj|���iit|�d6|d
6||dd6d6}tjjjtddj|���tjjjtddj||���tdd�}tjjj|�tjjj|d�}idd6|d
6||dd6|d<dj|�}|dd}tj
j|�sDtdj|���n|s�||ddj|�<tjdj|��j�j�|ddj|�<n�d|ddj|�<d|ddj|�<tjjjtddj|���tddj|��}tjjj|�|d|dd<dj|�}	tj
j|	�r||r|tjjjtddj|	���n|S("u�
    Convert ext2/3/4 to BTRFS. Device should be mounted.

    Filesystem can be converted temporarily so the further processing and rollback is possible,
    or permanently, where previous extended filesystem image gets deleted. Please note, permanent
    conversion takes a while as BTRFS filesystem needs to be properly rebalanced afterwards.

    General options:

    * **permanent**: Specify if the migration should be permanent (false by default)
    * **keeplf**: Keep ``lost+found`` of the partition (removed by default,
                  but still in the image, if not permanent migration)

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.convert /dev/sda1
        salt '*' btrfs.convert /dev/sda1 permanent=True
    ucmd.run_allublkid -o exportustdoutu"The device "{0}" was is not found.utypeuext2uext3uext4u(The device "{0}" is a "{1}" file system.umount_pointiu/ubOne does not simply converts a root filesystem!

Converting an extended root filesystem to BTRFS is a careful
and lengthy process, among other steps including the following
requirements:

  1. Proper verified backup.
  2. System outage.
  3. Offline system access.

For further details, please refer to your OS vendor
documentation regarding this topic.
u
umount {0}ufsck_statusubeforeubtrfs-convert {0}u
mount {0} {1}uN/Auafteru{0}/ext2_savedu6BTRFS migration went wrong: the image "{0}" not found!u	{0}_imageufile {0}/imageu{0}_image_infouremovedubtrfs subvolume delete {0}ubtrfs filesystem balance {0}ubalance_logu{0}/lost+foundu
rm -rf {0}(uext2uext3uext4N(RRRRR R$R
RRR*RR]R.R/R0tpopentreadR(
R!t	permanenttkeeplfRR%R'Rt
image_pathtorig_fstypet
lost_found((s6/usr/lib/python2.7/site-packages/salt/modules/btrfs.pytconvert�s^	#&
&)2&)cO@s�g}tjjj|�r3tdj|���nt}xWtjtjjj	d��D]7\}}x(|D] }|d|krkt
}PqkqkWqXW|s�tdj|���n|s�td��ntd�}	x;|D]3}|tj|	�kr�tdj|���q�q�Wdj|�g}
x|D]}|
j
|�q*W|d	kr�|jd
�rl|
j
d�n|jd�r�|
j
d
�q�n|
j
|�tddj|
��}tjjj|�|dr�|j
|d�n|d	kr�d}|jd�}|jd�}
|rC|
rCtddj||
|��}ntddj|��}tjjj|�|dr�|j
|d�q�ni}|r�|jidj|�d6�n|jtd|��|S(uW
    Restripe BTRFS: add or remove devices from the particular mounted filesystem.
    u1Mountpount expected, while device "{0}" specifiedubtrfsumount_pointu+No BTRFS device mounted on "{0}" mountpointuNo devices specified.u
btrfs.devicesuDevice "{0}" is not recognizedubtrfs device {0}uaddu	nodiscardu-Kuforceu-fucmd.run_allu ustdoutudcumcu3btrfs balance start -dconvert={0} -mconvert={1} {2}ubtrfs filesystem balance {0}u
ulogu
btrfs.infoN(RRRR)RRR&Rt	iteritemsR*R-RtiterkeysR+R
RUR RRJ(R't	directionR%RVtfs_logtmountedR!t	mntpointstmntdatatavailable_devicesRWRtdata_conversiontmeta_conversionR((s6/usr/lib/python2.7/site-packages/salt/modules/btrfs.pyt	_restripesb+






 cO@st|d||�S(u$
    Add a devices to a BTRFS filesystem.

    General options:

    * **nodiscard**: Do not perform whole device TRIM
    * **force**: Force overwrite existing filesystem on the disk

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.add /mountpoint /dev/sda1 /dev/sda2
    uadd(Rp(R'R%RV((s6/usr/lib/python2.7/site-packages/salt/modules/btrfs.pytaddGscO@st|d||�S(u�
    Remove devices from a BTRFS filesystem.

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.delete /mountpoint /dev/sda1 /dev/sda2
    udelete(Rp(R'R%RV((s6/usr/lib/python2.7/site-packages/salt/modules/btrfs.pytdeleteYs
cC@s`i}xS|jd�D]B}tjd|d�}t|�dkr|d||d<qqW|S(u 
    Parse properties list.
    u
u\s+iii(R
RR=(RRR((s6/usr/lib/python2.7/site-packages/salt/modules/btrfs.pyt_parse_proplistfsc

C@s�|r*|dkr*td	j|���nd
g}|jd�|j|rRdpUd
�|rx|jdj|��n|j|�|r#ysxlg|jd�D].}g|jd�D]}|j�^q�^q�D]&\}}|j|�|j|�q�WWq#tk
r}t|��q#Xntddj|��}	tj	j
j|	�|s�i}
xtj
t|	d��D]d\}}i|d6|
|<tddj||��d}|r�|jd�dp�d|
|d<quW|
SdS(uM
    List properties for given btrfs object. The object can be path of BTRFS device,
    mount point, or any directories/files inside the BTRFS filesystem.

    General options:

    * **type**: Possible types are s[ubvol], f[ilesystem], i[node] and d[evice].
    * **force**: Force overwrite existing filesystem on the disk
    * **set**: <key=value,key1=value1...> Options for a filesystem properties.

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.properties /mountpoint
        salt '*' btrfs.properties /dev/sda1 type=subvol set='ro=false,label="My Storage"'
    ususubvolufu
filesystemuiuinodeududeviceu&Unknown property type: "{0}" specifiedubtrfsupropertyusetulistu-t{0}u,u=ucmd.run_allu ustdoutudescriptionubtrfs property get {0} {1}i����uN/AuvalueN(ususubvolufu
filesystemuiuinodeududevice(RRR+R
Rt	ExceptionRRURRRR RRfRs(
tobjttypetsetRWRBRARCtvaluetexRRtproptdescr((s6/usr/lib/python2.7/site-packages/salt/modules/btrfs.pyt
propertiesss4	

K
&+(&t__doc__t
__future__RRRR.RRRtsalt.utils.fsutilsRtsalt.utils.platformtsalt.exceptionsRtsalt.extRRRRR"R%R(R9R<RERORPRQRZR[R]R&ReRpRqRrRsRR|(((s6/usr/lib/python2.7/site-packages/salt/modules/btrfs.pyt<module>s:						
	,				
		S	#	e	E		
	

Zerion Mini Shell 1.0