Add ospf net type (#45904)

* Added ospf network type option to nxos_interface_ospf module

* Added documentation and example for the 'network' parameter

* adding version
This commit is contained in:
Dan 2018-09-25 07:08:39 +01:00 committed by Trishna Guha
parent d5f8738bf2
commit a6c20488d3
3 changed files with 28 additions and 1 deletions

View file

@ -36,6 +36,7 @@ notes:
- To remove an existing authentication configuration you should use
C(message_digest_key_id=default) plus all other options matching their
existing values.
- Loopback interfaces only support ospf network type 'point-to-point'.
- C(state=absent) removes the whole OSPF interface configuration.
options:
interface:
@ -69,6 +70,11 @@ options:
- Setting to true will prevent this interface from receiving
HELLO packets.
type: bool
network:
description:
- Specifies interface ospf network type. Valid values are 'point-to-point' or 'broadcast'.
choices: ['point-to-point', 'broadcast']
version_added: "2.8"
message_digest:
description:
- Enables or disables the usage of message digest authentication.
@ -105,6 +111,13 @@ EXAMPLES = '''
ospf: 1
area: 1
cost: default
- nxos_interface_ospf:
interface: loopback0
ospf: prod
area: 0.0.0.0
network: point-to-point
state: present
'''
RETURN = '''
@ -141,6 +154,7 @@ PARAM_TO_COMMAND_KEYMAP = {
'message_digest_algorithm_type': 'ip ospf message-digest-key',
'message_digest_encryption_type': 'ip ospf message-digest-key',
'message_digest_password': 'ip ospf message-digest-key',
'network': 'ip ospf network',
}
@ -249,6 +263,12 @@ def get_custom_command(existing_cmd, proposed, key, module):
if command not in existing_cmd:
commands.append(command)
if key == 'ip ospf network':
command = '{0} {1}'.format(key, proposed['network'])
if command not in existing_cmd:
commands.append(command)
elif key.startswith('ip ospf message-digest-key'):
if (proposed['message_digest_key_id'] != 'default' and
'options' not in key):
@ -281,6 +301,8 @@ def state_present(module, existing, proposed, candidate):
if key == 'ip ospf passive-interface' and module.params.get('interface').upper().startswith('LO'):
module.fail_json(msg='loopback interface does not support passive_interface')
if key == 'ip ospf network' and value == 'broadcast' and module.params.get('interface').upper().startswith('LO'):
module.fail_json(msg='loopback interface does not support ospf network type broadcast')
if value is True:
commands.append(key)
elif value is False:
@ -325,7 +347,7 @@ def state_absent(module, existing, proposed, candidate):
existing['message_digest_password'])
commands.append(command)
elif key in ['ip ospf authentication message-digest',
'ip ospf passive-interface']:
'ip ospf passive-interface', 'ip ospf network']:
if value:
commands.append('no {0}'.format(key))
elif key == 'ip router ospf':
@ -359,6 +381,7 @@ def main():
hello_interval=dict(required=False, type='str'),
dead_interval=dict(required=False, type='str'),
passive_interface=dict(required=False, type='bool'),
network=dict(required=False, type='str', choices=['broadcast', 'point-to-point']),
message_digest=dict(required=False, type='bool'),
message_digest_key_id=dict(required=False, type='str'),
message_digest_algorithm_type=dict(required=False, type='str', choices=['md5', 'default']),

View file

@ -55,6 +55,7 @@
passive_interface: true
hello_interval: 15
dead_interval: 75
network: point-to-point
provider: "{{ connection }}"
state: present
register: result
@ -80,6 +81,7 @@
passive_interface: false
hello_interval: 17
dead_interval: 70
network: broadcast
provider: "{{ connection }}"
state: present
register: result

View file

@ -54,3 +54,5 @@ class TestNxosInterfaceOspfModule(TestNxosModule):
def test_loopback_interface_failed(self):
set_module_args(dict(interface='loopback0', ospf=1, area=0, passive_interface=True))
self.execute_module(failed=True, changed=False)
set_module_args(dict(interface='loopback0', ospf=1, area=0, network='broadcast'))
self.execute_module(failed=True, changed=False)