%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/cache/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/cache/mysql_cache.pyo

�
���^c@@s�dZddlmZmZmZddlmZddlZy8ddlZddl	Zddl
ZddlmZWnye
k
r�yNddlZej�ddlZddl	Zddl
ZddlmZWq�e
k
r�dZq�XnXddlmZdZdZd	Zeje�Zdadadad
Zidd6Zd
�Zdd�Z d�Z!d�Z"d�Z#d�Z$dd�Z%d�Z&d�Z'dS(u�
Minion data cache plugin for MySQL database.

.. versionadded:: develop

It is up to the system administrator to set up and configure the MySQL
infrastructure. All is needed for this plugin is a working MySQL server.

The module requires the `salt_cache` database to exists but creates its own
table if needed. The keys are indexed using the `bank` and `etcd_key` columns.

To enable this cache plugin, the master will need the python client for
MySQL installed. This can be easily installed with pip:

.. code-block: bash

    pip install python-mysql

Optionally, depending on the MySQL agent configuration, the following values
could be set in the master config. These are the defaults:

.. code-block:: yaml

    mysql.host: 127.0.0.1
    mysql.port: 2379
    mysql.user: None
    mysql.password: None
    mysql.database: salt_cache
    mysql.table_name: cache

Related docs could be found in the `python-mysql documentation`_.

To use the mysql as a minion data cache backend, set the master ``cache`` config
value to ``mysql``:

.. code-block:: yaml

    cache: mysql


.. _`MySQL documentation`: https://github.com/coreos/mysql
.. _`python-mysql documentation`: http://python-mysql.readthedocs.io/en/latest/

i(tabsolute_importtprint_functiontunicode_literals(tsleepN(tOperationalError(tSaltCacheErroru
salt_cacheucacheg�������?umysqlulistulscC@s"tt�tdkrdndfS(u:
    Confirm that a python mysql client is installed.
    u!No python mysql client installed.uN(tbooltMySQLdbtNone(((s:/usr/lib/python2.7/site-packages/salt/cache/mysql_cache.pyt__virtual__UsicC@s�y)|j�}|j|�}||fSWn�ttfk
r�}|dkrS�ntt�|dkrytjd�ntj	d|�t
jt�a
tt
||d�Stk
r�}t|�dkr�|d d}ntdj||���nXdS(	u�
    Get a cursor and run a query. Reconnect up to `retries` times if
    needed.
    Returns: cursor, affected rows counter
    Raises: SaltCacheError, AttributeError, OperationalError
    iu#mysql_cache: creating db connectionu0mysql_cache: recreating db connection due to: %rii�u<...>uError running {0}: {1}N(tcursortexecutetAttributeErrorRRt_RECONNECT_INTERVAL_SECRtlogtdebugtinfoRtconnectt
_mysql_kwargstclientt	run_queryt	ExceptiontlenRtformat(tconntquerytretriestcurtoutte((s:/usr/lib/python2.7/site-packages/salt/cache/mysql_cache.pyR\s"
cC@s�djtdt�}tt|�\}}|j�}|j�|ddkrUdSdjt�}tjdt�tt|�\}}|j�dS(u 
    Create table if needed
    uqSELECT COUNT(TABLE_NAME) FROM information_schema.tables
        WHERE table_schema = '{0}' AND table_name = '{1}'udbiiNu�CREATE TABLE IF NOT EXISTS {0} (
      bank CHAR(255),
      etcd_key CHAR(255),
      data MEDIUMBLOB,
      PRIMARY KEY(bank, etcd_key)
    );umysql_cache: creating table %s(	RRt_table_nameRRtfetchonetcloseRR(RRt_tr((s:/usr/lib/python2.7/site-packages/salt/cache/mysql_cache.pyt
_create_tableys	
cC@stdk	rdSitjdd�d6tjdd�d6tjdd�d6tjd	t�d
6tjdd�d
6tjdd�d6tjdd�d6td6atjdt�ax6tj�D](\}}|dkr�tj	|�q�q�Wtj
�}d|d<tjd|�t
�dS(u5Initialize connection and create table if needed
    Nu
mysql.hostu	127.0.0.1uhostu
mysql.useruuserumysql.passwordupasswdumysql.databaseudbu
mysql.porti�uportumysql.unix_socketuunix_socketumysql.connect_timeoutuconnect_timeoutu
autocommitumysql.table_nameu<hidden>u.mysql_cache: Setting up client with params: %r(RRt__opts__tgett_DEFAULT_DATABASE_NAMEtTrueRRtitemstpoptcopyRRR#(tktvtkwargs_copy((s:/usr/lib/python2.7/site-packages/salt/cache/mysql_cache.pyt_init_client�s&

cC@st�tdj|�}djt|||�}tt|�\}}|j�|dkr{tdj|||���ndS(u
    Store a key value.
    userialsCREPLACE INTO {0} (bank, etcd_key, data) values('{1}', '{2}', '{3}')iiu"Error storing {0} {1} returned {2}N(ii(	R.t__context__tdumpsRRRRR R(tbanktkeytdataRRtcnt((s:/usr/lib/python2.7/site-packages/salt/cache/mysql_cache.pytstore�s	
cC@slt�djt||�}tt|�\}}|j�}|j�|dkrWiStdj	|d�S(u
    Fetch a key value.
    u8SELECT data FROM {0} WHERE bank='{1}' AND etcd_key='{2}'userialiN(
R.RRRRRR RR/tloads(R1R2RRR!R"((s:/usr/lib/python2.7/site-packages/salt/cache/mysql_cache.pytfetch�s
cC@s^t�djt|�}|dk	r;|dj|�7}ntt|�\}}|j�dS(uF
    Remove the key from the cache bank with all the key content.
    u DELETE FROM {0} WHERE bank='{1}'u AND etcd_key='{0}'N(R.RRRRRR (R1R2RRR!((s:/usr/lib/python2.7/site-packages/salt/cache/mysql_cache.pytflush�scC@s_t�djt|�}tt|�\}}g|j�D]}|d^q;}|j�|S(u\
    Return an iterable object containing all entries stored in the specified
    bank.
    u)SELECT etcd_key FROM {0} WHERE bank='{1}'i(R.RRRRtfetchallR (R1RRR!trowR((s:/usr/lib/python2.7/site-packages/salt/cache/mysql_cache.pytls�s#
cC@sUt�djt||�}tt|�\}}|j�}|j�|ddkS(uB
    Checks if the specified bank contains the specified key.
    u?SELECT COUNT(data) FROM {0} WHERE bank='{1}' AND etcd_key='{2}'ii(R.RRRRRR (R1R2RRR!R"((s:/usr/lib/python2.7/site-packages/salt/cache/mysql_cache.pytcontains�s
((t__doc__t
__future__RRRttimeRtloggingRtMySQLdb.cursorstMySQLdb.converterstMySQLdb.connectionsRtImportErrortpymysqltinstall_as_MySQLdbtMySQLdb.errRtsalt.exceptionsRR&t_DEFAULT_CACHE_TABLE_NAMER
t	getLoggert__name__RRRRt__virtualname__t__func_alias__R	RR#R.R5R7R8R;R<(((s:/usr/lib/python2.7/site-packages/salt/cache/mysql_cache.pyt<module>-sJ



					
	

Zerion Mini Shell 1.0