%PDF- %PDF-
Direktori : /usr/lib/python2.7/site-packages/salt/utils/ |
Current File : //usr/lib/python2.7/site-packages/salt/utils/etcd_util.pyc |
� ���^c @@ s� d Z d d l m Z m Z m Z d d l Z d d l m Z d d l m Z y, d d l Z d d l m Z m Z e Z Wn e k r� e Z n Xe j e � Z d e f d � � YZ d e f d � � YZ e d � Z d � Z d S( 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 ( t absolute_importt unicode_literalst print_functionN( t six( t CommandExecutionError( t ReadTimeoutErrort MaxRetryErrort EtcdUtilWatchTimeoutc B@ s e Z d Z RS( 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.pyR J s t EtcdClientc B@ s� e Z d d d d d d d d d � Z e d d d � Z e d � Z e e d d d � Z d d � Z d d � Z d e d � Z d e d � Z d � Z e d � Z e d � Z d � Z RS( c K@ s) | j d i � } | j d i � } i } | j | � | j | � | j | � | ro | j | i � | _ n | | _ | p� | j j d d � } | p� | j j d d � } | p� | j j d � } | p� | j j d � } | p� | j j d � } | p| j j d � } | p#| j j d � } i } | ra| rai t j | � d 6t j | � d 6} n i } | r�| pv| r�i t j | � d 6d d 6} n | r�| r�| r�| | f } i t j | � d 6| d 6d d 6} n | j � } | j | � t rt j | | | � | _ n t d � � d S( Nu pillaru masteru etcd.hostu 127.0.0.1u etcd.portiK u etcd.usernameu etcd.passwordu etcd.cau etcd.client_keyu etcd.client_certu usernameu passwordu ca_certu httpsu protocolu certu9 (unable to import etcd, module most likely not installed)( t gett updatet confR t text_typet copyt HAS_LIBSt etcdt Clientt clientR ( t selft optst profilet hostt portt usernamet passwordt cat client_keyt client_certt kwargst opts_pillart opts_mastert opts_mergedt ca_certt cli_keyt cli_certt autht certst certt xargs( ( s8 /usr/lib/python2.7/site-packages/salt/utils/etcd_util.pyt __init__R sL i c C@ s� i | d 6d d 6t d 6d d 6t d 6} y+ | j | d | d t d | d | �} Wn� t k r� y | j | � } Wn3 t j k r� t j d � | St k r� i SX| r� t | d � r� t | d <n t | d � | d <t | d � | d <| St j t f k r#t j d | � i St k r4i SX| d k rEi S| rdt | d d � | d <n t | d d � | d <t | d d � | d <t | d <t | d � | d <| S( Nu keyu valueu changedi u mIndexu dirt recursivet waitt timeoutt waitIndexu( etcd: key was not created while watchingu modifiedIndexuK etcd: failed to perform 'watch' operation on key %s due to connection error( t Nonet Falset readt TrueR R t EtcdKeyNotFoundt logt debugt ValueErrort getattrt EtcdConnectionFailedR t error( R t keyt recurseR- t indext rett result( ( s8 /usr/lib/python2.7/site-packages/salt/utils/etcd_util.pyt watch� sF + c C@ sv y | j | d | �} WnJ t j k r0 d St j k rT t j d | � d St k re d SXt | d d � S( NR+ uI etcd: failed to perform 'get' operation on key %s due to connection erroru value( R1 R R3 R/ R8 R4 R9 R6 R7 ( R R: R; R>