o
    gZhR                     @   sH   d dl Zd dl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)ObjectApiResponse   )NamespacedClient)SKIP_IN_PATH_quote_rewrite_parametersc                   @   s  e Zd Ze dddddddd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  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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  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ddZe 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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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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
ej fd!d"Zeddddddddd#ded$ejejeejf  deje dejejeej	e f  deje d%ejejeejf  d
eje de
ej fd&d'Zedddddddddd(d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  d)ejejeej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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
ej fd,d-Ze dddddd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
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jdd	ef  d
eje dejejdd	ef  de
ej fd0d1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jdd	ef  d
eje dejejdd	ef  de
ej fd2d3ZdS )4	IlmClientN)error_tracefilter_pathhumanmaster_timeoutprettytimeoutnamer	   r
   r   r   zt.Literal[-1]zt.Literal[0]r   r   returnc                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ur9||	d< |durA||	d	< d
di}
| jd||	|
dS )ay  
        Deletes the specified lifecycle policy definition. A currently used policy cannot
        be deleted.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ilm-delete-lifecycle.html>`_

        :param name: Identifier for the policy.
        :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'/_ilm/policy/Nr	   r
   r   r   r   r   acceptapplication/jsonDELETEparamsheadersr   
ValueErrorr   perform_requestselfr   r	   r
   r   r   r   r   _IlmClient__path_IlmClient__query_IlmClient__headers r!   U/var/www/html/lang_env/lib/python3.10/site-packages/elasticsearch/_sync/client/ilm.pydelete_lifecycle   s(   zIlmClient.delete_lifecycle)r	   r
   r   r   only_errorsonly_managedr   r   indexr$   r%   c       	         C   s   |t v rtddt| d}
i }|dur||d< |dur"||d< |dur*||d< |dur2||d< |dur:||d	< |durB||d
< |durJ||d< |	durR|	|d< ddi}| jd|
||dS )a  
        Retrieves information about the index's current lifecycle state, such as the
        currently executing phase, action, and step.

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

        :param index: Comma-separated list of data streams, indices, and aliases to target.
            Supports wildcards (`*`). To target all data streams and indices, use `*`
            or `_all`.
        :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 only_errors: Filters the returned indices to only indices that are managed
            by ILM and are in an error state, either due to an encountering an error
            while executing the policy, or attempting to use a policy that does not exist.
        :param only_managed: Filters the returned indices to only indices that are managed
            by ILM.
        :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 'index'/z/_ilm/explainNr	   r
   r   r   r$   r%   r   r   r   r   GETr   r   )r   r&   r	   r
   r   r   r$   r%   r   r   r   r   r    r!   r!   r"   explain_lifecycleK   s0   $zIlmClient.explain_lifecycle)r   r	   r
   r   r   r   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
di}
| jd||	|
dS )au  
        Returns the specified policy definition. Includes the policy version and last
        modified date.

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

        :param name: Identifier for the policy.
        :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.
        r   z/_ilm/policyNr	   r
   r   r   r   r   r   r   r)   r   )r   r   r   r   r!   r!   r"   get_lifecycle   s(   zIlmClient.get_lifecycle)r	   r
   r   r   c                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
        Retrieves the current index lifecycle management (ILM) status.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ilm-get-status.html>`_
        z/_ilm/statusNr	   r
   r   r   r   r   r)   r   r   )r   r	   r
   r   r   r   r   r    r!   r!   r"   
get_status   s   zIlmClient.get_statusT)Zbody_fields)dry_runr	   r
   r   legacy_template_to_deletenode_attributer   r.   r/   r0   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	< |
