File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/etcd_util.cpython-310.pyc
Back
o ;jD� � @ s d Z ddlZddlZddlZddlmZ zddlZddlm Z m Z dZW n ey/ dZY nw zddl Z dZW n eyC dZY nw e�e�ZG dd� de�ZG d d � d e�ZG dd� de�ZG d d� de�ZG dd� d�ZG dd� de�ZG dd� de�Zddd�Zddd�Zdd� ZdS )a� Utilities for working with etcd .. versionadded:: 2014.7.0 :depends: - python-etcd or etcd3-py This library sets up a client object for etcd, using the configuration passed into the get_conn() 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 etcd.require_v2: True # Optional; defaults to True etcd.encode_keys: False # Optional (v3 ONLY); defaults to False etcd.encode_values: True # Optional (v3 ONLY); defaults to True etcd.raw_keys: False # Optional (v3 ONLY); defaults to False etcd.raw_values: False # Optional (v3 ONLY); defaults to False etcd.unicode_errors: "surrogateescape" # Optional (v3 ONLY); defaults to "surrogateescape" # 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 etcd.require_v2: True # Optional; defaults to True etcd.encode_keys: False # Optional (v3 ONLY); defaults to False etcd.encode_values: True # Optional (v3 ONLY); defaults to True etcd.raw_keys: False # Optional (v3 ONLY); defaults to False etcd.raw_values: False # Optional (v3 ONLY); defaults to False etcd.unicode_errors: "surrogateescape" # Optional (v3 ONLY); defaults to "surrogateescape" Encoding keys for etcd v3 allows a differentiation within etcd between byte and string keys. It is worth noting that if you chose to encode keys, due to the way encoding pre-etcd with msgpack works, all recursive functionality will not work as intended. This includes tree and ls along with all methods that have recurse kwargs. Thus, enabling this option is not recommended. 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.get_conn(__opts__, profile='my_etcd_config') You may also use the newer syntax and bypass the generator function. V2 API .. code-block:: python import salt.utils.etcd_utils client = salt.utils.etcd_utils.EtcdClient(__opts__, profile='my_etcd_config') V3 API .. versionadded:: 3005 .. code-block:: python import salt.utils.etcd_utils client = salt.utils.etcd_utils.EtcdClientV3(__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. � N)� SaltException)� MaxRetryError�ReadTimeoutErrorTFc @ � e Zd ZdZdS )�EtcdLibraryNotInstalled�2 We didn't find the required etcd library N��__name__� __module__�__qualname__�__doc__� r r �H/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/etcd_util.pyr h � r c @ r )�IncompatibleEtcdRequirementszX A user is explicitly creating a client class, but requires a different version Nr r r r r r n r r c @ r )�Etcd3DirectoryExceptionr Nr r r r r r t r r c @ r )�EtcdUtilWatchTimeoutz6 A watch timed out without returning a result Nr r r r r r z r r c @ s� e Zd ZdZ d"dd�Zd#dd�Zd$d d �Z d%dd�Zd&dd�Zd&dd�Z d'dd�Z d'dd�Zd(dd�Zd(dd�Z dd� Zd$dd�Zd$dd�Zd d!� ZdS ))�EtcdBasez� Base class for the different versions of etcd clients. This also serves as a documentation hub for all superclasses. Nc K s2 | � dd�st||�}n|}|| _|p| j� dd�| _|p#| j� dd�| _| jdkr4| jdkr4t�d� |p;| j� d�}|pC| j� d �}|pK| j� d �}|pS| j� d�} | p[| j� d�}i }|rk|rkt|�t|�d �}i }|rz|sz| szt|�dd�}|r�|r�| r�|| f}t|�|dd�}|�� | _ | j � |� d S )N� has_etcd_optsFz etcd.hostz 127.0.0.1z etcd.portiK z:Using default etcd host and port, use a profile if needed.z etcd.usernamez etcd.passwordzetcd.cazetcd.client_keyzetcd.client_cert)�username�password�https)�ca_cert�protocol)r �certr )�get�_get_etcd_opts�conf�host�port�log�warning�str�copy�xargs�update)�self�opts�profiler r r r �caZ client_keyZclient_cert�kwargsZ etcd_optsr Zcli_keyZcli_cert�auth�certsr r r r �__init__� s: �� zEtcdBase.__init__Fr c K � t � ��N��NotImplementedError)r&