Flatten namespaces, keep xpack access as failover

This commit is contained in:
Honza Král
2019-12-22 16:32:49 +01:00
committed by Honza Král
parent d2a0cc62eb
commit d8d1b4b0fa
19 changed files with 83 additions and 98 deletions
+35 -6
View File
@@ -12,9 +12,26 @@ from .nodes import NodesClient
from .remote import RemoteClient
from .snapshot import SnapshotClient
from .tasks import TasksClient
from .xpack import XPackClient, XPACK_NAMESPACES
from .xpack import XPackClient
from .utils import query_params, _make_path, SKIP_IN_PATH
# xpack APIs
from .ccr import CcrClient
from .data_frame import Data_FrameClient
from .deprecation import DeprecationClient
from .graph import GraphClient
from .ilm import IlmClient
from .license import LicenseClient
from .migration import MigrationClient
from .ml import MlClient
from .monitoring import MonitoringClient
from .rollup import RollupClient
from .security import SecurityClient
from .sql import SqlClient
from .ssl import SslClient
from .watcher import WatcherClient
logger = logging.getLogger("elasticsearch")
@@ -215,12 +232,22 @@ class Elasticsearch(object):
self.snapshot = SnapshotClient(self)
self.tasks = TasksClient(self)
# new style access to x-pack features without .xpack step
for namespace, NamespacedClient in XPACK_NAMESPACES.items():
setattr(self, namespace, NamespacedClient(self))
# old style xpack access
self.xpack = XPackClient(self)
self.ccr = CcrClient(self)
self.data_frame = Data_FrameClient(self)
self.deprecation = DeprecationClient(self)
self.graph = GraphClient(self)
self.ilm = IlmClient(self)
self.indices = IndicesClient(self)
self.license = LicenseClient(self)
self.migration = MigrationClient(self)
self.ml = MlClient(self)
self.monitoring = MonitoringClient(self)
self.rollup = RollupClient(self)
self.security = SecurityClient(self)
self.sql = SqlClient(self)
self.ssl = SslClient(self)
self.watcher = WatcherClient(self)
def __repr__(self):
try:
@@ -245,6 +272,8 @@ class Elasticsearch(object):
return body
# AUTO-GENERATED-API-DEFINITIONS #
@query_params()
def ping(self, params=None):
"""
@@ -1,4 +1,4 @@
from ..utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
class CcrClient(NamespacedClient):
+1 -1
View File
@@ -122,7 +122,7 @@ class ClusterClient(NamespacedClient):
"""
url = "/_cluster/stats"
if node_id:
url = _make_path("_cluster","stats","nodes", node_id)
url = _make_path("_cluster", "stats", "nodes", node_id)
return self.transport.perform_request("GET", url, params=params)
@query_params(
@@ -1,4 +1,4 @@
from ..utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
class Data_FrameClient(NamespacedClient):
@@ -1,4 +1,4 @@
from ..utils import NamespacedClient, query_params, _make_path
from .utils import NamespacedClient, query_params, _make_path
class DeprecationClient(NamespacedClient):
@@ -1,4 +1,4 @@
from ..utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
class GraphClient(NamespacedClient):
@@ -1,4 +1,4 @@
from ..utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
class IlmClient(NamespacedClient):
+4 -13
View File
@@ -79,10 +79,7 @@ class IndicesClient(NamespacedClient):
)
@query_params(
"master_timeout",
"timeout",
"wait_for_active_shards",
"include_type_name",
"master_timeout", "timeout", "wait_for_active_shards", "include_type_name",
)
def create(self, index, body=None, params=None):
"""
@@ -104,11 +101,7 @@ class IndicesClient(NamespacedClient):
"PUT", _make_path(index), params=params, body=body
)
@query_params(
"master_timeout",
"timeout",
"wait_for_active_shards"
)
@query_params("master_timeout", "timeout", "wait_for_active_shards")
def clone(self, index, target, body=None, params=None):
"""
Clones an index
@@ -127,7 +120,7 @@ class IndicesClient(NamespacedClient):
raise ValueError("Empty value passed for a required argument 'target'.")
return self.transport.perform_request(
"PUT", _make_path(index, '_clone', target), params=params, body=body
"PUT", _make_path(index, "_clone", target), params=params, body=body
)
@query_params(
@@ -1035,9 +1028,7 @@ class IndicesClient(NamespacedClient):
"POST", _make_path(index, "_forcemerge"), params=params
)
@query_params(
"master_timeout", "timeout", "wait_for_active_shards"
)
@query_params("master_timeout", "timeout", "wait_for_active_shards")
def shrink(self, index, target, body=None, params=None):
"""
The shrink index API allows you to shrink an existing index into a new
@@ -1,4 +1,4 @@
from ..utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
class LicenseClient(NamespacedClient):
@@ -1,4 +1,4 @@
from ..utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
class MigrationClient(NamespacedClient):
@@ -1,4 +1,4 @@
from ..utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
class MlClient(NamespacedClient):
@@ -1,4 +1,4 @@
from ..utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
class MonitoringClient(NamespacedClient):
@@ -1,4 +1,4 @@
from ..utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
class RollupClient(NamespacedClient):
@@ -1,4 +1,4 @@
from ..utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
class SecurityClient(NamespacedClient):
@@ -1,4 +1,4 @@
from ..utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
class SqlClient(NamespacedClient):
@@ -1,4 +1,4 @@
from ..utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
class SslClient(NamespacedClient):
@@ -1,4 +1,4 @@
from ..utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
class WatcherClient(NamespacedClient):
+29
View File
@@ -0,0 +1,29 @@
from .utils import NamespacedClient, query_params
class XPackClient(NamespacedClient):
def __getattr__(self, attr_name):
return getattr(self.client, attr_name)
# AUTO-GENERATED-API-DEFINITIONS #
@query_params("categories", "human")
def info(self, params=None):
"""
Retrieve information about xpack, including build number/timestamp and license status
`<https://www.elastic.co/guide/en/elasticsearch/reference/current/info-api.html>`_
:arg categories: Comma-separated list of info categories. Can be any of:
build, license, features
:arg human: Presents additional info for humans (feature descriptions
and X-Pack tagline)
"""
return self.transport.perform_request("GET", "/_xpack", params=params)
@query_params("master_timeout")
def usage(self, params=None):
"""
Retrieve information about xpack features usage
:arg master_timeout: Specify timeout for watch write operation
"""
return self.transport.perform_request("GET", "/_xpack/usage", params=params)
-64
View File
@@ -1,64 +0,0 @@
from ..utils import NamespacedClient, query_params
from .ccr import CcrClient
from .data_frame import Data_FrameClient
from .deprecation import DeprecationClient
from .graph import GraphClient
from .ilm import IlmClient
from ..indices import IndicesClient
from .license import LicenseClient
from .migration import MigrationClient
from .ml import MlClient
from .monitoring import MonitoringClient
from .rollup import RollupClient
from .security import SecurityClient
from .sql import SqlClient
from .ssl import SslClient
from .watcher import WatcherClient
XPACK_NAMESPACES = {
"ccr": CcrClient,
"data_frame": Data_FrameClient,
"deprecation": DeprecationClient,
"graph": GraphClient,
"ilm": IlmClient,
"indices": IndicesClient,
"license": LicenseClient,
"migration": MigrationClient,
"ml": MlClient,
"monitoring": MonitoringClient,
"rollup": RollupClient,
"security": SecurityClient,
"sql": SqlClient,
"ssl": SslClient,
"watcher": WatcherClient,
}
class XPackClient(NamespacedClient):
def __init__(self, *args, **kwargs):
super(XPackClient, self).__init__(*args, **kwargs)
for namespace in XPACK_NAMESPACES:
setattr(self, namespace, getattr(self.client, namespace))
@query_params("categories", "human")
def info(self, params=None):
"""
Retrieve information about xpack, including build number/timestamp and license status
`<https://www.elastic.co/guide/en/elasticsearch/reference/current/info-api.html>`_
:arg categories: Comma-separated list of info categories. Can be any of:
build, license, features
:arg human: Presents additional info for humans (feature descriptions
and X-Pack tagline)
"""
return self.transport.perform_request("GET", "/_xpack", params=params)
@query_params("master_timeout")
def usage(self, params=None):
"""
Retrieve information about xpack features usage
:arg master_timeout: Specify timeout for watch write operation
"""
return self.transport.perform_request("GET", "/_xpack/usage", params=params)