mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Add lldp nighbors intent arg support for junos_interface (#29057)
* Add lldp neighbor state arg for junos_interfaces * minor change
This commit is contained in:
parent
91e7c3ec81
commit
49658f9437
1 changed files with 42 additions and 1 deletions
|
@ -50,6 +50,17 @@ options:
|
||||||
rx_rate:
|
rx_rate:
|
||||||
description:
|
description:
|
||||||
- Receiver rate in bits per second (bps).
|
- Receiver rate in bits per second (bps).
|
||||||
|
neighbors:
|
||||||
|
description:
|
||||||
|
- Check the operational state of given interface C(name) for LLDP neighbor.
|
||||||
|
- The following suboptions are available.
|
||||||
|
suboptions:
|
||||||
|
host:
|
||||||
|
description:
|
||||||
|
- "LLDP neighbor host for given interface C(name)."
|
||||||
|
port:
|
||||||
|
description:
|
||||||
|
- "LLDP neighbor port to which given interface C(name) is connected."
|
||||||
delay:
|
delay:
|
||||||
description:
|
description:
|
||||||
- Time in seconds to wait before checking for the operational state on remote
|
- Time in seconds to wait before checking for the operational state on remote
|
||||||
|
@ -142,6 +153,13 @@ EXAMPLES = """
|
||||||
tx_rate: ge(0)
|
tx_rate: ge(0)
|
||||||
rx_rate: le(0)
|
rx_rate: le(0)
|
||||||
|
|
||||||
|
- name: Check neighbor intent
|
||||||
|
junos_interface:
|
||||||
|
name: xe-0/1/1
|
||||||
|
neighbors:
|
||||||
|
- port: Ethernet1/0/1
|
||||||
|
host: netdev
|
||||||
|
|
||||||
- name: Config + intent
|
- name: Config + intent
|
||||||
junos_interface:
|
junos_interface:
|
||||||
name: "{{ name }}"
|
name: "{{ name }}"
|
||||||
|
@ -199,6 +217,11 @@ def validate_param_values(module, obj, param=None):
|
||||||
def main():
|
def main():
|
||||||
""" main entry point for module execution
|
""" main entry point for module execution
|
||||||
"""
|
"""
|
||||||
|
neighbors_spec = dict(
|
||||||
|
host=dict(),
|
||||||
|
port=dict()
|
||||||
|
)
|
||||||
|
|
||||||
element_spec = dict(
|
element_spec = dict(
|
||||||
name=dict(),
|
name=dict(),
|
||||||
description=dict(),
|
description=dict(),
|
||||||
|
@ -208,6 +231,7 @@ def main():
|
||||||
duplex=dict(choices=['full', 'half', 'auto']),
|
duplex=dict(choices=['full', 'half', 'auto']),
|
||||||
tx_rate=dict(),
|
tx_rate=dict(),
|
||||||
rx_rate=dict(),
|
rx_rate=dict(),
|
||||||
|
neighbors=dict(type='list', elements='dict', options=neighbors_spec),
|
||||||
delay=dict(default=10, type='int'),
|
delay=dict(default=10, type='int'),
|
||||||
state=dict(default='present', choices=['present', 'absent', 'up', 'down']),
|
state=dict(default='present', choices=['present', 'absent', 'up', 'down']),
|
||||||
active=dict(default=True, type='bool')
|
active=dict(default=True, type='bool')
|
||||||
|
@ -296,12 +320,14 @@ def main():
|
||||||
result['diff'] = {'prepared': diff}
|
result['diff'] = {'prepared': diff}
|
||||||
|
|
||||||
failed_conditions = []
|
failed_conditions = []
|
||||||
|
neighbors = None
|
||||||
for item in params:
|
for item in params:
|
||||||
state = item.get('state')
|
state = item.get('state')
|
||||||
tx_rate = item.get('tx_rate')
|
tx_rate = item.get('tx_rate')
|
||||||
rx_rate = item.get('rx_rate')
|
rx_rate = item.get('rx_rate')
|
||||||
|
want_neighbors = item.get('neighbors')
|
||||||
|
|
||||||
if state not in ('up', 'down') and tx_rate is None and rx_rate is None:
|
if state not in ('up', 'down') and tx_rate is None and rx_rate is None and want_neighbors is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
element = Element('get-interface-information')
|
element = Element('get-interface-information')
|
||||||
|
@ -328,6 +354,21 @@ def main():
|
||||||
if not input_bps or not conditional(rx_rate, input_bps[0].text.strip(), cast=int):
|
if not input_bps or not conditional(rx_rate, input_bps[0].text.strip(), cast=int):
|
||||||
failed_conditions.append('rx_rate ' + rx_rate)
|
failed_conditions.append('rx_rate ' + rx_rate)
|
||||||
|
|
||||||
|
if want_neighbors:
|
||||||
|
if neighbors is None:
|
||||||
|
element = Element('get-lldp-interface-neighbors')
|
||||||
|
intf_name = SubElement(element, 'interface-device')
|
||||||
|
intf_name.text = item.get('name')
|
||||||
|
|
||||||
|
reply = send_request(module, element, ignore_warning=False)
|
||||||
|
have_host = [item.text for item in reply.xpath('lldp-neighbors-information/lldp-neighbor-information/lldp-remote-system-name')]
|
||||||
|
have_port = [item.text for item in reply.xpath('lldp-neighbors-information/lldp-neighbor-information/lldp-remote-port-id')]
|
||||||
|
|
||||||
|
for neighbor in want_neighbors:
|
||||||
|
if neighbor['host'] not in have_host:
|
||||||
|
failed_conditions.append('host ' + neighbor['host'])
|
||||||
|
if neighbor['port'] not in have_port:
|
||||||
|
failed_conditions.append('port ' + neighbor['port'])
|
||||||
if failed_conditions:
|
if failed_conditions:
|
||||||
msg = 'One or more conditional statements have not be satisfied'
|
msg = 'One or more conditional statements have not be satisfied'
|
||||||
module.fail_json(msg=msg, failed_conditions=failed_conditions)
|
module.fail_json(msg=msg, failed_conditions=failed_conditions)
|
||||||
|
|
Loading…
Reference in a new issue