diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a0094f6e..67f8e10e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,26 @@ Infoblox.Nios_Modules Release Notes .. contents:: Topics +v1.6.0 +====== + +Release Summary +--------------- + +This release provides plugins for NIOS DTC monitoring and topology + +New Modules +----------- + +- infoblox.nios_modules.nios_dtc_monitor_http - Configure Infoblox NIOS DTC HTTP monitor +- infoblox.nios_modules.nios_dtc_monitor_icmp - Configure Infoblox NIOS DTC ICMP monitor +- infoblox.nios_modules.nios_dtc_monitor_pdp - Configure Infoblox NIOS DTC PDP monitor +- infoblox.nios_modules.nios_dtc_monitor_sip - Configure Infoblox NIOS DTC SIP monitor +- infoblox.nios_modules.nios_dtc_monitor_snmp - Configure Infoblox NIOS DTC SNMP monitor +- infoblox.nios_modules.nios_dtc_monitor_tcp - Configure Infoblox NIOS DTC TCP monitor +- infoblox.nios_modules.nios_dtc_topology - Configure Infoblox NIOS DTC Topology + + v1.5.0 ====== diff --git a/README.md b/README.md index a5b72d0b..bc00c1d6 100644 --- a/README.md +++ b/README.md @@ -29,10 +29,24 @@ Modules - `nios_dtc_lbdn` – Configure Infoblox NIOS DTC LBDN records +- `nios_dtc_monitor_http` – Configure Infoblox NIOS DTC HTTP monitors + +- `nios_dtc_monitor_icmp` – Configure Infoblox NIOS DTC ICMP monitors + +- `nios_dtc_monitor_pdp` – Configure Infoblox NIOS DTC PDP monitors + +- `nios_dtc_monitor_sip` – Configure Infoblox NIOS DTC SIP monitors + +- `nios_dtc_monitor_snmp` – Configure Infoblox NIOS DTC SNMP monitors + +- `nios_dtc_monitor_tcp` – Configure Infoblox NIOS DTC TCP monitors + - `nios_dtc_pool` – Configure Infoblox NIOS DTC pools - `nios_dtc_server` – Configure Infoblox NIOS DTC server records +- `nios_dtc_topology` – Configure Infoblox NIOS DTC topologies + - `nios_fixed_address` – Configure Infoblox NIOS DHCP Fixed Address - `nios_host_record` – Configure Infoblox NIOS host records diff --git a/changelogs/.plugin-cache.yaml b/changelogs/.plugin-cache.yaml index f7b27505..f36ee335 100644 --- a/changelogs/.plugin-cache.yaml +++ b/changelogs/.plugin-cache.yaml @@ -59,6 +59,41 @@ plugins: name: nios_dtc_server namespace: '' version_added: 1.1.0 + nios_dtc_monitor_http: + description: Configure Infoblox NIOS DTC HTTP monitor + name: nios_dtc_monitor_http + namespace: '' + version_added: 1.6.0 + nios_dtc_monitor_tcp: + description: Configure Infoblox NIOS DTC TCP monitor + name: nios_dtc_monitor_tcp + namespace: '' + version_added: 1.6.0 + nios_dtc_monitor_icmp: + description: Configure Infoblox NIOS DTC ICMP monitor + name: nios_dtc_monitor_icmp + namespace: '' + version_added: 1.6.0 + nios_dtc_monitor_pdp: + description: Configure Infoblox NIOS DTC PDP monitor + name: nios_dtc_monitor_pdp + namespace: '' + version_added: 1.6.0 + nios_dtc_monitor_sip: + description: Configure Infoblox NIOS DTC SIP monitor + name: nios_dtc_monitor_sip + namespace: '' + version_added: 1.6.0 + nios_dtc_monitor_snmp: + description: Configure Infoblox NIOS DTC SNMP monitor + name: nios_dtc_monitor_snmp + namespace: '' + version_added: 1.6.0 + nios_dtc_topology: + description: Configure Infoblox NIOS DTC Topology + name: nios_dtc_topology + namespace: '' + version_added: 1.6.0 nios_fixed_address: description: Configure Infoblox NIOS DHCP Fixed Address name: nios_fixed_address diff --git a/changelogs/changelog.yaml b/changelogs/changelog.yaml index ac91562e..3e822d3b 100644 --- a/changelogs/changelog.yaml +++ b/changelogs/changelog.yaml @@ -217,3 +217,29 @@ releases: Updates default WAPI version to `2.9`, Added Grid Master Candidate feature' release_date: '2023-05-11' + 1.6.0: + changes: + release_summary: This release provides plugins for NIOS DTC monitoring + modules: + - description: Configure Infoblox NIOS DTC HTTP monitor + name: nios_dtc_monitor_http + namespace: '' + - description: Configure Infoblox NIOS DTC ICMP monitor + name: nios_dtc_monitor_icmp + namespace: '' + - description: Configure Infoblox NIOS DTC PDP monitor + name: nios_dtc_monitor_pdp + namespace: '' + - description: Configure Infoblox NIOS DTC SIP monitor + name: nios_dtc_monitor_sip + namespace: '' + - description: Configure Infoblox NIOS DTC SNMP monitor + name: nios_dtc_monitor_snpp + namespace: '' + - description: Configure Infoblox NIOS DTC TCP monitor + name: nios_dtc_monitor_tcp + namespace: '' + - description: Configure Infoblox NIOS DTC Topology + name: nios_dtc_topology + namespace: '' + release_date: 'tbd' diff --git a/galaxy.yml b/galaxy.yml index 717fbe6b..043d7d86 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -9,7 +9,7 @@ namespace: infoblox name: nios_modules # The version of the collection. Must be compatible with semantic versioning -version: 1.5.0 +version: 1.6.0 # The path to the Markdown (.md) readme file. This path is relative to the root of the collection readme: README.md diff --git a/playbooks/create_dtc_monitor_http.yaml b/playbooks/create_dtc_monitor_http.yaml new file mode 100644 index 00000000..2d2afc3e --- /dev/null +++ b/playbooks/create_dtc_monitor_http.yaml @@ -0,0 +1,19 @@ +--- + +- hosts: localhost + vars: + nios_provider: + host: 10.36.118.2 + username: cloudadmin + password: admin + + connection: local + tasks: + - name: Create Nios DTC HTTPS monitor Test + infoblox.nios_modules.nios_dtc_monitor_http: + name: https_monitor + port: 443 + secure: true + comment: Created with Ansible + state: present + provider: "{{ nios_provider }}" diff --git a/playbooks/create_dtc_monitor_icmp.yaml b/playbooks/create_dtc_monitor_icmp.yaml new file mode 100644 index 00000000..f792cfa6 --- /dev/null +++ b/playbooks/create_dtc_monitor_icmp.yaml @@ -0,0 +1,17 @@ +--- + +- hosts: localhost + vars: + nios_provider: + host: 10.36.118.2 + username: cloudadmin + password: admin + + connection: local + tasks: + - name: Create Nios DTC ICMP monitor Test + infoblox.nios_modules.nios_dtc_monitor_icmp: + name: icmp_monitor + comment: Created with Ansible + state: present + provider: "{{ nios_provider }}" diff --git a/playbooks/create_dtc_monitor_pdp.yaml b/playbooks/create_dtc_monitor_pdp.yaml new file mode 100644 index 00000000..ea2bc9b9 --- /dev/null +++ b/playbooks/create_dtc_monitor_pdp.yaml @@ -0,0 +1,17 @@ +--- + +- hosts: localhost + vars: + nios_provider: + host: 10.36.118.2 + username: cloudadmin + password: admin + + connection: local + tasks: + - name: Create Nios DTC PDP monitor Test + infoblox.nios_modules.nios_dtc_monitor_pdp: + name: pdp_monitor + comment: Created with Ansible + state: present + provider: "{{ nios_provider }}" diff --git a/playbooks/create_dtc_monitor_sip.yaml b/playbooks/create_dtc_monitor_sip.yaml new file mode 100644 index 00000000..4caa32ea --- /dev/null +++ b/playbooks/create_dtc_monitor_sip.yaml @@ -0,0 +1,17 @@ +--- + +- hosts: localhost + vars: + nios_provider: + host: 10.36.118.2 + username: cloudadmin + password: admin + + connection: local + tasks: + - name: Create Nios DTC SIP monitor Test + infoblox.nios_modules.nios_dtc_monitor_sip: + name: sip_monitor + comment: Created with Ansible + state: present + provider: "{{ nios_provider }}" diff --git a/playbooks/create_dtc_monitor_snmp.yaml b/playbooks/create_dtc_monitor_snmp.yaml new file mode 100644 index 00000000..b8b796ee --- /dev/null +++ b/playbooks/create_dtc_monitor_snmp.yaml @@ -0,0 +1,17 @@ +--- + +- hosts: localhost + vars: + nios_provider: + host: 10.36.118.2 + username: cloudadmin + password: admin + + connection: local + tasks: + - name: Create Nios DTC SNMP monitor Test + infoblox.nios_modules.nios_dtc_monitor_snmp: + name: snmp_monitor + comment: Created with Ansible + state: present + provider: "{{ nios_provider }}" diff --git a/playbooks/create_dtc_monitor_tcp.yaml b/playbooks/create_dtc_monitor_tcp.yaml new file mode 100644 index 00000000..95a824a1 --- /dev/null +++ b/playbooks/create_dtc_monitor_tcp.yaml @@ -0,0 +1,18 @@ +--- + +- hosts: localhost + vars: + nios_provider: + host: 10.36.118.2 + username: cloudadmin + password: admin + + connection: local + tasks: + - name: Create Nios DTC TCP monitor Test + infoblox.nios_modules.nios_dtc_monitor_tcp: + name: tcp_monitor + port: 8080 + comment: Created with Ansible + state: present + provider: "{{ nios_provider }}" diff --git a/playbooks/create_dtc_topology.yml b/playbooks/create_dtc_topology.yml new file mode 100644 index 00000000..01c50bd4 --- /dev/null +++ b/playbooks/create_dtc_topology.yml @@ -0,0 +1,31 @@ +--- +- hosts: localhost + vars: + nios_provider: + host: 10.196.205.10 + username: cloudadmin + password: infoblox + wapi_version: "2.12" + + connection: local + tasks: + - name: Create a DTC Topology + infoblox.nios_modules.nios_dtc_topology: + name: a_topology + rules: + - dest_type: POOL + destination_link: web_pool1 + return_type: REGULAR + sources: + - source_op: IS + source_type: EA0 + source_value: DC1 + - dest_type: POOL + destination_link: web_pool2 + return_type: REGULAR + sources: + - source_op: IS + source_type: EA0 + source_value: DC2 + state: present + provider: "{{ nios_provider }}" diff --git a/playbooks/delete_dtc_monitor_http.yaml b/playbooks/delete_dtc_monitor_http.yaml new file mode 100644 index 00000000..29427ebd --- /dev/null +++ b/playbooks/delete_dtc_monitor_http.yaml @@ -0,0 +1,16 @@ +--- + +- hosts: localhost + vars: + nios_provider: + host: 10.36.118.2 + username: cloudadmin + password: admin + + connection: local + tasks: + - name: Delete Nios DTC HTTPS monitor Test + infoblox.nios_modules.nios_dtc_monitor_http: + name: https_monitor + state: absent + provider: "{{ nios_provider }}" diff --git a/playbooks/delete_dtc_monitor_icmp.yaml b/playbooks/delete_dtc_monitor_icmp.yaml new file mode 100644 index 00000000..eca2975f --- /dev/null +++ b/playbooks/delete_dtc_monitor_icmp.yaml @@ -0,0 +1,16 @@ +--- + +- hosts: localhost + vars: + nios_provider: + host: 10.36.118.2 + username: cloudadmin + password: admin + + connection: local + tasks: + - name: Delete Nios DTC ICMP monitor Test + infoblox.nios_modules.nios_dtc_monitor_icmp: + name: icmp_monitor + state: absent + provider: "{{ nios_provider }}" diff --git a/playbooks/delete_dtc_monitor_pdp.yaml b/playbooks/delete_dtc_monitor_pdp.yaml new file mode 100644 index 00000000..b69fb462 --- /dev/null +++ b/playbooks/delete_dtc_monitor_pdp.yaml @@ -0,0 +1,16 @@ +--- + +- hosts: localhost + vars: + nios_provider: + host: 10.36.118.2 + username: cloudadmin + password: admin + + connection: local + tasks: + - name: Delete Nios DTC PDP monitor Test + infoblox.nios_modules.nios_dtc_monitor_pdp: + name: pdp_monitor + state: absent + provider: "{{ nios_provider }}" diff --git a/playbooks/delete_dtc_monitor_sip.yaml b/playbooks/delete_dtc_monitor_sip.yaml new file mode 100644 index 00000000..10cc49dd --- /dev/null +++ b/playbooks/delete_dtc_monitor_sip.yaml @@ -0,0 +1,16 @@ +--- + +- hosts: localhost + vars: + nios_provider: + host: 10.36.118.2 + username: cloudadmin + password: admin + + connection: local + tasks: + - name: Delete Nios DTC SIP monitor Test + infoblox.nios_modules.nios_dtc_monitor_sip: + name: sip_monitor + state: absent + provider: "{{ nios_provider }}" diff --git a/playbooks/delete_dtc_monitor_snmp.yaml b/playbooks/delete_dtc_monitor_snmp.yaml new file mode 100644 index 00000000..972751a6 --- /dev/null +++ b/playbooks/delete_dtc_monitor_snmp.yaml @@ -0,0 +1,16 @@ +--- + +- hosts: localhost + vars: + nios_provider: + host: 10.36.118.2 + username: cloudadmin + password: admin + + connection: local + tasks: + - name: Delete Nios DTC SNMP monitor Test + infoblox.nios_modules.nios_dtc_monitor_snmp: + name: snmp_monitor + state: absent + provider: "{{ nios_provider }}" diff --git a/playbooks/delete_dtc_monitor_tcp.yaml b/playbooks/delete_dtc_monitor_tcp.yaml new file mode 100644 index 00000000..662df448 --- /dev/null +++ b/playbooks/delete_dtc_monitor_tcp.yaml @@ -0,0 +1,16 @@ +--- + +- hosts: localhost + vars: + nios_provider: + host: 10.36.118.2 + username: cloudadmin + password: admin + + connection: local + tasks: + - name: Delete Nios DTC TCP monitor Test + infoblox.nios_modules.nios_dtc_monitor_tcp: + name: tcp_monitor + state: absent + provider: "{{ nios_provider }}" diff --git a/playbooks/delete_dtc_topology.yml b/playbooks/delete_dtc_topology.yml new file mode 100644 index 00000000..c80fa117 --- /dev/null +++ b/playbooks/delete_dtc_topology.yml @@ -0,0 +1,16 @@ +--- +- hosts: localhost + vars: + nios_provider: + host: 10.196.205.10 + username: cloudadmin + password: infoblox + wapi_version: "2.12" + + connection: local + tasks: + - name: Delete a DTC Topology + nios_dtc_topology: + name: a_topology + state: absent + provider: "{{ nios_provider }}" diff --git a/plugins/module_utils/api.py b/plugins/module_utils/api.py index 51c51257..e1616ad9 100644 --- a/plugins/module_utils/api.py +++ b/plugins/module_utils/api.py @@ -71,6 +71,13 @@ NIOS_DTC_SERVER = 'dtc:server' NIOS_DTC_POOL = 'dtc:pool' NIOS_DTC_LBDN = 'dtc:lbdn' +NIOS_DTC_MONITOR_HTTP = 'dtc:monitor:http' +NIOS_DTC_MONITOR_ICMP = 'dtc:monitor:icmp' +NIOS_DTC_MONITOR_PDP = 'dtc:monitor:pdp' +NIOS_DTC_MONITOR_SIP = 'dtc:monitor:sip' +NIOS_DTC_MONITOR_SNMP = 'dtc:monitor:snmp' +NIOS_DTC_MONITOR_TCP = 'dtc:monitor:tcp' +NIOS_DTC_TOPOLOGY = 'dtc:topology' NIOS_PROVIDER_SPEC = { 'host': dict(fallback=(env_fallback, ['INFOBLOX_HOST'])), diff --git a/plugins/modules/nios_dtc_monitor_http.py b/plugins/modules/nios_dtc_monitor_http.py new file mode 100644 index 00000000..b90e98a0 --- /dev/null +++ b/plugins/modules/nios_dtc_monitor_http.py @@ -0,0 +1,272 @@ +#!/usr/bin/python +# Copyright (c) 2018-2019 Red Hat, Inc. +# Copyright (c) 2020 Infoblox, Inc. +# 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 + +DOCUMENTATION = ''' +--- +module: nios_dtc_monitor_http +author: "Joachim Buyse (@jbisabel)" +version_added: "1.6.0" +short_description: Configure Infoblox NIOS DTC HTTP monitors +description: + - Adds and/or removes instances of DTC HTTP monitor objects from Infoblox NIOS + servers. This module manages C(dtc:monitor:http) objects using the Infoblox + WAPI interface over REST. +requirements: + - infoblox-client +extends_documentation_fragment: infoblox.nios_modules.nios +notes: + - This module supports C(check_mode). +options: + name: + description: + - Configures the display name for this DTC monitor. Values with leading + or trailing white space are not valid for this field. + required: true + type: str + port: + description: + - Configures the port value for HTTP requests. + type: int + default: 80 + ciphers: + description: + - Configures an optional cipher list for the secure HTTP/S connection. + type: str + client_cert: + description: + - Configures an optional client certificate, supplied in a secure HTTP/S + mode if present. + type: str + content_check: + description: + - Configures the content check type + type: str + choices: + - EXTRACT + - MATCH + - NONE + default: NONE + content_check_input: + description: + - Configures the portion of the response to use as input for content check. + type: str + choices: + - ALL + - BODY + - HEADERS + default: ALL + content_check_op: + description: + - Configures the content check success criteria operator. + type: str + choices: + - EQ + - GEQ + - LEQ + - NEQ + content_check_regex: + description: + - Configures the content check regular expression. Values with leading + or trailing white space are not valid for this field. + type: str + content_extract_group: + description: + - Configures the content extraction sub-expression to extract. + type: int + default: 0 + content_extract_type: + description: + - Configures the content extraction expected type for the extracted data. + type: str + choices: + - INTEGER + - STRING + default: STRING + content_extract_value: + description: + - Configures the content extraction value to compare with the extracted + result. Values with leading or trailing white space are not valid for + this field. + type: str + request: + description: + - Configures the HTTP request to send + type: str + default: GET / + result: + description: + - Configures the type of the expected result + type: str + choices: + - ANY + - CODE_IS + - CODE_IS_NOT + default: ANY + result_code: + description: + - Configures the expected return code + type: int + default: 200 + enable_sni: + description: + - Configures whether or not Server Name Indication (SNI) for the HTTPS + monitor is enabled. + type: bool + default: false + secure: + description: + - Configures the security status of the connection. + type: bool + default: false + validate_cert: + description: + - Configures whether the validation of the remote server's certificate is + enabled. + type: bool + default: true + interval: + description: + - Configures the interval for HTTP health check. + type: int + default: 5 + retry_down: + description: + - Configures the value of how many times the server should appear as + down to be treated as dead after it was alive. + type: int + default: 1 + retry_up: + description: + - Configures the value of how many times the server should appear as up + to be treated as alive after it was dead. + type: int + default: 1 + timeout: + description: + - Configures the timeout for HTTP health check in seconds. + type: int + default: 15 + extattrs: + description: + - Allows for the configuration of Extensible Attributes on the + instance of the object. This argument accepts a set of key / value + pairs for configuration. + type: dict + comment: + description: + - Configures a text string comment to be associated with the instance + of this object. The provided text string will be configured on the + object instance. + type: str + state: + description: + - Configures the intended state of the instance of the object on + the NIOS server. When this value is set to C(present), the object + is configured on the device and when this value is set to C(absent) + the value is removed (if necessary) from the device. + default: present + choices: + - present + - absent + type: str +''' + +EXAMPLES = ''' +- name: Configure a DTC HTTPS monitor + infoblox.nios_modules.nios_dtc_monitor_http: + name: https_monitor + port: 443 + secure: true + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Add a comment to an existing DTC HTTPS monitor + infoblox.nios_modules.nios_dtc_monitor_http: + name: https_monitor + comment: this is a test comment + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Remove a DTC HTTPS monitor from the system + infoblox.nios_modules.nios_dtc_monitor_http: + name: https_monitor + state: absent + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local +''' + +RETURN = ''' # ''' + +from ansible.module_utils.basic import AnsibleModule +from ..module_utils.api import WapiModule +from ..module_utils.api import NIOS_DTC_MONITOR_HTTP +from ..module_utils.api import normalize_ib_spec + + +def main(): + ''' Main entry point for module execution + ''' + + ib_spec = dict( + name=dict(required=True, ib_req=True), + + port=dict(type='int', default=80), + ciphers=dict(type='str'), + client_cert=dict(type='str'), + content_check=dict(default='NONE', choices=['EXTRACT', 'MATCH', 'NONE']), + content_check_input=dict(default='ALL', choices=['ALL', 'BODY', 'HEADERS']), + content_check_op=dict(choices=['EQ', 'GEQ', 'LEQ', 'NEQ']), + content_check_regex=dict(type='str'), + content_extract_group=dict(type='int', default=0), + content_extract_type=dict(default='STRING', choices=['INTEGER', 'STRING']), + content_extract_value=dict(type='str'), + request=dict(type='str', default='GET /'), + result=dict(default='ANY', choices=['ANY', 'CODE_IS', 'CODE_IS_NOT']), + result_code=dict(type='int', default=200), + enable_sni=dict(type='bool', default=False), + secure=dict(type='bool', default=False), + validate_cert=dict(type='bool', default=True), + interval=dict(type='int', default=5), + retry_down=dict(type='int', default=1), + retry_up=dict(type='int', default=1), + timeout=dict(type='int', default=15), + + extattrs=dict(type='dict'), + comment=dict(), + ) + + argument_spec = dict( + provider=dict(required=True), + state=dict(default='present', choices=['present', 'absent']) + ) + + argument_spec.update(normalize_ib_spec(ib_spec)) + argument_spec.update(WapiModule.provider_spec) + + module = AnsibleModule(argument_spec=argument_spec, + supports_check_mode=True) + + wapi = WapiModule(module) + result = wapi.run(NIOS_DTC_MONITOR_HTTP, ib_spec) + + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/nios_dtc_monitor_icmp.py b/plugins/modules/nios_dtc_monitor_icmp.py new file mode 100644 index 00000000..e133954e --- /dev/null +++ b/plugins/modules/nios_dtc_monitor_icmp.py @@ -0,0 +1,154 @@ +#!/usr/bin/python +# Copyright (c) 2018-2019 Red Hat, Inc. +# Copyright (c) 2020 Infoblox, Inc. +# 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 + +DOCUMENTATION = ''' +--- +module: nios_dtc_monitor_icmp +author: "Joachim Buyse (@jbisabel)" +version_added: "1.6.0" +short_description: Configure Infoblox NIOS DTC ICMP monitors +description: + - Adds and/or removes instances of DTC ICMP monitor objects from Infoblox NIOS + servers. This module manages C(dtc:monitor:icmp) objects using the Infoblox + WAPI interface over REST. +requirements: + - infoblox-client +extends_documentation_fragment: infoblox.nios_modules.nios +notes: + - This module supports C(check_mode). +options: + name: + description: + - Configures the display name for this DTC monitor. Values with leading + or trailing white space are not valid for this field. + required: true + type: str + interval: + description: + - Configures the interval for ICMP health check. + type: int + default: 5 + retry_down: + description: + - Configures the value of how many times the server should appear as + down to be treated as dead after it was alive. + type: int + default: 1 + retry_up: + description: + - Configures the value of how many times the server should appear as up + to be treated as alive after it was dead. + type: int + default: 1 + timeout: + description: + - Configures the timeout for ICMP health check in seconds. + type: int + default: 15 + extattrs: + description: + - Allows for the configuration of Extensible Attributes on the + instance of the object. This argument accepts a set of key / value + pairs for configuration. + type: dict + comment: + description: + - Configures a text string comment to be associated with the instance + of this object. The provided text string will be configured on the + object instance. + type: str + state: + description: + - Configures the intended state of the instance of the object on + the NIOS server. When this value is set to C(present), the object + is configured on the device and when this value is set to C(absent) + the value is removed (if necessary) from the device. + default: present + choices: + - present + - absent + type: str +''' + +EXAMPLES = ''' +- name: Configure a DTC ICMP monitor + infoblox.nios_modules.nios_dtc_monitor_icmp: + name: icmp_monitor + port: 8080 + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Add a comment to an existing DTC ICMP monitor + infoblox.nios_modules.nios_dtc_monitor_icmp: + name: icmp_monitor + comment: this is a test comment + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Remove a DTC ICMP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_icmp: + name: icmp_monitor + state: absent + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local +''' + +RETURN = ''' # ''' + +from ansible.module_utils.basic import AnsibleModule +from ..module_utils.api import WapiModule +from ..module_utils.api import NIOS_DTC_MONITOR_ICMP +from ..module_utils.api import normalize_ib_spec + + +def main(): + ''' Main entry point for module execution + ''' + + ib_spec = dict( + name=dict(required=True, ib_req=True), + + interval=dict(type='int', default=5), + retry_down=dict(type='int', default=1), + retry_up=dict(type='int', default=1), + timeout=dict(type='int', default=15), + + extattrs=dict(type='dict'), + comment=dict(), + ) + + argument_spec = dict( + provider=dict(required=True), + state=dict(default='present', choices=['present', 'absent']) + ) + + argument_spec.update(normalize_ib_spec(ib_spec)) + argument_spec.update(WapiModule.provider_spec) + + module = AnsibleModule(argument_spec=argument_spec, + supports_check_mode=True) + + wapi = WapiModule(module) + result = wapi.run(NIOS_DTC_MONITOR_ICMP, ib_spec) + + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/nios_dtc_monitor_pdp.py b/plugins/modules/nios_dtc_monitor_pdp.py new file mode 100644 index 00000000..d9cf8e4a --- /dev/null +++ b/plugins/modules/nios_dtc_monitor_pdp.py @@ -0,0 +1,159 @@ +#!/usr/bin/python +# Copyright (c) 2018-2019 Red Hat, Inc. +# Copyright (c) 2020 Infoblox, Inc. +# 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 + +DOCUMENTATION = ''' +--- +module: nios_dtc_monitor_pdp +author: "Joachim Buyse (@jbisabel)" +version_added: "1.6.0" +short_description: Configure Infoblox NIOS DTC PDP monitors +description: + - Adds and/or removes instances of DTC PDP monitor objects from Infoblox NIOS + servers. This module manages C(dtc:monitor:pdp) objects using the Infoblox + WAPI interface over REST. +requirements: + - infoblox-client +extends_documentation_fragment: infoblox.nios_modules.nios +notes: + - This module supports C(check_mode). +options: + name: + description: + - Configures the display name for this DTC monitor. Values with leading + or trailing white space are not valid for this field. + required: true + type: str + port: + description: + - Configures the port value for PDP requests. + type: int + default: 2123 + interval: + description: + - Configures the interval for PDP health check. + type: int + default: 5 + retry_down: + description: + - Configures the value of how many times the server should appear as + down to be treated as dead after it was alive. + type: int + default: 1 + retry_up: + description: + - Configures the value of how many times the server should appear as up + to be treated as alive after it was dead. + type: int + default: 1 + timeout: + description: + - Configures the timeout for PDP health check in seconds. + type: int + default: 15 + extattrs: + description: + - Allows for the configuration of Extensible Attributes on the + instance of the object. This argument accepts a set of key / value + pairs for configuration. + type: dict + comment: + description: + - Configures a text string comment to be associated with the instance + of this object. The provided text string will be configured on the + object instance. + type: str + state: + description: + - Configures the intended state of the instance of the object on + the NIOS server. When this value is set to C(present), the object + is configured on the device and when this value is set to C(absent) + the value is removed (if necessary) from the device. + default: present + choices: + - present + - absent + type: str +''' + +EXAMPLES = ''' +- name: Configure a DTC PDP monitor + infoblox.nios_modules.nios_dtc_monitor_pdp: + name: pdp_monitor + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Add a comment to an existing DTC PDP monitor + infoblox.nios_modules.nios_dtc_monitor_pdp: + name: pdp_monitor + comment: this is a test comment + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Remove a DTC PDP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_pdp: + name: pdp_monitor + state: absent + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local +''' + +RETURN = ''' # ''' + +from ansible.module_utils.basic import AnsibleModule +from ..module_utils.api import WapiModule +from ..module_utils.api import NIOS_DTC_MONITOR_PDP +from ..module_utils.api import normalize_ib_spec + + +def main(): + ''' Main entry point for module execution + ''' + + ib_spec = dict( + name=dict(required=True, ib_req=True), + + port=dict(type='int', default=2123), + interval=dict(type='int', default=5), + retry_down=dict(type='int', default=1), + retry_up=dict(type='int', default=1), + timeout=dict(type='int', default=15), + + extattrs=dict(type='dict'), + comment=dict(), + ) + + argument_spec = dict( + provider=dict(required=True), + state=dict(default='present', choices=['present', 'absent']) + ) + + argument_spec.update(normalize_ib_spec(ib_spec)) + argument_spec.update(WapiModule.provider_spec) + + module = AnsibleModule(argument_spec=argument_spec, + supports_check_mode=True) + + wapi = WapiModule(module) + result = wapi.run(NIOS_DTC_MONITOR_PDP, ib_spec) + + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/nios_dtc_monitor_sip.py b/plugins/modules/nios_dtc_monitor_sip.py new file mode 100644 index 00000000..c1df0985 --- /dev/null +++ b/plugins/modules/nios_dtc_monitor_sip.py @@ -0,0 +1,209 @@ +#!/usr/bin/python +# Copyright (c) 2018-2019 Red Hat, Inc. +# Copyright (c) 2020 Infoblox, Inc. +# 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 + +DOCUMENTATION = ''' +--- +module: nios_dtc_monitor_sip +author: "Joachim Buyse (@jbisabel)" +version_added: "1.6.0" +short_description: Configure Infoblox NIOS DTC SIP monitors +description: + - Adds and/or removes instances of DTC SIP monitor objects from Infoblox NIOS + servers. This module manages C(dtc:monitor:sip) objects using the Infoblox + WAPI interface over REST. +requirements: + - infoblox-client +extends_documentation_fragment: infoblox.nios_modules.nios +notes: + - This module supports C(check_mode). +options: + name: + description: + - Configures the display name for this DTC monitor. Values with leading + or trailing white space are not valid for this field. + required: true + type: str + port: + description: + - Configures the port value for SIP requests. + type: int + default: 5060 + ciphers: + description: + - Configures an optional cipher list for the secure TLS/SIPS connection. + type: str + client_cert: + description: + - Configures an optional client certificate, supplied in TLS or SIPS mode + if present. + type: str + request: + description: + - Configures the SIP request to send + type: str + result: + description: + - Configures the type of the expected result + type: str + choices: + - ANY + - CODE_IS + - CODE_IS_NOT + default: ANY + result_code: + description: + - Configures the expected return code + type: int + default: 200 + transport: + description: + - Configures the transport layer protocol to use for the SIP check + type: str + choices: + - SIPS + - TCP + - TLS + - UDP + default: TCP + validate_cert: + description: + - Configures whether the validation of the remote server's certificate is + enabled. + type: bool + default: true + interval: + description: + - Configures the interval for SIP health check. + type: int + default: 5 + retry_down: + description: + - Configures the value of how many times the server should appear as + down to be treated as dead after it was alive. + type: int + default: 1 + retry_up: + description: + - Configures the value of how many times the server should appear as up + to be treated as alive after it was dead. + type: int + default: 1 + timeout: + description: + - Configures the timeout for SIP health check in seconds. + type: int + default: 15 + extattrs: + description: + - Allows for the configuration of Extensible Attributes on the + instance of the object. This argument accepts a set of key / value + pairs for configuration. + type: dict + comment: + description: + - Configures a text string comment to be associated with the instance + of this object. The provided text string will be configured on the + object instance. + type: str + state: + description: + - Configures the intended state of the instance of the object on + the NIOS server. When this value is set to C(present), the object + is configured on the device and when this value is set to C(absent) + the value is removed (if necessary) from the device. + default: present + choices: + - present + - absent + type: str +''' + +EXAMPLES = ''' +- name: Configure a DTC SIP monitor + infoblox.nios_modules.nios_dtc_monitor_sip: + name: sip_monitor + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Add a comment to an existing DTC SIP monitor + infoblox.nios_modules.nios_dtc_monitor_sip: + name: sip_monitor + comment: this is a test comment + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Remove a DTC SIP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_sip: + name: sip_monitor + state: absent + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local +''' + +RETURN = ''' # ''' + +from ansible.module_utils.basic import AnsibleModule +from ..module_utils.api import WapiModule +from ..module_utils.api import NIOS_DTC_MONITOR_SIP +from ..module_utils.api import normalize_ib_spec + + +def main(): + ''' Main entry point for module execution + ''' + + ib_spec = dict( + name=dict(required=True, ib_req=True), + + port=dict(type='int', default=5060), + ciphers=dict(type='str'), + client_cert=dict(type='str'), + request=dict(type='str'), + result=dict(default='ANY', choices=['ANY', 'CODE_IS', 'CODE_IS_NOT']), + result_code=dict(type='int', default=200), + transport=dict(default='TCP', choices=['SIPS', 'TCP', 'TLS', 'UDP']), + validate_cert=dict(type='bool', default=True), + interval=dict(type='int', default=5), + retry_down=dict(type='int', default=1), + retry_up=dict(type='int', default=1), + timeout=dict(type='int', default=15), + + extattrs=dict(type='dict'), + comment=dict(), + ) + + argument_spec = dict( + provider=dict(required=True), + state=dict(default='present', choices=['present', 'absent']) + ) + + argument_spec.update(normalize_ib_spec(ib_spec)) + argument_spec.update(WapiModule.provider_spec) + + module = AnsibleModule(argument_spec=argument_spec, + supports_check_mode=True) + + wapi = WapiModule(module) + result = wapi.run(NIOS_DTC_MONITOR_SIP, ib_spec) + + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/nios_dtc_monitor_snmp.py b/plugins/modules/nios_dtc_monitor_snmp.py new file mode 100644 index 00000000..036580e8 --- /dev/null +++ b/plugins/modules/nios_dtc_monitor_snmp.py @@ -0,0 +1,279 @@ +#!/usr/bin/python +# Copyright (c) 2018-2019 Red Hat, Inc. +# Copyright (c) 2020 Infoblox, Inc. +# 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 + +DOCUMENTATION = ''' +--- +module: nios_dtc_monitor_snmp +author: "Joachim Buyse (@jbisabel)" +version_added: "1.6.0" +short_description: Configure Infoblox NIOS DTC SNMP monitors +description: + - Adds and/or removes instances of DTC SNMP monitor objects from Infoblox NIOS + servers. This module manages C(dtc:monitor:snmp) objects using the Infoblox + WAPI interface over REST. +requirements: + - infoblox-client +extends_documentation_fragment: infoblox.nios_modules.nios +notes: + - This module supports C(check_mode). +options: + name: + description: + - Configures the display name for this DTC monitor. Values with leading + or trailing white space are not valid for this field. + required: true + type: str + port: + description: + - Configures the port value for SNMP requests. + type: int + default: 161 + version: + description: + - Configures the SNMP protocol version for the SNMP health check. + type: str + choices: + - V1 + - V2C + - V3 + default: V2C + community: + description: + - Configures the SNMP community string for SNMP authentication. + type: str + default: public + user: + description: + - Configures the SNMPv3 user setting. + type: str + context: + description: + - Configures the SNMPv3 context. Values with leading or trailing white + space are not valid for this field. + type: str + engine_id: + description: + - Configures the SNMPv3 engine identifier. Values with leading or + trailing white space are not valid for this field. + type: str + oids: + description: + - Configures the list of OIDs for SNMP monitoring. + type: list + elements: dict + suboptions: + comment: + description: + - Configures a text string comment to be associated with the instance + of this object. The provided text string will be configured on the + object instance. + type: str + condition: + description: + - Configures the condition of the validation result for the SNMP + health check. + type: str + choices: + - ANY + - EXACT + - GEQ + - LEQ + - RANGE + default: ANY + first: + description: + - Configures the condition's first term to match against the SNMP + health check result. + type: str + last: + description: + - Configures the condition's second term to match against the SNMP + health check result with 'RANGE' condition. + type: str + oid: + description: + - Configures the SNMP OID value for DTC SNMP Monitor health checks. + - This field is required on creation + required: true + type: str + type: + description: + - Configures the condition type for DTC SNMP Monitor health checks + results. + type: str + choices: + - INTEGER + - STRING + default: STRING + interval: + description: + - Configures the interval for SNMP health check. + type: int + default: 5 + retry_down: + description: + - Configures the value of how many times the server should appear as + down to be treated as dead after it was alive. + type: int + default: 1 + retry_up: + description: + - Configures the value of how many times the server should appear as up + to be treated as alive after it was dead. + type: int + default: 1 + timeout: + description: + - Configures the timeout for SNMP health check in seconds. + type: int + default: 15 + extattrs: + description: + - Allows for the configuration of Extensible Attributes on the + instance of the object. This argument accepts a set of key / value + pairs for configuration. + type: dict + comment: + description: + - Configures a text string comment to be associated with the instance + of this object. The provided text string will be configured on the + object instance. + type: str + state: + description: + - Configures the intended state of the instance of the object on + the NIOS server. When this value is set to C(present), the object + is configured on the device and when this value is set to C(absent) + the value is removed (if necessary) from the device. + default: present + choices: + - present + - absent + type: str +''' + +EXAMPLES = ''' +- name: Configure a DTC SNMP monitor + infoblox.nios_modules.nios_dtc_monitor_snmp: + name: snmp_monitor + port: 8080 + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Add a comment to an existing DTC SNMP monitor + infoblox.nios_modules.nios_dtc_monitor_snmp: + name: snmp_monitor + comment: this is a test comment + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Remove a DTC SNMP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_snmp: + name: snmp_monitor + state: absent + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local +''' + +RETURN = ''' # ''' + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.six import iteritems +from ..module_utils.api import WapiModule +from ..module_utils.api import NIOS_DTC_MONITOR_SNMP +from ..module_utils.api import normalize_ib_spec + + +def oids(module): + ''' Transform the module argument into a valid WAPI struct + This function will transform the oids argument into a structure that is a + valid WAPI structure in the format of: + { + comment: , + condition: , + first: , + last: , + oid: , + type: , + } + It will remove any options that are set to None since WAPI will error on + that condition. + The remainder of the value validation is performed by WAPI + ''' + + oids = list() + for item in module.params['oids']: + oid = dict([(k, v) for k, v in iteritems(item) if v is not None]) + if 'oid' not in oid: + module.fail_json(msg='oid is required for oid value') + oids.append(oid) + return oids + + +def main(): + ''' Main entry point for module execution + ''' + + oid_spec = dict( + comment=dict(type='str'), + condition=dict(default='ANY', choices=['ANY', 'EXACT', 'GEQ', 'LEQ', 'RANGE']), + first=dict(type='str'), + last=dict(type='str'), + oid=dict(type='str', required=True), + type=dict(default='STRING', choices=['INTEGER', 'STRING']) + ) + + ib_spec = dict( + name=dict(required=True, ib_req=True), + + port=dict(type='int', default=161), + version=dict(default='V2C', choices=['V1', 'V2C', 'V3']), + community=dict(type='str', default='public'), + user=dict(type='str'), + context=dict(type='str'), + engine_id=dict(type='str'), + oids=dict(type='list', elements='dict', options=oid_spec, transform=oids), + interval=dict(type='int', default=5), + retry_down=dict(type='int', default=1), + retry_up=dict(type='int', default=1), + timeout=dict(type='int', default=15), + + extattrs=dict(type='dict'), + comment=dict(), + ) + + argument_spec = dict( + provider=dict(required=True), + state=dict(default='present', choices=['present', 'absent']) + ) + + argument_spec.update(normalize_ib_spec(ib_spec)) + argument_spec.update(WapiModule.provider_spec) + + module = AnsibleModule(argument_spec=argument_spec, + supports_check_mode=True) + + wapi = WapiModule(module) + result = wapi.run(NIOS_DTC_MONITOR_SNMP, ib_spec) + + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/nios_dtc_monitor_tcp.py b/plugins/modules/nios_dtc_monitor_tcp.py new file mode 100644 index 00000000..f06b5cac --- /dev/null +++ b/plugins/modules/nios_dtc_monitor_tcp.py @@ -0,0 +1,160 @@ +#!/usr/bin/python +# Copyright (c) 2018-2019 Red Hat, Inc. +# Copyright (c) 2020 Infoblox, Inc. +# 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 + +DOCUMENTATION = ''' +--- +module: nios_dtc_monitor_tcp +author: "Joachim Buyse (@jbisabel)" +version_added: "1.6.0" +short_description: Configure Infoblox NIOS DTC TCP monitors +description: + - Adds and/or removes instances of DTC TCP monitor objects from Infoblox NIOS + servers. This module manages C(dtc:monitor:tcp) objects using the Infoblox + WAPI interface over REST. +requirements: + - infoblox-client +extends_documentation_fragment: infoblox.nios_modules.nios +notes: + - This module supports C(check_mode). +options: + name: + description: + - Configures the display name for this DTC monitor. Values with leading + or trailing white space are not valid for this field. + required: true + type: str + port: + description: + - Configures the port value for TCP requests. The field is required on + creation. + type: int + interval: + description: + - Configures the interval for TCP health check. + type: int + default: 5 + retry_down: + description: + - Configures the value of how many times the server should appear as + down to be treated as dead after it was alive. + type: int + default: 1 + retry_up: + description: + - Configures the value of how many times the server should appear as up + to be treated as alive after it was dead. + type: int + default: 1 + timeout: + description: + - Configures the timeout for TCP health check in seconds. + type: int + default: 15 + extattrs: + description: + - Allows for the configuration of Extensible Attributes on the + instance of the object. This argument accepts a set of key / value + pairs for configuration. + type: dict + comment: + description: + - Configures a text string comment to be associated with the instance + of this object. The provided text string will be configured on the + object instance. + type: str + state: + description: + - Configures the intended state of the instance of the object on + the NIOS server. When this value is set to C(present), the object + is configured on the device and when this value is set to C(absent) + the value is removed (if necessary) from the device. + default: present + choices: + - present + - absent + type: str +''' + +EXAMPLES = ''' +- name: Configure a DTC TCP monitor + infoblox.nios_modules.nios_dtc_monitor_tcp: + name: tcp_monitor + port: 8080 + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Add a comment to an existing DTC TCP monitor + infoblox.nios_modules.nios_dtc_monitor_tcp: + name: tcp_monitor + comment: this is a test comment + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Remove a DTC TCP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_tcp: + name: tcp_monitor + state: absent + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local +''' + +RETURN = ''' # ''' + +from ansible.module_utils.basic import AnsibleModule +from ..module_utils.api import WapiModule +from ..module_utils.api import NIOS_DTC_MONITOR_TCP +from ..module_utils.api import normalize_ib_spec + + +def main(): + ''' Main entry point for module execution + ''' + + ib_spec = dict( + name=dict(required=True, ib_req=True), + + port=dict(type='int'), + interval=dict(type='int', default=5), + retry_down=dict(type='int', default=1), + retry_up=dict(type='int', default=1), + timeout=dict(type='int', default=15), + + extattrs=dict(type='dict'), + comment=dict(), + ) + + argument_spec = dict( + provider=dict(required=True), + state=dict(default='present', choices=['present', 'absent']) + ) + + argument_spec.update(normalize_ib_spec(ib_spec)) + argument_spec.update(WapiModule.provider_spec) + + module = AnsibleModule(argument_spec=argument_spec, + supports_check_mode=True) + + wapi = WapiModule(module) + result = wapi.run(NIOS_DTC_MONITOR_TCP, ib_spec) + + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/nios_dtc_topology.py b/plugins/modules/nios_dtc_topology.py new file mode 100644 index 00000000..32a21528 --- /dev/null +++ b/plugins/modules/nios_dtc_topology.py @@ -0,0 +1,250 @@ +#!/usr/bin/python +# Copyright (c) 2018-2019 Red Hat, Inc. +# Copyright (c) 2020 Infoblox, Inc. +# 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 + +DOCUMENTATION = ''' +--- +module: nios_dtc_topology +author: "Joachim Buyse (@jbisabel)" +short_description: Configure Infoblox NIOS DTC Topology +version_added: "1.6.0" +description: + - Adds and/or removes instances of DTC Topology objects from + Infoblox NIOS topologies. This module manages NIOS C(dtc:topology) objects + using the Infoblox WAPI interface over REST. +requirements: + - infoblox-client +extends_documentation_fragment: infoblox.nios_modules.nios +notes: + - This module supports C(check_mode). +options: + name: + description: + - Specifies the DTC Topology display name. + required: true + type: str + rules: + description: + - Configures the topology rules + type: list + elements: dict + suboptions: + dest_type: + description: + - Configures the type of the destination for this DTC Topology Rule. + type: str + choices: + - POOL + - SERVER + required: true + destination_link: + description: + - Configures the name of the destination DTC pool or DTC server. + type: str + return_type: + description: + - Configures the type of the DNS response for the rule. + type: str + choices: + - NOERR + - NXDOMAIN + - REGULAR + default: REGULAR + sources: + description: + - Configures the conditions for matching sources. Should be empty to + set the rule as default destination. + type: list + elements: dict + suboptions: + source_op: + description: + - Configures the operation used to match the value. + type: str + choices: + - IS + - IS_NOT + source_type: + description: + - Configures the source type. + type: str + choices: + - CITY + - CONTINENT + - COUNTRY + - EA0 + - EA1 + - EA2 + - EA3 + - SUBDIVISION + - SUBNET + required: true + source_value: + description: + - Configures the source value. + type: str + required: true + extattrs: + description: + - Allows for the configuration of Extensible Attributes on the + instance of the object. This argument accepts a set of key / value + pairs for configuration. + type: dict + comment: + description: + - Configures a text string comment to be associated with the instance + of this object. The provided text string will be configured on the + object instance. + type: str + state: + description: + - Configures the intended state of the instance of the object on + the NIOS topology. When this value is set to C(present), the object + is configured on the device and when this value is set to C(absent) + the value is removed (if necessary) from the device. + default: present + choices: + - present + - absent + type: str +''' + +EXAMPLES = ''' +- name: Configure a DTC Topology + infoblox.nios_modules.nios_dtc_topology: + name: a_topology + rules: + - dest_type: POOL + destination_link: web_pool1 + return_type: REGULAR + sources: + - source_op: IS + source_type: EA0 + source_value: DC1 + - dest_type: POOL + destination_link: web_pool2 + return_type: REGULAR + sources: + - source_op: IS + source_type: EA0 + source_value: DC2 + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Add a comment to a DTC topology + infoblox.nios_modules.nios_dtc_topology: + name: a_topology + comment: this is a test comment + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Remove a DTC Topology from the system + infoblox.nios_modules.nios_dtc_topology: + name: a_topology + state: absent + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local +''' + +RETURN = ''' # ''' + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.six import iteritems +from ..module_utils.api import WapiModule +from ..module_utils.api import NIOS_DTC_TOPOLOGY +from ..module_utils.api import normalize_ib_spec + + +def main(): + ''' Main entry point for module execution + ''' + + def sources_transform(sources, module): + source_list = list() + for source in sources: + src = dict([(k, v) for k, v in iteritems(source) if v is not None]) + if 'source_type' not in src or 'source_value' not in src: + module.fail_json(msg='source_type and source_value are required for source') + source_list.append(src) + return source_list + + def rules_transform(module): + rule_list = list() + if not module.params['rules']: + return rule_list + for rule in module.params['rules']: + if rule['dest_type'] == 'POOL': + dest_obj = wapi.get_object('dtc:pool', {'name': rule['destination_link']}) + else: + dest_obj = wapi.get_object('dtc:server', {'name': rule['destination_link']}) + if not dest_obj: + module.fail_json(msg='destination_link %s does not exist' % rule['destination_link']) + + tf_rule = dict( + dest_type=rule['dest_type'], + destination_link=dest_obj[0]['_ref'], + return_type=rule['return_type'] + ) + + if rule['sources']: + tf_rule['sources'] = sources_transform(rule['sources'], module) + + rule_list.append(tf_rule) + return rule_list + + source_spec = dict( + source_op=dict(choices=['IS', 'IS_NOT']), + source_type=dict(required=True, choices=['CITY', 'CONTINENT', 'COUNTRY', 'EA0', 'EA1', 'EA2', 'EA3', 'SUBDIVISION', 'SUBNET']), + source_value=dict(required=True, type='str') + ) + + rule_spec = dict( + dest_type=dict(required=True, choices=['POOL', 'SERVER']), + destination_link=dict(type='str'), + return_type=dict(default='REGULAR', choices=['NOERR', 'NXDOMAIN', 'REGULAR']), + sources=dict(type='list', elements='dict', options=source_spec) + ) + + ib_spec = dict( + name=dict(required=True, ib_req=True), + + rules=dict(type='list', elements='dict', options=rule_spec, transform=rules_transform), + + extattrs=dict(type='dict'), + comment=dict(), + ) + + argument_spec = dict( + provider=dict(required=True), + state=dict(default='present', choices=['present', 'absent']) + ) + + argument_spec.update(normalize_ib_spec(ib_spec)) + argument_spec.update(WapiModule.provider_spec) + + module = AnsibleModule(argument_spec=argument_spec, + supports_check_mode=True) + + wapi = WapiModule(module) + result = wapi.run(NIOS_DTC_TOPOLOGY, ib_spec) + + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/tests/integration/targets/nios_dtc_monitor_http/aliases b/tests/integration/targets/nios_dtc_monitor_http/aliases new file mode 100644 index 00000000..b3138dc7 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_http/aliases @@ -0,0 +1,3 @@ +shippable/cloud/group1 +cloud/nios +destructive diff --git a/tests/integration/targets/nios_dtc_monitor_http/defaults/main.yaml b/tests/integration/targets/nios_dtc_monitor_http/defaults/main.yaml new file mode 100644 index 00000000..9ef5ba51 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_http/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/tests/integration/targets/nios_dtc_monitor_http/meta/main.yaml b/tests/integration/targets/nios_dtc_monitor_http/meta/main.yaml new file mode 100644 index 00000000..1b01a972 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_http/meta/main.yaml @@ -0,0 +1,2 @@ +dependencies: + - prepare_nios_tests diff --git a/tests/integration/targets/nios_dtc_monitor_http/tasks/main.yaml b/tests/integration/targets/nios_dtc_monitor_http/tasks/main.yaml new file mode 100644 index 00000000..f774bfbf --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_http/tasks/main.yaml @@ -0,0 +1 @@ +- include_tasks: nios_dtc_monitor_http_idempotence.yaml diff --git a/tests/integration/targets/nios_dtc_monitor_http/tasks/nios_dtc_monitor_http_idempotence.yaml b/tests/integration/targets/nios_dtc_monitor_http/tasks/nios_dtc_monitor_http_idempotence.yaml new file mode 100644 index 00000000..8b3a4f40 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_http/tasks/nios_dtc_monitor_http_idempotence.yaml @@ -0,0 +1,75 @@ +- name: Clean up the parent object + infoblox.nios_modules.nios_zone: + name: ansible.com + state: absent + provider: "{{ nios_provider }}" + +- name: Create the parent object + infoblox.nios_modules.nios_zone: + name: ansible.com + state: present + provider: "{{ nios_provider }}" + +- name: Clean up the DTC HTTPS monitor + infoblox.nios_modules.nios_dtc_monitor_http: + name: https_monitor + state: absent + provider: "{{ nios_provider }}" + +- name: Create a DTC HTTPS monitor + infoblox.nios_modules.nios_dtc_monitor_http: + name: https_monitor + port: 443 + secure: true + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_http_create1 + +- name: Recreate a DTC HTTPS monitor + infoblox.nios_modules.nios_dtc_monitor_http: + name: https_monitor + port: 443 + secure: true + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_http_create2 + +- name: Add a comment to an existing DTC HTTPS monitor + infoblox.nios_modules.nios_dtc_monitor_http: + name: https_monitor + comment: this is a test comment + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_http_update1 + +- name: Readd a comment to an existing DTC HTTPS monitor + infoblox.nios_modules.nios_dtc_monitor_http: + name: https_monitor + comment: this is a test comment + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_http_update2 + +- name: Remove a DTC HTTPS monitor from the system + infoblox.nios_modules.nios_dtc_monitor_http: + name: https_monitor + state: absent + provider: "{{ nios_provider }}" + register: dtc_monitor_http_delete1 + +- name: Reremove a DTC HTTPS monitor from the system + infoblox.nios_modules.nios_dtc_monitor_http: + name: https_monitor + state: absent + provider: "{{ nios_provider }}" + register: dtc_monitor_http_delete2 + +- name: Verify outcomes + ansible.builtin.assert: + that: + - "dtc_monitor_http_create1.changed" + - "not dtc_monitor_http_create2.changed" + - "dtc_monitor_http_update1.changed" + - "not dtc_monitor_http_update2.changed" + - "dtc_monitor_http_delete1.changed" + - "not dtc_monitor_http_delete2.changed" diff --git a/tests/integration/targets/nios_dtc_monitor_icmp/aliases b/tests/integration/targets/nios_dtc_monitor_icmp/aliases new file mode 100644 index 00000000..b3138dc7 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_icmp/aliases @@ -0,0 +1,3 @@ +shippable/cloud/group1 +cloud/nios +destructive diff --git a/tests/integration/targets/nios_dtc_monitor_icmp/defaults/main.yaml b/tests/integration/targets/nios_dtc_monitor_icmp/defaults/main.yaml new file mode 100644 index 00000000..9ef5ba51 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_icmp/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/tests/integration/targets/nios_dtc_monitor_icmp/meta/main.yaml b/tests/integration/targets/nios_dtc_monitor_icmp/meta/main.yaml new file mode 100644 index 00000000..1b01a972 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_icmp/meta/main.yaml @@ -0,0 +1,2 @@ +dependencies: + - prepare_nios_tests diff --git a/tests/integration/targets/nios_dtc_monitor_icmp/tasks/main.yaml b/tests/integration/targets/nios_dtc_monitor_icmp/tasks/main.yaml new file mode 100644 index 00000000..28bf85bd --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_icmp/tasks/main.yaml @@ -0,0 +1 @@ +- include_tasks: nios_dtc_monitor_icmp_idempotence.yaml diff --git a/tests/integration/targets/nios_dtc_monitor_icmp/tasks/nios_dtc_monitor_icmp_idempotence.yaml b/tests/integration/targets/nios_dtc_monitor_icmp/tasks/nios_dtc_monitor_icmp_idempotence.yaml new file mode 100644 index 00000000..984aa59a --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_icmp/tasks/nios_dtc_monitor_icmp_idempotence.yaml @@ -0,0 +1,71 @@ +- name: Clean up the parent object + infoblox.nios_modules.nios_zone: + name: ansible.com + state: absent + provider: "{{ nios_provider }}" + +- name: Create the parent object + infoblox.nios_modules.nios_zone: + name: ansible.com + state: present + provider: "{{ nios_provider }}" + +- name: Clean up the DTC ICMP monitor + infoblox.nios_modules.nios_dtc_monitor_icmp: + name: icmp_monitor + state: absent + provider: "{{ nios_provider }}" + +- name: Create a DTC ICMP monitor + infoblox.nios_modules.nios_dtc_monitor_icmp: + name: icmp_monitor + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_icmp_create1 + +- name: Recreate a DTC ICMP monitor + infoblox.nios_modules.nios_dtc_monitor_icmp: + name: icmp_monitor + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_icmp_create2 + +- name: Add a comment to an existing DTC ICMP monitor + infoblox.nios_modules.nios_dtc_monitor_icmp: + name: icmp_monitor + comment: this is a test comment + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_icmp_update1 + +- name: Readd a comment to an existing DTC ICMP monitor + infoblox.nios_modules.nios_dtc_monitor_icmp: + name: icmp_monitor + comment: this is a test comment + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_icmp_update2 + +- name: Remove a DTC ICMP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_icmp: + name: icmp_monitor + state: absent + provider: "{{ nios_provider }}" + register: dtc_monitor_icmp_delete1 + +- name: Reremove a DTC ICMP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_icmp: + name: icmp_monitor + state: absent + provider: "{{ nios_provider }}" + register: dtc_monitor_icmp_delete2 + +- name: Verify outcomes + ansible.builtin.assert: + that: + - "dtc_monitor_icmp_create1.changed" + - "not dtc_monitor_icmp_create2.changed" + - "dtc_monitor_icmp_update1.changed" + - "not dtc_monitor_icmp_update2.changed" + - "dtc_monitor_icmp_delete1.changed" + - "not dtc_monitor_icmp_delete2.changed" diff --git a/tests/integration/targets/nios_dtc_monitor_pdp/aliases b/tests/integration/targets/nios_dtc_monitor_pdp/aliases new file mode 100644 index 00000000..b3138dc7 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_pdp/aliases @@ -0,0 +1,3 @@ +shippable/cloud/group1 +cloud/nios +destructive diff --git a/tests/integration/targets/nios_dtc_monitor_pdp/defaults/main.yaml b/tests/integration/targets/nios_dtc_monitor_pdp/defaults/main.yaml new file mode 100644 index 00000000..9ef5ba51 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_pdp/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/tests/integration/targets/nios_dtc_monitor_pdp/meta/main.yaml b/tests/integration/targets/nios_dtc_monitor_pdp/meta/main.yaml new file mode 100644 index 00000000..1b01a972 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_pdp/meta/main.yaml @@ -0,0 +1,2 @@ +dependencies: + - prepare_nios_tests diff --git a/tests/integration/targets/nios_dtc_monitor_pdp/tasks/main.yaml b/tests/integration/targets/nios_dtc_monitor_pdp/tasks/main.yaml new file mode 100644 index 00000000..55829c8d --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_pdp/tasks/main.yaml @@ -0,0 +1 @@ +- include_tasks: nios_dtc_monitor_pdp_idempotence.yaml diff --git a/tests/integration/targets/nios_dtc_monitor_pdp/tasks/nios_dtc_monitor_pdp_idempotence.yaml b/tests/integration/targets/nios_dtc_monitor_pdp/tasks/nios_dtc_monitor_pdp_idempotence.yaml new file mode 100644 index 00000000..022f12d7 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_pdp/tasks/nios_dtc_monitor_pdp_idempotence.yaml @@ -0,0 +1,71 @@ +- name: Clean up the parent object + infoblox.nios_modules.nios_zone: + name: ansible.com + state: absent + provider: "{{ nios_provider }}" + +- name: Create the parent object + infoblox.nios_modules.nios_zone: + name: ansible.com + state: present + provider: "{{ nios_provider }}" + +- name: Clean up the DTC PDP monitor + infoblox.nios_modules.nios_dtc_monitor_pdp: + name: pdp_monitor + state: absent + provider: "{{ nios_provider }}" + +- name: Create a DTC PDP monitor + infoblox.nios_modules.nios_dtc_monitor_pdp: + name: pdp_monitor + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_pdp_create1 + +- name: Recreate a DTC PDP monitor + infoblox.nios_modules.nios_dtc_monitor_pdp: + name: pdp_monitor + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_pdp_create2 + +- name: Add a comment to an existing DTC PDP monitor + infoblox.nios_modules.nios_dtc_monitor_pdp: + name: pdp_monitor + comment: this is a test comment + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_pdp_update1 + +- name: Readd a comment to an existing DTC PDP monitor + infoblox.nios_modules.nios_dtc_monitor_pdp: + name: pdp_monitor + comment: this is a test comment + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_pdp_update2 + +- name: Remove a DTC PDP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_pdp: + name: pdp_monitor + state: absent + provider: "{{ nios_provider }}" + register: dtc_monitor_pdp_delete1 + +- name: Reremove a DTC PDP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_pdp: + name: pdp_monitor + state: absent + provider: "{{ nios_provider }}" + register: dtc_monitor_pdp_delete2 + +- name: Verify outcomes + ansible.builtin.assert: + that: + - "dtc_monitor_pdp_create1.changed" + - "not dtc_monitor_pdp_create2.changed" + - "dtc_monitor_pdp_update1.changed" + - "not dtc_monitor_pdp_update2.changed" + - "dtc_monitor_pdp_delete1.changed" + - "not dtc_monitor_pdp_delete2.changed" diff --git a/tests/integration/targets/nios_dtc_monitor_sip/aliases b/tests/integration/targets/nios_dtc_monitor_sip/aliases new file mode 100644 index 00000000..b3138dc7 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_sip/aliases @@ -0,0 +1,3 @@ +shippable/cloud/group1 +cloud/nios +destructive diff --git a/tests/integration/targets/nios_dtc_monitor_sip/defaults/main.yaml b/tests/integration/targets/nios_dtc_monitor_sip/defaults/main.yaml new file mode 100644 index 00000000..9ef5ba51 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_sip/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/tests/integration/targets/nios_dtc_monitor_sip/meta/main.yaml b/tests/integration/targets/nios_dtc_monitor_sip/meta/main.yaml new file mode 100644 index 00000000..1b01a972 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_sip/meta/main.yaml @@ -0,0 +1,2 @@ +dependencies: + - prepare_nios_tests diff --git a/tests/integration/targets/nios_dtc_monitor_sip/tasks/main.yaml b/tests/integration/targets/nios_dtc_monitor_sip/tasks/main.yaml new file mode 100644 index 00000000..e5e1b33f --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_sip/tasks/main.yaml @@ -0,0 +1 @@ +- include_tasks: nios_dtc_monitor_sip_idempotence.yaml diff --git a/tests/integration/targets/nios_dtc_monitor_sip/tasks/nios_dtc_monitor_sip_idempotence.yaml b/tests/integration/targets/nios_dtc_monitor_sip/tasks/nios_dtc_monitor_sip_idempotence.yaml new file mode 100644 index 00000000..68187a12 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_sip/tasks/nios_dtc_monitor_sip_idempotence.yaml @@ -0,0 +1,71 @@ +- name: Clean up the parent object + infoblox.nios_modules.nios_zone: + name: ansible.com + state: absent + provider: "{{ nios_provider }}" + +- name: Create the parent object + infoblox.nios_modules.nios_zone: + name: ansible.com + state: present + provider: "{{ nios_provider }}" + +- name: Clean up the DTC SIP monitor + infoblox.nios_modules.nios_dtc_monitor_sip: + name: sip_monitor + state: absent + provider: "{{ nios_provider }}" + +- name: Create a DTC SIP monitor + infoblox.nios_modules.nios_dtc_monitor_sip: + name: sip_monitor + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_sip_create1 + +- name: Recreate a DTC SIP monitor + infoblox.nios_modules.nios_dtc_monitor_sip: + name: sip_monitor + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_sip_create2 + +- name: Add a comment to an existing DTC SIP monitor + infoblox.nios_modules.nios_dtc_monitor_sip: + name: sip_monitor + comment: this is a test comment + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_sip_update1 + +- name: Readd a comment to an existing DTC SIP monitor + infoblox.nios_modules.nios_dtc_monitor_sip: + name: sip_monitor + comment: this is a test comment + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_sip_update2 + +- name: Remove a DTC SIP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_sip: + name: sip_monitor + state: absent + provider: "{{ nios_provider }}" + register: dtc_monitor_sip_delete1 + +- name: Reremove a DTC SIP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_sip: + name: sip_monitor + state: absent + provider: "{{ nios_provider }}" + register: dtc_monitor_sip_delete2 + +- name: Verify outcomes + ansible.builtin.assert: + that: + - "dtc_monitor_sip_create1.changed" + - "not dtc_monitor_sip_create2.changed" + - "dtc_monitor_sip_update1.changed" + - "not dtc_monitor_sip_update2.changed" + - "dtc_monitor_sip_delete1.changed" + - "not dtc_monitor_sip_delete2.changed" diff --git a/tests/integration/targets/nios_dtc_monitor_snmp/aliases b/tests/integration/targets/nios_dtc_monitor_snmp/aliases new file mode 100644 index 00000000..b3138dc7 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_snmp/aliases @@ -0,0 +1,3 @@ +shippable/cloud/group1 +cloud/nios +destructive diff --git a/tests/integration/targets/nios_dtc_monitor_snmp/defaults/main.yaml b/tests/integration/targets/nios_dtc_monitor_snmp/defaults/main.yaml new file mode 100644 index 00000000..9ef5ba51 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_snmp/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/tests/integration/targets/nios_dtc_monitor_snmp/meta/main.yaml b/tests/integration/targets/nios_dtc_monitor_snmp/meta/main.yaml new file mode 100644 index 00000000..1b01a972 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_snmp/meta/main.yaml @@ -0,0 +1,2 @@ +dependencies: + - prepare_nios_tests diff --git a/tests/integration/targets/nios_dtc_monitor_snmp/tasks/main.yaml b/tests/integration/targets/nios_dtc_monitor_snmp/tasks/main.yaml new file mode 100644 index 00000000..02c852d3 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_snmp/tasks/main.yaml @@ -0,0 +1 @@ +- include_tasks: nios_dtc_monitor_snmp_idempotence.yaml diff --git a/tests/integration/targets/nios_dtc_monitor_snmp/tasks/nios_dtc_monitor_snmp_idempotence.yaml b/tests/integration/targets/nios_dtc_monitor_snmp/tasks/nios_dtc_monitor_snmp_idempotence.yaml new file mode 100644 index 00000000..12b56047 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_snmp/tasks/nios_dtc_monitor_snmp_idempotence.yaml @@ -0,0 +1,71 @@ +- name: Clean up the parent object + infoblox.nios_modules.nios_zone: + name: ansible.com + state: absent + provider: "{{ nios_provider }}" + +- name: Create the parent object + infoblox.nios_modules.nios_zone: + name: ansible.com + state: present + provider: "{{ nios_provider }}" + +- name: Clean up the DTC SNMP monitor + infoblox.nios_modules.nios_dtc_monitor_snmp: + name: snmp_monitor + state: absent + provider: "{{ nios_provider }}" + +- name: Create a DTC SNMP monitor + infoblox.nios_modules.nios_dtc_monitor_snmp: + name: snmp_monitor + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_snmp_create1 + +- name: Recreate a DTC SNMP monitor + infoblox.nios_modules.nios_dtc_monitor_snmp: + name: snmp_monitor + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_snmp_create2 + +- name: Add a comment to an existing DTC SNMP monitor + infoblox.nios_modules.nios_dtc_monitor_snmp: + name: snmp_monitor + comment: this is a test comment + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_snmp_update1 + +- name: Readd a comment to an existing DTC SNMP monitor + infoblox.nios_modules.nios_dtc_monitor_snmp: + name: snmp_monitor + comment: this is a test comment + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_snmp_update2 + +- name: Remove a DTC SNMP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_snmp: + name: snmp_monitor + state: absent + provider: "{{ nios_provider }}" + register: dtc_monitor_snmp_delete1 + +- name: Reremove a DTC SNMP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_snmp: + name: snmp_monitor + state: absent + provider: "{{ nios_provider }}" + register: dtc_monitor_snmp_delete2 + +- name: Verify outcomes + ansible.builtin.assert: + that: + - "dtc_monitor_snmp_create1.changed" + - "not dtc_monitor_snmp_create2.changed" + - "dtc_monitor_snmp_update1.changed" + - "not dtc_monitor_snmp_update2.changed" + - "dtc_monitor_snmp_delete1.changed" + - "not dtc_monitor_snmp_delete2.changed" diff --git a/tests/integration/targets/nios_dtc_monitor_tcp/aliases b/tests/integration/targets/nios_dtc_monitor_tcp/aliases new file mode 100644 index 00000000..b3138dc7 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_tcp/aliases @@ -0,0 +1,3 @@ +shippable/cloud/group1 +cloud/nios +destructive diff --git a/tests/integration/targets/nios_dtc_monitor_tcp/defaults/main.yaml b/tests/integration/targets/nios_dtc_monitor_tcp/defaults/main.yaml new file mode 100644 index 00000000..9ef5ba51 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_tcp/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/tests/integration/targets/nios_dtc_monitor_tcp/meta/main.yaml b/tests/integration/targets/nios_dtc_monitor_tcp/meta/main.yaml new file mode 100644 index 00000000..1b01a972 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_tcp/meta/main.yaml @@ -0,0 +1,2 @@ +dependencies: + - prepare_nios_tests diff --git a/tests/integration/targets/nios_dtc_monitor_tcp/tasks/main.yaml b/tests/integration/targets/nios_dtc_monitor_tcp/tasks/main.yaml new file mode 100644 index 00000000..e24c8265 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_tcp/tasks/main.yaml @@ -0,0 +1 @@ +- include_tasks: nios_dtc_monitor_tcp_idempotence.yaml diff --git a/tests/integration/targets/nios_dtc_monitor_tcp/tasks/nios_dtc_monitor_tcp_idempotence.yaml b/tests/integration/targets/nios_dtc_monitor_tcp/tasks/nios_dtc_monitor_tcp_idempotence.yaml new file mode 100644 index 00000000..89b4431d --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_tcp/tasks/nios_dtc_monitor_tcp_idempotence.yaml @@ -0,0 +1,73 @@ +- name: Clean up the parent object + infoblox.nios_modules.nios_zone: + name: ansible.com + state: absent + provider: "{{ nios_provider }}" + +- name: Create the parent object + infoblox.nios_modules.nios_zone: + name: ansible.com + state: present + provider: "{{ nios_provider }}" + +- name: Clean up the DTC TCP monitor + infoblox.nios_modules.nios_dtc_monitor_tcp: + name: tcp_monitor + state: absent + provider: "{{ nios_provider }}" + +- name: Create a DTC TCP monitor + infoblox.nios_modules.nios_dtc_monitor_tcp: + name: tcp_monitor + port: 8080 + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_tcp_create1 + +- name: Recreate a DTC TCP monitor + infoblox.nios_modules.nios_dtc_monitor_tcp: + name: tcp_monitor + port: 8080 + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_tcp_create2 + +- name: Add a comment to an existing DTC TCP monitor + infoblox.nios_modules.nios_dtc_monitor_tcp: + name: tcp_monitor + comment: this is a test comment + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_tcp_update1 + +- name: Readd a comment to an existing DTC TCP monitor + infoblox.nios_modules.nios_dtc_monitor_tcp: + name: tcp_monitor + comment: this is a test comment + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_tcp_update2 + +- name: Remove a DTC TCP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_tcp: + name: tcp_monitor + state: absent + provider: "{{ nios_provider }}" + register: dtc_monitor_tcp_delete1 + +- name: Reremove a DTC TCP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_tcp: + name: tcp_monitor + state: absent + provider: "{{ nios_provider }}" + register: dtc_monitor_tcp_delete2 + +- name: Verify outcomes + ansible.builtin.assert: + that: + - "dtc_monitor_tcp_create1.changed" + - "not dtc_monitor_tcp_create2.changed" + - "dtc_monitor_tcp_update1.changed" + - "not dtc_monitor_tcp_update2.changed" + - "dtc_monitor_tcp_delete1.changed" + - "not dtc_monitor_tcp_delete2.changed" diff --git a/tests/integration/targets/nios_dtc_topology/aliases b/tests/integration/targets/nios_dtc_topology/aliases new file mode 100644 index 00000000..b3138dc7 --- /dev/null +++ b/tests/integration/targets/nios_dtc_topology/aliases @@ -0,0 +1,3 @@ +shippable/cloud/group1 +cloud/nios +destructive diff --git a/tests/integration/targets/nios_dtc_topology/defaults/main.yaml b/tests/integration/targets/nios_dtc_topology/defaults/main.yaml new file mode 100644 index 00000000..9ef5ba51 --- /dev/null +++ b/tests/integration/targets/nios_dtc_topology/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/tests/integration/targets/nios_dtc_topology/meta/main.yaml b/tests/integration/targets/nios_dtc_topology/meta/main.yaml new file mode 100644 index 00000000..1b01a972 --- /dev/null +++ b/tests/integration/targets/nios_dtc_topology/meta/main.yaml @@ -0,0 +1,2 @@ +dependencies: + - prepare_nios_tests diff --git a/tests/integration/targets/nios_dtc_topology/tasks/main.yaml b/tests/integration/targets/nios_dtc_topology/tasks/main.yaml new file mode 100644 index 00000000..8873ef55 --- /dev/null +++ b/tests/integration/targets/nios_dtc_topology/tasks/main.yaml @@ -0,0 +1 @@ +- include_tasks: nios_dtc_topology_idempotence.yaml diff --git a/tests/integration/targets/nios_dtc_topology/tasks/nios_dtc_topology_idempotence.yaml b/tests/integration/targets/nios_dtc_topology/tasks/nios_dtc_topology_idempotence.yaml new file mode 100644 index 00000000..a24a9c31 --- /dev/null +++ b/tests/integration/targets/nios_dtc_topology/tasks/nios_dtc_topology_idempotence.yaml @@ -0,0 +1,122 @@ +- name: Clean up the parent object + infoblox.nios_modules.nios_zone: + name: ansible.com + state: absent + provider: "{{ nios_provider }}" + +- name: Create the parent object + infoblox.nios_modules.nios_zone: + name: ansible.com + state: present + provider: "{{ nios_provider }}" + +- name: Clean up the DTC Topology + infoblox.nios_modules.nios_dtc_topology: + name: a_topology + state: absent + provider: "{{ nios_provider }}" + +- name: Clean up the DTC pool + infoblox.nios_modules.nios_dtc_pool: + name: web_pool + lb_preferred_method: ROUND_ROBIN + state: absent + provider: "{{ nios_provider }}" + +- name: Clean up the DTC server + infoblox.nios_modules.nios_dtc_server: + name: Server1 + host: 192.168.10.1 + state: absent + provider: "{{ nios_provider }}" + +- name: Create DTC server + infoblox.nios_modules.nios_dtc_server: + name: Server1 + host: 192.168.10.1 + comment: Created with Ansible + state: present + provider: "{{ nios_provider }}" + +- name: Create DTC Pool + infoblox.nios_modules.nios_dtc_pool: + name: web_pool + lb_preferred_method: ROUND_ROBIN + servers: + - server: Server1 + ratio: 1 + comment: Created with Ansible + state: present + provider: "{{ nios_provider }}" + +- name: Create a DTC Topology + infoblox.nios_modules.nios_dtc_topology: + name: a_topology + rules: + - dest_type: POOL + destination_link: web_pool + return_type: REGULAR + state: present + provider: "{{ nios_provider }}" + register: dtc_topology_create1 + +- name: Recreate a DTC Topology + infoblox.nios_modules.nios_dtc_topology: + name: a_topology + state: present + provider: "{{ nios_provider }}" + register: dtc_topology_create2 + +- name: Add a comment to an existing DTC Topology + infoblox.nios_modules.nios_dtc_topology: + name: a_topology + comment: this is a test comment + state: present + provider: "{{ nios_provider }}" + register: dtc_topology_update1 + +- name: Readd a comment to an existing DTC Topology + infoblox.nios_modules.nios_dtc_topology: + name: a_topology + comment: this is a test comment + state: present + provider: "{{ nios_provider }}" + register: dtc_topology_update2 + +- name: Remove a DTC Topology + infoblox.nios_modules.nios_dtc_topology: + name: a_topology + state: absent + provider: "{{ nios_provider }}" + register: dtc_topology_delete1 + +- name: Reremove a DTC Topology + infoblox.nios_modules.nios_dtc_topology: + name: a_topology + state: absent + provider: "{{ nios_provider }}" + register: dtc_topology_delete2 + +- name: Remove the DTC pool + infoblox.nios_modules.nios_dtc_pool: + name: web_pool + lb_preferred_method: ROUND_ROBIN + state: absent + provider: "{{ nios_provider }}" + +- name: Remove the DTC server + infoblox.nios_modules.nios_dtc_server: + name: Server1 + host: 192.168.10.1 + state: absent + provider: "{{ nios_provider }}" + +- name: Verify outcomes + ansible.builtin.assert: + that: + - "dtc_topology_create1.changed" + - "not dtc_topology_create2.changed" + - "dtc_topology_update1.changed" + - "not dtc_topology_update2.changed" + - "dtc_topology_delete1.changed" + - "not dtc_topology_delete2.changed" diff --git a/tests/unit/plugins/modules/test_nios_dtc_monitor_http.py b/tests/unit/plugins/modules/test_nios_dtc_monitor_http.py new file mode 100644 index 00000000..d053f0bf --- /dev/null +++ b/tests/unit/plugins/modules/test_nios_dtc_monitor_http.py @@ -0,0 +1,136 @@ +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + + +from ansible_collections.infoblox.nios_modules.plugins.modules import nios_dtc_monitor_http +from ansible_collections.infoblox.nios_modules.plugins.module_utils import api +from ansible_collections.infoblox.nios_modules.tests.unit.compat.mock import patch, MagicMock, Mock +from .test_nios_module import TestNiosModule, load_fixture + + +class TestNiosDtcHttpMonitorModule(TestNiosModule): + + module = nios_dtc_monitor_http + + def setUp(self): + super(TestNiosDtcHttpMonitorModule, self).setUp() + self.module = MagicMock(name='ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_http.WapiModule') + self.module.check_mode = False + self.module.params = {'provider': None} + self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_http.WapiModule') + self.exec_command = self.mock_wapi.start() + self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_http.WapiModule.run') + self.mock_wapi_run.start() + self.load_config = self.mock_wapi_run.start() + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') + self.mock_check_type_dict_obj = self.mock_check_type_dict.start() + + def tearDown(self): + super(TestNiosDtcHttpMonitorModule, self).tearDown() + self.mock_wapi.stop() + self.mock_wapi_run.stop() + self.mock_check_type_dict.stop() + + def _get_wapi(self, test_object): + wapi = api.WapiModule(self.module) + wapi.get_object = Mock(name='get_object', return_value=test_object) + wapi.create_object = Mock(name='create_object') + wapi.update_object = Mock(name='update_object') + wapi.delete_object = Mock(name='delete_object') + return wapi + + def load_fixtures(self, commands=None): + self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None) + self.load_config.return_value = dict(diff=None, session='session') + + def test_nios_dtc_monitor_http_create(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'https_monitor', + 'port': 443, 'secure': True, 'comment': None, 'extattrs': None} + + test_object = None + + test_spec = { + "name": {"ib_req": True}, + "port": {}, + "secure": {}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.create_object.assert_called_once_with('testobject', {'name': 'https_monitor', + 'port': 443, 'secure': True}) + + def test_nios_dtc_monitor_http_update_comment(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'https_monitor', + 'comment': 'updated comment', 'extattrs': None} + + test_object = [ + { + "comment": "test comment", + "_ref": "dtc:monitor:http/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "name": "https_monitor", + "port": 443, + "secure": True, + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + + def test_nios_dtc_monitor_http_remove(self): + self.module.params = {'provider': None, 'state': 'absent', 'name': 'https_monitor', + 'comment': None, 'extattrs': None} + + ref = "dtc:monitor:http/ZG5zLm5ldHdvcmtfdmlldyQw:default/false" + + test_object = [ + { + "comment": "test comment", + "_ref": ref, + "name": "https_monitor", + "port": 443, + "secure": True, + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.delete_object.assert_called_once_with(ref) diff --git a/tests/unit/plugins/modules/test_nios_dtc_monitor_icmp.py b/tests/unit/plugins/modules/test_nios_dtc_monitor_icmp.py new file mode 100644 index 00000000..fb4b300d --- /dev/null +++ b/tests/unit/plugins/modules/test_nios_dtc_monitor_icmp.py @@ -0,0 +1,129 @@ +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + + +from ansible_collections.infoblox.nios_modules.plugins.modules import nios_dtc_monitor_icmp +from ansible_collections.infoblox.nios_modules.plugins.module_utils import api +from ansible_collections.infoblox.nios_modules.tests.unit.compat.mock import patch, MagicMock, Mock +from .test_nios_module import TestNiosModule, load_fixture + + +class TestNiosDtcIcmpMonitorModule(TestNiosModule): + + module = nios_dtc_monitor_icmp + + def setUp(self): + super(TestNiosDtcIcmpMonitorModule, self).setUp() + self.module = MagicMock(name='ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_icmp.WapiModule') + self.module.check_mode = False + self.module.params = {'provider': None} + self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_icmp.WapiModule') + self.exec_command = self.mock_wapi.start() + self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_icmp.WapiModule.run') + self.mock_wapi_run.start() + self.load_config = self.mock_wapi_run.start() + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') + self.mock_check_type_dict_obj = self.mock_check_type_dict.start() + + def tearDown(self): + super(TestNiosDtcIcmpMonitorModule, self).tearDown() + self.mock_wapi.stop() + self.mock_wapi_run.stop() + self.mock_check_type_dict.stop() + + def _get_wapi(self, test_object): + wapi = api.WapiModule(self.module) + wapi.get_object = Mock(name='get_object', return_value=test_object) + wapi.create_object = Mock(name='create_object') + wapi.update_object = Mock(name='update_object') + wapi.delete_object = Mock(name='delete_object') + return wapi + + def load_fixtures(self, commands=None): + self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None) + self.load_config.return_value = dict(diff=None, session='session') + + def test_nios_dtc_monitor_icmp_create(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'icmp_monitor', + 'comment': None, 'extattrs': None} + + test_object = None + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.create_object.assert_called_once_with('testobject', {'name': 'icmp_monitor'}) + + def test_nios_dtc_monitor_icmp_update_comment(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'icmp_monitor', + 'comment': 'updated comment', 'extattrs': None} + + test_object = [ + { + "comment": "test comment", + "_ref": "dtc:monitor:icmp/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "name": "icmp_monitor", + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + + def test_nios_dtc_monitor_icmp_remove(self): + self.module.params = {'provider': None, 'state': 'absent', 'name': 'icmp_monitor', + 'comment': None, 'extattrs': None} + + ref = "dtc:monitor:icmp/ZG5zLm5ldHdvcmtfdmlldyQw:default/false" + + test_object = [ + { + "comment": "test comment", + "_ref": ref, + "name": "icmp_monitor", + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.delete_object.assert_called_once_with(ref) diff --git a/tests/unit/plugins/modules/test_nios_dtc_monitor_pdp.py b/tests/unit/plugins/modules/test_nios_dtc_monitor_pdp.py new file mode 100644 index 00000000..80263784 --- /dev/null +++ b/tests/unit/plugins/modules/test_nios_dtc_monitor_pdp.py @@ -0,0 +1,131 @@ +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + + +from ansible_collections.infoblox.nios_modules.plugins.modules import nios_dtc_monitor_pdp +from ansible_collections.infoblox.nios_modules.plugins.module_utils import api +from ansible_collections.infoblox.nios_modules.tests.unit.compat.mock import patch, MagicMock, Mock +from .test_nios_module import TestNiosModule, load_fixture + + +class TestNiosDtcTcpMonitorModule(TestNiosModule): + + module = nios_dtc_monitor_pdp + + def setUp(self): + super(TestNiosDtcTcpMonitorModule, self).setUp() + self.module = MagicMock(name='ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_pdp.WapiModule') + self.module.check_mode = False + self.module.params = {'provider': None} + self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_pdp.WapiModule') + self.exec_command = self.mock_wapi.start() + self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_pdp.WapiModule.run') + self.mock_wapi_run.start() + self.load_config = self.mock_wapi_run.start() + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') + self.mock_check_type_dict_obj = self.mock_check_type_dict.start() + + def tearDown(self): + super(TestNiosDtcTcpMonitorModule, self).tearDown() + self.mock_wapi.stop() + self.mock_wapi_run.stop() + self.mock_check_type_dict.stop() + + def _get_wapi(self, test_object): + wapi = api.WapiModule(self.module) + wapi.get_object = Mock(name='get_object', return_value=test_object) + wapi.create_object = Mock(name='create_object') + wapi.update_object = Mock(name='update_object') + wapi.delete_object = Mock(name='delete_object') + return wapi + + def load_fixtures(self, commands=None): + self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None) + self.load_config.return_value = dict(diff=None, session='session') + + def test_nios_dtc_monitor_pdp_create(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'pdp_monitor', + 'comment': None, 'extattrs': None} + + test_object = None + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.create_object.assert_called_once_with('testobject', {'name': 'pdp_monitor'}) + + def test_nios_dtc_monitor_pdp_update_comment(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'pdp_monitor', + 'comment': 'updated comment', 'extattrs': None} + + test_object = [ + { + "comment": "test comment", + "_ref": "dtc:monitor:pdp/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "name": "pdp_monitor", + "port": 2123, + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + + def test_nios_dtc_monitor_pdp_remove(self): + self.module.params = {'provider': None, 'state': 'absent', 'name': 'pdp_monitor', + 'comment': None, 'extattrs': None} + + ref = "dtc:monitor:pdp/ZG5zLm5ldHdvcmtfdmlldyQw:default/false" + + test_object = [ + { + "comment": "test comment", + "_ref": ref, + "name": "pdp_monitor", + "port": 2123, + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.delete_object.assert_called_once_with(ref) diff --git a/tests/unit/plugins/modules/test_nios_dtc_monitor_sip.py b/tests/unit/plugins/modules/test_nios_dtc_monitor_sip.py new file mode 100644 index 00000000..90b86bfa --- /dev/null +++ b/tests/unit/plugins/modules/test_nios_dtc_monitor_sip.py @@ -0,0 +1,129 @@ +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + + +from ansible_collections.infoblox.nios_modules.plugins.modules import nios_dtc_monitor_sip +from ansible_collections.infoblox.nios_modules.plugins.module_utils import api +from ansible_collections.infoblox.nios_modules.tests.unit.compat.mock import patch, MagicMock, Mock +from .test_nios_module import TestNiosModule, load_fixture + + +class TestNiosDtcSipMonitorModule(TestNiosModule): + + module = nios_dtc_monitor_sip + + def setUp(self): + super(TestNiosDtcSipMonitorModule, self).setUp() + self.module = MagicMock(name='ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_sip.WapiModule') + self.module.check_mode = False + self.module.params = {'provider': None} + self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_sip.WapiModule') + self.exec_command = self.mock_wapi.start() + self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_sip.WapiModule.run') + self.mock_wapi_run.start() + self.load_config = self.mock_wapi_run.start() + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') + self.mock_check_type_dict_obj = self.mock_check_type_dict.start() + + def tearDown(self): + super(TestNiosDtcSipMonitorModule, self).tearDown() + self.mock_wapi.stop() + self.mock_wapi_run.stop() + self.mock_check_type_dict.stop() + + def _get_wapi(self, test_object): + wapi = api.WapiModule(self.module) + wapi.get_object = Mock(name='get_object', return_value=test_object) + wapi.create_object = Mock(name='create_object') + wapi.update_object = Mock(name='update_object') + wapi.delete_object = Mock(name='delete_object') + return wapi + + def load_fixtures(self, commands=None): + self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None) + self.load_config.return_value = dict(diff=None, session='session') + + def test_nios_dtc_monitor_sip_create(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'sip_monitor', + 'comment': None, 'extattrs': None} + + test_object = None + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.create_object.assert_called_once_with('testobject', {'name': 'sip_monitor'}) + + def test_nios_dtc_monitor_sip_update_comment(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'sip_monitor', + 'comment': 'updated comment', 'extattrs': None} + + test_object = [ + { + "comment": "test comment", + "_ref": "dtc:monitor:sip/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "name": "sip_monitor", + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + + def test_nios_dtc_monitor_sip_remove(self): + self.module.params = {'provider': None, 'state': 'absent', 'name': 'sip_monitor', + 'comment': None, 'extattrs': None} + + ref = "dtc:monitor:sip/ZG5zLm5ldHdvcmtfdmlldyQw:default/false" + + test_object = [ + { + "comment": "test comment", + "_ref": ref, + "name": "sip_monitor", + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.delete_object.assert_called_once_with(ref) diff --git a/tests/unit/plugins/modules/test_nios_dtc_monitor_snmp.py b/tests/unit/plugins/modules/test_nios_dtc_monitor_snmp.py new file mode 100644 index 00000000..838a35eb --- /dev/null +++ b/tests/unit/plugins/modules/test_nios_dtc_monitor_snmp.py @@ -0,0 +1,143 @@ +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + + +from ansible_collections.infoblox.nios_modules.plugins.modules import nios_dtc_monitor_snmp +from ansible_collections.infoblox.nios_modules.plugins.module_utils import api +from ansible_collections.infoblox.nios_modules.tests.unit.compat.mock import patch, MagicMock, Mock +from .test_nios_module import TestNiosModule, load_fixture + + +class TestNiosDtcSnmpMonitorModule(TestNiosModule): + + module = nios_dtc_monitor_snmp + + def setUp(self): + super(TestNiosDtcSnmpMonitorModule, self).setUp() + self.module = MagicMock(name='ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_snmp.WapiModule') + self.module.check_mode = False + self.module.params = {'provider': None} + self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_snmp.WapiModule') + self.exec_command = self.mock_wapi.start() + self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_snmp.WapiModule.run') + self.mock_wapi_run.start() + self.load_config = self.mock_wapi_run.start() + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') + self.mock_check_type_dict_obj = self.mock_check_type_dict.start() + + def tearDown(self): + super(TestNiosDtcSnmpMonitorModule, self).tearDown() + self.mock_wapi.stop() + self.mock_wapi_run.stop() + self.mock_check_type_dict.stop() + + def _get_wapi(self, test_object): + wapi = api.WapiModule(self.module) + wapi.get_object = Mock(name='get_object', return_value=test_object) + wapi.create_object = Mock(name='create_object') + wapi.update_object = Mock(name='update_object') + wapi.delete_object = Mock(name='delete_object') + return wapi + + def load_fixtures(self, commands=None): + self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None) + self.load_config.return_value = dict(diff=None, session='session') + + def test_nios_dtc_monitor_snmp_create(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'snmp_monitor', + 'comment': None, 'extattrs': None} + + test_object = None + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.create_object.assert_called_once_with('testobject', {'name': 'snmp_monitor'}) + + def test_nios_dtc_monitor_snmp_update_comment(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'snmp_monitor', + 'comment': 'updated comment', 'extattrs': None} + + test_object = [ + { + "comment": "test comment", + "_ref": "dtc:monitor:snmp/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "name": "snmp_monitor", + "port": 161, + "version": "V2C", + "community": "public", + "interval": 5, + "retry_down": 1, + "retry_up": 1, + "timeout": 15, + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + + def test_nios_dtc_monitor_snmp_remove(self): + self.module.params = {'provider': None, 'state': 'absent', 'name': 'snmp_monitor', + 'comment': None, 'extattrs': None} + + ref = "dtc:monitor:snmp/ZG5zLm5ldHdvcmtfdmlldyQw:default/false" + + test_object = [ + { + "comment": "test comment", + "_ref": ref, + "name": "snmp_monitor", + "port": 161, + "version": "V2C", + "community": "public", + "interval": 5, + "retry_down": 1, + "retry_up": 1, + "timeout": 15, + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.delete_object.assert_called_once_with(ref) diff --git a/tests/unit/plugins/modules/test_nios_dtc_monitor_tcp.py b/tests/unit/plugins/modules/test_nios_dtc_monitor_tcp.py new file mode 100644 index 00000000..072ba1a3 --- /dev/null +++ b/tests/unit/plugins/modules/test_nios_dtc_monitor_tcp.py @@ -0,0 +1,133 @@ +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + + +from ansible_collections.infoblox.nios_modules.plugins.modules import nios_dtc_monitor_tcp +from ansible_collections.infoblox.nios_modules.plugins.module_utils import api +from ansible_collections.infoblox.nios_modules.tests.unit.compat.mock import patch, MagicMock, Mock +from .test_nios_module import TestNiosModule, load_fixture + + +class TestNiosDtcTcpMonitorModule(TestNiosModule): + + module = nios_dtc_monitor_tcp + + def setUp(self): + super(TestNiosDtcTcpMonitorModule, self).setUp() + self.module = MagicMock(name='ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_tcp.WapiModule') + self.module.check_mode = False + self.module.params = {'provider': None} + self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_tcp.WapiModule') + self.exec_command = self.mock_wapi.start() + self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_tcp.WapiModule.run') + self.mock_wapi_run.start() + self.load_config = self.mock_wapi_run.start() + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') + self.mock_check_type_dict_obj = self.mock_check_type_dict.start() + + def tearDown(self): + super(TestNiosDtcTcpMonitorModule, self).tearDown() + self.mock_wapi.stop() + self.mock_wapi_run.stop() + self.mock_check_type_dict.stop() + + def _get_wapi(self, test_object): + wapi = api.WapiModule(self.module) + wapi.get_object = Mock(name='get_object', return_value=test_object) + wapi.create_object = Mock(name='create_object') + wapi.update_object = Mock(name='update_object') + wapi.delete_object = Mock(name='delete_object') + return wapi + + def load_fixtures(self, commands=None): + self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None) + self.load_config.return_value = dict(diff=None, session='session') + + def test_nios_dtc_monitor_tcp_create(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'tcp_monitor', + 'port': 8080, 'comment': None, 'extattrs': None} + + test_object = None + + test_spec = { + "name": {"ib_req": True}, + "port": {}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.create_object.assert_called_once_with('testobject', {'name': 'tcp_monitor', + 'port': 8080}) + + def test_nios_dtc_monitor_tcp_update_comment(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'tcp_monitor', + 'comment': 'updated comment', 'extattrs': None} + + test_object = [ + { + "comment": "test comment", + "_ref": "dtc:monitor:tcp/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "name": "tcp_monitor", + "port": 8080, + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + + def test_nios_dtc_monitor_tcp_remove(self): + self.module.params = {'provider': None, 'state': 'absent', 'name': 'tcp_monitor', + 'comment': None, 'extattrs': None} + + ref = "dtc:monitor:tcp/ZG5zLm5ldHdvcmtfdmlldyQw:default/false" + + test_object = [ + { + "comment": "test comment", + "_ref": ref, + "name": "tcp_monitor", + "port": 8080, + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.delete_object.assert_called_once_with(ref) diff --git a/tests/unit/plugins/modules/test_nios_dtc_topology.py b/tests/unit/plugins/modules/test_nios_dtc_topology.py new file mode 100644 index 00000000..d0ee4c69 --- /dev/null +++ b/tests/unit/plugins/modules/test_nios_dtc_topology.py @@ -0,0 +1,156 @@ +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + + +from ansible_collections.infoblox.nios_modules.plugins.modules import nios_dtc_topology +from ansible_collections.infoblox.nios_modules.plugins.module_utils import api +from ansible_collections.infoblox.nios_modules.tests.unit.compat.mock import patch, MagicMock, Mock +from .test_nios_module import TestNiosModule, load_fixture + + +class TestNiosDtcTopologyModule(TestNiosModule): + + module = nios_dtc_topology + + def setUp(self): + super(TestNiosDtcTopologyModule, self).setUp() + self.module = MagicMock(name='ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_topology.WapiModule') + self.module.check_mode = False + self.module.params = {'provider': None} + self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_topology.WapiModule') + self.exec_command = self.mock_wapi.start() + self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_topology.WapiModule.run') + self.mock_wapi_run.start() + self.load_config = self.mock_wapi_run.start() + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') + self.mock_check_type_dict_obj = self.mock_check_type_dict.start() + + def tearDown(self): + super(TestNiosDtcTopologyModule, self).tearDown() + self.mock_wapi.stop() + self.mock_wapi_run.stop() + self.mock_check_type_dict.stop() + + def _get_wapi(self, test_object): + wapi = api.WapiModule(self.module) + wapi.get_object = Mock(name='get_object', return_value=test_object) + wapi.create_object = Mock(name='create_object') + wapi.update_object = Mock(name='update_object') + wapi.delete_object = Mock(name='delete_object') + return wapi + + def load_fixtures(self, commands=None): + self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None) + self.load_config.return_value = dict(diff=None, session='session') + + def test_nios_dtc_topology_create(self): + self.module.params = { + 'provider': None, + 'state': 'present', + 'name': 'a_topology', + 'rules': [{ + 'dest_type': 'POOL', + 'destination_link': 'web_pool', + 'return_type': 'REGULAR' + }], + 'comment': None, + 'extattrs': None + } + + test_object = None + + test_spec = { + "name": {"ib_req": True}, + "rules": {}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.create_object.assert_called_once_with( + 'testobject', + { + 'name': 'a_topology', + 'rules': [{ + 'dest_type': 'POOL', + 'destination_link': 'web_pool', + 'return_type': 'REGULAR' + }] + } + ) + + def test_nios_dtc_topology_update_comment(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'a_topology', + 'comment': 'updated comment', 'extattrs': None} + + test_object = [ + { + '_ref': 'dtc:topology/ZG5zLm5ldHdvcmtfdmlldyQw:default/true', + 'name': 'a_topology', + 'rules': [{ + '_ref': 'dtc:topology:rule/ZG5zLm5ldHdvcmtfdmlldyQw:a_topology/web_pool' + }], + 'comment': "test comment", + 'extattrs': {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + + def test_nios_dtc_topology_remove(self): + self.module.params = {'provider': None, 'state': 'absent', 'name': 'a_topology', + 'comment': None, 'extattrs': None} + + ref = "dtc:topology/ZG5zLm5ldHdvcmtfdmlldyQw:default/false" + + test_object = [ + { + "comment": {}, + "_ref": ref, + "name": "a_topology", + 'rules': [{ + '_ref': 'dtc:topology:rule/ZG5zLm5ldHdvcmtfdmlldyQw:a_topology/web_pool' + }], + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.delete_object.assert_called_once_with(ref)