%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/modules/cassandra_cql.pyc

�
���^c	@@s�dZddlmZmZmZddlZddlZddlZddlZ	ddl
mZddlm
Z
ddlmZddlZ	dZeje�ZdZeZyfdd	lmZdd
lmZddlmZmZmZddlm Z dd
l!m"Z"e#ZWne$k
r(nXd�Z%d�Z&edd�Z(d�Z)dddddd�Z*ddddd�Z+dddddd�Z,ddddd�Z-ddddd�Z.ddddd�Z/dddddd�Z0ddddd�Z1dddddddd�Z2ddddd�Z3ddddd�Z4eddddd�Z5ddd dddddd!�Z6dd dddddd"�Z7dS(#u�
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

i(tabsolute_importtunicode_literalstprint_functionN(tCommandExecutionError(tsix(trangeussl_versionu
cassandra_cql(tCluster(tNoHostAvailable(tConnectionExceptiontConnectionShutdowntOperationTimedOut(tPlainTextAuthProvider(tdict_factorycC@str
tStdfS(u�
    Return virtual name of the module only if the python driver can be loaded.

    :return: The virtual name of the module.
    :rtype:  str
    u9Cannot load cassandra_cql module: python driver not found(t
HAS_DRIVERt__virtualname__tFalse(((s>/usr/lib/python2.7/site-packages/salt/modules/cassandra_cql.pyt__virtual__wscC@stjd|�dS(Nu,Cassandra_cql asynchronous call returned: %s(tlogterror(terrors((s>/usr/lib/python2.7/site-packages/salt/modules/cassandra_cql.pyt_async_log_errors�scC@s�|s�tjd�ytdd�}Wn&tk
rO}tjd|��nX|j|�}|s�|r�tjd||�|}q�tjd|�tdj|���n|S|S(uB
    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
    uINo property specified in function, trying to load from salt configurationu
config.optionu	cassandrau2Failed to get cassandra config options. Reason: %su"Setting default Cassandra %s to %suGNo cassandra %s specified in the configuration or passed to the module.u%ERROR: Cassandra {0} cannot be empty.(Rtdebugt__salt__t
BaseExceptionRtgetRtformat(t
property_namet
config_optiontset_defaulttdefaulttoptionstetloaded_property((s>/usr/lib/python2.7/site-packages/salt/modules/cassandra_cql.pyt_load_properties�s 
	cC@s�tdd�jdd�}i}|r�|d|d<t|kr�|tjd�s�djgtt�D]}|jd�rh|^qh�}tdj	|���q�t
t|t�|t<n|SdSdS(	u�
    Parse out ssl_options for Cassandra cluster connection.
    Make sure that the ssl_version (if any specified) is valid.
    u
config.optionu	cassandraussl_optionsuca_certsu	PROTOCOL_u, u�Invalid protocol_version specified! Please make sure that the ssl protocolversion is one from the SSLmodule. Valid options are {0}N(RRtNonetSSL_VERSIONt
startswithtjointdirtsslRRtgetattr(tssloptstssl_optstxt
valid_opts((s>/usr/lib/python2.7/site-packages/salt/modules/cassandra_cql.pyt
_get_ssl_opts�s1	c
C@sLtr0dtkr0dtkr0tdtdfStd|dd�}t|t�rZ|n|jd�}td|dddtd	d
�}td|dddtd	d�}td|dd
dtd	d�}td|dddtd	d�}ytd|d|�}t�}|rAt|d|d|d|d|dt�}n$t|d|d|d|dt�}x^t	dd�D]M}y|j
�}	PWqutk
r�tj
d|�|dkr��q�quXquW|td<|	td<itd<tjd|�||	fSWnFtk
rn6tttfk
rGtjd|�td��nXdS(u�
    Connect to a Cassandra cluster.

    :param contact_points: The Cassandra cluster addresses, can either be a string or a list of IPs.
    :type  contact_points: str or list of str
    :param cql_user:       The Cassandra user if authentication is turned on.
    :type  cql_user:       str
    :param cql_pass:       The Cassandra user password if authentication is turned on.
    :type  cql_pass:       str
    :param port:           The Cassandra cluster port, defaults to None.
    :type  port:           int
    :param protocol_version:  Cassandra protocol version to use.
    :type  port:           int
    :return:               The session and cluster objects.
    :rtype:                cluster object, session object
    ucassandra_cql_returner_clusterucassandra_cql_returner_sessionRRuclusteru,uportRRiR#uusernameu	cassandraupassworduprotocol_versionitusernametpasswordtportt
auth_providertssl_optionstprotocol_versiontcompressioniu+Cassandra cluster.connect timed out, try %siucassandra_cql_preparedu1Successfully connected to Cassandra cluster at %su,Could not connect to Cassandra cluster at %su.ERROR: Could not connect to Cassandra cluster.N(t__context__R!t
isinstancetlisttsplittTrueRR-RRtconnectR
RtwarningRt	TypeErrorRR	RRR(
tcontact_pointsR0tcql_usertcql_passR3R1R*tclustert
recontimestsession((s>/usr/lib/python2.7/site-packages/salt/modules/cassandra_cql.pyt_connect�sX$!!!			




c	C@sy+td|d|d|d|�\}}WnFtk
rNtjd��n&tk
rs}tjd|��nXt|_g}t|t�r't	d|d|d|d|�}	t
jd|	�}
|
j�\}}}
y||	}Wn)t
k
r|j|t|��}nXtjd|�ny|j|�}WnDtk
r�}tjd	||�d
j||�}t|��nX|rx�|D]�}i}xftj|�D]U\}}t|tj�s�t|tttf�s�tj|�}q�n|||<q�W|j|�q�Wn|S(u�
    Run a query on a Cassandra cluster and return a dictionary.

    :param query:          The query to execute.
    :type  query:          str
    :param contact_points: The Cassandra cluster addresses, can either be a string or a list of IPs.
    :type  contact_points: str | list[str]
    :param cql_user:       The Cassandra user if authentication is turned on.
    :type  cql_user:       str
    :param cql_pass:       The Cassandra user password if authentication is turned on.
    :type  cql_pass:       str
    :param port:           The Cassandra cluster port, defaults to None.
    :type  port:           int
    :param params:         The parameters for the query, optional.
    :type  params:         str
    :return:               A dictionary from the return values of the query
    :rtype:                list[dict]

    CLI Example:

    .. code-block:: bash

         salt 'cassandra-server' cassandra_cql.cql_query "SELECT * FROM users_by_name WHERE first_name = 'jane'"
    R=R0R>R?u(Could not get Cassandra cluster session.u<Unexpected error while getting Cassandra cluster session: %su^(\d+)\.(\d+)(?:\.(\d+))?uNew query is: %su'Failed to execute query: %s
 reason: %su.ERROR: Cassandra query failed: {0} reason: {1}(RCRRtcriticalRRtrow_factoryR6tdicttversiontretmatchtgroupstKeyErrorRtmaxRtexecuteRRRt	iteritemst	text_typetsetR7tappend(tqueryR=R0R>R?R@RBRtrettcluster_versionRItmajortminortpointtresultstmsgtresulttvaluestkeytvalue((s>/usr/lib/python2.7/site-packages/salt/modules/cassandra_cql.pyt	cql_querysL+

		

c	K@s%|jdt�}	y+td|d|d|d|�\}
}WnFtk
r`tjd��n&tk
r�}tjd|��nX|tdkr�y!|j|�}
|
td|<Wq�tk
r�}tjd	|��q�Xntd|}
t	|_
g}y=|	r$|j|
j|��}n|j
|
j|��}WnDtk
r�}tjd
||�dj||�}t|��nX|	r!|r!x�|D]�}i}xftj|�D]U\}}t|tj�s�t|tttf�s�tj|�}q�n|||<q�W|j|�q�Wn|S(u
    Run a query on a Cassandra cluster and return a dictionary.

    This function should not be used asynchronously for SELECTs -- it will not
    return anything and we don't currently have a mechanism for handling a future
    that will return results.

    :param query:          The query to execute.
    :type  query:          str
    :param statement_name: Name to assign the prepared statement in the __context__ dictionary
    :type  statement_name: str
    :param statement_arguments: Bind parameters for the SQL statement
    :type  statement_arguments: list[str]
    :param async:           Run this query in asynchronous mode
    :type  async:           bool
    :param callback_errors: Function to call after query runs if there is an error
    :type  callback_errors: Function callable
    :param contact_points: The Cassandra cluster addresses, can either be a string or a list of IPs.
    :type  contact_points: str | list[str]
    :param cql_user:       The Cassandra user if authentication is turned on.
    :type  cql_user:       str
    :param cql_pass:       The Cassandra user password if authentication is turned on.
    :type  cql_pass:       str
    :param port:           The Cassandra cluster port, defaults to None.
    :type  port:           int
    :param params:         The parameters for the query, optional.
    :type  params:         str
    :return:               A dictionary from the return values of the query
    :rtype:                list[dict]


    CLI Example:

    .. code-block:: bash

        # Insert data asynchronously
        salt this-node cassandra_cql.cql_query_with_prepare "name_insert" "INSERT INTO USERS (first_name, last_name) VALUES (?, ?)"             statement_arguments=['John','Doe'], asynchronous=True

        # Select data, should not be asynchronous because there is not currently a facility to return data from a future
        salt this-node cassandra_cql.cql_query_with_prepare "name_select" "SELECT * FROM USERS WHERE first_name=?"             statement_arguments=['John']
    uasyncR=R0R>R?u(Could not get Cassandra cluster session.u<Unexpected error while getting Cassandra cluster session: %sucassandra_cql_preparedu2Unexpected error while preparing SQL statement: %su'Failed to execute query: %s
 reason: %su.ERROR: Cassandra query failed: {0} reason: {1}(RRRCRRRDRR5tprepareRREt
execute_asynctbindRMRRRRNR6RORPR7RFRQ(RRtstatement_nametstatement_argumentstcallback_errorsR=R0R>R?tkwargstasynchronousR@RBRtbound_statementRStfuture_resultsRXRYRZR[R\R]((s>/usr/lib/python2.7/site-packages/salt/modules/cassandra_cql.pytcql_query_with_preparemsL.


	

cC@s|d}yt|||||�}WnFtk
rEtjd��n&tk
rj}tjd|��nX|djd�S(u
    Show the Cassandra version.

    :param contact_points: The Cassandra cluster addresses, can either be a string or a list of IPs.
    :type  contact_points: str | list[str]
    :param cql_user:       The Cassandra user if authentication is turned on.
    :type  cql_user:       str
    :param cql_pass:       The Cassandra user password if authentication is turned on.
    :type  cql_pass:       str
    :param port:           The Cassandra cluster port, defaults to None.
    :type  port:           int
    :return:               The version for this Cassandra cluster.
    :rtype:                str

    CLI Example:

    .. code-block:: bash

        salt 'minion1' cassandra_cql.version

        salt 'minion1' cassandra_cql.version contact_points=minion1
    uRselect release_version
                 from system.local
                limit 1;u Could not get Cassandra version.u4Unexpected error while getting Cassandra version: %siurelease_version(R^RRRDRR(R=R0R>R?RRRSR((s>/usr/lib/python2.7/site-packages/salt/modules/cassandra_cql.pyRG�s

cC@sud}i}yt|||||�}WnFtk
rKtjd��n&tk
rp}tjd|��nX|S(u
    Show the Cassandra information for this cluster.

    :param contact_points: The Cassandra cluster addresses, can either be a string or a list of IPs.
    :type  contact_points: str | list[str]
    :param cql_user:       The Cassandra user if authentication is turned on.
    :type  cql_user:       str
    :param cql_pass:       The Cassandra user password if authentication is turned on.
    :type  cql_pass:       str
    :param port:           The Cassandra cluster port, defaults to None.
    :type  port:           int
    :return:               The information for this Cassandra cluster.
    :rtype:                dict

    CLI Example:

    .. code-block:: bash

        salt 'minion1' cassandra_cql.info

        salt 'minion1' cassandra_cql.info contact_points=minion1
    ufselect cluster_name,
                      data_center,
                      partitioner,
                      host_id,
                      rack,
                      release_version,
                      cql_version,
                      schema_version,
                      thrift_version
                 from system.local
                limit 1;uCould not list Cassandra info.u1Unexpected error while listing Cassandra info: %s(R^RRRDR(R=R0R>R?RRRSR((s>/usr/lib/python2.7/site-packages/salt/modules/cassandra_cql.pytinfo�s"

cC@s�idd6dd6}i}yt|||||�}WnFtk
rYtjd��n&tk
r~}tjd|��nX|S(u-
    List keyspaces in a Cassandra cluster.

    :param contact_points: The Cassandra cluster addresses, can either be a string or a list of IPs.
    :type  contact_points: str | list[str]
    :param cql_user:       The Cassandra user if authentication is turned on.
    :type  cql_user:       str
    :param cql_pass:       The Cassandra user password if authentication is turned on.
    :type  cql_pass:       str
    :param port:           The Cassandra cluster port, defaults to None.
    :type  port:           int
    :return:               The keyspaces in this Cassandra cluster.
    :rtype:                list[dict]

    CLI Example:

    .. code-block:: bash

        salt 'minion1' cassandra_cql.list_keyspaces

        salt 'minion1' cassandra_cql.list_keyspaces contact_points=minion1 port=9000
    u2select keyspace_name from system.schema_keyspaces;u2u2select keyspace_name from system_schema.keyspaces;u3uCould not list keyspaces.u,Unexpected error while listing keyspaces: %s(R^RRRDR(R=R0R>R?RRRSR((s>/usr/lib/python2.7/site-packages/salt/modules/cassandra_cql.pytlist_keyspaces*s


c	C@s�|rdj|�nd}idj|�d6dj|�d6}i}yt|||||�}WnFtk
r�tjd��n&tk
r�}tjd|��nX|S(	u&
    List column families in a Cassandra cluster for all keyspaces or just the provided one.

    :param keyspace:       The keyspace to provide the column families for, optional.
    :type  keyspace:       str
    :param contact_points: The Cassandra cluster addresses, can either be a string or a list of IPs.
    :type  contact_points: str | list[str]
    :param cql_user:       The Cassandra user if authentication is turned on.
    :type  cql_user:       str
    :param cql_pass:       The Cassandra user password if authentication is turned on.
    :type  cql_pass:       str
    :param port:           The Cassandra cluster port, defaults to None.
    :type  port:           int
    :return:               The column families in this Cassandra cluster.
    :rtype:                list[dict]

    CLI Example:

    .. code-block:: bash

        salt 'minion1' cassandra_cql.list_column_families

        salt 'minion1' cassandra_cql.list_column_families contact_points=minion1

        salt 'minion1' cassandra_cql.list_column_families keyspace=system
    uwhere keyspace_name = '{0}'uuOselect columnfamily_name from system.schema_columnfamilies
                {0};u2uBselect column_name from system_schema.columns
                {0};u3uCould not list column families.u2Unexpected error while listing column families: %s(RR^RRRDR(	tkeyspaceR=R0R>R?twhere_clauseRRRSR((s>/usr/lib/python2.7/site-packages/salt/modules/cassandra_cql.pytlist_column_familiesTs

cC@s�idj|�d6dj|�d6}yt|||||�}WnFtk
retjd��n&tk
r�}tjd|��nX|r�tStS(uX
    Check if a keyspace exists in a Cassandra cluster.

    :param keyspace        The keyspace name to check for.
    :type  keyspace:       str
    :param contact_points: The Cassandra cluster addresses, can either be a string or a list of IPs.
    :type  contact_points: str | list[str]
    :param cql_user:       The Cassandra user if authentication is turned on.
    :type  cql_user:       str
    :param cql_pass:       The Cassandra user password if authentication is turned on.
    :type  cql_pass:       str
    :param port:           The Cassandra cluster port, defaults to None.
    :type  port:           int
    :return:               The info for the keyspace or False if it does not exist.
    :rtype:                dict

    CLI Example:

    .. code-block:: bash

        salt 'minion1' cassandra_cql.keyspace_exists keyspace=system
    u^select keyspace_name from system.schema_keyspaces
                where keyspace_name = '{0}';u2u^select keyspace_name from system_schema.keyspaces
                where keyspace_name = '{0}';u3u'Could not determine if keyspace exists.u9Unexpected error while determining if keyspace exists: %s(RR^RRRDRR9R(RlR=R0R>R?RRRSR((s>/usr/lib/python2.7/site-packages/salt/modules/cassandra_cql.pytkeyspace_exists�s

uSimpleStrategyic
C@st|||�}|si|d6}	|r�t|tj�r�y&tjjj|�}
|	j|
�Wq�t	k
r�t
jd�tSXq�|	j|�n
||	d<dj
||	�}yt|||||�Wqtk
r�t
jd��qt	k
r}t
jd|��qXndS(u�
    Create a new keyspace in Cassandra.

    :param keyspace:                The keyspace name
    :type  keyspace:                str
    :param replication_strategy:    either `SimpleStrategy` or `NetworkTopologyStrategy`
    :type  replication_strategy:    str
    :param replication_factor:      number of replicas of data on multiple nodes. not used if using NetworkTopologyStrategy
    :type  replication_factor:      int
    :param replication_datacenters: string or dict of datacenter names to replication factors, required if using
                                    NetworkTopologyStrategy (will be a dict if coming from state file).
    :type  replication_datacenters: str | dict[str, int]
    :param contact_points:          The Cassandra cluster addresses, can either be a string or a list of IPs.
    :type  contact_points:          str | list[str]
    :param cql_user:                The Cassandra user if authentication is turned on.
    :type  cql_user:                str
    :param cql_pass:                The Cassandra user password if authentication is turned on.
    :type  cql_pass:                str
    :param port:                    The Cassandra cluster port, defaults to None.
    :type  port:                    int
    :return:                        The info for the keyspace or False if it does not exist.
    :rtype:                         dict

    CLI Example:

    .. code-block:: bash

        # CLI Example:
        salt 'minion1' cassandra_cql.create_keyspace keyspace=newkeyspace

        salt 'minion1' cassandra_cql.create_keyspace keyspace=newkeyspace replication_strategy=NetworkTopologyStrategy         replication_datacenters='{"datacenter_1": 3, "datacenter_2": 2}'
    uclassu,Could not load json replication_datacenters.ureplication_factorupcreate keyspace {0}
                     with replication = {1}
                      and durable_writes = true;uCould not create keyspace.u,Unexpected error while creating keyspace: %sN(RoR6Rtstring_typestsalttutilstjsontloadstupdateRRRRRR^RRD(
Rltreplication_strategytreplication_factortreplication_datacentersR=R0R>R?texisting_keyspacetreplication_maptreplication_datacenter_mapRRR((s>/usr/lib/python2.7/site-packages/salt/modules/cassandra_cql.pytcreate_keyspace�s.#





cC@s�t|||�}|r�dj|�}yt|||||�Wq�tk
rdtjd��q�tk
r�}tjd|��q�XntS(u�
    Drop a keyspace if it exists in a Cassandra cluster.

    :param keyspace:       The keyspace to drop.
    :type  keyspace:       str
    :param contact_points: The Cassandra cluster addresses, can either be a string or a list of IPs.
    :type  contact_points: str | list[str]
    :param cql_user:       The Cassandra user if authentication is turned on.
    :type  cql_user:       str
    :param cql_pass:       The Cassandra user password if authentication is turned on.
    :type  cql_pass:       str
    :param port:           The Cassandra cluster port, defaults to None.
    :type  port:           int
    :return:               The info for the keyspace or False if it does not exist.
    :rtype:                dict

    CLI Example:

    .. code-block:: bash

        salt 'minion1' cassandra_cql.drop_keyspace keyspace=test

        salt 'minion1' cassandra_cql.drop_keyspace keyspace=test contact_points=minion1
    udrop keyspace {0};uCould not drop keyspace.u,Unexpected error while dropping keyspace: %s(RoRR^RRRDRR9(RlR=R0R>R?RyRRR((s>/usr/lib/python2.7/site-packages/salt/modules/cassandra_cql.pyt
drop_keyspace�s


cC@sud}i}yt|||||�}WnFtk
rKtjd��n&tk
rp}tjd|��nX|S(u
    List existing users in this Cassandra cluster.

    :param contact_points: The Cassandra cluster addresses, can either be a string or a list of IPs.
    :type  contact_points: str | list[str]
    :param port:           The Cassandra cluster port, defaults to None.
    :type  port:           int
    :param cql_user:       The Cassandra user if authentication is turned on.
    :type  cql_user:       str
    :param cql_pass:       The Cassandra user password if authentication is turned on.
    :type  cql_pass:       str
    :return:               The list of existing users.
    :rtype:                dict

    CLI Example:

    .. code-block:: bash

        salt 'minion1' cassandra_cql.list_users

        salt 'minion1' cassandra_cql.list_users contact_points=minion1
    ulist users;uCould not list users.u(Unexpected error while listing users: %s(R^RRRDR(R=R0R>R?RRRSR((s>/usr/lib/python2.7/site-packages/salt/modules/cassandra_cql.pyt
list_userss

c
C@s�|rdnd}dj|||�}tjd||�yt|||||�WnFtk
rwtjd��n&tk
r�}	tjd|	��nXtS(u�
    Create a new cassandra user with credentials and superuser status.

    :param username:       The name of the new user.
    :type  username:       str
    :param password:       The password of the new user.
    :type  password:       str
    :param superuser:      Is the new user going to be a superuser? default: False
    :type  superuser:      bool
    :param contact_points: The Cassandra cluster addresses, can either be a string or a list of IPs.
    :type  contact_points: str | list[str]
    :param cql_user:       The Cassandra user if authentication is turned on.
    :type  cql_user:       str
    :param cql_pass:       The Cassandra user password if authentication is turned on.
    :type  cql_pass:       str
    :param port:           The Cassandra cluster port, defaults to None.
    :type  port:           int
    :return:
    :rtype:

    CLI Example:

    .. code-block:: bash

        salt 'minion1' cassandra_cql.create_user username=joe password=secret

        salt 'minion1' cassandra_cql.create_user username=joe password=secret superuser=True

        salt 'minion1' cassandra_cql.create_user username=joe password=secret superuser=True contact_points=minion1
    u	superuserunosuperuseru6create user if not exists {0} with password '{1}' {2};u=Attempting to create a new user with username=%s superuser=%suCould not create user.u(Unexpected error while creating user: %s(RRRR^RRDRR9(
R.R/t	superuserR=R0R>R?t
superuser_cqlRRR((s>/usr/lib/python2.7/site-packages/salt/modules/cassandra_cql.pytcreate_userDs

ukeyspacec
C@s�|rdj||�nd}|r3dj|�nd}	dj|	|�}
|rfdj|
|�}
ntjd|
�i}yt|
||||�}WnFtk
r�tjd��n&tk
r�}tjd	|��nX|S(
u�
    List permissions.

    :param username:       The name of the user to list permissions for.
    :type  username:       str
    :param resource:       The resource (keyspace or table), if None, permissions for all resources are listed.
    :type  resource:       str
    :param resource_type:  The resource_type (keyspace or table), defaults to 'keyspace'.
    :type  resource_type:  str
    :param permission:     A permission name (e.g. select), if None, all permissions are listed.
    :type  permission:     str
    :param contact_points: The Cassandra cluster addresses, can either be a string or a list of IPs.
    :type  contact_points: str | list[str]
    :param cql_user:       The Cassandra user if authentication is turned on.
    :type  cql_user:       str
    :param cql_pass:       The Cassandra user password if authentication is turned on.
    :type  cql_pass:       str
    :param port:           The Cassandra cluster port, defaults to None.
    :type  port:           int
    :return:               Dictionary of permissions.
    :rtype:                dict

    CLI Example:

    .. code-block:: bash

        salt 'minion1' cassandra_cql.list_permissions

        salt 'minion1' cassandra_cql.list_permissions username=joe resource=test_keyspace permission=select

        salt 'minion1' cassandra_cql.list_permissions username=joe resource=test_table resource_type=table           permission=select contact_points=minion1
    u{0} {1}u
all keyspacesu{0} permissionuall permissionsulist {0} on {1}u
{0} of {1}u.Attempting to list permissions with query '%s'uCould not list permissions.u.Unexpected error while listing permissions: %s(RRRR^RRDR(
R.tresourcet
resource_typet
permissionR=R0R>R?tkeyspace_cqltpermission_cqlRRRSR((s>/usr/lib/python2.7/site-packages/salt/modules/cassandra_cql.pytlist_permissionsus #

cC@s�|rdj|�nd}|r3dj||�nd}	dj||	|�}
tjd|
�yt|
||||�WnFtk
r�tjd��n&tk
r�}tjd|��nXtS(	uz
    Grant permissions to a user.

    :param username:       The name of the user to grant permissions to.
    :type  username:       str
    :param resource:       The resource (keyspace or table), if None, permissions for all resources are granted.
    :type  resource:       str
    :param resource_type:  The resource_type (keyspace or table), defaults to 'keyspace'.
    :type  resource_type:  str
    :param permission:     A permission name (e.g. select), if None, all permissions are granted.
    :type  permission:     str
    :param contact_points: The Cassandra cluster addresses, can either be a string or a list of IPs.
    :type  contact_points: str | list[str]
    :param cql_user:       The Cassandra user if authentication is turned on.
    :type  cql_user:       str
    :param cql_pass:       The Cassandra user password if authentication is turned on.
    :type  cql_pass:       str
    :param port:           The Cassandra cluster port, defaults to None.
    :type  port:           int
    :return:
    :rtype:

    CLI Example:

    .. code-block:: bash

        salt 'minion1' cassandra_cql.grant_permission

        salt 'minion1' cassandra_cql.grant_permission username=joe resource=test_keyspace permission=select

        salt 'minion1' cassandra_cql.grant_permission username=joe resource=test_table resource_type=table         permission=select contact_points=minion1
    u	grant {0}ugrant all permissionsu
on {0} {1}uon all keyspacesu{0} {1} to {2}u/Attempting to grant permissions with query '%s'uCould not grant permissions.u/Unexpected error while granting permissions: %s(RRRR^RRDRR9(R.R�R�R�R=R0R>R?R�tresource_cqlRRR((s>/usr/lib/python2.7/site-packages/salt/modules/cassandra_cql.pytgrant_permission�s#

(8t__doc__t
__future__RRRtloggingRHR'tsalt.utils.jsonRqtsalt.exceptionsRtsalt.extRtsalt.ext.six.movesRtsalt.utils.versionsR#t	getLoggert__name__RRRR
tcassandra.clusterRRtcassandra.connectionRR	R
tcassandra.authRtcassandra.queryRR9tImportErrorRRR"R!R-RCR^RiRGRjRkRnRoR|R}R~R�R�R�(((s>/usr/lib/python2.7/site-packages/salt/modules/cassandra_cql.pyt<module>QsZ

		#	SPc'2*2*	D('19

Zerion Mini Shell 1.0