%PDF- %PDF-
Mini Shell

Mini Shell

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

�
���^c@@s�dZddlmZmZmZyddlZeZWnek
rQe	ZnXddl
Z
ddlZddlZ
ddlmZeje�ZdZd�Zddddd�Zd�Zd	�Zd
�Zd�Zd�Zd
�Zd�Ze	d�Zd�Z d�Z!d�Z"d�Z#d�Z$d�Z%d�Z&e	d�Z'e	d�Z(d�Z)d�Z*d�Z+d�Z,d�Z-ddd�Z.d�Z/d �Z0d!�Z1dS("u�
InfluxDB - A distributed time series database

Module to provide InfluxDB compatibility to Salt (compatible with InfluxDB
version 0.9+)

:depends:    - influxdb Python module (>= 3.0.0)

:configuration: This module accepts connection configuration details either as
    parameters or as configuration settings in /etc/salt/minion on the relevant
    minions::

        influxdb.host: 'localhost'
        influxdb.port: 8086
        influxdb.user: 'root'
        influxdb.password: 'root'

    This data can also be passed into pillar. Options passed into opts will
    overwrite options passed into pillar.

    Most functions in this module allow you to override or provide some or all
    of these settings via keyword arguments::

        salt '*' influxdb.foo_function user='influxadmin' passwd='s3cr1t'

    would override ``user`` and ``password`` while still using the defaults for
    ``host`` and ``port``.
