Merge branch 'async'

This commit is contained in:
Honza Král
2016-03-22 17:51:17 +01:00
8 changed files with 137 additions and 310 deletions
+33 -119
View File
@@ -3,7 +3,7 @@ import weakref
import logging
from ..transport import Transport
from ..exceptions import NotFoundError, TransportError
from ..exceptions import TransportError
from ..compat import string_types, urlparse
from .indices import IndicesClient
from .cluster import ClusterClient
@@ -204,11 +204,7 @@ class Elasticsearch(object):
Returns True if the cluster is up, False otherwise.
`<http://www.elastic.co/guide/>`_
"""
try:
self.transport.perform_request('HEAD', '/', params=params)
except NotFoundError:
return False
return True
return self.transport.perform_request('HEAD', '/', params=params)
@query_params()
def info(self, params=None):
@@ -216,8 +212,7 @@ class Elasticsearch(object):
Get the basic info from the current cluster.
`<http://www.elastic.co/guide/>`_
"""
_, data = self.transport.perform_request('GET', '/', params=params)
return data
return self.transport.perform_request('GET', '/', params=params)
@query_params('consistency', 'parent', 'refresh', 'routing',
'timeout', 'timestamp', 'ttl', 'version', 'version_type')
@@ -275,9 +270,8 @@ class Elasticsearch(object):
for param in (index, doc_type, body):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('POST' if id in SKIP_IN_PATH else 'PUT',
return self.transport.perform_request('POST' if id in SKIP_IN_PATH else 'PUT',
_make_path(index, doc_type, id), params=params, body=body)
return data
@query_params('parent', 'preference', 'realtime', 'refresh', 'routing')
def exists(self, index, doc_type, id, params=None):
@@ -301,12 +295,8 @@ class Elasticsearch(object):
for param in (index, doc_type, id):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
try:
self.transport.perform_request('HEAD', _make_path(index, doc_type,
return self.transport.perform_request('HEAD', _make_path(index, doc_type,
id), params=params)
except NotFoundError:
return False
return True
@query_params('_source', '_source_exclude', '_source_include', 'fields',
'parent', 'preference', 'realtime', 'refresh', 'routing', 'version',
@@ -342,9 +332,8 @@ class Elasticsearch(object):
for param in (index, doc_type, id):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
doc_type, id), params=params)
return data
@query_params('_source', '_source_exclude', '_source_include', 'parent',
'preference', 'realtime', 'refresh', 'routing', 'version',
@@ -379,9 +368,8 @@ class Elasticsearch(object):
for param in (index, doc_type, id):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
doc_type, id, '_source'), params=params)
return data
@query_params('_source', '_source_exclude', '_source_include', 'fields',
'preference', 'realtime', 'refresh')
@@ -411,9 +399,8 @@ class Elasticsearch(object):
"""
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
doc_type, '_mget'), params=params, body=body)
return data
@query_params('consistency', 'detect_noop', 'fields', 'lang', 'parent',
'refresh', 'retry_on_conflict', 'routing', 'script', 'script_id',
@@ -456,9 +443,8 @@ class Elasticsearch(object):
for param in (index, doc_type, id):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('POST', _make_path(index,
return self.transport.perform_request('POST', _make_path(index,
doc_type, id, '_update'), params=params, body=body)
return data
@query_params('_source', '_source_exclude', '_source_include',
'allow_no_indices', 'analyze_wildcard', 'analyzer', 'default_operator',
@@ -544,9 +530,8 @@ class Elasticsearch(object):
if doc_type and not index:
index = '_all'
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
doc_type, '_search'), params=params, body=body)
return data
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
'local', 'preference', 'routing')
@@ -575,9 +560,8 @@ class Elasticsearch(object):
performed on (default: random)
:arg routing: Specific routing value
"""
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
doc_type, '_search_shards'), params=params)
return data
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
'preference', 'routing', 'scroll', 'search_type')
@@ -609,9 +593,8 @@ class Elasticsearch(object):
'query_then_fetch', 'query_and_fetch', 'dfs_query_then_fetch',
'dfs_query_and_fetch', 'count', 'scan'
"""
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
doc_type, '_search', 'template'), params=params, body=body)
return data
@query_params('_source', '_source_exclude', '_source_include',
'analyze_wildcard', 'analyzer', 'default_operator', 'df', 'fields',
@@ -654,9 +637,8 @@ class Elasticsearch(object):
for param in (index, doc_type, id):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
doc_type, id, '_explain'), params=params, body=body)
return data
@query_params('scroll')
def scroll(self, scroll_id=None, body=None, params=None):
@@ -676,9 +658,8 @@ class Elasticsearch(object):
elif scroll_id:
params['scroll_id'] = scroll_id
_, data = self.transport.perform_request('GET', '/_search/scroll',
return self.transport.perform_request('GET', '/_search/scroll',
params=params, body=body)
return data
@query_params()
def clear_scroll(self, scroll_id=None, body=None, params=None):
@@ -691,9 +672,8 @@ class Elasticsearch(object):
:arg body: A comma-separated list of scroll IDs to clear if none was
specified via the scroll_id parameter
"""
_, data = self.transport.perform_request('DELETE', _make_path('_search',
return self.transport.perform_request('DELETE', _make_path('_search',
'scroll', scroll_id), params=params, body=body)
return data
@query_params('consistency', 'parent', 'refresh', 'routing', 'timeout',
'version', 'version_type')
@@ -718,9 +698,8 @@ class Elasticsearch(object):
for param in (index, doc_type, id):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('DELETE', _make_path(index,
return self.transport.perform_request('DELETE', _make_path(index,
doc_type, id), params=params)
return data
@query_params('allow_no_indices', 'analyze_wildcard', 'analyzer',
'default_operator', 'df', 'expand_wildcards', 'ignore_unavailable',
@@ -764,9 +743,8 @@ class Elasticsearch(object):
if doc_type and not index:
index = '_all'
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
doc_type, '_count'), params=params, body=body)
return data
@query_params('consistency', 'fields', 'refresh', 'routing', 'timeout')
def bulk(self, body, index=None, doc_type=None, params=None):
@@ -791,9 +769,8 @@ class Elasticsearch(object):
"""
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
_, data = self.transport.perform_request('POST', _make_path(index,
return self.transport.perform_request('POST', _make_path(index,
doc_type, '_bulk'), params=params, body=self._bulk_body(body))
return data
@query_params('search_type')
def msearch(self, body, index=None, doc_type=None, params=None):
@@ -812,9 +789,8 @@ class Elasticsearch(object):
"""
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
doc_type, '_msearch'), params=params, body=self._bulk_body(body))
return data
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
'preference', 'routing')
@@ -842,9 +818,8 @@ class Elasticsearch(object):
"""
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
_, data = self.transport.perform_request('POST', _make_path(index,
return self.transport.perform_request('POST', _make_path(index,
'_suggest'), params=params, body=body)
return data
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
'percolate_format', 'percolate_index', 'percolate_preference',
@@ -892,9 +867,8 @@ class Elasticsearch(object):
for param in (index, doc_type):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
doc_type, id, '_percolate'), params=params, body=body)
return data
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable')
def mpercolate(self, body, index=None, doc_type=None, params=None):
@@ -921,9 +895,8 @@ class Elasticsearch(object):
"""
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
doc_type, '_mpercolate'), params=params, body=self._bulk_body(body))
return data
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
'percolate_index', 'percolate_type', 'preference', 'routing', 'version',
@@ -965,9 +938,8 @@ class Elasticsearch(object):
for param in (index, doc_type):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
doc_type, id, '_percolate', 'count'), params=params, body=body)
return data
@query_params('dfs', 'field_statistics', 'fields', 'offsets', 'parent',
'payloads', 'positions', 'preference', 'realtime', 'routing',
@@ -1014,9 +986,8 @@ class Elasticsearch(object):
for param in (index, doc_type):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
doc_type, id, '_termvectors'), params=params, body=body)
return data
@query_params('field_statistics', 'fields', 'ids', 'offsets', 'parent',
'payloads', 'positions', 'preference', 'realtime', 'routing',
@@ -1067,9 +1038,8 @@ class Elasticsearch(object):
:arg version_type: Specific version type, valid choices are: 'internal',
'external', 'external_gte', 'force'
"""
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
doc_type, '_mtermvectors'), params=params, body=body)
return data
@query_params('op_type', 'version', 'version_type')
def put_script(self, lang, id, body, params=None):
@@ -1089,9 +1059,8 @@ class Elasticsearch(object):
for param in (lang, id, body):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('PUT', _make_path('_scripts',
return self.transport.perform_request('PUT', _make_path('_scripts',
lang, id), params=params, body=body)
return data
@query_params('version', 'version_type')
def get_script(self, lang, id, params=None):
@@ -1108,9 +1077,8 @@ class Elasticsearch(object):
for param in (lang, id):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('GET', _make_path('_scripts',
return self.transport.perform_request('GET', _make_path('_scripts',
lang, id), params=params)
return data
@query_params('version', 'version_type')
def delete_script(self, lang, id, params=None):
@@ -1127,9 +1095,8 @@ class Elasticsearch(object):
for param in (lang, id):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('DELETE',
return self.transport.perform_request('DELETE',
_make_path('_scripts', lang, id), params=params)
return data
@query_params('op_type', 'version', 'version_type')
def put_template(self, id, body, params=None):
@@ -1148,9 +1115,8 @@ class Elasticsearch(object):
for param in (id, body):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('PUT', _make_path('_search',
return self.transport.perform_request('PUT', _make_path('_search',
'template', id), params=params, body=body)
return data
@query_params('version', 'version_type')
def get_template(self, id, params=None):
@@ -1165,9 +1131,8 @@ class Elasticsearch(object):
"""
if id in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'id'.")
_, data = self.transport.perform_request('GET', _make_path('_search',
return self.transport.perform_request('GET', _make_path('_search',
'template', id), params=params)
return data
@query_params('version', 'version_type')
def delete_template(self, id, params=None):
@@ -1182,56 +1147,8 @@ class Elasticsearch(object):
"""
if id in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'id'.")
_, data = self.transport.perform_request('DELETE', _make_path('_search',
return self.transport.perform_request('DELETE', _make_path('_search',
'template', id), params=params)
return data
@query_params('allow_no_indices', 'analyze_wildcard', 'analyzer',
'default_operator', 'df', 'expand_wildcards', 'ignore_unavailable',
'lenient', 'lowercase_expanded_terms', 'min_score', 'preference', 'q',
'routing')
def search_exists(self, index=None, doc_type=None, body=None, params=None):
"""
The exists API allows to easily determine if any matching documents
exist for a provided query.
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/search-exists.html>`_
:arg index: A comma-separated list of indices to restrict the results
:arg doc_type: A comma-separated list of types to restrict the results
:arg body: A query to restrict the results specified with the Query DSL
(optional)
: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)
:arg analyze_wildcard: Specify whether wildcard and prefix queries
should be analyzed (default: false)
:arg analyzer: The analyzer to use for the query string
:arg default_operator: The default operator for query string query (AND
or OR), default 'OR', valid choices are: 'AND', 'OR'
:arg df: The field to use as default where no field prefix is given in
the query string
: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'
:arg ignore_unavailable: Whether specified concrete indices should be
ignored when unavailable (missing or closed)
:arg lenient: Specify whether format-based query failures (such as
providing text to a numeric field) should be ignored
:arg lowercase_expanded_terms: Specify whether query terms should be
lowercased
:arg min_score: Include only documents with a specific `_score` value in
the result
:arg preference: Specify the node or shard the operation should be
performed on (default: random)
:arg q: Query in the Lucene query string syntax
:arg routing: Specific routing value
"""
try:
self.transport.perform_request('POST', _make_path(index,
doc_type, '_search', 'exists'), params=params, body=body)
except NotFoundError:
return False
return True
@query_params('allow_no_indices', 'expand_wildcards', 'fields',
'ignore_unavailable', 'level')
@@ -1261,9 +1178,8 @@ class Elasticsearch(object):
level or on a cluster wide level, default 'cluster', valid choices
are: 'indices', 'cluster'
"""
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
'_field_stats'), params=params, body=body)
return data
@query_params()
def render_search_template(self, id=None, body=None, params=None):
@@ -1273,7 +1189,5 @@ class Elasticsearch(object):
:arg id: The id of the stored search template
:arg body: The search definition template and its params
"""
_, data = self.transport.perform_request('GET', _make_path('_render',
return self.transport.perform_request('GET', _make_path('_render',
'template', id), params=params, body=body)
return data
+18 -36
View File
@@ -16,9 +16,8 @@ class CatClient(NamespacedClient):
node
:arg v: Verbose mode. Display column headers, default False
"""
_, data = self.transport.perform_request('GET', _make_path('_cat',
return self.transport.perform_request('GET', _make_path('_cat',
'aliases', name), params=params)
return data
@query_params('bytes', 'h', 'help', 'local', 'master_timeout', 'v')
def allocation(self, node_id=None, params=None):
@@ -39,9 +38,8 @@ class CatClient(NamespacedClient):
node
:arg v: Verbose mode. Display column headers, default False
"""
_, data = self.transport.perform_request('GET', _make_path('_cat',
return self.transport.perform_request('GET', _make_path('_cat',
'allocation', node_id), params=params)
return data
@query_params('h', 'help', 'local', 'master_timeout', 'v')
def count(self, index=None, params=None):
@@ -60,9 +58,8 @@ class CatClient(NamespacedClient):
node
:arg v: Verbose mode. Display column headers, default False
"""
_, data = self.transport.perform_request('GET', _make_path('_cat',
return self.transport.perform_request('GET', _make_path('_cat',
'count', index), params=params)
return data
@query_params('h', 'help', 'local', 'master_timeout', 'ts', 'v')
def health(self, params=None):
@@ -80,9 +77,8 @@ class CatClient(NamespacedClient):
:arg ts: Set to false to disable timestamping, default True
:arg v: Verbose mode. Display column headers, default False
"""
_, data = self.transport.perform_request('GET', '/_cat/health',
return self.transport.perform_request('GET', '/_cat/health',
params=params)
return data
@query_params('help')
def help(self, params=None):
@@ -92,8 +88,7 @@ class CatClient(NamespacedClient):
:arg help: Return help information, default False
"""
_, data = self.transport.perform_request('GET', '/_cat', params=params)
return data
return self.transport.perform_request('GET', '/_cat', params=params)
@query_params('bytes', 'h', 'help', 'local', 'master_timeout', 'pri', 'v')
def indices(self, index=None, params=None):
@@ -115,9 +110,8 @@ class CatClient(NamespacedClient):
False
:arg v: Verbose mode. Display column headers, default False
"""
_, data = self.transport.perform_request('GET', _make_path('_cat',
return self.transport.perform_request('GET', _make_path('_cat',
'indices', index), params=params)
return data
@query_params('h', 'help', 'local', 'master_timeout', 'v')
def master(self, params=None):
@@ -133,9 +127,8 @@ class CatClient(NamespacedClient):
node
:arg v: Verbose mode. Display column headers, default False
"""
_, data = self.transport.perform_request('GET', '/_cat/master',
return self.transport.perform_request('GET', '/_cat/master',
params=params)
return data
@query_params('h', 'help', 'local', 'master_timeout', 'v')
def nodes(self, params=None):
@@ -151,9 +144,8 @@ class CatClient(NamespacedClient):
node
:arg v: Verbose mode. Display column headers, default False
"""
_, data = self.transport.perform_request('GET', '/_cat/nodes',
return self.transport.perform_request('GET', '/_cat/nodes',
params=params)
return data
@query_params('bytes', 'h', 'help', 'master_timeout', 'v')
def recovery(self, index=None, params=None):
@@ -171,9 +163,8 @@ class CatClient(NamespacedClient):
node
:arg v: Verbose mode. Display column headers, default False
"""
_, data = self.transport.perform_request('GET', _make_path('_cat',
return self.transport.perform_request('GET', _make_path('_cat',
'recovery', index), params=params)
return data
@query_params('bytes', 'h', 'help', 'local', 'master_timeout', 'v')
def shards(self, index=None, params=None):
@@ -193,9 +184,8 @@ class CatClient(NamespacedClient):
node
:arg v: Verbose mode. Display column headers, default False
"""
_, data = self.transport.perform_request('GET', _make_path('_cat',
return self.transport.perform_request('GET', _make_path('_cat',
'shards', index), params=params)
return data
@query_params('bytes', 'h', 'help', 'v')
def segments(self, index=None, params=None):
@@ -211,9 +201,8 @@ class CatClient(NamespacedClient):
:arg help: Return help information, default False
:arg v: Verbose mode. Display column headers, default False
"""
_, data = self.transport.perform_request('GET', _make_path('_cat',
return self.transport.perform_request('GET', _make_path('_cat',
'segments', index), params=params)
return data
@query_params('h', 'help', 'local', 'master_timeout', 'v')
def pending_tasks(self, params=None):
@@ -231,9 +220,8 @@ class CatClient(NamespacedClient):
node
:arg v: Verbose mode. Display column headers, default False
"""
_, data = self.transport.perform_request('GET', '/_cat/pending_tasks',
return self.transport.perform_request('GET', '/_cat/pending_tasks',
params=params)
return data
@query_params('full_id', 'h', 'help', 'local', 'master_timeout', 'v')
def thread_pool(self, params=None):
@@ -250,9 +238,8 @@ class CatClient(NamespacedClient):
node
:arg v: Verbose mode. Display column headers, default False
"""
_, data = self.transport.perform_request('GET', '/_cat/thread_pool',
return self.transport.perform_request('GET', '/_cat/thread_pool',
params=params)
return data
@query_params('bytes', 'h', 'help', 'local', 'master_timeout', 'v')
def fielddata(self, fields=None, params=None):
@@ -272,9 +259,8 @@ class CatClient(NamespacedClient):
node
:arg v: Verbose mode. Display column headers, default False
"""
_, data = self.transport.perform_request('GET', _make_path('_cat',
return self.transport.perform_request('GET', _make_path('_cat',
'fielddata', fields), params=params)
return data
@query_params('h', 'help', 'local', 'master_timeout', 'v')
def plugins(self, params=None):
@@ -290,9 +276,8 @@ class CatClient(NamespacedClient):
node
:arg v: Verbose mode. Display column headers, default False
"""
_, data = self.transport.perform_request('GET', '/_cat/plugins',
return self.transport.perform_request('GET', '/_cat/plugins',
params=params)
return data
@query_params('h', 'help', 'local', 'master_timeout', 'v')
def nodeattrs(self, params=None):
@@ -307,9 +292,8 @@ class CatClient(NamespacedClient):
node
:arg v: Verbose mode. Display column headers, default False
"""
_, data = self.transport.perform_request('GET', '/_cat/nodeattrs',
return self.transport.perform_request('GET', '/_cat/nodeattrs',
params=params)
return data
@query_params('h', 'help', 'local', 'master_timeout', 'v')
def repositories(self, params=None):
@@ -324,9 +308,8 @@ class CatClient(NamespacedClient):
node
:arg v: Verbose mode. Display column headers, default False
"""
_, data = self.transport.perform_request('GET', '/_cat/repositories',
return self.transport.perform_request('GET', '/_cat/repositories',
params=params)
return data
@query_params('h', 'help', 'master_timeout', 'v')
def snapshots(self, repository=None, params=None):
@@ -341,6 +324,5 @@ class CatClient(NamespacedClient):
node
:arg v: Verbose mode. Display column headers, default False
"""
_, data = self.transport.perform_request('GET', _make_path('_cat',
return self.transport.perform_request('GET', _make_path('_cat',
'snapshots', repository), params=params)
return data
+7 -14
View File
@@ -26,9 +26,8 @@ class ClusterClient(NamespacedClient):
:arg wait_for_status: Wait until cluster is in a specific state, default
None, valid choices are: 'green', 'yellow', 'red'
"""
_, data = self.transport.perform_request('GET', _make_path('_cluster',
return self.transport.perform_request('GET', _make_path('_cluster',
'health', index), params=params)
return data
@query_params('local', 'master_timeout')
def pending_tasks(self, params=None):
@@ -42,9 +41,8 @@ class ClusterClient(NamespacedClient):
master node (default: false)
:arg master_timeout: Specify timeout for connection to master
"""
_, data = self.transport.perform_request('GET',
return self.transport.perform_request('GET',
'/_cluster/pending_tasks', params=params)
return data
@query_params('allow_no_indices', 'expand_wildcards', 'flat_settings',
'ignore_unavailable', 'local', 'master_timeout')
@@ -71,9 +69,8 @@ class ClusterClient(NamespacedClient):
"""
if index and not metric:
metric = '_all'
_, data = self.transport.perform_request('GET', _make_path('_cluster',
return self.transport.perform_request('GET', _make_path('_cluster',
'state', metric, index), params=params)
return data
@query_params('flat_settings', 'human', 'timeout')
def stats(self, node_id=None, params=None):
@@ -95,8 +92,7 @@ class ClusterClient(NamespacedClient):
url = '/_cluster/stats'
if node_id:
url = _make_path('_cluster/stats/nodes', node_id)
_, data = self.transport.perform_request('GET', url, params=params)
return data
return self.transport.perform_request('GET', url, params=params)
@query_params('dry_run', 'explain', 'master_timeout', 'metric', 'timeout')
def reroute(self, body=None, params=None):
@@ -116,9 +112,8 @@ class ClusterClient(NamespacedClient):
'metadata', 'nodes', 'routing_table', 'master_node', 'version'
:arg timeout: Explicit operation timeout
"""
_, data = self.transport.perform_request('POST', '/_cluster/reroute',
return self.transport.perform_request('POST', '/_cluster/reroute',
params=params, body=body)
return data
@query_params('flat_settings', 'master_timeout', 'timeout')
def get_settings(self, params=None):
@@ -131,9 +126,8 @@ class ClusterClient(NamespacedClient):
node
:arg timeout: Explicit operation timeout
"""
_, data = self.transport.perform_request('GET', '/_cluster/settings',
return self.transport.perform_request('GET', '/_cluster/settings',
params=params)
return data
@query_params('flat_settings', 'master_timeout', 'timeout')
def put_settings(self, body=None, params=None):
@@ -148,7 +142,6 @@ class ClusterClient(NamespacedClient):
node
:arg timeout: Explicit operation timeout
"""
_, data = self.transport.perform_request('PUT', '/_cluster/settings',
return self.transport.perform_request('PUT', '/_cluster/settings',
params=params, body=body)
return data
+39 -91
View File
@@ -1,5 +1,4 @@
from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
from ..exceptions import NotFoundError
class IndicesClient(NamespacedClient):
@query_params('analyzer', 'char_filters', 'field', 'filters', 'format',
@@ -25,9 +24,8 @@ class IndicesClient(NamespacedClient):
request body is not used)
:arg tokenizer: The name of the tokenizer to use for the analysis
"""
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
'_analyze'), params=params, body=body)
return data
@query_params('allow_no_indices', 'expand_wildcards', 'force',
'ignore_unavailable', 'operation_threading')
@@ -50,9 +48,8 @@ class IndicesClient(NamespacedClient):
ignored when unavailable (missing or closed)
:arg operation_threading: TODO: ?
"""
_, data = self.transport.perform_request('POST', _make_path(index,
return self.transport.perform_request('POST', _make_path(index,
'_refresh'), params=params)
return data
@query_params('allow_no_indices', 'expand_wildcards', 'force',
'ignore_unavailable', 'wait_if_ongoing')
@@ -82,9 +79,8 @@ class IndicesClient(NamespacedClient):
to be thrown on the shard level if another flush operation is
already running.
"""
_, data = self.transport.perform_request('POST', _make_path(index,
return self.transport.perform_request('POST', _make_path(index,
'_flush'), params=params)
return data
@query_params('master_timeout', 'timeout', 'update_all_types')
def create(self, index, body=None, params=None):
@@ -101,9 +97,8 @@ class IndicesClient(NamespacedClient):
"""
if index in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'index'.")
_, data = self.transport.perform_request('PUT', _make_path(index),
return self.transport.perform_request('PUT', _make_path(index),
params=params, body=body)
return data
@query_params('allow_no_indices', 'expand_wildcards', 'flat_settings',
'human', 'ignore_unavailable', 'local')
@@ -128,9 +123,8 @@ class IndicesClient(NamespacedClient):
"""
if index in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'index'.")
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
feature), params=params)
return data
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
'master_timeout', 'timeout')
@@ -153,9 +147,8 @@ class IndicesClient(NamespacedClient):
"""
if index in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'index'.")
_, data = self.transport.perform_request('POST', _make_path(index,
return self.transport.perform_request('POST', _make_path(index,
'_open'), params=params)
return data
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
'master_timeout', 'timeout')
@@ -179,9 +172,8 @@ class IndicesClient(NamespacedClient):
"""
if index in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'index'.")
_, data = self.transport.perform_request('POST', _make_path(index,
return self.transport.perform_request('POST', _make_path(index,
'_close'), params=params)
return data
@query_params('master_timeout', 'timeout')
def delete(self, index, params=None):
@@ -196,9 +188,8 @@ class IndicesClient(NamespacedClient):
"""
if index in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'index'.")
_, data = self.transport.perform_request('DELETE', _make_path(index),
return self.transport.perform_request('DELETE', _make_path(index),
params=params)
return data
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
'local')
@@ -221,12 +212,8 @@ class IndicesClient(NamespacedClient):
"""
if index in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'index'.")
try:
self.transport.perform_request('HEAD', _make_path(index),
return self.transport.perform_request('HEAD', _make_path(index),
params=params)
except NotFoundError:
return False
return True
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
'local')
@@ -252,12 +239,8 @@ class IndicesClient(NamespacedClient):
for param in (index, doc_type):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
try:
self.transport.perform_request('HEAD', _make_path(index, doc_type),
return self.transport.perform_request('HEAD', _make_path(index, doc_type),
params=params)
except NotFoundError:
return False
return True
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
'master_timeout', 'timeout', 'update_all_types')
@@ -287,9 +270,8 @@ class IndicesClient(NamespacedClient):
for param in (doc_type, body):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('PUT', _make_path(index,
return self.transport.perform_request('PUT', _make_path(index,
'_mapping', doc_type), params=params, body=body)
return data
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
'local')
@@ -311,9 +293,8 @@ class IndicesClient(NamespacedClient):
:arg local: Return local information, do not retrieve the state from
master node (default: false)
"""
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
'_mapping', doc_type), params=params)
return data
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
'include_defaults', 'local')
@@ -340,9 +321,8 @@ class IndicesClient(NamespacedClient):
"""
if fields in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'fields'.")
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
'_mapping', doc_type, 'field', fields), params=params)
return data
@query_params('master_timeout', 'timeout')
def put_alias(self, index, name, body=None, params=None):
@@ -361,9 +341,8 @@ class IndicesClient(NamespacedClient):
for param in (index, name):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('PUT', _make_path(index,
return self.transport.perform_request('PUT', _make_path(index,
'_alias', name), params=params, body=body)
return data
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
'local')
@@ -385,12 +364,8 @@ class IndicesClient(NamespacedClient):
:arg local: Return local information, do not retrieve the state from
master node (default: false)
"""
try:
self.transport.perform_request('HEAD', _make_path(index, '_alias',
return self.transport.perform_request('HEAD', _make_path(index, '_alias',
name), params=params)
except NotFoundError:
return False
return True
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
'local')
@@ -412,9 +387,8 @@ class IndicesClient(NamespacedClient):
:arg local: Return local information, do not retrieve the state from
master node (default: false)
"""
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
'_alias', name), params=params)
return data
@query_params('local', 'timeout')
def get_aliases(self, index=None, name=None, params=None):
@@ -428,9 +402,8 @@ class IndicesClient(NamespacedClient):
master node (default: false)
:arg timeout: Explicit operation timeout
"""
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
'_aliases', name), params=params)
return data
@query_params('master_timeout', 'timeout')
def update_aliases(self, body, params=None):
@@ -444,9 +417,8 @@ class IndicesClient(NamespacedClient):
"""
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
_, data = self.transport.perform_request('POST', '/_aliases',
return self.transport.perform_request('POST', '/_aliases',
params=params, body=body)
return data
@query_params('master_timeout', 'timeout')
def delete_alias(self, index, name, params=None):
@@ -465,9 +437,8 @@ class IndicesClient(NamespacedClient):
for param in (index, name):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('DELETE', _make_path(index,
return self.transport.perform_request('DELETE', _make_path(index,
'_alias', name), params=params)
return data
@query_params('create', 'flat_settings', 'master_timeout', 'order',
'timeout')
@@ -490,9 +461,8 @@ class IndicesClient(NamespacedClient):
for param in (name, body):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('PUT', _make_path('_template',
return self.transport.perform_request('PUT', _make_path('_template',
name), params=params, body=body)
return data
@query_params('local', 'master_timeout')
def exists_template(self, name, params=None):
@@ -508,12 +478,8 @@ class IndicesClient(NamespacedClient):
"""
if name in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'name'.")
try:
self.transport.perform_request('HEAD', _make_path('_template',
return self.transport.perform_request('HEAD', _make_path('_template',
name), params=params)
except NotFoundError:
return False
return True
@query_params('flat_settings', 'local', 'master_timeout')
def get_template(self, name=None, params=None):
@@ -528,9 +494,8 @@ class IndicesClient(NamespacedClient):
:arg master_timeout: Explicit operation timeout for connection to master
node
"""
_, data = self.transport.perform_request('GET', _make_path('_template',
return self.transport.perform_request('GET', _make_path('_template',
name), params=params)
return data
@query_params('master_timeout', 'timeout')
def delete_template(self, name, params=None):
@@ -544,9 +509,8 @@ class IndicesClient(NamespacedClient):
"""
if name in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'name'.")
_, data = self.transport.perform_request('DELETE',
return self.transport.perform_request('DELETE',
_make_path('_template', name), params=params)
return data
@query_params('allow_no_indices', 'expand_wildcards', 'flat_settings',
'human', 'ignore_unavailable', 'local')
@@ -572,9 +536,8 @@ class IndicesClient(NamespacedClient):
:arg local: Return local information, do not retrieve the state from
master node (default: false)
"""
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
'_settings', name), params=params)
return data
@query_params('allow_no_indices', 'expand_wildcards', 'flat_settings',
'ignore_unavailable', 'master_timeout')
@@ -599,9 +562,8 @@ class IndicesClient(NamespacedClient):
"""
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
_, data = self.transport.perform_request('PUT', _make_path(index,
return self.transport.perform_request('PUT', _make_path(index,
'_settings'), params=params, body=body)
return data
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
'master_timeout', 'request_cache')
@@ -636,9 +598,8 @@ class IndicesClient(NamespacedClient):
for param in (name, body):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('PUT', _make_path(index,
return self.transport.perform_request('PUT', _make_path(index,
doc_type, '_warmer', name), params=params, body=body)
return data
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
'local')
@@ -664,9 +625,8 @@ class IndicesClient(NamespacedClient):
:arg local: Return local information, do not retrieve the state from
master node (default: false)
"""
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
doc_type, '_warmer', name), params=params)
return data
@query_params('master_timeout')
def delete_warmer(self, index, name, params=None):
@@ -686,9 +646,8 @@ class IndicesClient(NamespacedClient):
for param in (index, name):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('DELETE', _make_path(index,
return self.transport.perform_request('DELETE', _make_path(index,
'_warmer', name), params=params)
return data
@query_params('completion_fields', 'fielddata_fields', 'fields', 'groups',
'human', 'level', 'types')
@@ -715,9 +674,8 @@ class IndicesClient(NamespacedClient):
:arg types: A comma-separated list of document types for the `indexing`
index metric
"""
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
'_stats', metric), params=params)
return data
@query_params('allow_no_indices', 'expand_wildcards', 'human',
'ignore_unavailable', 'operation_threading')
@@ -740,9 +698,8 @@ class IndicesClient(NamespacedClient):
ignored when unavailable (missing or closed)
:arg operation_threading: TODO: ?
"""
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
'_segments'), params=params)
return data
@query_params('allow_no_indices', 'expand_wildcards', 'flush',
'ignore_unavailable', 'max_num_segments', 'only_expunge_deletes',
@@ -772,9 +729,8 @@ class IndicesClient(NamespacedClient):
:arg wait_for_merge: Specify whether the request should block until the
merge process is finished (default: true)
"""
_, data = self.transport.perform_request('POST', _make_path(index,
return self.transport.perform_request('POST', _make_path(index,
'_optimize'), params=params)
return data
@query_params('allow_no_indices', 'analyze_wildcard', 'analyzer',
'default_operator', 'df', 'expand_wildcards', 'explain',
@@ -816,9 +772,8 @@ class IndicesClient(NamespacedClient):
:arg rewrite: Provide a more detailed explanation showing the actual
Lucene query that will be executed.
"""
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
doc_type, '_validate', 'query'), params=params, body=body)
return data
@query_params('allow_no_indices', 'expand_wildcards', 'field_data',
'fielddata', 'fields', 'ignore_unavailable', 'query', 'recycler',
@@ -845,9 +800,8 @@ class IndicesClient(NamespacedClient):
:arg recycler: Clear the recycler cache
:arg request: Clear request cache
"""
_, data = self.transport.perform_request('POST', _make_path(index,
return self.transport.perform_request('POST', _make_path(index,
'_cache', 'clear'), params=params)
return data
@query_params('active_only', 'detailed', 'human')
def recovery(self, index=None, params=None):
@@ -866,9 +820,8 @@ class IndicesClient(NamespacedClient):
:arg human: Whether to return time and byte values in human-readable
format., default False
"""
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
'_recovery'), params=params)
return data
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
'only_ancient_segments', 'wait_for_completion')
@@ -892,9 +845,8 @@ class IndicesClient(NamespacedClient):
:arg wait_for_completion: Specify whether the request should block until
the all segments are upgraded (default: false)
"""
_, data = self.transport.perform_request('POST', _make_path(index,
return self.transport.perform_request('POST', _make_path(index,
'_upgrade'), params=params)
return data
@query_params('allow_no_indices', 'expand_wildcards', 'human',
'ignore_unavailable')
@@ -916,9 +868,8 @@ class IndicesClient(NamespacedClient):
:arg ignore_unavailable: Whether specified concrete indices should be
ignored when unavailable (missing or closed)
"""
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
'_upgrade'), params=params)
return data
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable')
def flush_synced(self, index=None, params=None):
@@ -937,9 +888,8 @@ class IndicesClient(NamespacedClient):
:arg ignore_unavailable: Whether specified concrete indices should be
ignored when unavailable (missing or closed)
"""
_, data = self.transport.perform_request('POST', _make_path(index,
return self.transport.perform_request('POST', _make_path(index,
'_flush', 'synced'), params=params)
return data
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
'operation_threading', 'status')
@@ -962,9 +912,8 @@ class IndicesClient(NamespacedClient):
to get store information for, valid choices are: 'green', 'yellow',
'red', 'all'
"""
_, data = self.transport.perform_request('GET', _make_path(index,
return self.transport.perform_request('GET', _make_path(index,
'_shard_stores'), params=params)
return data
@query_params('allow_no_indices', 'expand_wildcards', 'flush',
'ignore_unavailable', 'max_num_segments', 'only_expunge_deletes',
@@ -993,6 +942,5 @@ class IndicesClient(NamespacedClient):
:arg wait_for_merge: Specify whether the request should block until the
merge process is finished (default: true)
"""
_, data = self.transport.perform_request('POST', _make_path(index,
return self.transport.perform_request('POST', _make_path(index,
'_forcemerge'), params=params)
return data
+3 -7
View File
@@ -19,9 +19,8 @@ class NodesClient(NamespacedClient):
format., default False
:arg timeout: Explicit operation timeout
"""
_, data = self.transport.perform_request('GET', _make_path('_nodes',
return self.transport.perform_request('GET', _make_path('_nodes',
node_id, metric), params=params)
return data
@query_params('completion_fields', 'fielddata_fields', 'fields', 'groups',
'human', 'level', 'timeout', 'types')
@@ -56,9 +55,8 @@ class NodesClient(NamespacedClient):
:arg types: A comma-separated list of document types for the `indexing`
index metric
"""
_, data = self.transport.perform_request('GET', _make_path('_nodes',
return self.transport.perform_request('GET', _make_path('_nodes',
node_id, 'stats', metric, index_metric), params=params)
return data
@query_params('doc_type', 'ignore_idle_threads', 'interval', 'snapshots',
'threads', 'timeout')
@@ -85,7 +83,5 @@ class NodesClient(NamespacedClient):
# avoid python reserved words
if params and 'type_' in params:
params['type'] = params.pop('type_')
_, data = self.transport.perform_request('GET', _make_path('_cluster',
return self.transport.perform_request('GET', _make_path('_cluster',
'nodes', node_id, 'hotthreads'), params=params)
return data
+9 -19
View File
@@ -18,9 +18,8 @@ class SnapshotClient(NamespacedClient):
for param in (repository, snapshot):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('PUT', _make_path('_snapshot',
return self.transport.perform_request('PUT', _make_path('_snapshot',
repository, snapshot), params=params, body=body)
return data
@query_params('master_timeout')
def delete(self, repository, snapshot, params=None):
@@ -36,9 +35,8 @@ class SnapshotClient(NamespacedClient):
for param in (repository, snapshot):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('DELETE',
return self.transport.perform_request('DELETE',
_make_path('_snapshot', repository, snapshot), params=params)
return data
@query_params('master_timeout')
def get(self, repository, snapshot, params=None):
@@ -54,9 +52,8 @@ class SnapshotClient(NamespacedClient):
for param in (repository, snapshot):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('GET', _make_path('_snapshot',
return self.transport.perform_request('GET', _make_path('_snapshot',
repository, snapshot), params=params)
return data
@query_params('master_timeout', 'timeout')
def delete_repository(self, repository, params=None):
@@ -71,9 +68,8 @@ class SnapshotClient(NamespacedClient):
"""
if repository in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'repository'.")
_, data = self.transport.perform_request('DELETE',
return self.transport.perform_request('DELETE',
_make_path('_snapshot', repository), params=params)
return data
@query_params('local', 'master_timeout')
def get_repository(self, repository=None, params=None):
@@ -87,9 +83,8 @@ class SnapshotClient(NamespacedClient):
:arg master_timeout: Explicit operation timeout for connection to master
node
"""
_, data = self.transport.perform_request('GET', _make_path('_snapshot',
return self.transport.perform_request('GET', _make_path('_snapshot',
repository), params=params)
return data
@query_params('master_timeout', 'timeout', 'verify')
def create_repository(self, repository, body, params=None):
@@ -107,9 +102,8 @@ class SnapshotClient(NamespacedClient):
for param in (repository, body):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('PUT', _make_path('_snapshot',
return self.transport.perform_request('PUT', _make_path('_snapshot',
repository), params=params, body=body)
return data
@query_params('master_timeout', 'wait_for_completion')
def restore(self, repository, snapshot, body=None, params=None):
@@ -128,9 +122,8 @@ class SnapshotClient(NamespacedClient):
for param in (repository, snapshot):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
_, data = self.transport.perform_request('POST', _make_path('_snapshot',
return self.transport.perform_request('POST', _make_path('_snapshot',
repository, snapshot, '_restore'), params=params, body=body)
return data
@query_params('master_timeout')
def status(self, repository=None, snapshot=None, params=None):
@@ -145,9 +138,8 @@ class SnapshotClient(NamespacedClient):
:arg master_timeout: Explicit operation timeout for connection to master
node
"""
_, data = self.transport.perform_request('GET', _make_path('_snapshot',
return self.transport.perform_request('GET', _make_path('_snapshot',
repository, snapshot, '_status'), params=params)
return data
@query_params('master_timeout', 'timeout')
def verify_repository(self, repository, params=None):
@@ -163,7 +155,5 @@ class SnapshotClient(NamespacedClient):
"""
if repository in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'repository'.")
_, data = self.transport.perform_request('POST', _make_path('_snapshot',
return self.transport.perform_request('POST', _make_path('_snapshot',
repository, '_verify'), params=params)
return data
+2 -2
View File
@@ -31,7 +31,7 @@ class RequestsHttpConnection(Connection):
if not REQUESTS_AVAILABLE:
raise ImproperlyConfigured("Please install requests to use RequestsHttpConnection.")
super(RequestsHttpConnection, self).__init__(host= host, port=port, **kwargs)
super(RequestsHttpConnection, self).__init__(host=host, port=port, **kwargs)
self.session = requests.session()
if http_auth is not None:
if isinstance(http_auth, (tuple, list)):
@@ -91,4 +91,4 @@ class RequestsHttpConnection(Connection):
"""
Explicitly closes connections
"""
self.session.close()
self.session.close()
+26 -22
View File
@@ -218,6 +218,24 @@ class Transport(object):
return list(node_info['nodes'].values())
def _get_host_info(self, host_info):
address_key = self.connection_class.transport_schema + '_address'
host = {}
address = host_info.get(address_key, '')
if '/' in address:
host['host'], address = address.split('/', 1)
# malformed address
if ':' not in address:
return None
ip, port = address.rsplit(':', 1)
# use the ip if not overridden by publish_host
host.setdefault('host', ip)
host['port'] = int(port)
return self.host_info_callback(host_info, host)
def sniff_hosts(self, initial=False):
"""
@@ -231,27 +249,7 @@ class Transport(object):
"""
node_info = self._get_sniff_data(initial)
hosts = []
address_key = self.connection_class.transport_schema + '_address'
for n in node_info:
host = {}
address = n.get(address_key, '')
if '/' in address:
host['host'], address = address.split('/', 1)
# malformed address
if ':' not in address:
continue
ip, port = address.rsplit(':', 1)
# use the ip if not overridden by publish_host
host.setdefault('host', ip)
host['port'] = int(port)
host = self.host_info_callback(n, host)
if host is not None:
hosts.append(host)
hosts = list(filter(None, (self._get_host_info(n) for n in node_info)))
# we weren't able to get any nodes, maybe using an incompatible
# transport_schema or host_info_callback blocked all - raise error.
@@ -329,6 +327,9 @@ class Transport(object):
status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
except TransportError as e:
if method == 'HEAD' and e.status_code == 404:
return False
retry = False
if isinstance(e, ConnectionTimeout):
retry = self.retry_on_timeout
@@ -347,11 +348,14 @@ class Transport(object):
raise
else:
if method == 'HEAD':
return 200 <= status < 300
# connection didn't fail, confirm it's live status
self.connection_pool.mark_live(connection)
if data:
data = self.deserializer.loads(data, headers.get('content-type'))
return status, data
return data
def close(self):
"""