Files
opensearch-pyd/elasticsearch/client/snapshot.py
T

235 lines
9.1 KiB
Python
Raw Normal View History

2020-04-23 11:22:08 -05:00
# Licensed to Elasticsearch B.V under one or more agreements.
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
# See the LICENSE file in the project root for more information
2014-12-02 00:13:01 +01:00
from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
2014-01-18 01:31:17 +01:00
2019-05-10 09:16:33 -06:00
2014-01-18 01:31:17 +01:00
class SnapshotClient(NamespacedClient):
2019-05-10 09:16:33 -06:00
@query_params("master_timeout", "wait_for_completion")
2020-03-11 16:33:15 -05:00
def create(self, repository, snapshot, body=None, params=None, headers=None):
2014-01-18 01:31:17 +01:00
"""
2019-12-17 22:31:35 +01:00
Creates a snapshot in a repository.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/modules-snapshots.html>`_
2014-01-18 01:31:17 +01:00
:arg repository: A repository name
:arg snapshot: A snapshot name
:arg body: The snapshot definition
2019-12-17 22:31:35 +01:00
:arg master_timeout: Explicit operation timeout for connection
to master node
:arg wait_for_completion: Should this request wait until the
operation has completed before returning
2014-01-18 01:31:17 +01:00
"""
2014-12-02 00:13:01 +01:00
for param in (repository, snapshot):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
2019-12-17 22:31:35 +01:00
2019-05-10 09:16:33 -06:00
return self.transport.perform_request(
"PUT",
_make_path("_snapshot", repository, snapshot),
params=params,
2020-03-11 16:33:15 -05:00
headers=headers,
2019-05-10 09:16:33 -06:00
body=body,
)
2015-08-25 01:21:16 +02:00
2019-05-10 09:16:33 -06:00
@query_params("master_timeout")
2020-03-11 16:33:15 -05:00
def delete(self, repository, snapshot, params=None, headers=None):
2014-01-18 01:31:17 +01:00
"""
2019-12-17 22:31:35 +01:00
Deletes a snapshot.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/modules-snapshots.html>`_
2014-01-18 01:31:17 +01:00
:arg repository: A repository name
:arg snapshot: A snapshot name
2019-12-17 22:31:35 +01:00
:arg master_timeout: Explicit operation timeout for connection
to master node
2014-01-18 01:31:17 +01:00
"""
2014-12-02 00:13:01 +01:00
for param in (repository, snapshot):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
2019-12-17 22:31:35 +01:00
2019-05-10 09:16:33 -06:00
return self.transport.perform_request(
2020-03-11 16:33:15 -05:00
"DELETE",
_make_path("_snapshot", repository, snapshot),
params=params,
headers=headers,
2019-05-10 09:16:33 -06:00
)
2015-08-25 01:21:16 +02:00
2019-05-10 09:16:33 -06:00
@query_params("ignore_unavailable", "master_timeout", "verbose")
2020-03-11 16:33:15 -05:00
def get(self, repository, snapshot, params=None, headers=None):
2014-01-18 01:31:17 +01:00
"""
2019-12-17 22:31:35 +01:00
Returns information about a snapshot.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/modules-snapshots.html>`_
2014-01-18 01:31:17 +01:00
2015-08-25 01:21:16 +02:00
:arg repository: A repository name
2014-01-18 01:31:17 +01:00
:arg snapshot: A comma-separated list of snapshot names
2019-12-17 22:31:35 +01:00
:arg ignore_unavailable: Whether to ignore unavailable
snapshots, defaults to false which means a SnapshotMissingException is
thrown
:arg master_timeout: Explicit operation timeout for connection
to master node
:arg verbose: Whether to show verbose snapshot info or only show
the basic info found in the repository index blob
2014-01-18 01:31:17 +01:00
"""
2014-12-02 00:13:01 +01:00
for param in (repository, snapshot):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
2019-12-17 22:31:35 +01:00
2019-05-10 09:16:33 -06:00
return self.transport.perform_request(
2020-03-11 16:33:15 -05:00
"GET",
_make_path("_snapshot", repository, snapshot),
params=params,
headers=headers,
2019-05-10 09:16:33 -06:00
)
2015-08-25 01:21:16 +02:00
2019-05-10 09:16:33 -06:00
@query_params("master_timeout", "timeout")
2020-03-11 16:33:15 -05:00
def delete_repository(self, repository, params=None, headers=None):
2014-01-18 01:31:17 +01:00
"""
2019-12-17 22:31:35 +01:00
Deletes a repository.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/modules-snapshots.html>`_
2014-01-18 01:31:17 +01:00
2020-06-03 10:38:35 -05:00
:arg repository: Name of the snapshot repository to unregister.
Wildcard (`*`) patterns are supported.
2019-12-17 22:31:35 +01:00
:arg master_timeout: Explicit operation timeout for connection
to master node
2015-08-25 01:21:16 +02:00
:arg timeout: Explicit operation timeout
2014-01-18 01:31:17 +01:00
"""
2014-12-02 00:13:01 +01:00
if repository in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'repository'.")
2019-12-17 22:31:35 +01:00
2019-05-10 09:16:33 -06:00
return self.transport.perform_request(
2020-03-11 16:33:15 -05:00
"DELETE",
_make_path("_snapshot", repository),
params=params,
headers=headers,
2019-05-10 09:16:33 -06:00
)
2015-08-25 01:21:16 +02:00
2019-05-10 09:16:33 -06:00
@query_params("local", "master_timeout")
2020-03-11 16:33:15 -05:00
def get_repository(self, repository=None, params=None, headers=None):
2014-01-18 01:31:17 +01:00
"""
2019-12-17 22:31:35 +01:00
Returns information about a repository.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/modules-snapshots.html>`_
2014-01-18 01:31:17 +01:00
:arg repository: A comma-separated list of repository names
2019-12-17 22:31:35 +01:00
:arg local: Return local information, do not retrieve the state
from master node (default: false)
:arg master_timeout: Explicit operation timeout for connection
to master node
2014-01-18 01:31:17 +01:00
"""
2019-05-10 09:16:33 -06:00
return self.transport.perform_request(
2020-03-11 16:33:15 -05:00
"GET", _make_path("_snapshot", repository), params=params, headers=headers
2019-05-10 09:16:33 -06:00
)
2015-08-25 01:21:16 +02:00
2019-05-10 09:16:33 -06:00
@query_params("master_timeout", "timeout", "verify")
2020-03-11 16:33:15 -05:00
def create_repository(self, repository, body, params=None, headers=None):
2014-01-18 01:31:17 +01:00
"""
2019-12-17 22:31:35 +01:00
Creates a repository.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/modules-snapshots.html>`_
2014-01-18 01:31:17 +01:00
:arg repository: A repository name
:arg body: The repository definition
2019-12-17 22:31:35 +01:00
:arg master_timeout: Explicit operation timeout for connection
to master node
2015-08-25 01:21:16 +02:00
:arg timeout: Explicit operation timeout
:arg verify: Whether to verify the repository after creation
2014-01-18 01:31:17 +01:00
"""
2014-12-02 00:13:01 +01:00
for param in (repository, body):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
2019-12-17 22:31:35 +01:00
2019-05-10 09:16:33 -06:00
return self.transport.perform_request(
2020-03-11 16:33:15 -05:00
"PUT",
_make_path("_snapshot", repository),
params=params,
headers=headers,
body=body,
2019-05-10 09:16:33 -06:00
)
2015-08-25 01:21:16 +02:00
2019-05-10 09:16:33 -06:00
@query_params("master_timeout", "wait_for_completion")
2020-03-11 16:33:15 -05:00
def restore(self, repository, snapshot, body=None, params=None, headers=None):
2014-01-18 01:31:17 +01:00
"""
2019-12-17 22:31:35 +01:00
Restores a snapshot.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/modules-snapshots.html>`_
2014-01-18 01:31:17 +01:00
:arg repository: A repository name
:arg snapshot: A snapshot name
:arg body: Details of what to restore
2019-12-17 22:31:35 +01:00
:arg master_timeout: Explicit operation timeout for connection
to master node
:arg wait_for_completion: Should this request wait until the
operation has completed before returning
2014-01-18 01:31:17 +01:00
"""
2014-12-02 00:13:01 +01:00
for param in (repository, snapshot):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
2019-12-17 22:31:35 +01:00
2019-05-10 09:16:33 -06:00
return self.transport.perform_request(
"POST",
_make_path("_snapshot", repository, snapshot, "_restore"),
params=params,
2020-03-11 16:33:15 -05:00
headers=headers,
2019-05-10 09:16:33 -06:00
body=body,
)
2014-01-18 01:31:17 +01:00
2019-05-10 09:16:33 -06:00
@query_params("ignore_unavailable", "master_timeout")
2020-03-11 16:33:15 -05:00
def status(self, repository=None, snapshot=None, params=None, headers=None):
"""
2019-12-17 22:31:35 +01:00
Returns information about the status of a snapshot.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/modules-snapshots.html>`_
:arg repository: A repository name
:arg snapshot: A comma-separated list of snapshot names
2019-12-17 22:31:35 +01:00
:arg ignore_unavailable: Whether to ignore unavailable
snapshots, defaults to false which means a SnapshotMissingException is
thrown
:arg master_timeout: Explicit operation timeout for connection
to master node
"""
2019-05-10 09:16:33 -06:00
return self.transport.perform_request(
"GET",
_make_path("_snapshot", repository, snapshot, "_status"),
params=params,
2020-03-11 16:33:15 -05:00
headers=headers,
2019-05-10 09:16:33 -06:00
)
2014-10-08 09:23:13 +02:00
2019-05-10 09:16:33 -06:00
@query_params("master_timeout", "timeout")
2020-03-11 16:33:15 -05:00
def verify_repository(self, repository, params=None, headers=None):
2014-10-08 09:23:13 +02:00
"""
2019-12-17 22:31:35 +01:00
Verifies a repository.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/modules-snapshots.html>`_
2014-10-08 09:23:13 +02:00
:arg repository: A repository name
2019-12-17 22:31:35 +01:00
:arg master_timeout: Explicit operation timeout for connection
to master node
2014-10-08 09:23:13 +02:00
:arg timeout: Explicit operation timeout
"""
2014-12-02 00:13:01 +01:00
if repository in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'repository'.")
2019-12-17 22:31:35 +01:00
2019-05-10 09:16:33 -06:00
return self.transport.perform_request(
2020-03-11 16:33:15 -05:00
"POST",
_make_path("_snapshot", repository, "_verify"),
params=params,
headers=headers,
2019-05-10 09:16:33 -06:00
)
2019-12-17 22:31:35 +01:00
@query_params("master_timeout", "timeout")
2020-03-11 16:33:15 -05:00
def cleanup_repository(self, repository, params=None, headers=None):
2019-12-17 22:31:35 +01:00
"""
Removes stale data from repository.
2020-05-19 12:59:40 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/clean-up-snapshot-repo-api.html>`_
2019-12-17 22:31:35 +01:00
:arg repository: A repository name
:arg master_timeout: Explicit operation timeout for connection
to master node
:arg timeout: Explicit operation timeout
"""
if repository in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'repository'.")
return self.transport.perform_request(
2020-03-11 16:33:15 -05:00
"POST",
_make_path("_snapshot", repository, "_cleanup"),
params=params,
headers=headers,
2019-12-17 22:31:35 +01:00
)