o
    gZh٫                     @   sL   d dl Zd dlmZmZ ddlmZ ddlmZm	Z	m
Z
 G dd deZdS )    N)HeadApiResponseObjectApiResponse   )NamespacedClient)SKIP_IN_PATH_quote_rewrite_parametersc                %   @   s  e Zd Zeddddddddddddd
deje deje dejejeej	e f  deje d	eje d
eje deje deje deje deje
 deej fddZe ddddddddejeej	e f deje dejejeej	e f  deje dejejddef  deje dejejddef  deej fddZe dddddddeje dejejeej	e f  deje deje deje deej fddZe ddddddddejeej	e f deje dejejeej	e f  deje deje dejejddef  deje defd d!Ze dddddddddd"	deje deje dejejeej	e f  d#eje deje d$eje deje dejejddef  deje deej fd%d&Ze ddddddddd'deje dejejeej	e f  d#eje deje d$eje dejejddef  deje dejejddef  deej fd(d)Ze ddddddddddddddddd*dejejeej	e f  deje d+ejejej	ejd,ef  ejd,ef f  dejejeej	e f  deje d-ejejd.ef  deje dejejddef  deje dejejddef  d/ejeje
ejd0ef f  d1ejejd2ef  d3eje d4eje d5ejeje
ef  d6ejejd7ef  deej f"d8d9Ze ddddd:d;ejej	ejd<ef  ejd<ef f deje dejejeej	e f  deje deje deej fd=d>Ze ddddddddeje dejejeej	e f  deje deje dejejddef  deje deej fd?d@Ze ddddddddAdeje dejejeej	e f  deje dBejejeej	e f  dCejejeej	e f  deje dejejddef  deej fdDdEZeddFdGidHddddddddddI	dedJejeejf dKeje dLeje deje dejejeej	e f  deje dejejddef  dGejejeejf  deje dMeje
 deej fdNdOZeddddddddddddP	deje dejejeej	e f  d#eje deje dejejddef  dQejejeejf  deje dejejddef  dRejejeejf  deej fdSdTZe ddddd:deje dejejeej	e f  deje deje deej f
dUdVZeddddddddddddddWdXejej	ejeejf   dYeje deje dZeje dejejeej	e f  deje dejejddef  d[ejejeej	e f  deje d\eje dejejddef  deej fd]d^Ze ddddddddddddddd_d[ejejeej	e f  dejejeej	e f  d`eje deje d+ejejej	ejd,ef  ejd,ef f  dejejeej	e f  d#eje deje daeje deje dejejddef  deje dbeje
 dcejejddef  deej fdddeZe ddddddddfdgejejeej	e f  deje dejejeej	e f  d#eje deje deje dejejddef  deej fdhdiZdS )jClusterClientT)body_fieldsN)
current_nodeerror_tracefilter_pathhumaninclude_disk_infoinclude_yes_decisionsindexprettyprimaryshardr   r   r   r   r   r   r   r   r   r   returnc       
         C   s   d}i }i }|dur||d< |dur||d< |dur||d< |dur&||d< |dur.||d< |dur6||d< |dur>||d	< |durF||d
< |	durN|	|d< |
durV|
|d< |sZd}ddi}|durfd|d< | j d||||dS )a\  
        Provides explanations for shard allocations in the cluster.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/cluster-allocation-explain.html>`_

        :param current_node: Specifies the node ID or the name of the node to only explain
            a shard that is currently located on the specified node.
        :param include_disk_info: If true, returns information about disk usage and shard
            sizes.
        :param include_yes_decisions: If true, returns YES decisions in explanation.
        :param index: Specifies the name of the index that you would like an explanation
            for.
        :param primary: If true, returns explanation for the primary shard for the given
            shard ID.
        :param shard: Specifies the ID of the shard that you would like an explanation
            for.
        z/_cluster/allocation/explainNr   r   r   r   r   r   r   r   r   r   acceptapplication/jsoncontent-typePOSTparamsheadersbodyperform_request)selfr   r   r   r   r   r   r   r   r   r   _ClusterClient__path_ClusterClient__body_ClusterClient__query_ClusterClient__headers r%   Y/var/www/html/lang_env/lib/python3.10/site-packages/elasticsearch/_sync/client/cluster.pyallocation_explain   s>   "
