Skip to content

Commit

Permalink
Merge pull request #342 from netscaler/switched-state
Browse files Browse the repository at this point in the history
new state `switched` added
  • Loading branch information
sumanth-lingappa authored Jan 14, 2024
2 parents 04bb593 + 5d86842 commit b6b2b21
Show file tree
Hide file tree
Showing 6 changed files with 1,497 additions and 305 deletions.
50 changes: 50 additions & 0 deletions examples/non_default_partition_configuration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
- name: Sample Playbook to show non-default partition configuration
hosts: localhost
gather_facts: false
vars:
partitionname: part1
module_defaults:
group/netscaler.adc.default_args:
nsip: 10.10.10.10
nitro_user: nsroot
nitro_protocol: http
validate_certs: false
tasks:
- name: Login to netscaler and get sessionid
delegate_to: localhost
register: login_result
netscaler.adc.login:
username: nsroot
password: notnsroot
- name: Print login sessionid
ansible.builtin.debug:
var: login_result.sessionid
- name: Add partition {{ partitionname }}
delegate_to: localhost
netscaler.adc.nspartition:
nitro_auth_token: "{{ login_result.sessionid }}"
partitionname: "{{ partitionname }}"
state: present
- name: Switch to partition {{ partitionname }}
delegate_to: localhost
netscaler.adc.nspartition:
nitro_auth_token: "{{ login_result.sessionid }}"
state: switched
partitionname: "{{ partitionname }}"
- name: Add nsip in partition {{ partitionname }}
delegate_to: localhost
netscaler.adc.nsip:
nitro_auth_token: "{{ login_result.sessionid }}"
state: present
ipaddress: 1.1.1.1
netmask: 255.255.255.0
type: VIP
- name: Save config in partition {{ partitionname }}
delegate_to: localhost
netscaler.adc.save_config:
nitro_auth_token: "{{ login_result.sessionid }}"
- name: Logout from netscaler
delegate_to: localhost
netscaler.adc.logout:
nitro_auth_token: "{{ login_result.sessionid }}"
2 changes: 1 addition & 1 deletion features_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The `netscaler.adc` collection supports 4 modes of 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 |
| `switched` | Switch partition |

> 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`, `flushed`. 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`, `switched`. 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
6 changes: 3 additions & 3 deletions plugins/module_utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ def _check_create_resource_params(resource_name, resource_module_params, action=
post_data[key] = resource_module_params[key]
else:
log(
"WARNING: Key `{}` is not allowed for the resource `{}` for CREATE operation. Skipping the key for the operation".format(
key, resource_name
"WARNING: Key `{}` is not allowed for the resource `{}` for `{}` action. Skipping the key for the operation".format(
key, resource_name, action.upper()
)
)

Expand Down Expand Up @@ -558,7 +558,7 @@ def get_valid_desired_states(resource_name):
desired_states.add("flushed")
if "import" in supported_operations or "Import" in supported_operations:
desired_states.add("imported")
if "Switch" in supported_operations:
if "Switch" in supported_operations or "switch" in supported_operations:
desired_states.add("switched")
return desired_states

Expand Down
8 changes: 7 additions & 1 deletion plugins/module_utils/module_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,11 +903,17 @@ 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", "flushed"}:
elif self.module.params["state"] in {
"created",
"imported",
"flushed",
"switched",
}:
state_action_map = {
"created": "create",
"imported": "import",
"flushed": "flush",
"switched": "switch",
}
self.act_on_resource(
action=state_action_map[self.module.params["state"]]
Expand Down
Loading

0 comments on commit b6b2b21

Please sign in to comment.