File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/cassandra_cql.cpython-310.pyc
Back
o ;j�� � @ s� d Z ddlZddlZddlZddlZddlZddlmZ dZ e� e�ZdZ dZzPddlmZ ddlmZmZ dd lmZmZmZ dd lmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z% ddl&m'Z' dZeee"ee%e$ee#ee!eee d � Z(W n e)y� Y nw dd� Z*dd� Z+dd� Z,d7dd�Z-dd� Z. d8dd�Z/ d8dd�Z0 d9dd�Z1 d8dd�Z2 d8d d!�Z3 d8d"d#�Z4 d:d$d%�Z5 d8d&d'�Z6 ( ) d;d*d+�Z7 d8d,d-�Z8 d8d.d/�Z9 d<d0d1�Z: 2 d=d3d4�Z; 2 d>d5d6�Z<dS )?a� Cassandra Database Module .. versionadded:: 2015.5.0 This module works with Cassandra v2 and v3 and hence generates queries based on the internal schema of said version. :depends: DataStax Python Driver for Apache Cassandra https://github.com/datastax/python-driver pip install cassandra-driver :referenced by: Salt's cassandra_cql returner :configuration: The Cassandra cluster members and connection port can either be specified in the master or minion config, the minion's pillar or be passed to the module. Example configuration in the config for a single node: .. code-block:: yaml cassandra: cluster: 192.168.50.10 port: 9000 Example configuration in the config for a cluster: .. code-block:: yaml cassandra: cluster: - 192.168.50.10 - 192.168.50.11 - 192.168.50.12 port: 9000 username: cas_admin .. versionchanged:: 2016.11.0 Added support for ``ssl_options`` and ``protocol_version``. Example configuration with `ssl options <http://datastax.github.io/python-driver/api/cassandra/cluster.html#cassandra.cluster.Cluster.ssl_options>`_: If ``ssl_options`` are present in cassandra config the cassandra_cql returner will use SSL. SSL isn't used if ``ssl_options`` isn't specified. .. code-block:: yaml cassandra: cluster: - 192.168.50.10 - 192.168.50.11 - 192.168.50.12 port: 9000 username: cas_admin ssl_options: ca_certs: /etc/ssl/certs/ca-bundle.trust.crt # SSL version should be one from the ssl module # This is an optional parameter ssl_version: PROTOCOL_TLSv1 Additionally you can also specify the ``protocol_version`` to `use <http://datastax.github.io/python-driver/api/cassandra/cluster.html#cassandra.cluster.Cluster.ssl_options>`_. .. code-block:: yaml cassandra: cluster: - 192.168.50.10 - 192.168.50.11 - 192.168.50.12 port: 9000 username: cas_admin # defaults to 4, if not set protocol_version: 3 Also all configuration could be passed directly to module as arguments. .. code-block:: bash salt minion1 cassandra_cql.info contact_points=delme-nextgen-01 port=9042 cql_user=cassandra cql_pass=cassandra protocol_version=4 salt minion1 cassandra_cql.info ssl_options='{"ca_certs": /path/to/-ca.crt}' We can also provide the load balancing policy as arguments .. code-block:: bash salt minion1 cassandra_cql.cql_query "alter user cassandra with password 'cassandra2' ;" contact_points=scylladb cql_user=user1 cql_pass=password port=9142 protocol_version=4 ssl_options='{"ca_certs": path-to-client-ca.crt}' load_balancing_policy=DCAwareRoundRobinPolicy load_balancing_policy_args='{"local_dc": "datacenter1"}' � N)�CommandExecutionError�ssl_versionZ cassandra_cqlF)�PlainTextAuthProvider)�Cluster�NoHostAvailable)�ConnectionException�ConnectionShutdown�OperationTimedOut) �DCAwareRoundRobinPolicy�ExponentialReconnectionPolicy�HostDistance�HostFilterPolicy�IdentityTranslator�LoadBalancingPolicy�NoSpeculativeExecutionPlan�NoSpeculativeExecutionPolicy�RetryPolicy�RoundRobinPolicy�SimpleConvictionPolicy�TokenAwarePolicy�WhiteListRoundRobinPolicy)�dict_factoryT) r r r r r r r r r r r r r c C s t rtS dS )z� Return virtual name of the module only if the python driver can be loaded. :return: The virtual name of the module. :rtype: str )Fz9Cannot load cassandra_cql module: python driver not found)� HAS_DRIVER�__virtualname__� r r �N/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/cassandra_cql.py�__virtual__� s r c C s t �d| � d S )Nz,Cassandra_cql asynchronous call returned: %s)�log�error)�errorsr r r �_async_log_errors� s r c K s, | t v rt �| �di |��S t�d| � dS )z8 Returns the Load Balancer Policy class by name zThe policy %s is not availableNr )�LOAD_BALANCING_POLICY_MAP�getr r )�nameZpolicy_argsr r r �_get_lbp_policy� s r$ c C s� | sIt �d� z td di d�}W n ty$ } zt �d|� � d}~ww |�|�}|sG|r9t �d||� |}|S t �d|� td |� d ���|S | S )aB Load properties for the cassandra module from config or pillar. :param property_name: The property to load. :type property_name: str or list of str :param config_option: The name of the config option. :type config_option: str :param set_default: Should a default be set if not found in config. :type set_default: bool :param default: The default value to be set. :type default: str or int :return: The property fetched from the configuration or default. :rtype: str or list of str zINo property specified in function, trying to load from salt configuration� config.option� cassandra��defaultz2Failed to get cassandra config options. Reason: %sNz"Setting default Cassandra %s to %szGNo cassandra %s specified in the configuration or passed to the module.zERROR: Cassandra z cannot be empty.)r �debug�__salt__� BaseExceptionr r"