Index State Management support (#398)
* feat(plugins): add index management client plugin Signed-off-by: florian <[email protected]> * chore(CHANGELOG): added entry for ISM api support in changelog Signed-off-by: florian <[email protected]> * test(plugins): use assertEqual to compare call parameters Signed-off-by: florian <[email protected]> * test(plugins): edit policy to support older versions of opensearch Signed-off-by: florian <[email protected]> * test(plugins): ignore plugin tests when opensearch is unreleased Signed-off-by: florian <[email protected]> * test(plugins): move plugin tests into separate files Signed-off-by: florian <[email protected]> * test(plugins): fix import of OpenSearchTestCase Signed-off-by: florian <[email protected]> * chore(USER_GUIDE): add a index management plugin part Signed-off-by: florian <[email protected]> --------- Signed-off-by: florian <[email protected]>
This commit is contained in:
@@ -0,0 +1,153 @@
|
||||
# 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 ..client.utils import SKIP_IN_PATH, NamespacedClient, _make_path, query_params
|
||||
|
||||
|
||||
class IndexManagementClient(NamespacedClient):
|
||||
@query_params()
|
||||
def put_policy(self, policy, body=None, params=None, headers=None):
|
||||
"""
|
||||
Creates, or updates, a policy.
|
||||
|
||||
:arg policy: The name of the policy
|
||||
"""
|
||||
if policy in SKIP_IN_PATH:
|
||||
raise ValueError("Empty value passed for a required argument 'policy'.")
|
||||
|
||||
return self.transport.perform_request(
|
||||
"PUT",
|
||||
_make_path("_plugins", "_ism", "policies", policy),
|
||||
params=params,
|
||||
headers=headers,
|
||||
body=body,
|
||||
)
|
||||
|
||||
@query_params()
|
||||
def add_policy(self, index, body=None, params=None, headers=None):
|
||||
"""
|
||||
Adds a policy to an index. This operation does not change the policy if the index already has one.
|
||||
|
||||
:arg index: The name of the index to add policy on
|
||||
"""
|
||||
if index in SKIP_IN_PATH:
|
||||
raise ValueError("Empty value passed for a required argument 'index'.")
|
||||
|
||||
return self.transport.perform_request(
|
||||
"POST",
|
||||
_make_path("_plugins", "_ism", "add", index),
|
||||
params=params,
|
||||
headers=headers,
|
||||
body=body,
|
||||
)
|
||||
|
||||
@query_params()
|
||||
def get_policy(self, policy, params=None, headers=None):
|
||||
"""
|
||||
Gets the policy by `policy_id`.
|
||||
|
||||
:arg policy: The name of the policy
|
||||
"""
|
||||
if policy in SKIP_IN_PATH:
|
||||
raise ValueError("Empty value passed for a required argument 'policy'.")
|
||||
|
||||
return self.transport.perform_request(
|
||||
"GET",
|
||||
_make_path("_plugins", "_ism", "policies", policy),
|
||||
params=params,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
@query_params()
|
||||
def remove_policy_from_index(self, index, params=None, headers=None):
|
||||
"""
|
||||
Removes any ISM policy from the index.
|
||||
|
||||
:arg index: The name of the index to remove policy on
|
||||
"""
|
||||
if index in SKIP_IN_PATH:
|
||||
raise ValueError("Empty value passed for a required argument 'index'.")
|
||||
|
||||
return self.transport.perform_request(
|
||||
"POST",
|
||||
_make_path("_plugins", "_ism", "remove", index),
|
||||
params=params,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
@query_params()
|
||||
def change_policy(self, index, body=None, params=None, headers=None):
|
||||
"""
|
||||
Updates the managed index policy to a new policy (or to a new version of the policy).
|
||||
|
||||
:arg index: The name of the index to change policy on
|
||||
"""
|
||||
if index in SKIP_IN_PATH:
|
||||
raise ValueError("Empty value passed for a required argument 'index'.")
|
||||
|
||||
return self.transport.perform_request(
|
||||
"POST",
|
||||
_make_path("_plugins", "_ism", "change_policy", index),
|
||||
params=params,
|
||||
headers=headers,
|
||||
body=body,
|
||||
)
|
||||
|
||||
@query_params()
|
||||
def retry(self, index, body=None, params=None, headers=None):
|
||||
"""
|
||||
Retries the failed action for an index.
|
||||
|
||||
:arg index: The name of the index whose is in a failed state
|
||||
"""
|
||||
if index in SKIP_IN_PATH:
|
||||
raise ValueError("Empty value passed for a required argument 'index'.")
|
||||
|
||||
return self.transport.perform_request(
|
||||
"POST",
|
||||
_make_path("_plugins", "_ism", "retry", index),
|
||||
params=params,
|
||||
headers=headers,
|
||||
body=body,
|
||||
)
|
||||
|
||||
@query_params("show_policy")
|
||||
def explain_index(self, index, params=None, headers=None):
|
||||
"""
|
||||
Gets the current state of the index.
|
||||
|
||||
:arg index: The name of the index to explain
|
||||
"""
|
||||
if index in SKIP_IN_PATH:
|
||||
raise ValueError("Empty value passed for a required argument 'index'.")
|
||||
|
||||
return self.transport.perform_request(
|
||||
"GET",
|
||||
_make_path("_plugins", "_ism", "explain", index),
|
||||
params=params,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
@query_params()
|
||||
def delete_policy(self, policy, params=None, headers=None):
|
||||
"""
|
||||
Deletes the policy by `policy_id`.
|
||||
|
||||
:arg policy: The name of the policy to delete
|
||||
"""
|
||||
if policy in SKIP_IN_PATH:
|
||||
raise ValueError("Empty value passed for a required argument 'policy'.")
|
||||
|
||||
return self.transport.perform_request(
|
||||
"DELETE",
|
||||
_make_path("_plugins", "_ism", "policies", policy),
|
||||
params=params,
|
||||
headers=headers,
|
||||
)
|
||||
@@ -0,0 +1,71 @@
|
||||
# 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 typing import Any, Union
|
||||
|
||||
from ..client.utils import NamespacedClient as NamespacedClient
|
||||
from ..client.utils import query_params as query_params
|
||||
|
||||
class IndexManagementClient(NamespacedClient):
|
||||
def put_policy(
|
||||
self,
|
||||
policy: Any,
|
||||
body: Any | None = ...,
|
||||
params: Any | None = ...,
|
||||
headers: Any | None = ...,
|
||||
) -> Union[bool, Any]: ...
|
||||
def add_policy(
|
||||
self,
|
||||
index: Any,
|
||||
body: Any | None = ...,
|
||||
params: Any | None = ...,
|
||||
headers: Any | None = ...,
|
||||
) -> Union[bool, Any]: ...
|
||||
def get_policy(
|
||||
self,
|
||||
policy: Any,
|
||||
body: Any | None = ...,
|
||||
params: Any | None = ...,
|
||||
headers: Any | None = ...,
|
||||
) -> Union[bool, Any]: ...
|
||||
def remove_policy_from_index(
|
||||
self,
|
||||
index: Any,
|
||||
body: Any | None = ...,
|
||||
params: Any | None = ...,
|
||||
headers: Any | None = ...,
|
||||
) -> Union[bool, Any]: ...
|
||||
def change_policy(
|
||||
self,
|
||||
index: Any,
|
||||
body: Any | None = ...,
|
||||
params: Any | None = ...,
|
||||
headers: Any | None = ...,
|
||||
) -> Union[bool, Any]: ...
|
||||
def retry(
|
||||
self,
|
||||
index: Any,
|
||||
body: Any | None = ...,
|
||||
params: Any | None = ...,
|
||||
headers: Any | None = ...,
|
||||
) -> Union[bool, Any]: ...
|
||||
def explain_index(
|
||||
self,
|
||||
index: Any,
|
||||
body: Any | None = ...,
|
||||
params: Any | None = ...,
|
||||
headers: Any | None = ...,
|
||||
) -> Union[bool, Any]: ...
|
||||
def delete_policy(
|
||||
self,
|
||||
policy: Any,
|
||||
body: Any | None = ...,
|
||||
params: Any | None = ...,
|
||||
headers: Any | None = ...,
|
||||
) -> Union[bool, Any]: ...
|
||||
Reference in New Issue
Block a user