sBd}
d
di}|
durNd|d< | j d||	||
dS )aE  
        Migrates the indices and ILM policies away from custom node attribute allocation
        routing to data tiers routing

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ilm-migrate-to-data-tiers.html>`_

        :param dry_run: If true, simulates the migration from node attributes based allocation
            filters to data tiers, but does not perform the migration. This provides
            a way to retrieve the indices and ILM policies that need to be migrated.
        :param legacy_template_to_delete:
        :param node_attribute:
        z/_ilm/migrate_to_data_tiersNr.   r	   r
   r   r/   r0   r   r   r   content-typePOSTr   r   bodyr,   )r   r.   r	   r
   r   r/   r0   r   r   r   _IlmClient__bodyr    r!   r!   r"   migrate_to_data_tiers   s2   
zIlmClient.migrate_to_data_tiers)current_stepr	   r
   r   	next_stepr   r7   r8   c                C   s   |t v rtddt| }i }	i }
|dur||	d< |dur#||
d< |dur+||
d< |dur3||
d< |dur;||	d< |durC||
d	< |	sGd}	d
di}|	durSd|d< | jd||
||	dS )a@  
        Manually moves an index into the specified step and executes that step.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ilm-move-to-step.html>`_

        :param index: The name of the index whose lifecycle step is to change
        :param current_step:
        :param next_step:
        r'   z/_ilm/move/Nr7   r	   r
   r   r8   r   r   r   r1   r2   r3   r   )r   r&   r7   r	   r
   r   r8   r   r   r5   r   r    r!   r!   r"   move_to_step
  s2   
zIlmClient.move_to_step)r	   r
   r   r   policyr   r   r:   c                C   s   |t v rtddt| }	i }
i }|dur||
d< |dur#||
d< |dur+||
d< |dur3||
d< |dur;||d< |durC||
d	< |durK||
d
< |sOd}ddi}|dur[d|d< | jd|	|
||dS )aB  
        Creates a lifecycle policy

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ilm-put-lifecycle.html>`_

        :param name: Identifier for the policy.
        :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 policy:
        :param timeout: Period to wait for a response. If no response is received before
            the timeout expires, the request fails and returns an error.
        r   r   Nr	   r
   r   r   r:   r   r   r   r   r1   PUTr3   r   )r   r   r	   r
   r   r   r:   r   r   r   r   r5   r    r!   r!   r"   put_lifecycle;  s6   
zIlmClient.put_lifecyclec          	      C   ~   |t v rtddt| d}i }|dur||d< |dur"||d< |dur*||d< |dur2||d< d	d
i}| jd|||dS )a  
        Removes the assigned lifecycle policy and stops managing the specified index

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ilm-remove-policy.html>`_

        :param index: The name of the index to remove policy on
        r'   r(   z/_ilm/removeNr	   r
   r   r   r   r   r2   r   r   	r   r&   r	   r
   r   r   r   r   r    r!   r!   r"   remove_policyu  s    zIlmClient.remove_policyc          	      C   r=   )a/  
        Retries executing the policy for an index that is in the ERROR step.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ilm-retry-policy.html>`_

        :param index: The name of the indices (comma-separated) whose failed lifecycle
            step is to be retry
        r'   r(   z/_ilm/retryNr	   r
   r   r   r   r   r2   r   r   r>   r!   r!   r"   retry  s    zIlmClient.retryc          
      C      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 )z
        Start the index lifecycle management (ILM) plugin.

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

        :param master_timeout:
        :param timeout:
        z/_ilm/startNr	   r
   r   r   r   r   r   r   r2   r   r,   
r   r	   r
   r   r   r   r   r   r   r    r!   r!   r"   start  s$   zIlmClient.startc          
      C   rA   )a
  
        Halts all lifecycle management operations and stops the index lifecycle management
        (ILM) plugin

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

        :param master_timeout:
        :param timeout:
        z
/_ilm/stopNr	   r
   r   r   r   r   r   r   r2   r   r,   rB   r!   r!   r"   stop  s$   zIlmClient.stop)__name__
__module____qualname__r   strtOptionalboolUnionSequencer   Anyr#   r*   r+   r-   r6   Mappingr9   r<   r?   r@   rC   rD   r!   r!   r!   r"   r      s   
/
<
0	
1	
.
7!"	
'	
r   )typingrI   Zelastic_transportr   _baser   utilsr   r   r   r   r!   r!   r!   r"   <module>   s
   