2013-06-16 16:28:51 +02:00
|
|
|
from .utils import NamespacedClient, query_params, _make_path
|
|
|
|
|
|
2019-05-10 09:16:33 -06:00
|
|
|
|
2013-06-16 16:28:51 +02:00
|
|
|
class ClusterClient(NamespacedClient):
|
2019-05-10 09:16:33 -06:00
|
|
|
@query_params(
|
2019-05-10 16:41:50 -06:00
|
|
|
"expand_wildcards",
|
2019-05-10 09:16:33 -06:00
|
|
|
"level",
|
|
|
|
|
"local",
|
|
|
|
|
"master_timeout",
|
|
|
|
|
"timeout",
|
|
|
|
|
"wait_for_active_shards",
|
|
|
|
|
"wait_for_events",
|
2019-05-10 16:41:50 -06:00
|
|
|
"wait_for_no_initializing_shards",
|
2019-05-10 09:16:33 -06:00
|
|
|
"wait_for_no_relocating_shards",
|
|
|
|
|
"wait_for_nodes",
|
|
|
|
|
"wait_for_status",
|
|
|
|
|
)
|
2013-06-16 16:28:51 +02:00
|
|
|
def health(self, index=None, params=None):
|
|
|
|
|
"""
|
2013-08-07 01:34:17 +02:00
|
|
|
Get a very simple status on the health of the cluster.
|
2015-03-23 15:25:45 -07:00
|
|
|
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-health.html>`_
|
2013-06-16 16:28:51 +02:00
|
|
|
|
|
|
|
|
:arg index: Limit the information returned to a specific index
|
2019-05-10 16:41:50 -06:00
|
|
|
:arg expand_wildcards: Whether to expand wildcard expression to concrete
|
|
|
|
|
indices that are open, closed or both., default 'all', valid choices
|
|
|
|
|
are: 'open', 'closed', 'none', 'all'
|
2015-08-25 01:21:16 +02:00
|
|
|
:arg level: Specify the level of detail for returned information,
|
|
|
|
|
default 'cluster', valid choices are: 'cluster', 'indices', 'shards'
|
|
|
|
|
: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
|
2013-06-16 16:28:51 +02:00
|
|
|
:arg timeout: Explicit operation timeout
|
2015-08-25 01:21:16 +02:00
|
|
|
:arg wait_for_active_shards: Wait until the specified number of shards
|
|
|
|
|
is active
|
2016-07-14 17:29:33 +02:00
|
|
|
:arg wait_for_events: Wait until all currently queued events with the
|
2017-07-31 19:17:52 -04:00
|
|
|
given priority are processed, valid choices are: 'immediate',
|
2016-07-14 17:29:33 +02:00
|
|
|
'urgent', 'high', 'normal', 'low', 'languid'
|
2016-10-17 13:56:58 +02:00
|
|
|
:arg wait_for_no_relocating_shards: Whether to wait until there are no
|
|
|
|
|
relocating shards in the cluster
|
2015-08-25 01:21:16 +02:00
|
|
|
:arg wait_for_nodes: Wait until the specified number of nodes is
|
|
|
|
|
available
|
|
|
|
|
:arg wait_for_status: Wait until cluster is in a specific state, default
|
|
|
|
|
None, valid choices are: 'green', 'yellow', 'red'
|
2013-06-16 16:28:51 +02:00
|
|
|
"""
|
2019-05-10 09:16:33 -06:00
|
|
|
return self.transport.perform_request(
|
|
|
|
|
"GET", _make_path("_cluster", "health", index), params=params
|
|
|
|
|
)
|
2013-07-18 16:36:38 +02:00
|
|
|
|
2019-05-10 09:16:33 -06:00
|
|
|
@query_params("local", "master_timeout")
|
2014-01-17 14:39:04 +01:00
|
|
|
def pending_tasks(self, params=None):
|
|
|
|
|
"""
|
|
|
|
|
The pending cluster tasks API returns a list of any cluster-level
|
|
|
|
|
changes (e.g. create index, update mapping, allocate or fail shard)
|
|
|
|
|
which have not yet been executed.
|
2015-03-23 15:25:45 -07:00
|
|
|
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-pending.html>`_
|
2014-01-20 18:51:19 +01:00
|
|
|
|
2015-08-25 01:21:16 +02:00
|
|
|
:arg local: Return local information, do not retrieve the state from
|
|
|
|
|
master node (default: false)
|
2014-01-20 18:51:19 +01:00
|
|
|
:arg master_timeout: Specify timeout for connection to master
|
2014-01-17 14:39:04 +01:00
|
|
|
"""
|
2019-05-10 09:16:33 -06:00
|
|
|
return self.transport.perform_request(
|
|
|
|
|
"GET", "/_cluster/pending_tasks", params=params
|
|
|
|
|
)
|
2014-01-17 14:39:04 +01:00
|
|
|
|
2019-05-10 09:16:33 -06:00
|
|
|
@query_params(
|
|
|
|
|
"allow_no_indices",
|
|
|
|
|
"expand_wildcards",
|
|
|
|
|
"flat_settings",
|
|
|
|
|
"ignore_unavailable",
|
|
|
|
|
"local",
|
|
|
|
|
"master_timeout",
|
2019-05-10 16:41:50 -06:00
|
|
|
"wait_for_metadata_version",
|
|
|
|
|
"wait_for_timeout",
|
2019-05-10 09:16:33 -06:00
|
|
|
)
|
2014-01-17 15:03:23 +01:00
|
|
|
def state(self, metric=None, index=None, params=None):
|
2013-07-24 16:39:48 +02:00
|
|
|
"""
|
2013-08-07 01:34:17 +02:00
|
|
|
Get a comprehensive state information of the whole cluster.
|
2015-03-23 15:25:45 -07:00
|
|
|
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-state.html>`_
|
2013-07-24 16:39:48 +02:00
|
|
|
|
2015-08-25 01:21:16 +02:00
|
|
|
:arg metric: Limit the information returned to the specified metrics
|
2014-01-17 15:03:23 +01:00
|
|
|
:arg index: A comma-separated list of index names; use `_all` or empty
|
|
|
|
|
string to perform the operation on all indices
|
2015-01-23 03:47:01 +01:00
|
|
|
:arg allow_no_indices: Whether to ignore if a wildcard indices
|
|
|
|
|
expression resolves into no concrete indices. (This includes `_all`
|
|
|
|
|
string or when no indices have been specified)
|
2015-08-25 01:21:16 +02:00
|
|
|
:arg expand_wildcards: Whether to expand wildcard expression to concrete
|
|
|
|
|
indices that are open, closed or both., default 'open', valid
|
|
|
|
|
choices are: 'open', 'closed', 'none', 'all'
|
2014-01-08 19:44:56 +01:00
|
|
|
:arg flat_settings: Return settings in flat format (default: false)
|
2015-01-23 03:47:01 +01:00
|
|
|
:arg ignore_unavailable: Whether specified concrete indices should be
|
|
|
|
|
ignored when unavailable (missing or closed)
|
|
|
|
|
:arg local: Return local information, do not retrieve the state from
|
|
|
|
|
master node (default: false)
|
|
|
|
|
:arg master_timeout: Specify timeout for connection to master
|
2019-05-10 16:41:50 -06:00
|
|
|
:arg wait_for_metadata_version: Wait for the metadata version to be
|
|
|
|
|
equal or greater than the specified metadata version
|
|
|
|
|
:arg wait_for_timeout: The maximum time to wait for
|
|
|
|
|
wait_for_metadata_version before timing out
|
2013-07-24 16:39:48 +02:00
|
|
|
"""
|
2014-01-17 15:03:23 +01:00
|
|
|
if index and not metric:
|
2019-05-10 09:16:33 -06:00
|
|
|
metric = "_all"
|
|
|
|
|
return self.transport.perform_request(
|
|
|
|
|
"GET", _make_path("_cluster", "state", metric, index), params=params
|
|
|
|
|
)
|
2013-07-24 16:39:48 +02:00
|
|
|
|
2019-05-10 09:16:33 -06:00
|
|
|
@query_params("flat_settings", "timeout")
|
2014-01-17 15:20:44 +01:00
|
|
|
def stats(self, node_id=None, params=None):
|
|
|
|
|
"""
|
|
|
|
|
The Cluster Stats API allows to retrieve statistics from a cluster wide
|
|
|
|
|
perspective. The API returns basic index metrics and information about
|
|
|
|
|
the current nodes that form the cluster.
|
2015-03-23 15:25:45 -07:00
|
|
|
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-stats.html>`_
|
2014-01-17 15:20:44 +01:00
|
|
|
|
|
|
|
|
:arg node_id: A comma-separated list of node IDs or names to limit the
|
2015-08-25 01:21:16 +02:00
|
|
|
returned information; use `_local` to return information from the
|
|
|
|
|
node you're connecting to, leave empty to get information from all
|
|
|
|
|
nodes
|
2014-01-17 15:20:44 +01:00
|
|
|
:arg flat_settings: Return settings in flat format (default: false)
|
2015-10-14 00:06:27 +02:00
|
|
|
:arg timeout: Explicit operation timeout
|
2014-01-17 15:20:44 +01:00
|
|
|
"""
|
2019-05-10 09:16:33 -06:00
|
|
|
url = "/_cluster/stats"
|
2014-01-17 15:20:44 +01:00
|
|
|
if node_id:
|
2019-05-10 09:16:33 -06:00
|
|
|
url = _make_path("_cluster/stats/nodes", node_id)
|
|
|
|
|
return self.transport.perform_request("GET", url, params=params)
|
2013-07-24 16:39:48 +02:00
|
|
|
|
2019-05-10 09:16:33 -06:00
|
|
|
@query_params(
|
|
|
|
|
"dry_run", "explain", "master_timeout", "metric", "retry_failed", "timeout"
|
|
|
|
|
)
|
2013-07-18 16:36:38 +02:00
|
|
|
def reroute(self, body=None, params=None):
|
|
|
|
|
"""
|
2013-08-07 01:34:17 +02:00
|
|
|
Explicitly execute a cluster reroute allocation command including specific commands.
|
2015-03-23 15:25:45 -07:00
|
|
|
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-reroute.html>`_
|
2013-07-18 16:36:38 +02:00
|
|
|
|
2015-08-25 01:21:16 +02:00
|
|
|
:arg body: The definition of `commands` to perform (`move`, `cancel`,
|
|
|
|
|
`allocate`)
|
2013-07-18 16:36:38 +02:00
|
|
|
:arg dry_run: Simulate the operation only and return the resulting state
|
2015-08-25 01:21:16 +02:00
|
|
|
:arg explain: Return an explanation of why the commands can or cannot be
|
|
|
|
|
executed
|
|
|
|
|
:arg master_timeout: Explicit operation timeout for connection to master
|
|
|
|
|
node
|
2014-09-10 16:25:37 +02:00
|
|
|
:arg metric: Limit the information returned to the specified metrics.
|
2015-08-25 01:21:16 +02:00
|
|
|
Defaults to all but metadata, valid choices are: '_all', 'blocks',
|
|
|
|
|
'metadata', 'nodes', 'routing_table', 'master_node', 'version'
|
2016-06-28 16:38:32 +02:00
|
|
|
:arg retry_failed: Retries allocation of shards that are blocked due to
|
|
|
|
|
too many subsequent allocation failures
|
2014-01-17 14:59:17 +01:00
|
|
|
:arg timeout: Explicit operation timeout
|
2013-07-18 16:36:38 +02:00
|
|
|
"""
|
2019-05-10 09:16:33 -06:00
|
|
|
return self.transport.perform_request(
|
|
|
|
|
"POST", "/_cluster/reroute", params=params, body=body
|
|
|
|
|
)
|
2013-07-18 16:36:38 +02:00
|
|
|
|
2019-05-10 09:16:33 -06:00
|
|
|
@query_params("flat_settings", "include_defaults", "master_timeout", "timeout")
|
2013-07-18 16:47:05 +02:00
|
|
|
def get_settings(self, params=None):
|
|
|
|
|
"""
|
2013-08-07 01:34:17 +02:00
|
|
|
Get cluster settings.
|
2015-03-23 15:25:45 -07:00
|
|
|
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-update-settings.html>`_
|
2014-01-08 19:44:56 +01:00
|
|
|
|
|
|
|
|
:arg flat_settings: Return settings in flat format (default: false)
|
2016-03-22 21:04:07 +01:00
|
|
|
:arg include_defaults: Whether to return all default clusters setting.,
|
|
|
|
|
default False
|
2015-08-25 01:21:16 +02:00
|
|
|
:arg master_timeout: Explicit operation timeout for connection to master
|
|
|
|
|
node
|
2014-01-17 14:35:30 +01:00
|
|
|
:arg timeout: Explicit operation timeout
|
2013-07-18 16:47:05 +02:00
|
|
|
"""
|
2019-05-10 09:16:33 -06:00
|
|
|
return self.transport.perform_request(
|
|
|
|
|
"GET", "/_cluster/settings", params=params
|
|
|
|
|
)
|
2013-07-18 16:47:05 +02:00
|
|
|
|
2019-05-10 09:16:33 -06:00
|
|
|
@query_params("flat_settings", "master_timeout", "timeout")
|
2015-08-25 01:21:16 +02:00
|
|
|
def put_settings(self, body=None, params=None):
|
2013-07-18 16:47:05 +02:00
|
|
|
"""
|
2013-08-07 01:34:17 +02:00
|
|
|
Update cluster wide specific settings.
|
2015-03-23 15:25:45 -07:00
|
|
|
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-update-settings.html>`_
|
2013-07-18 16:47:05 +02:00
|
|
|
|
2013-08-07 01:34:17 +02:00
|
|
|
:arg body: The settings to be updated. Can be either `transient` or
|
|
|
|
|
`persistent` (survives cluster restart).
|
2014-01-08 19:44:56 +01:00
|
|
|
:arg flat_settings: Return settings in flat format (default: false)
|
2014-12-15 14:29:36 +01:00
|
|
|
:arg master_timeout: Explicit operation timeout for connection to master
|
|
|
|
|
node
|
|
|
|
|
:arg timeout: Explicit operation timeout
|
2013-07-18 16:47:05 +02:00
|
|
|
"""
|
2019-05-10 09:16:33 -06:00
|
|
|
return self.transport.perform_request(
|
|
|
|
|
"PUT", "/_cluster/settings", params=params, body=body
|
|
|
|
|
)
|
2013-07-18 16:47:05 +02:00
|
|
|
|
2019-05-10 16:41:50 -06:00
|
|
|
@query_params()
|
|
|
|
|
def remote_info(self, params=None):
|
|
|
|
|
"""
|
|
|
|
|
`<http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-remote-info.html>`_
|
|
|
|
|
"""
|
|
|
|
|
return self.transport.perform_request("GET", "/_remote/info", params=params)
|
|
|
|
|
|
2019-05-10 09:16:33 -06:00
|
|
|
@query_params("include_disk_info", "include_yes_decisions")
|
2016-05-17 14:12:39 +02:00
|
|
|
def allocation_explain(self, body=None, params=None):
|
|
|
|
|
"""
|
|
|
|
|
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-allocation-explain.html>`_
|
|
|
|
|
|
|
|
|
|
:arg body: The index, shard, and primary flag to explain. Empty means
|
|
|
|
|
'explain the first unassigned shard'
|
2016-07-14 17:29:33 +02:00
|
|
|
:arg include_disk_info: Return information about disk usage and shard
|
|
|
|
|
sizes (default: false)
|
2016-05-17 14:12:39 +02:00
|
|
|
:arg include_yes_decisions: Return 'YES' decisions in explanation
|
|
|
|
|
(default: false)
|
|
|
|
|
"""
|
2019-05-10 09:16:33 -06:00
|
|
|
return self.transport.perform_request(
|
|
|
|
|
"GET", "/_cluster/allocation/explain", params=params, body=body
|
|
|
|
|
)
|