%PDF- %PDF-
| Direktori : /proc/self/root/proc/3522530/root/lib/python2.7/site-packages/salt/returners/ |
| Current File : //proc/self/root/proc/3522530/root/lib/python2.7/site-packages/salt/returners/odbc.pyc |
�
���^c @@ s d Z d d l m Z m Z m Z d d l Z d d l Z d d l Z y d d l Z e
Z Wn e k
ru e
Z n Xd Z d � Z d d � Z d d � Z d � Z d � Z d d
� Z d d � Z d � Z d
� Z d � Z d � Z d � Z e
d d � Z d S( u|
Return data to an ODBC compliant server. This driver was
developed with Microsoft SQL Server in mind, but theoretically
could be used to return data to any compliant ODBC database
as long as there is a working ODBC driver for it on your
minion platform.
:maintainer: C. R. Oldham (cr@saltstack.com)
:maturity: New
:depends: unixodbc, pyodbc, freetds (for SQL Server)
:platform: all
To enable this returner the minion will need
On Linux:
unixodbc (http://www.unixodbc.org)
pyodbc (`pip install pyodbc`)
The FreeTDS ODBC driver for SQL Server (http://www.freetds.org)
or another compatible ODBC driver
On Windows:
TBD
unixODBC and FreeTDS need to be configured via /etc/odbcinst.ini and
/etc/odbc.ini.
/etc/odbcinst.ini::
[TDS]
Description=TDS
Driver=/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
(Note the above Driver line needs to point to the location of the FreeTDS
shared library. This example is for Ubuntu 14.04.)
/etc/odbc.ini::
[TS]
Description = "Salt Returner"
Driver=TDS
Server = <your server ip or fqdn>
Port = 1433
Database = salt
Trace = No
Also you need the following values configured in the minion or master config.
Configure as you see fit::
returner.odbc.dsn: 'TS'
returner.odbc.user: 'salt'
returner.odbc.passwd: 'salt'
Alternative configuration values can be used by prefacing the configuration.
Any values not found in the alternative configuration will be pulled from
the default location::
alternative.returner.odbc.dsn: 'TS'
alternative.returner.odbc.user: 'salt'
alternative.returner.odbc.passwd: 'salt'
Running the following commands against Microsoft SQL Server in the desired
database as the appropriate user should create the database tables
correctly. Replace with equivalent SQL for other ODBC-compliant servers
.. code-block:: sql
--
-- Table structure for table 'jids'
--
if OBJECT_ID('dbo.jids', 'U') is not null
DROP TABLE dbo.jids
CREATE TABLE dbo.jids (
jid varchar(255) PRIMARY KEY,
load varchar(MAX) NOT NULL
);
--
-- Table structure for table 'salt_returns'
--
IF OBJECT_ID('dbo.salt_returns', 'U') IS NOT NULL
DROP TABLE dbo.salt_returns;
CREATE TABLE dbo.salt_returns (
added datetime not null default (getdate()),
fun varchar(100) NOT NULL,
jid varchar(255) NOT NULL,
retval varchar(MAX) NOT NULL,
id varchar(255) NOT NULL,
success bit default(0) NOT NULL,
full_ret varchar(MAX)
);
CREATE INDEX salt_returns_added on dbo.salt_returns(added);
CREATE INDEX salt_returns_id on dbo.salt_returns(id);
CREATE INDEX salt_returns_jid on dbo.salt_returns(jid);
CREATE INDEX salt_returns_fun on dbo.salt_returns(fun);
To use this returner, append '--return odbc' to the salt command.
.. code-block:: bash
salt '*' status.diskusage --return odbc
To use the alternative configuration, append '--return_config alternative' to the salt command.
.. versionadded:: 2015.5.0
.. code-block:: bash
salt '*' test.ping --return odbc --return_config alternative
To override individual configuration items, append --return_kwargs '{"key:": "value"}' to the salt command.
.. versionadded:: 2016.3.0
.. code-block:: bash
salt '*' test.ping --return odbc --return_kwargs '{"dsn": "dsn-name"}'
i ( t absolute_importt print_functiont unicode_literalsNu odbcc C@ s t s t d f St S( Nu8 Could not import odbc returner; pyodbc is not installed.( t HAS_ODBCt Falset True( ( ( s7 /usr/lib/python2.7/site-packages/salt/returners/odbc.pyt __virtual__� s
c C@ sL i d d 6d d 6d d 6} t j j d j t � | | d t d t �} | S( u)
Get the odbc options from salt.
u dsnu useru passwdu returner.{0}t __salt__t __opts__( t saltt returnerst get_returner_optionst formatt __virtualname__R R ( t rett attrst _options( ( s7 /usr/lib/python2.7/site-packages/salt/returners/odbc.pyt _get_options� s
c C@ sU t | � } | j d � } | j d � } | j d � } t j d j | | | � � S( u$
Return a MSSQL connection.
u dsnu useru passwdu DSN={0};UID={1};PWD={2}( R t gett pyodbct connectR ( R R t dsnt usert passwd( ( s7 /usr/lib/python2.7/site-packages/salt/returners/odbc.pyt _get_conn� s c C@ s | j � | j � d S( u$
Close the MySQL connection
N( t committ close( t conn( ( s7 /usr/lib/python2.7/site-packages/salt/returners/odbc.pyt _close_conn� s
c C@ s� t | � } | j � } d } | j | | d | d t j j j | d � | d | d t j j j | � f � t | � d S( u'