z ClusterClient.allocation_explain)r   r   r   master_timeoutr   timeoutnamer(   zt.Literal[-1]zt.Literal[0]r)   c                C      |t v rtddt| }i }	|dur||	d< |dur!||	d< |dur)||	d< |dur1||	d< |dur9||	d< |durA||	d	< d
di}
| jd||	|
dS )a  
        Deletes a component template

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/indices-component-template.html>`_

        :param name: Comma-separated list or wildcard expression of component template
            names used to limit the request.
        :param master_timeout: Period to wait for a connection to the master node. If
            no response is received before the timeout expires, the request fails and
            returns an error.
        :param timeout: Period to wait for a response. If no response is received before
            the timeout expires, the request fails and returns an error.
        'Empty value passed for parameter 'name'/_component_template/Nr   r   r   r(   r   r)   r   r   DELETEr   r   r   
ValueErrorr   r   )r    r*   r   r   r   r(   r   r)   r!   r#   r$   r%   r%   r&   delete_component_template]   s(   z'ClusterClient.delete_component_template)r   r   r   r   wait_for_removalr3   c          	      C   sr   d}i }|dur||d< |dur||d< |dur||d< |dur$||d< |dur,||d< dd	i}| j d
|||dS )a  
        Clears cluster voting config exclusions.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/voting-config-exclusions.html>`_

        :param wait_for_removal: Specifies whether to wait for all excluded nodes to
            be removed from the cluster before clearing the voting configuration exclusions
            list. Defaults to true, meaning that all excluded nodes must be removed from
            the cluster before this API takes any action. If set to false then the voting
            configuration exclusions list is cleared even if some excluded nodes are
            still in the cluster.
        "/_cluster/voting_config_exclusionsNr   r   r   r   r3   r   r   r.   r/   r   )	r    r   r   r   r   r3   r!   r#   r$   r%   r%   r&   delete_voting_config_exclusions   s    z-ClusterClient.delete_voting_config_exclusions)r   r   r   localr(   r   r6   c                C   r+   )a  
        Returns information about whether a particular component template exist

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/indices-component-template.html>`_

        :param name: Comma-separated list of component template names used to limit the
            request. Wildcard (*) expressions are supported.
        :param local: If true, the request retrieves information from the local node
            only. Defaults to false, which means information is retrieved from the master
            node.
        :param master_timeout: Period to wait for a connection to the master node. If
            no response is received before the timeout expires, the request fails and
            returns an error.
        r,   r-   Nr   r   r   r6   r(   r   r   r   HEADr/   r0   )r    r*   r   r   r   r6   r(   r   r!   r#   r$   r%   r%   r&   exists_component_template   s(   z'ClusterClient.exists_component_template)	r*   r   r   flat_settingsr   include_defaultsr6   r(   r   r9   r:   c       	         C   s   |t vrdt| }
nd}
i }|dur||d< |dur ||d< |dur(||d< |dur0||d< |dur8||d< |dur@||d	< |durH||d
< |	durP|	|d< ddi}| jd|
||dS )ao  
        Returns one or more component templates

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/indices-component-template.html>`_

        :param name: Comma-separated list of component template names used to limit the
            request. Wildcard (`*`) expressions are supported.
        :param flat_settings: If `true`, returns settings in flat format.
        :param include_defaults: Return all default configurations for the component
            template (default: false)
        :param local: If `true`, the request retrieves information from the local node
            only. If `false`, information is retrieved from the master node.
        :param master_timeout: Period to wait for a connection to the master node. If
            no response is received before the timeout expires, the request fails and
            returns an error.
        r-   z/_component_templateNr   r   r9   r   r:   r6   r(   r   r   r   GETr/   r   r   r   )r    r*   r   r   r9   r   r:   r6   r(   r   r!   r#   r$   r%   r%   r&   get_component_template   s0    z$ClusterClient.get_component_template)r   r   r9   r   r:   r(   r   r)   c                C   s   d}	i }
|dur||
d< |dur||
d< |dur||
d< |dur$||
d< |dur,||
d< |dur4||
d< |dur<||
d	< |durD||
d
< ddi}| j d|	|
|dS )a  
        Returns cluster settings.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/cluster-get-settings.html>`_

        :param flat_settings: If `true`, returns settings in flat format.
        :param include_defaults: If `true`, returns default cluster settings from the
            local node.
        :param master_timeout: Period to wait for a connection to the master node. If
            no response is received before the timeout expires, the request fails and
            returns an error.
        :param timeout: Period to wait for a response. If no response is received before
            the timeout expires, the request fails and returns an error.
        /_cluster/settingsNr   r   r9   r   r:   r(   r   r)   r   r   r;   r/   r   )r    r   r   r9   r   r:   r(   r   r)   r!   r#   r$   r%   r%   r&   get_settings  s,   zClusterClient.get_settings)r   r   expand_wildcardsr   r   levelr6   r(   r   r)   wait_for_active_shardswait_for_eventswait_for_no_initializing_shardswait_for_no_relocating_shardswait_for_nodeswait_for_statusr@   z4t.Literal['all', 'closed', 'hidden', 'none', 'open']rA   z)t.Literal['cluster', 'indices', 'shards']rB   z!t.Literal['all', 'index-setting']rC   zDt.Literal['high', 'immediate', 'languid', 'low', 'normal', 'urgent']rD   rE   rF   rG   z#t.Literal['green', 'red', 'yellow']c                C   s*  |t vrdt| }nd}i }|dur||d< |dur ||d< |dur(||d< |dur0||d< |dur8||d< |dur@||d	< |durH||d
< |	durP|	|d< |
durX|
|d< |dur`||d< |durh||d< |durp||d< |durx||d< |dur||d< |dur||d< ddi}| jd|||dS )a
  
        Returns basic information about the health of the cluster.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/cluster-health.html>`_

        :param index: Comma-separated list of data streams, indices, and index aliases
            used to limit the request. Wildcard expressions (*) are supported. To target
            all data streams and indices in a cluster, omit this parameter or use _all
            or *.
        :param expand_wildcards: Whether to expand wildcard expression to concrete indices
            that are open, closed or both.
        :param level: Can be one of cluster, indices or shards. Controls the details
            level of the health information returned.
        :param local: If true, the request retrieves information from the local node
            only. Defaults to false, which means information is retrieved from the master
            node.
        :param master_timeout: Period to wait for a connection to the master node. If
            no response is received before the timeout expires, the request fails and
            returns an error.
        :param timeout: Period to wait for a response. If no response is received before
            the timeout expires, the request fails and returns an error.
        :param wait_for_active_shards: A number controlling to how many active shards
            to wait for, all to wait for all shards in the cluster to be active, or 0
            to not wait.
        :param wait_for_events: Can be one of immediate, urgent, high, normal, low, languid.
            Wait until all currently queued events with the given priority are processed.
        :param wait_for_no_initializing_shards: A boolean value which controls whether
            to wait (until the timeout provided) for the cluster to have no shard initializations.
            Defaults to false, which means it will not wait for initializing shards.
        :param wait_for_no_relocating_shards: A boolean value which controls whether
            to wait (until the timeout provided) for the cluster to have no shard relocations.
            Defaults to false, which means it will not wait for relocating shards.
        :param wait_for_nodes: The request waits until the specified number N of nodes
            is available. It also accepts >=N, <=N, >N and <N. Alternatively, it is possible
            to use ge(N), le(N), gt(N) and lt(N) notation.
        :param wait_for_status: One of green, yellow or red. Will wait (until the timeout
            provided) until the status of the cluster changes to the one provided or
            better, i.e. green > yellow > red. By default, will not wait for any status.
        z/_cluster/health/z/_cluster/healthNr   r@   r   r   rA   r6   r(   r   r)   rB   rC   rD   rE   rF   rG   r   r   r;   r/   r<   )r    r   r   r@   r   r   rA   r6   r(   r   r)   rB   rC   rD   rE   rF   rG   r!   r#   r$   r%   r%   r&   healthS  sL   PzClusterClient.health)r   r   r   r   targetz<t.Literal['_all', 'http', 'ingest', 'script', 'thread_pool']c          	      C   s|   |t v rtddt| }i }|dur||d< |dur!||d< |dur)||d< |dur1||d< dd	i}| jd
|||dS )a1  
        Returns different information about the cluster.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/cluster-info.html>`_

        :param target: Limits the information returned to the specific target. Supports
            a comma-separated list, such as http,ingest.
        z)Empty value passed for parameter 'target'z/_info/Nr   r   r   r   r   r   r;   r/   r0   )	r    rI   r   r   r   r   r!   r#   r$   r%   r%   r&   info  s    zClusterClient.infoc          
      C   s   d}i }|dur||d< |dur||d< |dur||d< |dur$||d< |dur,||d< |dur4||d< d	d
