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

�
���^c@@s�dZddlmZmZmZddlZddlmZmZddl	m
Z
eje�Z
y?ddlZddlmZejd�jej�eZWnek
r�eZnXd�Zddd	�Zeddd
�Zddd�Zdeddd�Zdd
eddd�Zdddd�Zddddd�Zddddd�Zdddd�Z ddddd�Z!dddddd�Z"ddd�Z#dddd�Z$dddd�Z%ddddd�Z&ddd�Z'ddd�Z(ddd�Z)ededdd�Z*ededdd �Z+ddddd!�Z,ddd"�Z-ddd#�Z.ddddd$�Z/ddd%�Z0ddd&�Z1ddd'�Z2ddd(�Z3ddd)�Z4ddd*�Z5eddd+�Z6ddd,�Z7ddd-�Z8ddd.�Z9eddd/�Z:ddd0�Z;ddd1�Z<ddd2�Z=ddeddd3�Z>eddd4�Z?dddd5�Z@dddd6�ZAddd7�ZBdS(8u�
Elasticsearch - A distributed RESTful search and analytics server

Module to provide Elasticsearch compatibility to Salt
(compatible with Elasticsearch version 1.5.2+)

.. versionadded:: 2015.8.0

:depends:       `elasticsearch-py <http://elasticsearch-py.readthedocs.org/en/latest/>`_

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

    .. code-block:: yaml

        elasticsearch:
          host: '10.10.10.100:9200'

        elasticsearch-cluster:
          hosts:
            - '10.10.10.100:9200'
            - '10.10.10.101:9200'
            - '10.10.10.102:9200'

        elasticsearch-extra:
          hosts:
            - '10.10.10.100:9200'
          use_ssl: True
          verify_certs: True
          ca_certs: /path/to/custom_ca_bundle.pem
          number_of_shards: 1
          number_of_replicas: 0
          functions_blacklist:
            - 'saltutil.find_job'
            - 'pillar.items'
            - 'grains.items'
          proxies:
            - http: http://proxy:3128
            - https: http://proxy:1080

    When specifying proxies the requests backend will be used and the 'proxies'
    data structure is passed as-is to that module.

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

    Some functionality might be limited by elasticsearch-py and Elasticsearch server versions.
