2021-08-06 12:59:39 +05:30
|
|
|
# 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.
|
|
|
|
|
#
|
2020-07-02 13:15:25 -05:00
|
|
|
# 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-04-23 11:22:08 -05:00
|
|
|
|
2021-01-13 14:21:04 -06:00
|
|
|
from .utils import SKIP_IN_PATH, NamespacedClient, _make_path, query_params
|
2014-01-18 01:31:17 +01:00
|
|
|
|
2019-05-10 09:16:33 -06:00
|
|
|
|
2014-01-18 01:31:17 +01:00
|
|
|
class SnapshotClient(NamespacedClient):
|
2019-05-10 09:16:33 -06:00
|
|
|
@query_params("master_timeout", "wait_for_completion")
|
2020-03-11 16:33:15 -05:00
|
|
|
def create(self, repository, snapshot, body=None, params=None, headers=None):
|
2014-01-18 01:31:17 +01:00
|
|
|
"""
|
2019-12-17 22:31:35 +01:00
|
|
|
Creates a snapshot in a repository.
|
2020-10-20 13:02:15 -05:00
|
|
|
|
2014-01-18 01:31:17 +01:00
|
|
|
|
|
|
|
|
:arg repository: A repository name
|
|
|
|
|
:arg snapshot: A snapshot name
|
|
|
|
|
:arg body: The snapshot definition
|
2019-12-17 22:31:35 +01:00
|
|
|
: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
|
2014-01-18 01:31:17 +01:00
|
|
|
"""
|
2014-12-02 00:13:01 +01:00
|
|
|
for param in (repository, snapshot):
|
|
|
|
|
if param in SKIP_IN_PATH:
|
|
|
|
|
raise ValueError("Empty value passed for a required argument.")
|
2019-12-17 22:31:35 +01:00
|
|
|
|
2019-05-10 09:16:33 -06:00
|
|
|
return self.transport.perform_request(
|
|
|
|
|
"PUT",
|
|
|
|
|
_make_path("_snapshot", repository, snapshot),
|
|
|
|
|
params=params,
|
2020-03-11 16:33:15 -05:00
|
|
|
headers=headers,
|
2019-05-10 09:16:33 -06:00
|
|
|
body=body,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@query_params("master_timeout")
|
2020-03-11 16:33:15 -05:00
|
|
|
def delete(self, repository, snapshot, params=None, headers=None):
|
2014-01-18 01:31:17 +01:00
|
|
|
"""
|
2019-12-17 22:31:35 +01:00
|
|
|
Deletes a snapshot.
|
2020-10-20 13:02:15 -05:00
|
|
|
|
2014-01-18 01:31:17 +01:00
|
|
|
|
|
|
|
|
:arg repository: A repository name
|
|
|
|
|
:arg snapshot: A snapshot name
|
2019-12-17 22:31:35 +01:00
|
|
|
:arg master_timeout: Explicit operation timeout for connection
|
|
|
|
|
to master node
|
2014-01-18 01:31:17 +01:00
|
|
|
"""
|
2014-12-02 00:13:01 +01:00
|
|
|
for param in (repository, snapshot):
|
|
|
|
|
if param in SKIP_IN_PATH:
|
|
|
|
|
raise ValueError("Empty value passed for a required argument.")
|
2019-12-17 22:31:35 +01:00
|
|
|
|
2019-05-10 09:16:33 -06:00
|
|
|
return self.transport.perform_request(
|
2020-03-11 16:33:15 -05:00
|
|
|
"DELETE",
|
|
|
|
|
_make_path("_snapshot", repository, snapshot),
|
|
|
|
|
params=params,
|
|
|
|
|
headers=headers,
|
2019-05-10 09:16:33 -06:00
|
|
|
)
|
2015-08-25 01:21:16 +02:00
|
|
|
|
2021-07-13 19:57:03 -05:00
|
|
|
@query_params(
|
|
|
|
|
"ignore_unavailable",
|
|
|
|
|
"include_repository",
|
|
|
|
|
"index_details",
|
|
|
|
|
"master_timeout",
|
|
|
|
|
"verbose",
|
|
|
|
|
)
|
2020-03-11 16:33:15 -05:00
|
|
|
def get(self, repository, snapshot, params=None, headers=None):
|
2014-01-18 01:31:17 +01:00
|
|
|
"""
|
2019-12-17 22:31:35 +01:00
|
|
|
Returns information about a snapshot.
|
2020-10-20 13:02:15 -05:00
|
|
|
|
2014-01-18 01:31:17 +01:00
|
|
|
|
2015-08-25 01:21:16 +02:00
|
|
|
:arg repository: A repository name
|
2014-01-18 01:31:17 +01:00
|
|
|
:arg snapshot: A comma-separated list of snapshot names
|
2019-12-17 22:31:35 +01:00
|
|
|
:arg ignore_unavailable: Whether to ignore unavailable
|
|
|
|
|
snapshots, defaults to false which means a SnapshotMissingException is
|
|
|
|
|
thrown
|
2021-07-13 19:57:03 -05:00
|
|
|
:arg include_repository: Whether to include the repository name
|
|
|
|
|
in the snapshot info. Defaults to true.
|
2021-05-03 10:30:13 -05:00
|
|
|
:arg index_details: Whether to include details of each index in
|
|
|
|
|
the snapshot, if those details are available. Defaults to false.
|
2019-12-17 22:31:35 +01:00
|
|
|
:arg master_timeout: Explicit operation timeout for connection
|
|
|
|
|
to master node
|
|
|
|
|
:arg verbose: Whether to show verbose snapshot info or only show
|
|
|
|
|
the basic info found in the repository index blob
|
2014-01-18 01:31:17 +01:00
|
|
|
"""
|
2014-12-02 00:13:01 +01:00
|
|
|
for param in (repository, snapshot):
|
|
|
|
|
if param in SKIP_IN_PATH:
|
|
|
|
|
raise ValueError("Empty value passed for a required argument.")
|
2019-12-17 22:31:35 +01:00
|
|
|
|
2019-05-10 09:16:33 -06:00
|
|
|
return self.transport.perform_request(
|
2020-03-11 16:33:15 -05:00
|
|
|
"GET",
|
|
|
|
|
_make_path("_snapshot", repository, snapshot),
|
|
|
|
|
params=params,
|
|
|
|
|
headers=headers,
|
2019-05-10 09:16:33 -06:00
|
|
|
)
|
2015-08-25 01:21:16 +02:00
|
|
|
|
2019-05-10 09:16:33 -06:00
|
|
|
@query_params("master_timeout", "timeout")
|
2020-03-11 16:33:15 -05:00
|
|
|
def delete_repository(self, repository, params=None, headers=None):
|
2014-01-18 01:31:17 +01:00
|
|
|
"""
|
2019-12-17 22:31:35 +01:00
|
|
|
Deletes a repository.
|
2020-10-20 13:02:15 -05:00
|
|
|
|
2014-01-18 01:31:17 +01:00
|
|
|
|
2020-06-03 10:38:35 -05:00
|
|
|
:arg repository: Name of the snapshot repository to unregister.
|
|
|
|
|
Wildcard (`*`) patterns are supported.
|
2019-12-17 22:31:35 +01:00
|
|
|
:arg master_timeout: Explicit operation timeout for connection
|
|
|
|
|
to master node
|
2015-08-25 01:21:16 +02:00
|
|
|
:arg timeout: Explicit operation timeout
|
2014-01-18 01:31:17 +01:00
|
|
|
"""
|
2014-12-02 00:13:01 +01:00
|
|
|
if repository in SKIP_IN_PATH:
|
|
|
|
|
raise ValueError("Empty value passed for a required argument 'repository'.")
|
2019-12-17 22:31:35 +01:00
|
|
|
|
2019-05-10 09:16:33 -06:00
|
|
|
return self.transport.perform_request(
|
2020-03-11 16:33:15 -05:00
|
|
|
"DELETE",
|
|
|
|
|
_make_path("_snapshot", repository),
|
|
|
|
|
params=params,
|
|
|
|
|
headers=headers,
|
2019-05-10 09:16:33 -06:00
|
|
|
)
|
2015-08-25 01:21:16 +02:00
|
|
|
|
2019-05-10 09:16:33 -06:00
|
|
|
@query_params("local", "master_timeout")
|
2020-03-11 16:33:15 -05:00
|
|
|
def get_repository(self, repository=None, params=None, headers=None):
|
2014-01-18 01:31:17 +01:00
|
|
|
"""
|
2019-12-17 22:31:35 +01:00
|
|
|
Returns information about a repository.
|
2020-10-20 13:02:15 -05:00
|
|
|
|
2014-01-18 01:31:17 +01:00
|
|
|
|
|
|
|
|
:arg repository: A comma-separated list of repository names
|
2019-12-17 22:31:35 +01:00
|
|
|
:arg local: Return local information, do not retrieve the state
|
|
|
|
|
from master node (default: false)
|
|
|
|
|
:arg master_timeout: Explicit operation timeout for connection
|
|
|
|
|
to master node
|
2014-01-18 01:31:17 +01:00
|
|
|
"""
|
2019-05-10 09:16:33 -06:00
|
|
|
return self.transport.perform_request(
|
2020-03-11 16:33:15 -05:00
|
|
|
"GET", _make_path("_snapshot", repository), params=params, headers=headers
|
2019-05-10 09:16:33 -06:00
|
|
|
)
|
2015-08-25 01:21:16 +02:00
|
|
|
|
2019-05-10 09:16:33 -06:00
|
|
|
@query_params("master_timeout", "timeout", "verify")
|
2020-03-11 16:33:15 -05:00
|
|
|
def create_repository(self, repository, body, params=None, headers=None):
|
2014-01-18 01:31:17 +01:00
|
|
|
"""
|
2019-12-17 22:31:35 +01:00
|
|
|
Creates a repository.
|
2020-10-20 13:02:15 -05:00
|
|
|
|
2014-01-18 01:31:17 +01:00
|
|
|
|
|
|
|
|
:arg repository: A repository name
|
|
|
|
|
:arg body: The repository definition
|
2019-12-17 22:31:35 +01:00
|
|
|
:arg master_timeout: Explicit operation timeout for connection
|
|
|
|
|
to master node
|
2015-08-25 01:21:16 +02:00
|
|
|
:arg timeout: Explicit operation timeout
|
|
|
|
|
:arg verify: Whether to verify the repository after creation
|
2014-01-18 01:31:17 +01:00
|
|
|
"""
|
2014-12-02 00:13:01 +01:00
|
|
|
for param in (repository, body):
|
|
|
|
|
if param in SKIP_IN_PATH:
|
|
|
|
|
raise ValueError("Empty value passed for a required argument.")
|
2019-12-17 22:31:35 +01:00
|
|
|
|
2019-05-10 09:16:33 -06:00
|
|
|
return self.transport.perform_request(
|
2020-03-11 16:33:15 -05:00
|
|
|
"PUT",
|
|
|
|
|
_make_path("_snapshot", repository),
|
|
|
|
|
params=params,
|
|
|
|
|
headers=headers,
|
|
|
|
|
body=body,
|
2019-05-10 09:16:33 -06:00
|
|
|
)
|
2015-08-25 01:21:16 +02:00
|
|
|
|
2019-05-10 09:16:33 -06:00
|
|
|
@query_params("master_timeout", "wait_for_completion")
|
2020-03-11 16:33:15 -05:00
|
|
|
def restore(self, repository, snapshot, body=None, params=None, headers=None):
|
2014-01-18 01:31:17 +01:00
|
|
|
"""
|
2019-12-17 22:31:35 +01:00
|
|
|
Restores a snapshot.
|
2020-10-20 13:02:15 -05:00
|
|
|
|
2014-01-18 01:31:17 +01:00
|
|
|
|
|
|
|
|
:arg repository: A repository name
|
|
|
|
|
:arg snapshot: A snapshot name
|
|
|
|
|
:arg body: Details of what to restore
|
2019-12-17 22:31:35 +01:00
|
|
|
: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
|
2014-01-18 01:31:17 +01:00
|
|
|
"""
|
2014-12-02 00:13:01 +01:00
|
|
|
for param in (repository, snapshot):
|
|
|
|
|
if param in SKIP_IN_PATH:
|
|
|
|
|
raise ValueError("Empty value passed for a required argument.")
|
2019-12-17 22:31:35 +01:00
|
|
|
|
2019-05-10 09:16:33 -06:00
|
|
|
return self.transport.perform_request(
|
|
|
|
|
"POST",
|
|
|
|
|
_make_path("_snapshot", repository, snapshot, "_restore"),
|
|
|
|
|
params=params,
|
2020-03-11 16:33:15 -05:00
|
|
|
headers=headers,
|
2019-05-10 09:16:33 -06:00
|
|
|
body=body,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@query_params("ignore_unavailable", "master_timeout")
|
2020-03-11 16:33:15 -05:00
|
|
|
def status(self, repository=None, snapshot=None, params=None, headers=None):
|
2014-07-02 16:48:25 +02:00
|
|
|
"""
|
2019-12-17 22:31:35 +01:00
|
|
|
Returns information about the status of a snapshot.
|
2020-10-20 13:02:15 -05:00
|
|
|
|
2014-07-02 16:48:25 +02:00
|
|
|
|
|
|
|
|
:arg repository: A repository name
|
|
|
|
|
:arg snapshot: A comma-separated list of snapshot names
|
2019-12-17 22:31:35 +01:00
|
|
|
:arg ignore_unavailable: Whether to ignore unavailable
|
|
|
|
|
snapshots, defaults to false which means a SnapshotMissingException is
|
|
|
|
|
thrown
|
|
|
|
|
:arg master_timeout: Explicit operation timeout for connection
|
|
|
|
|
to master node
|
2014-07-02 16:48:25 +02:00
|
|
|
"""
|
2019-05-10 09:16:33 -06:00
|
|
|
return self.transport.perform_request(
|
|
|
|
|
"GET",
|
|
|
|
|
_make_path("_snapshot", repository, snapshot, "_status"),
|
|
|
|
|
params=params,
|
2020-03-11 16:33:15 -05:00
|
|
|
headers=headers,
|
2019-05-10 09:16:33 -06:00
|
|
|
)
|
2014-10-08 09:23:13 +02:00
|
|
|
|
2019-05-10 09:16:33 -06:00
|
|
|
@query_params("master_timeout", "timeout")
|
2020-03-11 16:33:15 -05:00
|
|
|
def verify_repository(self, repository, params=None, headers=None):
|
2014-10-08 09:23:13 +02:00
|
|
|
"""
|
2019-12-17 22:31:35 +01:00
|
|
|
Verifies a repository.
|
2020-10-20 13:02:15 -05:00
|
|
|
|
2014-10-08 09:23:13 +02:00
|
|
|
|
|
|
|
|
:arg repository: A repository name
|
2019-12-17 22:31:35 +01:00
|
|
|
:arg master_timeout: Explicit operation timeout for connection
|
|
|
|
|
to master node
|
2014-10-08 09:23:13 +02:00
|
|
|
:arg timeout: Explicit operation timeout
|
|
|
|
|
"""
|
2014-12-02 00:13:01 +01:00
|
|
|
if repository in SKIP_IN_PATH:
|
|
|
|
|
raise ValueError("Empty value passed for a required argument 'repository'.")
|
2019-12-17 22:31:35 +01:00
|
|
|
|
2019-05-10 09:16:33 -06:00
|
|
|
return self.transport.perform_request(
|
2020-03-11 16:33:15 -05:00
|
|
|
"POST",
|
|
|
|
|
_make_path("_snapshot", repository, "_verify"),
|
|
|
|
|
params=params,
|
|
|
|
|
headers=headers,
|
2019-05-10 09:16:33 -06:00
|
|
|
)
|
2019-12-17 22:31:35 +01:00
|
|
|
|
|
|
|
|
@query_params("master_timeout", "timeout")
|
2020-03-11 16:33:15 -05:00
|
|
|
def cleanup_repository(self, repository, params=None, headers=None):
|
2019-12-17 22:31:35 +01:00
|
|
|
"""
|
|
|
|
|
Removes stale data from repository.
|
2020-10-20 13:02:15 -05:00
|
|
|
|
2019-12-17 22:31:35 +01:00
|
|
|
|
|
|
|
|
:arg repository: A repository name
|
|
|
|
|
:arg master_timeout: Explicit operation timeout for connection
|
|
|
|
|
to master node
|
|
|
|
|
:arg timeout: Explicit operation timeout
|
|
|
|
|
"""
|
|
|
|
|
if repository in SKIP_IN_PATH:
|
|
|
|
|
raise ValueError("Empty value passed for a required argument 'repository'.")
|
|
|
|
|
|
|
|
|
|
return self.transport.perform_request(
|
2020-03-11 16:33:15 -05:00
|
|
|
"POST",
|
|
|
|
|
_make_path("_snapshot", repository, "_cleanup"),
|
|
|
|
|
params=params,
|
|
|
|
|
headers=headers,
|
2019-12-17 22:31:35 +01:00
|
|
|
)
|
2020-10-20 13:02:15 -05:00
|
|
|
|
|
|
|
|
@query_params("master_timeout")
|
|
|
|
|
def clone(
|
|
|
|
|
self, repository, snapshot, target_snapshot, body, params=None, headers=None
|
|
|
|
|
):
|
|
|
|
|
"""
|
|
|
|
|
Clones indices from one snapshot into another snapshot in the same repository.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:arg repository: A repository name
|
|
|
|
|
:arg snapshot: The name of the snapshot to clone from
|
|
|
|
|
:arg target_snapshot: The name of the cloned snapshot to create
|
|
|
|
|
:arg body: The snapshot clone definition
|
|
|
|
|
:arg master_timeout: Explicit operation timeout for connection
|
|
|
|
|
to master node
|
|
|
|
|
"""
|
|
|
|
|
for param in (repository, snapshot, target_snapshot, body):
|
|
|
|
|
if param in SKIP_IN_PATH:
|
|
|
|
|
raise ValueError("Empty value passed for a required argument.")
|
|
|
|
|
|
|
|
|
|
return self.transport.perform_request(
|
|
|
|
|
"PUT",
|
|
|
|
|
_make_path("_snapshot", repository, snapshot, "_clone", target_snapshot),
|
|
|
|
|
params=params,
|
|
|
|
|
headers=headers,
|
|
|
|
|
body=body,
|
|
|
|
|
)
|
2021-06-04 10:17:58 -05:00
|
|
|
|
|
|
|
|
@query_params(
|
|
|
|
|
"blob_count",
|
|
|
|
|
"concurrency",
|
|
|
|
|
"detailed",
|
|
|
|
|
"early_read_node_count",
|
|
|
|
|
"max_blob_size",
|
|
|
|
|
"max_total_data_size",
|
|
|
|
|
"rare_action_probability",
|
|
|
|
|
"rarely_abort_writes",
|
|
|
|
|
"read_node_count",
|
|
|
|
|
"seed",
|
|
|
|
|
"timeout",
|
|
|
|
|
)
|
|
|
|
|
def repository_analyze(self, repository, params=None, headers=None):
|
|
|
|
|
"""
|
|
|
|
|
Analyzes a repository for correctness and performance
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:arg repository: A repository name
|
|
|
|
|
:arg blob_count: Number of blobs to create during the test.
|
|
|
|
|
Defaults to 100.
|
|
|
|
|
:arg concurrency: Number of operations to run concurrently
|
|
|
|
|
during the test. Defaults to 10.
|
|
|
|
|
:arg detailed: Whether to return detailed results or a summary.
|
|
|
|
|
Defaults to 'false' so that only the summary is returned.
|
|
|
|
|
:arg early_read_node_count: Number of nodes on which to perform
|
|
|
|
|
an early read on a blob, i.e. before writing has completed. Early reads
|
|
|
|
|
are rare actions so the 'rare_action_probability' parameter is also
|
|
|
|
|
relevant. Defaults to 2.
|
|
|
|
|
:arg max_blob_size: Maximum size of a blob to create during the
|
|
|
|
|
test, e.g '1gb' or '100mb'. Defaults to '10mb'.
|
|
|
|
|
:arg max_total_data_size: Maximum total size of all blobs to
|
|
|
|
|
create during the test, e.g '1tb' or '100gb'. Defaults to '1gb'.
|
|
|
|
|
:arg rare_action_probability: Probability of taking a rare
|
|
|
|
|
action such as an early read or an overwrite. Defaults to 0.02.
|
|
|
|
|
:arg rarely_abort_writes: Whether to rarely abort writes before
|
|
|
|
|
they complete. Defaults to 'true'.
|
|
|
|
|
:arg read_node_count: Number of nodes on which to read a blob
|
|
|
|
|
after writing. Defaults to 10.
|
|
|
|
|
:arg seed: Seed for the random number generator used to create
|
|
|
|
|
the test workload. Defaults to a random value.
|
|
|
|
|
:arg timeout: Explicit operation timeout. Defaults to '30s'.
|
|
|
|
|
"""
|
|
|
|
|
if repository in SKIP_IN_PATH:
|
|
|
|
|
raise ValueError("Empty value passed for a required argument 'repository'.")
|
|
|
|
|
|
|
|
|
|
return self.transport.perform_request(
|
|
|
|
|
"POST",
|
|
|
|
|
_make_path("_snapshot", repository, "_analyze"),
|
|
|
|
|
params=params,
|
|
|
|
|
headers=headers,
|
|
|
|
|
)
|