From 212e7cd8a2a6dbf427ea0284a3d48e52ea510011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Honza=20Kr=C3=A1l?= Date: Sat, 18 Jan 2014 01:31:17 +0100 Subject: [PATCH] Added the snapshot apis --- docs/api.rst | 6 ++ elasticsearch/client/__init__.py | 2 + elasticsearch/client/snapshot.py | 115 +++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 elasticsearch/client/snapshot.py diff --git a/docs/api.rst b/docs/api.rst index 75c5be7f..d0f51d4d 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -50,3 +50,9 @@ Cat .. autoclass:: CatClient :members: +Snapshot +--- + +.. autoclass:: SnapshotClient + :members: + diff --git a/elasticsearch/client/__init__.py b/elasticsearch/client/__init__.py index 06567245..f717c31d 100644 --- a/elasticsearch/client/__init__.py +++ b/elasticsearch/client/__init__.py @@ -7,6 +7,7 @@ from .indices import IndicesClient from .cluster import ClusterClient from .cat import CatClient from .nodes import NodesClient +from .snapshot import SnapshotClient from .utils import query_params, _make_path logger = logging.getLogger('elasticsearch') @@ -82,6 +83,7 @@ class Elasticsearch(object): self.cluster = ClusterClient(weakref.proxy(self)) self.cat = CatClient(weakref.proxy(self)) self.nodes = NodesClient(weakref.proxy(self)) + self.snapshot = SnapshotClient(weakref.proxy(self)) def __repr__(self): try: diff --git a/elasticsearch/client/snapshot.py b/elasticsearch/client/snapshot.py new file mode 100644 index 00000000..13b9c3d7 --- /dev/null +++ b/elasticsearch/client/snapshot.py @@ -0,0 +1,115 @@ +from .utils import NamespacedClient, query_params, _make_path + +class SnapshotClient(NamespacedClient): + @query_params('master_timeout', 'wait_for_completion') + def create(self, repository, snapshot, body=None, params=None): + """ + Create a snapshot in repository + ``_ + + :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 + has completed before returning, default False + """ + _, data = self.transport.perform_request('PUT', _make_path('_snapshot', + repository, snapshot), params=params, body=body) + return data + + @query_params('master_timeout') + def delete(self, repository, snapshot, params=None): + """ + Deletes a snapshot from a repository. + ``_ + + :arg repository: A repository name + :arg snapshot: A snapshot name + :arg master_timeout: Explicit operation timeout for connection to master + node + """ + _, data = self.transport.perform_request('DELETE', + _make_path('_snapshot', repository, snapshot), params=params) + return data + + @query_params('master_timeout') + def get(self, repository, snapshot, params=None): + """ + Retrieve information about a snapshot. + ``_ + + :arg repository: A comma-separated list of repository names + :arg snapshot: A comma-separated list of snapshot names + :arg master_timeout: Explicit operation timeout for connection to master + node + """ + _, data = self.transport.perform_request('GET', _make_path('_snapshot', + repository, snapshot), params=params) + return data + + @query_params('master_timeout', 'timeout') + def delete_repository(self, repository, params=None): + """ + Removes a shared file system repository. + ``_ + + :arg repository: A comma-separated list of repository names + :arg master_timeout: Explicit operation timeout for connection to master + node + :arg timeout: Explicit operation timeout + """ + _, data = self.transport.perform_request('DELETE', + _make_path('_snapshot', repository), params=params) + return data + + @query_params('master_timeout') + def get_repository(self, repository=None, params=None): + """ + Return information about registered repositories. + ``_ + + :arg repository: A comma-separated list of repository names + :arg master_timeout: Explicit operation timeout for connection to master + node + """ + _, data = self.transport.perform_request('GET', _make_path('_snapshot', + repository), params=params) + return data + + @query_params('master_timeout', 'timeout') + def create_repository(self, repository, body, params=None): + """ + Registers a shared file system repository. + ``_ + + :arg repository: A repository name + :arg body: The repository definition + :arg master_timeout: Explicit operation timeout for connection to master + node + :arg timeout: Explicit operation timeout + """ + _, data = self.transport.perform_request('PUT', _make_path('_snapshot', + repository), params=params, body=body) + return data + + @query_params('master_timeout', 'wait_for_completion') + def restore(self, repository, snapshot, body=None, params=None): + """ + Restore a snapshot. + ``_ + + :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 + has completed before returning, default False + """ + _, data = self.transport.perform_request('POST', _make_path('_snapshot', + repository, snapshot, '_restore'), params=params, body=body) + return data + +