Files
opensearch-pyd/elasticsearch/_async/client/slm.py
T

158 lines
5.7 KiB
Python
Raw Normal View History

# Licensed to Elasticsearch B.V. under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Elasticsearch B.V. licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
2020-05-15 09:36:47 -05:00
from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
class SlmClient(NamespacedClient):
@query_params()
2020-05-20 12:34:29 -05:00
async def delete_lifecycle(self, policy_id, params=None, headers=None):
2020-05-15 09:36:47 -05:00
"""
Deletes an existing snapshot lifecycle policy.
2020-10-20 13:02:15 -05:00
2020-05-20 12:34:29 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/slm-api-delete-policy.html>`_
2020-05-15 09:36:47 -05:00
:arg policy_id: The id of the snapshot lifecycle policy to
remove
"""
if policy_id in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'policy_id'.")
2020-05-20 12:34:29 -05:00
return await self.transport.perform_request(
2020-05-15 09:36:47 -05:00
"DELETE",
_make_path("_slm", "policy", policy_id),
params=params,
headers=headers,
)
@query_params()
2020-05-20 12:34:29 -05:00
async def execute_lifecycle(self, policy_id, params=None, headers=None):
2020-05-15 09:36:47 -05:00
"""
Immediately creates a snapshot according to the lifecycle policy, without
waiting for the scheduled time.
2020-10-20 13:02:15 -05:00
2020-05-20 12:34:29 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/slm-api-execute-lifecycle.html>`_
2020-05-15 09:36:47 -05:00
:arg policy_id: The id of the snapshot lifecycle policy to be
executed
"""
if policy_id in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'policy_id'.")
2020-05-20 12:34:29 -05:00
return await self.transport.perform_request(
2020-05-15 09:36:47 -05:00
"PUT",
_make_path("_slm", "policy", policy_id, "_execute"),
params=params,
headers=headers,
)
@query_params()
2020-05-20 12:34:29 -05:00
async def execute_retention(self, params=None, headers=None):
2020-05-15 09:36:47 -05:00
"""
Deletes any snapshots that are expired according to the policy's retention
rules.
2020-10-20 13:02:15 -05:00
2020-05-20 12:34:29 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/slm-api-execute-retention.html>`_
2020-05-15 09:36:47 -05:00
"""
2020-05-20 12:34:29 -05:00
return await self.transport.perform_request(
2020-05-15 09:36:47 -05:00
"POST", "/_slm/_execute_retention", params=params, headers=headers
)
@query_params()
2020-05-20 12:34:29 -05:00
async def get_lifecycle(self, policy_id=None, params=None, headers=None):
2020-05-15 09:36:47 -05:00
"""
Retrieves one or more snapshot lifecycle policy definitions and information
about the latest snapshot attempts.
2020-10-20 13:02:15 -05:00
2020-05-20 12:34:29 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/slm-api-get-policy.html>`_
2020-05-15 09:36:47 -05:00
:arg policy_id: Comma-separated list of snapshot lifecycle
policies to retrieve
"""
2020-05-20 12:34:29 -05:00
return await self.transport.perform_request(
2020-05-15 09:36:47 -05:00
"GET",
_make_path("_slm", "policy", policy_id),
params=params,
headers=headers,
)
@query_params()
2020-05-20 12:34:29 -05:00
async def get_stats(self, params=None, headers=None):
2020-05-15 09:36:47 -05:00
"""
Returns global and policy-level statistics about actions taken by snapshot
lifecycle management.
2020-10-20 13:02:15 -05:00
2020-05-20 12:34:29 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/slm-api-get-stats.html>`_
2020-05-15 09:36:47 -05:00
"""
2020-05-20 12:34:29 -05:00
return await self.transport.perform_request(
2020-05-15 09:36:47 -05:00
"GET", "/_slm/stats", params=params, headers=headers
)
@query_params()
2020-05-20 12:34:29 -05:00
async def put_lifecycle(self, policy_id, body=None, params=None, headers=None):
2020-05-15 09:36:47 -05:00
"""
Creates or updates a snapshot lifecycle policy.
2020-10-20 13:02:15 -05:00
2020-05-20 12:34:29 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/slm-api-put-policy.html>`_
2020-05-15 09:36:47 -05:00
:arg policy_id: The id of the snapshot lifecycle policy
:arg body: The snapshot lifecycle policy definition to register
"""
if policy_id in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'policy_id'.")
2020-05-20 12:34:29 -05:00
return await self.transport.perform_request(
2020-05-15 09:36:47 -05:00
"PUT",
_make_path("_slm", "policy", policy_id),
params=params,
headers=headers,
body=body,
)
@query_params()
2020-05-20 12:34:29 -05:00
async def get_status(self, params=None, headers=None):
2020-05-15 09:36:47 -05:00
"""
Retrieves the status of snapshot lifecycle management (SLM).
2020-10-20 13:02:15 -05:00
2020-05-20 12:34:29 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/slm-api-get-status.html>`_
2020-05-15 09:36:47 -05:00
"""
2020-05-20 12:34:29 -05:00
return await self.transport.perform_request(
2020-05-15 09:36:47 -05:00
"GET", "/_slm/status", params=params, headers=headers
)
@query_params()
2020-05-20 12:34:29 -05:00
async def start(self, params=None, headers=None):
2020-05-15 09:36:47 -05:00
"""
Turns on snapshot lifecycle management (SLM).
2020-10-20 13:02:15 -05:00
2020-05-20 12:34:29 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/slm-api-start.html>`_
2020-05-15 09:36:47 -05:00
"""
2020-05-20 12:34:29 -05:00
return await self.transport.perform_request(
2020-05-15 09:36:47 -05:00
"POST", "/_slm/start", params=params, headers=headers
)
@query_params()
2020-05-20 12:34:29 -05:00
async def stop(self, params=None, headers=None):
2020-05-15 09:36:47 -05:00
"""
Turns off snapshot lifecycle management (SLM).
2020-10-20 13:02:15 -05:00
2020-05-20 12:34:29 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/slm-api-stop.html>`_
2020-05-15 09:36:47 -05:00
"""
2020-05-20 12:34:29 -05:00
return await self.transport.perform_request(
2020-05-15 09:36:47 -05:00
"POST", "/_slm/stop", params=params, headers=headers
)