mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 19:31:26 -07:00
Pep8 fixes for rabbitmq modules (#24590)
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
85fc4c67ef
commit
f7321a87ca
9 changed files with 192 additions and 207 deletions
|
@ -134,6 +134,7 @@ def main():
|
|||
|
||||
if not HAS_REQUESTS:
|
||||
module.fail_json(msg="requests library is required for this module. To install, use `pip install requests`")
|
||||
result = dict(changed=False, name=module.params['name'])
|
||||
|
||||
if module.params['destination_type'] == "queue":
|
||||
dest_type = "q"
|
||||
|
@ -145,9 +146,9 @@ def main():
|
|||
else:
|
||||
props = urllib_parse.quote(module.params['routing_key'], '')
|
||||
|
||||
url = "http://%s:%s/api/bindings/%s/e/%s/%s/%s/%s" % (
|
||||
module.params['login_host'],
|
||||
module.params['login_port'],
|
||||
base_url = "http://%s:%s/api/bindings" % (module.params['login_host'], module.params['login_port'])
|
||||
|
||||
url = "%s/%s/e/%s/%s/%s/%s" % (base_url,
|
||||
urllib_parse.quote(module.params['vhost'], ''),
|
||||
urllib_parse.quote(module.params['name'], ''),
|
||||
dest_type,
|
||||
|
@ -177,19 +178,16 @@ def main():
|
|||
|
||||
# Exit if check_mode
|
||||
if module.check_mode:
|
||||
module.exit_json(
|
||||
changed= change_required,
|
||||
name = module.params['name'],
|
||||
details = response,
|
||||
arguments = module.params['arguments']
|
||||
)
|
||||
result['changed'] = change_required
|
||||
result['details'] = response
|
||||
result['arguments'] = module.params['arguments']
|
||||
module.exit_json(**result)
|
||||
|
||||
# Do changes
|
||||
if change_required:
|
||||
if module.params['state'] == 'present':
|
||||
url = "http://%s:%s/api/bindings/%s/e/%s/%s/%s" % (
|
||||
module.params['login_host'],
|
||||
module.params['login_port'],
|
||||
url = "%s/%s/e/%s/%s/%s" % (
|
||||
base_url,
|
||||
urllib_parse.quote(module.params['vhost'], ''),
|
||||
urllib_parse.quote(module.params['name'], ''),
|
||||
dest_type,
|
||||
|
@ -209,11 +207,9 @@ def main():
|
|||
r = requests.delete(url, auth=(module.params['login_user'], module.params['login_password']))
|
||||
|
||||
if r.status_code == 204 or r.status_code == 201:
|
||||
module.exit_json(
|
||||
changed = True,
|
||||
name = module.params['name'],
|
||||
destination = module.params['destination']
|
||||
)
|
||||
result['changed'] = True
|
||||
result['destination'] = module.params['destination']
|
||||
module.exit_json(**result)
|
||||
else:
|
||||
module.fail_json(
|
||||
msg="Error creating exchange",
|
||||
|
@ -222,11 +218,8 @@ def main():
|
|||
)
|
||||
|
||||
else:
|
||||
module.exit_json(
|
||||
changed = False,
|
||||
name = module.params['name']
|
||||
)
|
||||
|
||||
result['changed'] = False
|
||||
module.exit_json(**result)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -135,6 +135,8 @@ def main():
|
|||
supports_check_mode=True
|
||||
)
|
||||
|
||||
result = dict(changed=False, name=module.params['name'])
|
||||
|
||||
url = "http://%s:%s/api/exchanges/%s/%s" % (
|
||||
module.params['login_host'],
|
||||
module.params['login_port'],
|
||||
|
@ -179,12 +181,10 @@ def main():
|
|||
|
||||
# Exit if check_mode
|
||||
if module.check_mode:
|
||||
module.exit_json(
|
||||
changed= change_required,
|
||||
name = module.params['name'],
|
||||
details = response,
|
||||
arguments = module.params['arguments']
|
||||
)
|
||||
result['changed'] = change_required
|
||||
result['details'] = response
|
||||
result['arguments'] = module.params['arguments']
|
||||
module.exit_json(**result)
|
||||
|
||||
# Do changes
|
||||
if change_required:
|
||||
|
@ -206,10 +206,8 @@ def main():
|
|||
|
||||
# RabbitMQ 3.6.7 changed this response code from 204 to 201
|
||||
if r.status_code == 204 or r.status_code == 201:
|
||||
module.exit_json(
|
||||
changed = True,
|
||||
name = module.params['name']
|
||||
)
|
||||
result['changed'] = True
|
||||
module.exit_json(**result)
|
||||
else:
|
||||
module.fail_json(
|
||||
msg="Error creating exchange",
|
||||
|
@ -218,11 +216,8 @@ def main():
|
|||
)
|
||||
|
||||
else:
|
||||
module.exit_json(
|
||||
changed = False,
|
||||
name = module.params['name']
|
||||
)
|
||||
|
||||
result['changed'] = False
|
||||
module.exit_json(**result)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -65,7 +65,6 @@ EXAMPLES = """
|
|||
state: present
|
||||
"""
|
||||
import json
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
|
@ -114,6 +113,7 @@ class RabbitMqParameter(object):
|
|||
def has_modifications(self):
|
||||
return self.value != self._value
|
||||
|
||||
|
||||
def main():
|
||||
arg_spec = dict(
|
||||
component=dict(required=True),
|
||||
|
@ -137,23 +137,26 @@ def main():
|
|||
state = module.params['state']
|
||||
node = module.params['node']
|
||||
|
||||
result = dict(changed=False)
|
||||
rabbitmq_parameter = RabbitMqParameter(module, component, name, value, vhost, node)
|
||||
|
||||
changed = False
|
||||
if rabbitmq_parameter.get():
|
||||
if state == 'absent':
|
||||
rabbitmq_parameter.delete()
|
||||
changed = True
|
||||
result['changed'] = True
|
||||
else:
|
||||
if rabbitmq_parameter.has_modifications():
|
||||
rabbitmq_parameter.set()
|
||||
changed = True
|
||||
result['changed'] = True
|
||||
elif state == 'present':
|
||||
rabbitmq_parameter.set()
|
||||
changed = True
|
||||
|
||||
module.exit_json(changed=changed, component=component, name=name, vhost=vhost, state=state)
|
||||
result['changed'] = True
|
||||
|
||||
result['component'] = component
|
||||
result['name'] = name
|
||||
result['vhost'] = vhost
|
||||
result['state'] = state
|
||||
module.exit_json(**result)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -57,11 +57,14 @@ EXAMPLES = '''
|
|||
'''
|
||||
|
||||
import os
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
class RabbitMqPlugins(object):
|
||||
|
||||
def __init__(self, module):
|
||||
self.module = module
|
||||
|
||||
|
@ -116,6 +119,7 @@ def main():
|
|||
supports_check_mode=True
|
||||
)
|
||||
|
||||
result = dict()
|
||||
names = module.params['names'].split(',')
|
||||
new_only = module.params['new_only']
|
||||
state = module.params['state']
|
||||
|
@ -142,8 +146,10 @@ def main():
|
|||
rabbitmq_plugins.disable(plugin)
|
||||
disabled.append(plugin)
|
||||
|
||||
changed = len(enabled) > 0 or len(disabled) > 0
|
||||
module.exit_json(changed=changed, enabled=enabled, disabled=disabled)
|
||||
result['changed'] = len(enabled) > 0 or len(disabled) > 0
|
||||
result['enabled'] = enabled
|
||||
result['disabled'] = disabled
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -82,10 +82,13 @@ EXAMPLES = '''
|
|||
tags:
|
||||
ha-mode: all
|
||||
'''
|
||||
|
||||
import json
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
class RabbitMqPolicy(object):
|
||||
|
||||
def __init__(self, module, name):
|
||||
self._module = module
|
||||
self._name = name
|
||||
|
@ -116,14 +119,13 @@ class RabbitMqPolicy(object):
|
|||
return False
|
||||
|
||||
def set(self):
|
||||
import json
|
||||
args = ['set_policy']
|
||||
args.append(self._name)
|
||||
args.append(self._pattern)
|
||||
args.append(json.dumps(self._tags))
|
||||
args.append('--priority')
|
||||
args.append(self._priority)
|
||||
if (self._apply_to != 'all'):
|
||||
if self._apply_to != 'all':
|
||||
args.append('--apply-to')
|
||||
args.append(self._apply_to)
|
||||
return self._exec(args)
|
||||
|
@ -153,19 +155,18 @@ def main():
|
|||
state = module.params['state']
|
||||
rabbitmq_policy = RabbitMqPolicy(module, name)
|
||||
|
||||
changed = False
|
||||
result = dict(changed=False, name=name, state=state)
|
||||
if rabbitmq_policy.list():
|
||||
if state == 'absent':
|
||||
rabbitmq_policy.clear()
|
||||
changed = True
|
||||
result['changed'] = True
|
||||
else:
|
||||
changed = False
|
||||
result['changed'] = False
|
||||
elif state == 'present':
|
||||
rabbitmq_policy.set()
|
||||
changed = True
|
||||
|
||||
module.exit_json(changed=changed, name=name, state=state)
|
||||
result['changed'] = True
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -163,6 +163,8 @@ def main():
|
|||
if not HAS_REQUESTS:
|
||||
module.fail_json(msg="requests library is required for this module. To install, use `pip install requests`")
|
||||
|
||||
result = dict(changed=False, name=module.params['name'])
|
||||
|
||||
# Check if queue already exists
|
||||
r = requests.get(url, auth=(module.params['login_user'], module.params['login_password']))
|
||||
|
||||
|
@ -215,7 +217,6 @@ def main():
|
|||
msg="RabbitMQ RESTAPI doesn't support attribute changes for existing queues",
|
||||
)
|
||||
|
||||
|
||||
# Copy parameters to arguments as used by RabbitMQ
|
||||
for k, v in {
|
||||
'message_ttl': 'x-message-ttl',
|
||||
|
@ -229,12 +230,10 @@ def main():
|
|||
|
||||
# Exit if check_mode
|
||||
if module.check_mode:
|
||||
module.exit_json(
|
||||
changed= change_required,
|
||||
name = module.params['name'],
|
||||
details = response,
|
||||
arguments = module.params['arguments']
|
||||
)
|
||||
result['changed'] = change_required
|
||||
result['details'] = response
|
||||
result['arguments'] = module.params['arguments']
|
||||
module.exit_json(**result)
|
||||
|
||||
# Do changes
|
||||
if change_required:
|
||||
|
@ -254,10 +253,8 @@ def main():
|
|||
|
||||
# RabbitMQ 3.6.7 changed this response code from 204 to 201
|
||||
if r.status_code == 204 or r.status_code == 201:
|
||||
module.exit_json(
|
||||
changed = True,
|
||||
name = module.params['name']
|
||||
)
|
||||
result['changed'] = True
|
||||
module.exit_json(**result)
|
||||
else:
|
||||
module.fail_json(
|
||||
msg="Error creating queue",
|
||||
|
@ -266,11 +263,8 @@ def main():
|
|||
)
|
||||
|
||||
else:
|
||||
module.exit_json(
|
||||
changed = False,
|
||||
name = module.params['name']
|
||||
)
|
||||
|
||||
result['changed'] = False
|
||||
module.exit_json(**result)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -229,6 +229,7 @@ class RabbitMqUser(object):
|
|||
def has_permissions_modifications(self):
|
||||
return sorted(self._permissions) != sorted(self.permissions)
|
||||
|
||||
|
||||
def main():
|
||||
arg_spec = dict(
|
||||
user=dict(required=True, aliases=['username', 'name']),
|
||||
|
@ -261,7 +262,7 @@ def main():
|
|||
node = module.params['node']
|
||||
|
||||
bulk_permissions = True
|
||||
if permissions == []:
|
||||
if not permissions:
|
||||
perm = {
|
||||
'vhost': vhost,
|
||||
'configure_priv': configure_priv,
|
||||
|
@ -274,33 +275,33 @@ def main():
|
|||
rabbitmq_user = RabbitMqUser(module, username, password, tags, permissions,
|
||||
node, bulk_permissions=bulk_permissions)
|
||||
|
||||
changed = False
|
||||
result = dict(changed=False, user=username, state=state)
|
||||
|
||||
if rabbitmq_user.get():
|
||||
if state == 'absent':
|
||||
rabbitmq_user.delete()
|
||||
changed = True
|
||||
result['changed'] = True
|
||||
else:
|
||||
if force:
|
||||
rabbitmq_user.delete()
|
||||
rabbitmq_user.add()
|
||||
rabbitmq_user.get()
|
||||
changed = True
|
||||
result['changed'] = True
|
||||
|
||||
if rabbitmq_user.has_tags_modifications():
|
||||
rabbitmq_user.set_tags()
|
||||
changed = True
|
||||
result['changed'] = True
|
||||
|
||||
if rabbitmq_user.has_permissions_modifications():
|
||||
rabbitmq_user.set_permissions()
|
||||
changed = True
|
||||
result['changed'] = True
|
||||
elif state == 'present':
|
||||
rabbitmq_user.add()
|
||||
rabbitmq_user.set_tags()
|
||||
rabbitmq_user.set_permissions()
|
||||
changed = True
|
||||
|
||||
module.exit_json(changed=changed, user=username, state=state)
|
||||
result['changed'] = True
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -123,24 +123,22 @@ def main():
|
|||
tracing = module.params['tracing']
|
||||
state = module.params['state']
|
||||
node = module.params['node']
|
||||
|
||||
result = dict(changed=False, name=name, state=state)
|
||||
rabbitmq_vhost = RabbitMqVhost(module, name, tracing, node)
|
||||
|
||||
changed = False
|
||||
if rabbitmq_vhost.get():
|
||||
if state == 'absent':
|
||||
rabbitmq_vhost.delete()
|
||||
changed = True
|
||||
result['changed'] = True
|
||||
else:
|
||||
if rabbitmq_vhost.set_tracing():
|
||||
changed = True
|
||||
result['changed'] = True
|
||||
elif state == 'present':
|
||||
rabbitmq_vhost.add()
|
||||
rabbitmq_vhost.set_tracing()
|
||||
changed = True
|
||||
|
||||
module.exit_json(changed=changed, name=name, state=state)
|
||||
result['changed'] = True
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -216,12 +216,6 @@ lib/ansible/modules/files/replace.py
|
|||
lib/ansible/modules/files/synchronize.py
|
||||
lib/ansible/modules/files/tempfile.py
|
||||
lib/ansible/modules/files/xattr.py
|
||||
lib/ansible/modules/messaging/rabbitmq_binding.py
|
||||
lib/ansible/modules/messaging/rabbitmq_exchange.py
|
||||
lib/ansible/modules/messaging/rabbitmq_parameter.py
|
||||
lib/ansible/modules/messaging/rabbitmq_plugin.py
|
||||
lib/ansible/modules/messaging/rabbitmq_queue.py
|
||||
lib/ansible/modules/messaging/rabbitmq_user.py
|
||||
lib/ansible/modules/monitoring/airbrake_deployment.py
|
||||
lib/ansible/modules/monitoring/bigpanda.py
|
||||
lib/ansible/modules/monitoring/boundary_meter.py
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue