Skip to content

Commit 4fda104

Browse files
authored
Adding X-Pack clients to -py repo (elastic#748)
1 parent b5595d0 commit 4fda104

File tree

10 files changed

+1069
-0
lines changed

10 files changed

+1069
-0
lines changed

elasticsearch/client/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from .remote import RemoteClient
1313
from .snapshot import SnapshotClient
1414
from .tasks import TasksClient
15+
from .xpack import XPackClient
1516
from .utils import query_params, _make_path, SKIP_IN_PATH
1617

1718
logger = logging.getLogger('elasticsearch')
@@ -195,6 +196,7 @@ def __init__(self, hosts=None, transport_class=Transport, **kwargs):
195196
self.remote = RemoteClient(self)
196197
self.snapshot = SnapshotClient(self)
197198
self.tasks = TasksClient(self)
199+
self.xpack = XPackClient(self)
198200

199201
def __repr__(self):
200202
try:
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from elasticsearch.client.utils import NamespacedClient, query_params
2+
3+
from .graph import GraphClient
4+
from .license import LicenseClient
5+
from .monitoring import MonitoringClient
6+
from .security import SecurityClient
7+
from .watcher import WatcherClient
8+
from .ml import MlClient
9+
from .migration import MigrationClient
10+
from .deprecation import DeprecationClient
11+
12+
class XPackClient(NamespacedClient):
13+
namespace = 'xpack'
14+
15+
def __init__(self, *args, **kwargs):
16+
super(XPackClient, self).__init__(*args, **kwargs)
17+
self.graph = GraphClient(self.client)
18+
self.license = LicenseClient(self.client)
19+
self.monitoring = MonitoringClient(self.client)
20+
self.security = SecurityClient(self.client)
21+
self.watcher = WatcherClient(self.client)
22+
self.ml = MlClient(self.client)
23+
self.migration = MigrationClient(self.client)
24+
self.deprecation = DeprecationClient(self.client)
25+
26+
@query_params('categories', 'human')
27+
def info(self, params=None):
28+
"""
29+
Retrieve information about xpack, including build number/timestamp and license status
30+
`<https://www.elastic.co/guide/en/elasticsearch/reference/current/info-api.html>`_
31+
32+
:arg categories: Comma-separated list of info categories. Can be any of:
33+
build, license, features
34+
:arg human: Presents additional info for humans (feature descriptions
35+
and X-Pack tagline)
36+
"""
37+
return self.transport.perform_request('GET', '/_xpack', params=params)
38+
39+
@query_params('master_timeout')
40+
def usage(self, params=None):
41+
"""
42+
Retrieve information about xpack features usage
43+
44+
:arg master_timeout: Specify timeout for watch write operation
45+
"""
46+
return self.transport.perform_request('GET', '/_xpack/usage',
47+
params=params)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from elasticsearch.client.utils import NamespacedClient, query_params, _make_path
2+
3+
class DeprecationClient(NamespacedClient):
4+
@query_params()
5+
def info(self, index=None, params=None):
6+
"""
7+
`<http://www.elastic.co/guide/en/migration/current/migration-api-deprecation.html>`_
8+
9+
:arg index: Index pattern
10+
"""
11+
return self.transport.perform_request('GET', _make_path(index, '_xpack',
12+
'migration', 'deprecations'), params=params)
13+

elasticsearch/client/xpack/graph.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from elasticsearch.client.utils import NamespacedClient, query_params, _make_path
2+
3+
class GraphClient(NamespacedClient):
4+
@query_params('routing', 'timeout')
5+
def explore(self, index=None, doc_type=None, body=None, params=None):
6+
"""
7+
`<https://www.elastic.co/guide/en/elasticsearch/reference/current/graph-explore-api.html>`_
8+
9+
:arg index: A comma-separated list of index names to search; use `_all`
10+
or empty string to perform the operation on all indices
11+
:arg doc_type: A comma-separated list of document types to search; leave
12+
empty to perform the operation on all types
13+
:arg body: Graph Query DSL
14+
:arg routing: Specific routing value
15+
:arg timeout: Explicit operation timeout
16+
"""
17+
return self.transport.perform_request('GET', _make_path(index, doc_type,
18+
'_xpack', 'graph', '_explore'), params=params, body=body)

elasticsearch/client/xpack/license.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from elasticsearch.client.utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
2+
3+
class LicenseClient(NamespacedClient):
4+
@query_params()
5+
def delete(self, params=None):
6+
"""
7+
8+
`<https://www.elastic.co/guide/en/x-pack/current/license-management.html>`_
9+
"""
10+
return self.transport.perform_request('DELETE', '/_xpack/license',
11+
params=params)
12+
13+
@query_params('local')
14+
def get(self, params=None):
15+
"""
16+
17+
`<https://www.elastic.co/guide/en/x-pack/current/license-management.html>`_
18+
19+
:arg local: Return local information, do not retrieve the state from
20+
master node (default: false)
21+
"""
22+
return self.transport.perform_request('GET', '/_xpack/license',
23+
params=params)
24+
25+
@query_params('acknowledge')
26+
def post(self, body=None, params=None):
27+
"""
28+
29+
`<https://www.elastic.co/guide/en/x-pack/current/license-management.html>`_
30+
31+
:arg body: licenses to be installed
32+
:arg acknowledge: whether the user has acknowledged acknowledge messages
33+
(default: false)
34+
"""
35+
return self.transport.perform_request('PUT', '/_xpack/license',
36+
params=params, body=body)
37+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from elasticsearch.client.utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
2+
3+
class MigrationClient(NamespacedClient):
4+
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable')
5+
def get_assistance(self, index=None, params=None):
6+
"""
7+
`<https://www.elastic.co/guide/en/elasticsearch/reference/current/migration-api-assistance.html>`_
8+
9+
:arg index: A comma-separated list of index names; use `_all` or empty
10+
string to perform the operation on all indices
11+
:arg allow_no_indices: Whether to ignore if a wildcard indices
12+
expression resolves into no concrete indices. (This includes `_all`
13+
string or when no indices have been specified)
14+
:arg expand_wildcards: Whether to expand wildcard expression to concrete
15+
indices that are open, closed or both., default 'open', valid
16+
choices are: 'open', 'closed', 'none', 'all'
17+
:arg ignore_unavailable: Whether specified concrete indices should be
18+
ignored when unavailable (missing or closed)
19+
"""
20+
return self.transport.perform_request('GET', _make_path('_xpack',
21+
'migration', 'assistance', index), params=params)
22+
23+
@query_params('wait_for_completion')
24+
def upgrade(self, index, params=None):
25+
"""
26+
27+
`<https://www.elastic.co/guide/en/elasticsearch/reference/current/migration-api-upgrade.html>`_
28+
29+
:arg index: The name of the index
30+
:arg wait_for_completion: Should the request block until the upgrade
31+
operation is completed, default True
32+
"""
33+
if index in SKIP_IN_PATH:
34+
raise ValueError("Empty value passed for a required argument 'index'.")
35+
return self.transport.perform_request('POST', _make_path('_xpack',
36+
'migration', 'upgrade', index), params=params)

0 commit comments

Comments
 (0)