%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/zk_concurrency.pyo

�
���^c@@s�dZddlmZmZmZddlZddlZy�ddlZddl	m
Z
ddlZddlZddl
ZddlmZddlmZddlmZdejjjfd	��YZeZWnek
r�eZnXd
Zd�Zdd�Zddd
dedddddd�
Zddd
deedddddd�Zddd
edddddd�	Z dd
edddddd�Z!dS(u�
Concurrency controls in zookeeper
=========================================================================

:depends: kazoo
:configuration: See :py:mod:`salt.modules.zookeeper` for setup instructions.

This module allows you to acquire and release a slot. This is primarily useful
for ensureing that no more than N hosts take a specific action at once. This can
also be used to coordinate between masters.
i(tabsolute_importtprint_functiontunicode_literalsN(tForceRetryError(tCancelledError(tNoNodeError(tgethostnamet
_SemaphorecB@s&eZdded�Zdd�ZRS(ic		C@s�|pt�}tjjjj|||d|d|�||_|js�y�x�|jj|j	�D]w}y]|jj
|j	d|�\}}||jd�kr�|j	d||_t
|_PnWqbtk
r�qbXqbWWq�tk
r�q�XndS(Nt
identifiert
max_leasesu/uutf-8(Rtkazootrecipetlockt	Semaphoret__init__tephemeral_leasetclienttget_childrentpathtgettdecodetcreate_pathtTruetis_acquiredR(	tselfRRRR	Rtchildtdatatstat((s?/usr/lib/python2.7/site-packages/salt/modules/zk_concurrency.pyR"s(		#	

cC@s�|jrtd��n|jr0td��n|jj|j|j�}t|�|j	kr�|jj
|j|jd|j
�n|jj|j�r�t|_n	t|_|jS(NuRetry on session loss at topuSemaphore cancelledt	ephemeral(t_session_expiredRt	cancelledRRRRt_watch_lease_changetlenR	tcreateRRRtexistsRRtFalse(RRtchildren((s?/usr/lib/python2.7/site-packages/salt/modules/zk_concurrency.pyt
_get_lease@s		%	N(t__name__t
__module__tNoneRRR%(((s?/usr/lib/python2.7/site-packages/salt/modules/zk_concurrency.pyR!suzk_concurrencycC@ststdfSitd<tS(Nu*Module zk_concurrency: dependencies failedu
semaphore_map(tHAS_DEPSR#t__context__t__virtualname__(((s?/usr/lib/python2.7/site-packages/salt/modules/zk_concurrency.pyt__virtual__ds

c
@s�|rd|�nd�d��fd�}|dd�}|dd�}|dd�}|dd�}|d	d�}t|t�r�d
j|�}n|dk	r�|dk	r�|dkr�d}nd}|r|r|r|dj||g�fg}n|dk	rWt|t�rAg|D]}	td
|	�^q"}qWtd
|�g}ntjdi�j|pr|tjj	d|d|d|��td|p�|j
s�td|p�|j�ntd|p�|S(Nu
zookeeper:u	zookeeperc@s/�j|�p.tddj�|g�|�S(uL
        look in connection_args first, then default to config file
        u
config.getu:(Rt__salt__tjoin(tkeytdefault(tconnection_argstprefix(s?/usr/lib/python2.7/site-packages/salt/modules/zk_concurrency.pyRssuhostsu127.0.0.1:2181uschemeuusernameupasswordudefault_aclu,udigestu:uzookeeper.make_digest_acluzkconnectionthoststdefault_aclt	auth_data(R(t
isinstancetlistR.R-R*t
setdefaultR
RtKazooClientt	connectedtstart(
tprofileR1RR3tschemetusernametpasswordR4R5tacl((R1R2s?/usr/lib/python2.7/site-packages/salt/modules/zk_concurrency.pyt_get_zk_connms6
$	!&
ic
C@sxtd|d|d|d|d|	d|
�}|tdkrft|||d|d	|�td|<ntd|j�S(
uO
    Return an un-ordered list of lock holders

    path
        The path in zookeeper where the lock is

    zk_hosts
        zookeeper connect string

    identifier
        Name to identify this minion, if unspecified defaults to hostname

    max_concurrency
        Maximum number of lock holders

    timeout
        timeout to wait for the lock. A None timeout will block forever

    ephemeral_lease
        Whether the locks in zookeper should be ephemeral

    Example:

    .. code-block: bash

        salt minion zk_concurrency.lock_holders /lock/path host1:1234,host2:1234
    R<R3R=R>R?R4u
semaphore_mapR	R(RAR*Rt
lease_holders(Rtzk_hostsRtmax_concurrencyttimeoutRR<R=R>R?R4tzk((s?/usr/lib/python2.7/site-packages/salt/modules/zk_concurrency.pytlock_holders�s&c

C@s�td|d|d|d|	d|
d|�}|tdkrft|||d|d	|�td|<n|r�ttd|_tjtd|_n|r�tj	d
||�td|j
d|�n"tj	d|�td|j
�td|jS(
u�
    Get lock (with optional timeout)

    path
        The path in zookeeper where the lock is

    zk_hosts
        zookeeper connect string

    identifier
        Name to identify this minion, if unspecified defaults to the hostname

    max_concurrency
        Maximum number of lock holders

    timeout
        timeout to wait for the lock. A None timeout will block forever

    ephemeral_lease
        Whether the locks in zookeper should be ephemeral

    force
        Forcibly acquire the lock regardless of available slots

    Example:

    .. code-block: bash

        salt minion zk_concurrency.lock /lock/path host1:1234,host2:1234
    R<R3R=R>R?R4u
semaphore_mapR	Ru!Acquiring lock %s with timeout=%sREu!Acquiring lock %s with no timeout(RAR*RRtassured_pathtsystmaxintR	tloggingtinfotacquireR(
RRCRRDRERtforceR<R=R>R?R4RF((s?/usr/lib/python2.7/site-packages/salt/modules/zk_concurrency.pyR�s+c

C@s�td|d|d|d|d|d|	�}
|tdkrft|
||d|d	|�td|<n|tdkr�td|j�td|=tStjd
|�tSdS(u;
    Remove lease from semaphore

    path
        The path in zookeeper where the lock is

    zk_hosts
        zookeeper connect string

    identifier
        Name to identify this minion, if unspecified defaults to hostname

    max_concurrency
        Maximum number of lock holders

    timeout
        timeout to wait for the lock. A None timeout will block forever

    ephemeral_lease
        Whether the locks in zookeper should be ephemeral

    Example:

    .. code-block: bash

        salt minion zk_concurrency.unlock /lock/path host1:1234,host2:1234
    R<R3R=R>R?R4u
semaphore_mapR	Ru Unable to find lease for path %sN(RAR*RtreleaseRRKterrorR#(RRCRRDRR=R<R>R?R4RF((s?/usr/lib/python2.7/site-packages/salt/modules/zk_concurrency.pytunlocks(c	
C@s�td|d|d|d|d|d|�}	tjjj|	|�}
|r�tjjj|	||�}|j�tjjj|	|�}
|j�nt	|
�S(u�
    Get the List of identifiers in a particular party, optionally waiting for the
    specified minimum number of nodes (min_nodes) to appear

    path
        The path in zookeeper where the lock is

    zk_hosts
        zookeeper connect string

    min_nodes
        The minimum number of nodes expected to be present in the party

    blocking
        The boolean indicating if we need to block until min_nodes are available

    Example:

    .. code-block: bash

        salt minion zk_concurrency.party_members /lock/path host1:1234,host2:1234
        salt minion zk_concurrency.party_members /lock/path host1:1234,host2:1234 min_nodes=3 blocking=True
    R<R3R=R>R?R4(
RAR
RtpartytShallowPartytbarriert
DoubleBarriertentertleaveR7(RRCt	min_nodestblockingR<R=R>R?R4RFRRRT((s?/usr/lib/python2.7/site-packages/salt/modules/zk_concurrency.pyt
party_membersCs!

("t__doc__t
__future__RRRRKRItkazoo.clientR
tkazoo.retryRtkazoo.recipe.locktkazoo.recipe.barriertkazoo.recipe.partytkazoo.exceptionsRRtsocketRRRR
RRR)tImportErrorR#R+R,R(RARGRQRZ(((s?/usr/lib/python2.7/site-packages/salt/modules/zk_concurrency.pyt<module>sr;


		.&80

Zerion Mini Shell 1.0