Skip to content

Commit

Permalink
Merge pull request #341 from netscaler/flushed-state
Browse files Browse the repository at this point in the history
  • Loading branch information
sumanth-lingappa authored Jan 13, 2024
2 parents ce0eb06 + 4fd1fe7 commit 04bb593
Show file tree
Hide file tree
Showing 21 changed files with 102 additions and 17 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ lint:
yamllint .
echo "\n\n\n\n\n\n\n\n\n\n"
ansible-lint
python3 -m pycodestyle --max-line-length 160 --config /dev/null --ignore E203,E402,E741,W503,W504 plugins tests

test_sanity: galaxy_importer install
cd ~/.ansible/collections/ansible_collections/netscaler/adc && \
Expand Down
9 changes: 9 additions & 0 deletions examples/dnsproxyrecords.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- name: Sample Playbook for netscaler.adc.dnsproxyrecords
hosts: localhost
gather_facts: false
tasks:
- name: Flush DNS Proxy records
delegate_to: localhost
netscaler.adc.dnsproxyrecords:
state: flushed
1 change: 1 addition & 0 deletions features_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The `netscaler.adc` collection supports 4 modes of operation.
| `disabled` | Resource will be disabled on the NetScaler ADC nodes. Not all resources have disable operation |
| `created` | Some of the NITRO resources support `create` operation. This state will "create" those resources on the NetScaler. Eg: `create sslcert`, `create dnskey` etc |
| `imported` | Resource will be imported on the NetScaler ADC nodes |
| `flushed` | Resources will be flushed on the NetScaler ADC nodes. Eg., `flush dns proxyrecords` |
| `switched` | TBD: Resource will be switched on the NetScaler ADC nodes. Eg: Partition switch |

> NOTE: The `enabled`, `disabled`, `created`, `imported`, `switched` modes are supported only for the modules that have `enable`, `disable`, `create`, `import`, `switch` operations in the NetScaler ADC NITRO API.
Expand Down
2 changes: 1 addition & 1 deletion playbook_anatomy.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ This is how a typical playbook for `netscaler.adc` collection looks like:
# Should the module save the config after making the changes. This is optional. Default is false.
save_config: false # This can also be given via NETSCALER_SAVE_CONFIG environment variable

state: present # This is the desired state of the resource. The module will make sure that the resource is in this state. Valid values are `present`, `absent`, `enabled`, `disabled`, `imported`, `created`. However, not all modules support all the states. Refer to the module documentation for the supported states.
state: present # This is the desired state of the resource. The module will make sure that the resource is in this state. Valid values are `present`, `absent`, `enabled`, `disabled`, `imported`, `created`, `flushed`. However, not all modules support all the states. Refer to the module documentation for the supported states.

# The following are the module parameters. Refer to the module documentation for the list of supported parameters.
name: s1
Expand Down
2 changes: 2 additions & 0 deletions plugins/module_utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,8 @@ def get_valid_desired_states(resource_name):
desired_states.add("disabled")
if "create" in supported_operations:
desired_states.add("created")
if "flush" in supported_operations:
desired_states.add("flushed")
if "import" in supported_operations or "Import" in supported_operations:
desired_states.add("imported")
if "Switch" in supported_operations:
Expand Down
3 changes: 2 additions & 1 deletion plugins/module_utils/module_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,10 +903,11 @@ def main(self):
if "bindings" in NITRO_RESOURCE_MAP[self.resource_name].keys():
self.sync_all_bindings()

