Add enable, disable operation in netscaler_service (#28321)

This commit is contained in:
George Nikolopoulos 2017-08-25 18:58:51 +03:00 committed by John R Barker
parent fbeb3b9ac5
commit 2281a6676b
7 changed files with 115 additions and 8 deletions

View file

@ -356,6 +356,16 @@ options:
description:
- Weight to assign to the binding between the monitor and service.
disabled:
description:
- When set to C(yes) the service state will be set to DISABLED.
- When set to C(no) the service 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
requirements:
- nitro python sdk
@ -538,6 +548,16 @@ def all_identical(client, module, service_proxy, monitor_bindings_rw_attrs):
return service_identical(client, module, service_proxy) and monitor_bindings_identical(client, module, monitor_bindings_rw_attrs)
def do_state_change(client, module, service_proxy):
if module.params['disabled']:
log('Disabling service')
result = service.disable(client, service_proxy.actual)
else:
log('Enabling service')
result = service.enable(client, service_proxy.actual)
return result
def main():
module_specific_arguments = dict(
@ -675,6 +695,10 @@ def main():
hand_inserted_arguments = dict(
monitor_bindings=dict(type='list'),
disabled=dict(
type='bool',
default=False,
),
)
argument_spec = dict()
@ -883,6 +907,12 @@ def main():
else:
module_result['changed'] = False
if not module.check_mode:
res = do_state_change(client, module, service_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
if not module.check_mode:
log('Sanity checks for state present')

View file

@ -0,0 +1,10 @@
---
- 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 htttp service
netscaler_service:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: absent
name: service-http
delegate_to: localhost
register: result
check_mode: "{{ check_mode }}"

View file

@ -0,0 +1,47 @@
---
- name: Flap service
netscaler_service:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: present
name: service-http
ip: 192.168.1.1
ipaddress: 192.168.1.1
port: 80
servicetype: HTTP
disabled: "{{ item|int % 2 }}"
with_sequence: count=20
delay: 1
delegate_to: localhost
register: result
check_mode: "{{ check_mode }}"
- name: Flap service
netscaler_service:
nitro_user: "{{nitro_user}}"
nitro_pass: "{{nitro_pass}}"
nsip: "{{nsip}}"
state: present
name: service-http
ip: 192.168.1.1
ipaddress: 192.168.1.1
port: 80
servicetype: HTTP
disabled: "{{ item|int % 2 }}"
with_sequence: count=20
delay: 5
delegate_to: localhost
register: result
check_mode: "{{ check_mode }}"

View file

@ -19,7 +19,7 @@
healthmonitor: no
maxreq: 200
cacheable: no
cip: ENABLED
cip: enabled
cipheader: client-ip
usip: yes
useproxyport: yes
@ -34,11 +34,11 @@
maxbandwidth: 10000
accessdown: "NO"
monthreshold: 100
downstateflush: ENABLED
downstateflush: enabled
hashid: 10
comment: some comment
appflowlog: ENABLED
processlocal: ENABLED
appflowlog: enabled
processlocal: enabled
graceful: no
monitor_bindings:

View file

@ -19,7 +19,7 @@
healthmonitor: no
maxreq: 200
cacheable: no
cip: ENABLED
cip: enabled
cipheader: client-ip
usip: yes
useproxyport: yes
@ -34,11 +34,11 @@
maxbandwidth: 20000
accessdown: "NO"
monthreshold: 100
downstateflush: ENABLED
downstateflush: enabled
hashid: 10
comment: some comment
appflowlog: ENABLED
processlocal: ENABLED
appflowlog: enabled
processlocal: enabled
monitor_bindings:
- monitorname: http

View file

@ -162,6 +162,7 @@ class TestNetscalerServiceModule(TestModule):
'ansible.modules.network.netscaler.netscaler_service',
ConfigProxy=m,
service_exists=service_exists_mock,
do_state_change=Mock(return_value=Mock(errorcode=0)),
):
self.module = netscaler_service
result = self.exited()
@ -190,6 +191,7 @@ class TestNetscalerServiceModule(TestModule):
service_identical=service_identical_mock,
monitor_bindings_identical=monitor_bindings_identical_mock,
all_identical=all_identical_mock,
do_state_change=Mock(return_value=Mock(errorcode=0)),
):
self.module = netscaler_service
result = self.exited()
@ -220,6 +222,7 @@ class TestNetscalerServiceModule(TestModule):
monitor_bindings_identical=monitor_bindings_identical_mock,
all_identical=all_identical_mock,
sync_monitor_bindings=sync_monitor_bindings_mock,
do_state_change=Mock(return_value=Mock(errorcode=0)),
):
self.module = netscaler_service
result = self.exited()
@ -247,6 +250,7 @@ class TestNetscalerServiceModule(TestModule):
service_exists=service_exists_mock,
service_identical=service_identical_mock,
monitor_bindings_identical=monitor_bindings_identical_mock,
do_state_change=Mock(return_value=Mock(errorcode=0)),
):
self.module = netscaler_service
result = self.exited()