i}	| j d|||	dS )ar  
        Returns a list of any cluster-level changes (e.g. create index, update mapping,
        allocate or fail shard) which have not yet been executed.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/cluster-pending.html>`_

        :param local: If `true`, the request retrieves information from the local node
            only. If `false`, information is retrieved from the master node.
        :param master_timeout: Period to wait for a connection to the master node. If
            no response is received before the timeout expires, the request fails and
            returns an error.
        z/_cluster/pending_tasksNr   r   r   r6   r(   r   r   r   r;   r/   r   )
r    r   r   r   r6   r(   r   r!   r#   r$   r%   r%   r&   pending_tasks  s$   zClusterClient.pending_tasks)r   r   r   node_ids
node_namesr   r)   rL   rM   c                C   s   d}i }	|dur||	d< |dur||	d< |dur||	d< |dur$||	d< |dur,||	d< |dur4||	d< |dur<||	d	< d
di}
| j d||	|
dS )a{  
        Updates the cluster voting config exclusions by node ids or node names.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/voting-config-exclusions.html>`_

        :param node_ids: A comma-separated list of the persistent ids of the nodes to
            exclude from the voting configuration. If specified, you may not also specify
            node_names.
        :param node_names: A comma-separated list of the names of the nodes to exclude
            from the voting configuration. If specified, you may not also specify node_ids.
        :param timeout: When adding a voting configuration exclusion, the API waits for
            the specified nodes to be excluded from the voting configuration before returning.
            If the timeout expires before the appropriate condition is satisfied, the
            request fails and returns an error.
        r4   Nr   r   r   rL   rM   r   r)   r   r   r   r/   r   )r    r   r   r   rL   rM   r   r)   r!   r#   r$   r%   r%   r&   post_voting_config_exclusions#  s(   z+ClusterClient.post_voting_config_exclusions_metameta)r
   Zparameter_aliases)	allow_auto_createcreater   r   r   r(   rP   r   versiontemplaterQ   rR   rS   c                C   s   |t v rtd|du rtddt| }i }i }|dur#||d< |dur+||d< |dur3||d< |dur;||d< |durC||d	< |durK||d