elif self.module.params["state"] in {"created", "imported"}:
elif self.module.params["state"] in {"created", "imported", "flushed"}:
state_action_map = {
"created": "create",
"imported": "import",
"flushed": "flush",
}
self.act_on_resource(
action=state_action_map[self.module.params["state"]]
Expand Down
1 change: 1 addition & 0 deletions plugins/modules/cachecontentgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
choices:
- present
- absent
- flushed
default: present
description:
- The state of the resource being configured by the module on the NetScaler
Expand Down
3 changes: 2 additions & 1 deletion plugins/modules/cacheobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
- Sumanth Lingappa (@sumanth-lingappa)
options:
state:
choices: []
choices:
- flushed
default: present
description:
- The state of the resource being configured by the module on the NetScaler
Expand Down
3 changes: 2 additions & 1 deletion plugins/modules/dnsproxyrecords.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
- Sumanth Lingappa (@sumanth-lingappa)
options:
state:
choices: []
choices:
- flushed
default: present
description:
- The state of the resource being configured by the module on the NetScaler
Expand Down
3 changes: 2 additions & 1 deletion plugins/modules/dnssubnetcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
- Sumanth Lingappa (@sumanth-lingappa)
options:
state:
choices: []
choices:
- flushed
default: present
description:
- The state of the resource being configured by the module on the NetScaler
Expand Down
3 changes: 2 additions & 1 deletion plugins/modules/ipsecalgsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
- Sumanth Lingappa (@sumanth-lingappa)
options:
state:
choices: []
choices:
- flushed
default: present
description:
- The state of the resource being configured by the module on the NetScaler
Expand Down
3 changes: 2 additions & 1 deletion plugins/modules/lsnrtspalgsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
- Sumanth Lingappa (@sumanth-lingappa)
options:
state:
choices: []
choices:
- flushed
default: present
description:
- The state of the resource being configured by the module on the NetScaler
Expand Down
3 changes: 2 additions & 1 deletion plugins/modules/lsnsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
- Sumanth Lingappa (@sumanth-lingappa)
options:
state:
choices: []
choices:
- flushed
default: present
description:
- The state of the resource being configured by the module on the NetScaler
Expand Down
3 changes: 2 additions & 1 deletion plugins/modules/lsnsipalgcall.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
- Sumanth Lingappa (@sumanth-lingappa)
options:
state:
choices: []
choices:
- flushed
default: present
description:
- The state of the resource being configured by the module on the NetScaler
Expand Down
1 change: 1 addition & 0 deletions plugins/modules/nssimpleacl.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
choices:
- present
- absent
- flushed
default: present
description:
- The state of the resource being configured by the module on the NetScaler
Expand Down
1 change: 1 addition & 0 deletions plugins/modules/nssimpleacl6.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
choices:
- present
- absent
- flushed
default: present
description:
- The state of the resource being configured by the module on the NetScaler
Expand Down
3 changes: 2 additions & 1 deletion plugins/modules/nssurgeq.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
- Sumanth Lingappa (@sumanth-lingappa)
options:
state:
choices: []
choices:
- flushed
default: present
description:
- The state of the resource being configured by the module on the NetScaler
Expand Down
3 changes: 2 additions & 1 deletion plugins/modules/rnatsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
- Sumanth Lingappa (@sumanth-lingappa)
options:
state:
choices: []
choices:
- flushed
default: present
description:
- The state of the resource being configured by the module on the NetScaler
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/targets/dnsproxyrecords/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
gather_facts/no
netscaler/cpx/
netscaler/vpx/
57 changes: 57 additions & 0 deletions tests/integration/targets/dnsproxyrecords/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
- name: DNSPROXYRECORDS | FLUSH | --check
delegate_to: localhost
register: result
check_mode: true
tags: test
netscaler.adc.dnsproxyrecords:
nsip: "{{ nsip }}"
nitro_user: "{{ nitro_user }}"
nitro_pass: "{{ nitro_pass }}"
nitro_protocol: "{{ nitro_protocol }}"
validate_certs: "{{ validate_certs }}"
save_config: "{{ save_config }}"
state: flushed
- name: Assert | DNSPROXYRECORDS | FLUSH | --check
tags: test
ansible.builtin.assert:
that:
- "result.failed==false"
- "result.changed==true"
- name: DNSPROXYRECORDS | FLUSH
delegate_to: localhost
register: result
check_mode: false
tags: test
netscaler.adc.dnsproxyrecords:
nsip: "{{ nsip }}"
nitro_user: "{{ nitro_user }}"
nitro_pass: "{{ nitro_pass }}"
nitro_protocol: "{{ nitro_protocol }}"
validate_certs: "{{ validate_certs }}"
save_config: "{{ save_config }}"
state: flushed
- name: Assert | DNSPROXYRECORDS | FLUSH
ansible.builtin.assert:
that:
- "result.failed==false"
- "result.changed==true"
- name: DNSPROXYRECORDS | FLUSH | idempotent
delegate_to: localhost
register: result
check_mode: false
tags: test
netscaler.adc.dnsproxyrecords:
nsip: "{{ nsip }}"
nitro_user: "{{ nitro_user }}"
nitro_pass: "{{ nitro_pass }}"
nitro_protocol: "{{ nitro_protocol }}"
validate_certs: "{{ validate_certs }}"
save_config: "{{ save_config }}"
state: flushed
- name: Assert | DNSPROXYRECORDS | ADD | idempotent
tags: test
ansible.builtin.assert:
that:
- "result.failed==false"
- "result.changed==true" # flushed always returns changed true
11 changes: 5 additions & 6 deletions tests/integration/utils/generate_integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,12 @@ def main(module_name, module_specific_params):
# abcdefghijklmnopqrstuvwxyz

with open(target_dir + os.sep + "aliases", "w") as aliases_file:
aliases_file.write("gather_facts: no\n")
aliases_file.write("gather_facts/no\n")
aliases_file.write("netscaler/cpx/\n")
aliases_file.write("netscaler/vpx/\n")


if __name__ == "__main__":
module_name = "ntpserver"
module_specific_params = {
"servername": "pool.ntp.org",
"preferredntpserver": '"YES"',
}
module_name = "dnsproxyrecords"
module_specific_params = {}
main(module_name, module_specific_params)

0 comments on commit 04bb593

Please sign in to comment.