Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RabbitMQ: Add parameter types #53328

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
118 changes: 64 additions & 54 deletions lib/ansible/modules/messaging/rabbitmq/rabbitmq_binding.py
Expand Up @@ -13,63 +13,73 @@
'supported_by': 'community'
}

DOCUMENTATION = '''
DOCUMENTATION = r'''
---
module: rabbitmq_binding
author: Manuel Sousa (@manuel-sousa)
author:
- Manuel Sousa (@manuel-sousa)
version_added: "2.0"

short_description: Manage rabbitMQ bindings
short_description: Manage RabbitMQ bindings
description:
- This module uses rabbitMQ REST APIs to create / delete bindings.
requirements: [ "requests >= 1.0.0" ]
- This module uses RabbitMQ REST APIs to create / delete bindings.
requirements:
- requests >= 1.0.0
options:
state:
description:
- Whether the bindings should be present or absent.
choices: [ "present", "absent" ]
default: present
name:
description:
- source exchange to create binding on.
required: true
aliases: [ "src", "source" ]
destination:
description:
- destination exchange or queue for the binding.
required: true
aliases: [ "dst", "dest" ]
destination_type:
description:
- Either queue or exchange.
required: true
choices: [ "queue", "exchange" ]
aliases: [ "type", "dest_type" ]
routing_key:
description:
- routing key for the binding.
default: "#"
arguments:
description:
- extra arguments for exchange. If defined this argument is a key/value dictionary
required: false
default: {}
state:
description:
- Whether the bindings should be present or absent.
type: str
choices: [ absent, present ]
default: present
name:
description:
- Source exchange to create binding on.
type: str
required: true
aliases: [ source, src ]
destination:
description:
- Destination exchange or queue for the binding.
type: str
required: true
aliases: [ dest, dst ]
destination_type:
description:
- Either queue or exchange.
type: str
required: true
choices: [ exchange, queue ]
aliases: [ dest_type, type ]
routing_key:
description:
- Routing key for the binding.
type: str
default: "#"
arguments:
description:
- Extra arguments for exchange.
- If defined this argument is a key/value dictionary
type: dict
default: {}
extends_documentation_fragment:
- rabbitmq
- rabbitmq
seealso:
- module: rabbitmq_exchange
- module: rabbitmq_queue
'''

EXAMPLES = '''
# Bind myQueue to directExchange with routing key info
- rabbitmq_binding:
EXAMPLES = r'''
- name: Bind myQueue to directExchange with routing key 'info'
rabbitmq_binding:
name: directExchange
destination: myQueue
type: queue
routing_key: info

# Bind directExchange to topicExchange with routing key *.info
- rabbitmq_binding:
- name: Bind directExchange to topicExchange with routing key '*.info'
rabbitmq_binding:
name: topicExchange
destination: topicExchange
destination: directExchange
type: exchange
routing_key: '*.info'
'''
Expand All @@ -85,9 +95,9 @@
REQUESTS_IMP_ERR = traceback.format_exc()
HAS_REQUESTS = False

from ansible.module_utils.six.moves.urllib import parse as urllib_parse
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
from ansible.module_utils.rabbitmq import rabbitmq_argument_spec
from ansible.module_utils.six.moves.urllib import parse as urllib_parse


class RabbitMqBinding(object):
Expand Down Expand Up @@ -275,17 +285,17 @@ def main():

argument_spec = rabbitmq_argument_spec()
argument_spec.update(
dict(
state=dict(default='present', choices=['present', 'absent'], type='str'),
name=dict(required=True, aliases=["src", "source"], type='str'),
destination=dict(required=True, aliases=["dst", "dest"], type='str'),
destination_type=dict(required=True, aliases=["type", "dest_type"], choices=["queue", "exchange"],
type='str'),
routing_key=dict(default='#', type='str'),
arguments=dict(default=dict(), type='dict')
)
state=dict(type='str', default='present', choices=['absent', 'present']),
name=dict(type='str', required=True, aliases=['source', 'src']),
destination=dict(type='str', required=True, aliases=['dest', 'dst']),
destination_type=dict(type='str', required=True, choices=['exchange', 'queue'], aliases=['dest_type', 'type']),
routing_key=dict(type='str', default='#'),
arguments=dict(type='dict', default=dict()),
)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
)
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)

