%PDF- %PDF-
Mini Shell

Mini Shell

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

�
���^c@@s�dZddlmZmZmZddlZddlmZddlmZej	e
�ZdZidd6Z
idd6dd6Zidd6dd6d	d
6Zidd6dd6d	d
6d	d6Zd�Zeed
�Zeed�Zeed�Zeed�Zeed�Zed�Zed�Zdeeddd�Zeddd�Zeeddd�Zd�Zedd�Zd�Z d�Z!d�Z"e#dd�Z$dS(u�
States for managing zfs datasets

:maintainer:    Jorge Schrauwen <sjorge@blackdot.be>
:maturity:      new
:depends:       salt.utils.zfs, salt.modules.zfs
:platform:      smartos, illumos, solaris, freebsd, linux

.. versionadded:: 2016.3.0
.. versionchanged:: 2018.3.1
  Big refactor to remove duplicate code, better type converions and improved
  consistancy in output.

.. code-block:: yaml

    test/shares/yuki:
      zfs.filesystem_present:
        - create_parent: true
        - properties:
            quota: 16G

    test/iscsi/haruhi:
      zfs.volume_present:
        - create_parent: true
        - volume_size: 16M
        - sparse: true
        - properties:
            readonly: on

    test/shares/yuki@frozen:
      zfs.snapshot_present

    moka_origin:
      zfs.hold_present:
        - snapshot: test/shares/yuki@frozen

    test/shares/moka:
      zfs.filesystem_present:
        - cloned_from: test/shares/yuki@frozen

    test/shares/moka@tsukune:
      zfs.snapshot_absent

