1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Add disable operation for netscaler_servicegroup (#28327)

This commit is contained in:
George Nikolopoulos 2017-08-25 19:03:21 +03:00 committed by John R Barker
parent 2281a6676b
commit c01dd6470c
5 changed files with 111 additions and 5 deletions

View file

@ -314,6 +314,16 @@ options:
description: description:
- Weight to assign to the binding between the monitor and servicegroup. - Weight to assign to the binding between the monitor and servicegroup.
disabled:
description:
- When set to C(yes) the service group state will be set to DISABLED.
- When set to C(no) the service group state will be set to ENABLED.
- >-
Note that due to limitations of the underlying NITRO API a C(disabled) state change alone
does not cause the module result to report a changed status.
type: bool
default: false
extends_documentation_fragment: netscaler extends_documentation_fragment: netscaler
requirements: requirements:
@ -618,6 +628,16 @@ def diff(client, module, servicegroup_proxy):
return diff_object return diff_object
def do_state_change(client, module, servicegroup_proxy):
if module.params['disabled']:
log('Disabling service')
result = servicegroup.disable(client, servicegroup_proxy.actual)
else:
log('Enabling service')
result = servicegroup.enable(client, servicegroup_proxy.actual)
return result
def main(): def main():
module_specific_arguments = dict( module_specific_arguments = dict(
@ -730,6 +750,10 @@ def main():
hand_inserted_arguments = dict( hand_inserted_arguments = dict(
servicemembers=dict(type='list'), servicemembers=dict(type='list'),
monitorbindings=dict(type='list'), monitorbindings=dict(type='list'),
disabled=dict(
type='bool',
default=False,
),
) )
argument_spec = dict() argument_spec = dict()
@ -912,6 +936,12 @@ def main():
client.save_config() client.save_config()
module_result['changed'] = True module_result['changed'] = True
if not module.check_mode:
res = do_state_change(client, module, servicegroup_proxy)
if res.errorcode != 0:
msg = 'Error when setting disabled state. errorcode: %s message: %s' % (res.errorcode, res.message)
module.fail_json(msg=msg, **module_result)
# Sanity check for state # Sanity check for state
if not module.check_mode: if not module.check_mode:
log('Sanity checks for state present') log('Sanity checks for state present')

View file

@ -0,0 +1,9 @@
---
- include: "{{ role_path }}/tests/nitro/flap_disabled/setup.yaml"
vars:
check_mode: no
- include: "{{ role_path }}/tests/nitro/flap_disabled/remove.yaml"
vars:
check_mode: no

View file

@ -0,0 +1,16 @@
---
- name: Remove servicegroup
delegate_to: localhost
register: result
check_mode: "{{ check_mode }}"
netscaler_servicegroup:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: absent
servicegroupname: service-group-1
servicetype: HTTP

View file

@ -0,0 +1,47 @@
---
- name: Flap servicegroup
delegate_to: localhost
register: result
check_mode: "{{ check_mode }}"
netscaler_servicegroup:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: present
servicegroupname: service-group-1
servicetype: HTTP
servicemembers:
- ip: 10.78.78.78
port: 80
weight: 100
disabled: "{{ item|int % 2 }}"
with_sequence: count=20
delay: 1
- name: Flap servicegroup
delegate_to: localhost
register: result
check_mode: "{{ check_mode }}"
netscaler_servicegroup:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: present
servicegroupname: service-group-1
servicetype: HTTP
servicemembers:
- ip: 10.78.78.78
port: 80
weight: 100
disabled: "{{ item|int % 2 }}"
with_sequence: count=20
delay: 5

View file

@ -163,6 +163,7 @@ class TestNetscalerServicegroupModule(TestModule):
ConfigProxy=m, ConfigProxy=m,
servicegroup_exists=servicegroup_exists_mock, servicegroup_exists=servicegroup_exists_mock,
servicemembers_identical=Mock(side_effect=[False, True]), servicemembers_identical=Mock(side_effect=[False, True]),
do_state_change=Mock(return_value=Mock(errorcode=0)),
nitro_exception=self.MockException, nitro_exception=self.MockException,
): ):
self.module = netscaler_servicegroup self.module = netscaler_servicegroup
@ -191,6 +192,7 @@ class TestNetscalerServicegroupModule(TestModule):
servicegroup_identical=servicegroup_identical_mock, servicegroup_identical=servicegroup_identical_mock,
monitor_bindings_identical=monitor_bindings_identical_mock, monitor_bindings_identical=monitor_bindings_identical_mock,
servicemembers_identical=Mock(side_effect=[True, True]), servicemembers_identical=Mock(side_effect=[True, True]),
do_state_change=Mock(return_value=Mock(errorcode=0)),
nitro_exception=self.MockException, nitro_exception=self.MockException,
): ):
self.module = netscaler_servicegroup self.module = netscaler_servicegroup
@ -222,6 +224,7 @@ class TestNetscalerServicegroupModule(TestModule):
nitro_exception=self.MockException, nitro_exception=self.MockException,
servicemembers_identical=Mock(side_effect=[True, True]), servicemembers_identical=Mock(side_effect=[True, True]),
sync_monitor_bindings=sync_monitor_bindings_mock, sync_monitor_bindings=sync_monitor_bindings_mock,
do_state_change=Mock(return_value=Mock(errorcode=0)),
): ):
self.module = netscaler_servicegroup self.module = netscaler_servicegroup
result = self.exited() result = self.exited()
@ -250,7 +253,7 @@ class TestNetscalerServicegroupModule(TestModule):
sync_monitor_bindings=Mock(), sync_monitor_bindings=Mock(),
servicemembers_identical=Mock(side_effect=[False, True]), servicemembers_identical=Mock(side_effect=[False, True]),
sync_service_members=sync_mock, sync_service_members=sync_mock,
do_state_change=Mock(return_value=Mock(errorcode=0)),
): ):
self.module = netscaler_servicegroup self.module = netscaler_servicegroup
result = self.exited() result = self.exited()
@ -304,7 +307,7 @@ class TestNetscalerServicegroupModule(TestModule):
servicemembers_identical=Mock(side_effect=[False, True]), servicemembers_identical=Mock(side_effect=[False, True]),
nitro_exception=self.MockException, nitro_exception=self.MockException,
sync_service_members=sync_mock, sync_service_members=sync_mock,
do_state_change=Mock(return_value=Mock(errorcode=0)),
): ):
self.module = netscaler_servicegroup self.module = netscaler_servicegroup
result = self.failed() result = self.failed()
@ -332,7 +335,7 @@ class TestNetscalerServicegroupModule(TestModule):
servicemembers_identical=Mock(side_effect=[False, True]), servicemembers_identical=Mock(side_effect=[False, True]),
nitro_exception=self.MockException, nitro_exception=self.MockException,
sync_service_members=sync_mock, sync_service_members=sync_mock,
do_state_change=Mock(return_value=Mock(errorcode=0)),
): ):
self.module = netscaler_servicegroup self.module = netscaler_servicegroup
result = self.failed() result = self.failed()
@ -360,7 +363,7 @@ class TestNetscalerServicegroupModule(TestModule):
servicemembers_identical=Mock(side_effect=[False, False]), servicemembers_identical=Mock(side_effect=[False, False]),
nitro_exception=self.MockException, nitro_exception=self.MockException,
sync_service_members=sync_mock, sync_service_members=sync_mock,
do_state_change=Mock(return_value=Mock(errorcode=0)),
): ):
self.module = netscaler_servicegroup self.module = netscaler_servicegroup
result = self.failed() result = self.failed()
@ -388,7 +391,7 @@ class TestNetscalerServicegroupModule(TestModule):
servicemembers_identical=Mock(side_effect=[True, True]), servicemembers_identical=Mock(side_effect=[True, True]),
nitro_exception=self.MockException, nitro_exception=self.MockException,
sync_service_members=sync_mock, sync_service_members=sync_mock,
do_state_change=Mock(return_value=Mock(errorcode=0)),
): ):
self.module = netscaler_servicegroup self.module = netscaler_servicegroup
result = self.failed() result = self.failed()
@ -415,6 +418,7 @@ class TestNetscalerServicegroupModule(TestModule):
servicegroup_identical=servicegroup_identical_mock, servicegroup_identical=servicegroup_identical_mock,
servicemembers_identical=Mock(side_effect=[True, True]), servicemembers_identical=Mock(side_effect=[True, True]),
monitor_bindings_identical=monitor_bindings_identical_mock, monitor_bindings_identical=monitor_bindings_identical_mock,
do_state_change=Mock(return_value=Mock(errorcode=0)),
nitro_exception=self.MockException, nitro_exception=self.MockException,
): ):
self.module = netscaler_servicegroup self.module = netscaler_servicegroup