%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/utils/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/utils/zfs.pyo

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZddl	m
Z
ddlmZ
ddlmZddlmZddlZddlmZejd	�Zd
ddd
ddgZeje�Zd�Zd�Zdd�Zd�Z d�Z!d�Z"dd�Z$de%d�Z&e
d��Z'e
d��Z(dddddddd�Z)d�Z*e
d��Z+e
d��Z,e
d ��Z-d!�Z.d"�Z/d#�Z0d$�Z1d%�Z2d&�Z3d'�Z4e%d(�Z5d)�Z6d*�Z7dd+�Z8de%d,�Z9dd-�Z:de%d.�Z;d/�Z<d0�Z=d1�Z>ddddddd2�Z?dddddddd3�Z@dd4�ZAdS(5u7
Utility functions for zfs

These functions are for dealing with type conversion and basic execution

:maintainer:    Jorge Schrauwen <sjorge@blackdot.be>
:maturity:      new
:depends:       salt.utils.stringutils, salt.ext, salt.module.cmdmod
:platform:      illumos,freebsd,linux

.. versionadded:: 2018.3.1

i(tabsolute_importtunicode_literalstprint_functionN(tNumber(tmemoize(tOrderedDict(tto_num(tzipu,^(\d+|\d+(?=\d*)\.\d+)([KkMmGgTtPpEe][Bb]?)$uKuMuGuTuPuEcC@s%tjjj|dddt�dkS(u4
    Simple internal wrapper for cmdmod.retcode
    toutput_logleveluquiettignore_retcodei(tsalttmodulestcmdmodtretcodetTrue(tcmd((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pyt_check_retcode(scK@sEd|krt|d<nd|kr2d|d<ntjjj|�S(u0
    Simple internal wrapper for cmdmod.run
    uignore_retcodeuoutput_logleveluquiet(RR
RRtrun_all(tkwargs((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pyt_exec/s


u cC@sBt|�|kr>|d|d!|j||d�g}n|S(u=
    Merge values all values after X into the last value
    ii(tlentjoin(tvaluestmerge_aftert
merge_with((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pyt_merge_last:s,cC@s*d|kr&||jd�d }n|S(u#
    Normalizes property names
    u@i(tindex(tname((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pyt_property_normalize_nameDscC@s�d}|jd�rd}nl|jd�r6d}nT|dkrKd}n?|dkr`d}n*|dkrud}n|dkr�d}n|S(u+
    Detect the datatype of a property
    ustruon | offubooluyes | noubool_altu<size>u
<size> | noneusizeu<count>u<count> | noneu<guid>unumericusharenfsusharesmbucanmountuversionucopies(u<size>u
<size> | none(u<count>u<count> | noneu<guid>(usharenfsusharesmbucanmount(uversionucopies(t
startswith(RRt
value_type((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pyt_property_detect_typeMs						cC@s�tt|t|t|����}t|d�|d<t|d|d�|d<t|d�|d<d|kr�t|d�|d<n|d=|S(u 
    Create a property dict
    upropertyunameuvaluesutypeuedituinherit(tdictRRRRRt	from_bool(theadertdatatprop((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pyt_property_create_dictas$cC@s|si}ni}|ddkr2|d7}ng}x�td|�djd�D]�}|j�j�}|syqUn9|ddkr�|}qUn|sU|d	d
kr�qUnt||�}|||d<|d|kr�||||d<n|d=qUW|S(u/
    Parse output of zpool/zfs get command
    i����ugetu getRustderru
iupropertyiunouyesuname(unouyes(RtsplittlowerR%(Rtaliast
propertiestprop_hdrt	prop_dataR$((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pyt_property_parse_cmdos*	
#uautocC@s�|d	kr|St�}|dkr1t�}n|dkrP|jt��n||krj||dnd}|dkr�|dkr�t�dj||�||�St�dj||�|�S(
u2
    Internal magic for from_auto and to_auto
    utoufromuzfsuautoutypeustrusizeu{}_{}(utoufrom(tproperty_data_zpooltproperty_data_zfstupdatetglobalstformat(t	directionRtvaluetsourcetconvert_to_humantpropsR((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pyt_auto�s	  cC@stjjjd�S(u6
    Return the path of the zfs binary if present
    uzfs(R
tutilstpathtwhich(((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pyt_zfs_cmd�scC@stjjjd�S(u8
    Return the path of the zpool binary if present
    uzpool(R
R8R9R:(((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pyt
_zpool_cmd�sc	
C@s�|dkrt�nt�|g}	|dkr9g}nx|D]}
|	j|
�q@W|dkrli}nxpt|�D]b}t||t�s�||g||<nx2||D]&}|	j|�|	jt|��q�WqyW|dkr�i}nxkt|�D]]}
|	j|dkrdnd�|	jdjd|
dt	|
||
ddd	t
���qW|dkrwi}nxYt|�D]K}
|	jd�|	jdjd|
dt	|
||
ddd	t
���q�W|dk	r�|dk	rxt|t�s|g}nt|t�s!|g}nxat||�D]@\}}|	jdjd|dt	||d|d	t
���q1Wq�|	j|�n|dk	r�t|t�s�|g}nx6|D]+}|dkr�q�n|	jt|��q�Wnd
j|	�S(u�
    Build and properly escape a zfs command

    .. note::

        Input is not considered safe and will be passed through
        to_auto(from_auto('input_here')), you do not need to do so
        your self first.

    uzpoolu-Ou-ou{key}={val}tkeytvalR4uzfsR5u N(
R<R;tNonetappendtsortedt
isinstancetlisttto_strR1tto_autotFalseRR(R4tcommandtflagstoptst
property_nametproperty_valuetfilesystem_propertiestpool_propertiesttargetRtflagtoptR>tfsoptR=ttgt((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pyt_command�s\$	
	
	'	
'&
cC@st}tjjj�r!t}n�tjjj�rHtd�rHt}n�tjjj�rut	j
jd�rut}notjjj�r�tjj
jd�r�t}n?tjjj
�r�t	j
jd�r�t	j
jd�r�t}ntjj
jd�o�|tkS(u*
    Check the system for ZFS support
    ukldstat -q -m zfsu/sys/module/zfsuzfs-fuseu/Library/Extensions/zfs.kextu/dev/zfsuzpool(RFR
R8tplatformtis_sunosRt
is_freebsdRtis_linuxtosR9texistsR:t	is_darwin(ton_supported_platform((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pytis_supporteds		$	'		cC@s5tjjjd�}|r1tdjd|��StS(u.
    Check if zpool-features is available
    umanu{man} zpool-featurestman(R
R8R9R:RR1RF(R]((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pythas_feature_flags3scC@s�tt�idd6dd6dd6dd6d	d
6�}ddd
dddddg}ddg}x-|D]%}itd6dd6dd6||<qfWx-|D]%}itd6dd6dd6||<q�W|S(u"
    Return a dict of zpool properties

    .. note::

        Each property will have an entry with the following info:
            - edit : boolean - is this property editable after pool creation
            - type : str - either bool, bool_alt, size, numeric, or string
            - values : str - list of possible values

    .. warning::

        This data is probed from the output of 'zpool get' with some suplimental
        data that is hardcoded. There is no better way to get this informatio aside
        from reading the code.

    uallocu	allocateduexpandu
autoexpandureplaceuautoreplaceu	listsnapsu
listsnapshotsufragu
fragmentationucapacity-allocu
capacity-freeuoperations-readuoperations-writeu
bandwith-readubandwith-writeureaduwriteucksumucapueditusizeutypeu<size>uvaluesunumericu<count>(R,R<RF(t
property_datatzpool_size_extratzpool_numeric_extraR$((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pyR-?s,


cC@sVtt�i
dd6dd6dd6dd6d	d
6dd6d
d6dd6dd6dd6�S(u]
    Return a dict of zfs properties

    .. note::

        Each property will have an entry with the following info:
            - edit : boolean - is this property editable after pool creation
            - inherit : boolean - is this property inheritable
            - type : str - either bool, bool_alt, size, numeric, or string
            - values : str - list of possible values

    .. warning::

        This data is probed from the output of 'zfs get' with some suplimental
        data that is hardcoded. There is no better way to get this informatio aside
        from reading the code.

    uavailu	availableulrefer.ulogicalreferencedulused.ulogicalusedureferu
referenceduvolblockuvolblocksizeucompressucompressionurdonlyureadonlyurecsizeu
recordsizeu	refreservurefreservationureservureservation(R,R;(((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pyR.wscC@s.|dkrd}n|r*t|�}n|S(u+
    Convert zfs numeric to python int
    unoneN(R?t
str_to_num(R3((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pytfrom_numeric�s
	cC@s%t|�}|dkr!d}n|S(u+
    Convert python int to zfs numeric
    unoneN(RcR?(R3((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pyt
to_numeric�s	cC@sC|dkrt}n*|dkr*t}n|dkr?d}n|S(	u)
    Convert zfs bool to python bool
    uonuyesuoffunounone(uonuyes(uoffunoN(RRFR?(R3((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pyR!�s			cC@s
t|�S(u-
    Convert zfs bool_alt to python bool
    (R!(R3((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pyt
from_bool_alt�scC@sIt|�}t|t�r0|r'dnd}n|dkrEd}n|S(u0
    Convert python bool to zfs on/off bool
    uonuoffunoneN(R!RBtboolR?(R3((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pytto_bool�s	cC@sIt|�}t|t�r0|r'dnd}n|dkrEd}n|S(u,
    Convert python to zfs yes/no value
    uyesunounoneN(ReRBRfR?(R3((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pytto_bool_alt�s	cC@s�tjt|��}|r�|jd�j�d}t|jd��}tjdtj	|�d�}||}t
|�|kr�t
|�}q�n|dk	r�t|�}nt|�S(u@
    Convert zfs size (human readble) to python int (bytes)
    iiiiN(
tre_zfs_sizetmatchtstrtgrouptuppertfloattmathtpowtzfs_sizeRtintR?Rc(R3t
match_sizetv_unittv_sizetv_multiplier((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pyt	from_size�s
cC@st|�}|dkr!d}nt|t�r|dkr|rttjtj|d���}tjd|�}t	|�|}|t|�kr�dj
|t|d�}qxPdddgD]<}|j
|t|d�}t|�dkr�|}Pq�q�Wn|S(	u�
    Convert python int (bytes) to zfs size

    NOTE: http://src.illumos.org/source/xref/illumos-gate/usr/src/lib/pyzfs/common/util.py#114
    unoneiu{:.0f}{}iu{:.2f}{}u{:.1f}{}iN(
RwR?RBRRrRotfloortlogRpRnR1RqR(R3R5tv_powerRvtv_size_floattv_precisionRu((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pytto_size�s&	!!cC@sn|dkrd}n|rjt|�}|jd�rU|jd�rU|dd!}n|jdd�}n|S(u;
    Decode zfs safe string (used for name, path, ...)
    unoneu"ii����u\"N(R?RkRtendswithtreplace(R3((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pytfrom_strs	cC@s]t|�}|rD|jdd�}d|krYd|d}qYn|dkrYd}n|S(u;
    Encode zfs safe string (used for name, path, ...)
    u"u\"u unoneN(R�RR?(R3((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pyRD!s	cC@std|||�S(u+
    Convert zfs value to python value
    ufrom(R7(RR3R4((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pyt	from_auto1scC@std||||�S(u+
    Convert python value to zfs value
    uto(R7(RR3R4R5((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pyRE8scC@s7x0|j�D]"\}}t|||�||<q
W|S(uk
    Pass an entire dictionary to from_auto

    .. note::
        The key will be passed as the name

    (titemsR�(RR4RR3((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pytfrom_auto_dict?scC@s:x3|j�D]%\}}t||||�||<q
W|S(uh
    Pass an entire dictionary to to_auto

    .. note::
        The key will be passed as the name
    (R�RE(RR4R5RR3((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pytto_auto_dictMscC@st|�jd�dkS(u0
    Check if name is a valid snapshot name
    u@i(R�tcount(R((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pytis_snapshotZscC@st|�jd�dkS(u0
    Check if name is a valid bookmark name
    u#i(R�R�(R((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pytis_bookmarkascC@st|�ot|�S(u<
    Check if name is a valid filesystem or volume name
    (R�R�(R((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pyt
is_datasethscC@s:tdd|d|d|d|d|d|dd
d	|�S(u�
    Build and properly escape a zfs command

    .. note::

        Input is not considered safe and will be passed through
        to_auto(from_auto('input_here')), you do not need to do so
        your self first.

    uzfsRGRHRIRJRKRLRMRNN(RSR?(RGRHRIRJRKRLRN((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pytzfs_commandoscC@s:tdd|d|d|d|d|d|d|d	|�S(
u�
    Build and properly escape a zpool command

    .. note::

        Input is not considered safe and will be passed through
        to_auto(from_auto('input_here')), you do not need to do so
        your self first.

    uzpoolRGRHRIRJRKRLRMRN(RS(RGRHRIRJRKRLRMRN((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pyt
zpool_command�scC@st�}|r&|ddk||<n|ddkrg|d<x�|dj�D]�}|j�jd�rpPn|j�jd�r�|jdd�}n|j�jd	�r�|jd
d�}n|dj|�qQW|dr�dj|d�|d<q|d=n|S(
ug
    Parse the result of a zpool/zfs command

    .. note::

        Output on failure is rather predicatable.
        - retcode > 0
        - each 'error' is a line on stderr
        - optional 'Usage:' block under those with hits

        We simple check those and return a OrderedDict were
        we set label = True|False and error = error_messages

    uretcodeiuerrorustderruusage:uuse '-f'u-fu
force=Trueuuse '-r'u-rurecursive=Trueu
(Rt
splitlinesR'RRR@R(trestlabeltretterror((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pytparse_command_result�s"	


(Bt__doc__t
__future__RRRRXtreRotloggingtnumbersRtsalt.utils.decoratorsRtreal_memoizetsalt.utils.odictRtsalt.utils.stringutilsRRbtsalt.modules.cmdmodR
tsalt.ext.six.movesRtcompileRiRqt	getLoggert__name__RyRRRRRR%R?R,RR7R;R<RSR\R^R-R.RcRdR!ReRgRhRwR}R�RDR�RER�R�R�R�R�R�R�R�(((s2/usr/lib/python2.7/site-packages/salt/utils/zfs.pyt<module>sl		
				*		S	8"		
			
	
	#		
			

Zerion Mini Shell 1.0