%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/returners/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/returners/odbc.pyc

�
���^c@@sdZddlmZmZmZddlZddlZddlZyddl	Z	e
ZWnek
rue
ZnXdZd�Zdd�Zdd�Zd�Zd	�Zdd
�Zdd�Zd�Zd
�Zd�Zd�Zd�Ze
dd�ZdS(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(tabsolute_importtprint_functiontunicode_literalsNuodbccC@ststdfStS(Nu8Could not import odbc returner; pyodbc is not installed.(tHAS_ODBCtFalsetTrue(((s7/usr/lib/python2.7/site-packages/salt/returners/odbc.pyt__virtual__�s
cC@sLidd6dd6dd6}tjjdjt�||dtdt�}|S(u)
    Get the odbc options from salt.
    udsnuuserupasswdureturner.{0}t__salt__t__opts__(tsaltt	returnerstget_returner_optionstformatt__virtualname__RR(trettattrst_options((s7/usr/lib/python2.7/site-packages/salt/returners/odbc.pyt_get_options�s

	cC@sUt|�}|jd�}|jd�}|jd�}tjdj|||��S(u$
    Return a MSSQL connection.
    udsnuuserupasswduDSN={0};UID={1};PWD={2}(RtgettpyodbctconnectR(RRtdsntusertpasswd((s7/usr/lib/python2.7/site-packages/salt/returners/odbc.pyt	_get_conn�scC@s|j�|j�dS(u$
    Close the MySQL connection
    N(tcommittclose(tconn((s7/usr/lib/python2.7/site-packages/salt/returners/odbc.pyt_close_conn�s
c	C@s�t|�}|j�}d}|j||d|dtjjj|d�|d|dtjjj|�f�t|�dS(u'
    Return data to an odbc server
    utINSERT INTO salt_returns
            (fun, jid, retval, id, success, full_ret)
            VALUES (?, ?, ?, ?, ?, ?)ufunujidureturnuidusuccessN(RtcursortexecuteR	tutilstjsontdumpsR(RRtcurtsql((s7/usr/lib/python2.7/site-packages/salt/returners/odbc.pytreturner�scC@sTtdd�}|j�}d}|j||tjjj|�f�t|�dS(u/
    Save the load to the specified jid id
    Ru*INSERT INTO jids (jid, load) VALUES (?, ?)N(	RtNoneRRR	RR R!R(tjidtloadtminionsRR"R#((s7/usr/lib/python2.7/site-packages/salt/returners/odbc.pyt	save_load�s
%cC@sdS(u&
    Included for API consistency
    N((R&R(t	syndic_id((s7/usr/lib/python2.7/site-packages/salt/returners/odbc.pytsave_minions�scC@sgtdd�}|j�}d}|j||f�|j�}|rYtjjj|�St	|�iS(u9
    Return the load data that marks a specified jid
    Ru$SELECT load FROM jids WHERE jid = ?;N(
RR%RRtfetchoneR	RR tloadsR(R&RR"R#tdata((s7/usr/lib/python2.7/site-packages/salt/returners/odbc.pytget_load�s
cC@s�tdd�}|j�}d}|j||f�|j�}i}|rx0|D]%\}}tjjj|�||<qSWnt	|�|S(uP
    Return the information returned when the specified job id was executed
    Ru3SELECT id, full_ret FROM salt_returns WHERE jid = ?N(
RR%RRtfetchallR	RR R-R(R&RR"R#R.Rtminiontfull_ret((s7/usr/lib/python2.7/site-packages/salt/returners/odbc.pytget_jid�s 
c	C@s�tdd�}|j�}d}|j||f�|j�}i}|r�x3|D](\}}}tjjj|�||<qSWnt	|�|S(uC
    Return a dict of the last function called for all minions
    Ru�SELECT s.id,s.jid, s.full_ret
            FROM salt_returns s
            JOIN ( SELECT MAX(jid) AS jid FROM salt_returns GROUP BY fun, id) max
            ON s.jid = max.jid
            WHERE s.fun = ?
            N(
RR%RRR0R	RR R-R(	tfunRR"R#R.RR1t_tretval((s7/usr/lib/python2.7/site-packages/salt/returners/odbc.pytget_funs 
cC@s�tdd�}|j�}d}|j|�|j�}i}x?|D]7\}}tjjj|tjj	j
|��||<qGWt|�|S(u&
    Return a list of all job ids
    Ru#SELECT distinct jid, load FROM jidsN(RR%RRR0R	RR&tformat_jid_instanceR R-R(RR"R#R.RR&R'((s7/usr/lib/python2.7/site-packages/salt/returners/odbc.pytget_jids#s
/
cC@sptdd�}|j�}d}|j|�|j�}g}x|D]}|j|d�qGWt|�|S(u"
    Return a list of minions
    Ru$SELECT DISTINCT id FROM salt_returnsiN(RR%RRR0tappendR(RR"R#R.RR1((s7/usr/lib/python2.7/site-packages/salt/returners/odbc.pytget_minions4s


cC@s#|dk	r|Stjjjt�S(uO
    Do any work necessary to prepare a JID, including sending a custom id
    N(R%R	RR&tgen_jidR(tnocachet
passed_jid((s7/usr/lib/python2.7/site-packages/salt/returners/odbc.pytprep_jidEs(t__doc__t
__future__RRRtsalt.utils.jidR	tsalt.utils.jsontsalt.returnersRRRtImportErrorRR
RR%RRRR$R)R+R/R3R7R9R;R?(((s7/usr/lib/python2.7/site-packages/salt/returners/odbc.pyt<module>}s.


								

Zerion Mini Shell 1.0