From d6e0b5f54ab04b99ead162cf51e846f8ea501223 Mon Sep 17 00:00:00 2001 From: Sai Medhini Reddy Maryada <117196660+saimedhi@users.noreply.github.com> Date: Thu, 26 Oct 2023 07:59:07 -0700 Subject: [PATCH] added remote store client (#552) Signed-off-by: saimedhi Signed-off-by: roma2023 --- CHANGELOG.md | 1 + opensearchpy/_async/client/__init__.py | 2 + opensearchpy/_async/client/__init__.pyi | 2 + opensearchpy/_async/client/remote_store.py | 40 ++++++++++++++++++ opensearchpy/_async/client/remote_store.pyi | 41 +++++++++++++++++++ opensearchpy/client/__init__.py | 2 + opensearchpy/client/__init__.pyi | 2 + opensearchpy/client/remote_store.py | 40 ++++++++++++++++++ opensearchpy/client/remote_store.pyi | 41 +++++++++++++++++++ .../test_client/test_remote_store.py | 15 +++++++ 10 files changed, 186 insertions(+) create mode 100644 opensearchpy/_async/client/remote_store.py create mode 100644 opensearchpy/_async/client/remote_store.pyi create mode 100644 opensearchpy/client/remote_store.py create mode 100644 opensearchpy/client/remote_store.pyi create mode 100644 test_opensearchpy/test_client/test_remote_store.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c55a5d1..6803cf4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Added benchmarks ([#537](https://github.com/opensearch-project/opensearch-py/pull/537)) - Added guide on making raw JSON REST requests ([#542](https://github.com/opensearch-project/opensearch-py/pull/542)) - Added support for AWS SigV4 for urllib3 ([#547](https://github.com/opensearch-project/opensearch-py/pull/547)) +- Added `remote store` client APIs ([#552](https://github.com/opensearch-project/opensearch-py/pull/552)) ### Changed - Generate `tasks` client from API specs ([#508](https://github.com/opensearch-project/opensearch-py/pull/508)) - Generate `ingest` client from API specs ([#513](https://github.com/opensearch-project/opensearch-py/pull/513)) diff --git a/opensearchpy/_async/client/__init__.py b/opensearchpy/_async/client/__init__.py index 7f0d4f98..a7587f82 100644 --- a/opensearchpy/_async/client/__init__.py +++ b/opensearchpy/_async/client/__init__.py @@ -50,6 +50,7 @@ from .nodes import NodesClient from .plugins import PluginsClient from .remote import RemoteClient +from .remote_store import RemoteStoreClient from .security import SecurityClient from .snapshot import SnapshotClient from .tasks import TasksClient @@ -217,6 +218,7 @@ class as kwargs, or a string in the format of ``host[:port]`` which will be self.security = SecurityClient(self) self.snapshot = SnapshotClient(self) self.tasks = TasksClient(self) + self.remote_store = RemoteStoreClient(self) self.features = FeaturesClient(self) diff --git a/opensearchpy/_async/client/__init__.pyi b/opensearchpy/_async/client/__init__.pyi index 70a93d19..32ea967e 100644 --- a/opensearchpy/_async/client/__init__.pyi +++ b/opensearchpy/_async/client/__init__.pyi @@ -48,6 +48,7 @@ from .indices import IndicesClient from .ingest import IngestClient from .nodes import NodesClient from .remote import RemoteClient +from .remote_store import RemoteStoreClient from .security import SecurityClient from .snapshot import SnapshotClient from .tasks import TasksClient @@ -67,6 +68,7 @@ class AsyncOpenSearch(object): security: SecurityClient snapshot: SnapshotClient tasks: TasksClient + remote_store: RemoteStoreClient def __init__( self, hosts: Any = ..., diff --git a/opensearchpy/_async/client/remote_store.py b/opensearchpy/_async/client/remote_store.py new file mode 100644 index 00000000..731d1233 --- /dev/null +++ b/opensearchpy/_async/client/remote_store.py @@ -0,0 +1,40 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# The OpenSearch Contributors require contributions made to +# this file be licensed under the Apache-2.0 license or a +# compatible open source license. +# +# Modifications Copyright OpenSearch Contributors. See +# GitHub history for details. +# ---------------------------------------------------- +# THIS CODE IS GENERATED AND MANUAL EDITS WILL BE LOST. +# +# To contribute, kindly make essential modifications through either the "opensearch-py client generator": +# https://github.com/opensearch-project/opensearch-py/blob/main/utils/generate-api.py +# or the "OpenSearch API specification" available at: +# https://github.com/opensearch-project/opensearch-api-specification/blob/main/OpenSearch.openapi.json +# ----------------------------------------------------- + + +from .utils import SKIP_IN_PATH, NamespacedClient, query_params + + +class RemoteStoreClient(NamespacedClient): + @query_params("cluster_manager_timeout", "wait_for_completion") + async def restore(self, body, params=None, headers=None): + """ + Restores from remote store. + + + :arg body: Comma-separated list of index IDs + :arg cluster_manager_timeout: Operation timeout for connection + to cluster-manager node. + :arg wait_for_completion: Should this request wait until the + operation has completed before returning. (default: false) + """ + if body in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'body'.") + + return await self.transport.perform_request( + "POST", "/_remotestore/_restore", params=params, headers=headers, body=body + ) diff --git a/opensearchpy/_async/client/remote_store.pyi b/opensearchpy/_async/client/remote_store.pyi new file mode 100644 index 00000000..8ea2d077 --- /dev/null +++ b/opensearchpy/_async/client/remote_store.pyi @@ -0,0 +1,41 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# The OpenSearch Contributors require contributions made to +# this file be licensed under the Apache-2.0 license or a +# compatible open source license. +# +# Modifications Copyright OpenSearch Contributors. See +# GitHub history for details. +# ---------------------------------------------------- +# THIS CODE IS GENERATED AND MANUAL EDITS WILL BE LOST. +# +# To contribute, kindly make essential modifications through either the "opensearch-py client generator": +# https://github.com/opensearch-project/opensearch-py/blob/main/utils/generate-api.py +# or the "OpenSearch API specification" available at: +# https://github.com/opensearch-project/opensearch-api-specification/blob/main/OpenSearch.openapi.json +# ----------------------------------------------------- + +from typing import Any, Collection, MutableMapping, Optional, Tuple, Union + +from .utils import NamespacedClient + +class RemoteStoreClient(NamespacedClient): + async def restore( + self, + *, + body: Any, + cluster_manager_timeout: Optional[Any] = ..., + wait_for_completion: Optional[Any] = ..., + pretty: Optional[bool] = ..., + human: Optional[bool] = ..., + error_trace: Optional[bool] = ..., + format: Optional[str] = ..., + filter_path: Optional[Union[str, Collection[str]]] = ..., + request_timeout: Optional[Union[int, float]] = ..., + ignore: Optional[Union[int, Collection[int]]] = ..., + opaque_id: Optional[str] = ..., + http_auth: Optional[Union[str, Tuple[str, str]]] = ..., + api_key: Optional[Union[str, Tuple[str, str]]] = ..., + params: Optional[MutableMapping[str, Any]] = ..., + headers: Optional[MutableMapping[str, str]] = ..., + ) -> Any: ... diff --git a/opensearchpy/client/__init__.py b/opensearchpy/client/__init__.py index 25a779fd..6a8dffb6 100644 --- a/opensearchpy/client/__init__.py +++ b/opensearchpy/client/__init__.py @@ -50,6 +50,7 @@ from .nodes import NodesClient from .plugins import PluginsClient from .remote import RemoteClient +from .remote_store import RemoteStoreClient from .security import SecurityClient from .snapshot import SnapshotClient from .tasks import TasksClient @@ -217,6 +218,7 @@ class as kwargs, or a string in the format of ``host[:port]`` which will be self.security = SecurityClient(self) self.snapshot = SnapshotClient(self) self.tasks = TasksClient(self) + self.remote_store = RemoteStoreClient(self) self.features = FeaturesClient(self) diff --git a/opensearchpy/client/__init__.pyi b/opensearchpy/client/__init__.pyi index 5bf53ec7..9ad72a83 100644 --- a/opensearchpy/client/__init__.pyi +++ b/opensearchpy/client/__init__.pyi @@ -48,6 +48,7 @@ from .indices import IndicesClient from .ingest import IngestClient from .nodes import NodesClient from .remote import RemoteClient +from .remote_store import RemoteStoreClient from .security import SecurityClient from .snapshot import SnapshotClient from .tasks import TasksClient @@ -67,6 +68,7 @@ class OpenSearch(object): security: SecurityClient snapshot: SnapshotClient tasks: TasksClient + remote_store: RemoteStoreClient def __init__( self, hosts: Any = ..., diff --git a/opensearchpy/client/remote_store.py b/opensearchpy/client/remote_store.py new file mode 100644 index 00000000..a8fcfe06 --- /dev/null +++ b/opensearchpy/client/remote_store.py @@ -0,0 +1,40 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# The OpenSearch Contributors require contributions made to +# this file be licensed under the Apache-2.0 license or a +# compatible open source license. +# +# Modifications Copyright OpenSearch Contributors. See +# GitHub history for details. +# ---------------------------------------------------- +# THIS CODE IS GENERATED AND MANUAL EDITS WILL BE LOST. +# +# To contribute, kindly make essential modifications through either the "opensearch-py client generator": +# https://github.com/opensearch-project/opensearch-py/blob/main/utils/generate-api.py +# or the "OpenSearch API specification" available at: +# https://github.com/opensearch-project/opensearch-api-specification/blob/main/OpenSearch.openapi.json +# ----------------------------------------------------- + + +from .utils import SKIP_IN_PATH, NamespacedClient, query_params + + +class RemoteStoreClient(NamespacedClient): + @query_params("cluster_manager_timeout", "wait_for_completion") + def restore(self, body, params=None, headers=None): + """ + Restores from remote store. + + + :arg body: Comma-separated list of index IDs + :arg cluster_manager_timeout: Operation timeout for connection + to cluster-manager node. + :arg wait_for_completion: Should this request wait until the + operation has completed before returning. (default: false) + """ + if body in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'body'.") + + return self.transport.perform_request( + "POST", "/_remotestore/_restore", params=params, headers=headers, body=body + ) diff --git a/opensearchpy/client/remote_store.pyi b/opensearchpy/client/remote_store.pyi new file mode 100644 index 00000000..99928f3b --- /dev/null +++ b/opensearchpy/client/remote_store.pyi @@ -0,0 +1,41 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# The OpenSearch Contributors require contributions made to +# this file be licensed under the Apache-2.0 license or a +# compatible open source license. +# +# Modifications Copyright OpenSearch Contributors. See +# GitHub history for details. +# ---------------------------------------------------- +# THIS CODE IS GENERATED AND MANUAL EDITS WILL BE LOST. +# +# To contribute, kindly make essential modifications through either the "opensearch-py client generator": +# https://github.com/opensearch-project/opensearch-py/blob/main/utils/generate-api.py +# or the "OpenSearch API specification" available at: +# https://github.com/opensearch-project/opensearch-api-specification/blob/main/OpenSearch.openapi.json +# ----------------------------------------------------- + +from typing import Any, Collection, MutableMapping, Optional, Tuple, Union + +from .utils import NamespacedClient + +class RemoteStoreClient(NamespacedClient): + def restore( + self, + *, + body: Any, + cluster_manager_timeout: Optional[Any] = ..., + wait_for_completion: Optional[Any] = ..., + pretty: Optional[bool] = ..., + human: Optional[bool] = ..., + error_trace: Optional[bool] = ..., + format: Optional[str] = ..., + filter_path: Optional[Union[str, Collection[str]]] = ..., + request_timeout: Optional[Union[int, float]] = ..., + ignore: Optional[Union[int, Collection[int]]] = ..., + opaque_id: Optional[str] = ..., + http_auth: Optional[Union[str, Tuple[str, str]]] = ..., + api_key: Optional[Union[str, Tuple[str, str]]] = ..., + params: Optional[MutableMapping[str, Any]] = ..., + headers: Optional[MutableMapping[str, str]] = ..., + ) -> Any: ... diff --git a/test_opensearchpy/test_client/test_remote_store.py b/test_opensearchpy/test_client/test_remote_store.py new file mode 100644 index 00000000..eb6187b4 --- /dev/null +++ b/test_opensearchpy/test_client/test_remote_store.py @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# The OpenSearch Contributors require contributions made to +# this file be licensed under the Apache-2.0 license or a +# compatible open source license. +# +# Modifications Copyright OpenSearch Contributors. See +# GitHub history for details. +from test_opensearchpy.test_cases import OpenSearchTestCase + + +class TestRemoteStore(OpenSearchTestCase): + def test_remote_store_restore(self): + self.client.remote_store.restore(body=["index-1"]) + self.assert_url_called("POST", "/_remotestore/_restore")