i(tabsolute_importtprint_functiontunicode_literalsN(tSTATE_INTERNAL_KEYWORDSuinfluxdbcC@str
tStdfS(u.
    Only load if influxdb lib is present
    uQThe influxdb execution module could not be loaded:influxdb library not available.(tHAS_INFLUXDBt__virtualname__tFalse(((s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pyt__virtual__3sc
K@s�|stddd�}n|s8tddd�}n|sTtddd�}n|sptddd�}nx$tD]}||krw||=qwqwWtjd	|d
|d|d||�S(
Nu
config.optionu
influxdb.userurootuinfluxdb.passwordu
influxdb.hostu	localhostu
influxdb.porti�thosttporttusernametpassword(t__salt__t_STATE_INTERNAL_KEYWORDStinfluxdbtInfluxDBClient(t
influxdb_usertinfluxdb_passwordt
influxdb_hostt
influxdb_porttclient_argstignore((s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pyt_client=s 
cK@st|�}|j�S(uv
    List all InfluxDB databases.

    CLI Example:

    .. code-block:: bash

        salt '*' influxdb.list_dbs
    (Rtget_list_database(Rtclient((s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pytlist_dbsPs
cK@s1|gt|�D]}|d^qkr-tStS(u�
    Checks if a database exists in InfluxDB.

    name
        Name of the database to check.

    CLI Example:

    .. code-block:: bash

        salt '*' influxdb.db_exists <name>
    uname(RtTrueR(tnameRtdb((s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pyt	db_exists_s
)cK@s@t||�r#tjd|�tSt|�}|j|�tS(u�
    Create a database.

    name
        Name of the database to create.

    CLI Example:

    .. code-block:: bash

        salt '*' influxdb.create_db <name>
    uDB '%s' already exists(RtlogtinfoRRtcreate_databaseR(RRR((s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pyt	create_dbrs

cK@s@t||�s#tjd|�tSt|�}|j|�tS(u�
    Drop a database.

    name
        Name of the database to drop.

    CLI Example:

    .. code-block:: bash

        salt '*' influxdb.drop_db <name>
    uDB '%s' does not exist(RRRRRt
drop_databaseR(RRR((s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pytdrop_db�s

cK@st|�}|j�S(uk
    List all users.

    CLI Example:

    .. code-block:: bash

        salt '*' influxdb.list_users
    (Rtget_list_users(RR((s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pyt
list_users�s
cK@st||�rtStS(u�
    Check if a user exists.

    name
        Name of the user to check.

    CLI Example:

    .. code-block:: bash

        salt '*' influxdb.user_exists <name>
    (t	user_infoRR(RR((s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pytuser_exists�s
c@sB�fd�t|�D�}yt|�SWntk
r=nXdS(u�
    Get information about given user.

    name
        Name of the user for which to get information.

    CLI Example:

    .. code-block:: bash

        salt '*' influxdb.user_info <name>
    c3@s*|] }|jd��kr|VqdS(uuserN(tget(t.0tuser(R(s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pys	<genexpr>�sN(R%tnextt
StopIteration(RRtmatching_users((Rs</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pyR&�s


cK@sFt||�r#tjd|�tSt|�}|j|||�tS(u�
    Create a user.

    name
        Name of the user to create.

    passwd
        Password of the new user.

    admin : False
        Whether the user should have cluster administration
        privileges or not.

    CLI Example:

    .. code-block:: bash

        salt '*' influxdb.create_user <name> <password>
        salt '*' influxdb.create_user <name> <password> admin=True
    uUser '%s' already exists(R'RRRRtcreate_userR(RtpasswdtadminRR((s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pyR.�scK@sCt||�s#tjd|�tSt|�}|j||�tS(u�
    Change password of a user.

    name
        Name of the user for whom to set the password.

    passwd
        New password of the user.

    CLI Example:

    .. code-block:: bash

        salt '*' influxdb.set_user_password <name> <password>
    uUser '%s' does not exist(R'RRRRtset_user_passwordR(RR/RR((s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pyR1�scK@st|�}|j|�tS(u�
    Grant cluster administration privileges to a user.

    name
        Name of the user to whom admin privileges will be granted.

    CLI Example:

    .. code-block:: bash

        salt '*' influxdb.grant_admin_privileges <name>
    (Rtgrant_admin_privilegesR(RRR((s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pyR2s

cK@st|�}|j|�tS(u�
    Revoke cluster administration privileges from a user.

    name
        Name of the user from whom admin privileges will be revoked.

    CLI Example:

    .. code-block:: bash

        salt '*' influxdb.revoke_admin_privileges <name>
    (Rtrevoke_admin_privilegesR(RRR((s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pyR3$s

cK@s@t||�s#tjd|�tSt|�}|j|�tS(u�
    Remove a user.

    name
        Name of the user to remove

    CLI Example:

    .. code-block:: bash

        salt '*' influxdb.remove_user <name>
    uUser '%s' does not exist(R'RRRRt	drop_userR(RRR((s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pytremove_user7s

c@sLt|�}y't�fd�|j|�D��SWntk
rGiSXdS(u&
    Get an existing retention policy.

    database
        Name of the database for which the retention policy was
        defined.

    name
        Name of the retention policy.

    CLI Example:

    .. code-block:: bash

        salt '*' influxdb.get_retention_policy metrics default
    c3@s*|] }|jd��kr|VqdS(unameN(R((R)tp(R(s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pys	<genexpr>bsN(RR+tget_list_retention_policiesR,(tdatabaseRRR((Rs</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pytget_retention_policyNs
'
cK@st|||�rtStS(uB
    Check if retention policy with given name exists.

    database
        Name of the database for which the retention policy was
        defined.

    name
        Name of the retention policy to check.

    CLI Example:

    .. code-block:: bash

        salt '*' influxdb.retention_policy_exists metrics default
    (R9RR(R8RR((s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pytretention_policy_existshscK@s t|�}|j||�tS(u
    Drop a retention policy.

    database
        Name of the database for which the retention policy will be dropped.

    name
        Name of the retention policy to drop.

    CLI Example:

    .. code-block:: bash

        salt '*' influxdb.drop_retention_policy mydb mypr
    (Rtdrop_retention_policyR(R8RRR((s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pyR;scK@s)t|�}|j|||||�tS(u�
    Create a retention policy.

    database
        Name of the database for which the retention policy will be created.

    name
        Name of the new retention policy.

    duration
        Duration of the new retention policy.

        Durations such as 1h, 90m, 12h, 7d, and 4w, are all supported and mean
        1 hour, 90 minutes, 12 hours, 7 day, and 4 weeks, respectively. For
        infinite retention – meaning the data will never be deleted – use 'INF'
        for duration. The minimum retention period is 1 hour.

    replication
        Replication factor of the retention policy.

        This determines how many independent copies of each data point are
        stored in a cluster.

    default : False
        Whether or not the policy as default will be set as default.

    CLI Example:

    .. code-block:: bash

        salt '*' influxdb.create_retention_policy metrics default 1d 1
    (Rtcreate_retention_policyR(R8RtdurationtreplicationtdefaultRR((s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pyR<�s&cK@s)t|�}|j|||||�tS(u�
    Modify an existing retention policy.

    name
        Name of the retention policy to modify.

    database
        Name of the database for which the retention policy was defined.

    duration
        New duration of given retention policy.

        Durations such as 1h, 90m, 12h, 7d, and 4w, are all supported
        and mean 1 hour, 90 minutes, 12 hours, 7 day, and 4 weeks,
        respectively. For infinite retention – meaning the data will
        never be deleted – use 'INF' for duration.
        The minimum retention period is 1 hour.

    replication
        New replication of given retention policy.

        This determines how many independent copies of each data point are
        stored in a cluster.

    default : False
        Whether or not to set the modified policy as default.

    CLI Example:

    .. code-block:: bash

        salt '*' influxdb.alter_retention_policy metrics default 1d 1
    (Rtalter_retention_policyR(R8RR=R>R?RR((s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pyR@�s'cK@sRt|�}i}x9|j|�D](}|dj�dj�||d<q"W|S(u�
    List privileges from a user.

    name
        Name of the user from whom privileges will be listed.

    CLI Example:

    .. code-block:: bash

        salt '*' influxdb.list_privileges <name>
    u	privilegeiudatabase(Rtget_list_privilegestsplittlower(RRRtrestitem((s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pytlist_privileges�s

&cK@s#t|�}|j|||�tS(u
    Grant a privilege on a database to a user.

    database
        Name of the database to grant the privilege on.

    privilege
        Privilege to grant. Can be one of 'read', 'write' or 'all'.

    username
        Name of the user to grant the privilege to.
    (Rtgrant_privilegeR(R8t	privilegeR
RR((s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pyRGs
cK@s#t|�}|j|||�tS(u
    Revoke a privilege on a database from a user.

    database
        Name of the database to grant the privilege on.

    privilege
        Privilege to grant. Can be one of 'read', 'write' or 'all'.

    username
        Name of the user to grant the privilege to.
    (Rtrevoke_privilegeR(R8RHR
RR((s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pyRIs
cK@st|||�rtStS(uR
    Check if continuous query with given name exists on the database.

    database
        Name of the database for which the continuous query was
        defined.

    name
        Name of the continuous query to check.

    CLI Example:

    .. code-block:: bash

        salt '*' influxdb.continuous_query_exists metrics default
    (tget_continuous_queryRR(R8RR((s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pytcontinuous_query_exists*sc@syt|�}yTxM|jd�j�D]6\}}|d|kr%t�fd�|D��Sq%WWntk
rtiSXiS(u+
    Get an existing continuous query.

    database
        Name of the database for which the continuous query was
        defined.

    name
        Name of the continuous query to get.

    CLI Example:

    .. code-block:: bash

        salt '*' influxdb.get_continuous_query mydb cq_month
    uSHOW CONTINUOUS QUERIESic3@s*|] }|jd��kr|VqdS(unameN(R((R)tcq(R(s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pys	<genexpr>Ws(RtquerytitemsR+R,(R8RRRRtcqs((Rs</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pyRJAs""
cK@s}t|�}d}|r%|d7}n|r8|d7}n|d7}|jd|d|d|d|d	|�}|j|�tS(
uX
    Create a continuous query.

    database
        Name of the database for which the continuous query will be
        created on.

    name
        Name of the continuous query to create.

    query
        The continuous query string.

    resample_time : None
        Duration between continuous query resampling.

    coverage_period : None
        Duration specifying time period per sample.

    CLI Example:

    .. code-block:: bash

        salt '*' influxdb.create_continuous_query mydb cq_month 'SELECT mean(*) INTO mydb.a_month.:MEASUREMENT FROM mydb.a_week./.*/ GROUP BY time(5m), *' u,CREATE CONTINUOUS QUERY {name} ON {database}u RESAMPLE EVERY {resample_time}u FOR {coverage_period}u BEGIN {query} ENDRR8RMt
resample_timetcoverage_period(RtformatRMR(R8RRMRPRQRRt
full_query((s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pytcreate_continuous_query]s


		
cK@s/t|�}dj||�}|j|�tS(u'
    Drop a continuous query.

    database
        Name of the database for which the continuous query will
        be drop from.

    name
        Name of the continuous query to drop.

    CLI Example:

    .. code-block:: bash

        salt '*' influxdb.drop_continuous_query mydb my_cq
    u DROP CONTINUOUS QUERY {0} ON {1}(RRRRMR(R8RRRRM((s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pytdrop_continuous_query�s
cC@s�tjd��}x||j�D]n\}}|\}}|rpg|D]}|^qD||tjjj|�<qg|D]}|^qw||<qWtt|j���S(u�
    Parses a ResultSet returned from InfluxDB into a dictionary of results,
    grouped by series names and optional JSON-encoded grouping tags.
    cS@siS(N((((s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pyt<lambda>�s(	tcollectionstdefaultdictRNtsalttutilstjsontdumpstdicttsorted(t	resultsett_resultst_headert_valuest_group_tagst_value((s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pyt_pull_query_results�s3!cK@sot|�}|j|d|�}t|tj�rVg|D]}|r:t|�^q:S|rht|�nigS(u|
    Execute a query.

    database
        Name of the database to query on.

    query
        InfluxQL query string.
    R8(RRMt
isinstanceRWtSequenceRe(R8RMRRt_resultt
_query_result((s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pyRM�s

#(2t__doc__t
__future__RRRRRRtImportErrorRRWtloggingtsalt.utils.jsonRYt
salt.stateRR
t	getLoggert__name__RRRtNoneRRRR!R#R%R'R&R.R1R2R3R5R9R:R;R<R@RFRGRIRKRJRTRUReRM(((s</usr/lib/python2.7/site-packages/salt/modules/influxdbmod.pyt<module>sP


	
														-)					+		

Zerion Mini Shell 1.0