i(tabsolute_importtunicode_literalstprint_functionN(tdatetime(tOrderedDictuzfsuminuteuhouriudayumonthcC@stjd�stdfStS(u
    Provides zfs state
    uzfs_supportu1The zfs state cannot be loaded: zfs not supported(t
__grains__tgettFalset__virtualname__(((s3/usr/lib/python2.7/site-packages/salt/states/zfs.pyt__virtual__Cs
cC@sFi|d6id6td6dd6}|j�}tjd|||�tjd|||�td|i|d	6�r,td
s�td|i|d6|d
6�}ntdtfg�}|d|d<|dr�d|d|<dj||�|d<qBdj||�|d<d|krB|d|d<qBndj||�|d<|S(uE
    internal shared function for *_absent

    name : string
        name of dataset
    dataset_type : string [filesystem, volume, snapshot, or bookmark]
        type of dataset to remove
    force : boolean
        try harder to destroy the dataset
    recursive : boolean
        also destroy all the child datasets

    unameuchangesuresultuucommentu%zfs.%s_absent::%s::config::force = %su)zfs.%s_absent::%s::config::recursive = %su
zfs.existsutypeutestuzfs.destroyuforceu	recursiveu	destroyedu{0} {1} was destroyedufailed to destroy {0} {1}uerroru{0} {1} is absent(tTruetlowertlogtdebugt__salt__t__opts__Rtformat(tnametdataset_typetforcet	recursivetrettmod_res((s3/usr/lib/python2.7/site-packages/salt/states/zfs.pyt_absentLs8

	
	

$


cC@sWtd|�s>i|d6id6td6dj|�d6}nt|d||�}|S(u�
    ensure filesystem is absent on the system

    name : string
        name of filesystem
    force : boolean
        try harder to destroy the dataset (zfs destroy -f)
    recursive : boolean
        also destroy all the child datasets (zfs destroy -r)

    .. warning::

        If a volume with ``name`` exists, this state will succeed without
        destroying the volume specified by ``name``. This module is dataset type sensitive.

    uzfs.is_datasetunameuchangesuresultuinvalid dataset name: {0}ucommentu
filesystem(t	__utils__RRR(RRRR((s3/usr/lib/python2.7/site-packages/salt/states/zfs.pytfilesystem_absent�s
cC@sWtd|�s>i|d6id6td6dj|�d6}nt|d||�}|S(u�
    ensure volume is absent on the system

    name : string
        name of volume
    force : boolean
        try harder to destroy the dataset (zfs destroy -f)
    recursive : boolean
        also destroy all the child datasets (zfs destroy -r)

    .. warning::

        If a filesystem with ``name`` exists, this state will succeed without
        destroying the filesystem specified by ``name``. This module is dataset type sensitive.

    uzfs.is_datasetunameuchangesuresultuinvalid dataset name: {0}ucommentuvolume(RRRR(RRRR((s3/usr/lib/python2.7/site-packages/salt/states/zfs.pyt
volume_absent�s
cC@sWtd|�s>i|d6id6td6dj|�d6}nt|d||�}|S(u
    ensure snapshot is absent on the system

    name : string
        name of snapshot
    force : boolean
        try harder to destroy the dataset (zfs destroy -f)
    recursive : boolean
        also destroy all the child datasets (zfs destroy -r)

    uzfs.is_snapshotunameuchangesuresultuinvalid snapshot name: {0}ucommentusnapshot(RRRR(RRRR((s3/usr/lib/python2.7/site-packages/salt/states/zfs.pytsnapshot_absent�s
cC@sWtd|�s>i|d6id6td6dj|�d6}nt|d||�}|S(u
    ensure bookmark is absent on the system

    name : string
        name of snapshot
    force : boolean
        try harder to destroy the dataset (zfs destroy -f)
    recursive : boolean
        also destroy all the child datasets (zfs destroy -r)

    uzfs.is_bookmarkunameuchangesuresultuinvalid bookmark name: {0}ucommentubookmark(RRRR(RRRR((s3/usr/lib/python2.7/site-packages/salt/states/zfs.pytbookmark_absent�s
cC@s�i|d6id6td6dd6}tjd||�tjd||�td|�syt|d<d	j|�|d<|Std|�s�td
|�s�|dkr�t|d<dj|�|d<|Std
|�}||kr�tdstd||i|d6�}ntdtfg�}|d|d<|drgiid|6|6|d<dj|�|d<q�dj|�|d<d|kr�|d|d<q�n:d|kr�t|d<|d|d<ndj|�|d<|S(u
    ensure hold is absent on the system

    name : string
        name of hold
    snapshot : string
        name of snapshot
    recursive : boolean
        recursively releases a hold with the given tag on the snapshots of all descendent file systems.

    unameuchangesuresultuucommentu*zfs.hold_absent::%s::config::snapshot = %su+zfs.hold_absent::%s::config::recursive = %suzfs.is_snapshotuinvalid snapshot name: {0}uzfs.is_bookmarkuerroruinvalid tag name: {0}u	zfs.holdsutestuzfs.releaseu	recursiveureleaseduhold {0} releasedufailed to release hold {0}uhold {0} is absent(	R
RR
RRRRRR(RtsnapshotRRtholdsR((s3/usr/lib/python2.7/site-packages/salt/states/zfs.pythold_absent�sL

	
	



 



cC@s�i|d6id6td6dd6}tjd||�tjd||�td|�syt|d<d	j|�|d<|Std|�s�td
|�s�|dkr�t|d<dj|�|d<|Std
|�}||kr�dj||�|d<n�tds%td||i|d6�}ntdtfg�}|d|d<|dr�t|t|dfg�fg�|d<dj||�|d<n3dj||�|d<d|kr�|d|d<n|S(u
    ensure hold is present on the system

    name : string
        name of holdt
    snapshot : string
        name of snapshot
    recursive : boolean
        recursively add hold with the given tag on the snapshots of all descendent file systems.

    unameuchangesuresultuucommentu+zfs.hold_present::%s::config::snapshot = %su,zfs.hold_present::%s::config::recursive = %suzfs.is_snapshotuinvalid snapshot name: {0}uzfs.is_bookmarkuerroruinvalid tag name: {0}u	zfs.holdsuhold {0} is present for {1}utestuzfs.holdu	recursiveuhelduhold {0} added to {1}ufailed to add hold {0} to {1}(	R
RR
RRRRRR(RRRRRR((s3/usr/lib/python2.7/site-packages/salt/states/zfs.pythold_present.sP

	
	



 

c
C@s�i|d6id6td6dd6}|d2kr7d}n|rPtd|�}n|ritd	|�}n|d3kr~i}ntjd
|||�tjd|||�tjd|||�tjd
|||�tjd|||�td|�st|d<dj|�|d<|S|rUtd|�rUt|d<dj|�|d<|Std|i|d6�retd|d|dddddt�j|t	��}|r�||d<ng}	x^|D]V}
|
|kr�tj
d|||
�q�n||
d||
kr�|	j|
�q�q�Wx�|	D]�}
tdsXtd|i||
|
6�}nt	d tfg�}|d r�||dkr�i|d|<n||
|d||
<q't|d<|ddkr�d!|d<nd"j|d|
�|d<q'W|dr)||dkr)d#j||�|d<q�|drLd$j||�|d<q�d%j||�|d<n6|rqd&nd'}tdr�t	|tfg�}no|r�|r�||d<ntd(||i|d)6|d*6�}n/td+|i|d)6|d*6|d,6|d-6�}|||d<|dra||d|<|rE||d|<nd.j|||�|d<n:d/j|d0 ||�|d<d1|kr�|d1|d<n|S(4uT
    internal handler for filesystem_present/volume_present

    dataset_type : string
        volume or filesystem
    name : string
        name of volume
    volume_size : string
        size of volume
    sparse : boolean
        create sparse volume
    create_parent : boolean
        creates all the non-existing parent datasets.
        any property specified on the command line using the -o option is ignored.
    cloned_from : string
        name of snapshot to clone
    properties : dict
        additional zfs properties (-o)

    .. note::
        ``cloned_from`` is only use if the volume does not exist yet,
        when ``cloned_from`` is set after the volume exists it will be ignored.

    .. note::
        Properties do not get cloned, if you specify the properties in the state file
        they will be applied on a subsequent run.

        ``volume_size`` is considered a property, so the volume's size will be
        corrected when the properties get updated if it differs from the
        original volume.

        The sparse parameter is ignored when using ``cloned_from``.

    unameuchangesuresultuucommentu
filesystemuvolumeu
zfs.from_sizeuzfs.from_auto_dictu,zfs.%s_present::%s::config::volume_size = %su'zfs.%s_present::%s::config::sparse = %su.zfs.%s_present::%s::config::create_parent = %su,zfs.%s_present::%s::config::cloned_from = %su+zfs.%s_present::%s::config::properties = %suzfs.is_datasetuinvalid dataset name: {0}uzfs.is_snapshotu{0} is not a snapshotu
zfs.existsutypeuzfs.getttypetfieldsuvaluetdepthitparsableuvolsizeu1zfs.%s_present::%s::update - unknown property: %sutestuzfs.setusetu*The following properties were not updated:u{0} {1}u{0} {1} was updatedu{0} {1} is uptodateu{0} {1} failed to be updateducloneducreatedu	zfs.cloneu
create_parentu
propertiesu
zfs.createuvolume_sizeusparseu{0} {1} was {2}ufailed to {0} {1} {2}i����uerror(u
filesystemuvolumeN(
R
RtNoneRR
RRRRRtwarningtappendR(
RRtvolume_sizetsparset
create_parentt
propertiestcloned_fromRtproperties_currenttproperties_updatetpropRtmod_res_action((s3/usr/lib/python2.7/site-packages/salt/states/zfs.pyt_dataset_presentws�#

			
	
	
	
	


	

	


!









c	C@std|d|d|d|�S(u�
    ensure filesystem exists and has properties set

    name : string
        name of filesystem
    create_parent : boolean
        creates all the non-existing parent datasets.
        any property specified on the command line using the -o option is ignored.
    cloned_from : string
        name of snapshot to clone
    properties : dict
        additional zfs properties (-o)

    .. note::
        ``cloned_from`` is only use if the filesystem does not exist yet,
        when ``cloned_from`` is set after the filesystem exists it will be ignored.

    .. note::
        Properties do not get cloned, if you specify the properties in the
        state file they will be applied on a subsequent run.

    u
filesystemR*R+R,(R1(RR*R+R,((s3/usr/lib/python2.7/site-packages/salt/states/zfs.pytfilesystem_present)scC@s(td||d|d|d|d|�S(u
    ensure volume exists and has properties set

    name : string
        name of volume
    volume_size : string
        size of volume
    sparse : boolean
        create sparse volume
    create_parent : boolean
        creates all the non-existing parent datasets.
        any property specified on the command line using the -o option is ignored.
    cloned_from : string
        name of snapshot to clone
    properties : dict
        additional zfs properties (-o)

    .. note::
        ``cloned_from`` is only use if the volume does not exist yet,
        when ``cloned_from`` is set after the volume exists it will be ignored.

    .. note::
        Properties do not get cloned, if you specify the properties in the state file
        they will be applied on a subsequent run.

        ``volume_size`` is considered a property, so the volume's size will be
        corrected when the properties get updated if it differs from the
        original volume.

        The sparse parameter is ignored when using ``cloned_from``.

    uvolumeR)R*R+R,(R1(RR(R)R*R+R,((s3/usr/lib/python2.7/site-packages/salt/states/zfs.pytvolume_presentIs!cC@s�i|d6id6td6dd6}tjd||�td|�sft|d<dj|�|d<|Sd	|kr�d
|kr�dj||jd� |�}||d<ntd
|�s�t|d<dj|�|d<|Std|idd6�s�tdstd||�}nt	dtfg�}|d|d<|dri||d|<dj||�|d<q�dj|�|d<d|kr�|d|d<q�n
d|d<|S(u|
    ensure bookmark exists

    name : string
        name of bookmark
    snapshot : string
        name of snapshot

    unameuchangesuresultuucommentu/zfs.bookmark_present::%s::config::snapshot = %suzfs.is_snapshotuinvalid snapshot name: {0}u#u/u{0}#{1}u@uzfs.is_bookmarkuinvalid bookmark name: {0}u
zfs.existsubookmarkutypeutestuzfs.bookmarku
bookmarkedu{0} bookmarked as {1}ufailed to bookmark {0}uerrorubookmark is present(
R
RR
RRRtindexRRR(RRRR((s3/usr/lib/python2.7/site-packages/salt/states/zfs.pytbookmark_presentus<


	






cC@s�i|d6id6td6dd6}tjd||�tjd||�|ratd|�}ntd	|�s�t|d<d
j|�|d<|Std|idd
6�sutds�td|i|d6|d6�}ntdtfg�}|d|d<|drBd|d|<|r,||d|<ndj|�|d<qdj|�|d<d|kr|d|d<qn
d|d<|S(u8
    ensure snapshot exists and has properties set

    name : string
        name of snapshot
    recursive : boolean
        recursively create snapshots of all descendent datasets
    properties : dict
        additional zfs properties (-o)

    .. note:
        Properties are only set at creation time

    unameuchangesuresultuucommentu0zfs.snapshot_present::%s::config::recursive = %su1zfs.snapshot_present::%s::config::properties = %suzfs.from_auto_dictuzfs.is_snapshotuinvalid snapshot name: {0}u
zfs.existsusnapshotutypeutestuzfs.snapshotu	recursiveu
propertiesusnapshottedusnapshot {0} was createdufailed to create snapshot {0}uerrorusnapshot is present(	R
RR
RRRRRR(RRR+RR((s3/usr/lib/python2.7/site-packages/salt/states/zfs.pytsnapshot_present�s:

	
	


$

cC@si|d6id6td6dd6}td|�sSt|d<dj|�|d<|Std|id	d
6�s�t|d<dj|�|d<n�td|id
d6dd6td6�|d
ddkr�dj|�|d<n�tds�td|�}ntdtfg�}|d|d<|drKd|d|<dj|�|d<n0dj|�|d<d|kr{|d|d<n|S(u�
    ensure a dataset is not a clone

    name : string
        name of fileset or volume

    .. warning::

        only one dataset can be the origin,
        if you promote a clone the original will now point to the promoted dataset

    unameuchangesuresultuucommentuzfs.is_datasetuinvalid dataset name: {0}u
zfs.existsufilesystem,volumeutypeudataset {0} does not existuzfs.getuoriginu
propertiesuvalueufieldsuparsableu-u{0} already promotedutestuzfs.promoteupromotedu{0} promotedufailed to promote {0}uerror(R
RRRRRR(RRR((s3/usr/lib/python2.7/site-packages/salt/states/zfs.pytpromoted�s0



:

cC@s�x�ttd|itd6dd6dd6�j��D]�}||jd�d}|jdj|��spq5ntd	|�}|s�|d
j|�nx8|D]0}||dj�kr�||j|�q�q�Wq5W|S(uA
    Update snapshots dict with current snapshots

    dataset: string
        name of filesystem or volume
    prefix : string
        prefix for the snapshots
        e.g. 'test' will result in snapshots being named 'test-yyyymmdd_hhmm'
    snapshots : OrderedDict
        preseeded OrderedDict with configuration

    uzfs.listu	recursiveiudepthusnapshotutypeu@u{0}-u	zfs.holdsu	_prunableu	_schedule(tsortedRR
tkeysR4t
startswithRR'(tdatasettprefixt	snapshotstsnapt	snap_namet
snap_holdsthold((s3/usr/lib/python2.7/site-packages/salt/states/zfs.pyt_schedule_snapshot_retrieve#s;
c	C@s�djd|d|dtj�jd��}tj�jdddd�}g|d	|<xh|d
j�D]V\}}|dkr�qjn||r�tj||ddj||��jdddd�}|d
kr�||kr�qjq�|dkr|jt�|jt�krqjq�|dkrH|jt�|jt�krHqjq�|dkrx|jt	�|jt	�krxqjq�|dkr�|jt
�|jt
�kr�qjq�n|d	|j|�qjW|S(uG
    Update snapshots dict with info for a new snapshot

    dataset: string
        name of filesystem or volume
    prefix : string
        prefix for the snapshots
        e.g. 'test' will result in snapshots being named 'test-yyyymmdd_hhmm'
    snapshots : OrderedDict
        preseeded OrderedDict with configuration

    u{dataset}@{prefix}-{timestamp}R;R<t	timestampu
%Y%m%d_%H%M%Stseconditmicrosecondu_createu	_schedulei����u{0}@{1}-%Y%m%d_%H%M%Suminuteuhourudayumonthuyear(RRtnowtstrftimetreplacetitemststrptimet	comp_hourtcomp_dayt
comp_montht	comp_yearR'(R;R<R=tsnapshot_create_namet
timestamp_nowRAt
hold_countRC((s3/usr/lib/python2.7/site-packages/salt/states/zfs.pyt_schedule_snapshot_prepareKs>	
	c

C@sdi|d6id6td6dd6}dddd	d
g}tdt�fdgfd
t�fg�}td|�s�t|d<dj|�|d<ntd|idd6�s�dj|�|d<t|d<n|s�t|�dkrdj|�|d<t|d<nd}x�|D]�}g||<||krAd|d
|<nFt||t�ri|||d
|<nt|d<dj|�|d<P||d
|7}qW|dr�|dkr�t|d<d|d<n|ds�|St	|||�}t
|||�}tjd||�tjd||�tjd||�xl|dj
�D]Z\}	}
|
s^qFntds�td|	i|d6�}ntdtfg�}|ds�t|d<d j|	�|d<n�x�|
D]�}tds�td!||	i|d6�}ntd"tfg�}|d"s>t|d<d#j||	�|d<Pn||j|	�q�W|drFd$|d<d%|dkr�g|dd%<n|dd%j|	�qFqFWx�|d
j
�D]�\}}x�|dr�t||�|kr�||jd�}	tds!td&||	i|d6�}ntd'tfg�}|d'sct|d<d#j||	�|d<ntd(|	�s�|dj|	�q�q�Wq�Wxy|dD]m}	tds�td)|	i|d6�}ntd*tfg�}|d*s�t|d<d+j|	�|d<Pq�q�W|dr>|dr>d$|d<|d|dd,<n|dr`|dr`d-|d<n|S(.u�
    maintain a set of snapshots based on a schedule

    name : string
        name of filesystem or volume
    prefix : string
        prefix for the snapshots
        e.g. 'test' will result in snapshots being named 'test-yyyymmdd_hhmm'
    recursive : boolean
        create snapshots for all children also
    schedule : dict
        dict holding the schedule, the following keys are available (minute, hour,
        day, month, and year) by default all are set to 0 the value indicated the
        number of snapshots of that type to keep around.

    .. warning::

        snapshots will only be created and pruned every time the state runs.
        a schedule must be setup to automatically run the state. this means that if
        you run the state daily the hourly snapshot will only be made once per day!

    .. versionchanged:: 2018.3.0

        switched to localtime from gmtime so times now take into account timezones.

    unameuchangesuresultuucommentuminuteuhourudayumonthuyearu_createu	_prunableu	_scheduleuzfs.is_datasetuinvalid dataset name: {0}u