< |durS||d< |	dur[|	|d< |
durc|
|d< |durk||d< ddd}| jd||||dS )uc	  
        Creates or updates a component template

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/indices-component-template.html>`_

        :param name: Name of the component template to create. Elasticsearch includes
            the following built-in component templates: `logs-mappings`; 'logs-settings`;
            `metrics-mappings`; `metrics-settings`;`synthetics-mapping`; `synthetics-settings`.
            Elastic Agent uses these templates to configure backing indices for its data
            streams. If you use Elastic Agent and want to overwrite one of these templates,
            set the `version` for your replacement template higher than the current version.
            If you don’t use Elastic Agent and want to disable all built-in component
            and index templates, set `stack.templates.enabled` to `false` using the cluster
            update settings API.
        :param template: The template to be applied which includes mappings, settings,
            or aliases configuration.
        :param allow_auto_create: This setting overrides the value of the `action.auto_create_index`
            cluster setting. If set to `true` in a template, then indices can be automatically
            created using that template even if auto-creation of indices is disabled
            via `actions.auto_create_index`. If set to `false` then data streams matching
            the template must always be explicitly created.
        :param create: If `true`, this request cannot replace or update existing component
            templates.
        :param master_timeout: Period to wait for a connection to the master node. If
            no response is received before the timeout expires, the request fails and
            returns an error.
        :param meta: Optional user metadata about the component template. May have any
            contents. This map is not automatically generated by Elasticsearch. This
            information is stored in the cluster state, so keeping it short is preferable.
            To unset `_meta`, replace the template without specifying this information.
        :param version: Version number used to manage component templates externally.
            This number isn't automatically generated or incremented by Elasticsearch.
            To unset a version, replace the template without specifying a version.
        r,   Nz+Empty value passed for parameter 'template'r-   rT   rQ   rR   r   r   r   r(   rO   r   rS   r   r   r   PUTr   r0   )r    r*   rT   rQ   rR   r   r   r   r(   rP   r   rS   r!   r"   r#   r$   r%   r%   r&   put_component_templateS  s>   7

z$ClusterClient.put_component_template)	r   r   r9   r   r(   
persistentr   r)   	transientrX   rY   c       	         C   s   d}
i }i }|dur||d< |dur||d< |dur||d< |dur&||d< |dur.||d< |dur6||d< |dur>||d	< |durF||d
< |	durN|	|d< ddd}| j d|
|||dS )a  
        Updates the cluster settings.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/cluster-update-settings.html>`_

        :param flat_settings: Return settings in flat format (default: false)
        :param master_timeout: Explicit operation timeout for connection to master node
        :param persistent:
        :param timeout: Explicit operation timeout
        :param transient:
        r>   Nr   r   r9   r   r(   rX   r   r)   rY   r   rU   rV   r   r   )r    r   r   r9   r   r(   rX   r   r)   rY   r!   r#   r"   r$   r%   r%   r&   put_settings  s2   

zClusterClient.put_settingsc                C   sb   d}i }|dur||d< |dur||d< |dur||d< |dur$||d< ddi}| j d	|||d
S )z
        Returns the information about configured remote clusters.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/cluster-remote-info.html>`_
        z/_remote/infoNr   r   r   r   r   r   r;   r/   r   )r    r   r   r   r   r!   r#   r$   r%   r%   r&   remote_info  s   zClusterClient.remote_info)commandsdry_runr   explainr   r   r(   metricr   retry_failedr)   r\   r]   r^   r_   r`   c                C   s   d}i }i }|dur||d< |dur||d< |dur||d< |dur&||d< |dur.||d< |dur6||d< |dur>||d	< |durF||d
