mysql

Minion data cache plugin for MySQL database.

Added in version 2018.3.0.

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.

Warning

The mysql.database and mysql.table_name will be directly added into certain queries. Salt treats these as trusted input.

The module requires the database (default salt_cache) to exist 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:

pip install pymysql

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

mysql.host: 127.0.0.1
mysql.port: 2379
mysql.user: None
mysql.password: None
mysql.database: salt_cache
mysql.table_name: cache
# This may be enabled to create a fresh connection on every call
mysql.fresh_connection: false

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

cache: mysql
saltext.mysql.cache.mysql_cache.__virtual__()[source]

Confirm that a python mysql client is installed.

saltext.mysql.cache.mysql_cache.force_reconnect()[source]

Force a reconnection to the MySQL database, by removing the client from Salt’s __context__.

saltext.mysql.cache.mysql_cache.run_query(conn, query, args=None, retries=3)[source]

Get a cursor and run a query. Reconnect up to retries times if needed. Returns: cursor, affected rows counter Raises: SaltCacheError, AttributeError, OperationalError, InterfaceError

saltext.mysql.cache.mysql_cache.store(bank, key, data)[source]

Store a key value.

saltext.mysql.cache.mysql_cache.fetch(bank, key)[source]

Fetch a key value.

saltext.mysql.cache.mysql_cache.flush(bank, key=None)[source]

Remove the key from the cache bank with all the key content.

saltext.mysql.cache.mysql_cache.ls(bank)[source]

Return an iterable object containing all entries stored in the specified bank.

saltext.mysql.cache.mysql_cache.contains(bank, key)[source]

Checks if the specified bank contains the specified key.

saltext.mysql.cache.mysql_cache.updated(bank, key)[source]

Return the integer Unix epoch update timestamp of the specified bank and key.