Skip to content

Commit

Permalink
Merge pull request solace-iot-team#44 from pjgunadi/main
Browse files Browse the repository at this point in the history
Added replicated topic module
  • Loading branch information
ricardojosegomezulmke authored Nov 23, 2022
2 parents 304ee47 + 2290afb commit 8c6c5e8
Show file tree
Hide file tree
Showing 11 changed files with 736 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Module Reference
modules/solace_queue*
modules/solace_rdp*
modules/solace_replay*
modules/solace_replicated_topic*
modules/solace_service_*
modules/solace_topic_endpoint*
modules/solace_vpn
3 changes: 3 additions & 0 deletions src/ansible_collections/solace/pubsub_plus/plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
├── solace_get_rdp_rest_consumers.py
├── solace_get_rdps.py
├── solace_get_replay_logs.py
├── solace_get_replicated_topics.py
├── solace_get_topic_endpoints.py
├── solace_get_vpn_clients.py
├── solace_get_vpns.py
Expand All @@ -77,6 +78,8 @@
├── solace_rdp_rest_consumer_trusted_cn.py
├── solace_replay_log.py
├── solace_replay_log_trim_logged_msgs.py
├── solace_replicated_topic.py
├── solace_replicated_topics.py
├── solace_topic_endpoint.py
└── solace_vpn.py
```
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (c) 2022, Solace Corporation, Paulus Gunadi, <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

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

DOCUMENTATION = '''
---
module: solace_get_vpn_replicated_topics
short_description: get list of vpn replicated topics
description:
- "Get a list of VPN Replicated Topics objects."
notes:
- "Module Sempv2 Monitor: https://docs.solace.com/API-Developer-Online-Ref-Documentation/swagger-ui/monitor/index.html#/replicatedTopic"
extends_documentation_fragment:
- solace.pubsub_plus.solace.broker
- solace.pubsub_plus.solace.vpn
- solace.pubsub_plus.solace.get_list_monitor
seealso:
- module: solace_replicated_topic
- module: solace_replicated_topics
author:
- Paulus Gunadi (@pjgunadi)
'''

EXAMPLES = '''
hosts: all
gather_facts: no
any_errors_fatal: true
collections:
- solace.pubsub_plus
module_defaults:
solace_get_replicated_topics:
host: "{{ sempv2_host }}"
port: "{{ sempv2_port }}"
secure_connection: "{{ sempv2_is_secure_connection }}"
username: "{{ sempv2_username }}"
password: "{{ sempv2_password }}"
timeout: "{{ sempv2_timeout }}"
msg_vpn: "{{ vpn }}"
tasks:
- name: get list monitor
solace_get_replicated_topics:
register: result
- name: print result
debug:
msg:
- "{{ result.result_list }}"
- "{{ result.result_list_count }}"
'''

RETURN = '''
result_list:
description: The list of objects found containing requested fields. Payload depends on API called.
returned: success
type: list
elements: dict
result_list_count:
description: Number of items in result_list.
returned: success
type: int
rc:
description: Return code. rc=0 on success, rc=1 on error.
type: int
returned: always
sample:
success:
rc: 0
error:
rc: 1
msg:
description: The response from the HTTP call in case of error.
type: dict
returned: error
'''

from ansible_collections.solace.pubsub_plus.plugins.module_utils import solace_sys
from ansible_collections.solace.pubsub_plus.plugins.module_utils.solace_task import SolaceBrokerGetPagingTask
from ansible_collections.solace.pubsub_plus.plugins.module_utils.solace_task_config import SolaceTaskBrokerConfig
from ansible.module_utils.basic import AnsibleModule


class SolaceGetReplicatedTopicsTask(SolaceBrokerGetPagingTask):

def __init__(self, module):
super().__init__(module)

def get_path_array(self, params: dict) -> list:
# GET /msgVpns/{msgVpnName}/replicatedTopics
return ['msgVpns', params['msg_vpn'], 'replicatedTopics']


def run_module():
module_args = {}
arg_spec = SolaceTaskBrokerConfig.arg_spec_broker_config()
arg_spec.update(SolaceTaskBrokerConfig.arg_spec_vpn())
arg_spec.update(SolaceTaskBrokerConfig.arg_spec_get_object_list_monitor())
arg_spec.update(module_args)

module = AnsibleModule(
argument_spec=arg_spec,
supports_check_mode=False
)
solace_task = SolaceGetReplicatedTopicsTask(module)
solace_task.execute()


def main():
run_module()


if __name__ == '__main__':
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (c) 2022, Solace Corporation, Paulus Gunadi, <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

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

DOCUMENTATION = '''
---
module: solace_replicated_topic
short_description: replicated topic on a MessageVpn's replication
description:
- "Configure a replicatedTopic object on a MessageVpn. Allows addition, removal and configuration of replicatedTopic objects on a MessageVpn."
notes:
- "Module Sempv2 Config: https://docs.solace.com/API-Developer-Online-Ref-Documentation/swagger-ui/config/index.html#/replicatedTopic"
options:
name:
description: The replicated topic. Maps to 'replicatedTopic' in the API.
required: true
type: str
aliases: [topic, replicated_topic]
extends_documentation_fragment:
- solace.pubsub_plus.solace.broker
- solace.pubsub_plus.solace.vpn
- solace.pubsub_plus.solace.sempv2_settings
- solace.pubsub_plus.solace.state
seealso:
- module: solace_get_replicated_topics
- module: solace_replicated_topics
author:
- Paulus Gunadi (@pjgunadi)
'''

EXAMPLES = '''
hosts: all
gather_facts: no
any_errors_fatal: true
collections:
- solace.pubsub_plus
module_defaults:
solace_replicated_topic:
host: "{{ sempv2_host }}"
port: "{{ sempv2_port }}"
secure_connection: "{{ sempv2_is_secure_connection }}"
username: "{{ sempv2_username }}"
password: "{{ sempv2_password }}"
timeout: "{{ sempv2_timeout }}"
msg_vpn: "{{ vpn }}"
tasks:
- name: add vpn replicated topic
solace_replicated_topic:
topic: "foo/bar"
state: present
- name: remove vpn replicated topic
solace_replicated_topic:
topic: "foo/bar"
state: absent
'''

RETURN = '''
response:
description: The response from the Solace Sempv2 request.
type: dict
returned: success
msg:
description: The response from the HTTP call in case of error.
type: dict
returned: error
rc:
description: Return code. rc=0 on success, rc=1 on error.
type: int
returned: always
sample:
success:
rc: 0
error:
rc: 1
'''

from ansible_collections.solace.pubsub_plus.plugins.module_utils import solace_sys
from ansible_collections.solace.pubsub_plus.plugins.module_utils.solace_utils import SolaceUtils
from ansible_collections.solace.pubsub_plus.plugins.module_utils.solace_task import SolaceBrokerCRUDTask
from ansible_collections.solace.pubsub_plus.plugins.module_utils.solace_api import SolaceSempV2Api
from ansible_collections.solace.pubsub_plus.plugins.module_utils.solace_task_config import SolaceTaskBrokerConfig
from ansible_collections.solace.pubsub_plus.plugins.module_utils.solace_error import SolaceParamsValidationError
from ansible.module_utils.basic import AnsibleModule


class SolaceReplicatedTopicTask(SolaceBrokerCRUDTask):

OBJECT_KEY = 'replicatedTopic'

def __init__(self, module):
super().__init__(module)
self.sempv2_api = SolaceSempV2Api(module)

def validate_params(self):
topic = self.get_module().params['name']
if SolaceUtils.doesStringContainAnyWhitespaces(topic):
raise SolaceParamsValidationError('topic',
topic, "must not contain any whitespace")
return super().validate_params()

def get_args(self):
params = self.get_module().params
return [params['msg_vpn'], params['name']]

def get_func(self, vpn_name, replicated_topic):
# GET /msgVpns/{msgVpnName}/replicatedTopics/{replicatedTopic}
path_array = [SolaceSempV2Api.API_BASE_SEMPV2_CONFIG, 'msgVpns',
vpn_name, 'replicatedTopics', replicated_topic]
return self.sempv2_api.get_object_settings(self.get_config(), path_array)

def create_func(self, vpn_name, replicated_topic, settings=None):
# POST /msgVpns/{msgVpnName}/replicatedTopics
data = {
self.OBJECT_KEY: replicated_topic
}
data.update(settings if settings else {})
path_array = [SolaceSempV2Api.API_BASE_SEMPV2_CONFIG,
'msgVpns', vpn_name, 'replicatedTopics']
return self.sempv2_api.make_post_request(self.get_config(), path_array, data)

def update_func(self, vpn_name, replicated_topic, settings=None, delta_settings=None):
# PATCH /msgVpns/{msgVpnName}/replicatedTopics/{replicatedTopic}
path_array = [SolaceSempV2Api.API_BASE_SEMPV2_CONFIG,
'msgVpns', vpn_name, 'replicatedTopics', replicated_topic]
return self.sempv2_api.make_patch_request(self.get_config(), path_array, settings)

def delete_func(self, vpn_name, replicated_topic):
# DELETE /msgVpns/{msgVpnName}/replicatedTopics/{replicatedTopic}
path_array = [SolaceSempV2Api.API_BASE_SEMPV2_CONFIG, 'msgVpns',
vpn_name, 'replicatedTopics', replicated_topic]
return self.sempv2_api.make_delete_request(self.get_config(), path_array)


def run_module():
module_args = dict(
name=dict(type='str', required=True, aliases=[
'topic', 'replicated_topic'])
)
arg_spec = SolaceTaskBrokerConfig.arg_spec_broker_config()
arg_spec.update(SolaceTaskBrokerConfig.arg_spec_vpn())
arg_spec.update(SolaceTaskBrokerConfig.arg_spec_crud())
arg_spec.update(module_args)

module = AnsibleModule(
argument_spec=arg_spec,
supports_check_mode=False
)

solace_task = SolaceReplicatedTopicTask(module)
solace_task.execute()


def main():
run_module()


if __name__ == '__main__':
main()
Loading

0 comments on commit 8c6c5e8

Please sign in to comment.