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

208 lines
8.3 KiB
Python
Raw Normal View History

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")
2014-01-18 01:31:17 +01:00
def create(self, repository, snapshot, body=None, params=None):
"""
2019-12-17 22:31:35 +01:00
Creates a snapshot in a repository.
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/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,
body=body,
)
2015-08-25 01:21:16 +02:00
2019-05-10 09:16:33 -06:00
@query_params("master_timeout")
2014-01-18 01:31:17 +01:00
def delete(self, repository, snapshot, params=None):
"""
2019-12-17 22:31:35 +01:00
Deletes a snapshot.
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/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(
"DELETE", _make_path("_snapshot", repository, snapshot), params=params
)
2015-08-25 01:21:16 +02:00
2019-05-10 09:16:33 -06:00
@query_params("ignore_unavailable", "master_timeout", "verbose")
2014-01-18 01:31:17 +01:00
def get(self, repository, snapshot, params=None):
"""
2019-12-17 22:31:35 +01:00
Returns information about a snapshot.
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/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(
"GET", _make_path("_snapshot", repository, snapshot), params=params
)
2015-08-25 01:21:16 +02:00
2019-05-10 09:16:33 -06:00
@query_params("master_timeout", "timeout")
2014-01-18 01:31:17 +01:00
def delete_repository(self, repository, params=None):
"""
2019-12-17 22:31:35 +01:00
Deletes a repository.
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/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 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(
"DELETE", _make_path("_snapshot", repository), params=params
)
2015-08-25 01:21:16 +02:00
2019-05-10 09:16:33 -06:00
@query_params("local", "master_timeout")
2014-01-18 01:31:17 +01:00
def get_repository(self, repository=None, params=None):
"""
2019-12-17 22:31:35 +01:00
Returns information about a repository.
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/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(
"GET", _make_path("_snapshot", repository), params=params
)
2015-08-25 01:21:16 +02:00
2019-05-10 09:16:33 -06:00
@query_params("master_timeout", "timeout", "verify")
2014-01-18 01:31:17 +01:00
def create_repository(self, repository, body, params=None):
"""
2019-12-17 22:31:35 +01:00
Creates a repository.
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/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(
"PUT", _make_path("_snapshot", repository), params=params, body=body
)
2015-08-25 01:21:16 +02:00
2019-05-10 09:16:33 -06:00
@query_params("master_timeout", "wait_for_completion")
2014-01-18 01:31:17 +01:00
def restore(self, repository, snapshot, body=None, params=None):
"""
2019-12-17 22:31:35 +01:00
Restores a snapshot.
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/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,
body=body,
)
2014-01-18 01:31:17 +01:00
2019-05-10 09:16:33 -06:00
@query_params("ignore_unavailable", "master_timeout")
def status(self, repository=None, snapshot=None, params=None):
"""
2019-12-17 22:31:35 +01:00
Returns information about the status of a snapshot.
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/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,
)
2014-10-08 09:23:13 +02:00
2019-05-10 09:16:33 -06:00
@query_params("master_timeout", "timeout")
2014-10-08 09:23:13 +02:00
def verify_repository(self, repository, params=None):
"""
2019-12-17 22:31:35 +01:00
Verifies a repository.
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/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(
"POST", _make_path("_snapshot", repository, "_verify"), params=params
)
2019-12-17 22:31:35 +01:00
@query_params("master_timeout", "timeout")
def cleanup_repository(self, repository, params=None):
"""
Removes stale data from repository.
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html>`_
: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(
"POST", _make_path("_snapshot", repository, "_cleanup"), params=params
)