< |	durN|	|d< |
durV|
|d< |dur^||d< |sbd}ddi}|durnd|d< | j d||||dS )aN  
        Allows to manually change the allocation of individual shards in the cluster.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/cluster-reroute.html>`_

        :param commands: Defines the commands to perform.
        :param dry_run: If true, then the request simulates the operation only and returns
            the resulting state.
        :param explain: If true, then the response contains an explanation of why the
            commands can or cannot be executed.
        :param master_timeout: Period to wait for a connection to the master node. If
            no response is received before the timeout expires, the request fails and
            returns an error.
        :param metric: Limits the information returned to the specified metrics.
        :param retry_failed: If true, then retries allocation of shards that are blocked
            due to too many subsequent allocation failures.
        :param timeout: Period to wait for a response. If no response is received before
            the timeout expires, the request fails and returns an error.
        z/_cluster/rerouteNr\   r]   r   r^   r   r   r(   r_   r   r`   r)   r   r   r   r   r   r   )r    r\   r]   r   r^   r   r   r(   r_   r   r`   r)   r!   r"   r#   r$   r%   r%   r&   reroute  sB   '
zClusterClient.reroute)r_   r   allow_no_indicesr   r@   r   r9   r   ignore_unavailabler6   r(   r   wait_for_metadata_versionwait_for_timeoutrb   rc   rd   re   c                C   s<  |t vr|t vrdt| dt| }n|t vr!dt| }n|t vr-dt| }nd}i }|dur9||d< |durA||d< |durI||d< |durQ||d	< |durY||d
< |dura||d< |	duri|	|d< |
durq|
|d< |dury||d< |dur||d< |dur||d< |dur||d< ddi}| jd|||dS )a  
        Returns a comprehensive information about the state of the cluster.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/cluster-state.html>`_

        :param metric: Limit the information returned to the specified metrics
        :param index: A comma-separated list of index names; use `_all` or empty string
            to perform the operation on all indices
        :param 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)
        :param expand_wildcards: Whether to expand wildcard expression to concrete indices
            that are open, closed or both.
        :param flat_settings: Return settings in flat format (default: false)
        :param ignore_unavailable: Whether specified concrete indices should be ignored
            when unavailable (missing or closed)
        :param local: Return local information, do not retrieve the state from master
            node (default: false)
        :param master_timeout: Specify timeout for connection to master
        :param wait_for_metadata_version: Wait for the metadata version to be equal or
            greater than the specified metadata version
        :param wait_for_timeout: The maximum time to wait for wait_for_metadata_version
            before timing out
        z/_cluster/state//z/_cluster/state/_all/z/_cluster/stateNrb   r   r@   r   r9   r   rc   r6   r(   r   rd   re   r   r   r;   r/   r<   )r    r_   r   rb   r   r@   r   r9   r   rc   r6   r(   r   rd   re   r!   r#   r$   r%   r%   r&   stateG  sH   6zClusterClient.state)node_idr   r   r9   r   r   r)   rh   c                C   s   |t vrdt| }nd}i }	|dur||	d< |dur ||	d< |dur(||	d< |dur0||	d< |dur8||	d< |dur@||	d	< d
di}
| jd||	|
dS )u  
        Returns high-level overview of cluster statistics.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/cluster-stats.html>`_

        :param node_id: Comma-separated list of node filters used to limit returned information.
            Defaults to all nodes in the cluster.
        :param flat_settings: If `true`, returns settings in flat format.
        :param timeout: Period to wait for each node to respond. If a node does not respond
            before its timeout expires, the response does not include its stats. However,
            timed out nodes are included in the response’s `_nodes.failed` property.
            Defaults to no timeout.
        z/_cluster/stats/nodes/z/_cluster/statsNr   r   r9   r   r   r)   r   r   r;   r/   r<   )r    rh   r   r   r9   r   r   r)   r!   r#   r$   r%   r%   r&   stats  s(   zClusterClient.stats)__name__
__module____qualname__r   tOptionalstrboolUnionSequenceintr   Anyr'   r2   r5   r   r8   r=   r?   rH   rJ   rK   rN   MappingrW   rZ   r[   ra   rg   ri   r%   r%   r%   r&   r	      s2   	
?
/&0	
93!"#$'w+
+	
/		
S
4	F[	
r	   )typingrm   Zelastic_transportr   r   _baser   utilsr   r   r   r	   r%   r%   r%   r&   <module>   s
   