zfs.existsufilesystem,volumeutypeudataset {0} does not existiu$prefix ({0}) must be at least 4 longiu(schedule value for {0} is not an integeru:schedule is not valid, you need to keep atleast 1 snapshotu2zfs.scheduled_snapshot::%s::config::recursive = %su/zfs.scheduled_snapshot::%s::config::prefix = %su*zfs.scheduled_snapshot::%s::snapshots = %sutestuzfs.snapshotu	recursiveusnapshotteduerror creating snapshot ({0})uzfs.holduheldu)error adding hold ({0}) to snapshot ({1})uscheduled snapshots updateducreateduzfs.releaseureleasedu	zfs.holdsuzfs.destroyu	destroyeduerror prunding snapshot ({1})uprunedu"scheduled snapshots are up to date(R
RRRRRtlent
isinstancetintRBRRRR
RIRR'tpop(
RR<RtscheduleRtschedule_holdsR=ttotal_countRAt
snapshot_nametsnapshot_holdsRRQ((s3/usr/lib/python2.7/site-packages/salt/states/zfs.pytscheduled_snapshot�s�

	









	
	
	





 




#
 







(%t__doc__t
__future__RRRtloggingRtsalt.utils.odictRt	getLoggert__name__RRRKRLRMRNR	RRRRRRRR R%R1R2R3R5R6R7RBRRR
R\(((s3/usr/lib/python2.7/site-packages/salt/states/zfs.pyt<module>-s6
"		:FI� ,	<=	5	(	;

Zerion Mini Shell 1.0