o
    gZh2                     @   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de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ddddddededeje dej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eej	e f  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 deje de
ej fddZeddddddddddd ded!ejeejf 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eejf  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e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
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ddddddddddd+dedejeej	e f 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 d0eje dejejdd	ef  d1eje d2ejejd3ef  d
eje d4eje d5eje d6ejejd7ef  d8eje de
ej f(d9d:Ze 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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dddddddddddd?dededeje dejej	e  dejejeej	e f  deje d@ejej	e  deje dAeje deje dBejejeejf  dejejeej	e f  dejejdd	ef  deje d
eje dCeje dDeje deje de
ej f&dEdFZe dddddddddG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	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dHdI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dJdKZdS )LSnapshotClientN)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      |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di}
| jd||	|
dS )aa  
        Removes stale data from repository.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/clean-up-snapshot-repo-api.html>`_

        :param name: Snapshot repository to clean up.
        :param master_timeout: Period to wait for a connection to the master node.
        :param timeout: Period to wait for a response.
        'Empty value passed for parameter 'name'/_snapshot/z	/_cleanupNr	   r
   r   r   r   r   acceptapplication/jsonPOSTparamsheadersr   
ValueErrorr   perform_requestselfr   r	   r
   r   r   r   r   _SnapshotClient__path_SnapshotClient__query_SnapshotClient__headers r"   Z/var/www/html/lang_env/lib/python3.10/site-packages/elasticsearch/_sync/client/snapshot.pycleanup_repository   (   z!SnapshotClient.cleanup_repositoryT)Zbody_fields
repositorysnapshottarget_snapshotindicesc       
         C   s   |t v rtd|t v rtd|t v rtd|du r tddt| dt| dt| }i }i }|dur=||d	< |durE||d
< |durM||d< |durU||d< |dur]||d< |	dure|	|d< |
durm|
|d< ddd}| jd||||dS )a  
        Clones indices from one snapshot into another snapshot in the same repository.

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

        :param repository: A repository name
        :param snapshot: The name of the snapshot to clone from
        :param target_snapshot: The name of the cloned snapshot to create
        :param indices:
        :param master_timeout: Explicit operation timeout for connection to master node
        :param timeout:
        -Empty value passed for parameter 'repository'+Empty value passed for parameter 'snapshot'z2Empty value passed for parameter 'target_snapshot'Nz*Empty value passed for parameter 'indices'r   /z/_clone/r)   r	   r
   r   r   r   r   r   r   content-typePUTr   r   bodyr   )r   r&   r'   r(   r)   r	   r
   r   r   r   r   r   _SnapshotClient__bodyr    r!   r"   r"   r#   cloneG   s:   "

zSnapshotClient.clone)r	   feature_statesr
   r   ignore_unavailableinclude_global_stater)   r   metadatapartialr   wait_for_completionr4   r5   r6   r7   r8   r9   c                C   s4  |t v rtd|t v rtddt| dt| }i }i }|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< |sd}ddi}|durd|d< | jd||||dS )a
  
        Creates a snapshot in a repository.

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

        :param repository: Repository for the snapshot.
        :param snapshot: Name of the snapshot. Must be unique in the repository.
        :param feature_states: Feature states to include in the snapshot. Each feature
            state includes one or more system indices containing related data. You can
            view a list of eligible features using the get features API. If `include_global_state`
            is `true`, all current feature states are included by default. If `include_global_state`
            is `false`, no feature states are included by default.
        :param ignore_unavailable: If `true`, the request ignores data streams and indices
            in `indices` that are missing or closed. If `false`, the request returns
            an error for any data stream or index that is missing or closed.
        :param include_global_state: If `true`, the current cluster state is included
            in the snapshot. The cluster state includes persistent cluster settings,
            composable index templates, legacy index templates, ingest pipelines, and
            ILM policies. It also includes data stored in system indices, such as Watches
            and task records (configurable via `feature_states`).
        :param indices: Data streams and indices to include in the snapshot. Supports
            multi-target syntax. Includes all data streams and indices by default.
        :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 metadata: Optional metadata for the snapshot. May have any contents. Must
            be less than 1024 bytes. This map is not automatically generated by Elasticsearch.
        :param partial: If `true`, allows restoring a partial snapshot of indices with
            unavailable shards. Only shards that were successfully included in the snapshot
            will be restored. All missing shards will be recreated as empty. If `false`,
            the entire restore operation will fail if one or more indices included in
            the snapshot do not have all primary shards available.
        :param wait_for_completion: If `true`, the request returns a response when the
            snapshot is complete. If `false`, the request returns a response when the
            snapshot initializes.
        r*   r+   r   r,   Nr	   r4   r
   r   r5   r6   r)   r   r7   r8   r   r9   r   r   r.   r/   r0   r   )r   r&   r'   r	   r4   r
   r   r5   r6   r)   r   r7   r8   r   r9   r   r    r2   r!   r"   r"   r#   create   sN   ;
zSnapshotClient.create)r	   r
   r   r   r   r&   r   verifysettingstyper;   c                C   s  |t v rtd|du rtd|du rtddt| }i }i }|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urs||d< ddd}| jd||||dS )a  
        Creates a repository.

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

        :param name: A repository name
        :param settings:
        :param type:
        :param master_timeout: Explicit operation timeout for connection to master node
        :param repository:
        :param timeout: Explicit operation timeout
        :param verify: Whether to verify the repository after creation
        r   Nz+Empty value passed for parameter 'settings'z'Empty value passed for parameter 'type'r   r<   r=   r	   r
   r   r   r   r&   r   r;   r   r-   r/   r0   r   )r   r   r<   r=   r	   r
   r   r   r   r&   r   r;   r   r2   r    r!   r"   r"   r#   create_repository   sB   !

z SnapshotClient.create_repository)r	   r
   r   r   r   c                C   s   |t v rtd|t v rtddt| dt| }i }	|dur&||	d< |dur.||	d< |dur6||	d< |dur>||	d	< |durF||	d
< ddi}
| jd||	|
dS )aZ  
        Deletes one or more snapshots.

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

        :param repository: A repository name
        :param snapshot: A comma-separated list of snapshot names
        :param master_timeout: Explicit operation timeout for connection to master node
        r*   r+   r   r,   Nr	   r
   r   r   r   r   r   DELETEr   r   )r   r&   r'   r	   r
   r   r   r   r   r    r!   r"   r"   r#   delete*  s(   zSnapshotClient.deletec                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 )a  
        Deletes a repository.

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

        :param name: Name of the snapshot repository to unregister. Wildcard (`*`) patterns
            are supported.
        :param master_timeout: Explicit operation timeout for connection to master node
        :param timeout: Explicit operation timeout
        r   r   Nr	   r
   r   r   r   r   r   r   r?   r   r   r   r"   r"   r#   delete_repositoryV  s(   z SnapshotClient.delete_repository)afterr	   r
   from_sort_valuer   r5   include_repositoryindex_detailsindex_namesr   offsetorderr   sizeslm_policy_filtersortverboserB   rC   rD   rE   rF   rG   rH   zt.Literal['asc', 'desc']rI   rJ   rK   zmt.Literal['duration', 'failed_shard_count', 'index_count', 'name', 'repository', 'shard_count', 'start_time']rL   c                C   sf  |t v rtd|t v rtddt| dt| }i }|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< |durf||d< |durn||d< |durv||d< |dur~||d< |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  
        Returns information about a snapshot.

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

        :param repository: Comma-separated list of snapshot repository names used to
            limit the request. Wildcard (*) expressions are supported.
        :param snapshot: Comma-separated list of snapshot names to retrieve. Also accepts
            wildcards (*). - To get information about all snapshots in a registered repository,
            use a wildcard (*) or _all. - To get information about any snapshots that
            are currently running, use _current.
        :param after: Offset identifier to start pagination from as returned by the next
            field in the response body.
        :param from_sort_value: Value of the current sort column at which to start retrieval.
            Can either be a string snapshot- or repository name when sorting by snapshot
            or repository name, a millisecond time value or a number when sorting by
            index- or shard count.
        :param ignore_unavailable: If false, the request returns an error for any snapshots
            that are unavailable.
        :param include_repository: If true, returns the repository name in each snapshot.
        :param index_details: If true, returns additional information about each index
            in the snapshot comprising the number of shards in the index, the total size
            of the index in bytes, and the maximum number of segments per shard in the
            index. Defaults to false, meaning that this information is omitted.
        :param index_names: If true, returns the name of each index in each snapshot.
        :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 offset: Numeric offset to start pagination from based on the snapshots
            matching this request. Using a non-zero value for this parameter is mutually
            exclusive with using the after parameter. Defaults to 0.
        :param order: Sort order. Valid values are asc for ascending and desc for descending
            order. Defaults to asc, meaning ascending order.
        :param size: Maximum number of snapshots to return. Defaults to 0 which means
            return all that match the request without limit.
        :param slm_policy_filter: Filter snapshots by a comma-separated list of SLM policy
            names that snapshots belong to. Also accepts wildcards (*) and combinations
            of wildcards followed by exclude patterns starting with -. To include snapshots
            not created by an SLM policy you can use the special pattern _none that will
            match all snapshots without an SLM policy.
        :param sort: Allows setting a sort order for the result. Defaults to start_time,
            i.e. sorting by snapshot start time stamp.
        :param verbose: If true, returns additional information about each snapshot such
            as the version of Elasticsearch which took the snapshot, the start and end
            times of the snapshot, and the number of shards snapshotted.
        r*   r+   r   r,   NrB   r	   r
   rC   r   r5   rD   rE   rF   r   rG   rH   r   rI   rJ   rK   rL   r   r   GETr   r   )r   r&   r'   rB   r	   r
   rC   r   r5   rD   rE   rF   r   rG   rH   r   rI   rJ   rK   rL   r   r    r!   r"   r"   r#   get  sX   MzSnapshotClient.get)r   r	   r
   r   localr   r   rO   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 )a  
        Returns information about a repository.

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

        :param name: A comma-separated list of repository names
        :param local: Return local information, do not retrieve the state from master
            node (default: false)
        :param master_timeout: Explicit operation timeout for connection to master node
        r   z
/_snapshotNr	   r
   r   rO   r   r   r   r   rM   r   r   r   r   )r   r   r	   r
   r   rO   r   r   r   r    r!   r"   r"   r#   get_repository  s(   zSnapshotClient.get_repository)r	   r4   r
   r   ignore_index_settingsr5   include_aliasesr6   index_settingsr)   r   r8   r   rename_patternrename_replacementr9   rR   rS   rT   rU   rV   c                C   sv  |t v rtd|t v rtddt| dt| d}i }i }|dur)||d< |dur1||d< |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ur||d< |dur||d< |sd}ddi}|durd|d< | jd||||dS )a  
        Restores a snapshot.

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

        :param repository: A repository name
        :param snapshot: A snapshot name
        :param feature_states:
        :param ignore_index_settings:
        :param ignore_unavailable:
        :param include_aliases:
        :param include_global_state:
        :param index_settings:
        :param indices:
        :param master_timeout: Explicit operation timeout for connection to master node
        :param partial:
        :param rename_pattern:
        :param rename_replacement:
        :param wait_for_completion: Should this request wait until the operation has
            completed before returning
        r*   r+   r   r,   z	/_restoreNr	   r4   r
   r   rR   r5   rS   r6   rT   r)   r   r8   r   rU   rV   r9   r   r   r.   r   r0   r   )r   r&   r'   r	   r4   r
   r   rR   r5   rS   r6   rT   r)   r   r8   r   rU   rV   r9   r   r    r2   r!   r"   r"   r#   restore+  s^   0
zSnapshotClient.restore)r&   r'   r	   r
   r   r5   r   r   c                C   s   |t vr|t vrdt| dt| d}	n|t vr#dt| d}	nd}	i }
|dur/||
d< |dur7||
d< |dur?||
d< |durG||
d	< |durO||
d
< |durW||
d< ddi}| jd|	|
|dS )a
  
        Returns information about the status of a snapshot.

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

        :param repository: A repository name
        :param snapshot: A comma-separated list of snapshot names
        :param ignore_unavailable: Whether to ignore unavailable snapshots, defaults
            to false which means a SnapshotMissingException is thrown
        :param master_timeout: Explicit operation timeout for connection to master node
        r   r,   z/_statusz/_snapshot/_statusNr	   r
   r   r5   r   r   r   r   rM   r   rP   )r   r&   r'   r	   r
   r   r5   r   r   r   r    r!   r"   r"   r#   status  s,   zSnapshotClient.statusc                C   r   )a=  
        Verifies a repository.

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

        :param name: A repository name
        :param master_timeout: Explicit operation timeout for connection to master node
        :param timeout: Explicit operation timeout
        r   r   z/_verifyNr	   r
   r   r   r   r   r   r   r   r   r   r   r"   r"   r#   verify_repository  r%   z SnapshotClient.verify_repository)__name__
__module____qualname__r   strtOptionalboolUnionSequencer   Anyr$   r3   Mappingr:   r>   r@   rA   intrN   rQ   rW   rX   rY   r"   r"   r"   r#   r      s0   
+
	
:	
`		@+
,	
y-	
]	1
r   )typingr^   Zelastic_transportr   _baser   utilsr   r   r   r   r"   r"   r"   r#   <module>   s
   