i(tabsolute_importtprint_functiontunicode_literalsN(tCommandExecutionErrortSaltInvocationError(tsix(tRequestsHttpConnectionu
elasticsearchcC@ststdfStS(u5
    Only load if elasticsearch libraries exist.
    uCCannot load module elasticsearch: elasticsearch libraries not found(tHAS_ELASTICSEARCHtFalsetTrue(((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pyt__virtual__Hs
c
@sOd}d}t}d}t}d}d}|dkr?d}nt|tj�rgtd|d�}	nt|t�r|}	n|	rN|	jd|�}|s�|	jd|�}n|	jdd�}|	jdt�}|	jdd�}|	jd	t�}|	jd
d�}
|	jdd�}|	jdd�}|
rN|rN|
|f}qNn|s`d
g}nt|tj�r~|g}ny�|r�dt	f�fd��Y�t
j|d�d|d|d|d|d|d|�}n-t
j|d|d|d|d|d|�}|j�Wn1t
j
jk
rJ}tdj||���nX|S(u+
    Return the elasticsearch instance
    i
u
elasticsearchu
config.optionuhostuhostsuproxiesuuse_ssluca_certsuverify_certsuusernameupasswordutimeoutu127.0.0.1:9200tProxyConnectionc@seZ�fd�ZRS(c@s;|jdi�}t�|�j||�||j_dS(Nuproxies(tpoptsupert__init__tsessiontproxies(tselftargstkwargsR(R(s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pyR{s(t__name__t
__module__R((R(s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pyRzstconnection_classRtuse_ssltca_certstverify_certst	http_authttimeoutu?Could not connect to Elasticsearch host/ cluster {0} due to {1}N(tNoneRR	t
isinstanceRtstring_typest__salt__tdicttgetRt
elasticsearcht
Elasticsearchtinfot
exceptionstTransportErrorRtformat(
thoststprofiletesRRRRRRt_profiletusernametpasswordterr((Rs>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pyt
_get_instanceQsl			cC@s;yt||�Wn#tk
r6}|r2|�ntSXtS(uY
    .. versionadded:: 2017.7.0

    Test connection to Elasticsearch instance. This method does not fail if not explicitly specified.

    allow_failure
        Throw exception if ping fails

    CLI example::

        salt myminion elasticsearch.ping allow_failure=True
        salt myminion elasticsearch.ping profile=elasticsearch-extra
    (R/RRR	(t
allow_failureR(R)te((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytping�s	cC@sXt||�}y|j�SWn4tjk
rS}tdj|j|j���nXdS(u�
    .. versionadded:: 2017.7.0

    Return Elasticsearch information.

    CLI example::

        salt myminion elasticsearch.info
        salt myminion elasticsearch.info profile=elasticsearch-extra
    uMCannot retrieve server information, server returned code {0} with message {1}N(R/R$R"R&RR'tstatus_codeterror(R(R)R*R1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pyR$�s
cC@sgt||�}y|jjd|d|�SWn4tjk
rb}tdj|j|j���nXdS(uN
    .. versionadded:: 2017.7.0

    Return Elasticsearch node information.

    nodes
        List of cluster nodes (id or name) to display stats for. Use _local for connected node, empty for all
    flat_settings
        Flatten settings keys

    CLI example::

        salt myminion elasticsearch.node_info flat_settings=True
    tnode_idt
flat_settingsuKCannot retrieve node information, server returned code {0} with message {1}N(	R/tnodesR$R"R&RR'R3R4(R7R6R(R)R*R1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pyt	node_info�s
uclustercC@smt||�}y#|jjd|d|d|�SWn4tjk
rh}tdj|j|j���nXdS(u�
    .. versionadded:: 2017.7.0

    Return Elasticsearch cluster health.

    index
        Limit the information returned to a specific index
    level
        Specify the level of detail for returned information, default 'cluster', valid choices are: 'cluster', 'indices', 'shards'
    local
        Return local information, do not retrieve the state from master node

    CLI example::

        salt myminion elasticsearch.cluster_health
    tindextleveltlocaluMCannot retrieve health information, server returned code {0} with message {1}N(	R/tclusterthealthR"R&RR'R3R4(R9R:R;R(R)R*R1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytcluster_health�s
#cC@sat||�}y|jjd|�SWn4tjk
r\}tdj|j|j���nXdS(u
    .. versionadded:: 2017.7.0

    Return Elasticsearch cluster stats.

    nodes
        List of cluster nodes (id or name) to display stats for. Use _local for connected node, empty for all

    CLI example::

        salt myminion elasticsearch.cluster_stats
    R5uHCannot retrieve cluster stats, server returned code {0} with message {1}N(	R/R<tstatsR"R&RR'R3R4(R7R(R)R*R1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pyt
cluster_stats�s

c
C@s�t||�}|r0|r0d}t|��n|r[td|dtjdd��}ny5|jjd|d|d|�}|jd	t�SWn:tj	k
r�}	t
d
j|||	j|	j
���nXdS(uM
    Create an alias for a specific index/indices

    indices
        Single or multiple indices separated by comma, use _all to perform the operation on all indices.
    alias
        Alias name
    body
        Optional definition such as routing or filter as defined in https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html
    source
        URL of file specifying optional definition such as routing or filter. Cannot be used in combination with ``body``.

    CLI example::

        salt myminion elasticsearch.alias_create testindex_v1 testindex
    u7Either body or source should be specified but not both.ucp.get_file_strtsaltenvusaltenvubaseR9tnametbodyuacknowledgeduOCannot create alias {0} in index {1}, server returned code {2} with message {3}N(R/RRt__opts__R!tindicest	put_aliasRR"R&RR'R3R4(
REtaliasR(RCR)tsourceR*tmessagetresultR1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytalias_creates!c
C@s�t||�}|r0|r0d}t|��n|r[td|dtjdd��}ny/|jjd|d|�}|jdt�SWnQtj	j
k
r�tStjk
r�}	t
d	j|||	j|	j���nXd
S(u*
    Delete an alias of an index

    indices
        Single or multiple indices separated by comma, use _all to perform the operation on all indices.
    aliases
        Alias names separated by comma

    CLI example::

        salt myminion elasticsearch.alias_delete testindex_v1 testindex
    u7Either body or source should be specified but not both.ucp.get_file_strRAusaltenvubaseR9RBuacknowledgeduOCannot delete alias {0} in index {1}, server returned code {2} with message {3}N(R/RRRDR!REtdelete_aliasRR"R%t
NotFoundErrorR	R&RR'R3R4(
REtaliasesR(RCR)RHR*RIRJR1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytalias_delete+s
cC@s�t||�}y|jjd|d|�SWnQtjjk
rFtStjk
r}tdj	|||j
|j���nXdS(u=
    Return a boolean indicating whether given alias exists

    indices
        Single or multiple indices separated by comma, use _all to perform the operation on all indices.
    aliases
        Alias names separated by comma

    CLI example::

        salt myminion elasticsearch.alias_exists None testindex
    RBR9uLCannot get alias {0} in index {1}, server returned code {2} with message {3}N(R/REtexists_aliasR"R%RMRR&RR'R3R4(RNRER(R)R*R1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytalias_existsJs
cC@s�t||�}y|jjd|d|�SWnQtjjk
rFdStjk
r}tdj	|||j
|j���nXdS(u>
    Check for the existence of an alias and if it exists, return it

    indices
        Single or multiple indices separated by comma, use _all to perform the operation on all indices.
    aliases
        Alias names separated by comma

    CLI example::

        salt myminion elasticsearch.alias_get testindex
    R9RBuLCannot get alias {0} in index {1}, server returned code {2} with message {3}N(R/REt	get_aliasR"R%RMRR&RR'R3R4(RERNR(R)R*R1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pyt	alias_get`s
