diff --git a/elasticsearch/transport.py b/elasticsearch/transport.py deleted file mode 100644 index 5d84866aa..000000000 --- a/elasticsearch/transport.py +++ /dev/null @@ -1,57 +0,0 @@ -# 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. - -import warnings -from typing import Any, Dict, Optional, Union - -from elastic_transport import AsyncTransport, Transport # noqa: F401 - -# This file exists for backwards compatibility. -warnings.warn( - "Importing from the 'elasticsearch.transport' module is deprecated. " - "Instead import from 'elastic_transport'", - category=DeprecationWarning, - stacklevel=2, -) - - -def get_host_info( - node_info: Dict[str, Any], host: Dict[str, Union[int, str]] -) -> Optional[Dict[str, Union[int, str]]]: - """ - Simple callback that takes the node info from `/_cluster/nodes` and a - parsed connection information and return the connection information. If - `None` is returned this node will be skipped. - Useful for filtering nodes (by proximity for example) or if additional - information needs to be provided for the :class:`~elasticsearch.Connection` - class. By default master only nodes are filtered out since they shouldn't - typically be used for API operations. - :arg node_info: node information from `/_cluster/nodes` - :arg host: connection information (host, port) extracted from the node info - """ - - warnings.warn( - "The 'get_host_info' function is deprecated. Instead " - "use the 'sniff_node_callback' parameter on the client", - category=DeprecationWarning, - stacklevel=2, - ) - - # ignore master only nodes - if node_info.get("roles", []) == ["master"]: - return None - return host diff --git a/test_elasticsearch/test_transport.py b/test_elasticsearch/test_transport.py index 6fb72f98b..4978d52fc 100644 --- a/test_elasticsearch/test_transport.py +++ b/test_elasticsearch/test_transport.py @@ -38,7 +38,6 @@ ElasticsearchWarning, UnsupportedProductError, ) -from elasticsearch.transport import get_host_info class DummyNode(BaseNode): @@ -167,23 +166,6 @@ def mark_live(self, connection): }""" -class TestHostsInfoCallback: - def test_master_only_nodes_are_ignored(self): - nodes = [ - {"roles": ["master"]}, - {"roles": ["master", "data", "ingest"]}, - {"roles": ["data", "ingest"]}, - {"roles": []}, - {}, - ] - chosen = [ - i - for i, node_info in enumerate(nodes) - if get_host_info(node_info, i) is not None - ] - assert [1, 2, 3, 4] == chosen - - class TestTransport: def test_request_timeout_extracted_from_params_and_passed(self): client = Elasticsearch(