%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/utils/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/utils/etcd_util.pyc

�
���^c@@s�dZddlmZmZmZddlZddlmZddlm	Z	y,ddl
Z
ddlmZm
Z
eZWnek
r�eZnXeje�Zdefd��YZd	efd
��YZed�Zd�ZdS(
u

Utilities for working with etcd

.. versionadded:: 2014.7.0

:depends:  - python-etcd

This library sets up a client object for etcd, using the configuration passed
into the client() function. Normally, this is __opts__. Optionally, a profile
may be passed in. The following configurations are both valid:

.. code-block:: yaml

    # No profile name
    etcd.host: 127.0.0.1
    etcd.port: 2379
    etcd.username: larry  # Optional; requires etcd.password to be set
    etcd.password: 123pass  # Optional; requires etcd.username to be set
    etcd.ca: /path/to/your/ca_cert/ca.pem # Optional
    etcd.client_key: /path/to/your/client_key/client-key.pem # Optional; requires etcd.ca and etcd.client_cert to be set
    etcd.client_cert: /path/to/your/client_cert/client.pem # Optional; requires etcd.ca and etcd.client_key to be set

    # One or more profiles defined
    my_etcd_config:
      etcd.host: 127.0.0.1
      etcd.port: 2379
      etcd.username: larry  # Optional; requires etcd.password to be set
      etcd.password: 123pass  # Optional; requires etcd.username to be set
      etcd.ca: /path/to/your/ca_cert/ca.pem # Optional
      etcd.client_key: /path/to/your/client_key/client-key.pem # Optional; requires etcd.ca and etcd.client_cert to be set
      etcd.client_cert: /path/to/your/client_cert/client.pem # Optional; requires etcd.ca and etcd.client_key to be set

Once configured, the client() function is passed a set of opts, and optionally,
the name of a profile to be used.

.. code-block:: python

    import salt.utils.etcd_utils
    client = salt.utils.etcd_utils.client(__opts__, profile='my_etcd_config')

You may also use the newer syntax and bypass the generator function.

.. code-block:: python

    import salt.utils.etcd_utils
    client = salt.utils.etcd_utils.EtcdClient(__opts__, profile='my_etcd_config')

It should be noted that some usages of etcd require a profile to be specified,
rather than top-level configurations. This being the case, it is better to
always use a named configuration profile, as shown above.
i(tabsolute_importtunicode_literalstprint_functionN(tsix(tCommandExecutionError(tReadTimeoutErrort
MaxRetryErrortEtcdUtilWatchTimeoutcB@seZdZRS(u6
    A watch timed out without returning a result
    (t__name__t
__module__t__doc__(((s8/usr/lib/python2.7/site-packages/salt/utils/etcd_util.pyRJst
EtcdClientc	B@s�eZddddddddd�Zeddd�Zed�Zeeddd�Zdd�Zdd�Z	ded�Z
ded	�Zd
�Zed�Z
ed�Zd
�ZRS(c
K@s)|jdi�}|jdi�}i}
|
j|�|
j|�|
j|�|ro|
j|i�|_n	|
|_|p�|jjdd�}|p�|jjdd�}|p�|jjd�}|p�|jjd�}|p�|jjd	�}|p|jjd
�}|	p#|jjd�}i}|ra|raitj|�d6tj|�d
6}ni}|r�|pv|r�itj|�d6dd6}n|r�|r�|r�||f}itj|�d6|d6dd6}n|j�}|j|�trtj|||�|_	nt
d��dS(Nupillarumasteru	etcd.hostu	127.0.0.1u	etcd.portiK	u
etcd.usernameu
etcd.passworduetcd.cauetcd.client_keyuetcd.client_certuusernameupassworduca_certuhttpsuprotocolucertu9(unable to import etcd, module most likely not installed)(tgettupdatetconfRt	text_typetcopytHAS_LIBStetcdtClienttclientR(tselftoptstprofilethosttporttusernametpasswordtcat
client_keytclient_certtkwargstopts_pillartopts_mastertopts_mergedtca_certtcli_keytcli_certtauthtcertstcerttxargs((s8/usr/lib/python2.7/site-packages/salt/utils/etcd_util.pyt__init__RsL


	


ic
C@s�i|d6dd6td6dd6td6}y+|j|d|dtd	|d
|�}Wn�tk
r�y|j|�}Wn3tjk
r�tjd�|St	k
r�iSX|r�t
|d�r�t|d<nt
|d�|d<t
|d�|d<|Stjtfk
r#tj
d
|�iSt	k
r4iSX|dkrEiS|rdt
|dd�|d<nt
|dd�|d<t
|dd�|d<t|d<t
|d�|d<|S(NukeyuvalueuchangediumIndexudirt	recursivetwaitttimeoutt	waitIndexu(etcd: key was not created while watchingu
modifiedIndexuKetcd: failed to perform 'watch' operation on key %s due to connection error(tNonetFalsetreadtTrueRRtEtcdKeyNotFoundtlogtdebugt
ValueErrortgetattrtEtcdConnectionFailedRterror(RtkeytrecurseR-tindextrettresult((s8/usr/lib/python2.7/site-packages/salt/utils/etcd_util.pytwatch�sF
+





cC@svy|j|d|�}WnJtjk
r0dStjk
rTtjd|�dStk
redSXt|dd�S(NR+uIetcd: failed to perform 'get' operation on key %s due to connection erroruvalue(	R1RR3R/R8R4R9R6R7(RR:R;R>((s8/usr/lib/python2.7/site-packages/salt/utils/etcd_util.pyR�s
c
C@s�y[|r6|jj|d|d|d|d|�}n$|jj|d|d|d|�}Wn*tjtjfk
r�}tjd|��n�tk
r�|r�tjd�t	dj
|���ntjd�tjd	��n�tk
r}tjd
�tjd��nttjk
rB}tjdj
|���nFt
k
rbtjd
��n&tk
r�}tjd|��nX|S(NR+R,R-R.uetcd: %su&etcd: Timed out while executing a waituWatch on {0} timed outuetcd: Timed outuConnection faileduetcd: Could not connectu Could not connect to etcd serveru	etcd: {0}uZetcd: error. python-etcd does not fully support python 2.6, no error information availableuetcd: uncaught exception %s(RR1RR8R3R4R9RR5RtformatRt
EtcdExceptionR6t	Exception(RR:R+R,R-R.R>terr((s8/usr/lib/python2.7/site-packages/salt/utils/etcd_util.pyR1�s4-(





ucC@s�t|j��dkr#ii|6S|jd�}i}x�tj|�D]�\}}|jd�}|r~dj||�}ndj|�}t|t�r�|j||�}|j	|�qH|||<qHW|S(Niu/u/{0}/{1}u/{0}(
tlentkeyststripRt	iteritemsR@t
isinstancetdictt_flattenR
(RtdatatpathtflattktvtpR=((s8/usr/lib/python2.7/site-packages/salt/utils/etcd_util.pyRJ�scC@s�t|t�s tjd�dS|j||�}i}xWtj|�D]F\}}t}t|t�rrt	}n|j
||d|�||<qHW|S(Nu$etcd.update: fields is not type dictt	directory(RHRIR4R9R/RJRRGR0R2twrite(RtfieldsRLRERNROtis_dir((s8/usr/lib/python2.7/site-packages/salt/utils/etcd_util.pyR
�s
	 cC@s|j||d|d|�S(NtttlRQ(RR(RR:tvalueRURQ((s8/usr/lib/python2.7/site-packages/salt/utils/etcd_util.pytset
scC@s�|rd}ny%|jj||d|d|�}Wn�tjtjtjtfk
ro}tj	d|�dSt
k
r�}tj	d|�dStk
r�}tj	d|��nX|r�t|d�St|d�SdS(NRUtdiruetcd: %su*etcd: Could not connect to etcd server: %suetcd: uncaught exception %sudiruvalue(
R/RRRRtEtcdNotFilet
EtcdNotDirtEtcdRootReadOnlyR6R4R9RRBR7(RR:RVRURQR>RC((s8/usr/lib/python2.7/site-packages/salt/utils/etcd_util.pyRR
s 	%$
cC@s�i}y|j|�}Wn?tjtfk
r6iStjk
rZtjd|�dSXxd|jD]Y}|j	t
kr�|j|kr�qendj|j�}i||<qe|j
||j<qeWi||6S(NuIetcd: failed to perform 'ls' operation on path %s due to connection erroru{0}/(R1RR3R6R8R4R9R/tchildrenRXR2R:R@RV(RRLR=titemstitemtdir_name((s8/usr/lib/python2.7/site-packages/salt/utils/etcd_util.pytls"s 
cC@s|j||�S(N(tdelete(RR:R;((s8/usr/lib/python2.7/site-packages/salt/utils/etcd_util.pytrm6sc	C@s�y$|jj|d|�rtStSWn�tjtjtjtjt	fk
re}t
jd|�dSt
k
r�}t
jd|�dStk
r�}t
jd|��nXdS(NR+uetcd: %su*etcd: Could not connect to etcd server: %suetcd: uncaught exception %s(RRaR2R0RRYR[tEtcdDirNotEmptyR3R6R4R9R/RRB(RR:R+RC((s8/usr/lib/python2.7/site-packages/salt/utils/etcd_util.pyRa9s*cC@s�i}y|j|�}Wn?tjtfk
r6dStjk
rZtjd|�dSXx~|jD]s}t	j
|j�jd�}|j
tkr�|j|kr�qen|j|j�||d<qe|j||d<qeW|S(u`
        .. versionadded:: 2014.7.0

        Recurse through etcd and return all values
        uKetcd: failed to perform 'tree' operation on path %s due to connection erroru/i����N(R1RR3R6R/R8R4R9R\RRR:tsplitRXR2ttreeRV(RRLR=R]R^tcomps((s8/usr/lib/python2.7/site-packages/salt/utils/etcd_util.pyReIs N(RR	R/R*R0R?RR1RJR
RWRRR`RbRaRe(((s8/usr/lib/python2.7/site-packages/salt/utils/etcd_util.pyRQs7))
	cK@st|||�}|S(N(R(RRRR((s8/usr/lib/python2.7/site-packages/salt/utils/etcd_util.pytget_conncscC@s
|j|�S(N(Re(RRL((s8/usr/lib/python2.7/site-packages/salt/utils/etcd_util.pyRehs(R
t
__future__RRRtloggingtsalt.extRtsalt.exceptionsRRturllib3.exceptionsRRR2RtImportErrorR0t	getLoggerRR4RBRtobjectRR/RgRe(((s8/usr/lib/python2.7/site-packages/salt/utils/etcd_util.pyt<module>4s 


�

Zerion Mini Shell 1.0