c

C@s�t||�}|r0|r0d}t|��n|r[td|dtjdd��}ny&|jd|d|d|d	|�SWn7tjk
r�}	td
j	||	j
|	j���nXdS(u�
    Create a document in a specified index

    index
        Index name where the document should reside
    doc_type
        Type of the document
    body
        Document to store
    source
        URL of file specifying document to store. Cannot be used in combination with ``body``.
    id
        Optional unique document identifier for specified doc_type (empty for random)

    CLI example::

        salt myminion elasticsearch.document_create testindex doctype1 '{}'
    u7Either body or source should be specified but not both.ucp.get_file_strRAusaltenvubaseR9tdoc_typeRCtiduNCannot create document in index {0}, server returned code {1} with message {2}N(R/RRRDR!R9R"R&RR'R3R4(
R9RTRCRUR(R)RHR*RIR1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytdocument_createws&cC@s�t||�}y |jd|d|d|�SWnQtjjk
rIdStjk
r�}tdj|||j	|j
���nXdS(u
    Delete a document from an index

    index
        Index name where the document resides
    doc_type
        Type of the document
    id
        Document identifier

    CLI example::

        salt myminion elasticsearch.document_delete testindex doctype1 AUx-384m0Bug_8U80wQZ
    R9RTRUuRCannot delete document {0} in index {1}, server returned code {2} with message {3}N(R/tdeleteR"R%RMRR&RR'R3R4(R9RTRUR(R)R*R1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytdocument_delete�s u_allcC@s�t||�}y |jd|d|d|�SWnQtjjk
rItStjk
r�}tdj|||j	|j
���nXdS(uw
    Return a boolean indicating whether given document exists

    index
        Index name where the document resides
    id
        Document identifier
    doc_type
        Type of the document, use _all to fetch the first document matching the ID across all types

    CLI example::

        salt myminion elasticsearch.document_exists testindex AUx-384m0Bug_8U80wQZ
    R9RURTuVCannot retrieve document {0} from index {1}, server returned code {2} with message {3}N(R/texistsR"R%RMRR&RR'R3R4(R9RURTR(R)R*R1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytdocument_exists�s cC@s�t||�}y |jd|d|d|�SWnQtjjk
rIdStjk
r�}tdj|||j	|j
���nXdS(u|
    Check for the existence of a document and if it exists, return it

    index
        Index name where the document resides
    id
        Document identifier
    doc_type
        Type of the document, use _all to fetch the first document matching the ID across all types

    CLI example::

        salt myminion elasticsearch.document_get testindex AUx-384m0Bug_8U80wQZ
    R9RURTuVCannot retrieve document {0} from index {1}, server returned code {2} with message {3}N(R/R!R"R%RMRR&RR'R3R4(R9RURTR(R)R*R1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytdocument_get�s c	C@s�t||�}|r0|r0d}t|��n|r[td|dtjdd��}nyA|jjd|d|�}|jdt�o�|jd	t�SWnJt	j
k
r�}d
|jkr�tStdj
||j|j���nXdS(
u$
    Create an index

    index
        Index name
    body
        Index definition, such as settings and mappings as defined in https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html
    source
        URL to file specifying index definition. Cannot be used in combination with ``body``.

    CLI example::

        salt myminion elasticsearch.index_create testindex
        salt myminion elasticsearch.index_create testindex2 '{"settings" : {"index" : {"number_of_shards" : 3, "number_of_replicas" : 2}}}'
    u7Either body or source should be specified but not both.ucp.get_file_strRAusaltenvubaseR9RCuacknowledgedushards_acknowledgeduindex_already_exists_exceptionuBCannot create index {0}, server returned code {1} with message {2}N(R/RRRDR!REtcreateRR	R"R&R4RR'R3(	R9RCR(R)RHR*RIRJR1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytindex_create�s&cC@s�t||�}y)|jjd|�}|jdt�SWnNtjjk
rRtStj	k
r�}t
dj||j|j
���nXdS(u�
    Delete an index

    index
        Index name

    CLI example::

        salt myminion elasticsearch.index_delete testindex
    R9uacknowledgeduBCannot delete index {0}, server returned code {1} with message {2}N(R/RERWR!RR"R%RMR	R&RR'R3R4(R9R(R)R*RJR1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytindex_deletescC@s{t||�}y|jjd|�SWnNtjjk
r@tStjk
rv}tdj	||j
|j���nXdS(u�
    Return a boolean indicating whether given index exists

    index
        Index name

    CLI example::

        salt myminion elasticsearch.index_exists testindex
    R9uDCannot retrieve index {0}, server returned code {1} with message {2}N(R/RERYR"R%RMRR&RR'R3R4(R9R(R)R*R1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytindex_existsscC@s{t||�}y|jjd|�SWnNtjjk
r@dStjk
rv}tdj	||j
|j���nXdS(u�
    Check for the existence of an index and if it exists, return it

    index
        Index name

    CLI example::

        salt myminion elasticsearch.index_get testindex
    R9uDCannot retrieve index {0}, server returned code {1} with message {2}N(R/RER!R"R%RMRR&RR'R3R4(R9R(R)R*R1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pyt	index_get1suclosedc		C@s�t||�}y;|jjd|d|d|d|�}|jdt�SWn7tjk
r�}tdj||j	|j
���nXdS(u�
    .. versionadded:: 2017.7.0

    Open specified index.

    index
        Index to be opened
    allow_no_indices
        Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes _all string or when no indices have been specified)
    expand_wildcards
        Whether to expand wildcard expression to concrete indices that are open, closed or both., default ‘closed’, valid choices are: ‘open’, ‘closed’, ‘none’, ‘all’
    ignore_unavailable
        Whether specified concrete indices should be ignored when unavailable (missing or closed)

    CLI example::

        salt myminion elasticsearch.index_open testindex
    R9tallow_no_indicestexpand_wildcardstignore_unavailableuacknowledgedu@Cannot open index {0}, server returned code {1} with message {2}N(R/REtopenR!RR"R&RR'R3R4(	R9RaRbRcR(R)R*RJR1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pyt
index_openFs'uopenc		C@s�t||�}y;|jjd|d|d|d|�}|jdt�SWn7tjk
r�}tdj||j	|j
���nXdS(u�
    .. versionadded:: 2017.7.0

    Close specified index.

    index
        Index to be closed
    allow_no_indices
        Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes _all string or when no indices have been specified)
    expand_wildcards
        Whether to expand wildcard expression to concrete indices that are open, closed or both., default ‘open’, valid choices are: ‘open’, ‘closed’, ‘none’, ‘all’
    ignore_unavailable
        Whether specified concrete indices should be ignored when unavailable (missing or closed)

    CLI example::

        salt myminion elasticsearch.index_close testindex
    R9RaRbRcuacknowledgeduACannot close index {0}, server returned code {1} with message {2}N(R/REtcloseR!RR"R&RR'R3R4(	R9RaRbRcR(R)R*RJR1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytindex_closecs'c
C@s�t||�}|r0|r0d}t|��n|r[td|dtjdd��}ny5|jjd|d|d|�}|jd	t�SWn7tj	k
r�}	t
d
j||	j|	j
���nXdS(u(
    Create a mapping in a given index

    index
        Index for the mapping
    doc_type
        Name of the document type
    body
        Mapping definition as specified in https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html
    source
        URL to file specifying mapping definition. Cannot be used in combination with ``body``.

    CLI example::

        salt myminion elasticsearch.mapping_create testindex user '{ "user" : { "properties" : { "message" : {"type" : "string", "store" : true } } } }'
    u7Either body or source should be specified but not both.ucp.get_file_strRAusaltenvubaseR9RTRCuacknowledgeduDCannot create mapping {0}, server returned code {1} with message {2}N(R/RRRDR!REtput_mappingRR"R&RR'R3R4(
R9RTRCR(R)RHR*RIRJR1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytmapping_create�s!cC@s�t||�}y/|jjd|d|�}|jdt�SWnjtjjk
rXtStj	k
r�}t
dj||j|j
���ntk
r�t
d��nXdS(u
    Delete a mapping (type) along with its data. As of Elasticsearch 5.0 this is no longer available.

    index
        Index for the mapping
    doc_type
        Name of the document type

    CLI example::

        salt myminion elasticsearch.mapping_delete testindex user
    R9RTuacknowledgeduDCannot delete mapping {0}, server returned code {1} with message {2}u/Method is not applicable for Elasticsearch 5.0+N(R/REtdelete_mappingR!RR"R%RMR	R&RR'R3R4tAttributeError(R9RTR(R)R*RJR1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytmapping_delete�s
$
cC@s�t||�}y|jjd|d|�SWnNtjjk
rFdStjk
r|}tdj	||j
|j���nXdS(u�
    Retrieve mapping definition of index or index/type

    index
        Index for the mapping
    doc_type
        Name of the document type

    CLI example::

        salt myminion elasticsearch.mapping_get testindex user
    R9RTuFCannot retrieve mapping {0}, server returned code {1} with message {2}N(R/REtget_mappingR"R%RMRR&RR'R3R4(R9RTR(R)R*R1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytmapping_get�s
c	C@s�t||�}|r0|r0d}t|��n|r[td|dtjdd��}ny/|jjd|d|�}|jdt�SWn7tj	k
r�}t
d	j||j|j
���nXd
S(u�
    Create an index template

    name
        Index template name

    body
        Template definition as specified in http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html

    source
        URL to file specifying template definition. Cannot be used in combination with ``body``.

    CLI example::

        salt myminion elasticsearch.index_template_create testindex_templ '{ "template": "logstash-*", "order": 1, "settings": { "number_of_shards": 1 } }'
    u7Either body or source should be specified but not both.ucp.get_file_strRAusaltenvubaseRBRCuacknowledgeduECannot create template {0}, server returned code {1} with message {2}N(R/RRRDR!REtput_templateRR"R&RR'R3R4(	RBRCR(R)RHR*RIRJR1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytindex_template_create�scC@s�t||�}y)|jjd|�}|jdt�SWnNtjjk
rRtStj	k
r�}t
dj||j|j
���nXdS(u�
    Delete an index template (type) along with its data

    name
        Index template name

    CLI example::

        salt myminion elasticsearch.index_template_delete testindex_templ user
    RBuacknowledgeduECannot delete template {0}, server returned code {1} with message {2}N(R/REtdelete_templateR!RR"R%RMR	R&RR'R3R4(RBR(R)R*RJR1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytindex_template_delete�scC@sdt||�}y|jjd|�SWn7tjk
r_}tdj||j|j���nXdS(u�
    Return a boolean indicating whether given index template exists

    name
        Index template name

    CLI example::

        salt myminion elasticsearch.index_template_exists testindex_templ
    RBuGCannot retrieve template {0}, server returned code {1} with message {2}N(	R/REtexists_templateR"R&RR'R3R4(RBR(R)R*R1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytindex_template_existss
cC@s{t||�}y|jjd|�SWnNtjjk
r@dStjk
rv}tdj	||j
|j���nXdS(u�
    Retrieve template definition of index or index/type

    name
        Index template name

    CLI example::

        salt myminion elasticsearch.index_template_get testindex_templ
    RBuGCannot retrieve template {0}, server returned code {1} with message {2}N(R/REtget_templateR"R%RMRR&RR'R3R4(RBR(R)R*R1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytindex_template_getscC@s�t||�}y|jjd|�SWngtjk
r=dStjk
rs}tdj||j	|j
���ntk
r�td��nXdS(u�
    .. versionadded:: 2017.7.0

    Retrieve Ingest pipeline definition. Available since Elasticsearch 5.0.

    id
        Pipeline id

    CLI example::

        salt myminion elasticsearch.pipeline_get mypipeline
    RUuECannot create pipeline {0}, server returned code {1} with message {2}u0Method is applicable only for Elasticsearch 5.0+N(R/tingesttget_pipelineR"RMRR&RR'R3R4Rk(RUR(R)R*R1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytpipeline_get/s
$
cC@s�t||�}y)|jjd|�}|jdt�SWngtjk
rOtStjk
r�}t	dj
||j|j���nt
k
r�t	d��nXdS(u�
    .. versionadded:: 2017.7.0

    Delete Ingest pipeline. Available since Elasticsearch 5.0.

    id
        Pipeline id

    CLI example::

        salt myminion elasticsearch.pipeline_delete mypipeline
    RUuacknowledgeduECannot delete pipeline {0}, server returned code {1} with message {2}u0Method is applicable only for Elasticsearch 5.0+N(R/Rwtdelete_pipelineR!RR"RMR	R&RR'R3R4Rk(RUR(R)R*tretR1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytpipeline_deleteHs
$
cC@s�t||�}y/|jjd|d|�}|jdt�SWnStjk
rw}tdj||j	|j
���ntk
r�td��nXdS(u�
    .. versionadded:: 2017.7.0

    Create Ingest pipeline by supplied definition. Available since Elasticsearch 5.0.

    id
        Pipeline id
    body
        Pipeline definition as specified in https://www.elastic.co/guide/en/elasticsearch/reference/master/pipeline.html

    CLI example::

        salt myminion elasticsearch.pipeline_create mypipeline '{"description": "my custom pipeline", "processors": [{"set" : {"field": "collector_timestamp_millis", "value": "{{_ingest.timestamp}}"}}]}'
    RURCuacknowledgeduECannot create pipeline {0}, server returned code {1} with message {2}u0Method is applicable only for Elasticsearch 5.0+N(R/Rwtput_pipelineR!RR"R&RR'R3R4Rk(RURCR(R)R*toutR1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytpipeline_createbs$
cC@s�t||�}y#|jjd|d|d|�SWnStjk
rk}tdj||j|j���nt	k
r�td��nXdS(uX
    .. versionadded:: 2017.7.0

    Simulate existing Ingest pipeline on provided data. Available since Elasticsearch 5.0.

    id
        Pipeline id
    body
        Pipeline definition as specified in https://www.elastic.co/guide/en/elasticsearch/reference/master/pipeline.html
    verbose
        Specify if the output should be more verbose

    CLI example::

        salt myminion elasticsearch.pipeline_simulate mypipeline '{"docs":[{"_index":"index","_type":"type","_id":"id","_source":{"foo":"bar"}},{"_index":"index","_type":"type","_id":"id","_source":{"foo":"rab"}}]}' verbose=True
    RURCtverboseuGCannot simulate pipeline {0}, server returned code {1} with message {2}u0Method is applicable only for Elasticsearch 5.0+N(
R/RwtsimulateR"R&RR'R3R4Rk(RURCR�R(R)R*R1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytpipeline_simulate{s#$
cC@sut||�}y|jd|�SWnKtjk
r:dStjk
rp}tdj||j|j	���nXdS(u�
    .. versionadded:: 2017.7.0

    Obtain existing search template definition.

    id
        Template ID

    CLI example::

        salt myminion elasticsearch.search_template_get mytemplate
    RUuLCannot obtain search template {0}, server returned code {1} with message {2}N(
R/RuR"RMRR&RR'R3R4(RUR(R)R*R1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytsearch_template_get�s
cC@syt||�}y,|jd|d|�}|jdt�SWn7tjk
rt}tdj||j|j	���nXdS(u9
    .. versionadded:: 2017.7.0

    Create search template by supplied definition

    id
        Template ID
    body
        Search template definition

    CLI example::

        salt myminion elasticsearch.search_template_create mytemplate '{"template":{"query":{"match":{"title":"{{query_string}}"}}}}'
    RURCuacknowledgeduLCannot create search template {0}, server returned code {1} with message {2}N(
R/RoR!RR"R&RR'R3R4(RURCR(R)R*RJR1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytsearch_template_create�scC@s�t||�}y&|jd|�}|jdt�SWnKtjk
rLtStjk
r�}tdj	||j
|j���nXdS(u�
    .. versionadded:: 2017.7.0

    Delete existing search template definition.

    id
        Template ID

    CLI example::

        salt myminion elasticsearch.search_template_delete mytemplate
    RUuacknowledgeduLCannot delete search template {0}, server returned code {1} with message {2}N(R/RqR!RR"RMR	R&RR'R3R4(RUR(R)R*RJR1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytsearch_template_delete�s
cC@s~t||�}y|jjd|d|�SWnKtjk
rCdStjk
ry}tdj||j	|j
���nXdS(u
    .. versionadded:: 2017.7.0

    Get existing repository details.

    name
        Repository name
    local
        Retrieve only local information, default is false

    CLI example::

        salt myminion elasticsearch.repository_get testrepo
    t
repositoryR;uGCannot obtain repository {0}, server returned code {1} with message {2}N(R/tsnapshottget_repositoryR"RMRR&RR'R3R4(RBR;R(R)R*R1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytrepository_get�scC@s|t||�}y/|jjd|d|�}|jdt�SWn7tjk
rw}tdj||j	|j
���nXdS(u�
    .. versionadded:: 2017.7.0

    Create repository for storing snapshots. Note that shared repository paths have to be specified in path.repo Elasticsearch configuration option.

    name
        Repository name
    body
        Repository definition as in https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html

    CLI example::

        salt myminion elasticsearch.repository_create testrepo '{"type":"fs","settings":{"location":"/tmp/test","compress":true}}'
    R�RCuacknowledgeduGCannot create repository {0}, server returned code {1} with message {2}N(R/R�tcreate_repositoryR!RR"R&RR'R3R4(RBRCR(R)R*RJR1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytrepository_create�scC@s�t||�}y)|jjd|�}|jdt�SWnKtjk
rOtStjk
r�}t	dj
||j|j���nXdS(u�
    .. versionadded:: 2017.7.0

    Delete existing repository.

    name
        Repository name

    CLI example::

        salt myminion elasticsearch.repository_delete testrepo
    R�uacknowledgeduGCannot delete repository {0}, server returned code {1} with message {2}N(
R/R�tdelete_repositoryR!RR"RMR	R&RR'R3R4(RBR(R)R*RJR1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytrepository_deletes
cC@sxt||�}y|jjd|�SWnKtjk
r=dStjk
rs}tdj||j	|j
���nXdS(u�
    .. versionadded:: 2017.7.0

    Obtain list of cluster nodes which successfully verified this repository.

    name
        Repository name

    CLI example::

        salt myminion elasticsearch.repository_verify testrepo
    R�uGCannot verify repository {0}, server returned code {1} with message {2}N(R/R�tverify_repositoryR"RMRR&RR'R3R4(RBR(R)R*R1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytrepository_verify)s
cC@smt||�}y#|jjd|d|d|�SWn4tjk
rh}tdj|j|j���nXdS(u^
    .. versionadded:: 2017.7.0

    Obtain status of all currently running snapshots.

    repository
        Particular repository to look for snapshots
    snapshot
        Snapshot name
    ignore_unavailable
        Ignore unavailable snapshots

    CLI example::

        salt myminion elasticsearch.snapshot_status ignore_unavailable=True
    R�R�RcuHCannot obtain snapshot status, server returned code {0} with message {1}N(	R/R�tstatusR"R&RR'R3R4(R�R�RcR(R)R*R1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytsnapshot_status@s
#cC@sst||�}y#|jjd|d|d|�SWn:tjk
rn}tdj|||j|j���nXdS(uw
    .. versionadded:: 2017.7.0

    Obtain snapshot residing in specified repository.

    repository
        Repository name
    snapshot
        Snapshot name, use _all to obtain all snapshots in specified repository
    ignore_unavailable
        Ignore unavailable snapshots

    CLI example::

        salt myminion elasticsearch.snapshot_get testrepo testsnapshot
    R�R�RcubCannot obtain details of snapshot {0} in repository {1}, server returned code {2} with message {3}N(	R/R�R!R"R&RR'R3R4(R�R�RcR(R)R*R1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytsnapshot_getYs
#cC@s�t||�}y5|jjd|d|d|�}|jdt�SWn:tjk
r�}tdj|||j	|j
���nXdS(u�
    .. versionadded:: 2017.7.0

    Create snapshot in specified repository by supplied definition.

    repository
        Repository name
    snapshot
        Snapshot name
    body
        Snapshot definition as in https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html

    CLI example::

        salt myminion elasticsearch.snapshot_create testrepo testsnapshot '{"indices":"index_1,index_2","ignore_unavailable":true,"include_global_state":false}'
    R�R�RCuaccepteduWCannot create snapshot {0} in repository {1}, server returned code {2} with message {3}N(R/R�R\R!RR"R&RR'R3R4(R�R�RCR(R)R*tresponseR1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytsnapshot_creaters!cC@s�t||�}y5|jjd|d|d|�}|jdt�SWn:tjk
r�}tdj|||j	|j
���nXdS(u�
    .. versionadded:: 2017.7.0

    Restore existing snapshot in specified repository by supplied definition.

    repository
        Repository name
    snapshot
        Snapshot name
    body
        Restore definition as in https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html

    CLI example::

        salt myminion elasticsearch.snapshot_restore testrepo testsnapshot '{"indices":"index_1,index_2","ignore_unavailable":true,"include_global_state":true}'
    R�R�RCuaccepteduXCannot restore snapshot {0} in repository {1}, server returned code {2} with message {3}N(R/R�trestoreR!RR"R&RR'R3R4(R�R�RCR(R)R*R�R1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytsnapshot_restore�s!cC@s�t||�}y/|jjd|d|�}|jdt�SWnNtjk
rUtStjk
r�}t	dj
|||j|j���nXdS(u�
    .. versionadded:: 2017.7.0

    Delete snapshot from specified repository.

    repository
        Repository name
    snapshot
        Snapshot name

    CLI example::

        salt myminion elasticsearch.snapshot_delete testrepo testsnapshot
    R�R�uacknowledgeduYCannot delete snapshot {0} from repository {1}, server returned code {2} with message {3}N(
R/R�RWR!RR"RMR	R&RR'R3R4(R�R�R(R)R*RJR1((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pytsnapshot_delete�s(Ct__doc__t
__future__RRRtloggingtsalt.exceptionsRRtsalt.extRt	getLoggerRtlogR"RtsetLeveltCRITICALR	RtImportErrorRR
RR/R2R$R8R>R@RKRORQRSRVRXRZR[R]R^R_R`ReRgRiRlRnRpRrRtRvRyR|RR�R�R�R�R�R�R�R�R�R�R�R�R�(((s>/usr/lib/python2.7/site-packages/salt/modules/elasticsearch.pyt<module>2sp


		K !"! 

Zerion Mini Shell 1.0