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

184 lines
7.9 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):
"""
Create a snapshot in repository
2015-08-25 01:21:16 +02:00
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/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
:arg master_timeout: Explicit operation timeout for connection to master
node
:arg wait_for_completion: Should this request wait until the operation
2015-08-25 01:21:16 +02:00
has completed before returning, default False
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-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):
"""
Deletes a snapshot from a repository.
2015-08-25 01:21:16 +02:00
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html>`_
2014-01-18 01:31:17 +01:00
:arg repository: A repository name
:arg snapshot: A snapshot name
:arg master_timeout: Explicit operation timeout for connection to master
2015-08-25 01:21:16 +02:00
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-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):
"""
Retrieve information about a snapshot.
2015-08-25 01:21:16 +02:00
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/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
2016-10-17 13:56:58 +02:00
:arg ignore_unavailable: Whether to ignore unavailable snapshots,
2018-04-20 13:11:37 -06:00
defaults to false which means a NotFoundError `snapshot_missing_exception` is thrown
2014-01-18 01:31:17 +01:00
:arg master_timeout: Explicit operation timeout for connection to master
2015-08-25 01:21:16 +02:00
node
2017-07-31 19:17:52 -04:00
: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-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):
"""
Removes a shared file system repository.
2015-08-25 01:21:16 +02:00
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html>`_
2014-01-18 01:31:17 +01:00
:arg repository: A comma-separated list of repository names
: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-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):
"""
Return information about registered repositories.
2015-08-25 01:21:16 +02:00
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html>`_
2014-01-18 01:31:17 +01:00
:arg repository: A comma-separated list of repository names
2014-01-20 18:51:19 +01:00
:arg local: Return local information, do not retrieve the state from
master node (default: false)
2015-08-25 01:21:16 +02:00
: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):
"""
Registers a shared file system repository.
2015-08-25 01:21:16 +02:00
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html>`_
2014-01-18 01:31:17 +01:00
:arg repository: A repository name
:arg body: The repository definition
: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-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):
"""
Restore a snapshot.
2015-08-25 01:21:16 +02:00
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/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
:arg master_timeout: Explicit operation timeout for connection to master
node
:arg wait_for_completion: Should this request wait until the operation
2015-08-25 01:21:16 +02:00
has completed before returning, default False
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-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):
"""
2014-10-08 09:23:13 +02:00
Return information about all currently running snapshots. By specifying
2014-10-08 09:58:17 +02:00
a repository name, it's possible to limit the results to a particular
2014-10-08 09:23:13 +02:00
repository.
2015-03-23 15:25:45 -07:00
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html>`_
:arg repository: A repository name
:arg snapshot: A comma-separated list of snapshot names
2016-10-17 13:56:58 +02:00
:arg ignore_unavailable: Whether to ignore unavailable snapshots,
2018-04-20 13:11:37 -06:00
defaults to false which means a NotFoundError `snapshot_missing_exception` 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):
"""
Returns a list of nodes where repository was successfully verified or
an error message if verification process failed.
2015-03-23 15:25:45 -07:00
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html>`_
2014-10-08 09:23:13 +02:00
:arg repository: A repository name
:arg master_timeout: Explicit operation timeout for connection to master
node
: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-05-10 09:16:33 -06:00
return self.transport.perform_request(
"POST", _make_path("_snapshot", repository, "_verify"), params=params
)