-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathkafka_quotas.py
178 lines (161 loc) · 4.97 KB
/
kafka_quotas.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Ansible module for akfka quotas management
"""
from __future__ import absolute_import, division, print_function
__metaclass__ = type
# Init logging
import logging
import sys
# XXX: fix kafka-python import broken for Python 3.12
import ansible.module_utils.kafka_fix_import # noqa
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.kafka_lib_quotas import process_module_quotas
from ansible.module_utils.kafka_lib_commons import (
module_commons, module_zookeeper_commons,
DOCUMENTATION_COMMON
)
# Default logging
# TODO: refactor all this logging logic
log = logging.getLogger('kafka')
log.addHandler(logging.StreamHandler(sys.stdout))
log.setLevel(logging.INFO)
log = logging.getLogger('kazoo.client')
log.addHandler(logging.StreamHandler(sys.stdout))
log.setLevel(logging.INFO)
ANSIBLE_METADATA = {'metadata_version': '1.0'}
DOCUMENTATION = '''
---
module: kafka_quotas
short_description: Manage Kafka quotas
description:
- Configure Kafka quotas.
- Not compatible avec Kafka version < 0.11.0.
author:
- Stephen SORRIAUX
- ryarnyah
options:
entries:
description:
- Entries to manage.
mark_others_as_absent:
description:
- make non listed topics as absent, thus triggering the deletion
- of topics absent from the `topics` listing
zookeeper:
description:
- 'the zookeeper connection.'
zookeeper_auth_scheme:
description:
- 'when zookeeper is configured to use authentication, schema used to '
- 'connect to zookeeper.'
default: 'digest'
choices: [digest, sasl]
zookeeper_auth_value:
description:
- 'when zookeeper is configured to use authentication, value used to '
- 'connect.'
zookeeper_use_ssl:
description:
- 'force using ssl for zookeeper connection.'
default: False
zookeeper_ssl_check_hostname:
description:
- 'when using ssl for zookeeper, check if certificate for hostname is '
- 'correct.'
default: True
zookeeper_ssl_cafile:
description:
- 'when using ssl for zookeeper, content of ca cert file or path to '
- 'ca cert file.'
zookeeper_ssl_certfile:
description:
- 'when using ssl for zookeeper, content of cert file or path to '
- 'server cert file.'
zookeeper_ssl_keyfile:
description:
- 'when using ssl for zookeeper, content of keyfile or path to '
- 'server cert key file.'
zookeeper_ssl_password:
description:
- 'when using ssl for zookeeper, password for ssl_keyfile.'
zookeeper_sleep_time:
description:
- 'when updating number of partitions and while checking for'
- 'the ZK node, the time to sleep (in seconds) between'
- 'each checks.'
default: 5
zookeeper_max_retries:
description:
- 'when updating number of partitions and while checking for'
- 'the ZK node, maximum of try to do before failing'
default: 5
kafka_sleep_time:
description:
- 'when updating number of partitions and while checking for'
- 'kafka to applied, the time to sleep (in seconds) between'
- 'each checks.'
default: 5
kafka_max_retries:
description:
- 'when updating number of partitions and while checking for'
- 'kafka to applied, maximum of try to do before failing'
default: 5
''' + DOCUMENTATION_COMMON
EXAMPLES = '''
# add quotas
- name: create quotas
kafka_quotas:
entries:
- entity:
user: test
quotas:
producer_byte_rate: 1048576
consumer_byte_rate: 1048576
request_percentage: 55
zookeeper: >
"{{ hostvars['zk']['ansible_eth0']['ipv4']['address'] }}:2181"
bootstrap_servers: >
"{{ hostvars['kafka1']['ansible_eth0']['ipv4']['address'] }}:9092,
{{ hostvars['kafka2']['ansible_eth0']['ipv4']['address'] }}:9092"
'''
def main():
"""
Module usage
"""
spec = dict(
entries=dict(
type='list',
elements='dict',
required=True,
options=dict(
entity=dict(
type='dict',
required=True,
required_one_of=[('user', 'client')],
options=dict(
user=dict(type='str'),
client=dict(type='str')
)
),
quotas=dict(
type='dict',
required=True,
options=dict(
producer_byte_rate=dict(type='int'),
consumer_byte_rate=dict(type='int'),
request_percentage=dict(type='float')
))
)
),
**module_commons
)
spec.update(module_zookeeper_commons)
module = AnsibleModule(
argument_spec=spec,
supports_check_mode=True
)
process_module_quotas(module)
if __name__ == '__main__':
main()