From 65f5f18dd04233d2f916b452fd3f18d7c0c537d3 Mon Sep 17 00:00:00 2001 From: saimedhi <117196660+saimedhi@users.noreply.github.com> Date: Tue, 10 Dec 2024 03:42:47 +0000 Subject: [PATCH] Updated opensearch-py to reflect the latest OpenSearch API spec (2024-12-10) Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- CHANGELOG.md | 1 + opensearchpy/_async/client/__init__.py | 20 +- opensearchpy/_async/client/indices.py | 9 +- opensearchpy/_async/client/plugins.py | 4 + opensearchpy/_async/plugins/knn.py | 5 +- opensearchpy/_async/plugins/observability.py | 2 +- opensearchpy/_async/plugins/sm.py | 346 +++++++++++++++++++ opensearchpy/client/__init__.py | 20 +- opensearchpy/client/indices.py | 9 +- opensearchpy/client/plugins.py | 4 + opensearchpy/plugins/knn.py | 5 +- opensearchpy/plugins/observability.py | 2 +- opensearchpy/plugins/sm.py | 346 +++++++++++++++++++ 13 files changed, 747 insertions(+), 26 deletions(-) create mode 100644 opensearchpy/_async/plugins/sm.py create mode 100644 opensearchpy/plugins/sm.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 3354d4e1..4d662986 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Added option to pass custom headers to 'AWSV4SignerAsyncAuth' ([863](https://github.com/opensearch-project/opensearch-py/pull/863)) - Added sync and async sample that uses `search_after` parameter ([859](https://github.com/opensearch-project/opensearch-py/pull/859)) ### Updated APIs +- Updated opensearch-py APIs to reflect [opensearch-api-specification@c0237fb](https://github.com/opensearch-project/opensearch-api-specification/commit/c0237fb6e96bb1614c946a51d31a9461ddb4cfdb) ### Changed - Small refactor of AWS Signer classes for both sync and async clients ([866](https://github.com/opensearch-project/opensearch-py/pull/866)) ### Deprecated diff --git a/opensearchpy/_async/client/__init__.py b/opensearchpy/_async/client/__init__.py index 5c1fa04f..2ae52901 100644 --- a/opensearchpy/_async/client/__init__.py +++ b/opensearchpy/_async/client/__init__.py @@ -667,7 +667,7 @@ async def count( specified. :arg default_operator: The default operator for query string query: `AND` or `OR`. This parameter can only be used when the `q` query - string parameter is specified. Valid choices are and, or. + string parameter is specified. Valid choices are and, AND, or, OR. :arg df: Field to use as default where no field prefix is given in the query string. This parameter can only be used when the `q` query string parameter is specified. @@ -855,7 +855,7 @@ async def delete_by_query( :arg conflicts: What to do if delete by query hits version conflicts: `abort` or `proceed`. Valid choices are abort, proceed. :arg default_operator: The default operator for query string - query: `AND` or `OR`. Valid choices are and, or. + query: `AND` or `OR`. Valid choices are and, AND, or, OR. :arg df: Field to use as default where no field prefix is given in the query string. :arg error_trace: Whether to include the stack trace of returned @@ -1225,7 +1225,7 @@ async def explain( parameter can only be used when the `q` query string parameter is specified. :arg default_operator: The default operator for query string - query: `AND` or `OR`. Valid choices are and, or. + query: `AND` or `OR`. Valid choices are and, AND, or, OR. :arg df: Field to use as default where no field prefix is given in the query string. Default is _all. :arg error_trace: Whether to include the stack trace of returned @@ -2281,7 +2281,7 @@ async def search( executing cross-cluster search (CCS) requests. Default is True. :arg default_operator: The default operator for query string query: AND or OR. This parameter can only be used when the `q` query - string parameter is specified. Valid choices are and, or. + string parameter is specified. Valid choices are and, AND, or, OR. :arg df: Field to use as default where no field prefix is given in the query string. This parameter can only be used when the q query string parameter is specified. @@ -2451,6 +2451,7 @@ async def search( ) async def search_shards( self, + body: Any = None, index: Any = None, params: Any = None, headers: Any = None, @@ -2460,6 +2461,9 @@ async def search_shards( executed against. + :arg body: Defines the parameters that can be used in the + `search_shards` endpoint request. See documentation for supported query + syntax. :arg index: Returns the indexes and shards that a search request would be executed against. :arg allow_no_indices: If `false`, the request returns an error @@ -2495,7 +2499,11 @@ async def search_shards( libraries that do not accept a request body for non-POST requests. """ return await self.transport.perform_request( - "GET", _make_path(index, "_search_shards"), params=params, headers=headers + "POST", + _make_path(index, "_search_shards"), + params=params, + headers=headers, + body=body, ) @query_params( @@ -2834,7 +2842,7 @@ async def update_by_query( :arg conflicts: What to do if update by query hits version conflicts: `abort` or `proceed`. Valid choices are abort, proceed. :arg default_operator: The default operator for query string - query: `AND` or `OR`. Valid choices are and, or. + query: `AND` or `OR`. Valid choices are and, AND, or, OR. :arg df: Field to use as default where no field prefix is given in the query string. :arg error_trace: Whether to include the stack trace of returned diff --git a/opensearchpy/_async/client/indices.py b/opensearchpy/_async/client/indices.py index 99603830..2a10af57 100644 --- a/opensearchpy/_async/client/indices.py +++ b/opensearchpy/_async/client/indices.py @@ -1638,7 +1638,7 @@ async def validate_query( parameter can only be used when the `q` query string parameter is specified. :arg default_operator: The default operator for query string - query: `AND` or `OR`. Valid choices are and, or. + query: `AND` or `OR`. Valid choices are and, AND, or, OR. :arg df: Field to use as default where no field prefix is given in the query string. This parameter can only be used when the `q` query string parameter is specified. @@ -1797,6 +1797,7 @@ async def recovery( ) async def upgrade( self, + body: Any = None, index: Any = None, params: Any = None, headers: Any = None, @@ -1832,7 +1833,11 @@ async def upgrade( operation has completed before returning. Default is false. """ return await self.transport.perform_request( - "POST", _make_path(index, "_upgrade"), params=params, headers=headers + "POST", + _make_path(index, "_upgrade"), + params=params, + headers=headers, + body=body, ) @query_params( diff --git a/opensearchpy/_async/client/plugins.py b/opensearchpy/_async/client/plugins.py index d625f838..985839cd 100644 --- a/opensearchpy/_async/client/plugins.py +++ b/opensearchpy/_async/client/plugins.py @@ -22,6 +22,7 @@ from ..plugins.query import QueryClient from ..plugins.replication import ReplicationClient from ..plugins.rollups import RollupsClient +from ..plugins.sm import SmClient from ..plugins.sql import SqlClient from ..plugins.transforms import TransformsClient from .client import Client @@ -29,6 +30,7 @@ class PluginsClient(NamespacedClient): + sm: Any asynchronous_search: Any alerting: Any index_management: Any @@ -45,6 +47,7 @@ class PluginsClient(NamespacedClient): def __init__(self, client: Client) -> None: super().__init__(client) + self.sm = SmClient(client) self.replication = ReplicationClient(client) self.flow_framework = FlowFrameworkClient(client) self.asynchronous_search = AsynchronousSearchClient(client) @@ -66,6 +69,7 @@ def _dynamic_lookup(self, client: Any) -> None: # Issue : https://github.com/opensearch-project/opensearch-py/issues/90#issuecomment-1003396742 plugins = [ + "sm", "replication", "flow_framework", "asynchronous_search", diff --git a/opensearchpy/_async/plugins/knn.py b/opensearchpy/_async/plugins/knn.py index 8cf7fa42..fd5e2e31 100644 --- a/opensearchpy/_async/plugins/knn.py +++ b/opensearchpy/_async/plugins/knn.py @@ -310,7 +310,7 @@ async def stats( ) async def train_model( self, - body: Any, + body: Any = None, model_id: Any = None, params: Any = None, headers: Any = None, @@ -335,9 +335,6 @@ async def train_model( :arg source: The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests. """ - if body in SKIP_IN_PATH: - raise ValueError("Empty value passed for a required argument 'body'.") - return await self.transport.perform_request( "POST", _make_path("_plugins", "_knn", "models", model_id, "_train"), diff --git a/opensearchpy/_async/plugins/observability.py b/opensearchpy/_async/plugins/observability.py index 1242171d..3894a611 100644 --- a/opensearchpy/_async/plugins/observability.py +++ b/opensearchpy/_async/plugins/observability.py @@ -135,7 +135,7 @@ async def get_localstats( headers: Any = None, ) -> Any: """ - Retrieves Local Stats of all observability objects. + Retrieves local stats of all observability objects. :arg error_trace: Whether to include the stack trace of returned diff --git a/opensearchpy/_async/plugins/sm.py b/opensearchpy/_async/plugins/sm.py new file mode 100644 index 00000000..4ea3a1d9 --- /dev/null +++ b/opensearchpy/_async/plugins/sm.py @@ -0,0 +1,346 @@ +# 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 AUTOMATICALLY GENERATED AND MANUAL EDITS WILL BE LOST +# +# To contribute, kindly make modifications in the opensearch-py client generator +# or in the OpenSearch API specification, and run `nox -rs generate`. See DEVELOPER_GUIDE.md +# and https://github.com/opensearch-project/opensearch-api-specification for details. +# -----------------------------------------------------------------------------------------+ + + +from typing import Any + +from ..client.utils import SKIP_IN_PATH, NamespacedClient, _make_path, query_params + + +class SmClient(NamespacedClient): + @query_params("error_trace", "filter_path", "human", "pretty", "source") + async def create_policy( + self, + policy_name: Any, + body: Any = None, + params: Any = None, + headers: Any = None, + ) -> Any: + """ + Creates a snapshot management policy. + + + :arg policy_name: The name of the snapshot management policy. + :arg error_trace: Whether to include the stack trace of returned + errors. Default is false. + :arg filter_path: Used to reduce the response. This parameter + takes a comma-separated list of filters. It supports using wildcards to + match any field or part of a field’s name. You can also exclude fields + with "-". + :arg human: Whether to return human readable values for + statistics. Default is True. + :arg pretty: Whether to pretty format the returned JSON + response. Default is false. + :arg source: The URL-encoded request definition. Useful for + libraries that do not accept a request body for non-POST requests. + """ + if policy_name in SKIP_IN_PATH: + raise ValueError( + "Empty value passed for a required argument 'policy_name'." + ) + + return await self.transport.perform_request( + "POST", + _make_path("_plugins", "_sm", "policies", policy_name), + params=params, + headers=headers, + body=body, + ) + + @query_params("error_trace", "filter_path", "human", "pretty", "source") + async def delete_policy( + self, + policy_name: Any, + params: Any = None, + headers: Any = None, + ) -> Any: + """ + Deletes a snapshot management policy. + + + :arg policy_name: The name of the snapshot management policy. + :arg error_trace: Whether to include the stack trace of returned + errors. Default is false. + :arg filter_path: Used to reduce the response. This parameter + takes a comma-separated list of filters. It supports using wildcards to + match any field or part of a field’s name. You can also exclude fields + with "-". + :arg human: Whether to return human readable values for + statistics. Default is True. + :arg pretty: Whether to pretty format the returned JSON + response. Default is false. + :arg source: The URL-encoded request definition. Useful for + libraries that do not accept a request body for non-POST requests. + """ + if policy_name in SKIP_IN_PATH: + raise ValueError( + "Empty value passed for a required argument 'policy_name'." + ) + + return await self.transport.perform_request( + "DELETE", + _make_path("_plugins", "_sm", "policies", policy_name), + params=params, + headers=headers, + ) + + @query_params("error_trace", "filter_path", "human", "pretty", "source") + async def explain_policy( + self, + policy_name: Any, + params: Any = None, + headers: Any = None, + ) -> Any: + """ + Explains the state of the snapshot management policy. + + + :arg policy_name: The name of the snapshot management policy. + :arg error_trace: Whether to include the stack trace of returned + errors. Default is false. + :arg filter_path: Used to reduce the response. This parameter + takes a comma-separated list of filters. It supports using wildcards to + match any field or part of a field’s name. You can also exclude fields + with "-". + :arg human: Whether to return human readable values for + statistics. Default is True. + :arg pretty: Whether to pretty format the returned JSON + response. Default is false. + :arg source: The URL-encoded request definition. Useful for + libraries that do not accept a request body for non-POST requests. + """ + if policy_name in SKIP_IN_PATH: + raise ValueError( + "Empty value passed for a required argument 'policy_name'." + ) + + return await self.transport.perform_request( + "GET", + _make_path("_plugins", "_sm", "policies", policy_name, "_explain"), + params=params, + headers=headers, + ) + + @query_params( + "error_trace", + "filter_path", + "from_", + "human", + "pretty", + "queryString", + "size", + "sortField", + "sortOrder", + "source", + ) + async def get_policies( + self, + params: Any = None, + headers: Any = None, + ) -> Any: + """ + Retrieves all snapshot management policies with optional pagination and + filtering. + + + :arg error_trace: Whether to include the stack trace of returned + errors. Default is false. + :arg filter_path: Used to reduce the response. This parameter + takes a comma-separated list of filters. It supports using wildcards to + match any field or part of a field’s name. You can also exclude fields + with "-". + :arg from_: The starting index (default: 0) + :arg human: Whether to return human readable values for + statistics. Default is True. + :arg pretty: Whether to pretty format the returned JSON + response. Default is false. + :arg queryString: A query string to filter policies. + :arg size: The number of policies to return. + :arg sortField: The field to sort on. + :arg sortOrder: The order of sorting. Valid choices are asc, + desc.Default is asc. + :arg source: The URL-encoded request definition. Useful for + libraries that do not accept a request body for non-POST requests. + """ + # from is a reserved word so it cannot be used, use from_ instead + if "from_" in params: + params["from"] = params.pop("from_") + + return await self.transport.perform_request( + "GET", "/_plugins/_sm/policies", params=params, headers=headers + ) + + @query_params("error_trace", "filter_path", "human", "pretty", "source") + async def get_policy( + self, + policy_name: Any, + params: Any = None, + headers: Any = None, + ) -> Any: + """ + Retrieves a specific snapshot management policy by name. + + + :arg policy_name: The name of the snapshot management policy. + :arg error_trace: Whether to include the stack trace of returned + errors. Default is false. + :arg filter_path: Used to reduce the response. This parameter + takes a comma-separated list of filters. It supports using wildcards to + match any field or part of a field’s name. You can also exclude fields + with "-". + :arg human: Whether to return human readable values for + statistics. Default is True. + :arg pretty: Whether to pretty format the returned JSON + response. Default is false. + :arg source: The URL-encoded request definition. Useful for + libraries that do not accept a request body for non-POST requests. + """ + if policy_name in SKIP_IN_PATH: + raise ValueError( + "Empty value passed for a required argument 'policy_name'." + ) + + return await self.transport.perform_request( + "GET", + _make_path("_plugins", "_sm", "policies", policy_name), + params=params, + headers=headers, + ) + + @query_params("error_trace", "filter_path", "human", "pretty", "source") + async def start_policy( + self, + policy_name: Any, + params: Any = None, + headers: Any = None, + ) -> Any: + """ + Starts a snapshot management policy. + + + :arg policy_name: The name of the snapshot management policy. + :arg error_trace: Whether to include the stack trace of returned + errors. Default is false. + :arg filter_path: Used to reduce the response. This parameter + takes a comma-separated list of filters. It supports using wildcards to + match any field or part of a field’s name. You can also exclude fields + with "-". + :arg human: Whether to return human readable values for + statistics. Default is True. + :arg pretty: Whether to pretty format the returned JSON + response. Default is false. + :arg source: The URL-encoded request definition. Useful for + libraries that do not accept a request body for non-POST requests. + """ + if policy_name in SKIP_IN_PATH: + raise ValueError( + "Empty value passed for a required argument 'policy_name'." + ) + + return await self.transport.perform_request( + "POST", + _make_path("_plugins", "_sm", "policies", policy_name, "_start"), + params=params, + headers=headers, + ) + + @query_params("error_trace", "filter_path", "human", "pretty", "source") + async def stop_policy( + self, + policy_name: Any, + params: Any = None, + headers: Any = None, + ) -> Any: + """ + Stops a snapshot management policy. + + + :arg policy_name: The name of the snapshot management policy. + :arg error_trace: Whether to include the stack trace of returned + errors. Default is false. + :arg filter_path: Used to reduce the response. This parameter + takes a comma-separated list of filters. It supports using wildcards to + match any field or part of a field’s name. You can also exclude fields + with "-". + :arg human: Whether to return human readable values for + statistics. Default is True. + :arg pretty: Whether to pretty format the returned JSON + response. Default is false. + :arg source: The URL-encoded request definition. Useful for + libraries that do not accept a request body for non-POST requests. + """ + if policy_name in SKIP_IN_PATH: + raise ValueError( + "Empty value passed for a required argument 'policy_name'." + ) + + return await self.transport.perform_request( + "POST", + _make_path("_plugins", "_sm", "policies", policy_name, "_stop"), + params=params, + headers=headers, + ) + + @query_params( + "error_trace", + "filter_path", + "human", + "if_primary_term", + "if_seq_no", + "pretty", + "source", + ) + async def update_policy( + self, + policy_name: Any, + body: Any = None, + params: Any = None, + headers: Any = None, + ) -> Any: + """ + Updates an existing snapshot management policy. Requires `if_seq_no` and + `if_primary_term`. + + + :arg policy_name: The name of the snapshot management policy. + :arg error_trace: Whether to include the stack trace of returned + errors. Default is false. + :arg filter_path: Used to reduce the response. This parameter + takes a comma-separated list of filters. It supports using wildcards to + match any field or part of a field’s name. You can also exclude fields + with "-". + :arg human: Whether to return human readable values for + statistics. Default is True. + :arg if_primary_term: The primary term of the policy to update. + :arg if_seq_no: The sequence number of the policy to update. + :arg pretty: Whether to pretty format the returned JSON + response. Default is false. + :arg source: The URL-encoded request definition. Useful for + libraries that do not accept a request body for non-POST requests. + """ + if policy_name in SKIP_IN_PATH: + raise ValueError( + "Empty value passed for a required argument 'policy_name'." + ) + + return await self.transport.perform_request( + "PUT", + _make_path("_plugins", "_sm", "policies", policy_name), + params=params, + headers=headers, + body=body, + ) diff --git a/opensearchpy/client/__init__.py b/opensearchpy/client/__init__.py index 118cfa7a..680ede25 100644 --- a/opensearchpy/client/__init__.py +++ b/opensearchpy/client/__init__.py @@ -667,7 +667,7 @@ def count( specified. :arg default_operator: The default operator for query string query: `AND` or `OR`. This parameter can only be used when the `q` query - string parameter is specified. Valid choices are and, or. + string parameter is specified. Valid choices are and, AND, or, OR. :arg df: Field to use as default where no field prefix is given in the query string. This parameter can only be used when the `q` query string parameter is specified. @@ -855,7 +855,7 @@ def delete_by_query( :arg conflicts: What to do if delete by query hits version conflicts: `abort` or `proceed`. Valid choices are abort, proceed. :arg default_operator: The default operator for query string - query: `AND` or `OR`. Valid choices are and, or. + query: `AND` or `OR`. Valid choices are and, AND, or, OR. :arg df: Field to use as default where no field prefix is given in the query string. :arg error_trace: Whether to include the stack trace of returned @@ -1225,7 +1225,7 @@ def explain( parameter can only be used when the `q` query string parameter is specified. :arg default_operator: The default operator for query string - query: `AND` or `OR`. Valid choices are and, or. + query: `AND` or `OR`. Valid choices are and, AND, or, OR. :arg df: Field to use as default where no field prefix is given in the query string. Default is _all. :arg error_trace: Whether to include the stack trace of returned @@ -2281,7 +2281,7 @@ def search( executing cross-cluster search (CCS) requests. Default is True. :arg default_operator: The default operator for query string query: AND or OR. This parameter can only be used when the `q` query - string parameter is specified. Valid choices are and, or. + string parameter is specified. Valid choices are and, AND, or, OR. :arg df: Field to use as default where no field prefix is given in the query string. This parameter can only be used when the q query string parameter is specified. @@ -2451,6 +2451,7 @@ def search( ) def search_shards( self, + body: Any = None, index: Any = None, params: Any = None, headers: Any = None, @@ -2460,6 +2461,9 @@ def search_shards( executed against. + :arg body: Defines the parameters that can be used in the + `search_shards` endpoint request. See documentation for supported query + syntax. :arg index: Returns the indexes and shards that a search request would be executed against. :arg allow_no_indices: If `false`, the request returns an error @@ -2495,7 +2499,11 @@ def search_shards( libraries that do not accept a request body for non-POST requests. """ return self.transport.perform_request( - "GET", _make_path(index, "_search_shards"), params=params, headers=headers + "POST", + _make_path(index, "_search_shards"), + params=params, + headers=headers, + body=body, ) @query_params( @@ -2834,7 +2842,7 @@ def update_by_query( :arg conflicts: What to do if update by query hits version conflicts: `abort` or `proceed`. Valid choices are abort, proceed. :arg default_operator: The default operator for query string - query: `AND` or `OR`. Valid choices are and, or. + query: `AND` or `OR`. Valid choices are and, AND, or, OR. :arg df: Field to use as default where no field prefix is given in the query string. :arg error_trace: Whether to include the stack trace of returned diff --git a/opensearchpy/client/indices.py b/opensearchpy/client/indices.py index c4b2405c..61523e1b 100644 --- a/opensearchpy/client/indices.py +++ b/opensearchpy/client/indices.py @@ -1638,7 +1638,7 @@ def validate_query( parameter can only be used when the `q` query string parameter is specified. :arg default_operator: The default operator for query string - query: `AND` or `OR`. Valid choices are and, or. + query: `AND` or `OR`. Valid choices are and, AND, or, OR. :arg df: Field to use as default where no field prefix is given in the query string. This parameter can only be used when the `q` query string parameter is specified. @@ -1797,6 +1797,7 @@ def recovery( ) def upgrade( self, + body: Any = None, index: Any = None, params: Any = None, headers: Any = None, @@ -1832,7 +1833,11 @@ def upgrade( operation has completed before returning. Default is false. """ return self.transport.perform_request( - "POST", _make_path(index, "_upgrade"), params=params, headers=headers + "POST", + _make_path(index, "_upgrade"), + params=params, + headers=headers, + body=body, ) @query_params( diff --git a/opensearchpy/client/plugins.py b/opensearchpy/client/plugins.py index d625f838..985839cd 100644 --- a/opensearchpy/client/plugins.py +++ b/opensearchpy/client/plugins.py @@ -22,6 +22,7 @@ from ..plugins.query import QueryClient from ..plugins.replication import ReplicationClient from ..plugins.rollups import RollupsClient +from ..plugins.sm import SmClient from ..plugins.sql import SqlClient from ..plugins.transforms import TransformsClient from .client import Client @@ -29,6 +30,7 @@ class PluginsClient(NamespacedClient): + sm: Any asynchronous_search: Any alerting: Any index_management: Any @@ -45,6 +47,7 @@ class PluginsClient(NamespacedClient): def __init__(self, client: Client) -> None: super().__init__(client) + self.sm = SmClient(client) self.replication = ReplicationClient(client) self.flow_framework = FlowFrameworkClient(client) self.asynchronous_search = AsynchronousSearchClient(client) @@ -66,6 +69,7 @@ def _dynamic_lookup(self, client: Any) -> None: # Issue : https://github.com/opensearch-project/opensearch-py/issues/90#issuecomment-1003396742 plugins = [ + "sm", "replication", "flow_framework", "asynchronous_search", diff --git a/opensearchpy/plugins/knn.py b/opensearchpy/plugins/knn.py index 191bfb5f..c5b2e065 100644 --- a/opensearchpy/plugins/knn.py +++ b/opensearchpy/plugins/knn.py @@ -310,7 +310,7 @@ def stats( ) def train_model( self, - body: Any, + body: Any = None, model_id: Any = None, params: Any = None, headers: Any = None, @@ -335,9 +335,6 @@ def train_model( :arg source: The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests. """ - if body in SKIP_IN_PATH: - raise ValueError("Empty value passed for a required argument 'body'.") - return self.transport.perform_request( "POST", _make_path("_plugins", "_knn", "models", model_id, "_train"), diff --git a/opensearchpy/plugins/observability.py b/opensearchpy/plugins/observability.py index 2bf9e03f..af1d68ba 100644 --- a/opensearchpy/plugins/observability.py +++ b/opensearchpy/plugins/observability.py @@ -135,7 +135,7 @@ def get_localstats( headers: Any = None, ) -> Any: """ - Retrieves Local Stats of all observability objects. + Retrieves local stats of all observability objects. :arg error_trace: Whether to include the stack trace of returned diff --git a/opensearchpy/plugins/sm.py b/opensearchpy/plugins/sm.py new file mode 100644 index 00000000..7c5cb208 --- /dev/null +++ b/opensearchpy/plugins/sm.py @@ -0,0 +1,346 @@ +# 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 AUTOMATICALLY GENERATED AND MANUAL EDITS WILL BE LOST +# +# To contribute, kindly make modifications in the opensearch-py client generator +# or in the OpenSearch API specification, and run `nox -rs generate`. See DEVELOPER_GUIDE.md +# and https://github.com/opensearch-project/opensearch-api-specification for details. +# -----------------------------------------------------------------------------------------+ + + +from typing import Any + +from ..client.utils import SKIP_IN_PATH, NamespacedClient, _make_path, query_params + + +class SmClient(NamespacedClient): + @query_params("error_trace", "filter_path", "human", "pretty", "source") + def create_policy( + self, + policy_name: Any, + body: Any = None, + params: Any = None, + headers: Any = None, + ) -> Any: + """ + Creates a snapshot management policy. + + + :arg policy_name: The name of the snapshot management policy. + :arg error_trace: Whether to include the stack trace of returned + errors. Default is false. + :arg filter_path: Used to reduce the response. This parameter + takes a comma-separated list of filters. It supports using wildcards to + match any field or part of a field’s name. You can also exclude fields + with "-". + :arg human: Whether to return human readable values for + statistics. Default is True. + :arg pretty: Whether to pretty format the returned JSON + response. Default is false. + :arg source: The URL-encoded request definition. Useful for + libraries that do not accept a request body for non-POST requests. + """ + if policy_name in SKIP_IN_PATH: + raise ValueError( + "Empty value passed for a required argument 'policy_name'." + ) + + return self.transport.perform_request( + "POST", + _make_path("_plugins", "_sm", "policies", policy_name), + params=params, + headers=headers, + body=body, + ) + + @query_params("error_trace", "filter_path", "human", "pretty", "source") + def delete_policy( + self, + policy_name: Any, + params: Any = None, + headers: Any = None, + ) -> Any: + """ + Deletes a snapshot management policy. + + + :arg policy_name: The name of the snapshot management policy. + :arg error_trace: Whether to include the stack trace of returned + errors. Default is false. + :arg filter_path: Used to reduce the response. This parameter + takes a comma-separated list of filters. It supports using wildcards to + match any field or part of a field’s name. You can also exclude fields + with "-". + :arg human: Whether to return human readable values for + statistics. Default is True. + :arg pretty: Whether to pretty format the returned JSON + response. Default is false. + :arg source: The URL-encoded request definition. Useful for + libraries that do not accept a request body for non-POST requests. + """ + if policy_name in SKIP_IN_PATH: + raise ValueError( + "Empty value passed for a required argument 'policy_name'." + ) + + return self.transport.perform_request( + "DELETE", + _make_path("_plugins", "_sm", "policies", policy_name), + params=params, + headers=headers, + ) + + @query_params("error_trace", "filter_path", "human", "pretty", "source") + def explain_policy( + self, + policy_name: Any, + params: Any = None, + headers: Any = None, + ) -> Any: + """ + Explains the state of the snapshot management policy. + + + :arg policy_name: The name of the snapshot management policy. + :arg error_trace: Whether to include the stack trace of returned + errors. Default is false. + :arg filter_path: Used to reduce the response. This parameter + takes a comma-separated list of filters. It supports using wildcards to + match any field or part of a field’s name. You can also exclude fields + with "-". + :arg human: Whether to return human readable values for + statistics. Default is True. + :arg pretty: Whether to pretty format the returned JSON + response. Default is false. + :arg source: The URL-encoded request definition. Useful for + libraries that do not accept a request body for non-POST requests. + """ + if policy_name in SKIP_IN_PATH: + raise ValueError( + "Empty value passed for a required argument 'policy_name'." + ) + + return self.transport.perform_request( + "GET", + _make_path("_plugins", "_sm", "policies", policy_name, "_explain"), + params=params, + headers=headers, + ) + + @query_params( + "error_trace", + "filter_path", + "from_", + "human", + "pretty", + "queryString", + "size", + "sortField", + "sortOrder", + "source", + ) + def get_policies( + self, + params: Any = None, + headers: Any = None, + ) -> Any: + """ + Retrieves all snapshot management policies with optional pagination and + filtering. + + + :arg error_trace: Whether to include the stack trace of returned + errors. Default is false. + :arg filter_path: Used to reduce the response. This parameter + takes a comma-separated list of filters. It supports using wildcards to + match any field or part of a field’s name. You can also exclude fields + with "-". + :arg from_: The starting index (default: 0) + :arg human: Whether to return human readable values for + statistics. Default is True. + :arg pretty: Whether to pretty format the returned JSON + response. Default is false. + :arg queryString: A query string to filter policies. + :arg size: The number of policies to return. + :arg sortField: The field to sort on. + :arg sortOrder: The order of sorting. Valid choices are asc, + desc.Default is asc. + :arg source: The URL-encoded request definition. Useful for + libraries that do not accept a request body for non-POST requests. + """ + # from is a reserved word so it cannot be used, use from_ instead + if "from_" in params: + params["from"] = params.pop("from_") + + return self.transport.perform_request( + "GET", "/_plugins/_sm/policies", params=params, headers=headers + ) + + @query_params("error_trace", "filter_path", "human", "pretty", "source") + def get_policy( + self, + policy_name: Any, + params: Any = None, + headers: Any = None, + ) -> Any: + """ + Retrieves a specific snapshot management policy by name. + + + :arg policy_name: The name of the snapshot management policy. + :arg error_trace: Whether to include the stack trace of returned + errors. Default is false. + :arg filter_path: Used to reduce the response. This parameter + takes a comma-separated list of filters. It supports using wildcards to + match any field or part of a field’s name. You can also exclude fields + with "-". + :arg human: Whether to return human readable values for + statistics. Default is True. + :arg pretty: Whether to pretty format the returned JSON + response. Default is false. + :arg source: The URL-encoded request definition. Useful for + libraries that do not accept a request body for non-POST requests. + """ + if policy_name in SKIP_IN_PATH: + raise ValueError( + "Empty value passed for a required argument 'policy_name'." + ) + + return self.transport.perform_request( + "GET", + _make_path("_plugins", "_sm", "policies", policy_name), + params=params, + headers=headers, + ) + + @query_params("error_trace", "filter_path", "human", "pretty", "source") + def start_policy( + self, + policy_name: Any, + params: Any = None, + headers: Any = None, + ) -> Any: + """ + Starts a snapshot management policy. + + + :arg policy_name: The name of the snapshot management policy. + :arg error_trace: Whether to include the stack trace of returned + errors. Default is false. + :arg filter_path: Used to reduce the response. This parameter + takes a comma-separated list of filters. It supports using wildcards to + match any field or part of a field’s name. You can also exclude fields + with "-". + :arg human: Whether to return human readable values for + statistics. Default is True. + :arg pretty: Whether to pretty format the returned JSON + response. Default is false. + :arg source: The URL-encoded request definition. Useful for + libraries that do not accept a request body for non-POST requests. + """ + if policy_name in SKIP_IN_PATH: + raise ValueError( + "Empty value passed for a required argument 'policy_name'." + ) + + return self.transport.perform_request( + "POST", + _make_path("_plugins", "_sm", "policies", policy_name, "_start"), + params=params, + headers=headers, + ) + + @query_params("error_trace", "filter_path", "human", "pretty", "source") + def stop_policy( + self, + policy_name: Any, + params: Any = None, + headers: Any = None, + ) -> Any: + """ + Stops a snapshot management policy. + + + :arg policy_name: The name of the snapshot management policy. + :arg error_trace: Whether to include the stack trace of returned + errors. Default is false. + :arg filter_path: Used to reduce the response. This parameter + takes a comma-separated list of filters. It supports using wildcards to + match any field or part of a field’s name. You can also exclude fields + with "-". + :arg human: Whether to return human readable values for + statistics. Default is True. + :arg pretty: Whether to pretty format the returned JSON + response. Default is false. + :arg source: The URL-encoded request definition. Useful for + libraries that do not accept a request body for non-POST requests. + """ + if policy_name in SKIP_IN_PATH: + raise ValueError( + "Empty value passed for a required argument 'policy_name'." + ) + + return self.transport.perform_request( + "POST", + _make_path("_plugins", "_sm", "policies", policy_name, "_stop"), + params=params, + headers=headers, + ) + + @query_params( + "error_trace", + "filter_path", + "human", + "if_primary_term", + "if_seq_no", + "pretty", + "source", + ) + def update_policy( + self, + policy_name: Any, + body: Any = None, + params: Any = None, + headers: Any = None, + ) -> Any: + """ + Updates an existing snapshot management policy. Requires `if_seq_no` and + `if_primary_term`. + + + :arg policy_name: The name of the snapshot management policy. + :arg error_trace: Whether to include the stack trace of returned + errors. Default is false. + :arg filter_path: Used to reduce the response. This parameter + takes a comma-separated list of filters. It supports using wildcards to + match any field or part of a field’s name. You can also exclude fields + with "-". + :arg human: Whether to return human readable values for + statistics. Default is True. + :arg if_primary_term: The primary term of the policy to update. + :arg if_seq_no: The sequence number of the policy to update. + :arg pretty: Whether to pretty format the returned JSON + response. Default is false. + :arg source: The URL-encoded request definition. Useful for + libraries that do not accept a request body for non-POST requests. + """ + if policy_name in SKIP_IN_PATH: + raise ValueError( + "Empty value passed for a required argument 'policy_name'." + ) + + return self.transport.perform_request( + "PUT", + _make_path("_plugins", "_sm", "policies", policy_name), + params=params, + headers=headers, + body=body, + )