if not HAS_REQUESTS:
module.fail_json(msg=missing_required_lib("requests"), exception=REQUESTS_IMP_ERR)
Expand Down
131 changes: 66 additions & 65 deletions lib/ansible/modules/messaging/rabbitmq/rabbitmq_exchange.py
Expand Up @@ -7,74 +7,74 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type


ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}


DOCUMENTATION = '''
DOCUMENTATION = r'''
---
module: rabbitmq_exchange
author: Manuel Sousa (@manuel-sousa)
author:
- Manuel Sousa (@manuel-sousa)
version_added: "2.0"

short_description: Manage rabbitMQ exchanges
short_description: Manage RabbitMQ exchanges
description:
- This module uses rabbitMQ Rest API to create/delete exchanges
requirements: [ "requests >= 1.0.0" ]
- This module uses RabbitMQ Rest API to create/delete exchanges
requirements:
- requests >= 1.0.0
options:
name:
description:
- Name of the exchange to create
required: true
state:
description:
- Whether the exchange should be present or absent
choices: [ "present", "absent" ]
required: false
default: present
durable:
description:
- whether exchange is durable or not
required: false
type: bool
default: yes
exchange_type:
description:
- type for the exchange
required: false
choices: [ "fanout", "direct", "headers", "topic" ]
aliases: [ "type" ]
default: direct
auto_delete:
description:
- if the exchange should delete itself after all queues/exchanges unbound from it
required: false
type: bool
default: no
internal:
description:
- exchange is available only for other exchanges
required: false
type: bool
default: no
arguments:
description:
- extra arguments for exchange. If defined this argument is a key/value dictionary
required: false
default: {}
name:
description:
- Name of the exchange to create.
required: true
state:
description:
- Whether the exchange should be present or absent.
type: str
choices: [ absent, present ]
default: present
durable:
description:
- Whether exchange is durable or not.
type: bool
default: yes
exchange_type:
description:
- Type for the exchange.
type: str
choices: [ direct, fanout, headers, topic ]
default: direct
aliases: [ type ]
auto_delete:
description:
- Whether the exchange should delete itself after all queues/exchanges unbound from it.
type: bool
default: no
internal:
description:
- hether the exchange is available only for other exchanges.
dagwieers marked this conversation as resolved.
Show resolved Hide resolved
type: bool
default: no
arguments:
description:
- Extra arguments for exchange.
- If defined this argument is a key/value dictionary.
type: dict
default: {}
extends_documentation_fragment:
- rabbitmq
- rabbitmq
seealso:
- module: rabbitmq_binding
- module: rabbitmq_queue
'''

EXAMPLES = '''
# Create direct exchange
- rabbitmq_exchange:
EXAMPLES = r'''
- name: Create direct exchange
rabbitmq_exchange:
name: directExchange

# Create topic exchange on vhost
- rabbitmq_exchange:
- name: Create topic exchange on vhost
rabbitmq_exchange:
name: topicExchange
type: topic
vhost: myVhost
Expand All @@ -92,25 +92,26 @@
HAS_REQUESTS = False

from ansible.module_utils.basic import AnsibleModule, missing_required_lib
from ansible.module_utils.six.moves.urllib import parse as urllib_parse
from ansible.module_utils.rabbitmq import rabbitmq_argument_spec
from ansible.module_utils.six.moves.urllib import parse as urllib_parse


def main():

argument_spec = rabbitmq_argument_spec()
argument_spec.update(
dict(
state=dict(default='present', choices=['present', 'absent'], type='str'),
name=dict(required=True, type='str'),
durable=dict(default=True, type='bool'),
auto_delete=dict(default=False, type='bool'),
internal=dict(default=False, type='bool'),
exchange_type=dict(default='direct', aliases=['type'], type='str'),
arguments=dict(default=dict(), type='dict')
)
state=dict(type='str', default='present', choices=['absent', 'present']),
name=dict(type='str', required=True),
durable=dict(type='bool', default=True),
auto_delete=dict(type='bool', default=False),
internal=dict(type='bool', default=False),
exchange_type=dict(type='str', default='direct', choices=['direct', 'fanout', 'headers', 'topic'], aliases=['type']),
arguments=dict(type='dict', default=dict()),
)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
)
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)

url = "%s://%s:%s/api/exchanges/%s/%s" % (
module.params['login_protocol'],
Expand Down