%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/mssql.pyo

�
���^c@@s�dZddlmZmZmZddlmZmZddlj	j
Z
yddlZeZ
Wnek
ryeZ
nXidd6dd6d	d
6dd6dd
6ed6Zd�Zd�Zdefd��YZd�Zd�Zd�Zd�Zddd�Zd�Zd�Zd�Zddd�Zd�Zdd�Zddddd�Z d �Z!ddd!�Z"d"�Z#dddddd#�Z$d$�Z%dS(%u�
Module to provide MS SQL Server compatibility to salt.

:depends:   - FreeTDS
            - pymssql Python module

:configuration: In order to connect to MS SQL Server, certain configuration is
    required in minion configs/pillars on the relevant minions. Some sample
    pillars might look like::

        mssql.server: 'localhost'
        mssql.port:   1433
        mssql.user:   'sysdba'
        mssql.password:   'Some preferable complex password'
        mssql.database: ''

    The default for the port is '1433' and for the database is '' (empty string);
    in most cases they can be left at the default setting.
    Options that are directly passed into functions will overwrite options from
    configs or pillars.
i(tabsolute_importtprint_functiontunicode_literals(tJSONEncodertloadsNu	localhostuserveri�uportusysdbauuseruupasswordudatabaseuas_dictcC@str
tStdfS(uC
    Only load this module if all imports succeeded bin exists
    uYThe mssql execution module cannot be loaded: the pymssql python library is not available.(tHAS_ALL_IMPORTStTruetFalse(((s6/usr/lib/python2.7/site-packages/salt/modules/mssql.pyt__virtual__0scK@shi}xRd	D]J}||kr0||||<q
tdd|tj|d��||<q
Wtj|�S(
Nuserveruportuuserupasswordudatabaseuas_dictu
config.optionumssql.(userveruportuuserupasswordudatabaseuas_dict(t__salt__t	_DEFAULTStgettNonetpymssqltconnect(tkwargstconnection_argstarg((s6/usr/lib/python2.7/site-packages/salt/modules/mssql.pyt_get_connection9s
+t
_MssqlEncodercB@seZd�ZRS(cC@s
tj|�S(N(tsixt	text_type(tselfto((s6/usr/lib/python2.7/site-packages/salt/modules/mssql.pytdefaultEs(t__name__t
__module__R(((s6/usr/lib/python2.7/site-packages/salt/modules/mssql.pyRCscK@swyJt|�j�}|j|�tt�ji|j�d6��dSWn&tk
rr}dtj	|�ffSXdS(u
    Run a SQL query and return query result as list of tuples, or a list of dictionaries if as_dict was passed, or an empty list if no data is available.

    CLI Example:

    .. code-block:: bash

        salt minion mssql.tsql_query 'SELECT @@version as version' as_dict=True
    u	resultsetuCould not run the queryN(uCould not run the query(
RtcursortexecuteRRtencodetfetchallt	ExceptionRR(tqueryRtcurterr((s6/usr/lib/python2.7/site-packages/salt/modules/mssql.pyt
tsql_queryIs

+cK@s
td|�S(u
    Return the version of a MS SQL server.

    CLI Example:

    .. code-block:: bash

        salt minion mssql.version
    uSELECT @@version(R#(R((s6/usr/lib/python2.7/site-packages/salt/modules/mssql.pytversion]s
cK@s*gtddt|�D]}|d^qS(u�
    Return the database list created on a MS SQL server.

    CLI Example:

    .. code-block:: bash

        salt minion mssql.db_list
    uSELECT name FROM sys.databasestas_dicti(R#R(Rtrow((s6/usr/lib/python2.7/site-packages/salt/modules/mssql.pytdb_listjs
cK@s"ttdj|�|��dkS(u�
    Find if a specific database exists on the MS SQL server.

    CLI Example:

    .. code-block:: bash

        salt minion mssql.db_exists database_name='DBNAME'
    u6SELECT database_id FROM sys.databases WHERE NAME='{0}'i(tlenR#tformat(t
database_nameR((s6/usr/lib/python2.7/site-packages/salt/modules/mssql.pyt	db_existswsuNONEcK@s�|d	krdSdj||�}|rB|ddj|�7}nd}zTy0t|�}|jt�|j�j|�Wntk
r�}dj|�SXWd|r�|jt	�|j
�nXtS(
u�
    Creates a new database.
    Does not update options of existing databases.
    new_database_options can only be a list of strings

    CLI Example:

    .. code-block:: bash

        salt minion mssql.db_create DB_NAME
    uNONEuPARTIALu*CONTAINMENT can be one of NONE and PARTIALu(CREATE DATABASE [{0}] CONTAINMENT = {1} u WITH u, uCould not create the login: {0}N(uNONEuPARTIAL(R)tjoinRRt
autocommitRRRRRtclose(tdatabasetcontainmenttnew_database_optionsRtsqltconnte((s6/usr/lib/python2.7/site-packages/salt/modules/mssql.pyt	db_create�s"

cK@s�y�t||�r�|d	kr�t|�}|jt�|j�}|jdj|��|jdj|��|jt�|j�tStSWnt	k
r�}dj|�SXdS(
u�
    Drops a specific database from the MS SQL server.
    It will not drop any of 'master', 'model', 'msdb' or 'tempdb'.

    CLI Example:

    .. code-block:: bash

        salt minion mssql.db_remove database_name='DBNAME'
    umasterumodelumsdbutempdbu:ALTER DATABASE {0} SET SINGLE_USER WITH ROLLBACK IMMEDIATEuDROP DATABASE {0}u Could not find the database: {0}N(umasterumodelumsdbutempdb(
R+RR-RRRR)RR.R(R*RR3R!R4((s6/usr/lib/python2.7/site-packages/salt/modules/mssql.pyt	db_remove�s


cK@stdddt|�S(up
    Lists database roles.

    CLI Example:

    .. code-block:: bash

        salt minion mssql.role_list
    R usp_helproleR%(R#R(R((s6/usr/lib/python2.7/site-packages/salt/modules/mssql.pyt	role_list�scK@s+ttddj|�dt|��dkS(u~
    Checks if a role exists.

    CLI Example:

    .. code-block:: bash

        salt minion mssql.role_exists db_owner
    R usp_helprole "{0}"R%i(R(R#R)R(troleR((s6/usr/lib/python2.7/site-packages/salt/modules/mssql.pytrole_exists�scK@s�|sg}ndj|�}|r:|dj|�7}nd}z�y`t|�}|jt�|j�j|�x-|D]%}|j�jdj||��qyWWntk
r�}dj|�SXWd|r�|jt�|j	�nXtS(u�
    Creates a new database role.
    If no owner is specified, the role will be owned by the user that
    executes CREATE ROLE, which is the user argument or mssql.user option.
    grants is list of strings.

    CLI Example:

    .. code-block:: bash

        salt minion mssql.role_create role=product01 owner=sysdba grants='["SELECT", "INSERT", "UPDATE", "DELETE", "EXECUTE"]'
    uCREATE ROLE {0}u AUTHORIZATION {0}uGRANT {0} TO [{1}]uCould not create the role: {0}N(
R)RRR-RRRRRR.(R8townertgrantsRR2R3tgrantR4((s6/usr/lib/python2.7/site-packages/salt/modules/mssql.pytrole_create�s&
	

'
cK@s~yZt|�}|jt�|j�}|jdj|��|jt�|j�tSWntk
ry}dj|�SXdS(u�
    Remove a database role.

    CLI Example:

    .. code-block:: bash

        salt minion mssql.role_create role=test_role01
    u
DROP ROLE {0}uCould not create the role: {0}N(RR-RRRR)R.R(R8RR3R!R4((s6/usr/lib/python2.7/site-packages/salt/modules/mssql.pytrole_removes



cK@sh|rdj||�}ny)ttddj|�|��dkSWntk
rc}dj|�SXdS(u�
    Find if a login exists in the MS SQL server.
    domain, if provided, will be prepended to login

    CLI Example:

    .. code-block:: bash

        salt minion mssql.login_exists 'LOGIN'
    u{0}\{1}R u/SELECT name FROM sys.syslogins WHERE name='{0}'iuCould not find the login: {0}N(R)R(R#R(tlogintdomainRR4((s6/usr/lib/python2.7/site-packages/salt/modules/mssql.pytlogin_existss)c
K@s�t|�t|�krtSt|||�r2tS|rMdj||�}n|s\g}n|skg}ndj|�}|r�|d7}nGt|tj�r�|jddj|��n|jddj|��|r�|ddj|�7}nd}z�y`t
|�}|jt�|j
�j|�x-|D]%}|j
�jd	j||��q3WWntk
r|}	d
j|	�SXWd|r�|jt�|j�nXtS(uK
    Creates a new login.  Does not update password of existing logins.  For
    Windows authentication, provide ``new_login_domain``.  For SQL Server
    authentication, prvide ``new_login_password``.  Since hashed passwords are
    *varbinary* values, if the ``new_login_password`` is 'int / long', it will
    be considered to be HASHED.

    new_login_roles
        a list of SERVER roles

    new_login_options
        a list of strings

    CLI Example:

    .. code-block:: bash

        salt minion mssql.login_create LOGIN_NAME database=DBNAME [new_login_password=PASSWORD]
    u{0}\{1}uCREATE LOGIN [{0}] u FROM WINDOWS iuPASSWORD=0x{0:x} HASHEDuPASSWORD=N'{0}'u WITH u, u(ALTER SERVER ROLE [{0}] ADD MEMBER [{1}]uCould not create the login: {0}N(tboolRRAR)t
isinstanceRt
integer_typestinsertR,RRR-RRRRR.(
R?tnew_login_passwordtnew_login_domaintnew_login_rolestnew_login_optionsRR2R3R8R4((s6/usr/lib/python2.7/site-packages/salt/modules/mssql.pytlogin_create.s@		


'
cK@s~yZt|�}|jt�|j�}|jdj|��|jt�|j�tSWntk
ry}dj|�SXdS(uy
    Removes an login.

    CLI Example:

    .. code-block:: bash

        salt minion mssql.login_remove LOGINNAME
    uDROP LOGIN [{0}]uCould not remove the login: {0}N(	RR-RRRR)RR.R(R?RR3R!R4((s6/usr/lib/python2.7/site-packages/salt/modules/mssql.pytlogin_removeis



cK@sS|rdj||�}n|r.||d<nttddj|�|��dkS(u�
    Find if an user exists in a specific database on the MS SQL server.
    domain, if provided, will be prepended to username

    CLI Example:

    .. code-block:: bash

        salt minion mssql.user_exists 'USERNAME' [database='DBNAME']
    u{0}\{1}udatabaseR u*SELECT name FROM sysusers WHERE name='{0}'i(R)R(R#(tusernameR@R/R((s6/usr/lib/python2.7/site-packages/salt/modules/mssql.pytuser_existss

cK@s*gtddt|�D]}|d^qS(u�
    Get the user list for a specific database on the MS SQL server.

    CLI Example:

    .. code-block:: bash

        salt minion mssql.user_list [database='DBNAME']
    u9SELECT name FROM sysusers where issqluser=1 or isntuser=1R%i(R#R(RR&((s6/usr/lib/python2.7/site-packages/salt/modules/mssql.pyt	user_list�s
cK@s�|r|rdSt|||�r0dj|�S|ridj||�}|r`dj||�n|}n|r|||d<n|s�g}n|s�g}ndj|�}|r�|dj|�7}n
|d7}|r�|dd	j|�7}nd}z�y`t|�}|jt�|j�j|�x-|D]%}	|j�jd
j|	|��q.WWnt	k
rw}
dj|
�SXWd|r�|jt
�|j�nXtS(
u2
    Creates a new user.  If login is not specified, the user will be created
    without a login.  domain, if provided, will be prepended to username.
    options can only be a list of strings

    CLI Example:

    .. code-block:: bash

        salt minion mssql.user_create USERNAME database=DBNAME
    u"domain cannot be set without loginuUser {0} already existsu{0}\{1}udatabaseuCREATE USER [{0}] u FOR LOGIN [{0}]u WITHOUT LOGINu WITH u, u!ALTER ROLE [{0}] ADD MEMBER [{1}]uCould not create the user: {0}N(RMR)R,RRR-RRRRRR.(RLR?R@R/trolestoptionsRR2R3R8R4((s6/usr/lib/python2.7/site-packages/salt/modules/mssql.pytuser_create�sB

!
		


'
cK@s�d|krtSyZt|�}|jt�|j�}|jdj|��|jt�|j�tSWntk
r�}dj|�SXdS(u�
    Removes an user.

    CLI Example:

    .. code-block:: bash

        salt minion mssql.user_remove USERNAME database=DBNAME
    udatabaseu
DROP USER {0}uCould not create the user: {0}N(	RRR-RRRR)R.R(RLRR3R!R4((s6/usr/lib/python2.7/site-packages/salt/modules/mssql.pytuser_remove�s


(&t__doc__t
__future__RRRtjsonRRtsalt.ext.sixtextRR
RRtImportErrorRR
RRRR#R$R'R+RR5R6R7R9R=R>RARJRKRMRNRQRR(((s6/usr/lib/python2.7/site-packages/salt/modules/mssql.pyt<module>sF



			
		
	
	!			%	;		
6

Zerion Mini Shell 1.0