diff options
author | Ansible Core Team <info@ansible.com> | 2020-03-09 09:40:37 +0000 |
---|---|---|
committer | Ansible Core Team <info@ansible.com> | 2020-03-09 09:40:37 +0000 |
commit | 64ce847c6172d65ee9a86e226d1a5ba9c206f722 (patch) | |
tree | 1dfdf178457be6fcedfac83ac28e39af574788f2 | |
parent | b6d1e433093cb6c26783baa9b89bb44595a3db04 (diff) | |
download | ansible-64ce847c6172d65ee9a86e226d1a5ba9c206f722.tar.gz |
Migrated to vyos.vyos
334 files changed, 0 insertions, 31406 deletions
diff --git a/lib/ansible/module_utils/network/vyos/argspec/facts/facts.py b/lib/ansible/module_utils/network/vyos/argspec/facts/facts.py deleted file mode 100644 index 3a33f31914..0000000000 --- a/lib/ansible/module_utils/network/vyos/argspec/facts/facts.py +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -""" -The arg spec for the vyos facts module. -""" -from __future__ import absolute_import, division, print_function -__metaclass__ = type - - -class FactsArgs(object): # pylint: disable=R0903 - """ The arg spec for the vyos facts module - """ - - def __init__(self, **kwargs): - pass - - argument_spec = { - 'gather_subset': dict(default=['!config'], type='list'), - 'gather_network_resources': dict(type='list'), - } diff --git a/lib/ansible/module_utils/network/vyos/argspec/firewall_global/firewall_global.py b/lib/ansible/module_utils/network/vyos/argspec/firewall_global/firewall_global.py deleted file mode 100644 index bea4d61a2a..0000000000 --- a/lib/ansible/module_utils/network/vyos/argspec/firewall_global/firewall_global.py +++ /dev/null @@ -1,197 +0,0 @@ -# -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -############################################# -# WARNING # -############################################# -# -# This file is auto generated by the resource -# module builder playbook. -# -# Do not edit this file manually. -# -# Changes to this file will be over written -# by the resource module builder. -# -# Changes should be made in the model used to -# generate this file or in the resource module -# builder template. -# -############################################# -""" -The arg spec for the vyos_firewall_global module -""" - -from __future__ import absolute_import, division, print_function -__metaclass__ = type - - -class Firewall_globalArgs(object): # pylint: disable=R0903 - """The arg spec for the vyos_firewall_global module - """ - def __init__(self, **kwargs): - pass - - argument_spec = { - 'config': { - 'options': { - 'config_trap': { - 'type': 'bool' - }, - 'group': { - 'options': { - 'address_group': { - 'elements': 'dict', - 'options': { - 'description': { - 'type': 'str' - }, - 'members': { - 'elements': 'dict', - 'options': { - 'address': { - 'type': 'str' - } - }, - 'type': 'list' - }, - 'name': { - 'required': True, - 'type': 'str' - } - }, - 'type': 'list' - }, - 'network_group': { - 'elements': 'dict', - 'options': { - 'description': { - 'type': 'str' - }, - 'members': { - 'elements': 'dict', - 'options': { - 'address': { - 'type': 'str' - } - }, - 'type': 'list' - }, - 'name': { - 'required': True, - 'type': 'str' - } - }, - 'type': 'list' - }, - 'port_group': { - 'elements': 'dict', - 'options': { - 'description': { - 'type': 'str' - }, - 'members': { - 'elements': 'dict', - 'options': { - 'port': { - 'type': 'str' - } - }, - 'type': 'list' - }, - 'name': { - 'required': True, - 'type': 'str' - } - }, - 'type': 'list' - } - }, - 'type': 'dict' - }, - 'log_martians': { - 'type': 'bool' - }, - 'ping': { - 'options': { - 'all': { - 'type': 'bool' - }, - 'broadcast': { - 'type': 'bool' - } - }, - 'type': 'dict' - }, - 'route_redirects': { - 'elements': 'dict', - 'options': { - 'afi': { - 'choices': ['ipv4', 'ipv6'], - 'required': True, - 'type': 'str' - }, - 'icmp_redirects': { - 'options': { - 'receive': { - 'type': 'bool' - }, - 'send': { - 'type': 'bool' - } - }, - 'type': 'dict' - }, - 'ip_src_route': { - 'type': 'bool' - } - }, - 'type': 'list' - }, - 'state_policy': { - 'elements': 'dict', - 'options': { - 'action': { - 'choices': ['accept', 'drop', 'reject'], - 'type': 'str' - }, - 'connection_type': { - 'choices': ['established', 'invalid', 'related'], - 'type': 'str' - }, - 'log': { - 'type': 'bool' - } - }, - 'type': 'list' - }, - 'syn_cookies': { - 'type': 'bool' - }, - 'twa_hazards_protection': { - 'type': 'bool' - }, - 'validation': { - 'choices': ['strict', 'loose', 'disable'], - 'type': 'str' - } - }, - 'type': 'dict' - }, - 'running_config': { - 'type': 'str' - }, - 'state': { - 'choices': [ - 'merged', 'replaced', 'deleted', 'gathered', 'rendered', - 'parsed' - ], - 'default': - 'merged', - 'type': - 'str' - } - } # pylint: disable=C0301 diff --git a/lib/ansible/module_utils/network/vyos/argspec/firewall_interfaces/firewall_interfaces.py b/lib/ansible/module_utils/network/vyos/argspec/firewall_interfaces/firewall_interfaces.py deleted file mode 100644 index 604bf64817..0000000000 --- a/lib/ansible/module_utils/network/vyos/argspec/firewall_interfaces/firewall_interfaces.py +++ /dev/null @@ -1,85 +0,0 @@ -# -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -############################################# -# WARNING # -############################################# -# -# This file is auto generated by the resource -# module builder playbook. -# -# Do not edit this file manually. -# -# Changes to this file will be over written -# by the resource module builder. -# -# Changes should be made in the model used to -# generate this file or in the resource module -# builder template. -# -############################################# -""" -The arg spec for the vyos_firewall_interfaces module -""" - -from __future__ import absolute_import, division, print_function -__metaclass__ = type - - -class Firewall_interfacesArgs(object): # pylint: disable=R0903 - """The arg spec for the vyos_firewall_interfaces module - """ - def __init__(self, **kwargs): - pass - - argument_spec = { - 'config': { - 'elements': 'dict', - 'options': { - 'access_rules': { - 'elements': 'dict', - 'options': { - 'afi': { - 'choices': ['ipv4', 'ipv6'], - 'required': True, - 'type': 'str' - }, - 'rules': { - 'elements': 'dict', - 'options': { - 'direction': { - 'choices': ['in', 'local', 'out'], - 'required': True, - 'type': 'str' - }, - 'name': { - 'type': 'str' - } - }, - 'type': 'list' - } - }, - 'type': 'list' - }, - 'name': { - 'required': True, - 'type': 'str' - } - }, - 'type': 'list' - }, - 'running_config': {'type': 'str'}, - 'state': { - 'choices': [ - 'merged', 'replaced', 'overridden', 'deleted', 'parsed', - 'rendered', 'gathered' - ], - 'default': - 'merged', - 'type': - 'str' - } - } # pylint: disable=C0301 diff --git a/lib/ansible/module_utils/network/vyos/argspec/firewall_rules/firewall_rules.py b/lib/ansible/module_utils/network/vyos/argspec/firewall_rules/firewall_rules.py deleted file mode 100644 index fed2eede07..0000000000 --- a/lib/ansible/module_utils/network/vyos/argspec/firewall_rules/firewall_rules.py +++ /dev/null @@ -1,318 +0,0 @@ -# -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -############################################# -# WARNING # -############################################# -# -# This file is auto generated by the resource -# module builder playbook. -# -# Do not edit this file manually. -# -# Changes to this file will be over written -# by the resource module builder. -# -# Changes should be made in the model used to -# generate this file or in the resource module -# builder template. -# -############################################# -""" -The arg spec for the vyos_firewall_rules module -""" - -from __future__ import absolute_import, division, print_function -__metaclass__ = type - - -class Firewall_rulesArgs(object): # pylint: disable=R0903 - """The arg spec for the vyos_firewall_rules module - """ - def __init__(self, **kwargs): - pass - - argument_spec = { - 'config': { - 'elements': 'dict', - 'options': { - 'afi': { - 'choices': ['ipv4', 'ipv6'], - 'required': True, - 'type': 'str' - }, - 'rule_sets': { - 'elements': 'dict', - 'options': { - 'default_action': { - 'choices': ['drop', 'reject', 'accept'], - 'type': 'str' - }, - 'description': { - 'type': 'str' - }, - 'enable_default_log': { - 'type': 'bool' - }, - 'name': { - 'type': 'str' - }, - 'rules': { - 'elements': 'dict', - 'options': { - 'action': { - 'choices': - ['drop', 'reject', 'accept', 'inspect'], - 'type': - 'str' - }, - 'description': { - 'type': 'str' - }, - 'destination': { - 'options': { - 'address': { - 'type': 'str' - }, - 'group': { - 'options': { - 'address_group': { - 'type': 'str' - }, - 'network_group': { - 'type': 'str' - }, - 'port_group': { - 'type': 'str' - } - }, - 'type': 'dict' - }, - 'port': { - 'type': 'str' - } - }, - 'type': 'dict' - }, - 'disabled': { - 'type': 'bool' - }, - 'fragment': { - 'choices': - ['match-frag', 'match-non-frag'], - 'type': 'str' - }, - 'icmp': { - 'options': { - 'code': { - 'type': 'int' - }, - 'type': { - 'type': 'int' - }, - 'type_name': { - 'choices': [ - 'any', 'echo-reply', - 'destination-unreachable', - 'network-unreachable', - 'host-unreachable', - 'protocol-unreachable', - 'port-unreachable', - 'fragmentation-needed', - 'source-route-failed', - 'network-unknown', - 'host-unknown', - 'network-prohibited', - 'host-prohibited', - 'TOS-network-unreachable', - 'TOS-host-unreachable', - 'communication-prohibited', - 'host-precedence-violation', - 'precedence-cutoff', - 'source-quench', 'redirect', - 'network-redirect', - 'host-redirect', - 'TOS-network-redirect', - 'TOS-host-redirect', - 'echo-request', - 'router-advertisement', - 'router-solicitation', - 'time-exceeded', - 'ttl-zero-during-transit', - 'ttl-zero-during-reassembly', - 'parameter-problem', - 'ip-header-bad', - 'required-option-missing', - 'timestamp-request', - 'timestamp-reply', - 'address-mask-request', - 'address-mask-reply', 'ping', - 'pong', 'ttl-exceeded' - ], - 'type': - 'str' - } - }, - 'type': 'dict' - }, - 'ipsec': { - 'choices': ['match-ipsec', 'match-none'], - 'type': 'str' - }, - 'limit': { - 'options': { - 'burst': { - 'type': 'int' - }, - 'rate': { - 'options': { - 'number': { - 'type': 'int' - }, - 'unit': { - 'type': 'str' - } - }, - 'type': 'dict' - } - }, - 'type': 'dict' - }, - 'number': { - 'required': True, - 'type': 'int' - }, - 'p2p': { - 'elements': 'dict', - 'options': { - 'application': { - 'choices': [ - 'all', 'applejuice', - 'bittorrent', 'directconnect', - 'edonkey', 'gnutella', 'kazaa' - ], - 'type': - 'str' - } - }, - 'type': 'list' - }, - 'protocol': { - 'type': 'str' - }, - 'recent': { - 'options': { - 'count': { - 'type': 'int' - }, - 'time': { - 'type': 'int' - } - }, - 'type': 'dict' - }, - 'source': { - 'options': { - 'address': { - 'type': 'str' - }, - 'group': { - 'options': { - 'address_group': { - 'type': 'str' - }, - 'network_group': { - 'type': 'str' - }, - 'port_group': { - 'type': 'str' - } - }, - 'type': 'dict' - }, - 'mac_address': { - 'type': 'str' - }, - 'port': { - 'type': 'str' - } - }, - 'type': 'dict' - }, - 'state': { - 'options': { - 'established': { - 'type': 'bool' - }, - 'invalid': { - 'type': 'bool' - }, - 'new': { - 'type': 'bool' - }, - 'related': { - 'type': 'bool' - } - }, - 'type': 'dict' - }, - 'tcp': { - 'options': { - 'flags': { - 'type': 'str' - } - }, - 'type': 'dict' - }, - 'time': { - 'options': { - 'monthdays': { - 'type': 'str' - }, - 'startdate': { - 'type': 'str' - }, - 'starttime': { - 'type': 'str' - }, - 'stopdate': { - 'type': 'str' - }, - 'stoptime': { - 'type': 'str' - }, - 'utc': { - 'type': 'bool' - }, - 'weekdays': { - 'type': 'str' - } - }, - 'type': 'dict' - } - }, - 'type': 'list' - } - }, - 'type': 'list' - } - }, - 'type': 'list' - }, - 'running_config': { - 'type': 'str' - }, - 'state': { - 'choices': [ - 'merged', 'replaced', 'overridden', 'deleted', 'gathered', - 'rendered', 'parsed' - ], - 'default': - 'merged', - 'type': - 'str' - } - } # pylint: disable=C0301 diff --git a/lib/ansible/module_utils/network/vyos/argspec/interfaces/interfaces.py b/lib/ansible/module_utils/network/vyos/argspec/interfaces/interfaces.py deleted file mode 100644 index d6ab446558..0000000000 --- a/lib/ansible/module_utils/network/vyos/argspec/interfaces/interfaces.py +++ /dev/null @@ -1,67 +0,0 @@ -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -############################################# -# WARNING # -############################################# -# -# This file is auto generated by the resource -# module builder playbook. -# -# Do not edit this file manually. -# -# Changes to this file will be over written -# by the resource module builder. -# -# Changes should be made in the model used to -# generate this file or in the resource module -# builder template. -# -############################################# -""" -The arg spec for the vyos_interfaces module -""" - -from __future__ import absolute_import, division, print_function -__metaclass__ = type - - -class InterfacesArgs(object): # pylint: disable=R0903 - """The arg spec for the vyos_interfaces module - """ - - def __init__(self, **kwargs): - pass - - argument_spec = \ - { - 'config': { - 'elements': 'dict', - 'options': { - 'description': {'type': 'str'}, - 'duplex': {'choices': ['full', 'half', 'auto']}, - 'enabled': {'default': True, 'type': 'bool'}, - 'mtu': {'type': 'int'}, - 'name': {'required': True, 'type': 'str'}, - 'speed': {'choices': ['auto', '10', '100', '1000', '2500', - '10000'], - 'type': 'str'}, - 'vifs': { - 'elements': 'dict', - 'options': { - 'vlan_id': {'type': 'int'}, - 'description': {'type': 'str'}, - 'enabled': {'default': True, 'type': 'bool'}, - 'mtu': {'type': 'int'} - }, - 'type': 'list' - }, - }, - 'type': 'list' - }, - 'state': {'choices': ['merged', 'replaced', - 'overridden', 'deleted'], - 'default': 'merged', - 'type': 'str'} - } # pylint: disable=C0301 diff --git a/lib/ansible/module_utils/network/vyos/argspec/l3_interfaces/l3_interfaces.py b/lib/ansible/module_utils/network/vyos/argspec/l3_interfaces/l3_interfaces.py deleted file mode 100644 index e5785a8308..0000000000 --- a/lib/ansible/module_utils/network/vyos/argspec/l3_interfaces/l3_interfaces.py +++ /dev/null @@ -1,101 +0,0 @@ -# -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -############################################# -# WARNING # -############################################# -# -# This file is auto generated by the resource -# module builder playbook. -# -# Do not edit this file manually. -# -# Changes to this file will be over written -# by the resource module builder. -# -# Changes should be made in the model used to -# generate this file or in the resource module -# builder template. -# -############################################# -""" -The arg spec for the vyos_l3_interfaces module -""" - - -from __future__ import absolute_import, division, print_function -__metaclass__ = type - - -class L3_interfacesArgs(object): # pylint: disable=R0903 - """The arg spec for the vyos_l3_interfaces module - """ - - def __init__(self, **kwargs): - pass - - argument_spec = { - 'config': { - 'elements': 'dict', - 'options': { - 'ipv4': { - 'elements': 'dict', - 'options': { - 'address': { - 'type': 'str' - } - }, - 'type': 'list' - }, - 'ipv6': { - 'elements': 'dict', - 'options': { - 'address': { - 'type': 'str' - } - }, - 'type': 'list' - }, - 'name': { - 'required': True, - 'type': 'str' - }, - 'vifs': { - 'elements': 'dict', - 'options': { - 'ipv4': { - 'elements': 'dict', - 'options': { - 'address': { - 'type': 'str' - } - }, - 'type': 'list' - }, - 'ipv6': { - 'elements': 'dict', - 'options': { - 'address': { - 'type': 'str' - } - }, - 'type': 'list' - }, - 'vlan_id': { - 'type': 'int' - } - }, - 'type': 'list' - } - }, - 'type': 'list' - }, - 'state': { - 'choices': ['merged', 'replaced', 'overridden', 'deleted'], - 'default': 'merged', - 'type': 'str' - } - } # pylint: disable=C0301 diff --git a/lib/ansible/module_utils/network/vyos/argspec/lag_interfaces/lag_interfaces.py b/lib/ansible/module_utils/network/vyos/argspec/lag_interfaces/lag_interfaces.py deleted file mode 100644 index 25317e69b4..0000000000 --- a/lib/ansible/module_utils/network/vyos/argspec/lag_interfaces/lag_interfaces.py +++ /dev/null @@ -1,68 +0,0 @@ -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -############################################# -# WARNING # -############################################# -# -# This file is auto generated by the resource -# module builder playbook. -# -# Do not edit this file manually. -# -# Changes to this file will be over written -# by the resource module builder. -# -# Changes should be made in the model used to -# generate this file or in the resource module -# builder template. -# -############################################# - -""" -The arg spec for the vyos_lag_interfaces module -""" -from __future__ import absolute_import, division, print_function -__metaclass__ = type - - -class Lag_interfacesArgs(object): # pylint: disable=R0903 - """The arg spec for the vyos_lag_interfaces module - """ - - def __init__(self, **kwargs): - pass - - argument_spec = \ - { - 'config': { - 'elements': 'dict', - 'options': { - 'arp_monitor': { - 'options': { - 'interval': {'type': 'int'}, - 'target': {'type': 'list'} - }, - 'type': 'dict'}, - 'hash_policy': {'choices': ['layer2', 'layer2+3', 'layer3+4'], - 'type': 'str'}, - 'members': {'elements': 'dict', 'options': { - 'member': {'type': 'str'}}, 'type': 'list'}, - 'mode': {'choices': ['802.3ad', - 'active-backup', - 'broadcast', - 'round-robin', - 'transmit-load-balance', - 'adaptive-load-balance', - 'xor-hash'], - 'type': 'str'}, - 'name': {'required': True, 'type': 'str'}, - 'primary': {'type': 'str'} - }, - 'type': 'list' - }, - 'state': {'choices': ['merged', 'replaced', 'overridden', 'deleted'], - 'default': 'merged', - 'type': 'str'} - } # pylint: disable=C0301 diff --git a/lib/ansible/module_utils/network/vyos/argspec/lldp_global/lldp_global.py b/lib/ansible/module_utils/network/vyos/argspec/lldp_global/lldp_global.py deleted file mode 100644 index 4582c2307c..0000000000 --- a/lib/ansible/module_utils/network/vyos/argspec/lldp_global/lldp_global.py +++ /dev/null @@ -1,61 +0,0 @@ -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -############################################# -# WARNING # -############################################# -# -# This file is auto generated by the resource -# module builder playbook. -# -# Do not edit this file manually. -# -# Changes to this file will be over written -# by the resource module builder. -# -# Changes should be made in the model used to -# generate this file or in the resource module -# builder template. -# -############################################# - -""" -The arg spec for the vyos_lldp_global module -""" -from __future__ import absolute_import, division, print_function -__metaclass__ = type - - -class Lldp_globalArgs(object): # pylint: disable=R0903 - """The arg spec for the vyos_lldp_global module - """ - - def __init__(self, **kwargs): - pass - - argument_spec = { - 'config': { - 'options': { - 'address': { - 'type': 'str' - }, - 'enable': { - 'type': 'bool' - }, - 'legacy_protocols': { - 'choices': ['cdp', 'edp', 'fdp', 'sonmp'], - 'type': 'list' - }, - 'snmp': { - 'type': 'str' - } - }, - 'type': 'dict' - }, - 'state': { - 'choices': ['merged', 'replaced', 'deleted'], - 'default': 'merged', - 'type': 'str' - } - } # pylint: disable=C0301 diff --git a/lib/ansible/module_utils/network/vyos/argspec/lldp_interfaces/lldp_interfaces.py b/lib/ansible/module_utils/network/vyos/argspec/lldp_interfaces/lldp_interfaces.py deleted file mode 100644 index 29558a6c3e..0000000000 --- a/lib/ansible/module_utils/network/vyos/argspec/lldp_interfaces/lldp_interfaces.py +++ /dev/null @@ -1,107 +0,0 @@ -# -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -############################################# -# WARNING # -############################################# -# -# This file is auto generated by the resource -# module builder playbook. -# -# Do not edit this file manually. -# -# Changes to this file will be over written -# by the resource module builder. -# -# Changes should be made in the model used to -# generate this file or in the resource module -# builder template. -# -############################################# -""" -The arg spec for the vyos_lldp_interfaces module -""" - -from __future__ import absolute_import, division, print_function -__metaclass__ = type - - -class Lldp_interfacesArgs(object): # pylint: disable=R0903 - """The arg spec for the vyos_lldp_interfaces module - """ - def __init__(self, **kwargs): - pass - - argument_spec = { - 'config': { - 'elements': 'dict', - 'options': { - 'enable': { - 'default': True, - 'type': 'bool' - }, - 'location': { - 'options': { - 'civic_based': { - 'options': { - 'ca_info': { - 'elements': 'dict', - 'options': { - 'ca_type': { - 'type': 'int' - }, - 'ca_value': { - 'type': 'str' - } - }, - 'type': 'list' - }, - 'country_code': { - 'required': True, - 'type': 'str' - } - }, - 'type': 'dict' - }, - 'coordinate_based': { - 'options': { - 'altitude': { - 'type': 'int' - }, - 'datum': { - 'choices': ['WGS84', 'NAD83', 'MLLW'], - 'type': 'str' - }, - 'latitude': { - 'required': True, - 'type': 'str' - }, - 'longitude': { - 'required': True, - 'type': 'str' - } - }, - 'type': 'dict' - }, - 'elin': { - 'type': 'str' - } - }, - 'type': 'dict' - }, - 'name': { - 'required': True, - 'type': 'str' - } - }, - 'type': 'list' - }, - 'state': { - 'choices': ['merged', 'replaced', 'overridden', 'deleted'], - 'default': 'merged', - 'type': 'str' - } - } # pylint: disable=C0301 diff --git a/lib/ansible/module_utils/network/vyos/argspec/static_routes/static_routes.py b/lib/ansible/module_utils/network/vyos/argspec/static_routes/static_routes.py deleted file mode 100644 index 1042d6d31a..0000000000 --- a/lib/ansible/module_utils/network/vyos/argspec/static_routes/static_routes.py +++ /dev/null @@ -1,107 +0,0 @@ -# -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -############################################# -# WARNING # -############################################# -# -# This file is auto generated by the resource -# module builder playbook. -# -# Do not edit this file manually. -# -# Changes to this file will be over written -# by the resource module builder. -# -# Changes should be made in the model used to -# generate this file or in the resource module -# builder template. -# -############################################# -""" -The arg spec for the vyos_static_routes module -""" - -from __future__ import absolute_import, division, print_function -__metaclass__ = type - - -class Static_routesArgs(object): # pylint: disable=R0903 - """The arg spec for the vyos_static_routes module - """ - def __init__(self, **kwargs): - pass - - argument_spec = { - 'config': { - 'elements': 'dict', - 'options': { - 'address_families': { - 'elements': 'dict', - 'options': { - 'afi': { - 'choices': ['ipv4', 'ipv6'], - 'required': True, - 'type': 'str' - }, - 'routes': { - 'elements': 'dict', - 'options': { - 'blackhole_config': { - 'options': { - 'distance': { - 'type': 'int' - }, - 'type': { - 'type': 'str' - } - }, - 'type': 'dict' - }, - 'dest': { - 'required': True, - 'type': 'str' - }, - 'next_hops': { - 'elements': 'dict', - 'options': { - 'admin_distance': { - 'type': 'int' - }, - 'enabled': { - 'type': 'bool' - }, - 'forward_router_address': { - 'required': True, - 'type': 'str' - }, - 'interface': { - 'type': 'str' - } - }, - 'type': 'list' - } - }, - 'type': 'list' - } - }, - 'type': 'list' - } - }, - 'type': 'list' - }, - 'running_config': {'type': 'str'}, - 'state': { - 'choices': [ - 'merged', 'replaced', 'overridden', 'deleted', 'gathered', - 'rendered', 'parsed' - ], - 'default': - 'merged', - 'type': - 'str' - } - } # pylint: disable=C0301 diff --git a/lib/ansible/module_utils/network/vyos/config/firewall_global/firewall_global.py b/lib/ansible/module_utils/network/vyos/config/firewall_global/firewall_global.py deleted file mode 100644 index b930768ba3..0000000000 --- a/lib/ansible/module_utils/network/vyos/config/firewall_global/firewall_global.py +++ /dev/null @@ -1,611 +0,0 @@ -# -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -""" -The vyos_firewall_global class -It is in this file where the current configuration (as dict) -is compared to the provided configuration (as dict) and the command set -necessary to bring the current configuration to it's desired end-state is -created -""" -from __future__ import absolute_import, division, print_function -__metaclass__ = type - -from copy import deepcopy -from ansible.module_utils.network.common.cfg.base import ConfigBase -from ansible.module_utils.network.common.utils import to_list, remove_empties -from ansible.module_utils.network.vyos.facts.facts import Facts -from ansible.module_utils.six import iteritems -from ansible.module_utils.network.vyos.utils.utils import list_diff_want_only - - -class Firewall_global(ConfigBase): - """ - The vyos_firewall_global class - """ - - gather_subset = [ - '!all', - '!min', - ] - - gather_network_resources = [ - 'firewall_global', - ] - - def __init__(self, module): - super(Firewall_global, self).__init__(module) - - def get_firewall_global_facts(self, data=None): - """ Get the 'facts' (the current configuration) - - :rtype: A dictionary - :returns: The current configuration as a dictionary - """ - facts, _warnings = Facts(self._module).get_facts(self.gather_subset, self.gather_network_resources, data=data) - firewall_global_facts = facts['ansible_network_resources'].get('firewall_global') - if not firewall_global_facts: - return [] - return firewall_global_facts - - def execute_module(self): - """ Execute the module - - :rtype: A dictionary - :returns: The result from module execution - """ - result = {'changed': False} - warnings = list() - commands = list() - - if self.state in self.ACTION_STATES: - existing_firewall_global_facts = self.get_firewall_global_facts() - else: - existing_firewall_global_facts = [] - - if self.state in self.ACTION_STATES or self.state == 'rendered': - commands.extend(self.set_config(existing_firewall_global_facts)) - - if commands and self.state in self.ACTION_STATES: - if not self._module.check_mode: - self._connection.edit_config(commands) - result['changed'] = True - - if self.state in self.ACTION_STATES: - result['commands'] = commands - - if self.state in self.ACTION_STATES or self.state == 'gathered': - changed_firewall_global_facts = self.get_firewall_global_facts() - elif self.state == 'rendered': - result['rendered'] = commands - elif self.state == 'parsed': - running_config = self._module.params['running_config'] - if not running_config: - self._module.fail_json( - msg="value of running_config parameter must not be empty for state parsed" - ) - result['parsed'] = self.get_firewall_global_facts(data=running_config) - else: - changed_firewall_global_facts = [] - - if self.state in self.ACTION_STATES: - result['before'] = existing_firewall_global_facts - if result['changed']: - result['after'] = changed_firewall_global_facts - elif self.state == 'gathered': - result['gathered'] = changed_firewall_global_facts - - result['warnings'] = warnings - return result - - def set_config(self, existing_firewall_global_facts): - """ Collect the configuration from the args passed to the module, - collect the current configuration (as a dict from facts) - - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - want = self._module.params['config'] - have = existing_firewall_global_facts - resp = self.set_state(want, have) - return to_list(resp) - - def set_state(self, w, h): - """ Select the appropriate function based on the state provided - - :param want: the desired configuration as a dictionary - :param have: the current configuration as a dictionary - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - commands = [] - if self.state in ('merged', 'replaced', 'rendered') and not w: - self._module.fail_json(msg='value of config parameter must not be empty for state {0}'.format(self.state)) - if self.state == 'deleted': - commands.extend(self._state_deleted(want=None, have=h)) - elif w: - if self.state == 'merged' or self.state == 'rendered': - commands.extend(self._state_merged(w, h)) - elif self.state == 'replaced': - commands.extend(self._state_replaced(w, h)) - return commands - - def _state_replaced(self, want, have): - """ The command generator when state is replaced - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - commands = [] - if have: - commands.extend(self._state_deleted(have, want)) - commands.extend(self._state_merged(want, have)) - return commands - - def _state_merged(self, want, have): - """ The command generator when state is merged - - :rtype: A list - :returns: the commands necessary to merge the provided into - the current configuration - """ - commands = [] - commands.extend(self._add_global_attr(want, have)) - return commands - - def _state_deleted(self, want, have): - """ The command generator when state is deleted - - :rtype: A list - :returns: the commands necessary to remove the current configuration - of the provided objects - """ - commands = [] - b_set = ('config_trap', - 'validation', - 'log_martians', - 'syn_cookies', - 'twa_hazards_protection') - if want: - for key, val in iteritems(want): - if val and key in b_set and not have: - commands.append(self._form_attr_cmd(attr=key, opr=False)) - elif val and key in b_set and have and key in have and have[key] != val: - commands.append(self._form_attr_cmd(attr=key, opr=False)) - else: - commands.extend(self._render_attr_config(want, have, key)) - elif not want and have: - commands.append(self._compute_command(opr=False)) - elif have: - for key, val in iteritems(have): - if val and key in b_set: - commands.append(self._form_attr_cmd(attr=key, opr=False)) - else: - commands.extend(self._render_attr_config(want, have, key)) - return commands - - def _render_attr_config(self, w, h, key, opr=False): - """ - This function invoke the function to extend commands - based on the key. - :param w: the desired configuration. - :param h: the current configuration. - :param key: attribute name - :param opr: operation - :return: list of commands - """ - commands = [] - if key == 'ping': - commands.extend(self._render_ping(key, w, h, opr=opr)) - elif key == 'group': - commands.extend(self._render_group(key, w, h, opr=opr)) - elif key == 'state_policy': - commands.extend(self._render_state_policy(key, w, h, opr=opr)) - elif key == 'route_redirects': - commands.extend(self._render_route_redirects(key, w, h, opr=opr)) - return commands - - def _add_global_attr(self, w, h, opr=True): - """ - This function forms the set/delete commands based on the 'opr' type - for firewall_global attributes. - :param w: the desired config. - :param h: the target config. - :param opr: True/False. - :return: generated commands list. - """ - commands = [] - w_fg = deepcopy(remove_empties(w)) - l_set = ('config_trap', - 'validation', - 'log_martians', - 'syn_cookies', - 'twa_hazards_protection') - if w_fg: - for key, val in iteritems(w_fg): - if opr and key in l_set and not (h and self._is_w_same(w_fg, h, key)): - commands.append(self._form_attr_cmd(attr=key, val=self._bool_to_str(val), opr=opr)) - elif not opr: - if key and self._is_del(l_set, h): - commands.append(self._form_attr_cmd(attr=key, key=self._bool_to_str(val), opr=opr)) - continue - elif key in l_set and not (h and self._in_target(h, key)) and not self._is_del(l_set, h): - commands.append(self._form_attr_cmd(attr=key, val=self._bool_to_str(val), opr=opr)) - else: - commands.extend(self._render_attr_config(w_fg, h, key, opr)) - return commands - - def _render_ping(self, attr, w, h, opr): - """ - This function forms the commands for 'ping' attributes based on the 'opr'. - :param attr: attribute name. - :param w: the desired configuration. - :param h: the target config. - :param opr: True/False. - :return: generated list of commands. - """ - commands = [] - h_ping = {} - l_set = ('all', 'broadcast') - if h: - h_ping = h.get(attr) or {} - if self._is_root_del(w[attr], h_ping, attr): - for item, value in iteritems(h[attr]): - if not opr and item in l_set: - commands.append(self._form_attr_cmd(attr=item, opr=opr)) - elif w[attr]: - if h and attr in h.keys(): - h_ping = h.get(attr) or {} - for item, value in iteritems(w[attr]): - if opr and item in l_set and not (h_ping and self._is_w_same(w[attr], h_ping, item)): - commands.append(self._form_attr_cmd(attr=item, val=self._bool_to_str(value), opr=opr)) - elif not opr and item in l_set and not (h_ping and self._is_w_same(w[attr], h_ping, item)): - commands.append(self._form_attr_cmd(attr=item, opr=opr)) - return commands - - def _render_group(self, attr, w, h, opr): - """ - This function forms the commands for 'group' attribute based on the 'opr'. - :param attr: attribute name. - :param w: base config. - :param h: target config. - :param opr: True/False. - :return: generated list of commands. - """ - commands = [] - h_grp = {} - if not opr and self._is_root_del(h, w, attr): - commands.append(self._form_attr_cmd(attr=attr, opr=opr)) - else: - if h: - h_grp = h.get('group') or {} - if w: - commands.extend(self._render_grp_mem('port-group', w['group'], h_grp, opr)) - commands.extend(self._render_grp_mem('address_group', w['group'], h_grp, opr)) - commands.extend(self._render_grp_mem('network_group', w['group'], h_grp, opr)) - return commands - - def _render_grp_mem(self, attr, w, h, opr): - """ - This function forms the commands for group list/members attributes based on the 'opr'. - :param attr: attribute name. - :param w: the desired config. - :param h: the target config. - :param opr: True/False. - :return: generated list of commands. - """ - commands = [] - h_grp = [] - w_grp = [] - l_set = ('name', 'description') - if w: - w_grp = w.get(attr) or [] - if h: - h_grp = h.get(attr) or [] - - if w_grp: - for want in w_grp: - cmd = self._compute_command(key='group', attr=attr, opr=opr) - h = self.search_attrib_in_have(h_grp, want, 'name') - for key, val in iteritems(want): - if val: - if opr and key in l_set and not (h and self._is_w_same(want, h, key)): - if key == 'name': - commands.append(cmd + ' ' + str(val)) - else: - commands.append(cmd + ' ' + want['name'] + ' ' + key + " '" + str(want[key]) + "'") - elif not opr and key in l_set: - if key == 'name' and self._is_grp_del(h, want, key): - commands.append(cmd + ' ' + want['name']) - continue - elif not (h and self._in_target(h, key)) and not self._is_grp_del(h, want, key): - commands.append(cmd + ' ' + want['name'] + ' ' + key) - elif key == 'members': - commands.extend(self._render_ports_addrs(key, want, h, opr, cmd, want['name'], attr)) - return commands - - def _render_ports_addrs(self, attr, w, h, opr, cmd, name, type): - """ - This function forms the commands for port/address/network group members - based on the 'opr'. - :param attr: attribute name. - :param w: the desired config. - :param h: the target config. - :param cmd: commands to be prepend. - :param name: name of group. - :param type: group type. - :return: generated list of commands. - """ - commands = [] - have = [] - if w: - want = w.get(attr) or [] - if h: - have = h.get(attr) or [] - - if want: - if opr: - members = list_diff_want_only(want, have) - for member in members: - commands.append( - cmd + ' ' + name + ' ' + self._grp_type(type) + ' ' + member[self._get_mem_type(type)] - ) - elif not opr and have: - members = list_diff_want_only(want, have) - for member in members: - commands.append( - cmd + ' ' + name + ' ' + self._grp_type(type) + ' ' + member[self._get_mem_type(type)] - ) - return commands - - def _get_mem_type(self, group): - """ - This function returns the member type - based on the type of group. - """ - return 'port' if group == 'port_group' else 'address' - - def _render_state_policy(self, attr, w, h, opr): - """ - This function forms the commands for 'state-policy' attributes - based on the 'opr'. - :param attr: attribute name. - :param w: the desired config. - :param h: the target config. - :param opr: True/False. - :return: generated list of commands. - """ - commands = [] - have = [] - l_set = ('log', 'action', 'connection_type') - if not opr and self._is_root_del(h, w, attr): - commands.append(self._form_attr_cmd(attr=attr, opr=opr)) - else: - w_sp = deepcopy(remove_empties(w)) - want = w_sp.get(attr) or [] - if h: - have = h.get(attr) or [] - if want: - for w in want: - h = self.search_attrib_in_have(have, w, 'connection_type') - for key, val in iteritems(w): - if val and key != 'connection_type': - if opr and key in l_set and not (h and self._is_w_same(w, h, key)): - commands.append(self._form_attr_cmd(key=attr + ' ' + w['connection_type'], attr=key, val=self._bool_to_str(val), opr=opr)) - elif not opr and key in l_set: - if not (h and self._in_target(h, key)) and not self._is_del(l_set, h): - if key == 'action': - commands.append(self._form_attr_cmd(attr=attr + ' ' + w['connection_type'], opr=opr)) - else: - commands.append(self._form_attr_cmd(attr=attr + ' ' + w['connection_type'], val=self._bool_to_str(val), opr=opr)) - return commands - - def _render_route_redirects(self, attr, w, h, opr): - """ - This function forms the commands for 'route_redirects' attributes based on the 'opr'. - :param attr: attribute name. - :param w: the desired config. - :param h: the target config. - :param opr: True/False. - :return: generated list of commands. - """ - commands = [] - have = [] - l_set = ('afi', 'ip_src_route') - - if w: - want = w.get(attr) or [] - if h: - have = h.get(attr) or [] - - if want: - for w in want: - h = self.search_attrib_in_have(have, w, 'afi') - for key, val in iteritems(w): - if val and key != 'afi': - if opr and key in l_set and not (h and self._is_w_same(w, h, key)): - commands.append(self._form_attr_cmd(attr=key, val=self._bool_to_str(val), opr=opr)) - elif not opr and key in l_set: - if self._is_del(l_set, h): - commands.append(self._form_attr_cmd(attr=key, val=self._bool_to_str(val), opr=opr)) - continue - elif not (h and self._in_target(h, key)) and not self._is_del(l_set, h): - commands.append(self._form_attr_cmd(attr=key, val=self._bool_to_str(val), opr=opr)) - elif key == 'icmp_redirects': - commands.extend(self._render_icmp_redirects(key, w, h, opr)) - return commands - - def _render_icmp_redirects(self, attr, w, h, opr): - """ - This function forms the commands for 'icmp_redirects' attributes - based on the 'opr'. - :param attr: attribute name. - :param w: the desired config. - :param h: the target config. - :param opr: True/False. - :return: generated list of commands. - """ - commands = [] - h_red = {} - l_set = ('send', 'receive') - if w[attr]: - if h and attr in h.keys(): - h_red = h.get(attr) or {} - for item, value in iteritems(w[attr]): - if opr and item in l_set and not (h_red and self._is_w_same(w[attr], h_red, item)): - commands.append(self._form_attr_cmd(attr=item, val=self._bool_to_str(value), opr=opr)) - elif not opr and item in l_set and not (h_red and self._is_w_same(w[attr], h_red, item)): - commands.append(self._form_attr_cmd(attr=item, opr=opr)) - return commands - - def search_attrib_in_have(self, have, want, attr): - """ - This function returns the attribute if it is present in target config. - :param have: the target config. - :param want: the desired config. - :param attr: attribute name . - :return: attribute/None - """ - if have: - for h in have: - if h[attr] == want[attr]: - return h - return None - - def _form_attr_cmd(self, key=None, attr=None, val=None, opr=True): - """ - This function forms the command for leaf attribute. - :param key: parent key. - :param attr: attribute name - :param value: value - :param opr: True/False. - :return: generated command. - """ - command = self._compute_command(key=key, attr=self._map_attrib(attr), val=val, opr=opr) - return command - - def _compute_command(self, key=None, attr=None, val=None, remove=False, opr=True): - """ - This function construct the add/delete command based on passed attributes. - :param key: parent key. - :param attr: attribute name - :param value: value - :param remove: True/False. - :param opr: True/False. - :return: generated command. - """ - if remove or not opr: - cmd = 'delete firewall ' - else: - cmd = 'set firewall ' - if key: - cmd += (key.replace("_", "-") + " ") - if attr: - cmd += (attr.replace("_", "-")) - if val and opr: - cmd += (" '" + str(val) + "'") - return cmd - - def _bool_to_str(self, val): - """ - This function converts the bool value into string. - :param val: bool value. - :return: enable/disable. - """ - return 'enable' if str(val) == 'True' else 'disable' if str(val) == 'False' else val - - def _grp_type(self, val): - """ - This function returns the group member type based on value argument. - :param val: value. - :return: member type. - """ - return 'address' if val == 'address_group' else 'network' if val == 'network_group' else 'port' - - def _is_w_same(self, w, h, key): - """ - This function checks whether the key value is same in desired and - target config dictionary. - :param w: base config. - :param h: target config. - :param key:attribute name. - :return: True/False. - """ - return True if h and key in h and h[key] == w[key] else False - - def _in_target(self, h, key): - """ - This function checks whether the target exist and key present in target config. - :param h: target config. - :param key: attribute name. - :return: True/False. - """ - return True if h and key in h else False - - def _is_grp_del(self, w, h, key): - """ - This function checks whether group needed to be deleted based on - desired and target configs. - :param w: the desired config. - :param h: the target config. - :param key: group name. - :return: True/False. - """ - return True if h and key in h and (not w or key not in w or not w[key]) else False - - def _is_root_del(self, w, h, key): - """ - This function checks whether a root attribute which can have - further child attributes needed to be deleted. - :param w: the desired config. - :param h: the target config. - :param key: attribute name. - :return: True/False. - """ - return True if h and key in h and (not w or key not in w or not w[key]) else False - - def _is_del(self, b_set, h, key='number'): - """ - This function checks whether attribute needs to be deleted - when operation is false and attribute present in present target config. - :param b_set: attribute set. - :param h: target config. - :param key: number. - :return: True/False. - """ - return key in b_set and not (h and self._in_target(h, key)) - - def _map_attrib(self, attrib, type=None): - """ - - This function construct the regex string. - - replace the underscore with hyphen. - :param attrib: attribute - :return: regex string - """ - regex = attrib.replace("_", "-") - if attrib == 'send': - if type == 'ipv6': - regex = 'ipv6-send-redirects' - else: - regex = 'send-redirects' - elif attrib == 'ip_src_route': - if type == 'ipv6': - regex = 'ipv6-src-route' - elif attrib == 'receive': - if type == 'ipv6': - regex = 'ipv6-receive-redirects' - else: - regex = 'receive-redirects' - elif attrib == 'disabled': - regex = 'disable' - elif attrib == 'all': - regex = 'all-ping' - elif attrib == 'broadcast': - regex = 'broadcast-ping' - elif attrib == 'validation': - regex = 'source-validation' - return regex diff --git a/lib/ansible/module_utils/network/vyos/config/firewall_interfaces/firewall_interfaces.py b/lib/ansible/module_utils/network/vyos/config/firewall_interfaces/firewall_interfaces.py deleted file mode 100644 index c16609485e..0000000000 --- a/lib/ansible/module_utils/network/vyos/config/firewall_interfaces/firewall_interfaces.py +++ /dev/null @@ -1,364 +0,0 @@ -# -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -""" -The vyos_firewall_interfaces class -It is in this file where the current configuration (as dict) -is compared to the provided configuration (as dict) and the command set -necessary to bring the current configuration to it's desired end-state is -created -""" -from __future__ import absolute_import, division, print_function -__metaclass__ = type - -from copy import deepcopy -from ansible.module_utils.network.common.cfg.base import ConfigBase -from ansible.module_utils.network.common.utils import to_list, dict_diff, remove_empties, search_obj_in_list -from ansible.module_utils.network.vyos.facts.facts import Facts - - -class Firewall_interfaces(ConfigBase): - """ - The vyos_firewall_interfaces class - """ - - gather_subset = [ - '!all', - '!min', - ] - - gather_network_resources = [ - 'firewall_interfaces', - ] - - def __init__(self, module): - super(Firewall_interfaces, self).__init__(module) - - def get_firewall_interfaces_facts(self, data=None): - """ Get the 'facts' (the current configuration) - - :rtype: A dictionary - :returns: The current configuration as a dictionary - """ - facts, _warnings = Facts(self._module).get_facts(self.gather_subset, self.gather_network_resources, data=data) - firewall_interfaces_facts = facts['ansible_network_resources'].get('firewall_interfaces') - if not firewall_interfaces_facts: - return [] - return firewall_interfaces_facts - - def execute_module(self): - """ Execute the module - - :rtype: A dictionary - :returns: The result from module execution - """ - result = {'changed': False} - warnings = list() - commands = list() - - if self.state in self.ACTION_STATES: - existing_firewall_interfaces_facts = self.get_firewall_interfaces_facts() - else: - existing_firewall_interfaces_facts = [] - - if self.state in self.ACTION_STATES or self.state == 'rendered': - commands.extend(self.set_config(existing_firewall_interfaces_facts)) - - if commands and self.state in self.ACTION_STATES: - if not self._module.check_mode: - self._connection.edit_config(commands) - result['changed'] = True - - if self.state in self.ACTION_STATES: - result['commands'] = commands - - if self.state in self.ACTION_STATES or self.state == 'gathered': - changed_firewall_interfaces_facts = self.get_firewall_interfaces_facts() - elif self.state == 'rendered': - result['rendered'] = commands - elif self.state == 'parsed': - running_config = self._module.params['running_config'] - if not running_config: - self._module.fail_json( - msg="value of running_config parameter must not be empty for state parsed" - ) - result['parsed'] = self.get_firewall_interfaces_facts(data=running_config) - else: - changed_firewall_interfaces_facts = [] - - if self.state in self.ACTION_STATES: - result['before'] = existing_firewall_interfaces_facts - if result['changed']: - result['after'] = changed_firewall_interfaces_facts - elif self.state == 'gathered': - result['gathered'] = changed_firewall_interfaces_facts - - result['warnings'] = warnings - return result - - def set_config(self, existing_firewall_interfaces_facts): - """ Collect the configuration from the args passed to the module, - collect the current configuration (as a dict from facts) - - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - want = self._module.params['config'] - have = existing_firewall_interfaces_facts - resp = self.set_state(want, have) - return to_list(resp) - - def set_state(self, w, h): - """ Select the appropriate function based on the state provided - - :param want: the desired configuration as a dictionary - :param have: the current configuration as a dictionary - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - commands = [] - if self.state in ('merged', 'replaced', 'overridden', 'rendered') and not w: - self._module.fail_json(msg='value of config parameter must not be empty for state {0}'.format(self.state)) - if self.state == 'overridden': - commands.extend(self._state_overridden(w, h)) - elif self.state == 'deleted': - commands.extend(self._state_deleted(w, h)) - elif w: - if self.state == 'merged' or self.state == 'rendered': - commands.extend(self._state_merged(w, h)) - elif self.state == 'replaced': - commands.extend(self._state_replaced(w, h)) - return commands - - def _state_replaced(self, want, have): - """ The command generator when state is replaced - - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - commands = [] - if have: - for h in have: - w = search_obj_in_list(h['name'], want) - commands.extend(self._render_access_rules(h, w, opr=False)) - commands.extend(self._state_merged(want, have)) - return commands - - def _state_overridden(self, want, have): - """ The command generator when state is overridden - - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - commands = [] - if have: - for h_ar in have: - w_ar = search_obj_in_list(h_ar['name'], want) - if not w_ar and 'access_rules' in h_ar: - commands.append(self._compute_command(name=h_ar['name'], opr=False)) - else: - h_rules = h_ar.get('access_rules') or [] - key = 'direction' - if w_ar: - w_rules = w_ar.get('access_rules') or [] - if not w_rules and h_rules: - commands.append(self._compute_command(name=h_ar['name'], opr=False)) - if h_rules: - for h_rule in h_rules: - w_rule = search_obj_in_list(h_rule['afi'], w_rules, key='afi') - have_rules = h_rule.get('rules') or [] - if w_rule: - want_rules = w_rule.get('rules') or [] - for h in have_rules: - if key in h: - w = search_obj_in_list(h[key], want_rules, key=key) - if not w or key not in w or ('name' in h and w and 'name' not in w): - commands.append( - self._compute_command( - afi=h_rule['afi'], name=h_ar['name'], attrib=h[key], opr=False - ) - ) - - commands.extend(self._state_merged(want, have)) - return commands - - def _state_merged(self, want, have): - """ The command generator when state is merged - - :rtype: A list - :returns: the commands necessary to merge the provided into - the current configuration - """ - commands = [] - for w in want: - h = search_obj_in_list(w['name'], have) - commands.extend(self._render_access_rules(w, h)) - return commands - - def _state_deleted(self, want, have): - """ The command generator when state is deleted - - :rtype: A list - :returns: the commands necessary to remove the current configuration - of the provided objects - """ - commands = [] - - if want: - for w in want: - h = search_obj_in_list(w['name'], have) - if h and 'access_rules' in h: - commands.extend(self._delete_access_rules(w, h, opr=False)) - elif have: - for h in have: - if 'access_rules' in h: - commands.append(self._compute_command(name=h['name'], opr=False)) - return commands - - def _delete_access_rules(self, want, have, opr=False): - """ - This function forms the delete commands based on the 'opr' type - for 'access_rules' attributes. - :param want: desired config. - :param have: target config. - :param opr: True/False. - :return: generated commands list. - """ - commands = [] - h_rules = {} - w_rs = deepcopy(remove_empties(want)) - w_rules = w_rs.get('access_rules') or [] - if have: - h_rs = deepcopy(remove_empties(have)) - h_rules = h_rs.get('access_rules') or [] - - # if all firewall config needed to be deleted for specific interface - # when operation is delete. - if not w_rules and h_rules: - commands.append(self._compute_command(name=want['name'], opr=opr)) - if w_rules: - for w in w_rules: - h = search_obj_in_list(w['afi'], h_rules, key='afi') - commands.extend(self._delete_rules(want['name'], w, h)) - return commands - - def _delete_rules(self, name, want, have, opr=False): - """ - This function forms the delete commands based on the 'opr' type - for rules attributes. - :param name: interface id/name. - :param want: desired config. - :param have: target config. - :param opr: True/False. - :return: generated commands list. - """ - commands = [] - h_rules = [] - key = 'direction' - w_rules = want.get('rules') or [] - if have: - h_rules = have.get('rules') or [] - # when rule set needed to be removed on - # (inbound|outbound|local interface) - if h_rules and not w_rules: - for h in h_rules: - if key in h: - commands.append(self._compute_command(afi=want['afi'], name=name, attrib=h[key], opr=opr)) - for w in w_rules: - h = search_obj_in_list(w[key], h_rules, key=key) - if key in w and h and key in h and 'name' in w and 'name' in h and w['name'] == h['name']: - commands.append(self._compute_command( - afi=want['afi'], - name=name, - attrib=w[key], - value=w['name'], - opr=opr) - ) - return commands - - def _render_access_rules(self, want, have, opr=True): - """ - This function forms the set/delete commands based on the 'opr' type - for 'access_rules' attributes. - :param want: desired config. - :param have: target config. - :param opr: True/False. - :return: generated commands list. - """ - commands = [] - h_rules = {} - w_rs = deepcopy(remove_empties(want)) - w_rules = w_rs.get('access_rules') or [] - if have: - h_rs = deepcopy(remove_empties(have)) - h_rules = h_rs.get('access_rules') or [] - if w_rules: - for w in w_rules: - h = search_obj_in_list(w['afi'], h_rules, key='afi') - commands.extend(self._render_rules(want['name'], w, h, opr)) - return commands - - def _render_rules(self, name, want, have, opr=True): - """ - This function forms the set/delete commands based on the 'opr' type - for rules attributes. - :param name: interface id/name. - :param want: desired config. - :param have: target config. - :param opr: True/False. - :return: generated commands list. - """ - commands = [] - h_rules = [] - key = 'direction' - w_rules = want.get('rules') or [] - if have: - h_rules = have.get('rules') or [] - for w in w_rules: - h = search_obj_in_list(w[key], h_rules, key=key) - if key in w: - if opr: - if 'name' in w and not (h and h[key] == w[key] and h['name'] == w['name']): - commands.append(self._compute_command(afi=want['afi'], name=name, attrib=w[key], value=w['name'])) - elif not (h and key in h): - commands.append(self._compute_command(afi=want['afi'], name=name, attrib=w[key])) - elif not opr: - if not h or key not in h or ('name' in w and h and 'name' not in h): - commands.append(self._compute_command(afi=want['afi'], name=name, attrib=w[key], opr=opr)) - return commands - - def _compute_command(self, afi=None, name=None, attrib=None, value=None, opr=True): - """ - This function construct the add/delete command based on passed attributes. - :param afi: address type. - :param name: interface name. - :param attrib: attribute name. - :param value: attribute value. - :param opr: operation flag. - :return: generated command. - """ - if not opr: - cmd = 'delete interfaces ethernet' + ' ' + name + ' firewall' - else: - cmd = 'set interfaces ethernet' + ' ' + name + ' firewall' - if attrib: - cmd += (' ' + attrib) - if afi: - cmd += ' ' + self._get_fw_type(afi) - if value: - cmd += (" '" + str(value) + "'") - return cmd - - def _get_fw_type(self, afi): - """ - This function returns the firewall rule-set type based on IP address. - :param afi: address type - :return: rule-set type. - """ - return 'ipv6-name' if afi == 'ipv6' else 'name' diff --git a/lib/ansible/module_utils/network/vyos/config/firewall_rules/firewall_rules.py b/lib/ansible/module_utils/network/vyos/config/firewall_rules/firewall_rules.py deleted file mode 100644 index 38ee047e54..0000000000 --- a/lib/ansible/module_utils/network/vyos/config/firewall_rules/firewall_rules.py +++ /dev/null @@ -1,706 +0,0 @@ -# -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -""" -The vyos_firewall_rules class -It is in this file where the current configuration (as dict) -is compared to the provided configuration (as dict) and the command set -necessary to bring the current configuration to it's desired end-state is -created -""" -from __future__ import absolute_import, division, print_function -__metaclass__ = type - -from copy import deepcopy -from ansible.module_utils.network.common.cfg.base import ConfigBase -from ansible.module_utils.network.common.utils import to_list, remove_empties -from ansible.module_utils.network.vyos.facts.facts import Facts -from ansible.module_utils.six import iteritems -from ansible.module_utils.network.vyos.utils.utils import list_diff_want_only - - -class Firewall_rules(ConfigBase): - """ - The vyos_firewall_rules class - """ - - gather_subset = [ - '!all', - '!min', - ] - - gather_network_resources = [ - 'firewall_rules', - ] - - def __init__(self, module): - super(Firewall_rules, self).__init__(module) - - def get_firewall_rules_facts(self, data=None): - """ Get the 'facts' (the current configuration) - - :rtype: A dictionary - :returns: The current configuration as a dictionary - """ - facts, _warnings = Facts(self._module).get_facts(self.gather_subset, self.gather_network_resources, data=data) - firewall_rules_facts = facts['ansible_network_resources'].get('firewall_rules') - if not firewall_rules_facts: - return [] - return firewall_rules_facts - - def execute_module(self): - """ Execute the module - - :rtype: A dictionary - :returns: The result from module execution - """ - result = {'changed': False} - warnings = list() - commands = list() - - if self.state in self.ACTION_STATES: - existing_firewall_rules_facts = self.get_firewall_rules_facts() - else: - existing_firewall_rules_facts = [] - - if self.state in self.ACTION_STATES or self.state == 'rendered': - commands.extend(self.set_config(existing_firewall_rules_facts)) - - if commands and self.state in self.ACTION_STATES: - if not self._module.check_mode: - self._connection.edit_config(commands) - result['changed'] = True - - if self.state in self.ACTION_STATES: - result['commands'] = commands - - if self.state in self.ACTION_STATES or self.state == 'gathered': - changed_firewall_rules_facts = self.get_firewall_rules_facts() - elif self.state == 'rendered': - result['rendered'] = commands - elif self.state == 'parsed': - running_config = self._module.params['running_config'] - if not running_config: - self._module.fail_json( - msg="value of running_config parameter must not be empty for state parsed" - ) - result['parsed'] = self.get_firewall_rules_facts(data=running_config) - else: - changed_firewall_rules_facts = [] - - if self.state in self.ACTION_STATES: - result['before'] = existing_firewall_rules_facts - if result['changed']: - result['after'] = changed_firewall_rules_facts - elif self.state == 'gathered': - result['gathered'] = changed_firewall_rules_facts - - result['warnings'] = warnings - return result - - def set_config(self, existing_firewall_rules_facts): - """ Collect the configuration from the args passed to the module, - collect the current configuration (as a dict from facts) - - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - want = self._module.params['config'] - have = existing_firewall_rules_facts - resp = self.set_state(want, have) - return to_list(resp) - - def set_state(self, w, h): - """ Select the appropriate function based on the state provided - - :param want: the desired configuration as a dictionary - :param have: the current configuration as a dictionary - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - commands = [] - if self.state in ('merged', 'replaced', 'overridden', 'rendered') and not w: - self._module.fail_json(msg='value of config parameter must not be empty for state {0}'.format(self.state)) - if self.state == 'overridden': - commands.extend(self._state_overridden(w, h)) - elif self.state == 'deleted': - commands.extend(self._state_deleted(w, h)) - elif w: - if self.state == 'merged' or self.state == 'rendered': - commands.extend(self._state_merged(w, h)) - elif self.state == 'replaced': - commands.extend(self._state_replaced(w, h)) - return commands - - def _state_replaced(self, want, have): - """ The command generator when state is replaced - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - commands = [] - if have: - for h in have: - r_sets = self._get_r_sets(h) - for rs in r_sets: - w = self.search_r_sets_in_have(want, rs['name'], 'r_list') - commands.extend(self._add_r_sets(h['afi'], rs, w, opr=False)) - commands.extend(self._state_merged(want, have)) - return commands - - def _state_overridden(self, want, have): - """ The command generator when state is overridden - - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - commands = [] - if have: - for h in have: - r_sets = self._get_r_sets(h) - for rs in r_sets: - w = self.search_r_sets_in_have(want, rs['name'], 'r_list') - if not w: - commands.append(self._compute_command(h['afi'], rs['name'], remove=True)) - else: - commands.extend(self._add_r_sets(h['afi'], rs, w, opr=False)) - commands.extend(self._state_merged(want, have)) - return commands - - def _state_merged(self, want, have): - """ The command generator when state is merged - - :rtype: A list - :returns: the commands necessary to merge the provided into - the current configuration - """ - commands = [] - for w in want: - r_sets = self._get_r_sets(w) - for rs in r_sets: - h = self.search_r_sets_in_have(have, rs['name'], 'r_list') - commands.extend(self._add_r_sets(w['afi'], rs, h)) - return commands - - def _state_deleted(self, want, have): - """ The command generator when state is deleted - - :rtype: A list - :returns: the commands necessary to remove the current configuration - of the provided objects - """ - commands = [] - if want: - for w in want: - r_sets = self._get_r_sets(w) - if r_sets: - for rs in r_sets: - h = self.search_r_sets_in_have(have, rs['name'], 'r_list') - if h: - w_rules = rs.get('rules') or [] - h_rules = h.get('rules') or [] - if w_rules and h_rules: - for rule in w_rules: - if self.search_r_sets_in_have(h_rules, rule['number'], 'rules'): - commands.append(self._add_r_base_attrib(w['afi'], rs['name'], 'number', rule, opr=False)) - else: - commands.append(self._compute_command(w['afi'], h['name'], remove=True)) - elif have: - for h in have: - if h['afi'] == w['afi']: - commands.append(self._compute_command(w['afi'], remove=True)) - elif have: - for h in have: - r_sets = self._get_r_sets(h) - if r_sets: - commands.append(self._compute_command(afi=h['afi'], remove=True)) - return commands - - def _add_r_sets(self, afi, want, have, opr=True): - """ - This function forms the set/delete commands based on the 'opr' type - for rule-sets attributes. - :param afi: address type. - :param want: desired config. - :param have: target config. - :param opr: True/False. - :return: generated commands list. - """ - commands = [] - l_set = ('description', - 'default_action', - 'enable_default_log') - h_rs = {} - h_rules = {} - w_rs = deepcopy(remove_empties(want)) - w_rules = w_rs.pop('rules', None) - if have: - h_rs = deepcopy(remove_empties(have)) - h_rules = h_rs.pop('rules', None) - if w_rs: - for key, val in iteritems(w_rs): - if opr and key in l_set and not (h_rs and self._is_w_same(w_rs, h_rs, key)): - if key == 'enable_default_log': - if val and (not h_rs or key not in h_rs or not h_rs[key]): - commands.append(self._add_rs_base_attrib(afi, want['name'], key, w_rs)) - else: - commands.append(self._add_rs_base_attrib(afi, want['name'], key, w_rs)) - elif not opr and key in l_set: - if key == 'enable_default_log' and val and h_rs and (key not in h_rs or not h_rs[key]): - commands.append(self._add_rs_base_attrib(afi, want['name'], key, w_rs, opr)) - elif not (h_rs and self._in_target(h_rs, key)): - commands.append(self._add_rs_base_attrib(afi, want['name'], key, w_rs, opr)) - commands.extend(self._add_rules(afi, want['name'], w_rules, h_rules, opr)) - if h_rules: - have['rules'] = h_rules - if w_rules: - want['rules'] = w_rules - return commands - - def _add_rules(self, afi, name, w_rules, h_rules, opr=True): - """ - This function forms the set/delete commands based on the 'opr' type - for rules attributes. - :param want: desired config. - :param have: target config. - :return: generated commands list. - """ - commands = [] - l_set = ('ipsec', - 'action', - 'number', - 'protocol', - 'fragment', - 'disabled', - 'description') - if w_rules: - for w in w_rules: - cmd = self._compute_command(afi, name, w['number'], opr=opr) - h = self.search_r_sets_in_have(h_rules, w['number'], type='rules') - for key, val in iteritems(w): - if val: - if opr and key in l_set and not (h and self._is_w_same(w, h, key)): - if key == 'disabled': - if not (not val and (not h or key not in h or not h[key])): - commands.append(self._add_r_base_attrib(afi, name, key, w)) - else: - commands.append(self._add_r_base_attrib(afi, name, key, w)) - elif not opr: - if key == 'number' and self._is_del(l_set, h): - commands.append(self._add_r_base_attrib(afi, name, key, w, opr=opr)) - continue - elif key == 'disabled' and val and h and (key not in h or not h[key]): - commands.append(self._add_r_base_attrib(afi, name, key, w, opr=opr)) - elif key in l_set and not (h and self._in_target(h, key)) and not self._is_del(l_set, h): - commands.append(self._add_r_base_attrib(afi, name, key, w, opr=opr)) - elif key == 'p2p': - commands.extend(self._add_p2p(key, w, h, cmd, opr)) - elif key == 'tcp': - commands.extend(self._add_tcp(key, w, h, cmd, opr)) - elif key == 'time': - commands.extend(self._add_time(key, w, h, cmd, opr)) - elif key == 'icmp': - commands.extend(self._add_icmp(key, w, h, cmd, opr)) - elif key == 'state': - commands.extend(self._add_state(key, w, h, cmd, opr)) - elif key == 'limit': - commands.extend(self._add_limit(key, w, h, cmd, opr)) - elif key == 'recent': - commands.extend(self._add_recent(key, w, h, cmd, opr)) - elif key == 'destination' or key == 'source': - commands.extend(self._add_src_or_dest(key, w, h, cmd, opr)) - return commands - - def _add_p2p(self, attr, w, h, cmd, opr): - """ - This function forms the set/delete commands based on the 'opr' type - for p2p applications attributes. - :param want: desired config. - :param have: target config. - :return: generated commands list. - """ - commands = [] - have = [] - if w: - want = w.get(attr) or [] - if h: - have = h.get(attr) or [] - if want: - if opr: - applications = list_diff_want_only(want, have) - for app in applications: - commands.append(cmd + (' ' + attr + ' ' + app['application'])) - elif not opr and have: - applications = list_diff_want_only(want, have) - for app in applications: - commands.append(cmd + (' ' + attr + ' ' + app['application'])) - return commands - - def _add_state(self, attr, w, h, cmd, opr): - """ - This function forms the command for 'state' attributes based on the 'opr'. - :param attr: attribute name. - :param w: base config. - :param h: target config. - :param cmd: commands to be prepend. - :return: generated list of commands. - """ - h_state = {} - commands = [] - l_set = ('new', - 'invalid', - 'related', - 'established') - if w[attr]: - if h and attr in h.keys(): - h_state = h.get(attr) or {} - for item, val in iteritems(w[attr]): - if opr and item in l_set and not (h_state and self._is_w_same(w[attr], h_state, item)): - commands.append(cmd + (' ' + attr + ' ' + item + ' ' + self._bool_to_str(val))) - elif not opr and item in l_set and not (h_state and self._in_target(h_state, item)): - commands.append(cmd + (' ' + attr + ' ' + item)) - return commands - - def _add_recent(self, attr, w, h, cmd, opr): - """ - This function forms the command for 'recent' attributes based on the 'opr'. - :param attr: attribute name. - :param w: base config. - :param h: target config. - :param cmd: commands to be prepend. - :return: generated list of commands. - """ - commands = [] - h_recent = {} - l_set = ('count', 'time') - if w[attr]: - if h and attr in h.keys(): - h_recent = h.get(attr) or {} - for item, val in iteritems(w[attr]): - if opr and item in l_set and not (h_recent and self._is_w_same(w[attr], h_recent, item)): - commands.append(cmd + (' ' + attr + ' ' + item + ' ' + str(val))) - elif not opr and item in l_set and not (h_recent and self._in_target(h_recent, item)): - commands.append(cmd + (' ' + attr + ' ' + item)) - return commands - - def _add_icmp(self, attr, w, h, cmd, opr): - """ - This function forms the commands for 'icmp' attributes based on the 'opr'. - :param attr: attribute name. - :param w: base config. - :param h: target config. - :param cmd: commands to be prepend. - :return: generated list of commands. - """ - commands = [] - h_icmp = {} - l_set = ('code', 'type', 'type_name') - if w[attr]: - if h and attr in h.keys(): - h_icmp = h.get(attr) or {} - for item, val in iteritems(w[attr]): - if opr and item in l_set and not (h_icmp and self._is_w_same(w[attr], h_icmp, item)): - if item == 'type_name': - if 'ipv6-name' in cmd: - commands.append(cmd + (' ' + 'icmpv6' + ' ' + 'type' + ' ' + val)) - else: - commands.append(cmd + (' ' + attr + ' ' + item.replace("_", "-") + ' ' + val)) - else: - commands.append(cmd + (' ' + attr + ' ' + item + ' ' + str(val))) - elif not opr and item in l_set and not (h_icmp and self._in_target(h_icmp, item)): - commands.append(cmd + (' ' + attr + ' ' + item)) - return commands - - def _add_time(self, attr, w, h, cmd, opr): - """ - This function forms the commands for 'time' attributes based on the 'opr'. - :param attr: attribute name. - :param w: base config. - :param h: target config. - :param cmd: commands to be prepend. - :return: generated list of commands. - """ - commands = [] - h_time = {} - l_set = ('utc', - 'stopdate', - 'stoptime', - 'weekdays', - 'monthdays', - 'startdate', - 'starttime') - if w[attr]: - if h and attr in h.keys(): - h_time = h.get(attr) or {} - for item, val in iteritems(w[attr]): - if opr and item in l_set and not (h_time and self._is_w_same(w[attr], h_time, item)): - if item == 'utc': - if not (not val and (not h_time or item not in h_time)): - commands.append(cmd + (' ' + attr + ' ' + item)) - else: - commands.append(cmd + (' ' + attr + ' ' + item + ' ' + val)) - elif not opr and item in l_set and not (h_time and self._is_w_same(w[attr], h_time, item)): - commands.append(cmd + (' ' + attr + ' ' + item)) - return commands - - def _add_tcp(self, attr, w, h, cmd, opr): - """ - This function forms the commands for 'tcp' attributes based on the 'opr'. - :param attr: attribute name. - :param w: base config. - :param h: target config. - :param cmd: commands to be prepend. - :return: generated list of commands. - """ - h_tcp = {} - commands = [] - if w[attr]: - key = 'flags' - flags = w[attr].get(key) or {} - if flags: - if h and key in h[attr].keys(): - h_tcp = h[attr].get(key) or {} - if flags: - if opr and not (h_tcp and self._is_w_same(w[attr], h[attr], key)): - commands.append(cmd + (' ' + attr + ' ' + key + ' ' + flags)) - if not opr and not (h_tcp and self._is_w_same(w[attr], h[attr], key)): - commands.append(cmd + (' ' + attr + ' ' + key + ' ' + flags)) - return commands - - def _add_limit(self, attr, w, h, cmd, opr): - """ - This function forms the commands for 'limit' attributes based on the 'opr'. - :param attr: attribute name. - :param w: base config. - :param h: target config. - :param cmd: commands to be prepend. - :return: generated list of commands. - """ - h_limit = {} - commands = [] - if w[attr]: - key = 'burst' - if opr and key in w[attr].keys() and not (h and attr in h.keys() and self._is_w_same(w[attr], h[attr], key)): - commands.append(cmd + (' ' + attr + ' ' + key + ' ' + str(w[attr].get(key)))) - elif not opr and key in w[attr].keys() and not (h and attr in h.keys() and self._in_target(h[attr], key)): - commands.append(cmd + (' ' + attr + ' ' + key + ' ' + str(w[attr].get(key)))) - key = 'rate' - rate = w[attr].get(key) or {} - if rate: - if h and key in h[attr].keys(): - h_limit = h[attr].get(key) or {} - if 'unit' in rate and 'number' in rate: - if opr and not (h_limit and self._is_w_same(rate, h_limit, 'unit') and self.is_w_same(rate, h_limit, 'number')): - commands.append(cmd + (' ' + attr + ' ' + key + ' ' + str(rate['number']) + '/' + rate['unit'])) - if not opr and not (h_limit and self._is_w_same(rate, h_limit, 'unit') and self._is_w_same(rate, h_limit, 'number')): - commands.append(cmd + (' ' + attr + ' ' + key)) - return commands - - def _add_src_or_dest(self, attr, w, h, cmd, opr=True): - """ - This function forms the commands for 'src/dest' attributes based on the 'opr'. - :param attr: attribute name. - :param w: base config. - :param h: target config. - :param cmd: commands to be prepend. - :return: generated list of commands. - """ - commands = [] - h_group = {} - g_set = ('port_group', - 'address_group', - 'network_group') - if w[attr]: - keys = ('address', 'mac_address', 'port') - for key in keys: - if opr and key in w[attr].keys() and not (h and attr in h.keys() and self._is_w_same(w[attr], h[attr], key)): - commands.append(cmd + (' ' + attr + ' ' + key.replace("_", "-") + ' ' + w[attr].get(key))) - elif not opr and key in w[attr].keys() and not (h and attr in h.keys() and self._in_target(h[attr], key)): - commands.append(cmd + (' ' + attr + ' ' + key)) - - key = 'group' - group = w[attr].get(key) or {} - if group: - if h and key in h[attr].keys(): - h_group = h[attr].get(key) or {} - for item, val in iteritems(group): - if val: - if opr and item in g_set and not (h_group and self._is_w_same(group, h_group, item)): - commands.append(cmd + (' ' + attr + ' ' + key + ' ' + item.replace("_", "-") + ' ' + val)) - elif not opr and item in g_set and not (h_group and self._in_target(h_group, item)): - commands.append(cmd + (' ' + attr + ' ' + key + ' ' + item.replace("_", "-"))) - return commands - - def search_r_sets_in_have(self, have, w_name, type='rule_sets'): - """ - This function returns the rule-set/rule if it is present in target config. - :param have: target config. - :param w_name: rule-set name. - :param type: rule_sets/rule/r_list. - :return: rule-set/rule. - """ - if have: - key = 'name' - if type == 'rules': - key = 'number' - for r in have: - if r[key] == w_name: - return r - elif type == 'r_list': - for h in have: - r_sets = self._get_r_sets(h) - for rs in r_sets: - if rs[key] == w_name: - return rs - else: - for rs in have: - if rs[key] == w_name: - return rs - return None - - def _get_r_sets(self, item, type='rule_sets'): - """ - This function returns the list of rule-sets/rules. - :param item: config dictionary. - :param type: rule_sets/rule/r_list. - :return: list of rule-sets/rules. - """ - rs_list = [] - r_sets = item[type] - if r_sets: - for rs in r_sets: - rs_list.append(rs) - return rs_list - - def _compute_command(self, afi, name=None, number=None, attrib=None, value=None, remove=False, opr=True): - """ - This function construct the add/delete command based on passed attributes. - :param afi: address type. - :param name: rule-set name. - :param number: rule-number. - :param attrib: attribute name. - :param value: value. - :param remove: True if delete command needed to be construct. - :param opr: opeeration flag. - :return: generated command. - """ - if remove or not opr: - cmd = 'delete firewall ' + self._get_fw_type(afi) - else: - cmd = 'set firewall ' + self._get_fw_type(afi) - if name: - cmd += (' ' + name) - if number: - cmd += (' rule ' + str(number)) - if attrib: - cmd += (' ' + attrib.replace("_", "-")) - if value and opr and attrib != 'enable_default_log' and attrib != 'disabled': - cmd += (" '" + str(value) + "'") - return cmd - - def _add_r_base_attrib(self, afi, name, attr, rule, opr=True): - """ - This function forms the command for 'rules' attributes which doesn't - have further sub attributes. - :param afi: address type. - :param name: rule-set name - :param attrib: attribute name - :param rule: rule config dictionary. - :param opr: True/False. - :return: generated command. - """ - if attr == 'number': - command = self._compute_command( - afi=afi, name=name, number=rule['number'], opr=opr - ) - else: - command = self._compute_command( - afi=afi, name=name, number=rule['number'], attrib=attr, value=rule[attr], opr=opr - ) - return command - - def _add_rs_base_attrib(self, afi, name, attrib, rule, opr=True): - """ - - This function forms the command for 'rule-sets' attributes which doesn't - have further sub attributes. - :param afi: address type. - :param name: rule-set name - :param attrib: attribute name - :param rule: rule config dictionary. - :param opr: True/False. - :return: generated command. - """ - command = self._compute_command(afi=afi, name=name, attrib=attrib, value=rule[attrib], opr=opr) - return command - - def _bool_to_str(self, val): - """ - This function converts the bool value into string. - :param val: bool value. - :return: enable/disable. - """ - return 'enable' if val else 'disable' - - def _get_fw_type(self, afi): - """ - This function returns the firewall rule-set type based on IP address. - :param afi: address type - :return: rule-set type. - """ - return 'ipv6-name' if afi == 'ipv6' else 'name' - - def _is_del(self, l_set, h, key='number'): - """ - This function checks whether rule needs to be deleted based on - the rule number. - :param l_set: attribute set. - :param h: target config. - :param key: number. - :return: True/False. - """ - return key in l_set and not (h and self._in_target(h, key)) - - def _is_w_same(self, w, h, key): - """ - This function checks whether the key value is same in base and - target config dictionary. - :param w: base config. - :param h: target config. - :param key:attribute name. - :return: True/False. - """ - return True if h and key in h and h[key] == w[key] else False - - def _in_target(self, h, key): - """ - This function checks whether the target nexist and key present in target config. - :param h: target config. - :param key: attribute name. - :return: True/False. - """ - return True if h and key in h else False - - def _is_base_attrib(self, key): - """ - This function checks whether key is present in predefined - based attribute set. - :param key: - :return: True/False. - """ - r_set = ('p2p', - 'ipsec', - 'action', - 'fragment', - 'protocol', - 'disabled', - 'description', - 'mac_address', - 'default_action', - 'enable_default_log') - return True if key in r_set else False diff --git a/lib/ansible/module_utils/network/vyos/config/interfaces/interfaces.py b/lib/ansible/module_utils/network/vyos/config/interfaces/interfaces.py deleted file mode 100644 index 0d646ead30..0000000000 --- a/lib/ansible/module_utils/network/vyos/config/interfaces/interfaces.py +++ /dev/null @@ -1,284 +0,0 @@ -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -""" -The vyos_interfaces class -It is in this file where the current configuration (as dict) -is compared to the provided configuration (as dict) and the command set -necessary to bring the current configuration to it's desired end-state is -created -""" - -from __future__ import absolute_import, division, print_function -__metaclass__ = type - - -from copy import deepcopy -from ansible.module_utils.network.common.cfg.base import ConfigBase -from ansible.module_utils.network.common.utils import to_list, dict_diff, remove_empties -from ansible.module_utils.six import iteritems -from ansible.module_utils.network.vyos.facts.facts import Facts -from ansible.module_utils.network. \ - vyos.utils.utils import search_obj_in_list, get_interface_type, dict_delete - - -class Interfaces(ConfigBase): - """ - The vyos_interfaces class - """ - - gather_subset = [ - '!all', - '!min', - ] - - gather_network_resources = [ - 'interfaces' - ] - - def __init__(self, module): - super(Interfaces, self).__init__(module) - - def get_interfaces_facts(self): - """ Get the 'facts' (the current configuration) - - :rtype: A dictionary - :returns: The current configuration as a dictionary - """ - facts, _warnings = Facts(self._module).get_facts(self.gather_subset, - self.gather_network_resources) - interfaces_facts = facts['ansible_network_resources'].get('interfaces') - if not interfaces_facts: - return [] - return interfaces_facts - - def execute_module(self): - """ Execute the module - :rtype: A dictionary - :returns: The result from module execution - """ - result = {'changed': False} - commands = list() - warnings = list() - - existing_interfaces_facts = self.get_interfaces_facts() - commands.extend(self.set_config(existing_interfaces_facts)) - if commands: - if self._module.check_mode: - resp = self._connection.edit_config(commands, commit=False) - else: - resp = self._connection.edit_config(commands) - result['changed'] = True - - result['commands'] = commands - - if self._module._diff: - result['diff'] = resp['diff'] if result['changed'] else None - - changed_interfaces_facts = self.get_interfaces_facts() - - result['before'] = existing_interfaces_facts - if result['changed']: - result['after'] = changed_interfaces_facts - - result['warnings'] = warnings - return result - - def set_config(self, existing_interfaces_facts): - """ Collect the configuration from the args passed to the module, - collect the current configuration (as a dict from facts) - - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - want = self._module.params['config'] - have = existing_interfaces_facts - resp = self.set_state(want, have) - return to_list(resp) - - def set_state(self, want, have): - """ Select the appropriate function based on the state provided - - :param want: the desired configuration as a dictionary - :param have: the current configuration as a dictionary - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - commands = [] - state = self._module.params['state'] - - if state in ('merged', 'replaced', 'overridden') and not want: - self._module.fail_json(msg='value of config parameter must not be empty for state {0}'.format(state)) - - if state == 'overridden': - commands.extend(self._state_overridden(want=want, have=have)) - - elif state == 'deleted': - if not want: - for intf in have: - commands.extend( - self._state_deleted( - {'name': intf['name']}, - intf - ) - ) - else: - for item in want: - obj_in_have = search_obj_in_list(item['name'], have) - commands.extend( - self._state_deleted( - item, obj_in_have - ) - ) - else: - for item in want: - name = item['name'] - obj_in_have = search_obj_in_list(name, have) - - if not obj_in_have: - obj_in_have = {'name': item['name']} - - elif state == 'merged': - commands.extend( - self._state_merged( - item, obj_in_have - ) - ) - - elif state == 'replaced': - commands.extend( - self._state_replaced( - item, obj_in_have - ) - ) - - return commands - - def _state_replaced(self, want, have): - """ The command generator when state is replaced - - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - commands = [] - if have: - commands.extend(self._state_deleted(want, have)) - - commands.extend(self._state_merged(want, have)) - - return commands - - def _state_overridden(self, want, have): - """ The command generator when state is overridden - - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - commands = [] - - for intf in have: - intf_in_want = search_obj_in_list(intf['name'], want) - if not intf_in_want: - commands.extend(self._state_deleted({'name': intf['name']}, intf)) - - for intf in want: - intf_in_have = search_obj_in_list(intf['name'], have) - commands.extend(self._state_replaced(intf, intf_in_have)) - - return commands - - def _state_merged(self, want, have): - """ The command generator when state is merged - - :rtype: A list - :returns: the commands necessary to merge the provided into - the current configuration - """ - commands = [] - want_copy = deepcopy(remove_empties(want)) - have_copy = deepcopy(have) - - want_vifs = want_copy.pop('vifs', []) - have_vifs = have_copy.pop('vifs', []) - - updates = dict_diff(have_copy, want_copy) - - if updates: - for key, value in iteritems(updates): - commands.append(self._compute_commands(key=key, value=value, interface=want_copy['name'])) - - if want_vifs: - for want_vif in want_vifs: - have_vif = search_obj_in_list(want_vif['vlan_id'], have_vifs, key='vlan_id') - if not have_vif: - have_vif = {'vlan_id': want_vif['vlan_id'], 'enabled': True} - - vif_updates = dict_diff(have_vif, want_vif) - if vif_updates: - for key, value in iteritems(vif_updates): - commands.append(self._compute_commands(key=key, value=value, interface=want_copy['name'], vif=want_vif['vlan_id'])) - - return commands - - def _state_deleted(self, want, have): - """ The command generator when state is deleted - - :rtype: A list - :returns: the commands necessary to remove the current configuration - of the provided objects - """ - commands = [] - - want_copy = deepcopy(remove_empties(want)) - have_copy = deepcopy(have) - - want_vifs = want_copy.pop('vifs', []) - have_vifs = have_copy.pop('vifs', []) - - for key in dict_delete(have_copy, want_copy).keys(): - if key == 'enabled': - continue - commands.append(self._compute_commands(key=key, interface=want_copy['name'], remove=True)) - if have_copy['enabled'] is False: - commands.append(self._compute_commands(key='enabled', value=True, interface=want_copy['name'])) - - if have_vifs: - for have_vif in have_vifs: - want_vif = search_obj_in_list(have_vif['vlan_id'], want_vifs, key='vlan_id') - if not want_vif: - want_vif = {'vlan_id': have_vif['vlan_id'], 'enabled': True} - - for key in dict_delete(have_vif, want_vif).keys(): - if key == 'enabled': - continue - commands.append(self._compute_commands(key=key, interface=want_copy['name'], vif=want_vif['vlan_id'], remove=True)) - if have_vif['enabled'] is False: - commands.append(self._compute_commands(key='enabled', value=True, interface=want_copy['name'], vif=want_vif['vlan_id'])) - - return commands - - def _compute_commands(self, interface, key, vif=None, value=None, remove=False): - intf_context = 'interfaces {0} {1}'.format(get_interface_type(interface), interface) - set_cmd = 'set {0}'.format(intf_context) - del_cmd = 'delete {0}'.format(intf_context) - - if vif: - set_cmd = set_cmd + (' vif {0}'.format(vif)) - del_cmd = del_cmd + (' vif {0}'.format(vif)) - - if key == 'enabled': - if not value: - command = "{0} disable".format(set_cmd) - else: - command = "{0} disable".format(del_cmd) - else: - if not remove: - command = "{0} {1} '{2}'".format(set_cmd, key, value) - else: - command = "{0} {1}".format(del_cmd, key) - - return command diff --git a/lib/ansible/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py b/lib/ansible/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py deleted file mode 100644 index 4407b98727..0000000000 --- a/lib/ansible/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py +++ /dev/null @@ -1,278 +0,0 @@ -# -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -""" -The vyos_l3_interfaces class -It is in this file where the current configuration (as dict) -is compared to the provided configuration (as dict) and the command set -necessary to bring the current configuration to it's desired end-state is -created -""" - -from __future__ import absolute_import, division, print_function -__metaclass__ = type - - -from copy import deepcopy -from ansible.module_utils.network.common.cfg.base import ConfigBase -from ansible.module_utils.network.common.utils import to_list, remove_empties -from ansible.module_utils.six import iteritems -from ansible.module_utils.network.vyos.facts.facts import Facts -from ansible.module_utils.network. \ - vyos.utils.utils import search_obj_in_list, get_interface_type, diff_list_of_dicts - - -class L3_interfaces(ConfigBase): - """ - The vyos_l3_interfaces class - """ - - gather_subset = [ - '!all', - '!min', - ] - - gather_network_resources = [ - 'l3_interfaces', - ] - - def __init__(self, module): - super(L3_interfaces, self).__init__(module) - - def get_l3_interfaces_facts(self): - """ Get the 'facts' (the current configuration) - - :rtype: A dictionary - :returns: The current configuration as a dictionary - """ - facts, _warnings = Facts(self._module).get_facts(self.gather_subset, self.gather_network_resources) - l3_interfaces_facts = facts['ansible_network_resources'].get('l3_interfaces') - if not l3_interfaces_facts: - return [] - return l3_interfaces_facts - - def execute_module(self): - """ Execute the module - - :rtype: A dictionary - :returns: The result from module execution - """ - result = {'changed': False} - warnings = list() - commands = list() - - existing_l3_interfaces_facts = self.get_l3_interfaces_facts() - commands.extend(self.set_config(existing_l3_interfaces_facts)) - if commands: - if self._module.check_mode: - resp = self._connection.edit_config(commands, commit=False) - else: - resp = self._connection.edit_config(commands) - result['changed'] = True - - result['commands'] = commands - - if self._module._diff: - result['diff'] = resp['diff'] if result['changed'] else None - - changed_l3_interfaces_facts = self.get_l3_interfaces_facts() - - result['before'] = existing_l3_interfaces_facts - if result['changed']: - result['after'] = changed_l3_interfaces_facts - - result['warnings'] = warnings - return result - - def set_config(self, existing_l3_interfaces_facts): - """ Collect the configuration from the args passed to the module, - collect the current configuration (as a dict from facts) - - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - want = self._module.params['config'] - have = existing_l3_interfaces_facts - resp = self.set_state(want, have) - return to_list(resp) - - def set_state(self, want, have): - """ Select the appropriate function based on the state provided - - :param want: the desired configuration as a dictionary - :param have: the current configuration as a dictionary - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - commands = [] - state = self._module.params['state'] - - if state in ('merged', 'replaced', 'overridden') and not want: - self._module.fail_json(msg='value of config parameter must not be empty for state {0}'.format(state)) - - if state == 'overridden': - commands.extend(self._state_overridden(want=want, have=have)) - - elif state == 'deleted': - if not want: - for intf in have: - commands.extend( - self._state_deleted( - {'name': intf['name']}, - intf - ) - ) - else: - for item in want: - obj_in_have = search_obj_in_list(item['name'], have) - commands.extend( - self._state_deleted( - item, obj_in_have - ) - ) - else: - for item in want: - name = item['name'] - obj_in_have = search_obj_in_list(name, have) - - if not obj_in_have: - obj_in_have = {'name': item['name']} - - if state == 'merged': - commands.extend( - self._state_merged( - item, obj_in_have - ) - ) - - elif state == 'replaced': - commands.extend( - self._state_replaced( - item, obj_in_have - ) - ) - - return commands - - def _state_replaced(self, want, have): - """ The command generator when state is replaced - - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - commands = [] - if have: - commands.extend(self._state_deleted(want, have)) - - commands.extend(self._state_merged(want, have)) - - return commands - - def _state_overridden(self, want, have): - """ The command generator when state is overridden - - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - commands = [] - - for intf in have: - intf_in_want = search_obj_in_list(intf['name'], want) - if not intf_in_want: - commands.extend(self._state_deleted({'name': intf['name']}, intf)) - - for intf in want: - intf_in_have = search_obj_in_list(intf['name'], have) - commands.extend(self._state_replaced(intf, intf_in_have)) - - return commands - - def _state_merged(self, want, have): - """ The command generator when state is merged - - :rtype: A list - :returns: the commands necessary to merge the provided into - the current configuration - """ - commands = [] - want_copy = deepcopy(remove_empties(want)) - have_copy = deepcopy(remove_empties(have)) - - want_vifs = want_copy.pop('vifs', []) - have_vifs = have_copy.pop('vifs', []) - - for update in self._get_updates(want_copy, have_copy): - for key, value in iteritems(update): - commands.append(self._compute_commands(key=key, value=value, interface=want_copy['name'])) - - if want_vifs: - for want_vif in want_vifs: - have_vif = search_obj_in_list(want_vif['vlan_id'], have_vifs, key='vlan_id') - if not have_vif: - have_vif = {} - - for update in self._get_updates(want_vif, have_vif): - for key, value in iteritems(update): - commands.append(self._compute_commands(key=key, value=value, interface=want_copy['name'], vif=want_vif['vlan_id'])) - - return commands - - def _state_deleted(self, want, have): - """ The command generator when state is deleted - - :rtype: A list - :returns: the commands necessary to remove the current configuration - of the provided objects - """ - commands = [] - want_copy = deepcopy(remove_empties(want)) - have_copy = deepcopy(have) - - want_vifs = want_copy.pop('vifs', []) - have_vifs = have_copy.pop('vifs', []) - - for update in self._get_updates(have_copy, want_copy): - for key, value in iteritems(update): - commands.append(self._compute_commands(key=key, value=value, interface=want_copy['name'], remove=True)) - - if have_vifs: - for have_vif in have_vifs: - want_vif = search_obj_in_list(have_vif['vlan_id'], want_vifs, key='vlan_id') - if not want_vif: - want_vif = {'vlan_id': have_vif['vlan_id']} - - for update in self._get_updates(have_vif, want_vif): - for key, value in iteritems(update): - commands.append(self._compute_commands(key=key, interface=want_copy['name'], value=value, vif=want_vif['vlan_id'], remove=True)) - - return commands - - def _compute_commands(self, interface, key, vif=None, value=None, remove=False): - intf_context = 'interfaces {0} {1}'.format(get_interface_type(interface), interface) - set_cmd = 'set {0}'.format(intf_context) - del_cmd = 'delete {0}'.format(intf_context) - - if vif: - set_cmd = set_cmd + (' vif {0}'.format(vif)) - del_cmd = del_cmd + (' vif {0}'.format(vif)) - - if remove: - command = "{0} {1} '{2}'".format(del_cmd, key, value) - else: - command = "{0} {1} '{2}'".format(set_cmd, key, value) - - return command - - def _get_updates(self, want, have): - updates = [] - - updates = diff_list_of_dicts(want.get('ipv4', []), have.get('ipv4', [])) - updates.extend(diff_list_of_dicts(want.get('ipv6', []), have.get('ipv6', []))) - - return updates diff --git a/lib/ansible/module_utils/network/vyos/config/lag_interfaces/lag_interfaces.py b/lib/ansible/module_utils/network/vyos/config/lag_interfaces/lag_interfaces.py deleted file mode 100644 index 49abf0589f..0000000000 --- a/lib/ansible/module_utils/network/vyos/config/lag_interfaces/lag_interfaces.py +++ /dev/null @@ -1,389 +0,0 @@ -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -""" -The vyos_lag_interfaces class -It is in this file where the current configuration (as dict) -is compared to the provided configuration (as dict) and the command set -necessary to bring the current configuration to it's desired end-state is -created -""" -from __future__ import absolute_import, division, print_function -__metaclass__ = type -from ansible.module_utils.network.common.cfg.base import ConfigBase -from ansible.module_utils.network.vyos.facts.facts import Facts -from ansible.module_utils.network.common.utils import to_list, dict_diff -from ansible.module_utils.six import iteritems -from ansible.module_utils.network. \ - vyos.utils.utils import search_obj_in_list, \ - get_lst_diff_for_dicts, list_diff_want_only, list_diff_have_only - - -class Lag_interfaces(ConfigBase): - """ - The vyos_lag_interfaces class - """ - - gather_subset = [ - '!all', - '!min', - ] - - gather_network_resources = [ - 'lag_interfaces', - ] - - params = ['arp_monitor', 'hash_policy', 'members', 'mode', 'name', 'primary'] - - def __init__(self, module): - super(Lag_interfaces, self).__init__(module) - - def get_lag_interfaces_facts(self): - """ Get the 'facts' (the current configuration) - - :rtype: A dictionary - :returns: The current configuration as a dictionary - """ - facts, _warnings = Facts(self._module).get_facts(self.gather_subset, - self.gather_network_resources) - lag_interfaces_facts = facts['ansible_network_resources'].get('lag_interfaces') - if not lag_interfaces_facts: - return [] - return lag_interfaces_facts - - def execute_module(self): - """ Execute the module - - :rtype: A dictionary - :returns: The result from module execution - """ - result = {'changed': False} - commands = list() - warnings = list() - existing_lag_interfaces_facts = self.get_lag_interfaces_facts() - commands.extend(self.set_config(existing_lag_interfaces_facts)) - if commands: - if self._module.check_mode: - resp = self._connection.edit_config(commands, commit=False) - else: - resp = self._connection.edit_config(commands) - result['changed'] = True - - result['commands'] = commands - - if self._module._diff: - result['diff'] = resp['diff'] if result['changed'] else None - - changed_lag_interfaces_facts = self.get_lag_interfaces_facts() - - result['before'] = existing_lag_interfaces_facts - if result['changed']: - result['after'] = changed_lag_interfaces_facts - - result['warnings'] = warnings - return result - - def set_config(self, existing_lag_interfaces_facts): - """ Collect the configuration from the args passed to the module, - collect the current configuration (as a dict from facts) - - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - want = self._module.params['config'] - have = existing_lag_interfaces_facts - resp = self.set_state(want, have) - return to_list(resp) - - def set_state(self, want, have): - """ Select the appropriate function based on the state provided - - :param want: the desired configuration as a dictionary - :param have: the current configuration as a dictionary - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - commands = [] - state = self._module.params['state'] - if state in ('merged', 'replaced', 'overridden') and not want: - self._module.fail_json(msg='value of config parameter must not be empty for state {0}'.format(state)) - if state == 'overridden': - commands.extend(self._state_overridden(want, have)) - elif state == 'deleted': - if want: - for want_item in want: - name = want_item['name'] - obj_in_have = search_obj_in_list(name, have) - commands.extend(self._state_deleted(obj_in_have)) - else: - for have_item in have: - commands.extend(self._state_deleted(have_item)) - else: - for want_item in want: - name = want_item['name'] - obj_in_have = search_obj_in_list(name, have) - if state == 'merged': - commands.extend(self._state_merged(want_item, obj_in_have)) - elif state == 'replaced': - commands.extend(self._state_replaced(want_item, obj_in_have)) - return commands - - def _state_replaced(self, want, have): - """ The command generator when state is replaced - - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - commands = [] - if have: - commands.extend(self._render_del_commands(want, have)) - commands.extend(self._state_merged(want, have)) - return commands - - def _state_overridden(self, want, have): - """ The command generator when state is overridden - - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - commands = [] - for have_item in have: - lag_name = have_item['name'] - obj_in_want = search_obj_in_list(lag_name, want) - if not obj_in_want: - commands.extend(self._purge_attribs(have_item)) - - for want_item in want: - name = want_item['name'] - obj_in_have = search_obj_in_list(name, have) - commands.extend(self._state_replaced(want_item, obj_in_have)) - return commands - - def _state_merged(self, want, have): - """ The command generator when state is merged - - :rtype: A list - :returns: the commands necessary to merge the provided into - the current configuration - """ - commands = [] - if have: - commands.extend(self._render_updates(want, have)) - else: - commands.extend(self._render_set_commands(want)) - return commands - - def _state_deleted(self, have): - """ The command generator when state is deleted - - :rtype: A list - :returns: the commands necessary to remove the current configuration - of the provided objects - """ - commands = [] - if have: - commands.extend(self._purge_attribs(have)) - return commands - - def _render_updates(self, want, have): - commands = [] - - temp_have_members = have.pop('members', None) - temp_want_members = want.pop('members', None) - - updates = dict_diff(have, want) - - if temp_have_members: - have['members'] = temp_have_members - if temp_want_members: - want['members'] = temp_want_members - - commands.extend(self._add_bond_members(want, have)) - - if updates: - for key, value in iteritems(updates): - if value: - if key == 'arp_monitor': - commands.extend( - self._add_arp_monitor(updates, key, want, have) - ) - else: - commands.append(self._compute_command(have['name'], key, str(value))) - return commands - - def _render_set_commands(self, want): - commands = [] - have = [] - - params = Lag_interfaces.params - - for attrib in params: - value = want[attrib] - if value: - if attrib == 'arp_monitor': - commands.extend( - self._add_arp_monitor(want, attrib, want, have) - ) - elif attrib == 'members': - commands.extend( - self._add_bond_members(want, have) - ) - elif attrib != 'name': - commands.append( - self._compute_command(want['name'], attrib, value=str(value)) - ) - return commands - - def _purge_attribs(self, have): - commands = [] - for item in Lag_interfaces.params: - if have.get(item): - if item == 'members': - commands.extend( - self._delete_bond_members(have) - ) - elif item != 'name': - commands.append( - self._compute_command(have['name'], attrib=item, remove=True) - ) - return commands - - def _render_del_commands(self, want, have): - commands = [] - - params = Lag_interfaces.params - for attrib in params: - if attrib == 'members': - commands.extend( - self._update_bond_members(attrib, want, have) - ) - elif attrib == 'arp_monitor': - commands.extend( - self._update_arp_monitor(attrib, want, have) - ) - elif have.get(attrib) and not want.get(attrib): - commands.append( - self._compute_command(have['name'], attrib, remove=True) - ) - return commands - - def _add_bond_members(self, want, have): - commands = [] - diff_members = get_lst_diff_for_dicts(want, have, 'members') - if diff_members: - for key in diff_members: - commands.append( - self._compute_command(key['member'], 'bond-group', want['name'], type='ethernet') - ) - return commands - - def _add_arp_monitor(self, updates, key, want, have): - commands = [] - arp_monitor = updates.get(key) or {} - diff_targets = self._get_arp_monitor_target_diff(want, have, key, 'target') - - if 'interval' in arp_monitor: - commands.append( - self._compute_command( - key=want['name'] + ' arp-monitor', attrib='interval', value=str(arp_monitor['interval']) - ) - ) - if diff_targets: - for target in diff_targets: - commands.append( - self._compute_command(key=want['name'] + ' arp-monitor', attrib='target', value=target) - ) - return commands - - def _delete_bond_members(self, have): - commands = [] - for member in have['members']: - commands.append( - self._compute_command( - member['member'], 'bond-group', have['name'], remove=True, type='ethernet' - ) - ) - return commands - - def _update_arp_monitor(self, key, want, have): - commands = [] - want_arp_target = [] - have_arp_target = [] - want_arp_monitor = want.get(key) or {} - have_arp_monitor = have.get(key) or {} - - if want_arp_monitor and 'target' in want_arp_monitor: - want_arp_target = want_arp_monitor['target'] - - if have_arp_monitor and 'target' in have_arp_monitor: - have_arp_target = have_arp_monitor['target'] - - if 'interval' in have_arp_monitor and not want_arp_monitor: - commands.append( - self._compute_command( - key=have['name'] + ' arp-monitor', attrib='interval', remove=True - ) - ) - if 'target' in have_arp_monitor: - target_diff = list_diff_have_only(want_arp_target, have_arp_target) - if target_diff: - for target in target_diff: - commands.append( - self._compute_command( - key=have['name'] + ' arp-monitor', attrib='target', value=target, remove=True - ) - ) - - return commands - - def _update_bond_members(self, key, want, have): - commands = [] - want_members = want.get(key) or [] - have_members = have.get(key) or [] - - members_diff = list_diff_have_only(want_members, have_members) - if members_diff: - for member in members_diff: - commands.append( - self._compute_command( - member['member'], 'bond-group', have['name'], True, 'ethernet' - ) - ) - return commands - - def _get_arp_monitor_target_diff(self, want_list, have_list, dict_name, lst): - want_arp_target = [] - have_arp_target = [] - - want_arp_monitor = want_list.get(dict_name) or {} - if want_arp_monitor and lst in want_arp_monitor: - want_arp_target = want_arp_monitor[lst] - - if not have_list: - diff = want_arp_target - else: - have_arp_monitor = have_list.get(dict_name) or {} - if have_arp_monitor and lst in have_arp_monitor: - have_arp_target = have_arp_monitor[lst] - - diff = list_diff_want_only(want_arp_target, have_arp_target) - return diff - - def _compute_command(self, key, attrib, value=None, remove=False, type='bonding'): - if remove: - cmd = 'delete interfaces ' + type - else: - cmd = 'set interfaces ' + type - cmd += (' ' + key) - if attrib == 'arp_monitor': - attrib = 'arp-monitor' - elif attrib == 'hash_policy': - attrib = 'hash-policy' - cmd += (' ' + attrib) - if value: - cmd += (" '" + value + "'") - return cmd diff --git a/lib/ansible/module_utils/network/vyos/config/lldp_global/lldp_global.py b/lib/ansible/module_utils/network/vyos/config/lldp_global/lldp_global.py deleted file mode 100644 index 0f3a8947b6..0000000000 --- a/lib/ansible/module_utils/network/vyos/config/lldp_global/lldp_global.py +++ /dev/null @@ -1,240 +0,0 @@ -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -""" -The vyos_lldp_global class -It is in this file where the current configuration (as dict) -is compared to the provided configuration (as dict) and the command set -necessary to bring the current configuration to it's desired end-state is -created -""" -from __future__ import absolute_import, division, print_function -__metaclass__ = type -from ansible.module_utils.network.common.cfg.base import ConfigBase -from ansible.module_utils.network.common.utils import to_list, dict_diff -from ansible.module_utils.network.vyos.facts.facts import Facts -from ansible.module_utils.six import iteritems -from ansible.module_utils.network.vyos.utils.utils import get_lst_diff_for_dicts, list_diff_have_only - - -class Lldp_global(ConfigBase): - """ - The vyos_lldp_global class - """ - - gather_subset = [ - '!all', - '!min', - ] - - gather_network_resources = [ - 'lldp_global', - ] - - params = ['enable', 'address', 'snmp', 'legacy_protocols'] - - def __init__(self, module): - super(Lldp_global, self).__init__(module) - - def get_lldp_global_facts(self): - """ Get the 'facts' (the current configuration) - - :rtype: A dictionary - :returns: The current configuration as a dictionary - """ - facts, _warnings = Facts(self._module).get_facts(self.gather_subset, - self.gather_network_resources) - lldp_global_facts = facts['ansible_network_resources'].get('lldp_global') - if not lldp_global_facts: - return {} - return lldp_global_facts - - def execute_module(self): - """ Execute the module - - :rtype: A dictionary - :returns: The result from module execution - """ - result = {'changed': False} - commands = list() - warnings = list() - - existing_lldp_global_facts = self.get_lldp_global_facts() - commands.extend(self.set_config(existing_lldp_global_facts)) - if commands: - if not self._module.check_mode: - self._connection.edit_config(commands) - result['changed'] = True - result['commands'] = commands - - changed_lldp_global_facts = self.get_lldp_global_facts() - - result['before'] = existing_lldp_global_facts - if result['changed']: - result['after'] = changed_lldp_global_facts - - result['warnings'] = warnings - return result - - def set_config(self, existing_lldp_global_facts): - """ Collect the configuration from the args passed to the module, - collect the current configuration (as a dict from facts) - - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - want = self._module.params['config'] - have = existing_lldp_global_facts - resp = self.set_state(want, have) - return to_list(resp) - - def set_state(self, want, have): - """ Select the appropriate function based on the state provided - - :param want: the desired configuration as a dictionary - :param have: the current configuration as a dictionary - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - commands = [] - state = self._module.params['state'] - if state in ('merged', 'replaced') and not want: - self._module.fail_json(msg='value of config parameter must not be empty for state {0}'.format(state)) - if state == 'deleted': - commands.extend(self._state_deleted(want=None, have=have)) - elif state == 'merged': - commands.extend(self._state_merged(want=want, have=have)) - elif state == 'replaced': - commands.extend(self._state_replaced(want=want, have=have)) - return commands - - def _state_replaced(self, want, have): - """ The command generator when state is replaced - - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - commands = [] - if have: - commands.extend(self._state_deleted(want, have)) - commands.extend(self._state_merged(want, have)) - return commands - - def _state_merged(self, want, have): - """ The command generator when state is merged - - :rtype: A list - :returns: the commands necessary to merge the provided into - the current configuration - """ - commands = [] - commands.extend(self._render_updates(want, have)) - return commands - - def _state_deleted(self, want, have): - """ The command generator when state is deleted - - :rtype: A list - :returns: the commands necessary to remove the current configuration - of the provided objects - """ - commands = [] - if want: - for item in Lldp_global.params: - if item == 'legacy_protocols': - commands.extend(self._update_lldp_protocols(want, have)) - elif have.get(item) and not want.get(item) and item != 'enable': - commands.append(Lldp_global.del_cmd + item) - elif have: - for item in Lldp_global.params: - if have.get(item): - if item == 'legacy_protocols': - commands.append( - self._compute_command('legacy-protocols', remove=True) - ) - elif item == 'address': - commands.append( - self._compute_command('management-address', remove=True) - ) - elif item == 'snmp': - commands.append( - self._compute_command(item, remove=True) - ) - - return commands - - def _render_updates(self, want, have): - commands = [] - if have: - temp_have_legacy_protos = have.pop('legacy_protocols', None) - else: - have = {} - temp_want_legacy_protos = want.pop('legacy_protocols', None) - - updates = dict_diff(have, want) - - if have and temp_have_legacy_protos: - have['legacy_protocols'] = temp_have_legacy_protos - if not have and temp_want_legacy_protos: - want['legacy_protocols'] = temp_want_legacy_protos - - commands.extend(self._add_lldp_protocols(want, have)) - - if updates: - for key, value in iteritems(updates): - if value: - if key == 'enable': - commands.append( - self._compute_command() - ) - elif key == 'address': - commands.append( - self._compute_command('management-address', str(value)) - ) - elif key == 'snmp': - if value == 'disable': - commands.append( - self._compute_command(key, remove=True) - ) - else: - commands.append( - self._compute_command(key, str(value)) - ) - return commands - - def _add_lldp_protocols(self, want, have): - commands = [] - diff_members = get_lst_diff_for_dicts(want, have, 'legacy_protocols') - for key in diff_members: - commands.append( - self._compute_command('legacy-protocols', key) - ) - return commands - - def _update_lldp_protocols(self, want_item, have_item): - commands = [] - want_protocols = want_item.get('legacy_protocols') or [] - have_protocols = have_item.get('legacy_protocols') or [] - - members_diff = list_diff_have_only(want_protocols, have_protocols) - if members_diff: - for member in members_diff: - commands.append( - self._compute_command('legacy-protocols', member, remove=True) - ) - return commands - - def _compute_command(self, key=None, value=None, remove=False): - if remove: - cmd = 'delete service lldp' - else: - cmd = 'set service lldp' - if key: - cmd += (' ' + key) - - if value: - cmd += (" '" + value + "'") - return cmd diff --git a/lib/ansible/module_utils/network/vyos/config/lldp_interfaces/lldp_interfaces.py b/lib/ansible/module_utils/network/vyos/config/lldp_interfaces/lldp_interfaces.py deleted file mode 100644 index 21e135daf5..0000000000 --- a/lib/ansible/module_utils/network/vyos/config/lldp_interfaces/lldp_interfaces.py +++ /dev/null @@ -1,396 +0,0 @@ -# -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -""" -The vyos_lldp_interfaces class -It is in this file where the current configuration (as dict) -is compared to the provided configuration (as dict) and the command set -necessary to bring the current configuration to it's desired end-state is -created -""" - -from __future__ import absolute_import, division, print_function -__metaclass__ = type - - -from ansible.module_utils.network.common.cfg.base import ConfigBase -from ansible.module_utils.network.vyos.facts.facts import Facts -from ansible.module_utils.network.common.utils import to_list, dict_diff -from ansible.module_utils.six import iteritems -from ansible.module_utils.network. vyos.utils.utils import search_obj_in_list, \ - search_dict_tv_in_list, key_value_in_dict, is_dict_element_present - - -class Lldp_interfaces(ConfigBase): - """ - The vyos_lldp_interfaces class - """ - - gather_subset = [ - '!all', - '!min', - ] - - gather_network_resources = [ - 'lldp_interfaces', - ] - - params = ['enable', 'location', 'name'] - - def __init__(self, module): - super(Lldp_interfaces, self).__init__(module) - - def get_lldp_interfaces_facts(self): - """ Get the 'facts' (the current configuration) - - :rtype: A dictionary - :returns: The current configuration as a dictionary - """ - facts, _warnings = Facts(self._module).get_facts(self.gather_subset, - self.gather_network_resources) - lldp_interfaces_facts = facts['ansible_network_resources'].get('lldp_interfaces') - if not lldp_interfaces_facts: - return [] - return lldp_interfaces_facts - - def execute_module(self): - """ Execute the module - - :rtype: A dictionary - :returns: The result from module execution - """ - result = {'changed': False} - commands = list() - warnings = list() - existing_lldp_interfaces_facts = self.get_lldp_interfaces_facts() - commands.extend(self.set_config(existing_lldp_interfaces_facts)) - if commands: - if self._module.check_mode: - resp = self._connection.edit_config(commands, commit=False) - else: - resp = self._connection.edit_config(commands) - result['changed'] = True - - result['commands'] = commands - - if self._module._diff: - result['diff'] = resp['diff'] if result['changed'] else None - - changed_lldp_interfaces_facts = self.get_lldp_interfaces_facts() - result['before'] = existing_lldp_interfaces_facts - if result['changed']: - result['after'] = changed_lldp_interfaces_facts - - result['warnings'] = warnings - return result - - def set_config(self, existing_lldp_interfaces_facts): - """ Collect the configuration from the args passed to the module, - collect the current configuration (as a dict from facts) - - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - want = self._module.params['config'] - have = existing_lldp_interfaces_facts - resp = self.set_state(want, have) - return to_list(resp) - - def set_state(self, want, have): - """ Select the appropriate function based on the state provided - - :param want: the desired configuration as a dictionary - :param have: the current configuration as a dictionary - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - commands = [] - state = self._module.params['state'] - if state in ('merged', 'replaced', 'overridden') and not want: - self._module.fail_json(msg='value of config parameter must not be empty for state {0}'.format(state)) - if state == 'overridden': - commands.extend(self._state_overridden(want=want, have=have)) - elif state == 'deleted': - if want: - for item in want: - name = item['name'] - have_item = search_obj_in_list(name, have) - commands.extend(self._state_deleted(want=None, have=have_item)) - else: - for have_item in have: - commands.extend(self._state_deleted(want=None, have=have_item)) - else: - for want_item in want: - name = want_item['name'] - have_item = search_obj_in_list(name, have) - if state == 'merged': - commands.extend(self._state_merged(want=want_item, have=have_item)) - else: - commands.extend(self._state_replaced(want=want_item, have=have_item)) - return commands - - def _state_replaced(self, want, have): - """ The command generator when state is replaced - - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - commands = [] - if have: - commands.extend(self._state_deleted(want, have)) - commands.extend(self._state_merged(want, have)) - return commands - - def _state_overridden(self, want, have): - """ The command generator when state is overridden - - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - commands = [] - for have_item in have: - lldp_name = have_item['name'] - lldp_in_want = search_obj_in_list(lldp_name, want) - if not lldp_in_want: - commands.append( - self._compute_command(have_item['name'], remove=True) - ) - - for want_item in want: - name = want_item['name'] - lldp_in_have = search_obj_in_list(name, have) - commands.extend(self._state_replaced(want_item, lldp_in_have)) - return commands - - def _state_merged(self, want, have): - """ The command generator when state is merged - - :rtype: A list - :returns: the commands necessary to merge the provided into - the current configuration - """ - commands = [] - if have: - commands.extend(self._render_updates(want, have)) - else: - commands.extend(self._render_set_commands(want)) - return commands - - def _state_deleted(self, want, have): - """ The command generator when state is deleted - - :rtype: A list - :returns: the commands necessary to remove the current configuration - of the provided objects - """ - commands = [] - if want: - params = Lldp_interfaces.params - for attrib in params: - if attrib == 'location': - commands.extend(self._update_location(have['name'], want, have)) - - elif have: - commands.append( - self._compute_command(have['name'], remove=True) - ) - return commands - - def _render_updates(self, want, have): - commands = [] - lldp_name = have['name'] - commands.extend(self._configure_status(lldp_name, want, have)) - commands.extend(self._add_location(lldp_name, want, have)) - - return commands - - def _render_set_commands(self, want): - commands = [] - have = {} - lldp_name = want['name'] - params = Lldp_interfaces.params - - commands.extend(self._add_location(lldp_name, want, have)) - for attrib in params: - value = want[attrib] - if value: - if attrib == 'location': - commands.extend(self._add_location(lldp_name, want, have)) - elif attrib == 'enable': - if not value: - commands.append( - self._compute_command(lldp_name, value='disable') - ) - else: - commands.append( - self._compute_command(lldp_name) - ) - - return commands - - def _configure_status(self, name, want_item, have_item): - commands = [] - if is_dict_element_present(have_item, 'enable'): - temp_have_item = False - else: - temp_have_item = True - if want_item['enable'] != temp_have_item: - if want_item['enable']: - commands.append( - self._compute_command(name, value='disable', remove=True) - ) - else: - commands.append( - self._compute_command(name, value='disable') - ) - return commands - - def _add_location(self, name, want_item, have_item): - commands = [] - have_dict = {} - have_ca = {} - set_cmd = name + ' location ' - want_location_type = want_item.get('location') or {} - have_location_type = have_item.get('location') or {} - - if want_location_type['coordinate_based']: - want_dict = want_location_type.get('coordinate_based') or {} - if is_dict_element_present(have_location_type, 'coordinate_based'): - have_dict = have_location_type.get('coordinate_based') or {} - location_type = 'coordinate-based' - updates = dict_diff(have_dict, want_dict) - for key, value in iteritems(updates): - if value: - commands.append( - self._compute_command(set_cmd + location_type, key, str(value)) - ) - - elif want_location_type['civic_based']: - location_type = 'civic-based' - want_dict = want_location_type.get('civic_based') or {} - want_ca = want_dict.get('ca_info') or [] - if is_dict_element_present(have_location_type, 'civic_based'): - have_dict = have_location_type.get('civic_based') or {} - have_ca = have_dict.get('ca_info') or [] - if want_dict['country_code'] != have_dict['country_code']: - commands.append( - self._compute_command( - set_cmd + location_type, 'country-code', str(want_dict['country_code']) - ) - ) - else: - commands.append( - self._compute_command( - set_cmd + location_type, 'country-code', str(want_dict['country_code']) - ) - ) - commands.extend(self._add_civic_address(name, want_ca, have_ca)) - - elif want_location_type['elin']: - location_type = 'elin' - if is_dict_element_present(have_location_type, 'elin'): - if want_location_type.get('elin') != have_location_type.get('elin'): - commands.append( - self._compute_command( - set_cmd + location_type, value=str(want_location_type['elin']) - ) - ) - else: - commands.append( - self._compute_command( - set_cmd + location_type, value=str(want_location_type['elin']) - ) - ) - return commands - - def _update_location(self, name, want_item, have_item): - commands = [] - del_cmd = name + ' location' - want_location_type = want_item.get('location') or {} - have_location_type = have_item.get('location') or {} - - if want_location_type['coordinate_based']: - want_dict = want_location_type.get('coordinate_based') or {} - if is_dict_element_present(have_location_type, 'coordinate_based'): - have_dict = have_location_type.get('coordinate_based') or {} - location_type = 'coordinate-based' - for key, value in iteritems(have_dict): - only_in_have = key_value_in_dict(key, value, want_dict) - if not only_in_have: - commands.append( - self._compute_command(del_cmd + location_type, key, str(value), True) - ) - else: - commands.append( - self._compute_command(del_cmd, remove=True) - ) - - elif want_location_type['civic_based']: - want_dict = want_location_type.get('civic_based') or {} - want_ca = want_dict.get('ca_info') or [] - if is_dict_element_present(have_location_type, 'civic_based'): - have_dict = have_location_type.get('civic_based') or {} - have_ca = have_dict.get('ca_info') - commands.extend(self._update_civic_address(name, want_ca, have_ca)) - else: - commands.append( - self._compute_command(del_cmd, remove=True) - ) - - else: - if is_dict_element_present(have_location_type, 'elin'): - if want_location_type.get('elin') != have_location_type.get('elin'): - commands.append( - self._compute_command(del_cmd, remove=True) - ) - else: - commands.append( - self._compute_command(del_cmd, remove=True) - ) - return commands - - def _add_civic_address(self, name, want, have): - commands = [] - for item in want: - ca_type = item['ca_type'] - ca_value = item['ca_value'] - obj_in_have = search_dict_tv_in_list(ca_type, ca_value, have, 'ca_type', 'ca_value') - if not obj_in_have: - commands.append( - self._compute_command( - key=name + ' location civic-based ca-type', - attrib=str(ca_type) + ' ca-value', value=ca_value) - ) - return commands - - def _update_civic_address(self, name, want, have): - commands = [] - for item in have: - ca_type = item['ca_type'] - ca_value = item['ca_value'] - in_want = search_dict_tv_in_list(ca_type, ca_value, want, 'ca_type', 'ca_value') - if not in_want: - commands.append( - self._compute_command( - name, 'location civic-based ca-type', str(ca_type), remove=True - ) - ) - return commands - - def _compute_command(self, key, attrib=None, value=None, remove=False): - if remove: - cmd = 'delete service lldp interface ' - else: - cmd = 'set service lldp interface ' - cmd += (key) - if attrib: - cmd += (' ' + attrib) - if value: - cmd += (" '" + value + "'") - return cmd diff --git a/lib/ansible/module_utils/network/vyos/config/static_routes/static_routes.py b/lib/ansible/module_utils/network/vyos/config/static_routes/static_routes.py deleted file mode 100644 index d60b457ce7..0000000000 --- a/lib/ansible/module_utils/network/vyos/config/static_routes/static_routes.py +++ /dev/null @@ -1,523 +0,0 @@ -# -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -""" -The vyos_static_routes class -It is in this file where the current configuration (as dict) -is compared to the provided configuration (as dict) and the command set -necessary to bring the current configuration to it's desired end-state is -created -""" - -from __future__ import absolute_import, division, print_function -__metaclass__ = type -from copy import deepcopy -from ansible.module_utils.network.common.cfg.base import ConfigBase -from ansible.module_utils.network.common.utils import to_list, dict_diff, remove_empties -from ansible.module_utils.network.vyos.facts.facts import Facts -from ansible.module_utils.six import iteritems -from ansible.module_utils.network. vyos.utils.utils import get_route_type, \ - get_lst_diff_for_dicts, get_lst_same_for_dicts, dict_delete - - -class Static_routes(ConfigBase): - """ - The vyos_static_routes class - """ - - gather_subset = [ - '!all', - '!min', - ] - - gather_network_resources = [ - 'static_routes', - ] - - def __init__(self, module): - super(Static_routes, self).__init__(module) - - def get_static_routes_facts(self, data=None): - """ Get the 'facts' (the current configuration) - - :rtype: A dictionary - :returns: The current configuration as a dictionary - """ - facts, _warnings = Facts(self._module).get_facts(self.gather_subset, self.gather_network_resources, data=data) - static_routes_facts = facts['ansible_network_resources'].get('static_routes') - if not static_routes_facts: - return [] - return static_routes_facts - - def execute_module(self): - """ Execute the module - - :rtype: A dictionary - :returns: The result from module execution - """ - result = {'changed': False} - warnings = list() - commands = list() - - if self.state in self.ACTION_STATES: - existing_static_routes_facts = self.get_static_routes_facts() - else: - existing_static_routes_facts = [] - - if self.state in self.ACTION_STATES or self.state == 'rendered': - commands.extend(self.set_config(existing_static_routes_facts)) - - if commands and self.state in self.ACTION_STATES: - if not self._module.check_mode: - self._connection.edit_config(commands) - result['changed'] = True - - if self.state in self.ACTION_STATES: - result['commands'] = commands - - if self.state in self.ACTION_STATES or self.state == 'gathered': - changed_static_routes_facts = self.get_static_routes_facts() - elif self.state == 'rendered': - result['rendered'] = commands - elif self.state == 'parsed': - running_config = self._module.params['running_config'] - if not running_config: - self._module.fail_json( - msg="value of running_config parameter must not be empty for state parsed" - ) - result['parsed'] = self.get_static_routes_facts(data=running_config) - else: - changed_static_routes_facts = [] - - if self.state in self.ACTION_STATES: - result['before'] = existing_static_routes_facts - if result['changed']: - result['after'] = changed_static_routes_facts - elif self.state == 'gathered': - result['gathered'] = changed_static_routes_facts - - result['warnings'] = warnings - return result - - def set_config(self, existing_static_routes_facts): - """ Collect the configuration from the args passed to the module, - collect the current configuration (as a dict from facts) - - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - want = self._module.params['config'] - have = existing_static_routes_facts - resp = self.set_state(want, have) - return to_list(resp) - - def set_state(self, want, have): - """ Select the appropriate function based on the state provided - - :param want: the desired configuration as a dictionary - :param have: the current configuration as a dictionary - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - commands = [] - if self.state in ('merged', 'replaced', 'overridden', 'rendered') and not want: - self._module.fail_json(msg='value of config parameter must not be empty for state {0}'.format(self.state)) - if self.state == 'overridden': - commands.extend(self._state_overridden(want=want, have=have)) - elif self.state == 'deleted': - commands.extend(self._state_deleted(want=want, have=have)) - elif want: - routes = self._get_routes(want) - for r in routes: - h_item = self.search_route_in_have(have, r['dest']) - if self.state == 'merged' or self.state == 'rendered': - commands.extend(self._state_merged(want=r, have=h_item)) - elif self.state == 'replaced': - commands.extend(self._state_replaced(want=r, have=h_item)) - return commands - - def search_route_in_have(self, have, want_dest): - """ - This function returns the route if its found in - have config. - :param have: - :param dest: - :return: the matched route - """ - routes = self._get_routes(have) - for r in routes: - if r['dest'] == want_dest: - return r - return None - - def _state_replaced(self, want, have): - """ The command generator when state is replaced - - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - commands = [] - if have: - for key, value in iteritems(want): - if value: - if key == 'next_hops': - commands.extend(self._update_next_hop(want, have)) - elif key == 'blackhole_config': - commands.extend(self._update_blackhole(key, want, have)) - commands.extend(self._state_merged(want, have)) - return commands - - def _state_overridden(self, want, have): - """ The command generator when state is overridden - - :rtype: A list - :returns: the commands necessary to migrate the current configuration - to the desired configuration - """ - commands = [] - routes = self._get_routes(have) - for r in routes: - route_in_want = self.search_route_in_have(want, r['dest']) - if not route_in_want: - commands.append(self._compute_command(r['dest'], remove=True)) - routes = self._get_routes(want) - for r in routes: - route_in_have = self.search_route_in_have(have, r['dest']) - commands.extend(self._state_replaced(r, route_in_have)) - return commands - - def _state_merged(self, want, have, opr=True): - """ The command generator when state is merged - - :rtype: A list - :returns: the commands necessary to merge the provided into - the current configuration - """ - commands = [] - if have: - commands.extend(self._render_updates(want, have)) - else: - commands.extend(self._render_set_commands(want)) - return commands - - def _state_deleted(self, want, have): - """ The command generator when state is deleted - - :rtype: A list - :returns: the commands necessary to remove the current configuration - of the provided objects - """ - commands = [] - if want: - routes = self._get_routes(want) - if not routes: - for w in want: - af = w['address_families'] - for item in af: - if self.afi_in_have(have, item): - commands.append(self._compute_command(afi=item['afi'], remove=True)) - for r in routes: - h_route = self.search_route_in_have(have, r['dest']) - if h_route: - commands.extend(self._render_updates(r, h_route, opr=False)) - else: - routes = self._get_routes(have) - if self._is_ip_route_exist(routes): - commands.append(self._compute_command(afi='ipv4', remove=True)) - if self._is_ip_route_exist(routes, 'route6'): - commands.append(self._compute_command(afi='ipv6', remove=True)) - return commands - - def _render_set_commands(self, want): - """ - This function returns the list of commands to add attributes which are - present in want - :param want: - :return: list of commands. - """ - commands = [] - have = {} - for key, value in iteritems(want): - if value: - if key == 'dest': - commands.append( - self._compute_command(dest=want['dest']) - ) - elif key == 'blackhole_config': - commands.extend(self._add_blackhole(key, want, have)) - - elif key == 'next_hops': - commands.extend(self._add_next_hop(want, have)) - - return commands - - def _add_blackhole(self, key, want, have): - """ - This function gets the diff for blackhole config specific attributes - and form the commands for attributes which are present in want but not in have. - :param key: - :param want: - :param have: - :return: list of commands - """ - commands = [] - want_copy = deepcopy(remove_empties(want)) - have_copy = deepcopy(remove_empties(have)) - - want_blackhole = want_copy.get(key) or {} - have_blackhole = have_copy.get(key) or {} - - updates = dict_delete(want_blackhole, have_blackhole) - if updates: - for attrib, value in iteritems(updates): - if value: - if attrib == 'distance': - commands.append( - self._compute_command(dest=want['dest'], key='blackhole', - attrib=attrib, remove=False, value=str(value)) - ) - elif attrib == 'type': - commands.append( - self._compute_command(dest=want['dest'], key='blackhole') - ) - return commands - - def _add_next_hop(self, want, have, opr=True): - """ - This function gets the diff for next hop specific attributes - and form the commands to add attributes which are present in want but not in have. - :param want: - :param have: - :return: list of commands. - """ - commands = [] - want_copy = deepcopy(remove_empties(want)) - have_copy = deepcopy(remove_empties(have)) - if not opr: - diff_next_hops = get_lst_same_for_dicts(want_copy, have_copy, 'next_hops') - else: - diff_next_hops = get_lst_diff_for_dicts(want_copy, have_copy, 'next_hops') - if diff_next_hops: - for hop in diff_next_hops: - for element in hop: - if element == 'forward_router_address': - commands.append( - self._compute_command(dest=want['dest'], - key='next-hop', - value=hop[element], - opr=opr) - ) - elif element == 'enabled' and not hop[element]: - commands.append( - self._compute_command(dest=want['dest'], - key='next-hop', - attrib=hop['forward_router_address'], - value='disable', - opr=opr) - ) - elif element == 'admin_distance': - commands.append( - self._compute_command(dest=want['dest'], - key='next-hop', - attrib=hop['forward_router_address'] + " " + element, - value=str(hop[element]), - opr=opr) - ) - elif element == 'interface': - commands.append( - self._compute_command(dest=want['dest'], - key='next-hop', - attrib=hop['forward_router_address'] + " " + element, - value=hop[element], - opr=opr) - ) - return commands - - def _update_blackhole(self, key, want, have): - """ - This function gets the difference for blackhole dict and - form the commands to delete the attributes which are present in have but not in want. - :param want: - :param have: - :return: list of commands - :param key: - :param want: - :param have: - :return: list of commands - """ - commands = [] - want_copy = deepcopy(remove_empties(want)) - have_copy = deepcopy(remove_empties(have)) - - want_blackhole = want_copy.get(key) or {} - have_blackhole = have_copy.get(key) or {} - updates = dict_delete(have_blackhole, want_blackhole) - if updates: - for attrib, value in iteritems(updates): - if value: - if attrib == 'distance': - commands.append( - self._compute_command(dest=want['dest'], key='blackhole', - attrib=attrib, remove=True, value=str(value)) - ) - elif attrib == 'type' and 'distance' not in want_blackhole.keys(): - commands.append( - self._compute_command(dest=want['dest'], key='blackhole', remove=True) - ) - return commands - - def _update_next_hop(self, want, have, opr=True): - """ - This function gets the difference for next_hops list and - form the commands to delete the attributes which are present in have but not in want. - :param want: - :param have: - :return: list of commands - """ - commands = [] - - want_copy = deepcopy(remove_empties(want)) - have_copy = deepcopy(remove_empties(have)) - - diff_next_hops = get_lst_diff_for_dicts(have_copy, want_copy, 'next_hops') - if diff_next_hops: - for hop in diff_next_hops: - for element in hop: - if element == 'forward_router_address': - commands.append( - self._compute_command(dest=want['dest'], key='next-hop', value=hop[element], remove=True) - ) - elif element == 'enabled': - commands.append( - self._compute_command(dest=want['dest'], - key='next-hop', attrib=hop['forward_router_address'], value='disable', remove=True) - ) - elif element == 'admin_distance': - commands.append( - self._compute_command(dest=want['dest'], key='next-hop', - attrib=hop['forward_router_address'] + " " + element, value=str(hop[element]), remove=True) - ) - elif element == 'interface': - commands.append( - self._compute_command(dest=want['dest'], key='next-hop', - attrib=hop['forward_router_address'] + " " + element, value=hop[element], remove=True) - ) - return commands - - def _render_updates(self, want, have, opr=True): - """ - This function takes the diff between want and have and - invokes the appropriate functions to create the commands - to update the attributes. - :param want: - :param have: - :return: list of commands - """ - commands = [] - want_nh = want.get('next_hops') or [] - # delete static route operation per destination - if not opr and not want_nh: - commands.append(self._compute_command(dest=want['dest'], remove=True)) - - else: - temp_have_next_hops = have.pop('next_hops', None) - temp_want_next_hops = want.pop('next_hops', None) - updates = dict_diff(have, want) - if temp_have_next_hops: - have['next_hops'] = temp_have_next_hops - if temp_want_next_hops: - want['next_hops'] = temp_want_next_hops - commands.extend(self._add_next_hop(want, have, opr=opr)) - - if opr and updates: - for key, value in iteritems(updates): - if value: - if key == 'blackhole_config': - commands.extend(self._add_blackhole(key, want, have)) - return commands - - def _compute_command(self, dest=None, key=None, attrib=None, value=None, remove=False, afi=None, opr=True): - """ - This functions construct the required command based on the passed arguments. - :param dest: - :param key: - :param attrib: - :param value: - :param remove: - :return: constructed command - """ - if remove or not opr: - cmd = 'delete protocols static ' + self.get_route_type(dest, afi) - else: - cmd = 'set protocols static ' + self.get_route_type(dest, afi) - if dest: - cmd += (' ' + dest) - if key: - cmd += (' ' + key) - if attrib: - cmd += (' ' + attrib) - if value: - cmd += (" '" + value + "'") - return cmd - - def afi_in_have(self, have, w_item): - """ - This functions checks for the afi - list in have - :param have: - :param w_item: - :return: - """ - if have: - for h in have: - af = h.get('address_families') or [] - for item in af: - if w_item['afi'] == item['afi']: - return True - return False - - def get_route_type(self, dest=None, afi=None): - """ - This function returns the route type based on - destination ip address or afi - :param address: - :return: - """ - if dest: - return get_route_type(dest) - elif afi == 'ipv4': - return 'route' - elif afi == 'ipv6': - return 'route6' - - def _is_ip_route_exist(self, routes, type='route'): - """ - This functions checks for the type of route. - :param routes: - :param type: - :return: True/False - """ - for r in routes: - if type == self.get_route_type(r['dest']): - return True - return False - - def _get_routes(self, lst): - """ - This function returns the list of routes - :param lst: list of address families - :return: list of routes - """ - r_list = [] - for item in lst: - af = item['address_families'] - for element in af: - routes = element.get('routes') or [] - for r in routes: - r_list.append(r) - return r_list diff --git a/lib/ansible/module_utils/network/vyos/facts/facts.py b/lib/ansible/module_utils/network/vyos/facts/facts.py deleted file mode 100644 index acd249bba2..0000000000 --- a/lib/ansible/module_utils/network/vyos/facts/facts.py +++ /dev/null @@ -1,65 +0,0 @@ -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -""" -The facts class for vyos -this file validates each subset of facts and selectively -calls the appropriate facts gathering function -""" -from __future__ import absolute_import, division, print_function -__metaclass__ = type - -from ansible.module_utils.network.common.facts.facts import FactsBase -from ansible.module_utils.network.vyos.facts.interfaces.interfaces import InterfacesFacts -from ansible.module_utils.network.vyos.facts.l3_interfaces.l3_interfaces import L3_interfacesFacts -from ansible.module_utils.network.vyos.facts.lag_interfaces.lag_interfaces import Lag_interfacesFacts -from ansible.module_utils.network.vyos.facts.lldp_global.lldp_global import Lldp_globalFacts -from ansible.module_utils.network.vyos.facts.lldp_interfaces.lldp_interfaces import Lldp_interfacesFacts -from ansible.module_utils.network.vyos.facts.firewall_rules.firewall_rules import Firewall_rulesFacts -from ansible.module_utils.network.vyos.facts.static_routes.static_routes import Static_routesFacts -from ansible.module_utils.network.vyos.facts.firewall_global.firewall_global import Firewall_globalFacts -from ansible.module_utils.network.vyos.facts.firewall_interfaces.firewall_interfaces import Firewall_interfacesFacts -from ansible.module_utils.network.vyos.facts.legacy.base import Default, Neighbors, Config - - -FACT_LEGACY_SUBSETS = dict( - default=Default, - neighbors=Neighbors, - config=Config -) -FACT_RESOURCE_SUBSETS = dict( - interfaces=InterfacesFacts, - l3_interfaces=L3_interfacesFacts, - lag_interfaces=Lag_interfacesFacts, - lldp_global=Lldp_globalFacts, - lldp_interfaces=Lldp_interfacesFacts, - static_routes=Static_routesFacts, - firewall_rules=Firewall_rulesFacts, - firewall_global=Firewall_globalFacts, - firewall_interfaces=Firewall_interfacesFacts -) - - -class Facts(FactsBase): - """ The fact class for vyos - """ - - VALID_LEGACY_GATHER_SUBSETS = frozenset(FACT_LEGACY_SUBSETS.keys()) - VALID_RESOURCE_SUBSETS = frozenset(FACT_RESOURCE_SUBSETS.keys()) - - def __init__(self, module): - super(Facts, self).__init__(module) - - def get_facts(self, legacy_facts_type=None, resource_facts_type=None, data=None): - """ Collect the facts for vyos - :param legacy_facts_type: List of legacy facts types - :param resource_facts_type: List of resource fact types - :param data: previously collected conf - :rtype: dict - :return: the facts gathered - """ - if self.VALID_RESOURCE_SUBSETS: - self.get_network_resources_facts(FACT_RESOURCE_SUBSETS, resource_facts_type, data) - if self.VALID_LEGACY_GATHER_SUBSETS: - self.get_network_legacy_facts(FACT_LEGACY_SUBSETS, legacy_facts_type) - return self.ansible_facts, self._warnings diff --git a/lib/ansible/module_utils/network/vyos/facts/firewall_global/firewall_global.py b/lib/ansible/module_utils/network/vyos/facts/firewall_global/firewall_global.py deleted file mode 100644 index de517501ee..0000000000 --- a/lib/ansible/module_utils/network/vyos/facts/firewall_global/firewall_global.py +++ /dev/null @@ -1,360 +0,0 @@ -# -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -""" -The vyos firewall_global fact class -It is in this file the configuration is collected from the device -for a given resource, parsed, and the facts tree is populated -based on the configuration. -""" -from __future__ import absolute_import, division, print_function -__metaclass__ = type - -from copy import deepcopy -from re import findall, search, M -from ansible.module_utils.network.common import utils -from ansible.module_utils.network.vyos.argspec.firewall_global.firewall_global import Firewall_globalArgs - - -class Firewall_globalFacts(object): - """ The vyos firewall_global fact class - """ - - def __init__(self, module, subspec='config', options='options'): - self._module = module - self.argument_spec = Firewall_globalArgs.argument_spec - spec = deepcopy(self.argument_spec) - if subspec: - if options: - facts_argument_spec = spec[subspec][options] - else: - facts_argument_spec = spec[subspec] - else: - facts_argument_spec = spec - - self.generated_spec = utils.generate_dict(facts_argument_spec) - - def get_device_data(self, connection): - return connection.get_config() - - def populate_facts(self, connection, ansible_facts, data=None): - """ Populate the facts for firewall_global - :param connection: the device connection - :param ansible_facts: Facts dictionary - :param data: previously collected conf - :rtype: dictionary - :returns: facts - """ - if not data: - # typically data is populated from the current device configuration - # data = connection.get('show running-config | section ^interface') - # using mock data instead - data = self.get_device_data(connection) - objs = {} - firewalls = findall(r'^set firewall .*$', data, M) - if firewalls: - objs = self.render_config(firewalls) - facts = {} - params = utils.validate_config(self.argument_spec, {'config': objs}) - facts['firewall_global'] = utils.remove_empties(params['config']) - ansible_facts['ansible_network_resources'].update(facts) - return ansible_facts - - def render_config(self, conf): - """ - Render config as dictionary structure and delete keys - from spec for null values - - :param spec: The facts tree, generated from the argspec - :param conf: The configuration - :rtype: dictionary - :returns: The generated config - """ - conf = '\n'.join(filter(lambda x: ('firewall ipv6-name' and 'firewall name' not in x), conf)) - - a_lst = ['config_trap', 'validation', 'log_martians', 'syn_cookies', 'twa_hazards_protection'] - firewall = self.parse_attr(conf, a_lst) - f_sub = {'ping': self.parse_ping(conf), - 'group': self.parse_group(conf), - 'route_redirects': self.route_redirects(conf), - 'state_policy': self.parse_state_policy(conf)} - firewall.update(f_sub) - return firewall - - def route_redirects(self, conf): - """ - This function forms the regex to fetch the afi and invoke - functions to fetch route redirects and source routes - :param conf: configuration data. - :return: generated rule list configuration. - """ - rr_lst = [] - - v6_attr = findall(r'^set firewall (?:ipv6-src-route|ipv6-receive-redirects) (\S+)', conf, M) - if v6_attr: - obj = self.parse_rr_attrib(conf, 'ipv6') - if obj: - rr_lst.append(obj) - - v4_attr = findall(r'^set firewall (?:ip-src-route|receive-redirects|send-redirects) (\S+)', conf, M) - if v4_attr: - obj = self.parse_rr_attrib(conf, 'ipv4') - if obj: - rr_lst.append(obj) - return rr_lst - - def parse_rr_attrib(self, conf, attrib=None): - """ - This function fetches the 'ip_src_route' - invoke function to parse icmp redirects. - :param conf: configuration to be parsed. - :param attrib: 'ipv4/ipv6'. - :return: generated config dictionary. - """ - - cfg_dict = self.parse_attr(conf, ['ip_src_route'], type=attrib) - cfg_dict['icmp_redirects'] = self.parse_icmp_redirects(conf, attrib) - cfg_dict['afi'] = attrib - return cfg_dict - - def parse_icmp_redirects(self, conf, attrib=None): - """ - This function triggers the parsing of 'icmp_redirects' attributes. - :param conf: configuration to be parsed. - :param attrib: 'ipv4/ipv6'. - :return: generated config dictionary. - """ - a_lst = ['send', 'receive'] - cfg_dict = self.parse_attr(conf, a_lst, type=attrib) - return cfg_dict - - def parse_ping(self, conf): - """ - This function triggers the parsing of 'ping' attributes. - :param conf: configuration to be parsed. - :return: generated config dictionary. - """ - a_lst = ['all', 'broadcast'] - cfg_dict = self.parse_attr(conf, a_lst) - return cfg_dict - - def parse_state_policy(self, conf): - """ - This function fetched the connecton type and invoke - function to parse other state-policy attributes. - :param conf: configuration data. - :return: generated rule list configuration. - """ - sp_lst = [] - attrib = 'state-policy' - policies = findall(r'^set firewall ' + attrib + ' (\\S+)', conf, M) - - if policies: - rules_lst = [] - for sp in set(policies): - sp_regex = r' %s .+$' % sp - cfg = '\n'.join(findall(sp_regex, conf, M)) - obj = self.parse_policies(cfg, sp) - obj['connection_type'] = sp - if obj: - rules_lst.append(obj) - sp_lst = sorted(rules_lst, key=lambda i: i['connection_type']) - return sp_lst - - def parse_policies(self, conf, attrib=None): - """ - This function triggers the parsing of policy attributes - action and log. - :param conf: configuration - :param attrib: connection type. - :return: generated rule configuration dictionary. - """ - a_lst = ['action', 'log'] - cfg_dict = self.parse_attr(conf, a_lst, match=attrib) - return cfg_dict - - def parse_group(self, conf): - """ - This function triggers the parsing of 'group' attributes. - :param conf: configuration. - :return: generated config dictionary. - """ - cfg_dict = {} - cfg_dict['port_group'] = self.parse_group_lst(conf, 'port-group') - cfg_dict['address_group'] = self.parse_group_lst(conf, 'address-group') - cfg_dict['network_group'] = self.parse_group_lst(conf, 'network-group') - return cfg_dict - - def parse_group_lst(self, conf, type): - """ - This function fetches the name of group and invoke function to - parse group attributes'. - :param conf: configuration data. - :param type: type of group. - :return: generated group list configuration. - """ - g_lst = [] - - groups = findall(r'^set firewall group ' + type + ' (\\S+)', conf, M) - if groups: - rules_lst = [] - for gr in set(groups): - gr_regex = r' %s .+$' % gr - cfg = '\n'.join(findall(gr_regex, conf, M)) - obj = self.parse_groups(cfg, type, gr) - obj['name'] = gr.strip("'") - if obj: - rules_lst.append(obj) - g_lst = sorted(rules_lst, key=lambda i: i['name']) - return g_lst - - def parse_groups(self, conf, type, name): - """ - This function fetches the description and invoke - the parsing of group members. - :param conf: configuration. - :param type: type of group. - :param name: name of group. - :return: generated configuration dictionary. - """ - a_lst = ['name', 'description'] - group = self.parse_attr(conf, a_lst) - key = self.get_key(type) - r_sub = {key[0]: self.parse_address_port_lst(conf, name, key[1])} - group.update(r_sub) - return group - - def parse_address_port_lst(self, conf, name, key): - """ - This function forms the regex to fetch the - group members attributes. - :param conf: configuration data. - :param name: name of group. - :param key: key value. - :return: generated member list configuration. - """ - l_lst = [] - attribs = findall(r'^.*' + name + ' ' + key + ' (\\S+)', conf, M) - if attribs: - for attr in attribs: - if key == 'port': - l_lst.append({"port": attr.strip("'")}) - else: - l_lst.append({"address": attr.strip("'")}) - return l_lst - - def parse_attr(self, conf, attr_list, match=None, type=None): - """ - This function peforms the following: - - Form the regex to fetch the required attribute config. - - Type cast the output in desired format. - :param conf: configuration. - :param attr_list: list of attributes. - :param match: parent node/attribute name. - :return: generated config dictionary. - """ - config = {} - for attrib in attr_list: - regex = self.map_regex(attrib, type) - if match: - regex = match + ' ' + regex - if conf: - if self.is_bool(attrib): - attr = self.map_regex(attrib, type) - out = conf.find(attr.replace("_", "-")) - dis = conf.find(attr.replace("_", "-") + " 'disable'") - if out >= 1: - if dis >= 1: - config[attrib] = False - else: - config[attrib] = True - else: - out = search(r'^.*' + regex + ' (.+)', conf, M) - if out: - val = out.group(1).strip("'") - if self.is_num(attrib): - val = int(val) - config[attrib] = val - return config - - def get_key(self, type): - """ - This function map the group type to - member type - :param type: - :return: - """ - key = () - if type == 'port-group': - key = ('members', 'port') - elif type == 'address-group': - key = ('members', 'address') - elif type == 'network-group': - key = ('members', 'network') - return key - - def map_regex(self, attrib, type=None): - """ - - This function construct the regex string. - - replace the underscore with hyphen. - :param attrib: attribute - :return: regex string - """ - regex = attrib.replace("_", "-") - if attrib == 'all': - regex = 'all-ping' - elif attrib == 'disabled': - regex = 'disable' - elif attrib == 'broadcast': - regex = 'broadcast-ping' - elif attrib == 'send': - if type == 'ipv6': - regex = 'ipv6-send-redirects' - else: - regex = 'send-redirects' - elif attrib == 'ip_src_route': - if type == 'ipv6': - regex = 'ipv6-src-route' - elif attrib == 'receive': - if type == 'ipv6': - regex = 'ipv6-receive-redirects' - else: - regex = 'receive-redirects' - return regex - - def is_num(self, attrib): - """ - This function looks for the attribute in predefined integer type set. - :param attrib: attribute. - :return: True/false. - """ - num_set = ('time', 'code', 'type', 'count', 'burst', 'number') - return True if attrib in num_set else False - - def get_src_route(self, attrib): - """ - This function looks for the attribute in predefined integer type set. - :param attrib: attribute. - :return: True/false. - """ - return 'ipv6_src_route' if attrib == 'ipv6' else 'ip_src_route' - - def is_bool(self, attrib): - """ - This function looks for the attribute in predefined bool type set. - :param attrib: attribute. - :return: True/False - """ - bool_set = ('all', - 'log', - 'send', - 'receive', - 'broadcast', - 'config_trap', - 'log_martians', - 'syn_cookies', - 'ip_src_route', - 'twa_hazards_protection') - return True if attrib in bool_set else False diff --git a/lib/ansible/module_utils/network/vyos/facts/firewall_interfaces/firewall_interfaces.py b/lib/ansible/module_utils/network/vyos/facts/firewall_interfaces/firewall_interfaces.py deleted file mode 100644 index 5621fcd89a..0000000000 --- a/lib/ansible/module_utils/network/vyos/facts/firewall_interfaces/firewall_interfaces.py +++ /dev/null @@ -1,183 +0,0 @@ -# -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -""" -The vyos firewall_interfaces fact class -It is in this file the configuration is collected from the device -for a given resource, parsed, and the facts tree is populated -based on the configuration. -""" -from __future__ import absolute_import, division, print_function -__metaclass__ = type - -from re import findall, search, M -from copy import deepcopy -from ansible.module_utils.network.common import utils -from ansible.module_utils.network.vyos.argspec.firewall_interfaces.firewall_interfaces import Firewall_interfacesArgs - - -class Firewall_interfacesFacts(object): - """ The vyos firewall_interfaces fact class - """ - - def __init__(self, module, subspec='config', options='options'): - self._module = module - self.argument_spec = Firewall_interfacesArgs.argument_spec - spec = deepcopy(self.argument_spec) - if subspec: - if options: - facts_argument_spec = spec[subspec][options] - else: - facts_argument_spec = spec[subspec] - else: - facts_argument_spec = spec - - self.generated_spec = utils.generate_dict(facts_argument_spec) - - def get_device_data(self, connection): - return connection.get_config() - - def populate_facts(self, connection, ansible_facts, data=None): - """ Populate the facts for firewall_interfaces - :param connection: the device connection - :param ansible_facts: Facts dictionary - :param data: previously collected conf - :rtype: dictionary - :returns: facts - """ - if not data: - # typically data is populated from the current device configuration - # data = connection.get('show running-config | section ^interface') - # using mock data instead - data = self.get_device_data(connection) - objs = [] - interfaces = findall(r'^set interfaces ethernet (?:\'*)(\S+)(?:\'*)', data, M) - if interfaces: - objs = self.get_names(data, interfaces) - ansible_facts['ansible_network_resources'].pop('firewall_interfaces', None) - facts = {} - if objs: - facts['firewall_interfaces'] = [] - params = utils.validate_config(self.argument_spec, {'config': objs}) - for cfg in params['config']: - facts['firewall_interfaces'].append(utils.remove_empties(cfg)) - - ansible_facts['ansible_network_resources'].update(facts) - return ansible_facts - - def get_names(self, data, interfaces): - """ - This function performs following: - - Form regex to fetch 'interface name' from interfaces firewall data. - - Form the name list. - :param data: configuration. - :param rules: list of interfaces. - :return: generated firewall interfaces configuration. - """ - names = [] - for r in set(interfaces): - int_regex = r' %s .+$' % r.strip("'") - cfg = findall(int_regex, data, M) - fi = self.render_config(cfg) - fi['name'] = r.strip("'") - names.append(fi) - if names: - names = sorted(names, key=lambda i: i['name']) - return names - - def render_config(self, conf): - """ - Render config as dictionary structure and delete keys - from spec for null values - - :param spec: The facts tree, generated from the argspec - :param conf: The configuration - :rtype: dictionary - :returns: The generated config - """ - conf = '\n'.join(filter(lambda x: 'firewall' in x, conf)) - config = {'access_rules': self.parse_access_rules(conf)} - return config - - def parse_access_rules(self, conf): - """ - This function forms the regex to fetch the 'access-rules' - for specific interface. - :param conf: configuration data. - :return: generated access-rules list configuration. - """ - ar_lst = [] - v4_ar = findall(r'^.*(in|out|local) name .*$', conf, M) - v6_ar = findall(r'^.*(in|out|local) ipv6-name .*$', conf, M) - if v4_ar: - v4_conf = "\n".join(findall(r"(^.*?%s.*?$)" % ' name', conf, M)) - config = self.parse_int_rules(v4_conf, 'ipv4') - if config: - ar_lst.append(config) - if v6_ar: - v6_conf = "\n".join(findall(r"(^.*?%s.*?$)" % ' ipv6-name', conf, M)) - config = self.parse_int_rules(v6_conf, 'ipv6') - if config: - ar_lst.append(config) - if ar_lst: - ar_lst = sorted(ar_lst, key=lambda i: i['afi']) - else: - empty_rules = findall(r'^.*(in|out|local).*', conf, M) - if empty_rules: - ar_lst.append({'afi': 'ipv4', 'rules': []}) - ar_lst.append({'afi': 'ipv6', 'rules': []}) - return ar_lst - - def parse_int_rules(self, conf, afi): - """ - This function forms the regex to fetch the 'access-rules' - for specific interface based on ip-type. - :param conf: configuration data. - :param rules: rules configured per interface. - :param afi: ip address type. - :return: generated rule configuration dictionary. - """ - r_lst = [] - config = {} - rules = ['in', 'out', 'local'] - for r in set(rules): - fr = {} - r_regex = r' %s .+$' % r - cfg = '\n'.join(findall(r_regex, conf, M)) - if cfg: - fr = self.parse_rules(cfg, afi) - else: - out = search(r'^.*firewall ' + "'" + r + "'" + '(.*)', conf, M) - if out: - fr = {'direction': r} - if fr: - r_lst.append(fr) - if r_lst: - r_lst = sorted(r_lst, key=lambda i: i['direction']) - config = {'afi': afi, 'rules': r_lst} - return config - - def parse_rules(self, conf, afi): - """ - This function triggers the parsing of 'rule' attributes. - a_lst is a list having rule attributes which doesn't - have further sub attributes. - :param conf: configuration. - :param afi: ip address type. - :return: generated rule configuration dictionary. - """ - cfg = {} - out = findall(r'[^\s]+', conf, M) - if out: - cfg['direction'] = out[0].strip("'") - if afi == 'ipv6': - out = findall(r'[^\s]+ ipv6-name (?:\'*)(\S+)(?:\'*)', conf, M) - if out: - cfg['name'] = str(out[0]).strip("'") - else: - out = findall(r'[^\s]+ name (?:\'*)(\S+)(?:\'*)', conf, M) - if out: - cfg['name'] = out[-1].strip("'") - return cfg diff --git a/lib/ansible/module_utils/network/vyos/facts/firewall_rules/firewall_rules.py b/lib/ansible/module_utils/network/vyos/facts/firewall_rules/firewall_rules.py deleted file mode 100644 index e1af714cf0..0000000000 --- a/lib/ansible/module_utils/network/vyos/facts/firewall_rules/firewall_rules.py +++ /dev/null @@ -1,348 +0,0 @@ -# -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -""" -The vyos firewall_rules fact class -It is in this file the configuration is collected from the device -for a given resource, parsed, and the facts tree is populated -based on the configuration. -""" -from __future__ import absolute_import, division, print_function -__metaclass__ = type - -from re import findall, search, M -from copy import deepcopy -from ansible.module_utils.network.common import utils -from ansible.module_utils.network.vyos.argspec.firewall_rules.firewall_rules import Firewall_rulesArgs - - -class Firewall_rulesFacts(object): - """ The vyos firewall_rules fact class - """ - - def __init__(self, module, subspec='config', options='options'): - self._module = module - self.argument_spec = Firewall_rulesArgs.argument_spec - spec = deepcopy(self.argument_spec) - if subspec: - if options: - facts_argument_spec = spec[subspec][options] - else: - facts_argument_spec = spec[subspec] - else: - facts_argument_spec = spec - - self.generated_spec = utils.generate_dict(facts_argument_spec) - - def get_device_data(self, connection): - return connection.get_config() - - def populate_facts(self, connection, ansible_facts, data=None): - """ Populate the facts for firewall_rules - :param connection: the device connection - :param ansible_facts: Facts dictionary - :param data: previously collected conf - :rtype: dictionary - :returns: facts - """ - if not data: - # typically data is populated from the current device configuration - # data = connection.get('show running-config | section ^interface') - # using mock data instead - data = self.get_device_data(connection) - # split the config into instances of the resource - objs = [] - v6_rules = findall(r'^set firewall ipv6-name (?:\'*)(\S+)(?:\'*)', data, M) - v4_rules = findall(r'^set firewall name (?:\'*)(\S+)(?:\'*)', data, M) - if v6_rules: - config = self.get_rules(data, v6_rules, type='ipv6') - if config: - config = utils.remove_empties(config) - objs.append(config) - if v4_rules: - config = self.get_rules(data, v4_rules, type='ipv4') - if config: - config = utils.remove_empties(config) - objs.append(config) - - ansible_facts['ansible_network_resources'].pop('firewall_rules', None) - facts = {} - if objs: - facts['firewall_rules'] = [] - params = utils.validate_config(self.argument_spec, {'config': objs}) - for cfg in params['config']: - facts['firewall_rules'].append(utils.remove_empties(cfg)) - - ansible_facts['ansible_network_resources'].update(facts) - return ansible_facts - - def get_rules(self, data, rules, type): - """ - This function performs following: - - Form regex to fetch 'rule-sets' specific config from data. - - Form the rule-set list based on ip address. - :param data: configuration. - :param rules: list of rule-sets. - :param type: ip address type. - :return: generated rule-sets configuration. - """ - r_v4 = [] - r_v6 = [] - for r in set(rules): - rule_regex = r' %s .+$' % r.strip("'") - cfg = findall(rule_regex, data, M) - fr = self.render_config(cfg, r.strip("'")) - fr['name'] = r.strip("'") - if type == 'ipv6': - r_v6.append(fr) - else: - r_v4.append(fr) - if r_v4: - config = {'afi': 'ipv4', 'rule_sets': r_v4} - if r_v6: - config = {'afi': 'ipv6', 'rule_sets': r_v6} - return config - - def render_config(self, conf, match): - """ - Render config as dictionary structure and delete keys - from spec for null values - - :param spec: The facts tree, generated from the argspec - :param conf: The configuration - :rtype: dictionary - :returns: The generated config - """ - conf = '\n'.join(filter(lambda x: x, conf)) - a_lst = ['description', 'default_action', 'enable_default_log'] - config = self.parse_attr(conf, a_lst, match) - if not config: - config = {} - config['rules'] = self.parse_rules_lst(conf) - return config - - def parse_rules_lst(self, conf): - """ - This function forms the regex to fetch the 'rules' with in - 'rule-sets' - :param conf: configuration data. - :return: generated rule list configuration. - """ - r_lst = [] - rules = findall(r'rule (?:\'*)(\d+)(?:\'*)', conf, M) - if rules: - rules_lst = [] - for r in set(rules): - r_regex = r' %s .+$' % r - cfg = '\n'.join(findall(r_regex, conf, M)) - obj = self.parse_rules(cfg) - obj['number'] = int(r) - if obj: - rules_lst.append(obj) - r_lst = sorted(rules_lst, key=lambda i: i['number']) - return r_lst - - def parse_rules(self, conf): - """ - This function triggers the parsing of 'rule' attributes. - a_lst is a list having rule attributes which doesn't - have further sub attributes. - :param conf: configuration - :return: generated rule configuration dictionary. - """ - a_lst = ['ipsec', 'action', 'protocol', 'fragment', 'disabled', 'description'] - rule = self.parse_attr(conf, a_lst) - r_sub = {'p2p': self.parse_p2p(conf), - 'tcp': self.parse_tcp(conf, 'tcp'), - 'icmp': self.parse_icmp(conf, 'icmp'), - 'time': self.parse_time(conf, 'time'), - 'limit': self.parse_limit(conf, 'limit'), - 'state': self.parse_state(conf, 'state'), - 'recent': self.parse_recent(conf, 'recent'), - 'source': self.parse_src_or_dest(conf, 'source'), - 'destination': self.parse_src_or_dest(conf, 'destination')} - rule.update(r_sub) - return rule - - def parse_p2p(self, conf): - """ - This function forms the regex to fetch the 'p2p' with in - 'rules' - :param conf: configuration data. - :return: generated rule list configuration. - """ - a_lst = [] - applications = findall(r'p2p (?:\'*)(\d+)(?:\'*)', conf, M) - if applications: - app_lst = [] - for r in set(applications): - obj = {'application': r.strip("'")} - app_lst.append(obj) - a_lst = sorted(app_lst, key=lambda i: i['application']) - return a_lst - - def parse_src_or_dest(self, conf, attrib=None): - """ - This function triggers the parsing of 'source or - destination' attributes. - :param conf: configuration. - :param attrib:'source/destination'. - :return:generated source/destination configuration dictionary. - """ - a_lst = ['port', 'address', 'mac_address'] - cfg_dict = self.parse_attr(conf, a_lst, match=attrib) - cfg_dict['group'] = self.parse_group(conf, attrib + ' group') - return cfg_dict - - def parse_recent(self, conf, attrib=None): - """ - This function triggers the parsing of 'recent' attributes - :param conf: configuration. - :param attrib: 'recent'. - :return: generated config dictionary. - """ - a_lst = ['time', 'count'] - cfg_dict = self.parse_attr(conf, a_lst, match=attrib) - return cfg_dict - - def parse_tcp(self, conf, attrib=None): - """ - This function triggers the parsing of 'tcp' attributes. - :param conf: configuration. - :param attrib: 'tcp'. - :return: generated config dictionary. - """ - cfg_dict = self.parse_attr(conf, ['flags'], match=attrib) - return cfg_dict - - def parse_time(self, conf, attrib=None): - """ - This function triggers the parsing of 'time' attributes. - :param conf: configuration. - :param attrib: 'time'. - :return: generated config dictionary. - """ - a_lst = ['stopdate', 'stoptime', 'weekdays', 'monthdays', 'startdate', 'starttime'] - cfg_dict = self.parse_attr(conf, a_lst, match=attrib) - return cfg_dict - - def parse_state(self, conf, attrib=None): - """ - This function triggers the parsing of 'state' attributes. - :param conf: configuration - :param attrib: 'state'. - :return: generated config dictionary. - """ - a_lst = ['new', 'invalid', 'related', 'established'] - cfg_dict = self.parse_attr(conf, a_lst, match=attrib) - return cfg_dict - - def parse_group(self, conf, attrib=None): - """ - This function triggers the parsing of 'group' attributes. - :param conf: configuration. - :param attrib: 'group'. - :return: generated config dictionary. - """ - a_lst = ['port_group', 'address_group', 'network_group'] - cfg_dict = self.parse_attr(conf, a_lst, match=attrib) - return cfg_dict - - def parse_icmp(self, conf, attrib=None): - """ - This function triggers the parsing of 'icmp' attributes. - :param conf: configuration to be parsed. - :param attrib: 'icmp'. - :return: generated config dictionary. - """ - a_lst = ['code', 'type', 'type_name'] - cfg_dict = self.parse_attr(conf, a_lst, match=attrib) - return cfg_dict - - def parse_limit(self, conf, attrib=None): - """ - This function triggers the parsing of 'limit' attributes. - :param conf: configuration to be parsed. - :param attrib: 'limit' - :return: generated config dictionary. - """ - cfg_dict = self.parse_attr(conf, ['burst'], match=attrib) - cfg_dict['rate'] = self.parse_rate(conf, 'rate') - return cfg_dict - - def parse_rate(self, conf, attrib=None): - """ - This function triggers the parsing of 'rate' attributes. - :param conf: configuration. - :param attrib: 'rate' - :return: generated config dictionary. - """ - a_lst = ['unit', 'number'] - cfg_dict = self.parse_attr(conf, a_lst, match=attrib) - return cfg_dict - - def parse_attr(self, conf, attr_list, match=None): - """ - This function peforms the following: - - Form the regex to fetch the required attribute config. - - Type cast the output in desired format. - :param conf: configuration. - :param attr_list: list of attributes. - :param match: parent node/attribute name. - :return: generated config dictionary. - """ - config = {} - for attrib in attr_list: - regex = self.map_regex(attrib) - if match: - regex = match + ' ' + regex - if conf: - if self.is_bool(attrib): - out = conf.find(attrib.replace("_", "-")) - - dis = conf.find(attrib.replace("_", "-") + " 'disable'") - if out >= 1: - if dis >= 1: - config[attrib] = False - else: - config[attrib] = True - else: - out = search(r'^.*' + regex + ' (.+)', conf, M) - if out: - val = out.group(1).strip("'") - if self.is_num(attrib): - val = int(val) - config[attrib] = val - return config - - def map_regex(self, attrib): - """ - - This function construct the regex string. - - replace the underscore with hyphen. - :param attrib: attribute - :return: regex string - """ - regex = attrib.replace("_", "-") - if attrib == 'disabled': - regex = 'disable' - return regex - - def is_bool(self, attrib): - """ - This function looks for the attribute in predefined bool type set. - :param attrib: attribute. - :return: True/False - """ - bool_set = ('new', 'invalid', 'related', 'disabled', 'established', 'enable_default_log') - return True if attrib in bool_set else False - - def is_num(self, attrib): - """ - This function looks for the attribute in predefined integer type set. - :param attrib: attribute. - :return: True/false. - """ - num_set = ('time', 'code', 'type', 'count', 'burst', 'number') - return True if attrib in num_set else False diff --git a/lib/ansible/module_utils/network/vyos/facts/interfaces/interfaces.py b/lib/ansible/module_utils/network/vyos/facts/interfaces/interfaces.py deleted file mode 100644 index 325319e7bf..0000000000 --- a/lib/ansible/module_utils/network/vyos/facts/interfaces/interfaces.py +++ /dev/null @@ -1,123 +0,0 @@ -# -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -""" -The vyos interfaces fact class -It is in this file the configuration is collected from the device -for a given resource, parsed, and the facts tree is populated -based on the configuration. -""" - -from __future__ import absolute_import, division, print_function -__metaclass__ = type - - -from re import findall, M -from copy import deepcopy -from ansible.module_utils.network.common import utils -from ansible.module_utils.network.vyos.argspec.interfaces.interfaces import InterfacesArgs - - -class InterfacesFacts(object): - """ The vyos interfaces fact class - """ - - def __init__(self, module, subspec='config', options='options'): - self._module = module - self.argument_spec = InterfacesArgs.argument_spec - spec = deepcopy(self.argument_spec) - if subspec: - if options: - facts_argument_spec = spec[subspec][options] - else: - facts_argument_spec = spec[subspec] - else: - facts_argument_spec = spec - - self.generated_spec = utils.generate_dict(facts_argument_spec) - - def populate_facts(self, connection, ansible_facts, data=None): - """ Populate the facts for interfaces - :param connection: the device connection - :param ansible_facts: Facts dictionary - :param data: previously collected conf - :rtype: dictionary - :returns: facts - """ - if not data: - data = connection.get_config(flags=['| grep interfaces']) - - objs = [] - interface_names = findall(r'^set interfaces (?:ethernet|bonding|vti|loopback|vxlan) (?:\'*)(\S+)(?:\'*)', - data, M) - if interface_names: - for interface in set(interface_names): - intf_regex = r' %s .+$' % interface.strip("'") - cfg = findall(intf_regex, data, M) - obj = self.render_config(cfg) - obj['name'] = interface.strip("'") - if obj: - objs.append(obj) - facts = {} - if objs: - facts['interfaces'] = [] - params = utils.validate_config(self.argument_spec, {'config': objs}) - for cfg in params['config']: - facts['interfaces'].append(utils.remove_empties(cfg)) - - ansible_facts['ansible_network_resources'].update(facts) - return ansible_facts - - def render_config(self, conf): - """ - Render config as dictionary structure and delete keys - from spec for null values - - :param spec: The facts tree, generated from the argspec - :param conf: The configuration - :rtype: dictionary - :returns: The generated config - """ - vif_conf = '\n'.join(filter(lambda x: ('vif' in x), conf)) - eth_conf = '\n'.join(filter(lambda x: ('vif' not in x), conf)) - config = self.parse_attribs( - ['description', 'speed', 'mtu', 'duplex'], eth_conf) - config['vifs'] = self.parse_vifs(vif_conf) - - return utils.remove_empties(config) - - def parse_vifs(self, conf): - vif_names = findall(r'vif (?:\'*)(\d+)(?:\'*)', conf, M) - vifs_list = None - - if vif_names: - vifs_list = [] - for vif in set(vif_names): - vif_regex = r' %s .+$' % vif - cfg = '\n'.join(findall(vif_regex, conf, M)) - obj = self.parse_attribs(['description', 'mtu'], cfg) - obj['vlan_id'] = int(vif) - if obj: - vifs_list.append(obj) - vifs_list = sorted(vifs_list, key=lambda i: i['vlan_id']) - - return vifs_list - - def parse_attribs(self, attribs, conf): - config = {} - for item in attribs: - value = utils.parse_conf_arg(conf, item) - if value and item == 'mtu': - config[item] = int(value.strip("'")) - elif value: - config[item] = value.strip("'") - else: - config[item] = None - if 'disable' in conf: - config['enabled'] = False - else: - config['enabled'] = True - - return utils.remove_empties(config) diff --git a/lib/ansible/module_utils/network/vyos/facts/l3_interfaces/l3_interfaces.py b/lib/ansible/module_utils/network/vyos/facts/l3_interfaces/l3_interfaces.py deleted file mode 100644 index 7a33f81491..0000000000 --- a/lib/ansible/module_utils/network/vyos/facts/l3_interfaces/l3_interfaces.py +++ /dev/null @@ -1,130 +0,0 @@ -# -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -""" -The vyos l3_interfaces fact class -It is in this file the configuration is collected from the device -for a given resource, parsed, and the facts tree is populated -based on the configuration. -""" - -from __future__ import absolute_import, division, print_function -__metaclass__ = type - - -import re -from copy import deepcopy -from ansible.module_utils.network.common import utils -from ansible.module_utils.six import iteritems -from ansible.module_utils.compat import ipaddress -from ansible.module_utils.network.vyos.argspec.l3_interfaces.l3_interfaces import L3_interfacesArgs - - -class L3_interfacesFacts(object): - """ The vyos l3_interfaces fact class - """ - - def __init__(self, module, subspec='config', options='options'): - self._module = module - self.argument_spec = L3_interfacesArgs.argument_spec - spec = deepcopy(self.argument_spec) - if subspec: - if options: - facts_argument_spec = spec[subspec][options] - else: - facts_argument_spec = spec[subspec] - else: - facts_argument_spec = spec - - self.generated_spec = utils.generate_dict(facts_argument_spec) - - def populate_facts(self, connection, ansible_facts, data=None): - """ Populate the facts for l3_interfaces - :param connection: the device connection - :param ansible_facts: Facts dictionary - :param data: previously collected conf - :rtype: dictionary - :returns: facts - """ - if not data: - data = connection.get_config() - - # operate on a collection of resource x - objs = [] - interface_names = re.findall(r'set interfaces (?:ethernet|bonding|vti|vxlan) (?:\'*)(\S+)(?:\'*)', data, re.M) - if interface_names: - for interface in set(interface_names): - intf_regex = r' %s .+$' % interface - cfg = re.findall(intf_regex, data, re.M) - obj = self.render_config(cfg) - obj['name'] = interface.strip("'") - if obj: - objs.append(obj) - - ansible_facts['ansible_network_resources'].pop('l3_interfaces', None) - facts = {} - if objs: - facts['l3_interfaces'] = [] - params = utils.validate_config(self.argument_spec, {'config': objs}) - for cfg in params['config']: - facts['l3_interfaces'].append(utils.remove_empties(cfg)) - - ansible_facts['ansible_network_resources'].update(facts) - return ansible_facts - - def render_config(self, conf): - """ - Render config as dictionary structure and delete keys from spec for null values - :param spec: The facts tree, generated from the argspec - :param conf: The configuration - :rtype: dictionary - :returns: The generated config - """ - vif_conf = '\n'.join(filter(lambda x: ('vif' in x), conf)) - eth_conf = '\n'.join(filter(lambda x: ('vif' not in x), conf)) - config = self.parse_attribs(eth_conf) - config['vifs'] = self.parse_vifs(vif_conf) - - return utils.remove_empties(config) - - def parse_vifs(self, conf): - vif_names = re.findall(r'vif (\d+)', conf, re.M) - vifs_list = None - if vif_names: - vifs_list = [] - for vif in set(vif_names): - vif_regex = r' %s .+$' % vif - cfg = '\n'.join(re.findall(vif_regex, conf, re.M)) - obj = self.parse_attribs(cfg) - obj['vlan_id'] = vif - if obj: - vifs_list.append(obj) - - return vifs_list - - def parse_attribs(self, conf): - config = {} - ipaddrs = re.findall(r'address (\S+)', conf, re.M) - config['ipv4'] = [] - config['ipv6'] = [] - - for item in ipaddrs: - item = item.strip("'") - if item == 'dhcp': - config['ipv4'].append({'address': item}) - elif item == 'dhcpv6': - config['ipv6'].append({'address': item}) - else: - ip_version = ipaddress.ip_address(item.split("/")[0]).version - if ip_version == 4: - config['ipv4'].append({'address': item}) - else: - config['ipv6'].append({'address': item}) - - for key, value in iteritems(config): - if value == []: - config[key] = None - - return utils.remove_empties(config) diff --git a/lib/ansible/module_utils/network/vyos/facts/lag_interfaces/lag_interfaces.py b/lib/ansible/module_utils/network/vyos/facts/lag_interfaces/lag_interfaces.py deleted file mode 100644 index 7b3eb95a13..0000000000 --- a/lib/ansible/module_utils/network/vyos/facts/lag_interfaces/lag_interfaces.py +++ /dev/null @@ -1,142 +0,0 @@ -# -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -""" -The vyos lag_interfaces fact class -It is in this file the configuration is collected from the device -for a given resource, parsed, and the facts tree is populated -based on the configuration. -""" -from __future__ import absolute_import, division, print_function -__metaclass__ = type -from re import findall, search, M -from copy import deepcopy - -from ansible.module_utils.network.common import utils -from ansible.module_utils.network.vyos.argspec.lag_interfaces. \ - lag_interfaces import Lag_interfacesArgs - - -class Lag_interfacesFacts(object): - """ The vyos lag_interfaces fact class - """ - - def __init__(self, module, subspec='config', options='options'): - self._module = module - self.argument_spec = Lag_interfacesArgs.argument_spec - spec = deepcopy(self.argument_spec) - if subspec: - if options: - facts_argument_spec = spec[subspec][options] - else: - facts_argument_spec = spec[subspec] - else: - facts_argument_spec = spec - - self.generated_spec = utils.generate_dict(facts_argument_spec) - - def populate_facts(self, connection, ansible_facts, data=None): - """ Populate the facts for lag_interfaces - :param module: the module instance - :param connection: the device connection - :param data: previously collected conf - :rtype: dictionary - :returns: facts - """ - if not data: - data = connection.get_config() - - objs = [] - lag_names = findall(r'^set interfaces bonding (\S+)', data, M) - if lag_names: - for lag in set(lag_names): - lag_regex = r' %s .+$' % lag - cfg = findall(lag_regex, data, M) - obj = self.render_config(cfg) - - output = connection.run_commands(['show interfaces bonding ' + lag + ' slaves']) - lines = output[0].splitlines() - members = [] - member = {} - if len(lines) > 1: - for line in lines[2:]: - splitted_line = line.split() - - if len(splitted_line) > 1: - member['member'] = splitted_line[0] - members.append(member) - else: - members = [] - member = {} - obj['name'] = lag.strip("'") - if members: - obj['members'] = members - - if obj: - objs.append(obj) - - facts = {} - if objs: - facts['lag_interfaces'] = [] - params = utils.validate_config(self.argument_spec, {'config': objs}) - for cfg in params['config']: - facts['lag_interfaces'].append(utils.remove_empties(cfg)) - - ansible_facts['ansible_network_resources'].update(facts) - return ansible_facts - - def render_config(self, conf): - """ - Render config as dictionary structure and delete keys - from spec for null values - - :param spec: The facts tree, generated from the argspec - :param conf: The configuration - :rtype: dictionary - :returns: The generated config - """ - arp_monitor_conf = '\n'.join(filter(lambda x: ('arp-monitor' in x), conf)) - hash_policy_conf = '\n'.join(filter(lambda x: ('hash-policy' in x), conf)) - lag_conf = '\n'.join(filter(lambda x: ('bond' in x), conf)) - config = self.parse_attribs( - ['mode', 'primary'], lag_conf - ) - config['arp_monitor'] = self.parse_arp_monitor(arp_monitor_conf) - config['hash_policy'] = self.parse_hash_policy(hash_policy_conf) - - return utils.remove_empties(config) - - def parse_attribs(self, attribs, conf): - config = {} - for item in attribs: - value = utils.parse_conf_arg(conf, item) - if value: - config[item] = value.strip("'") - else: - config[item] = None - return utils.remove_empties(config) - - def parse_arp_monitor(self, conf): - arp_monitor = None - if conf: - arp_monitor = {} - target_list = [] - interval = search(r'^.*arp-monitor interval (.+)', conf, M) - targets = findall(r"^.*arp-monitor target '(.+)'", conf, M) - if targets: - for target in targets: - target_list.append(target) - arp_monitor['target'] = target_list - if interval: - value = interval.group(1).strip("'") - arp_monitor['interval'] = int(value) - return arp_monitor - - def parse_hash_policy(self, conf): - hash_policy = None - if conf: - hash_policy = search(r'^.*hash-policy (.+)', conf, M) - hash_policy = hash_policy.group(1).strip("'") - return hash_policy diff --git a/lib/ansible/module_utils/network/vyos/facts/legacy/base.py b/lib/ansible/module_utils/network/vyos/facts/legacy/base.py deleted file mode 100644 index 702cda5a1e..0000000000 --- a/lib/ansible/module_utils/network/vyos/facts/legacy/base.py +++ /dev/null @@ -1,159 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -""" -The VyOS interfaces fact class -It is in this file the configuration is collected from the device -for a given resource, parsed, and the facts tree is populated -based on the configuration. -""" - -from __future__ import absolute_import, division, print_function -__metaclass__ = type -import platform -import re -from ansible.module_utils. \ - network.vyos.vyos import run_commands, get_capabilities - - -class LegacyFactsBase(object): - - COMMANDS = frozenset() - - def __init__(self, module): - self.module = module - self.facts = dict() - self.warnings = list() - self.responses = None - - def populate(self): - self.responses = run_commands(self.module, list(self.COMMANDS)) - - -class Default(LegacyFactsBase): - - COMMANDS = [ - 'show version', - ] - - def populate(self): - super(Default, self).populate() - data = self.responses[0] - self.facts['serialnum'] = self.parse_serialnum(data) - self.facts.update(self.platform_facts()) - - def parse_serialnum(self, data): - match = re.search(r'HW S/N:\s+(\S+)', data) - if match: - return match.group(1) - - def platform_facts(self): - platform_facts = {} - - resp = get_capabilities(self.module) - device_info = resp['device_info'] - - platform_facts['system'] = device_info['network_os'] - - for item in ('model', 'image', 'version', 'platform', 'hostname'): - val = device_info.get('network_os_%s' % item) - if val: - platform_facts[item] = val - - platform_facts['api'] = resp['network_api'] - platform_facts['python_version'] = platform.python_version() - - return platform_facts - - -class Config(LegacyFactsBase): - - COMMANDS = [ - 'show configuration commands', - 'show system commit', - ] - - def populate(self): - super(Config, self).populate() - - self.facts['config'] = self.responses - - commits = self.responses[1] - entries = list() - entry = None - - for line in commits.split('\n'): - match = re.match(r'(\d+)\s+(.+)by(.+)via(.+)', line) - if match: - if entry: - entries.append(entry) - - entry = dict(revision=match.group(1), - datetime=match.group(2), - by=str(match.group(3)).strip(), - via=str(match.group(4)).strip(), - comment=None) - else: - entry['comment'] = line.strip() - - self.facts['commits'] = entries - - -class Neighbors(LegacyFactsBase): - - COMMANDS = [ - 'show lldp neighbors', - 'show lldp neighbors detail', - ] - - def populate(self): - super(Neighbors, self).populate() - - all_neighbors = self.responses[0] - if 'LLDP not configured' not in all_neighbors: - neighbors = self.parse( - self.responses[1] - ) - self.facts['neighbors'] = self.parse_neighbors(neighbors) - - def parse(self, data): - parsed = list() - values = None - for line in data.split('\n'): - if not line: - continue - elif line[0] == ' ': - values += '\n%s' % line - elif line.startswith('Interface'): - if values: - parsed.append(values) - values = line - if values: - parsed.append(values) - return parsed - - def parse_neighbors(self, data): - facts = dict() - for item in data: - interface = self.parse_interface(item) - host = self.parse_host(item) - port = self.parse_port(item) - if interface not in facts: - facts[interface] = list() - facts[interface].append(dict(host=host, port=port)) - return facts - - def parse_interface(self, data): - match = re.search(r'^Interface:\s+(\S+),', data) - return match.group(1) - - def parse_host(self, data): - match = re.search(r'SysName:\s+(.+)$', data, re.M) - if match: - return match.group(1) - - def parse_port(self, data): - match = re.search(r'PortDescr:\s+(.+)$', data, re.M) - if match: - return match.group(1) diff --git a/lib/ansible/module_utils/network/vyos/facts/lldp_global/lldp_global.py b/lib/ansible/module_utils/network/vyos/facts/lldp_global/lldp_global.py deleted file mode 100644 index 1341650ce2..0000000000 --- a/lib/ansible/module_utils/network/vyos/facts/lldp_global/lldp_global.py +++ /dev/null @@ -1,109 +0,0 @@ -# -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -""" -The vyos lldp_global fact class -It is in this file the configuration is collected from the device -for a given resource, parsed, and the facts tree is populated -based on the configuration. -""" -from __future__ import absolute_import, division, print_function -__metaclass__ = type - -from re import findall, M -from copy import deepcopy - -from ansible.module_utils.network.common import utils -from ansible.module_utils.network.vyos.argspec.lldp_global.lldp_global import Lldp_globalArgs - - -class Lldp_globalFacts(object): - """ The vyos lldp_global fact class - """ - - def __init__(self, module, subspec='config', options='options'): - self._module = module - self.argument_spec = Lldp_globalArgs.argument_spec - spec = deepcopy(self.argument_spec) - if subspec: - if options: - facts_argument_spec = spec[subspec][options] - else: - facts_argument_spec = spec[subspec] - else: - facts_argument_spec = spec - - self.generated_spec = utils.generate_dict(facts_argument_spec) - - def populate_facts(self, connection, ansible_facts, data=None): - """ Populate the facts for lldp_global - :param connection: the device connection - :param ansible_facts: Facts dictionary - :param data: previously collected conf - :rtype: dictionary - :returns: facts - """ - if not data: - data = connection.get_config() - - objs = {} - lldp_output = findall(r'^set service lldp (\S+)', data, M) - if lldp_output: - for item in set(lldp_output): - lldp_regex = r' %s .+$' % item - cfg = findall(lldp_regex, data, M) - obj = self.render_config(cfg) - if obj: - objs.update(obj) - lldp_service = findall(r"^set service (lldp)?('lldp')", data, M) - if lldp_service or lldp_output: - lldp_obj = {} - lldp_obj['enable'] = True - objs.update(lldp_obj) - - facts = {} - params = utils.validate_config(self.argument_spec, {'config': objs}) - facts['lldp_global'] = utils.remove_empties(params['config']) - - ansible_facts['ansible_network_resources'].update(facts) - - return ansible_facts - - def render_config(self, conf): - """ - Render config as dictionary structure and delete keys - from spec for null values - :param spec: The facts tree, generated from the argspec - :param conf: The configuration - :rtype: dictionary - :returns: The generated config - """ - protocol_conf = '\n'.join(filter(lambda x: ('legacy-protocols' in x), conf)) - att_conf = '\n'.join(filter(lambda x: ('legacy-protocols' not in x), conf)) - config = self.parse_attribs( - ['snmp', 'address'], att_conf - ) - config['legacy_protocols'] = self.parse_protocols(protocol_conf) - return utils.remove_empties(config) - - def parse_protocols(self, conf): - protocol_support = None - if conf: - protocols = findall(r'^.*legacy-protocols (.+)', conf, M) - if protocols: - protocol_support = [] - for protocol in protocols: - protocol_support.append(protocol.strip("'")) - return protocol_support - - def parse_attribs(self, attribs, conf): - config = {} - for item in attribs: - value = utils.parse_conf_arg(conf, item) - if value: - config[item] = value.strip("'") - else: - config[item] = None - return utils.remove_empties(config) diff --git a/lib/ansible/module_utils/network/vyos/facts/lldp_interfaces/lldp_interfaces.py b/lib/ansible/module_utils/network/vyos/facts/lldp_interfaces/lldp_interfaces.py deleted file mode 100644 index 62043b3ab9..0000000000 --- a/lib/ansible/module_utils/network/vyos/facts/lldp_interfaces/lldp_interfaces.py +++ /dev/null @@ -1,147 +0,0 @@ -# -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -""" -The vyos lldp_interfaces fact class -It is in this file the configuration is collected from the device -for a given resource, parsed, and the facts tree is populated -based on the configuration. -""" - -from __future__ import absolute_import, division, print_function -__metaclass__ = type - - -from re import findall, search, M -from copy import deepcopy - -from ansible.module_utils.network.common import utils -from ansible.module_utils.network.vyos.argspec.lldp_interfaces. \ - lldp_interfaces import Lldp_interfacesArgs - - -class Lldp_interfacesFacts(object): - """ The vyos lldp_interfaces fact class - """ - - def __init__(self, module, subspec='config', options='options'): - self._module = module - self.argument_spec = Lldp_interfacesArgs.argument_spec - spec = deepcopy(self.argument_spec) - if subspec: - if options: - facts_argument_spec = spec[subspec][options] - else: - facts_argument_spec = spec[subspec] - else: - facts_argument_spec = spec - - self.generated_spec = utils.generate_dict(facts_argument_spec) - - def populate_facts(self, connection, ansible_facts, data=None): - """ Populate the facts for lldp_interfaces - :param connection: the device connection - :param ansible_facts: Facts dictionary - :param data: previously collected conf - :rtype: dictionary - :returns: facts - """ - if not data: - data = connection.get_config() - - objs = [] - lldp_names = findall(r'^set service lldp interface (\S+)', data, M) - if lldp_names: - for lldp in set(lldp_names): - lldp_regex = r' %s .+$' % lldp - cfg = findall(lldp_regex, data, M) - obj = self.render_config(cfg) - obj['name'] = lldp.strip("'") - if obj: - objs.append(obj) - facts = {} - if objs: - facts['lldp_interfaces'] = objs - ansible_facts['ansible_network_resources'].update(facts) - - ansible_facts['ansible_network_resources'].update(facts) - return ansible_facts - - def render_config(self, conf): - """ - Render config as dictionary structure and delete keys - from spec for null values - - :param spec: The facts tree, generated from the argspec - :param conf: The configuration - :rtype: dictionary - :returns: The generated config - """ - config = {} - location = {} - - civic_conf = '\n'.join(filter(lambda x: ('civic-based' in x), conf)) - elin_conf = '\n'.join(filter(lambda x: ('elin' in x), conf)) - coordinate_conf = '\n'.join(filter(lambda x: ('coordinate-based' in x), conf)) - disable = '\n'.join(filter(lambda x: ('disable' in x), conf)) - - coordinate_based_conf = self.parse_attribs( - ['altitude', 'datum', 'longitude', 'latitude'], coordinate_conf - ) - elin_based_conf = self.parse_lldp_elin_based(elin_conf) - civic_based_conf = self.parse_lldp_civic_based(civic_conf) - if disable: - config['enable'] = False - if coordinate_conf: - location['coordinate_based'] = coordinate_based_conf - config['location'] = location - elif civic_based_conf: - location['civic_based'] = civic_based_conf - config['location'] = location - elif elin_conf: - location['elin'] = elin_based_conf - config['location'] = location - - return utils.remove_empties(config) - - def parse_attribs(self, attribs, conf): - config = {} - for item in attribs: - value = utils.parse_conf_arg(conf, item) - if value: - value = value.strip("'") - if item == 'altitude': - value = int(value) - config[item] = value - else: - config[item] = None - return utils.remove_empties(config) - - def parse_lldp_civic_based(self, conf): - civic_based = None - if conf: - civic_info_list = [] - civic_add_list = findall(r"^.*civic-based ca-type (.+)", conf, M) - if civic_add_list: - for civic_add in civic_add_list: - ca = civic_add.split(' ') - c_add = {} - c_add['ca_type'] = int(ca[0].strip("'")) - c_add['ca_value'] = ca[2].strip("'") - civic_info_list.append(c_add) - - country_code = search(r'^.*civic-based country-code (.+)', conf, M) - civic_based = {} - civic_based['ca_info'] = civic_info_list - civic_based['country_code'] = country_code.group(1).strip("'") - return civic_based - - def parse_lldp_elin_based(self, conf): - elin_based = None - if conf: - e_num = search(r'^.* elin (.+)', conf, M) - elin_based = e_num.group(1).strip("'") - - return elin_based diff --git a/lib/ansible/module_utils/network/vyos/facts/static_routes/static_routes.py b/lib/ansible/module_utils/network/vyos/facts/static_routes/static_routes.py deleted file mode 100644 index 4acbab4da7..0000000000 --- a/lib/ansible/module_utils/network/vyos/facts/static_routes/static_routes.py +++ /dev/null @@ -1,161 +0,0 @@ -# -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -""" -The vyos static_routes fact class -It is in this file the configuration is collected from the device -for a given resource, parsed, and the facts tree is populated -based on the configuration. -""" - -from __future__ import absolute_import, division, print_function -__metaclass__ = type -from re import findall, search, M -from copy import deepcopy -from ansible.module_utils.network.common import utils -from ansible.module_utils.network.vyos.argspec.static_routes.static_routes import Static_routesArgs -from ansible.module_utils.network. vyos.utils.utils import get_route_type - - -class Static_routesFacts(object): - """ The vyos static_routes fact class - """ - - def __init__(self, module, subspec='config', options='options'): - self._module = module - self.argument_spec = Static_routesArgs.argument_spec - spec = deepcopy(self.argument_spec) - if subspec: - if options: - facts_argument_spec = spec[subspec][options] - else: - facts_argument_spec = spec[subspec] - else: - facts_argument_spec = spec - - self.generated_spec = utils.generate_dict(facts_argument_spec) - - def get_device_data(self, connection): - return connection.get_config() - - def populate_facts(self, connection, ansible_facts, data=None): - """ Populate the facts for static_routes - :param connection: the device connection - :param ansible_facts: Facts dictionary - :param data: previously collected conf - :rtype: dictionary - :returns: facts - """ - if not data: - data = self.get_device_data(connection) - # typically data is populated from the current device configuration - # data = connection.get('show running-config | section ^interface') - # using mock data instead - objs = [] - r_v4 = [] - r_v6 = [] - af = [] - static_routes = findall(r'set protocols static route(6)? (\S+)', data, M) - if static_routes: - for route in set(static_routes): - route_regex = r' %s .+$' % route[1] - cfg = findall(route_regex, data, M) - sr = self.render_config(cfg) - sr['dest'] = route[1].strip("'") - afi = self.get_afi(sr['dest']) - if afi == 'ipv4': - r_v4.append(sr) - else: - r_v6.append(sr) - if r_v4: - afi_v4 = {'afi': 'ipv4', 'routes': r_v4} - af.append(afi_v4) - if r_v6: - afi_v6 = {'afi': 'ipv6', 'routes': r_v6} - af.append(afi_v6) - config = {'address_families': af} - if config: - objs.append(config) - - ansible_facts['ansible_network_resources'].pop('static_routes', None) - facts = {} - if objs: - facts['static_routes'] = [] - params = utils.validate_config(self.argument_spec, {'config': objs}) - for cfg in params['config']: - facts['static_routes'].append(utils.remove_empties(cfg)) - - ansible_facts['ansible_network_resources'].update(facts) - return ansible_facts - - def render_config(self, conf): - """ - Render config as dictionary structure and delete keys - from spec for null values - - :param spec: The facts tree, generated from the argspec - :param conf: The configuration - :rtype: dictionary - :returns: The generated config - """ - next_hops_conf = '\n'.join(filter(lambda x: ('next-hop' in x), conf)) - blackhole_conf = '\n'.join(filter(lambda x: ('blackhole' in x), conf)) - routes_dict = {'blackhole_config': self.parse_blackhole(blackhole_conf), - 'next_hops': self.parse_next_hop(next_hops_conf)} - return routes_dict - - def parse_blackhole(self, conf): - blackhole = None - if conf: - distance = search(r'^.*blackhole distance (.\S+)', conf, M) - bh = conf.find('blackhole') - if distance is not None: - blackhole = {} - value = distance.group(1).strip("'") - blackhole['distance'] = int(value) - elif bh: - blackhole = {} - blackhole['type'] = 'blackhole' - return blackhole - - def get_afi(self, address): - route_type = get_route_type(address) - if route_type == 'route': - return 'ipv4' - elif route_type == 'route6': - return 'ipv6' - - def parse_next_hop(self, conf): - nh_list = None - if conf: - nh_list = [] - hop_list = findall(r"^.*next-hop (.+)", conf, M) - if hop_list: - for hop in hop_list: - distance = search(r'^.*distance (.\S+)', hop, M) - interface = search(r'^.*interface (.\S+)', hop, M) - - dis = hop.find('disable') - hop_info = hop.split(' ') - nh_info = {'forward_router_address': hop_info[0].strip("'")} - if interface: - nh_info['interface'] = interface.group(1).strip("'") - if distance: - value = distance.group(1).strip("'") - nh_info['admin_distance'] = int(value) - elif dis >= 1: - nh_info['enabled'] = False - for element in nh_list: - if element['forward_router_address'] == nh_info['forward_router_address']: - if 'interface' in nh_info.keys(): - element['interface'] = nh_info['interface'] - if 'admin_distance' in nh_info.keys(): - element['admin_distance'] = nh_info['admin_distance'] - if 'enabled' in nh_info.keys(): - element['enabled'] = nh_info['enabled'] - nh_info = None - if nh_info is not None: - nh_list.append(nh_info) - return nh_list diff --git a/lib/ansible/module_utils/network/vyos/utils/utils.py b/lib/ansible/module_utils/network/vyos/utils/utils.py deleted file mode 100644 index cdcb448b19..0000000000 --- a/lib/ansible/module_utils/network/vyos/utils/utils.py +++ /dev/null @@ -1,210 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -# utils -from __future__ import absolute_import, division, print_function -__metaclass__ = type -from ansible.module_utils.six import iteritems -from ansible.module_utils.compat import ipaddress - - -def search_obj_in_list(name, lst, key='name'): - if lst: - for item in lst: - if item[key] == name: - return item - return None - - -def get_interface_type(interface): - """Gets the type of interface - """ - if interface.startswith('eth'): - return 'ethernet' - elif interface.startswith('bond'): - return 'bonding' - elif interface.startswith('vti'): - return 'vti' - elif interface.startswith('lo'): - return 'loopback' - - -def dict_delete(base, comparable): - """ - This function generates a dict containing key, value pairs for keys - that are present in the `base` dict but not present in the `comparable` - dict. - - :param base: dict object to base the diff on - :param comparable: dict object to compare against base - :returns: new dict object with key, value pairs that needs to be deleted. - - """ - to_delete = dict() - - for key in base: - if isinstance(base[key], dict): - sub_diff = dict_delete(base[key], comparable.get(key, {})) - if sub_diff: - to_delete[key] = sub_diff - else: - if key not in comparable: - to_delete[key] = base[key] - - return to_delete - - -def diff_list_of_dicts(want, have): - diff = [] - - set_w = set(tuple(d.items()) for d in want) - set_h = set(tuple(d.items()) for d in have) - difference = set_w.difference(set_h) - - for element in difference: - diff.append(dict((x, y) for x, y in element)) - - return diff - - -def get_lst_diff_for_dicts(want, have, lst): - """ - This function generates a list containing values - that are only in want and not in list in have dict - :param want: dict object to want - :param have: dict object to have - :param lst: list the diff on - :return: new list object with values which are only in want. - """ - if not have: - diff = want.get(lst) or [] - - else: - want_elements = want.get(lst) or {} - have_elements = have.get(lst) or {} - diff = list_diff_want_only(want_elements, have_elements) - return diff - - -def get_lst_same_for_dicts(want, have, lst): - """ - This function generates a list containing values - that are common for list in want and list in have dict - :param want: dict object to want - :param have: dict object to have - :param lst: list the comparison on - :return: new list object with values which are common in want and have. - """ - diff = None - if want and have: - want_list = want.get(lst) or {} - have_list = have.get(lst) or {} - diff = [i for i in want_list and have_list if i in have_list and i in want_list] - return diff - - -def list_diff_have_only(want_list, have_list): - """ - This function generated the list containing values - that are only in have list. - :param want_list: - :param have_list: - :return: new list with values which are only in have list - """ - if have_list and not want_list: - diff = have_list - elif not have_list: - diff = None - else: - diff = [i for i in have_list + want_list if i in have_list and i not in want_list] - return diff - - -def list_diff_want_only(want_list, have_list): - """ - This function generated the list containing values - that are only in want list. - :param want_list: - :param have_list: - :return: new list with values which are only in want list - """ - if have_list and not want_list: - diff = None - elif not have_list: - diff = want_list - else: - diff = [i for i in have_list + want_list if i in want_list and i not in have_list] - return diff - - -def search_dict_tv_in_list(d_val1, d_val2, lst, key1, key2): - """ - This function return the dict object if it exist in list. - :param d_val1: - :param d_val2: - :param lst: - :param key1: - :param key2: - :return: - """ - obj = next((item for item in lst if item[key1] == d_val1 and item[key2] == d_val2), None) - if obj: - return obj - else: - return None - - -def key_value_in_dict(have_key, have_value, want_dict): - """ - This function checks whether the key and values exist in dict - :param have_key: - :param have_value: - :param want_dict: - :return: - """ - for key, value in iteritems(want_dict): - if key == have_key and value == have_value: - return True - return False - - -def is_dict_element_present(dict, key): - """ - This function checks whether the key is present in dict. - :param dict: - :param key: - :return: - """ - for item in dict: - if item == key: - return True - return False - - -def get_ip_address_version(address): - """ - This function returns the version of IP address - :param address: IP address - :return: - """ - try: - address = unicode(address) - except NameError: - address = str(address) - version = ipaddress.ip_address(address.split("/")[0]).version - return version - - -def get_route_type(address): - """ - This function returns the route type based on IP address - :param address: - :return: - """ - version = get_ip_address_version(address) - if version == 6: - return 'route6' - elif version == 4: - return 'route' diff --git a/lib/ansible/module_utils/network/vyos/vyos.py b/lib/ansible/module_utils/network/vyos/vyos.py deleted file mode 100644 index d904e12926..0000000000 --- a/lib/ansible/module_utils/network/vyos/vyos.py +++ /dev/null @@ -1,116 +0,0 @@ -# This code is part of Ansible, but is an independent component. -# This particular file snippet, and this file snippet only, is BSD licensed. -# Modules you write using this snippet, which is embedded dynamically by Ansible -# still belong to the author of the module, and may assign their own license -# to the complete work. -# -# (c) 2016 Red Hat Inc. -# -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# -import json - -from ansible.module_utils._text import to_text -from ansible.module_utils.basic import env_fallback -from ansible.module_utils.connection import Connection, ConnectionError - -_DEVICE_CONFIGS = {} - -vyos_provider_spec = { - 'host': dict(), - 'port': dict(type='int'), - - 'username': dict(fallback=(env_fallback, ['ANSIBLE_NET_USERNAME'])), - 'password': dict(fallback=(env_fallback, ['ANSIBLE_NET_PASSWORD']), no_log=True), - 'ssh_keyfile': dict(fallback=(env_fallback, ['ANSIBLE_NET_SSH_KEYFILE']), type='path'), - - 'timeout': dict(type='int'), -} -vyos_argument_spec = { - 'provider': dict(type='dict', options=vyos_provider_spec, removed_in_version=2.14), -} - - -def get_provider_argspec(): - return vyos_provider_spec - - -def get_connection(module): - if hasattr(module, '_vyos_connection'): - return module._vyos_connection - - capabilities = get_capabilities(module) - network_api = capabilities.get('network_api') - if network_api == 'cliconf': - module._vyos_connection = Connection(module._socket_path) - else: - module.fail_json(msg='Invalid connection type %s' % network_api) - - return module._vyos_connection - - -def get_capabilities(module): - if hasattr(module, '_vyos_capabilities'): - return module._vyos_capabilities - - try: - capabilities = Connection(module._socket_path).get_capabilities() - except ConnectionError as exc: - module.fail_json(msg=to_text(exc, errors='surrogate_then_replace')) - - module._vyos_capabilities = json.loads(capabilities) - return module._vyos_capabilities - - -def get_config(module, flags=None, format=None): - flags = [] if flags is None else flags - global _DEVICE_CONFIGS - - if _DEVICE_CONFIGS != {}: - return _DEVICE_CONFIGS - else: - connection = get_connection(module) - try: - out = connection.get_config(flags=flags, format=format) - except ConnectionError as exc: - module.fail_json(msg=to_text(exc, errors='surrogate_then_replace')) - cfg = to_text(out, errors='surrogate_then_replace').strip() - _DEVICE_CONFIGS = cfg - return cfg - - -def run_commands(module, commands, check_rc=True): - connection = get_connection(module) - try: - response = connection.run_commands(commands=commands, check_rc=check_rc) - except ConnectionError as exc: - module.fail_json(msg=to_text(exc, errors='surrogate_then_replace')) - return response - - -def load_config(module, commands, commit=False, comment=None): - connection = get_connection(module) - - try: - response = connection.edit_config(candidate=commands, commit=commit, comment=comment) - except ConnectionError as exc: - module.fail_json(msg=to_text(exc, errors='surrogate_then_replace')) - - return response.get('diff') diff --git a/lib/ansible/modules/network/vyos/_vyos_interface.py b/lib/ansible/modules/network/vyos/_vyos_interface.py deleted file mode 100644 index f6652b1fd3..0000000000 --- a/lib/ansible/modules/network/vyos/_vyos_interface.py +++ /dev/null @@ -1,442 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['deprecated'], - 'supported_by': 'network'} - - -DOCUMENTATION = """ ---- -module: vyos_interface -version_added: "2.4" -author: "Ganesh Nalawade (@ganeshrn)" -short_description: Manage Interface on VyOS network devices -description: - - This module provides declarative management of Interfaces - on VyOS network devices. -deprecated: - removed_in: '2.13' - alternative: vyos_interfaces - why: Updated modules released with more functionality. -notes: - - Tested against VYOS 1.1.7 -options: - name: - description: - - Name of the Interface. - required: true - description: - description: - - Description of Interface. - enabled: - description: - - Interface link status. - type: bool - speed: - description: - - Interface link speed. - mtu: - description: - - Maximum size of transmit packet. - duplex: - description: - - Interface link status. - default: auto - choices: ['full', 'half', 'auto'] - delay: - description: - - Time in seconds to wait before checking for the operational state on remote - device. This wait is applicable for operational state argument which are - I(state) with values C(up)/C(down) and I(neighbors). - default: 10 - 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." - version_added: 2.5 - aggregate: - description: List of Interfaces definitions. - state: - description: - - State of the Interface configuration, C(up) means present and - operationally up and C(down) means present and operationally C(down) - default: present - choices: ['present', 'absent', 'up', 'down'] -extends_documentation_fragment: vyos -""" - -EXAMPLES = """ -- name: configure interface - vyos_interface: - name: eth0 - description: test-interface - -- name: remove interface - vyos_interface: - name: eth0 - state: absent - -- name: make interface down - vyos_interface: - name: eth0 - enabled: False - -- name: make interface up - vyos_interface: - name: eth0 - enabled: True - -- name: Configure interface speed, mtu, duplex - vyos_interface: - name: eth5 - state: present - speed: 100 - mtu: 256 - duplex: full - -- name: Set interface using aggregate - vyos_interface: - aggregate: - - { name: eth1, description: test-interface-1, speed: 100, duplex: half, mtu: 512} - - { name: eth2, description: test-interface-2, speed: 1000, duplex: full, mtu: 256} - -- name: Disable interface on aggregate - net_interface: - aggregate: - - name: eth1 - - name: eth2 - enabled: False - -- name: Delete interface using aggregate - net_interface: - aggregate: - - name: eth1 - - name: eth2 - state: absent - -- name: Check lldp neighbors intent arguments - vyos_interface: - name: eth0 - neighbors: - - port: eth0 - host: netdev - -- name: Config + intent - vyos_interface: - name: eth1 - enabled: False - state: down -""" - -RETURN = """ -commands: - description: The list of configuration mode commands to send to the device - returned: always, except for the platforms that use Netconf transport to manage the device. - type: list - sample: - - set interfaces ethernet eth0 description "test-interface" - - set interfaces ethernet eth0 speed 100 - - set interfaces ethernet eth0 mtu 256 - - set interfaces ethernet eth0 duplex full -""" -import re - -from copy import deepcopy -from time import sleep - -from ansible.module_utils._text import to_text -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.connection import exec_command -from ansible.module_utils.network.common.utils import conditional, remove_default_spec -from ansible.module_utils.network.vyos.vyos import load_config, get_config -from ansible.module_utils.network.vyos.vyos import vyos_argument_spec - - -def search_obj_in_list(name, lst): - for o in lst: - if o['name'] == name: - return o - - return None - - -def map_obj_to_commands(updates): - commands = list() - want, have = updates - - params = ('speed', 'description', 'duplex', 'mtu') - for w in want: - name = w['name'] - disable = w['disable'] - state = w['state'] - - obj_in_have = search_obj_in_list(name, have) - set_interface = 'set interfaces ethernet ' + name - delete_interface = 'delete interfaces ethernet ' + name - - if state == 'absent' and obj_in_have: - commands.append(delete_interface) - elif state in ('present', 'up', 'down'): - if obj_in_have: - for item in params: - value = w.get(item) - - if value and value != obj_in_have.get(item): - if item == 'description': - value = "\'" + str(value) + "\'" - commands.append(set_interface + ' ' + item + ' ' + str(value)) - - if disable and not obj_in_have.get('disable', False): - commands.append(set_interface + ' disable') - elif not disable and obj_in_have.get('disable', False): - commands.append(delete_interface + ' disable') - else: - commands.append(set_interface) - for item in params: - value = w.get(item) - if value: - if item == 'description': - value = "\'" + str(value) + "\'" - commands.append(set_interface + ' ' + item + ' ' + str(value)) - - if disable: - commands.append(set_interface + ' disable') - return commands - - -def map_config_to_obj(module): - data = get_config(module, flags=['| grep interface']) - obj = [] - for line in data.split('\n'): - if line.startswith('set interfaces ethernet'): - match = re.search(r'set interfaces ethernet (\S+)', line, re.M) - name = match.group(1) - if name: - interface = {} - for item in obj: - if item['name'] == name: - interface = item - break - - if not interface: - interface = {'name': name} - obj.append(interface) - - match = re.search(r'%s (\S+)' % name, line, re.M) - if match: - param = match.group(1) - if param == 'description': - match = re.search(r'description (.+)', line, re.M) - description = match.group(1).strip("'") - interface['description'] = description - elif param == 'speed': - match = re.search(r'speed (\S+)', line, re.M) - speed = match.group(1).strip("'") - interface['speed'] = speed - elif param == 'mtu': - match = re.search(r'mtu (\S+)', line, re.M) - mtu = match.group(1).strip("'") - interface['mtu'] = int(mtu) - elif param == 'duplex': - match = re.search(r'duplex (\S+)', line, re.M) - duplex = match.group(1).strip("'") - interface['duplex'] = duplex - elif param.strip("'") == 'disable': - interface['disable'] = True - - return obj - - -def map_params_to_obj(module): - obj = [] - aggregate = module.params.get('aggregate') - if aggregate: - for item in aggregate: - for key in item: - if item.get(key) is None: - item[key] = module.params[key] - - d = item.copy() - if d['enabled']: - d['disable'] = False - else: - d['disable'] = True - - obj.append(d) - else: - params = { - 'name': module.params['name'], - 'description': module.params['description'], - 'speed': module.params['speed'], - 'mtu': module.params['mtu'], - 'duplex': module.params['duplex'], - 'delay': module.params['delay'], - 'state': module.params['state'], - 'neighbors': module.params['neighbors'] - } - - if module.params['enabled']: - params.update({'disable': False}) - else: - params.update({'disable': True}) - - obj.append(params) - return obj - - -def check_declarative_intent_params(module, want, result): - failed_conditions = [] - have_neighbors = None - for w in want: - want_state = w.get('state') - want_neighbors = w.get('neighbors') - - if want_state not in ('up', 'down') and not want_neighbors: - continue - - if result['changed']: - sleep(w['delay']) - - command = 'show interfaces ethernet %s' % w['name'] - rc, out, err = exec_command(module, command) - if rc != 0: - module.fail_json(msg=to_text(err, errors='surrogate_then_replace'), command=command, rc=rc) - - if want_state in ('up', 'down'): - match = re.search(r'%s (\w+)' % 'state', out, re.M) - have_state = None - if match: - have_state = match.group(1) - if have_state is None or not conditional(want_state, have_state.strip().lower()): - failed_conditions.append('state ' + 'eq(%s)' % want_state) - - if want_neighbors: - have_host = [] - have_port = [] - if have_neighbors is None: - rc, have_neighbors, err = exec_command(module, 'show lldp neighbors detail') - if rc != 0: - module.fail_json(msg=to_text(err, errors='surrogate_then_replace'), command=command, rc=rc) - - if have_neighbors: - lines = have_neighbors.strip().split('Interface: ') - for line in lines: - field = line.split('\n') - if field[0].split(',')[0].strip() == w['name']: - for item in field: - if item.strip().startswith('SysName:'): - have_host.append(item.split(':')[1].strip()) - if item.strip().startswith('PortDescr:'): - have_port.append(item.split(':')[1].strip()) - for item in want_neighbors: - host = item.get('host') - port = item.get('port') - if host and host not in have_host: - failed_conditions.append('host ' + host) - if port and port not in have_port: - failed_conditions.append('port ' + port) - - return failed_conditions - - -def main(): - """ main entry point for module execution - """ - neighbors_spec = dict( - host=dict(), - port=dict() - ) - - element_spec = dict( - name=dict(), - description=dict(), - speed=dict(), - mtu=dict(type='int'), - duplex=dict(choices=['full', 'half', 'auto']), - enabled=dict(default=True, type='bool'), - neighbors=dict(type='list', elements='dict', options=neighbors_spec), - delay=dict(default=10, type='int'), - state=dict(default='present', - choices=['present', 'absent', 'up', 'down']) - ) - - aggregate_spec = deepcopy(element_spec) - aggregate_spec['name'] = dict(required=True) - - # remove default in aggregate spec, to handle common arguments - remove_default_spec(aggregate_spec) - - argument_spec = dict( - aggregate=dict(type='list', elements='dict', options=aggregate_spec), - ) - - argument_spec.update(element_spec) - argument_spec.update(vyos_argument_spec) - - required_one_of = [['name', 'aggregate']] - mutually_exclusive = [['name', 'aggregate']] - - required_together = [['speed', 'duplex']] - module = AnsibleModule(argument_spec=argument_spec, - required_one_of=required_one_of, - mutually_exclusive=mutually_exclusive, - required_together=required_together, - supports_check_mode=True) - - warnings = list() - - result = {'changed': False} - - if warnings: - result['warnings'] = warnings - - want = map_params_to_obj(module) - have = map_config_to_obj(module) - - commands = map_obj_to_commands((want, have)) - result['commands'] = commands - - if commands: - commit = not module.check_mode - diff = load_config(module, commands, commit=commit) - if diff: - if module._diff: - result['diff'] = {'prepared': diff} - result['changed'] = True - - failed_conditions = check_declarative_intent_params(module, want, result) - - if failed_conditions: - msg = 'One or more conditional statements have not been satisfied' - module.fail_json(msg=msg, failed_conditions=failed_conditions) - module.exit_json(**result) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/vyos/_vyos_l3_interface.py b/lib/ansible/modules/network/vyos/_vyos_l3_interface.py deleted file mode 100644 index 95b45103a8..0000000000 --- a/lib/ansible/modules/network/vyos/_vyos_l3_interface.py +++ /dev/null @@ -1,289 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['deprecated'], - 'supported_by': 'network'} - - -DOCUMENTATION = """ ---- -module: vyos_l3_interface -version_added: "2.4" -author: "Ricardo Carrillo Cruz (@rcarrillocruz)" -short_description: Manage L3 interfaces on VyOS network devices -description: - - This module provides declarative management of L3 interfaces - on VyOS network devices. -deprecated: - removed_in: '2.13' - alternative: vyos_l3_interfaces - why: Updated modules released with more functionality. -notes: - - Tested against VYOS 1.1.7 -options: - name: - description: - - Name of the L3 interface. - ipv4: - description: - - IPv4 of the L3 interface. - ipv6: - description: - - IPv6 of the L3 interface. - aggregate: - description: List of L3 interfaces definitions - state: - description: - - State of the L3 interface configuration. - default: present - choices: ['present', 'absent'] -extends_documentation_fragment: vyos -""" - -EXAMPLES = """ -- name: Set eth0 IPv4 address - vyos_l3_interface: - name: eth0 - ipv4: 192.168.0.1/24 - -- name: Remove eth0 IPv4 address - vyos_l3_interface: - name: eth0 - state: absent - -- name: Set IP addresses on aggregate - vyos_l3_interface: - aggregate: - - { name: eth1, ipv4: 192.168.2.10/24 } - - { name: eth2, ipv4: 192.168.3.10/24, ipv6: "fd5d:12c9:2201:1::1/64" } - -- name: Remove IP addresses on aggregate - vyos_l3_interface: - aggregate: - - { name: eth1, ipv4: 192.168.2.10/24 } - - { name: eth2, ipv4: 192.168.3.10/24, ipv6: "fd5d:12c9:2201:1::1/64" } - state: absent -""" - -RETURN = """ -commands: - description: The list of configuration mode commands to send to the device - returned: always, except for the platforms that use Netconf transport to manage the device. - type: list - sample: - - set interfaces ethernet eth0 address '192.168.0.1/24' -""" - -import socket -import re - -from copy import deepcopy - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.common.utils import is_masklen, validate_ip_address -from ansible.module_utils.network.common.utils import remove_default_spec -from ansible.module_utils.network.vyos.vyos import load_config, run_commands -from ansible.module_utils.network.vyos.vyos import vyos_argument_spec - - -def is_ipv4(value): - if value: - address = value.split('/') - if is_masklen(address[1]) and validate_ip_address(address[0]): - return True - return False - - -def is_ipv6(value): - if value: - address = value.split('/') - if 0 <= int(address[1]) <= 128: - try: - socket.inet_pton(socket.AF_INET6, address[0]) - except socket.error: - return False - return True - return False - - -def search_obj_in_list(name, lst): - for o in lst: - if o['name'] == name: - return o - - return None - - -def map_obj_to_commands(updates, module): - commands = list() - want, have = updates - - for w in want: - name = w['name'] - ipv4 = w['ipv4'] - ipv6 = w['ipv6'] - state = w['state'] - - obj_in_have = search_obj_in_list(name, have) - - if state == 'absent' and obj_in_have: - if not ipv4 and not ipv6 and (obj_in_have['ipv4'] or obj_in_have['ipv6']): - if name == "lo": - commands.append('delete interfaces loopback lo address') - else: - commands.append('delete interfaces ethernet ' + name + ' address') - else: - if ipv4 and ipv4 in obj_in_have['ipv4']: - if name == "lo": - commands.append('delete interfaces loopback lo address ' + ipv4) - else: - commands.append('delete interfaces ethernet ' + name + ' address ' + ipv4) - if ipv6 and ipv6 in obj_in_have['ipv6']: - if name == "lo": - commands.append('delete interfaces loopback lo address ' + ipv6) - else: - commands.append('delete interfaces ethernet ' + name + ' address ' + ipv6) - elif (state == 'present' and obj_in_have): - if ipv4 and ipv4 not in obj_in_have['ipv4']: - if name == "lo": - commands.append('set interfaces loopback lo address ' + ipv4) - else: - commands.append('set interfaces ethernet ' + name + ' address ' + ipv4) - - if ipv6 and ipv6 not in obj_in_have['ipv6']: - if name == "lo": - commands.append('set interfaces loopback lo address ' + ipv6) - else: - commands.append('set interfaces ethernet ' + name + ' address ' + ipv6) - - return commands - - -def map_config_to_obj(module): - obj = [] - output = run_commands(module, ['show interfaces']) - lines = re.split(r'\n[e|l]', output[0])[1:] - - if len(lines) > 0: - for line in lines: - splitted_line = line.split() - - if len(splitted_line) > 0: - ipv4 = [] - ipv6 = [] - - if splitted_line[0].lower().startswith('th'): - name = 'e' + splitted_line[0].lower() - elif splitted_line[0].lower().startswith('o'): - name = 'l' + splitted_line[0].lower() - - for i in splitted_line[1:]: - if (('.' in i or ':' in i) and '/' in i): - value = i.split(r'\n')[0] - if is_ipv4(value): - ipv4.append(value) - elif is_ipv6(value): - ipv6.append(value) - - obj.append({'name': name, - 'ipv4': ipv4, - 'ipv6': ipv6}) - - return obj - - -def map_params_to_obj(module): - obj = [] - - aggregate = module.params.get('aggregate') - if aggregate: - for item in aggregate: - for key in item: - if item.get(key) is None: - item[key] = module.params[key] - - obj.append(item.copy()) - else: - obj.append({ - 'name': module.params['name'], - 'ipv4': module.params['ipv4'], - 'ipv6': module.params['ipv6'], - 'state': module.params['state'] - }) - - return obj - - -def main(): - """ main entry point for module execution - """ - element_spec = dict( - name=dict(), - ipv4=dict(), - ipv6=dict(), - state=dict(default='present', - choices=['present', 'absent']) - ) - - aggregate_spec = deepcopy(element_spec) - aggregate_spec['name'] = dict(required=True) - - # remove default in aggregate spec, to handle common arguments - remove_default_spec(aggregate_spec) - - argument_spec = dict( - aggregate=dict(type='list', elements='dict', options=aggregate_spec), - ) - - argument_spec.update(element_spec) - argument_spec.update(vyos_argument_spec) - - required_one_of = [['name', 'aggregate']] - mutually_exclusive = [['name', 'aggregate']] - module = AnsibleModule(argument_spec=argument_spec, - required_one_of=required_one_of, - mutually_exclusive=mutually_exclusive, - supports_check_mode=True) - - warnings = list() - - result = {'changed': False} - - if warnings: - result['warnings'] = warnings - - want = map_params_to_obj(module) - have = map_config_to_obj(module) - - commands = map_obj_to_commands((want, have), module) - result['commands'] = commands - - if commands: - commit = not module.check_mode - load_config(module, commands, commit=commit) - result['changed'] = True - - module.exit_json(**result) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/vyos/_vyos_linkagg.py b/lib/ansible/modules/network/vyos/_vyos_linkagg.py deleted file mode 100644 index 6beeb0fb79..0000000000 --- a/lib/ansible/modules/network/vyos/_vyos_linkagg.py +++ /dev/null @@ -1,274 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['deprecated'], - 'supported_by': 'network'} - - -DOCUMENTATION = """ ---- -module: vyos_linkagg -version_added: "2.4" -author: "Ricardo Carrillo Cruz (@rcarrillocruz)" -short_description: Manage link aggregation groups on VyOS network devices -description: - - This module provides declarative management of link aggregation groups - on VyOS network devices. -deprecated: - removed_in: '2.13' - alternative: vyos_lag_interfaces - why: Updated modules released with more functionality. -notes: - - Tested against VYOS 1.1.7 -options: - name: - description: - - Name of the link aggregation group. - required: true - type: str - mode: - description: - - Mode of the link aggregation group. - choices: ['802.3ad', 'active-backup', 'broadcast', - 'round-robin', 'transmit-load-balance', - 'adaptive-load-balance', 'xor-hash', 'on'] - type: str - members: - description: - - List of members of the link aggregation group. - type: list - aggregate: - description: List of link aggregation definitions. - type: list - state: - description: - - State of the link aggregation group. - default: present - choices: ['present', 'absent', 'up', 'down'] - type: str -extends_documentation_fragment: vyos -""" - -EXAMPLES = """ -- name: configure link aggregation group - vyos_linkagg: - name: bond0 - members: - - eth0 - - eth1 - -- name: remove configuration - vyos_linkagg: - name: bond0 - state: absent - -- name: Create aggregate of linkagg definitions - vyos_linkagg: - aggregate: - - { name: bond0, members: [eth1] } - - { name: bond1, members: [eth2] } - -- name: Remove aggregate of linkagg definitions - vyos_linkagg: - aggregate: - - name: bond0 - - name: bond1 - state: absent -""" - -RETURN = """ -commands: - description: The list of configuration mode commands to send to the device - returned: always, except for the platforms that use Netconf transport to manage the device. - type: list - sample: - - set interfaces bonding bond0 - - set interfaces ethernet eth0 bond-group 'bond0' - - set interfaces ethernet eth1 bond-group 'bond0' -""" -from copy import deepcopy - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.common.utils import remove_default_spec -from ansible.module_utils.network.vyos.vyos import load_config, run_commands -from ansible.module_utils.network.vyos.vyos import vyos_argument_spec - - -def search_obj_in_list(name, lst): - for o in lst: - if o['name'] == name: - return o - - return None - - -def map_obj_to_commands(updates, module): - commands = list() - want, have = updates - - for w in want: - name = w['name'] - members = w.get('members') or [] - mode = w['mode'] - - if mode == 'on': - mode = '802.3ad' - - state = w['state'] - - obj_in_have = search_obj_in_list(name, have) - - if state == 'absent': - if obj_in_have: - for m in obj_in_have['members']: - commands.append('delete interfaces ethernet ' + m + ' bond-group') - - commands.append('delete interfaces bonding ' + name) - else: - if not obj_in_have: - commands.append('set interfaces bonding ' + name + ' mode ' + mode) - - for m in members: - commands.append('set interfaces ethernet ' + m + ' bond-group ' + name) - - if state == 'down': - commands.append('set interfaces bonding ' + name + ' disable') - else: - if mode != obj_in_have['mode']: - commands.append('set interfaces bonding ' + name + ' mode ' + mode) - - missing_members = list(set(members) - set(obj_in_have['members'])) - for m in missing_members: - commands.append('set interfaces ethernet ' + m + ' bond-group ' + name) - - if state == 'down' and obj_in_have['state'] == 'up': - commands.append('set interfaces bonding ' + name + ' disable') - elif state == 'up' and obj_in_have['state'] == 'down': - commands.append('delete interfaces bonding ' + name + ' disable') - - return commands - - -def map_config_to_obj(module): - obj = [] - output = run_commands(module, ['show interfaces bonding slaves']) - lines = output[0].splitlines() - - if len(lines) > 1: - for line in lines[1:]: - splitted_line = line.split() - - name = splitted_line[0] - mode = splitted_line[1] - state = splitted_line[2] - - if len(splitted_line) > 4: - members = splitted_line[4:] - else: - members = [] - - obj.append({'name': name, - 'mode': mode, - 'members': members, - 'state': state}) - - return obj - - -def map_params_to_obj(module): - obj = [] - aggregate = module.params.get('aggregate') - if aggregate: - for item in aggregate: - for key in item: - if item.get(key) is None: - item[key] = module.params[key] - - obj.append(item.copy()) - else: - obj.append({ - 'name': module.params['name'], - 'mode': module.params['mode'], - 'members': module.params['members'], - 'state': module.params['state'] - }) - - return obj - - -def main(): - """ main entry point for module execution - """ - element_spec = dict( - name=dict(), - mode=dict(choices=['802.3ad', 'active-backup', 'broadcast', - 'round-robin', 'transmit-load-balance', - 'adaptive-load-balance', 'xor-hash', 'on'], - default='802.3ad'), - members=dict(type='list'), - state=dict(default='present', - choices=['present', 'absent', 'up', 'down']) - ) - - aggregate_spec = deepcopy(element_spec) - aggregate_spec['name'] = dict(required=True) - - # remove default in aggregate spec, to handle common arguments - remove_default_spec(aggregate_spec) - - argument_spec = dict( - aggregate=dict(type='list', elements='dict', options=aggregate_spec), - ) - - argument_spec.update(element_spec) - argument_spec.update(vyos_argument_spec) - - required_one_of = [['name', 'aggregate']] - mutually_exclusive = [['name', 'aggregate']] - module = AnsibleModule(argument_spec=argument_spec, - required_one_of=required_one_of, - mutually_exclusive=mutually_exclusive, - supports_check_mode=True) - - warnings = list() - - result = {'changed': False} - - if warnings: - result['warnings'] = warnings - - want = map_params_to_obj(module) - have = map_config_to_obj(module) - - commands = map_obj_to_commands((want, have), module) - result['commands'] = commands - - if commands: - commit = not module.check_mode - load_config(module, commands, commit=commit) - result['changed'] = True - - module.exit_json(**result) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/vyos/_vyos_lldp.py b/lib/ansible/modules/network/vyos/_vyos_lldp.py deleted file mode 100644 index 1636c96bb8..0000000000 --- a/lib/ansible/modules/network/vyos/_vyos_lldp.py +++ /dev/null @@ -1,134 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# - -from __future__ import absolute_import, division, print_function -__metaclass__ = type - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['deprecated'], - 'supported_by': 'network'} - - -DOCUMENTATION = """ ---- -module: vyos_lldp -version_added: "2.4" -author: "Ricardo Carrillo Cruz (@rcarrillocruz)" -short_description: Manage LLDP configuration on VyOS network devices -description: - - This module provides declarative management of LLDP service - on VyOS network devices. -deprecated: - removed_in: '2.13' - alternative: vyos_lldp_global - why: Updated modules released with more functionality. -notes: - - Tested against VYOS 1.1.7 -options: - interfaces: - description: - - Name of the interfaces. - type: list - state: - description: - - State of the link aggregation group. - default: present - choices: ['present', 'absent', 'enabled', 'disabled'] - type: str -extends_documentation_fragment: vyos -""" - -EXAMPLES = """ -- name: Enable LLDP service - vyos_lldp: - state: present - -- name: Disable LLDP service - vyos_lldp: - state: absent -""" - -RETURN = """ -commands: - description: The list of configuration mode commands to send to the device - returned: always, except for the platforms that use Netconf transport to manage the device. - type: list - sample: - - set service lldp -""" -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.vyos.vyos import get_config, load_config -from ansible.module_utils.network.vyos.vyos import vyos_argument_spec - - -def has_lldp(module): - config = get_config(module).splitlines() - - if "set service 'lldp'" in config or 'set service lldp' in config: - return True - else: - return False - - -def main(): - """ main entry point for module execution - """ - argument_spec = dict( - interfaces=dict(type='list'), - state=dict(default='present', - choices=['present', 'absent', - 'enabled', 'disabled']) - ) - - argument_spec.update(vyos_argument_spec) - - module = AnsibleModule(argument_spec=argument_spec, - supports_check_mode=True) - - warnings = list() - - result = {'changed': False} - - if warnings: - result['warnings'] = warnings - - HAS_LLDP = has_lldp(module) - - commands = [] - - if module.params['state'] == 'absent' and HAS_LLDP: - commands.append('delete service lldp') - elif module.params['state'] == 'present' and not HAS_LLDP: - commands.append('set service lldp') - - result['commands'] = commands - - if commands: - commit = not module.check_mode - load_config(module, commands, commit=commit) - result['changed'] = True - - module.exit_json(**result) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/vyos/_vyos_lldp_interface.py b/lib/ansible/modules/network/vyos/_vyos_lldp_interface.py deleted file mode 100644 index 2d08e4d6aa..0000000000 --- a/lib/ansible/modules/network/vyos/_vyos_lldp_interface.py +++ /dev/null @@ -1,238 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['deprecated'], - 'supported_by': 'network'} - - -DOCUMENTATION = """ ---- -module: vyos_lldp_interface -version_added: "2.4" -author: "Ricardo Carrillo Cruz (@rcarrillocruz)" -short_description: Manage LLDP interfaces configuration on VyOS network devices -description: - - This module provides declarative management of LLDP interfaces - configuration on VyOS network devices. -deprecated: - removed_in: '2.13' - alternative: vyos_lldp_interfaces - why: Updated modules released with more functionality. -notes: - - Tested against VYOS 1.1.7 -options: - name: - description: - - Name of the interface LLDP should be configured on. - type: str - aggregate: - description: List of interfaces LLDP should be configured on. - type: list - state: - description: - - State of the LLDP configuration. - default: present - choices: ['present', 'absent', 'enabled', 'disabled'] - type: str -extends_documentation_fragment: vyos -""" - -EXAMPLES = """ -- name: Enable LLDP on eth1 - net_lldp_interface: - state: present - -- name: Enable LLDP on specific interfaces - net_lldp_interface: - interfaces: - - eth1 - - eth2 - state: present - -- name: Disable LLDP globally - net_lldp_interface: - state: disabled - -- name: Create aggregate of LLDP interface configurations - vyos_lldp_interface: - aggregate: - - name: eth1 - - name: eth2 - state: present - -- name: Delete aggregate of LLDP interface configurations - vyos_lldp_interface: - aggregate: - - name: eth1 - - name: eth2 - state: absent -""" - -RETURN = """ -commands: - description: The list of configuration mode commands to send to the device - returned: always, except for the platforms that use Netconf transport to manage the device. - type: list - sample: - - set service lldp eth1 - - set service lldp eth2 disable -""" - - -from copy import deepcopy - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.common.utils import remove_default_spec -from ansible.module_utils.network.vyos.vyos import get_config, load_config -from ansible.module_utils.network.vyos.vyos import vyos_argument_spec - - -def search_obj_in_list(name, lst): - for o in lst: - if o['name'] == name: - return o - - return None - - -def map_obj_to_commands(updates, module): - commands = list() - want, have = updates - - for w in want: - name = w['name'] - state = w['state'] - - obj_in_have = search_obj_in_list(name, have) - - if state == 'absent' and obj_in_have: - commands.append('delete service lldp interface ' + name) - elif state in ('present', 'enabled'): - if not obj_in_have: - commands.append('set service lldp interface ' + name) - elif obj_in_have and obj_in_have['state'] == 'disabled' and state == 'enabled': - commands.append('delete service lldp interface ' + name + ' disable') - elif state == 'disabled': - if not obj_in_have: - commands.append('set service lldp interface ' + name) - commands.append('set service lldp interface ' + name + ' disable') - elif obj_in_have and obj_in_have['state'] != 'disabled': - commands.append('set service lldp interface ' + name + ' disable') - - return commands - - -def map_config_to_obj(module): - obj = [] - config = get_config(module).splitlines() - - output = [c for c in config if c.startswith("set service lldp interface")] - - for i in output: - splitted_line = i.split() - - if len(splitted_line) > 5: - new_obj = {'name': splitted_line[4]} - - if splitted_line[5] == "'disable'": - new_obj['state'] = 'disabled' - else: - new_obj = {'name': splitted_line[4][1:-1]} - new_obj['state'] = 'present' - - obj.append(new_obj) - - return obj - - -def map_params_to_obj(module): - obj = [] - - aggregate = module.params.get('aggregate') - if aggregate: - for item in aggregate: - for key in item: - if item.get(key) is None: - item[key] = module.params[key] - - obj.append(item.copy()) - else: - obj.append({'name': module.params['name'], 'state': module.params['state']}) - - return obj - - -def main(): - """ main entry point for module execution - """ - element_spec = dict( - name=dict(), - state=dict(default='present', - choices=['present', 'absent', - 'enabled', 'disabled']) - ) - - aggregate_spec = deepcopy(element_spec) - aggregate_spec['name'] = dict(required=True) - - # remove default in aggregate spec, to handle common arguments - remove_default_spec(aggregate_spec) - - argument_spec = dict( - aggregate=dict(type='list', elements='dict', options=aggregate_spec), - ) - - argument_spec.update(element_spec) - argument_spec.update(vyos_argument_spec) - - required_one_of = [['name', 'aggregate']] - mutually_exclusive = [['name', 'aggregate']] - - module = AnsibleModule(argument_spec=argument_spec, - required_one_of=required_one_of, - mutually_exclusive=mutually_exclusive, - supports_check_mode=True) - - warnings = list() - - result = {'changed': False} - - if warnings: - result['warnings'] = warnings - - want = map_params_to_obj(module) - have = map_config_to_obj(module) - - commands = map_obj_to_commands((want, have), module) - result['commands'] = commands - - if commands: - commit = not module.check_mode - load_config(module, commands, commit=commit) - result['changed'] = True - - module.exit_json(**result) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/vyos/_vyos_static_route.py b/lib/ansible/modules/network/vyos/_vyos_static_route.py deleted file mode 100644 index d3a0f057c5..0000000000 --- a/lib/ansible/modules/network/vyos/_vyos_static_route.py +++ /dev/null @@ -1,276 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['deprecated'], - 'supported_by': 'network'} - - -DOCUMENTATION = """ ---- -module: vyos_static_route -version_added: "2.4" -author: "Trishna Guha (@trishnaguha)" -short_description: Manage static IP routes on Vyatta VyOS network devices -description: - - This module provides declarative management of static - IP routes on Vyatta VyOS network devices. -deprecated: - removed_in: '2.13' - alternative: vyos_static_routes - why: Updated modules released with more functionality. -notes: - - Tested against VyOS 1.1.8 (helium). - - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). -options: - prefix: - description: - - Network prefix of the static route. - C(mask) param should be ignored if C(prefix) is provided - with C(mask) value C(prefix/mask). - type: str - mask: - description: - - Network prefix mask of the static route. - type: str - next_hop: - description: - - Next hop IP of the static route. - type: str - admin_distance: - description: - - Admin distance of the static route. - type: int - aggregate: - description: List of static route definitions - type: list - state: - description: - - State of the static route configuration. - default: present - choices: ['present', 'absent'] - type: str -extends_documentation_fragment: vyos -""" - -EXAMPLES = """ -- name: configure static route - vyos_static_route: - prefix: 192.168.2.0 - mask: 24 - next_hop: 10.0.0.1 - -- name: configure static route prefix/mask - vyos_static_route: - prefix: 192.168.2.0/16 - next_hop: 10.0.0.1 - -- name: remove configuration - vyos_static_route: - prefix: 192.168.2.0 - mask: 16 - next_hop: 10.0.0.1 - state: absent - -- name: configure aggregates of static routes - vyos_static_route: - aggregate: - - { prefix: 192.168.2.0, mask: 24, next_hop: 10.0.0.1 } - - { prefix: 192.168.3.0, mask: 16, next_hop: 10.0.2.1 } - - { prefix: 192.168.3.0/16, next_hop: 10.0.2.1 } - -- name: Remove static route collections - vyos_static_route: - aggregate: - - { prefix: 172.24.1.0/24, next_hop: 192.168.42.64 } - - { prefix: 172.24.3.0/24, next_hop: 192.168.42.64 } - state: absent -""" - -RETURN = """ -commands: - description: The list of configuration mode commands to send to the device - returned: always - type: list - sample: - - set protocols static route 192.168.2.0/16 next-hop 10.0.0.1 -""" -import re - -from copy import deepcopy - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.common.utils import remove_default_spec -from ansible.module_utils.network.vyos.vyos import get_config, load_config -from ansible.module_utils.network.vyos.vyos import vyos_argument_spec - - -def spec_to_commands(updates, module): - commands = list() - want, have = updates - for w in want: - prefix = w['prefix'] - mask = w['mask'] - next_hop = w['next_hop'] - admin_distance = w['admin_distance'] - state = w['state'] - del w['state'] - - if state == 'absent' and w in have: - commands.append('delete protocols static route %s/%s' % (prefix, mask)) - elif state == 'present' and w not in have: - cmd = 'set protocols static route %s/%s next-hop %s' % (prefix, mask, next_hop) - if admin_distance != 'None': - cmd += ' distance %s' % (admin_distance) - commands.append(cmd) - - return commands - - -def config_to_dict(module): - data = get_config(module) - obj = [] - - for line in data.split('\n'): - if line.startswith('set protocols static route'): - match = re.search(r'static route (\S+)', line, re.M) - prefix = match.group(1).split('/')[0] - mask = match.group(1).split('/')[1] - if 'next-hop' in line: - match_hop = re.search(r'next-hop (\S+)', line, re.M) - next_hop = match_hop.group(1).strip("'") - - match_distance = re.search(r'distance (\S+)', line, re.M) - if match_distance is not None: - admin_distance = match_distance.group(1)[1:-1] - else: - admin_distance = None - - if admin_distance is not None: - obj.append({'prefix': prefix, - 'mask': mask, - 'next_hop': next_hop, - 'admin_distance': admin_distance}) - else: - obj.append({'prefix': prefix, - 'mask': mask, - 'next_hop': next_hop, - 'admin_distance': 'None'}) - - return obj - - -def map_params_to_obj(module, required_together=None): - obj = [] - aggregate = module.params.get('aggregate') - if aggregate: - for item in aggregate: - for key in item: - if item.get(key) is None: - item[key] = module.params[key] - - module._check_required_together(required_together, item) - d = item.copy() - if '/' in d['prefix']: - d['mask'] = d['prefix'].split('/')[1] - d['prefix'] = d['prefix'].split('/')[0] - - if 'admin_distance' in d: - d['admin_distance'] = str(d['admin_distance']) - - obj.append(d) - else: - prefix = module.params['prefix'].strip() - if '/' in prefix: - mask = prefix.split('/')[1] - prefix = prefix.split('/')[0] - else: - mask = module.params['mask'].strip() - next_hop = module.params['next_hop'].strip() - admin_distance = str(module.params['admin_distance']) - state = module.params['state'] - - obj.append({ - 'prefix': prefix, - 'mask': mask, - 'next_hop': next_hop, - 'admin_distance': admin_distance, - 'state': state - }) - - return obj - - -def main(): - """ main entry point for module execution - """ - element_spec = dict( - prefix=dict(type='str'), - mask=dict(type='str'), - next_hop=dict(type='str'), - admin_distance=dict(type='int'), - state=dict(default='present', choices=['present', 'absent']) - ) - - aggregate_spec = deepcopy(element_spec) - aggregate_spec['prefix'] = dict(required=True) - - # remove default in aggregate spec, to handle common arguments - remove_default_spec(aggregate_spec) - - argument_spec = dict( - aggregate=dict(type='list', elements='dict', options=aggregate_spec), - ) - - argument_spec.update(element_spec) - argument_spec.update(vyos_argument_spec) - - required_one_of = [['aggregate', 'prefix']] - required_together = [['prefix', 'next_hop']] - mutually_exclusive = [['aggregate', 'prefix']] - - module = AnsibleModule(argument_spec=argument_spec, - required_one_of=required_one_of, - required_together=required_together, - mutually_exclusive=mutually_exclusive, - supports_check_mode=True) - - warnings = list() - - result = {'changed': False} - if warnings: - result['warnings'] = warnings - want = map_params_to_obj(module, required_together=required_together) - have = config_to_dict(module) - - commands = spec_to_commands((want, have), module) - result['commands'] = commands - - if commands: - commit = not module.check_mode - load_config(module, commands, commit=commit) - result['changed'] = True - - module.exit_json(**result) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/vyos/vyos_banner.py b/lib/ansible/modules/network/vyos/vyos_banner.py deleted file mode 100644 index 6abd797fb1..0000000000 --- a/lib/ansible/modules/network/vyos/vyos_banner.py +++ /dev/null @@ -1,179 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'network'} - -DOCUMENTATION = """ ---- -module: vyos_banner -version_added: "2.4" -author: "Trishna Guha (@trishnaguha)" -short_description: Manage multiline banners on VyOS devices -description: - - This will configure both pre-login and post-login banners on remote - devices running VyOS. It allows playbooks to add or remote - banner text from the active running configuration. -notes: - - Tested against VyOS 1.1.8 (helium). - - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). -options: - banner: - description: - - Specifies which banner that should be - configured on the remote device. - required: true - choices: ['pre-login', 'post-login'] - text: - description: - - The banner text that should be - present in the remote device running configuration. This argument - accepts a multiline string, with no empty lines. Requires I(state=present). - state: - description: - - Specifies whether or not the configuration is present in the current - devices active running configuration. - default: present - choices: ['present', 'absent'] -extends_documentation_fragment: vyos -""" - -EXAMPLES = """ -- name: configure the pre-login banner - vyos_banner: - banner: pre-login - text: | - this is my pre-login banner - that contains a multiline - string - state: present -- name: remove the post-login banner - vyos_banner: - banner: post-login - state: absent -""" - -RETURN = """ -commands: - description: The list of configuration mode commands to send to the device - returned: always - type: list - sample: - - banner pre-login - - this is my pre-login banner - - that contains a multiline - - string -""" - -import re - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.vyos.vyos import get_config, load_config -from ansible.module_utils.network.vyos.vyos import vyos_argument_spec - - -def spec_to_commands(updates, module): - commands = list() - want, have = updates - state = module.params['state'] - - if state == 'absent': - if have.get('state') != 'absent' or (have.get('state') != 'absent' and - 'text' in have.keys() and have['text']): - commands.append('delete system login banner %s' % module.params['banner']) - - elif state == 'present': - if want['text'] and want['text'].encode().decode('unicode_escape') != have.get('text'): - banner_cmd = 'set system login banner %s ' % module.params['banner'] - banner_cmd += want['text'].strip() - commands.append(banner_cmd) - - return commands - - -def config_to_dict(module): - data = get_config(module) - output = None - obj = {'banner': module.params['banner'], 'state': 'absent'} - - for line in data.split('\n'): - if line.startswith('set system login banner %s' % obj['banner']): - match = re.findall(r'%s (.*)' % obj['banner'], line, re.M) - output = match - if output: - obj['text'] = output[0].encode().decode('unicode_escape') - obj['state'] = 'present' - - return obj - - -def map_params_to_obj(module): - text = module.params['text'] - if text: - text = "%r" % (str(text).strip()) - - return { - 'banner': module.params['banner'], - 'text': text, - 'state': module.params['state'] - } - - -def main(): - """ main entry point for module execution - """ - argument_spec = dict( - banner=dict(required=True, choices=['pre-login', 'post-login']), - text=dict(), - state=dict(default='present', choices=['present', 'absent']) - ) - - argument_spec.update(vyos_argument_spec) - - required_if = [('state', 'present', ('text',))] - - module = AnsibleModule(argument_spec=argument_spec, - required_if=required_if, - supports_check_mode=True) - - warnings = list() - - result = {'changed': False} - if warnings: - result['warnings'] = warnings - - want = map_params_to_obj(module) - have = config_to_dict(module) - - commands = spec_to_commands((want, have), module) - result['commands'] = commands - - if commands: - commit = not module.check_mode - load_config(module, commands, commit=commit) - result['changed'] = True - - module.exit_json(**result) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/vyos/vyos_command.py b/lib/ansible/modules/network/vyos/vyos_command.py deleted file mode 100644 index d53e401bd0..0000000000 --- a/lib/ansible/modules/network/vyos/vyos_command.py +++ /dev/null @@ -1,223 +0,0 @@ -#!/usr/bin/python -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'network'} - - -DOCUMENTATION = """ ---- -module: vyos_command -version_added: "2.2" -author: "Nathaniel Case (@Qalthos)" -short_description: Run one or more commands on VyOS devices -description: - - The command module allows running one or more commands on remote - devices running VyOS. This module can also be introspected - to validate key parameters before returning successfully. If the - conditional statements are not met in the wait period, the task - fails. - - Certain C(show) commands in VyOS produce many lines of output and - use a custom pager that can cause this module to hang. If the - value of the environment variable C(ANSIBLE_VYOS_TERMINAL_LENGTH) - is not set, the default number of 10000 is used. -extends_documentation_fragment: vyos -options: - commands: - description: - - The ordered set of commands to execute on the remote device - running VyOS. The output from the command execution is - returned to the playbook. If the I(wait_for) argument is - provided, the module is not returned until the condition is - satisfied or the number of retries has been exceeded. - required: true - wait_for: - description: - - Specifies what to evaluate from the output of the command - and what conditionals to apply. This argument will cause - the task to wait for a particular conditional to be true - before moving forward. If the conditional is not true - by the configured I(retries), the task fails. See examples. - aliases: ['waitfor'] - match: - description: - - The I(match) argument is used in conjunction with the - I(wait_for) argument to specify the match policy. Valid - values are C(all) or C(any). If the value is set to C(all) - then all conditionals in the wait_for must be satisfied. If - the value is set to C(any) then only one of the values must be - satisfied. - default: all - choices: ['any', 'all'] - retries: - description: - - Specifies the number of retries a command should be tried - before it is considered failed. The command is run on the - target device every retry and evaluated against the I(wait_for) - conditionals. - default: 10 - interval: - description: - - Configures the interval in seconds to wait between I(retries) - of the command. If the command does not pass the specified - conditions, the interval indicates how long to wait before - trying the command again. - default: 1 - -notes: - - Tested against VyOS 1.1.8 (helium). - - Running C(show system boot-messages all) will cause the module to hang since - VyOS is using a custom pager setting to display the output of that command. - - If a command sent to the device requires answering a prompt, it is possible - to pass a dict containing I(command), I(answer) and I(prompt). See examples. - - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). -""" - -EXAMPLES = """ -tasks: - - name: show configuration on ethernet devices eth0 and eth1 - vyos_command: - commands: - - show interfaces ethernet {{ item }} - with_items: - - eth0 - - eth1 - - - name: run multiple commands and check if version output contains specific version string - vyos_command: - commands: - - show version - - show hardware cpu - wait_for: - - "result[0] contains 'VyOS 1.1.7'" - - - name: run command that requires answering a prompt - vyos_command: - commands: - - command: 'rollback 1' - prompt: 'Proceed with reboot? [confirm][y]' - answer: y -""" - -RETURN = """ -stdout: - description: The set of responses from the commands - returned: always apart from low level errors (such as action plugin) - type: list - sample: ['...', '...'] -stdout_lines: - description: The value of stdout split into a list - returned: always - type: list - sample: [['...', '...'], ['...'], ['...']] -failed_conditions: - description: The list of conditionals that have failed - returned: failed - type: list - sample: ['...', '...'] -warnings: - description: The list of warnings (if any) generated by module based on arguments - returned: always - type: list - sample: ['...', '...'] -""" -import time - -from ansible.module_utils._text import to_text -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.common.parsing import Conditional -from ansible.module_utils.network.common.utils import transform_commands, to_lines -from ansible.module_utils.network.vyos.vyos import run_commands -from ansible.module_utils.network.vyos.vyos import vyos_argument_spec - - -def parse_commands(module, warnings): - commands = transform_commands(module) - - if module.check_mode: - for item in list(commands): - if not item['command'].startswith('show'): - warnings.append( - 'Only show commands are supported when using check mode, not ' - 'executing %s' % item['command'] - ) - commands.remove(item) - - return commands - - -def main(): - spec = dict( - commands=dict(type='list', required=True), - - wait_for=dict(type='list', aliases=['waitfor']), - match=dict(default='all', choices=['all', 'any']), - - retries=dict(default=10, type='int'), - interval=dict(default=1, type='int') - ) - - spec.update(vyos_argument_spec) - - module = AnsibleModule(argument_spec=spec, supports_check_mode=True) - - warnings = list() - result = {'changed': False, 'warnings': warnings} - commands = parse_commands(module, warnings) - wait_for = module.params['wait_for'] or list() - - try: - conditionals = [Conditional(c) for c in wait_for] - except AttributeError as exc: - module.fail_json(msg=to_text(exc)) - - retries = module.params['retries'] - interval = module.params['interval'] - match = module.params['match'] - - for _ in range(retries): - responses = run_commands(module, commands) - - for item in list(conditionals): - if item(responses): - if match == 'any': - conditionals = list() - break - conditionals.remove(item) - - if not conditionals: - break - - time.sleep(interval) - - if conditionals: - failed_conditions = [item.raw for item in conditionals] - msg = 'One or more conditional statements have not been satisfied' - module.fail_json(msg=msg, failed_conditions=failed_conditions) - - result.update({ - 'stdout': responses, - 'stdout_lines': list(to_lines(responses)), - }) - - module.exit_json(**result) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/vyos/vyos_config.py b/lib/ansible/modules/network/vyos/vyos_config.py deleted file mode 100644 index f62e019f63..0000000000 --- a/lib/ansible/modules/network/vyos/vyos_config.py +++ /dev/null @@ -1,349 +0,0 @@ -#!/usr/bin/python -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'network'} - - -DOCUMENTATION = """ ---- -module: vyos_config -version_added: "2.2" -author: "Nathaniel Case (@Qalthos)" -short_description: Manage VyOS configuration on remote device -description: - - This module provides configuration file management of VyOS - devices. It provides arguments for managing both the - configuration file and state of the active configuration. All - configuration statements are based on `set` and `delete` commands - in the device configuration. -extends_documentation_fragment: vyos -notes: - - Tested against VyOS 1.1.8 (helium). - - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). -options: - lines: - description: - - The ordered set of configuration lines to be managed and - compared with the existing configuration on the remote - device. - src: - description: - - The C(src) argument specifies the path to the source config - file to load. The source config file can either be in - bracket format or set format. The source file can include - Jinja2 template variables. - match: - description: - - The C(match) argument controls the method used to match - against the current active configuration. By default, the - desired config is matched against the active config and the - deltas are loaded. If the C(match) argument is set to C(none) - the active configuration is ignored and the configuration is - always loaded. - default: line - choices: ['line', 'none'] - backup: - description: - - The C(backup) argument will backup the current devices active - configuration to the Ansible control host prior to making any - changes. If the C(backup_options) value is not given, the - backup file will be located in the backup folder in the playbook - root directory or role root directory, if playbook is part of an - ansible role. If the directory does not exist, it is created. - type: bool - default: 'no' - comment: - description: - - Allows a commit description to be specified to be included - when the configuration is committed. If the configuration is - not changed or committed, this argument is ignored. - default: 'configured by vyos_config' - config: - description: - - The C(config) argument specifies the base configuration to use - to compare against the desired configuration. If this value - is not specified, the module will automatically retrieve the - current active configuration from the remote device. - save: - description: - - The C(save) argument controls whether or not changes made - to the active configuration are saved to disk. This is - independent of committing the config. When set to True, the - active configuration is saved. - type: bool - default: 'no' - backup_options: - description: - - This is a dict object containing configurable options related to backup file path. - The value of this option is read only when C(backup) is set to I(yes), if C(backup) is set - to I(no) this option will be silently ignored. - suboptions: - filename: - description: - - The filename to be used to store the backup configuration. If the filename - is not given it will be generated based on the hostname, current time and date - in format defined by <hostname>_config.<current-date>@<current-time> - dir_path: - description: - - This option provides the path ending with directory name in which the backup - configuration file will be stored. If the directory does not exist it will be first - created and the filename is either the value of C(filename) or default filename - as described in C(filename) options description. If the path value is not given - in that case a I(backup) directory will be created in the current working directory - and backup configuration will be copied in C(filename) within I(backup) directory. - type: path - type: dict - version_added: "2.8" -""" - -EXAMPLES = """ -- name: configure the remote device - vyos_config: - lines: - - set system host-name {{ inventory_hostname }} - - set service lldp - - delete service dhcp-server - -- name: backup and load from file - vyos_config: - src: vyos.cfg - backup: yes - -- name: render a Jinja2 template onto the VyOS router - vyos_config: - src: vyos_template.j2 - -- name: for idempotency, use full-form commands - vyos_config: - lines: - # - set int eth eth2 description 'OUTSIDE' - - set interface ethernet eth2 description 'OUTSIDE' - -- name: configurable backup path - vyos_config: - backup: yes - backup_options: - filename: backup.cfg - dir_path: /home/user -""" - -RETURN = """ -commands: - description: The list of configuration commands sent to the device - returned: always - type: list - sample: ['...', '...'] -filtered: - description: The list of configuration commands removed to avoid a load failure - returned: always - type: list - sample: ['...', '...'] -backup_path: - description: The full path to the backup file - returned: when backup is yes - type: str - sample: /playbooks/ansible/backup/vyos_config.2016-07-16@22:28:34 -filename: - description: The name of the backup file - returned: when backup is yes and filename is not specified in backup options - type: str - sample: vyos_config.2016-07-16@22:28:34 -shortname: - description: The full path to the backup file excluding the timestamp - returned: when backup is yes and filename is not specified in backup options - type: str - sample: /playbooks/ansible/backup/vyos_config -date: - description: The date extracted from the backup file name - returned: when backup is yes - type: str - sample: "2016-07-16" -time: - description: The time extracted from the backup file name - returned: when backup is yes - type: str - sample: "22:28:34" -""" -import re - -from ansible.module_utils._text import to_text -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.connection import ConnectionError -from ansible.module_utils.network.vyos.vyos import load_config, get_config, run_commands -from ansible.module_utils.network.vyos.vyos import vyos_argument_spec, get_connection - - -DEFAULT_COMMENT = 'configured by vyos_config' - -CONFIG_FILTERS = [ - re.compile(r'set system login user \S+ authentication encrypted-password') -] - - -def get_candidate(module): - contents = module.params['src'] or module.params['lines'] - - if module.params['src']: - contents = format_commands(contents.splitlines()) - - contents = '\n'.join(contents) - return contents - - -def format_commands(commands): - """ - This function format the input commands and removes the prepend white spaces - for command lines having 'set' or 'delete' and it skips empty lines. - :param commands: - :return: list of commands - """ - return [line.strip() if line.split()[0] in ('set', 'delete') else line for line in commands if len(line.strip()) > 0] - - -def diff_config(commands, config): - config = [str(c).replace("'", '') for c in config.splitlines()] - - updates = list() - visited = set() - - for line in commands: - item = str(line).replace("'", '') - - if not item.startswith('set') and not item.startswith('delete'): - raise ValueError('line must start with either `set` or `delete`') - - elif item.startswith('set') and item not in config: - updates.append(line) - - elif item.startswith('delete'): - if not config: - updates.append(line) - else: - item = re.sub(r'delete', 'set', item) - for entry in config: - if entry.startswith(item) and line not in visited: - updates.append(line) - visited.add(line) - - return list(updates) - - -def sanitize_config(config, result): - result['filtered'] = list() - index_to_filter = list() - for regex in CONFIG_FILTERS: - for index, line in enumerate(list(config)): - if regex.search(line): - result['filtered'].append(line) - index_to_filter.append(index) - # Delete all filtered configs - for filter_index in sorted(index_to_filter, reverse=True): - del config[filter_index] - - -def run(module, result): - # get the current active config from the node or passed in via - # the config param - config = module.params['config'] or get_config(module) - - # create the candidate config object from the arguments - candidate = get_candidate(module) - - # create loadable config that includes only the configuration updates - connection = get_connection(module) - try: - response = connection.get_diff(candidate=candidate, running=config, diff_match=module.params['match']) - except ConnectionError as exc: - module.fail_json(msg=to_text(exc, errors='surrogate_then_replace')) - - commands = response.get('config_diff') - sanitize_config(commands, result) - - result['commands'] = commands - - commit = not module.check_mode - comment = module.params['comment'] - - diff = None - if commands: - diff = load_config(module, commands, commit=commit, comment=comment) - - if result.get('filtered'): - result['warnings'].append('Some configuration commands were ' - 'removed, please see the filtered key') - - result['changed'] = True - - if module._diff: - result['diff'] = {'prepared': diff} - - -def main(): - backup_spec = dict( - filename=dict(), - dir_path=dict(type='path') - ) - argument_spec = dict( - src=dict(type='path'), - lines=dict(type='list'), - - match=dict(default='line', choices=['line', 'none']), - - comment=dict(default=DEFAULT_COMMENT), - - config=dict(), - - backup=dict(type='bool', default=False), - backup_options=dict(type='dict', options=backup_spec), - save=dict(type='bool', default=False), - ) - - argument_spec.update(vyos_argument_spec) - - mutually_exclusive = [('lines', 'src')] - - module = AnsibleModule( - argument_spec=argument_spec, - mutually_exclusive=mutually_exclusive, - supports_check_mode=True - ) - - warnings = list() - - result = dict(changed=False, warnings=warnings) - - if module.params['backup']: - result['__backup__'] = get_config(module=module) - - if any((module.params['src'], module.params['lines'])): - run(module, result) - - if module.params['save']: - diff = run_commands(module, commands=['configure', 'compare saved'])[1] - if diff != '[edit]': - run_commands(module, commands=['save']) - result['changed'] = True - run_commands(module, commands=['exit']) - - module.exit_json(**result) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/vyos/vyos_facts.py b/lib/ansible/modules/network/vyos/vyos_facts.py deleted file mode 100644 index 944382526c..0000000000 --- a/lib/ansible/modules/network/vyos/vyos_facts.py +++ /dev/null @@ -1,171 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -""" -The module file for vyos_facts -""" - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': [u'preview'], - 'supported_by': 'network'} - - -DOCUMENTATION = """ ---- -module: vyos_facts -version_added: 2.2 -short_description: Get facts about vyos devices. -description: - - Collects facts from network devices running the vyos operating - system. This module places the facts gathered in the fact tree keyed by the - respective resource name. The facts module will always collect a - base set of facts from the device and can enable or disable - collection of additional facts. -author: - - Nathaniel Case (@qalthos) - - Nilashish Chakraborty (@Nilashishc) - - Rohit Thakur (@rohitthakur2590) -extends_documentation_fragment: vyos -notes: - - Tested against VyOS 1.1.8 (helium). - - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). -options: - gather_subset: - description: - - When supplied, this argument will restrict the facts collected - to a given subset. Possible values for this argument include - all, default, config, and neighbors. Can specify a list of - values to include a larger subset. Values can also be used - with an initial C(M(!)) to specify that a specific subset should - not be collected. - required: false - default: "!config" - gather_network_resources: - description: - - When supplied, this argument will restrict the facts collected - to a given subset. Possible values for this argument include - all and the resources like interfaces. - Can specify a list of values to include a larger subset. Values - can also be used with an initial C(M(!)) to specify that a - specific subset should not be collected. - Valid subsets are 'all', 'interfaces', 'l3_interfaces', 'lag_interfaces', - 'lldp_global', 'lldp_interfaces', 'static_routes', 'firewall_rules', 'firewall_global', 'firewall_interfaces'. - required: false - version_added: "2.9" -""" - -EXAMPLES = """ -# Gather all facts -- vyos_facts: - gather_subset: all - gather_network_resources: all - -# collect only the config and default facts -- vyos_facts: - gather_subset: config - -# collect everything exception the config -- vyos_facts: - gather_subset: "!config" - -# Collect only the interfaces facts -- vyos_facts: - gather_subset: - - '!all' - - '!min' - gather_network_resources: - - interfaces - -# Do not collect interfaces facts -- vyos_facts: - gather_network_resources: - - "!interfaces" - -# Collect interfaces and minimal default facts -- vyos_facts: - gather_subset: min - gather_network_resources: interfaces -""" - -RETURN = """ -ansible_net_config: - description: The running-config from the device - returned: when config is configured - type: str -ansible_net_commits: - description: The set of available configuration revisions - returned: when present - type: list -ansible_net_hostname: - description: The configured system hostname - returned: always - type: str -ansible_net_model: - description: The device model string - returned: always - type: str -ansible_net_serialnum: - description: The serial number of the device - returned: always - type: str -ansible_net_version: - description: The version of the software running - returned: always - type: str -ansible_net_neighbors: - description: The set of LLDP neighbors - returned: when interface is configured - type: list -ansible_net_gather_subset: - description: The list of subsets gathered by the module - returned: always - type: list -ansible_net_api: - description: The name of the transport - returned: always - type: str -ansible_net_python_version: - description: The Python version Ansible controller is using - returned: always - type: str -ansible_net_gather_network_resources: - description: The list of fact resource subsets collected from the device - returned: always - type: list -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.vyos.argspec.facts.facts import FactsArgs -from ansible.module_utils.network.vyos.facts.facts import Facts -from ansible.module_utils.network.vyos.vyos import vyos_argument_spec - - -def main(): - """ - Main entry point for module execution - - :returns: ansible_facts - """ - argument_spec = FactsArgs.argument_spec - argument_spec.update(vyos_argument_spec) - - module = AnsibleModule(argument_spec=argument_spec, - supports_check_mode=True) - - warnings = [] - if module.params["gather_subset"] == "!config": - warnings.append('default value for `gather_subset` will be changed to `min` from `!config` v2.11 onwards') - - result = Facts(module).get_facts() - - ansible_facts, additional_warnings = result - warnings.extend(additional_warnings) - - module.exit_json(ansible_facts=ansible_facts, warnings=warnings) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/vyos/vyos_firewall_global.py b/lib/ansible/modules/network/vyos/vyos_firewall_global.py deleted file mode 100644 index 96267a6fa2..0000000000 --- a/lib/ansible/modules/network/vyos/vyos_firewall_global.py +++ /dev/null @@ -1,1185 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -############################################# -# WARNING # -############################################# -# -# This file is auto generated by the resource -# module builder playbook. -# -# Do not edit this file manually. -# -# Changes to this file will be over written -# by the resource module builder. -# -# Changes should be made in the model used to -# generate this file or in the resource module -# builder template. -# -############################################# - -""" -The module file for vyos_firewall_global -""" - -from __future__ import absolute_import, division, print_function -__metaclass__ = type - -ANSIBLE_METADATA = { - 'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'network' -} - -DOCUMENTATION = """ ---- -module: vyos_firewall_global -version_added: '2.10' -short_description: Manage global policies or configurations for firewall on VyOS devices. -description: This module manage global policies or configurations for firewall on VyOS devices. -notes: - - Tested against VyOS 1.1.8 (helium). - - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). -author: - - Rohit Thakur (@rohitthakur2590) -options: - config: - description: - - A dictionary of Firewall global configuration options. - type: dict - suboptions: - route_redirects: - description: - -A dictionary of Firewall icmp redirect and source route global configuration options. - type: list - elements: dict - suboptions: - afi: - description: - - Specifies IP address type - type: str - choices: ['ipv4', 'ipv6'] - required: True - icmp_redirects: - description: - - Specifies whether to allow sending/receiving of IPv4/v6 ICMP redirect messages. - type: dict - suboptions: - send: - description: - - Permits or denies transmitting packets ICMP redirect messages. - type: bool - receive: - description: - - Permits or denies receiving packets ICMP redirect messages. - type: bool - ip_src_route: - description: - - Specifies whether or not to process source route IP options. - type: bool - ping: - description: - - Policy for handling of all IPv4 ICMP echo requests. - type: dict - suboptions: - all: - description: - - Enables or disables response to all IPv4 ICMP Echo Request (ping) messages. - - The system responds to IPv4 ICMP Echo Request messages. - type: bool - broadcast: - description: - - Enables or disables response to broadcast IPv4 ICMP Echo Request and Timestamp Request messages. - - IPv4 ICMP Echo and Timestamp Request messages are not processed. - type: bool - config_trap: - description: - - SNMP trap generation on firewall configuration changes. - type: bool - validation: - description: - - Specifies a policy for source validation by reversed path, as defined in RFC 3704. - - (disable) No source validation is performed. - - (loose) Enable Loose Reverse Path Forwarding as defined in RFC3704. - - (strict) Enable Strict Reverse Path Forwarding as defined in RFC3704. - type: str - choices: ['strict', 'loose', 'disable'] - group: - description: - - Defines a group of objects for referencing in firewall rules. - type: dict - suboptions: - address_group: - description: - - Defines a group of IP addresses for referencing in firewall rules. - type: list - elements: dict - suboptions: - name: - description: - - Name of the firewall address group. - type: str - required: True - description: - description: - - Allows you to specify a brief description for the address group. - type: str - members: - description: - - Address-group members. - - IPv4 address to match. - - IPv4 range to match. - type: list - elements: dict - suboptions: - address: - description: IP address. - type: str - network_group: - description: - - Defines a group of networks for referencing in firewall rules. - type: list - elements: dict - suboptions: - name: - description: - - Name of the firewall network group. - type: str - required: True - description: - description: - - Allows you to specify a brief description for the network group. - type: str - members: - description: - - Adds an IPv4 network to the specified network group. - - The format is ip-address/prefix. - type: list - elements: dict - suboptions: - address: - description: IP address. - type: str - port_group: - description: - - Defines a group of ports for referencing in firewall rules. - type: list - elements: dict - suboptions: - name: - description: - - Name of the firewall port group. - type: str - required: True - description: - description: - - Allows you to specify a brief description for the port group. - type: str - members: - description: - - Port-group member. - type: list - elements: dict - suboptions: - port: - description: Defines the number. - type: str - - log_martians: - description: - - Specifies whether or not to record packets with invalid addresses in the log. - - (True) Logs packets with invalid addresses. - - (False) Does not log packets with invalid addresses. - type: bool - syn_cookies: - description: - - Specifies policy for using TCP SYN cookies with IPv4. - - (True) Enables TCP SYN cookies with IPv4. - - (False) Disables TCP SYN cookies with IPv4. - type: bool - twa_hazards_protection: - description: - - RFC1337 TCP TIME-WAIT assasination hazards protection. - type: bool - state_policy: - description: - - Specifies global firewall state-policy. - type: list - elements: dict - suboptions: - connection_type: - description: Specifies connection type. - type: str - choices: ['established', 'invalid', 'related'] - action: - description: - - Action for packets part of an established connection. - type: str - choices: ['accept', 'drop', 'reject'] - log: - description: - - Enable logging of packets part of an established connection. - type: bool - running_config: - description: - - The module, by default, will connect to the remote device and - retrieve the current running-config to use as a base for comparing - against the contents of source. There are times when it is not - desirable to have the task get the current running-config for - every task in a playbook. The I(running_config) argument allows the - implementer to pass in the configuration to use as the base - config for comparison. This value of this option should be the - output received from device by executing command - C(show configuration commands | grep 'firewall') - type: str - state: - description: - - The state the configuration should be left in. - type: str - choices: - - merged - - replaced - - deleted - - gathered - - rendered - - parsed - default: merged -""" -EXAMPLES = """ -# Using merged -# -# Before state: -# ------------- -# -# vyos@vyos# run show configuration commands | grep firewall -# -# -- name: Merge the provided configuration with the exisiting running configuration - vyos_firewall_global: - config: - validation: strict - config_trap: True - log_martians: True - syn_cookies: True - twa_hazards_protection: True - ping: - all: True - broadcast: True - state_policy: - - connection_type: 'established' - action: 'accept' - log: True - - connection_type: 'invalid' - action: 'reject' - route_redirects: - - afi: 'ipv4' - ip_src_route: True - icmp_redirects: - send: True - receive: False - group: - address_group: - - name: 'MGMT-HOSTS' - description: 'This group has the Management hosts address list' - members: - - address: 192.0.1.1 - - address: 192.0.1.3 - - address: 192.0.1.5 - network_group: - - name: 'MGMT' - description: 'This group has the Management network addresses' - members: - - address: 192.0.1.0/24 - state: merged -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# before": [] -# -# "commands": [ -# "set firewall group address-group MGMT-HOSTS address 192.0.1.1", -# "set firewall group address-group MGMT-HOSTS address 192.0.1.3", -# "set firewall group address-group MGMT-HOSTS address 192.0.1.5", -# "set firewall group address-group MGMT-HOSTS description 'This group has the Management hosts address list'", -# "set firewall group address-group MGMT-HOSTS", -# "set firewall group network-group MGMT network 192.0.1.0/24", -# "set firewall group network-group MGMT description 'This group has the Management network addresses'", -# "set firewall group network-group MGMT", -# "set firewall ip-src-route 'enable'", -# "set firewall receive-redirects 'disable'", -# "set firewall send-redirects 'enable'", -# "set firewall config-trap 'enable'", -# "set firewall state-policy established action 'accept'", -# "set firewall state-policy established log 'enable'", -# "set firewall state-policy invalid action 'reject'", -# "set firewall broadcast-ping 'enable'", -# "set firewall all-ping 'enable'", -# "set firewall log-martians 'enable'", -# "set firewall twa-hazards-protection 'enable'", -# "set firewall syn-cookies 'enable'", -# "set firewall source-validation 'strict'" -# ] -# -# "after": { -# "config_trap": true, -# "group": { -# "address_group": [ -# { -# "description": "This group has the Management hosts address list", -# "members": [ -# { -# "address": "192.0.1.1" -# }, -# { -# "address": "192.0.1.3" -# }, -# { -# "address": "192.0.1.5" -# } -# ], -# "name": "MGMT-HOSTS" -# } -# ], -# "network_group": [ -# { -# "description": "This group has the Management network addresses", -# "members": [ -# { -# "address": "192.0.1.0/24" -# } -# ], -# "name": "MGMT" -# } -# ] -# }, -# "log_martians": true, -# "ping": { -# "all": true, -# "broadcast": true -# }, -# "route_redirects": [ -# { -# "afi": "ipv4", -# "icmp_redirects": { -# "receive": false, -# "send": true -# }, -# "ip_src_route": true -# } -# ], -# "state_policy": [ -# { -# "action": "accept", -# "connection_type": "established", -# "log": true -# }, -# { -# "action": "reject", -# "connection_type": "invalid" -# } -# ], -# "syn_cookies": true, -# "twa_hazards_protection": true, -# "validation": "strict" -# } -# -# After state: -# ------------- -# -# vyos@192# run show configuration commands | grep firewall -# set firewall all-ping 'enable' -# set firewall broadcast-ping 'enable' -# set firewall config-trap 'enable' -# set firewall group address-group MGMT-HOSTS address '192.0.1.1' -# set firewall group address-group MGMT-HOSTS address '192.0.1.3' -# set firewall group address-group MGMT-HOSTS address '192.0.1.5' -# set firewall group address-group MGMT-HOSTS description 'This group has the Management hosts address list' -# set firewall group network-group MGMT description 'This group has the Management network addresses' -# set firewall group network-group MGMT network '192.0.1.0/24' -# set firewall ip-src-route 'enable' -# set firewall log-martians 'enable' -# set firewall receive-redirects 'disable' -# set firewall send-redirects 'enable' -# set firewall source-validation 'strict' -# set firewall state-policy established action 'accept' -# set firewall state-policy established log 'enable' -# set firewall state-policy invalid action 'reject' -# set firewall syn-cookies 'enable' -# set firewall twa-hazards-protection 'enable' -# -# -# Using parsed -# -# -- name: Render the commands for provided configuration - vyos_firewall_global: - running_config: - "set firewall all-ping 'enable' - set firewall broadcast-ping 'enable' - set firewall config-trap 'enable' - set firewall group address-group ENG-HOSTS address '192.0.3.1' - set firewall group address-group ENG-HOSTS address '192.0.3.2' - set firewall group address-group ENG-HOSTS description 'Sales office hosts address list' - set firewall group address-group SALES-HOSTS address '192.0.2.1' - set firewall group address-group SALES-HOSTS address '192.0.2.2' - set firewall group address-group SALES-HOSTS address '192.0.2.3' - set firewall group address-group SALES-HOSTS description 'Sales office hosts address list' - set firewall group network-group MGMT description 'This group has the Management network addresses' - set firewall group network-group MGMT network '192.0.1.0/24' - set firewall ip-src-route 'enable' - set firewall log-martians 'enable' - set firewall receive-redirects 'disable' - set firewall send-redirects 'enable' - set firewall source-validation 'strict' - set firewall state-policy established action 'accept' - set firewall state-policy established log 'enable' - set firewall state-policy invalid action 'reject' - set firewall syn-cookies 'enable' - set firewall twa-hazards-protection 'enable'" - state: parsed -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# -# "parsed": { -# "config_trap": true, -# "group": { -# "address_group": [ -# { -# "description": "Sales office hosts address list", -# "members": [ -# { -# "address": "192.0.3.1" -# }, -# { -# "address": "192.0.3.2" -# } -# ], -# "name": "ENG-HOSTS" -# }, -# { -# "description": "Sales office hosts address list", -# "members": [ -# { -# "address": "192.0.2.1" -# }, -# { -# "address": "192.0.2.2" -# }, -# { -# "address": "192.0.2.3" -# } -# ], -# "name": "SALES-HOSTS" -# } -# ], -# "network_group": [ -# { -# "description": "This group has the Management network addresses", -# "members": [ -# { -# "address": "192.0.1.0/24" -# } -# ], -# "name": "MGMT" -# } -# ] -# }, -# "log_martians": true, -# "ping": { -# "all": true, -# "broadcast": true -# }, -# "route_redirects": [ -# { -# "afi": "ipv4", -# "icmp_redirects": { -# "receive": false, -# "send": true -# }, -# "ip_src_route": true -# } -# ], -# "state_policy": [ -# { -# "action": "accept", -# "connection_type": "established", -# "log": true -# }, -# { -# "action": "reject", -# "connection_type": "invalid" -# } -# ], -# "syn_cookies": true, -# "twa_hazards_protection": true, -# "validation": "strict" -# } -# } -# -# -# Using deleted -# -# Before state -# ------------- -# -# vyos@192# run show configuration commands | grep firewall -# set firewall all-ping 'enable' -# set firewall broadcast-ping 'enable' -# set firewall config-trap 'enable' -# set firewall group address-group MGMT-HOSTS address '192.0.1.1' -# set firewall group address-group MGMT-HOSTS address '192.0.1.3' -# set firewall group address-group MGMT-HOSTS address '192.0.1.5' -# set firewall group address-group MGMT-HOSTS description 'This group has the Management hosts address list' -# set firewall group network-group MGMT description 'This group has the Management network addresses' -# set firewall group network-group MGMT network '192.0.1.0/24' -# set firewall ip-src-route 'enable' -# set firewall log-martians 'enable' -# set firewall receive-redirects 'disable' -# set firewall send-redirects 'enable' -# set firewall source-validation 'strict' -# set firewall state-policy established action 'accept' -# set firewall state-policy established log 'enable' -# set firewall state-policy invalid action 'reject' -# set firewall syn-cookies 'enable' -# set firewall twa-hazards-protection 'enable' -- name: Delete attributes of firewall. - vyos_firewall_global: - config: - state_policy: - config_trap: - log_martians: - syn_cookies: - twa_hazards_protection: - route_redirects: - ping: - group: - state: deleted -# -# -# ------------------------ -# Module Execution Results -# ------------------------ -# -# "before": { -# "config_trap": true, -# "group": { -# "address_group": [ -# { -# "description": "This group has the Management hosts address list", -# "members": [ -# { -# "address": "192.0.1.1" -# }, -# { -# "address": "192.0.1.3" -# }, -# { -# "address": "192.0.1.5" -# } -# ], -# "name": "MGMT-HOSTS" -# } -# ], -# "network_group": [ -# { -# "description": "This group has the Management network addresses", -# "members": [ -# { -# "address": "192.0.1.0/24" -# } -# ], -# "name": "MGMT" -# } -# ] -# }, -# "log_martians": true, -# "ping": { -# "all": true, -# "broadcast": true -# }, -# "route_redirects": [ -# { -# "afi": "ipv4", -# "icmp_redirects": { -# "receive": false, -# "send": true -# }, -# "ip_src_route": true -# } -# ], -# "state_policy": [ -# { -# "action": "accept", -# "connection_type": "established", -# "log": true -# }, -# { -# "action": "reject", -# "connection_type": "invalid" -# } -# ], -# "syn_cookies": true, -# "twa_hazards_protection": true, -# "validation": "strict" -# } -# "commands": [ -# "delete firewall source-validation", -# "delete firewall group", -# "delete firewall log-martians", -# "delete firewall ip-src-route", -# "delete firewall receive-redirects", -# "delete firewall send-redirects", -# "delete firewall config-trap", -# "delete firewall state-policy", -# "delete firewall syn-cookies", -# "delete firewall broadcast-ping", -# "delete firewall all-ping", -# "delete firewall twa-hazards-protection" -# ] -# -# "after": [] -# After state -# ------------ -# vyos@192# run show configuration commands | grep firewall -# set 'firewall' -# -# -# Using replaced -# -# Before state: -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep firewall -# set firewall all-ping 'enable' -# set firewall broadcast-ping 'enable' -# set firewall config-trap 'enable' -# set firewall group address-group MGMT-HOSTS address '192.0.1.1' -# set firewall group address-group MGMT-HOSTS address '192.0.1.3' -# set firewall group address-group MGMT-HOSTS address '192.0.1.5' -# set firewall group address-group MGMT-HOSTS description 'This group has the Management hosts address list' -# set firewall group network-group MGMT description 'This group has the Management network addresses' -# set firewall group network-group MGMT network '192.0.1.0/24' -# set firewall ip-src-route 'enable' -# set firewall log-martians 'enable' -# set firewall receive-redirects 'disable' -# set firewall send-redirects 'enable' -# set firewall source-validation 'strict' -# set firewall state-policy established action 'accept' -# set firewall state-policy established log 'enable' -# set firewall state-policy invalid action 'reject' -# set firewall syn-cookies 'enable' -# set firewall twa-hazards-protection 'enable' -# -- name: Replace firewall global attributes configuration. - vyos_firewall_global: - config: - validation: strict - config_trap: True - log_martians: True - syn_cookies: True - twa_hazards_protection: True - ping: - all: True - broadcast: True - state_policy: - - connection_type: 'established' - action: 'accept' - log: True - - connection_type: 'invalid' - action: 'reject' - route_redirects: - - afi: 'ipv4' - ip_src_route: True - icmp_redirects: - send: True - receive: False - group: - address_group: - - name: 'SALES-HOSTS' - description: 'Sales office hosts address list' - members: - - address: 192.0.2.1 - - address: 192.0.2.2 - - address: 192.0.2.3 - - name: 'ENG-HOSTS' - description: 'Sales office hosts address list' - members: - - address: 192.0.3.1 - - address: 192.0.3.2 - network_group: - - name: 'MGMT' - description: 'This group has the Management network addresses' - members: - - address: 192.0.1.0/24 - state: replaced -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# "before": { -# "config_trap": true, -# "group": { -# "address_group": [ -# { -# "description": "This group has the Management hosts address list", -# "members": [ -# { -# "address": "192.0.1.1" -# }, -# { -# "address": "192.0.1.3" -# }, -# { -# "address": "192.0.1.5" -# } -# ], -# "name": "MGMT-HOSTS" -# } -# ], -# "network_group": [ -# { -# "description": "This group has the Management network addresses", -# "members": [ -# { -# "address": "192.0.1.0/24" -# } -# ], -# "name": "MGMT" -# } -# ] -# }, -# "log_martians": true, -# "ping": { -# "all": true, -# "broadcast": true -# }, -# "route_redirects": [ -# { -# "afi": "ipv4", -# "icmp_redirects": { -# "receive": false, -# "send": true -# }, -# "ip_src_route": true -# } -# ], -# "state_policy": [ -# { -# "action": "accept", -# "connection_type": "established", -# "log": true -# }, -# { -# "action": "reject", -# "connection_type": "invalid" -# } -# ], -# "syn_cookies": true, -# "twa_hazards_protection": true, -# "validation": "strict" -# } -# -# "commands": [ -# "delete firewall group address-group MGMT-HOSTS", -# "set firewall group address-group SALES-HOSTS address 192.0.2.1", -# "set firewall group address-group SALES-HOSTS address 192.0.2.2", -# "set firewall group address-group SALES-HOSTS address 192.0.2.3", -# "set firewall group address-group SALES-HOSTS description 'Sales office hosts address list'", -# "set firewall group address-group SALES-HOSTS", -# "set firewall group address-group ENG-HOSTS address 192.0.3.1", -# "set firewall group address-group ENG-HOSTS address 192.0.3.2", -# "set firewall group address-group ENG-HOSTS description 'Sales office hosts address list'", -# "set firewall group address-group ENG-HOSTS" -# ] -# -# "after": { -# "config_trap": true, -# "group": { -# "address_group": [ -# { -# "description": "Sales office hosts address list", -# "members": [ -# { -# "address": "192.0.3.1" -# }, -# { -# "address": "192.0.3.2" -# } -# ], -# "name": "ENG-HOSTS" -# }, -# { -# "description": "Sales office hosts address list", -# "members": [ -# { -# "address": "192.0.2.1" -# }, -# { -# "address": "192.0.2.2" -# }, -# { -# "address": "192.0.2.3" -# } -# ], -# "name": "SALES-HOSTS" -# } -# ], -# "network_group": [ -# { -# "description": "This group has the Management network addresses", -# "members": [ -# { -# "address": "192.0.1.0/24" -# } -# ], -# "name": "MGMT" -# } -# ] -# }, -# "log_martians": true, -# "ping": { -# "all": true, -# "broadcast": true -# }, -# "route_redirects": [ -# { -# "afi": "ipv4", -# "icmp_redirects": { -# "receive": false, -# "send": true -# }, -# "ip_src_route": true -# } -# ], -# "state_policy": [ -# { -# "action": "accept", -# "connection_type": "established", -# "log": true -# }, -# { -# "action": "reject", -# "connection_type": "invalid" -# } -# ], -# "syn_cookies": true, -# "twa_hazards_protection": true, -# "validation": "strict" -# } -# -# After state: -# ------------- -# -# vyos@192# run show configuration commands | grep firewall -# set firewall all-ping 'enable' -# set firewall broadcast-ping 'enable' -# set firewall config-trap 'enable' -# set firewall group address-group ENG-HOSTS address '192.0.3.1' -# set firewall group address-group ENG-HOSTS address '192.0.3.2' -# set firewall group address-group ENG-HOSTS description 'Sales office hosts address list' -# set firewall group address-group SALES-HOSTS address '192.0.2.1' -# set firewall group address-group SALES-HOSTS address '192.0.2.2' -# set firewall group address-group SALES-HOSTS address '192.0.2.3' -# set firewall group address-group SALES-HOSTS description 'Sales office hosts address list' -# set firewall group network-group MGMT description 'This group has the Management network addresses' -# set firewall group network-group MGMT network '192.0.1.0/24' -# set firewall ip-src-route 'enable' -# set firewall log-martians 'enable' -# set firewall receive-redirects 'disable' -# set firewall send-redirects 'enable' -# set firewall source-validation 'strict' -# set firewall state-policy established action 'accept' -# set firewall state-policy established log 'enable' -# set firewall state-policy invalid action 'reject' -# set firewall syn-cookies 'enable' -# set firewall twa-hazards-protection 'enable' -# -# -# Using gathered -# -# Before state: -# ------------- -# -# vyos@192# run show configuration commands | grep firewall -# set firewall all-ping 'enable' -# set firewall broadcast-ping 'enable' -# set firewall config-trap 'enable' -# set firewall group address-group ENG-HOSTS address '192.0.3.1' -# set firewall group address-group ENG-HOSTS address '192.0.3.2' -# set firewall group address-group ENG-HOSTS description 'Sales office hosts address list' -# set firewall group address-group SALES-HOSTS address '192.0.2.1' -# set firewall group address-group SALES-HOSTS address '192.0.2.2' -# set firewall group address-group SALES-HOSTS address '192.0.2.3' -# set firewall group address-group SALES-HOSTS description 'Sales office hosts address list' -# set firewall group network-group MGMT description 'This group has the Management network addresses' -# set firewall group network-group MGMT network '192.0.1.0/24' -# set firewall ip-src-route 'enable' -# set firewall log-martians 'enable' -# set firewall receive-redirects 'disable' -# set firewall send-redirects 'enable' -# set firewall source-validation 'strict' -# set firewall state-policy established action 'accept' -# set firewall state-policy established log 'enable' -# set firewall state-policy invalid action 'reject' -# set firewall syn-cookies 'enable' -# set firewall twa-hazards-protection 'enable' -# -- name: Gather firewall global config with provided configurations - vyos_firewall_global: - config: - state: gathered -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# "gathered": [ -# { -# "config_trap": true, -# "group": { -# "address_group": [ -# { -# "description": "Sales office hosts address list", -# "members": [ -# { -# "address": "192.0.3.1" -# }, -# { -# "address": "192.0.3.2" -# } -# ], -# "name": "ENG-HOSTS" -# }, -# { -# "description": "Sales office hosts address list", -# "members": [ -# { -# "address": "192.0.2.1" -# }, -# { -# "address": "192.0.2.2" -# }, -# { -# "address": "192.0.2.3" -# } -# ], -# "name": "SALES-HOSTS" -# } -# ], -# "network_group": [ -# { -# "description": "This group has the Management network addresses", -# "members": [ -# { -# "address": "192.0.1.0/24" -# } -# ], -# "name": "MGMT" -# } -# ] -# }, -# "log_martians": true, -# "ping": { -# "all": true, -# "broadcast": true -# }, -# "route_redirects": [ -# { -# "afi": "ipv4", -# "icmp_redirects": { -# "receive": false, -# "send": true -# }, -# "ip_src_route": true -# } -# ], -# "state_policy": [ -# { -# "action": "accept", -# "connection_type": "established", -# "log": true -# }, -# { -# "action": "reject", -# "connection_type": "invalid" -# } -# ], -# "syn_cookies": true, -# "twa_hazards_protection": true, -# "validation": "strict" -# } -# -# After state: -# ------------- -# -# vyos@192# run show configuration commands | grep firewall -# set firewall all-ping 'enable' -# set firewall broadcast-ping 'enable' -# set firewall config-trap 'enable' -# set firewall group address-group ENG-HOSTS address '192.0.3.1' -# set firewall group address-group ENG-HOSTS address '192.0.3.2' -# set firewall group address-group ENG-HOSTS description 'Sales office hosts address list' -# set firewall group address-group SALES-HOSTS address '192.0.2.1' -# set firewall group address-group SALES-HOSTS address '192.0.2.2' -# set firewall group address-group SALES-HOSTS address '192.0.2.3' -# set firewall group address-group SALES-HOSTS description 'Sales office hosts address list' -# set firewall group network-group MGMT description 'This group has the Management network addresses' -# set firewall group network-group MGMT network '192.0.1.0/24' -# set firewall ip-src-route 'enable' -# set firewall log-martians 'enable' -# set firewall receive-redirects 'disable' -# set firewall send-redirects 'enable' -# set firewall source-validation 'strict' -# set firewall state-policy established action 'accept' -# set firewall state-policy established log 'enable' -# set firewall state-policy invalid action 'reject' -# set firewall syn-cookies 'enable' -# set firewall twa-hazards-protection 'enable' - - -# Using rendered -# -# -- name: Render the commands for provided configuration - vyos_firewall_global: - config: - validation: strict - config_trap: True - log_martians: True - syn_cookies: True - twa_hazards_protection: True - ping: - all: True - broadcast: True - state_policy: - - connection_type: 'established' - action: 'accept' - log: True - - connection_type: 'invalid' - action: 'reject' - route_redirects: - - afi: 'ipv4' - ip_src_route: True - icmp_redirects: - send: True - receive: False - group: - address_group: - - name: 'SALES-HOSTS' - description: 'Sales office hosts address list' - members: - - address: 192.0.2.1 - - address: 192.0.2.2 - - address: 192.0.2.3 - - name: 'ENG-HOSTS' - description: 'Sales office hosts address list' - members: - - address: 192.0.3.1 - - address: 192.0.3.2 - network_group: - - name: 'MGMT' - description: 'This group has the Management network addresses' - members: - - address: 192.0.1.0/24 - state: rendered -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# -# "rendered": [ -# "set firewall group address-group SALES-HOSTS address 192.0.2.1", -# "set firewall group address-group SALES-HOSTS address 192.0.2.2", -# "set firewall group address-group SALES-HOSTS address 192.0.2.3", -# "set firewall group address-group SALES-HOSTS description 'Sales office hosts address list'", -# "set firewall group address-group SALES-HOSTS", -# "set firewall group address-group ENG-HOSTS address 192.0.3.1", -# "set firewall group address-group ENG-HOSTS address 192.0.3.2", -# "set firewall group address-group ENG-HOSTS description 'Sales office hosts address list'", -# "set firewall group address-group ENG-HOSTS", -# "set firewall group network-group MGMT network 192.0.1.0/24", -# "set firewall group network-group MGMT description 'This group has the Management network addresses'", -# "set firewall group network-group MGMT", -# "set firewall ip-src-route 'enable'", -# "set firewall receive-redirects 'disable'", -# "set firewall send-redirects 'enable'", -# "set firewall config-trap 'enable'", -# "set firewall state-policy established action 'accept'", -# "set firewall state-policy established log 'enable'", -# "set firewall state-policy invalid action 'reject'", -# "set firewall broadcast-ping 'enable'", -# "set firewall all-ping 'enable'", -# "set firewall log-martians 'enable'", -# "set firewall twa-hazards-protection 'enable'", -# "set firewall syn-cookies 'enable'", -# "set firewall source-validation 'strict'" -# ] -# -# -""" -RETURN = """ -before: - description: The configuration prior to the model invocation. - returned: always - type: list - sample: > - The configuration returned will always be in the same format - of the parameters above. -after: - description: The resulting configuration model invocation. - returned: when changed - type: list - sample: > - The configuration returned will always be in the same format - of the parameters above. -commands: - description: The set of commands pushed to the remote device. - returned: always - type: list - sample: ['set firewall group address-group ENG-HOSTS', - 'set firewall group address-group ENG-HOSTS address 192.0.3.1'] -""" - - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.vyos.argspec.firewall_global.firewall_global import Firewall_globalArgs -from ansible.module_utils.network.vyos.config.firewall_global.firewall_global import Firewall_global - - -def main(): - """ - Main entry point for module execution - - :returns: the result form module invocation - """ - required_if = [('state', 'merged', ('config',)), - ('state', 'replaced', ('config',)), - ('state', 'parsed', ('running_config',))] - mutually_exclusive = [('config', 'running_config')] - module = AnsibleModule(argument_spec=Firewall_globalArgs.argument_spec, - required_if=required_if, - supports_check_mode=True, - mutually_exclusive=mutually_exclusive) - - result = Firewall_global(module).execute_module() - module.exit_json(**result) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/vyos/vyos_firewall_interfaces.py b/lib/ansible/modules/network/vyos/vyos_firewall_interfaces.py deleted file mode 100644 index 8655744ff7..0000000000 --- a/lib/ansible/modules/network/vyos/vyos_firewall_interfaces.py +++ /dev/null @@ -1,1279 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -############################################# -# WARNING # -############################################# -# -# This file is auto generated by the resource -# module builder playbook. -# -# Do not edit this file manually. -# -# Changes to this file will be over written -# by the resource module builder. -# -# Changes should be made in the model used to -# generate this file or in the resource module -# builder template. -# -############################################# - -""" -The module file for vyos_firewall_interfaces -""" - -from __future__ import absolute_import, division, print_function -__metaclass__ = type - -ANSIBLE_METADATA = { - 'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'network' -} - -DOCUMENTATION = """ ---- -module: vyos_firewall_interfaces -version_added: '2.10' -short_description: Manage firewall rules attributes of interfaces on VyOS devices -description: Manage firewall rules of interfaces on VyOS network devices. -author: - - Rohit Thakur (@rohitthakur2590) -options: - config: - description: A list of firewall rules options for interfaces. - type: list - elements: dict - suboptions: - name: - description: - - Name/Identifier for the interface. - type: str - required: True - access_rules: - description: - - Specifies firewall rules attached to the interfaces. - type: list - elements: dict - suboptions: - afi: - description: - - Specifies the AFI for the Firewall rules to be configured on this interface. - type: str - choices: ['ipv4', 'ipv6'] - required: True - rules: - description: - - Specifies the firewall rules for the provided AFI. - type: list - elements: dict - suboptions: - name: - description: - - Specifies the name of the IPv4/IPv6 Firewall rule for the interface. - type: str - direction: - description: - - Specifies the direction of packets that the firewall rule will be applied on. - type: str - choices: ['in', 'local', 'out'] - required: True - running_config: - description: - - The module, by default, will connect to the remote device and - retrieve the current running-config to use as a base for comparing - against the contents of source. There are times when it is not - desirable to have the task get the current running-config for - every task in a playbook. The I(running_config) argument allows the - implementer to pass in the configuration to use as the base - config for comparison. This value of this option should be the - output received from device by executing command - C(show configuration commands | grep 'firewall' - type: str - state: - description: - - The state the configuration should be left in. - type: str - choices: - - merged - - replaced - - overridden - - deleted - - parsed - - rendered - - gathered - default: merged -""" -EXAMPLES = """ -# Using merged -# -# Before state: -# ------------- -# -# vyos@192# run show configuration commands | grep firewall -# set firewall ipv6-name 'V6-LOCAL' -# set firewall name 'INBOUND' -# set firewall name 'LOCAL' -# set firewall name 'OUTBOUND' -# -- name: Merge the provided configuration with the existing running configuration - vyos_firewall_interfaces: - config: - - access_rules: - - afi: 'ipv4' - rules: - - name: 'INBOUND' - direction: 'in' - - name: 'OUTBOUND' - direction: 'out' - - name: 'LOCAL' - direction: 'local' - - afi: 'ipv6' - rules: - - name: 'V6-LOCAL' - direction: 'local' - name: 'eth1' - - access_rules: - - afi: 'ipv4' - rules: - - name: 'INBOUND' - direction: 'in' - - name: 'OUTBOUND' - direction: 'out' - - name: 'LOCAL' - direction: 'local' - - afi: 'ipv6' - rules: - - name: 'V6-LOCAL' - direction: 'local' - name: 'eth3' - state: merged -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# before": [ -# { -# "name": "eth0" -# }, -# { -# "name": "eth1" -# }, -# { -# "name": "eth2" -# }, -# { -# "name": "eth3" -# } -# ] -# -# "commands": [ -# "set interfaces ethernet eth1 firewall in name 'INBOUND'", -# "set interfaces ethernet eth1 firewall out name 'OUTBOUND'", -# "set interfaces ethernet eth1 firewall local name 'LOCAL'", -# "set interfaces ethernet eth1 firewall local ipv6-name 'V6-LOCAL'", -# "set interfaces ethernet eth3 firewall in name 'INBOUND'", -# "set interfaces ethernet eth3 firewall out name 'OUTBOUND'", -# "set interfaces ethernet eth3 firewall local name 'LOCAL'", -# "set interfaces ethernet eth3 firewall local ipv6-name 'V6-LOCAL'" -# ] -# -# "after": [ -# { -# "name": "eth0" -# }, -# { -# "access_rules": [ -# { -# "afi": "ipv4", -# "rules": [ -# { -# "direction": "in", -# "name": "INBOUND" -# }, -# { -# "direction": "local", -# "name": "LOCAL" -# }, -# { -# "direction": "out", -# "name": "OUTBOUND" -# } -# ] -# }, -# { -# "afi": "ipv6", -# "rules": [ -# { -# "direction": "local", -# "name": "V6-LOCAL" -# } -# ] -# } -# ], -# "name": "eth1" -# }, -# { -# "name": "eth2" -# }, -# { -# "access_rules": [ -# { -# "afi": "ipv4", -# "rules": [ -# { -# "direction": "in", -# "name": "INBOUND" -# }, -# { -# "direction": "local", -# "name": "LOCAL" -# }, -# { -# "direction": "out", -# "name": "OUTBOUND" -# } -# ] -# }, -# { -# "afi": "ipv6", -# "rules": [ -# { -# "direction": "local", -# "name": "V6-LOCAL" -# } -# ] -# } -# ], -# "name": "eth3" -# } -# ] -# -# After state: -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep firewall -# set firewall ipv6-name 'V6-LOCAL' -# set firewall name 'INBOUND' -# set firewall name 'LOCAL' -# set firewall name 'OUTBOUND' -# set interfaces ethernet eth1 firewall in name 'INBOUND' -# set interfaces ethernet eth1 firewall local ipv6-name 'V6-LOCAL' -# set interfaces ethernet eth1 firewall local name 'LOCAL' -# set interfaces ethernet eth1 firewall out name 'OUTBOUND' -# set interfaces ethernet eth3 firewall in name 'INBOUND' -# set interfaces ethernet eth3 firewall local ipv6-name 'V6-LOCAL' -# set interfaces ethernet eth3 firewall local name 'LOCAL' -# set interfaces ethernet eth3 firewall out name 'OUTBOUND' - - -# Using merged -# -# Before state: -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep firewall -# set firewall ipv6-name 'V6-LOCAL' -# set firewall name 'INBOUND' -# set firewall name 'LOCAL' -# set firewall name 'OUTBOUND' -# set interfaces ethernet eth1 firewall in name 'INBOUND' -# set interfaces ethernet eth1 firewall local ipv6-name 'V6-LOCAL' -# set interfaces ethernet eth1 firewall local name 'LOCAL' -# set interfaces ethernet eth1 firewall out name 'OUTBOUND' -# set interfaces ethernet eth3 firewall in name 'INBOUND' -# set interfaces ethernet eth3 firewall local ipv6-name 'V6-LOCAL' -# set interfaces ethernet eth3 firewall local name 'LOCAL' -# set interfaces ethernet eth3 firewall out name 'OUTBOUND' -# -- name: Merge the provided configuration with the existing running configuration - vyos_firewall_interfaces: - config: - - access_rules: - - afi: 'ipv4' - rules: - - name: 'OUTBOUND' - direction: 'in' - - name: 'INBOUND' - direction: 'out' - name: 'eth1' - state: merged -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# "before": [ -# { -# "name": "eth0" -# }, -# { -# "access_rules": [ -# { -# "afi": "ipv4", -# "rules": [ -# { -# "direction": "in", -# "name": "INBOUND" -# }, -# { -# "direction": "local", -# "name": "LOCAL" -# }, -# { -# "direction": "out", -# "name": "OUTBOUND" -# } -# ] -# }, -# { -# "afi": "ipv6", -# "rules": [ -# { -# "direction": "local", -# "name": "V6-LOCAL" -# } -# ] -# } -# ], -# "name": "eth1" -# }, -# { -# "name": "eth2" -# }, -# { -# "access_rules": [ -# { -# "afi": "ipv4", -# "rules": [ -# { -# "direction": "in", -# "name": "INBOUND" -# }, -# { -# "direction": "local", -# "name": "LOCAL" -# }, -# { -# "direction": "out", -# "name": "OUTBOUND" -# } -# ] -# }, -# { -# "afi": "ipv6", -# "rules": [ -# { -# "direction": "local", -# "name": "V6-LOCAL" -# } -# ] -# } -# ], -# "name": "eth3" -# } -# ] -# -# "commands": [ -# "set interfaces ethernet eth1 firewall in name 'OUTBOUND'", -# "set interfaces ethernet eth1 firewall out name 'INBOUND'" -# ] -# -# "after": [ -# { -# "name": "eth0" -# }, -# { -# "access_rules": [ -# { -# "afi": "ipv4", -# "rules": [ -# { -# "direction": "in", -# "name": "OUTBOUND" -# }, -# { -# "direction": "local", -# "name": "LOCAL" -# }, -# { -# "direction": "out", -# "name": "INBOUND" -# } -# ] -# }, -# { -# "afi": "ipv6", -# "rules": [ -# { -# "direction": "local", -# "name": "V6-LOCAL" -# } -# ] -# } -# ], -# "name": "eth1" -# }, -# { -# "name": "eth2" -# }, -# { -# "access_rules": [ -# { -# "afi": "ipv4", -# "rules": [ -# { -# "direction": "in", -# "name": "INBOUND" -# }, -# { -# "direction": "local", -# "name": "LOCAL" -# }, -# { -# "direction": "out", -# "name": "OUTBOUND" -# } -# ] -# }, -# { -# "afi": "ipv6", -# "rules": [ -# { -# "direction": "local", -# "name": "V6-LOCAL" -# } -# ] -# } -# ], -# "name": "eth3" -# } -# ] -# -# After state: -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep firewall -# set firewall ipv6-name 'V6-LOCAL' -# set firewall name 'INBOUND' -# set firewall name 'LOCAL' -# set firewall name 'OUTBOUND' -# set interfaces ethernet eth1 firewall in name 'OUTBOUND' -# set interfaces ethernet eth1 firewall local ipv6-name 'V6-LOCAL' -# set interfaces ethernet eth1 firewall local name 'LOCAL' -# set interfaces ethernet eth1 firewall out name 'INBOUND' -# set interfaces ethernet eth3 firewall in name 'INBOUND' -# set interfaces ethernet eth3 firewall local ipv6-name 'V6-LOCAL' -# set interfaces ethernet eth3 firewall local name 'LOCAL' -# set interfaces ethernet eth3 firewall out name 'OUTBOUND' - - -# Using replaced -# -# Before state: -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep firewall -# set firewall ipv6-name 'V6-LOCAL' -# set firewall name 'INBOUND' -# set firewall name 'LOCAL' -# set firewall name 'OUTBOUND' -# set interfaces ethernet eth1 firewall in name 'INBOUND' -# set interfaces ethernet eth1 firewall local ipv6-name 'V6-LOCAL' -# set interfaces ethernet eth1 firewall local name 'LOCAL' -# set interfaces ethernet eth1 firewall out name 'OUTBOUND' -# set interfaces ethernet eth3 firewall in name 'INBOUND' -# set interfaces ethernet eth3 firewall local ipv6-name 'V6-LOCAL' -# set interfaces ethernet eth3 firewall local name 'LOCAL' -# set interfaces ethernet eth3 firewall out name 'OUTBOUND' -# -- name: Replace device configurations of listed firewall interfaces with provided configurations - vyos_firewall_interfaces: - config: - - name: 'eth1' - access_rules: - - afi: 'ipv4' - rules: - - name: 'OUTBOUND' - direction: 'out' - - afi: 'ipv6' - rules: - - name: 'V6-LOCAL' - direction: 'local' - - name: 'eth3' - access_rules: - - afi: 'ipv4' - rules: - - name: 'INBOUND' - direction: 'in' - state: replaced -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# "before": [ -# { -# "name": "eth0" -# }, -# { -# "access_rules": [ -# { -# "afi": "ipv4", -# "rules": [ -# { -# "direction": "in", -# "name": "INBOUND" -# }, -# { -# "direction": "local", -# "name": "LOCAL" -# }, -# { -# "direction": "out", -# "name": "OUTBOUND" -# } -# ] -# }, -# { -# "afi": "ipv6", -# "rules": [ -# { -# "direction": "local", -# "name": "V6-LOCAL" -# } -# ] -# } -# ], -# "name": "eth1" -# }, -# { -# "name": "eth2" -# }, -# { -# "access_rules": [ -# { -# "afi": "ipv4", -# "rules": [ -# { -# "direction": "in", -# "name": "INBOUND" -# }, -# { -# "direction": "local", -# "name": "LOCAL" -# }, -# { -# "direction": "out", -# "name": "OUTBOUND" -# } -# ] -# }, -# { -# "afi": "ipv6", -# "rules": [ -# { -# "direction": "local", -# "name": "V6-LOCAL" -# } -# ] -# } -# ], -# "name": "eth3" -# } -# ] -# -# "commands": [ -# "delete interfaces ethernet eth1 firewall in name", -# "delete interfaces ethernet eth1 firewall local name", -# "delete interfaces ethernet eth3 firewall local name", -# "delete interfaces ethernet eth3 firewall out name", -# "delete interfaces ethernet eth3 firewall local ipv6-name" -# ] -# -# "after": [ -# { -# "name": "eth0" -# }, -# { -# "access_rules": [ -# { -# "afi": "ipv4", -# "rules": [ -# { -# "direction": "out", -# "name": "OUTBOUND" -# } -# ] -# }, -# { -# "afi": "ipv6", -# "rules": [ -# { -# "direction": "local", -# "name": "V6-LOCAL" -# } -# ] -# } -# ], -# "name": "eth1" -# }, -# { -# "name": "eth2" -# }, -# { -# "access_rules": [ -# { -# "afi": "ipv4", -# "rules": [ -# { -# "direction": "in", -# "name": "INBOUND" -# } -# ] -# } -# ], -# "name": "eth3" -# } -# ] -# -# After state: -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep firewall -# set firewall ipv6-name 'V6-LOCAL' -# set firewall name 'INBOUND' -# set firewall name 'LOCAL' -# set firewall name 'OUTBOUND' -# set interfaces ethernet eth1 firewall 'in' -# set interfaces ethernet eth1 firewall local ipv6-name 'V6-LOCAL' -# set interfaces ethernet eth1 firewall out name 'OUTBOUND' -# set interfaces ethernet eth3 firewall in name 'INBOUND' -# set interfaces ethernet eth3 firewall 'local' -# set interfaces ethernet eth3 firewall 'out' - - -# Using overridden -# -# Before state -# -------------- -# -# vyos@vyos:~$ show configuration commands| grep firewall -# set firewall ipv6-name 'V6-LOCAL' -# set firewall name 'INBOUND' -# set firewall name 'LOCAL' -# set firewall name 'OUTBOUND' -# set interfaces ethernet eth1 firewall 'in' -# set interfaces ethernet eth1 firewall local ipv6-name 'V6-LOCAL' -# set interfaces ethernet eth1 firewall out name 'OUTBOUND' -# set interfaces ethernet eth3 firewall in name 'INBOUND' -# set interfaces ethernet eth3 firewall 'local' -# set interfaces ethernet eth3 firewall 'out' -# -- name: Overrides all device configuration with provided configuration - vyos_firewall_interfaces: - config: - - name: 'eth3' - access_rules: - - afi: 'ipv4' - rules: - - name: 'INBOUND' - direction: 'out' - state: overridden -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# "before":[ -# { -# "name": "eth0" -# }, -# { -# "access_rules": [ -# { -# "afi": "ipv4", -# "rules": [ -# { -# "direction": "out", -# "name": "OUTBOUND" -# } -# ] -# }, -# { -# "afi": "ipv6", -# "rules": [ -# { -# "direction": "local", -# "name": "V6-LOCAL" -# } -# ] -# } -# ], -# "name": "eth1" -# }, -# { -# "name": "eth2" -# }, -# { -# "access_rules": [ -# { -# "afi": "ipv4", -# "rules": [ -# { -# "direction": "in", -# "name": "INBOUND" -# } -# ] -# } -# ], -# "name": "eth3" -# } -# ] -# -# "commands": [ -# "delete interfaces ethernet eth1 firewall", -# "delete interfaces ethernet eth3 firewall in name", -# "set interfaces ethernet eth3 firewall out name 'INBOUND'" -# -# -# "after": [ -# { -# "name": "eth0" -# }, -# { -# "name": "eth1" -# }, -# { -# "name": "eth2" -# }, -# { -# "access_rules": [ -# { -# "afi": "ipv4", -# "rules": [ -# { -# "direction": "out", -# "name": "INBOUND" -# } -# ] -# } -# ], -# "name": "eth3" -# } -# ] -# -# -# After state -# ------------ -# -# vyos@vyos:~$ show configuration commands| grep firewall -# set firewall ipv6-name 'V6-LOCAL' -# set firewall name 'INBOUND' -# set firewall name 'LOCAL' -# set firewall name 'OUTBOUND' -# set interfaces ethernet eth3 firewall 'in' -# set interfaces ethernet eth3 firewall 'local' -# set interfaces ethernet eth3 firewall out name 'INBOUND' - - -# Using deleted per interface name -# -# Before state -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep firewall -# set firewall ipv6-name 'V6-LOCAL' -# set firewall name 'INBOUND' -# set firewall name 'LOCAL' -# set firewall name 'OUTBOUND' -# set interfaces ethernet eth1 firewall in name 'INBOUND' -# set interfaces ethernet eth1 firewall local ipv6-name 'V6-LOCAL' -# set interfaces ethernet eth1 firewall local name 'LOCAL' -# set interfaces ethernet eth1 firewall out name 'OUTBOUND' -# set interfaces ethernet eth3 firewall in name 'INBOUND' -# set interfaces ethernet eth3 firewall local ipv6-name 'V6-LOCAL' -# set interfaces ethernet eth3 firewall local name 'LOCAL' -# set interfaces ethernet eth3 firewall out name 'OUTBOUND' -# -- name: Delete firewall interfaces based on interface name. - vyos_firewall_interfaces: - config: - - name: 'eth1' - - name: 'eth3' - state: deleted -# -# -# ------------------------ -# Module Execution Results -# ------------------------ -# -# "before": [ -# { -# "name": "eth0" -# }, -# { -# "access_rules": [ -# { -# "afi": "ipv4", -# "rules": [ -# { -# "direction": "in", -# "name": "INBOUND" -# }, -# { -# "direction": "local", -# "name": "LOCAL" -# }, -# { -# "direction": "out", -# "name": "OUTBOUND" -# } -# ] -# }, -# { -# "afi": "ipv6", -# "rules": [ -# { -# "direction": "local", -# "name": "V6-LOCAL" -# } -# ] -# } -# ], -# "name": "eth1" -# }, -# { -# "name": "eth2" -# }, -# { -# "access_rules": [ -# { -# "afi": "ipv4", -# "rules": [ -# { -# "direction": "in", -# "name": "INBOUND" -# }, -# { -# "direction": "local", -# "name": "LOCAL" -# }, -# { -# "direction": "out", -# "name": "OUTBOUND" -# } -# ] -# }, -# { -# "afi": "ipv6", -# "rules": [ -# { -# "direction": "local", -# "name": "V6-LOCAL" -# } -# ] -# } -# ], -# "name": "eth3" -# } -# ] -# "commands": [ -# "delete interfaces ethernet eth1 firewall", -# "delete interfaces ethernet eth3 firewall" -# ] -# -# "after": [ -# { -# "name": "eth0" -# }, -# { -# "name": "eth1" -# }, -# { -# "name": "eth2" -# }, -# { -# "name": "eth3" -# } -# ] -# After state -# ------------ -# vyos@vyos# run show configuration commands | grep firewall -# set firewall ipv6-name 'V6-LOCAL' -# set firewall name 'INBOUND' -# set firewall name 'LOCAL' -# set firewall name 'OUTBOUND' - - -# Using deleted per afi -# -# Before state -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep firewall -# set firewall ipv6-name 'V6-LOCAL' -# set firewall name 'INBOUND' -# set firewall name 'LOCAL' -# set firewall name 'OUTBOUND' -# set interfaces ethernet eth1 firewall in name 'INBOUND' -# set interfaces ethernet eth1 firewall local ipv6-name 'V6-LOCAL' -# set interfaces ethernet eth1 firewall local name 'LOCAL' -# set interfaces ethernet eth1 firewall out name 'OUTBOUND' -# set interfaces ethernet eth3 firewall in name 'INBOUND' -# set interfaces ethernet eth3 firewall local ipv6-name 'V6-LOCAL' -# set interfaces ethernet eth3 firewall local name 'LOCAL' -# set interfaces ethernet eth3 firewall out name 'OUTBOUND' -# -- name: Delete firewall interfaces config per afi. - vyos_firewall_interfaces: - config: - - name: 'eth1' - access_rules: - - afi: 'ipv4' - - afi: 'ipv6' - state: deleted -# -# -# ------------------------ -# Module Execution Results -# ------------------------ -# -# "commands": [ -# "delete interfaces ethernet eth1 firewall in name", -# "delete interfaces ethernet eth1 firewall out name", -# "delete interfaces ethernet eth1 firewall local name", -# "delete interfaces ethernet eth1 firewall local ipv6-name" -# ] -# -# After state -# ------------ -# vyos@vyos# run show configuration commands | grep firewall -# set firewall ipv6-name 'V6-LOCAL' -# set firewall name 'INBOUND' -# set firewall name 'LOCAL' -# set firewall name 'OUTBOUND' - - -# Using deleted without config -# -# Before state -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep firewall -# set firewall ipv6-name 'V6-LOCAL' -# set firewall name 'INBOUND' -# set firewall name 'LOCAL' -# set firewall name 'OUTBOUND' -# set interfaces ethernet eth1 firewall in name 'INBOUND' -# set interfaces ethernet eth1 firewall local ipv6-name 'V6-LOCAL' -# set interfaces ethernet eth1 firewall local name 'LOCAL' -# set interfaces ethernet eth1 firewall out name 'OUTBOUND' -# set interfaces ethernet eth3 firewall in name 'INBOUND' -# set interfaces ethernet eth3 firewall local ipv6-name 'V6-LOCAL' -# set interfaces ethernet eth3 firewall local name 'LOCAL' -# set interfaces ethernet eth3 firewall out name 'OUTBOUND' -# -- name: Delete firewall interfaces config when empty config provided. - vyos_firewall_interfaces: - config: - state: deleted -# -# -# ------------------------ -# Module Execution Results -# ------------------------ -# -# "commands": [ -# "delete interfaces ethernet eth1 firewall", -# "delete interfaces ethernet eth1 firewall" -# ] -# -# After state -# ------------ -# vyos@vyos# run show configuration commands | grep firewall -# set firewall ipv6-name 'V6-LOCAL' -# set firewall name 'INBOUND' -# set firewall name 'LOCAL' -# set firewall name 'OUTBOUND' - - -# Using parsed -# -# -- name: Parse the provided configuration - vyos_firewall_interfaces: - running_config: - "set interfaces ethernet eth1 firewall in name 'INBOUND' - set interfaces ethernet eth1 firewall out name 'OUTBOUND' - set interfaces ethernet eth1 firewall local name 'LOCAL' - set interfaces ethernet eth1 firewall local ipv6-name 'V6-LOCAL' - set interfaces ethernet eth2 firewall in name 'INBOUND' - set interfaces ethernet eth2 firewall out name 'OUTBOUND' - set interfaces ethernet eth2 firewall local name 'LOCAL' - set interfaces ethernet eth2 firewall local ipv6-name 'V6-LOCAL'" - state: parsed -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# -# "parsed": [ -# { -# "name": "eth0" -# }, -# { -# "access_rules": [ -# { -# "afi": "ipv4", -# "rules": [ -# { -# "direction": "in", -# "name": "INBOUND" -# }, -# { -# "direction": "local", -# "name": "LOCAL" -# }, -# { -# "direction": "out", -# "name": "OUTBOUND" -# } -# ] -# }, -# { -# "afi": "ipv6", -# "rules": [ -# { -# "direction": "local", -# "name": "V6-LOCAL" -# } -# ] -# } -# ], -# "name": "eth1" -# }, -# { -# "access_rules": [ -# { -# "afi": "ipv4", -# "rules": [ -# { -# "direction": "in", -# "name": "INBOUND" -# }, -# { -# "direction": "local", -# "name": "LOCAL" -# }, -# { -# "direction": "out", -# "name": "OUTBOUND" -# } -# ] -# }, -# { -# "afi": "ipv6", -# "rules": [ -# { -# "direction": "local", -# "name": "V6-LOCAL" -# } -# ] -# } -# ], -# "name": "eth2" -# }, -# { -# "name": "eth3" -# } -# ] - - -# Using gathered -# -# Before state: -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep firewall -# set firewall ipv6-name 'V6-LOCAL' -# set firewall name 'INBOUND' -# set firewall name 'LOCAL' -# set firewall name 'OUTBOUND' -# set interfaces ethernet eth1 firewall 'in' -# set interfaces ethernet eth1 firewall local ipv6-name 'V6-LOCAL' -# set interfaces ethernet eth1 firewall out name 'OUTBOUND' -# set interfaces ethernet eth3 firewall in name 'INBOUND' -# set interfaces ethernet eth3 firewall 'local' -# set interfaces ethernet eth3 firewall 'out' -# -- name: Gather listed firewall interfaces. - vyos_firewall_interfaces: - config: - state: gathered -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# "gathered": [ -# { -# "name": "eth0" -# }, -# { -# "access_rules": [ -# { -# "afi": "ipv4", -# "rules": [ -# { -# "direction": "out", -# "name": "OUTBOUND" -# } -# ] -# }, -# { -# "afi": "ipv6", -# "rules": [ -# { -# "direction": "local", -# "name": "V6-LOCAL" -# } -# ] -# } -# ], -# "name": "eth1" -# }, -# { -# "name": "eth2" -# }, -# { -# "access_rules": [ -# { -# "afi": "ipv4", -# "rules": [ -# { -# "direction": "in", -# "name": "INBOUND" -# } -# ] -# } -# ], -# "name": "eth3" -# } -# ] -# -# -# After state: -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep firewall -# set firewall ipv6-name 'V6-LOCAL' -# set firewall name 'INBOUND' -# set firewall name 'LOCAL' -# set firewall name 'OUTBOUND' -# set interfaces ethernet eth1 firewall 'in' -# set interfaces ethernet eth1 firewall local ipv6-name 'V6-LOCAL' -# set interfaces ethernet eth1 firewall out name 'OUTBOUND' -# set interfaces ethernet eth3 firewall in name 'INBOUND' -# set interfaces ethernet eth3 firewall 'local' -# set interfaces ethernet eth3 firewall 'out' - - -# Using rendered -# -# -- name: Render the commands for provided configuration - vyos_firewall_interfaces: - config: - - name: 'eth2' - access_rules: - - afi: 'ipv4' - rules: - - direction: 'in' - name: 'INGRESS' - - direction: 'out' - name: 'OUTGRESS' - - direction: 'local' - name: 'DROP' - state: rendered -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# -# "rendered": [ -# "set interfaces ethernet eth2 firewall in name 'INGRESS'", -# "set interfaces ethernet eth2 firewall out name 'OUTGRESS'", -# "set interfaces ethernet eth2 firewall local name 'DROP'", -# "set interfaces ethernet eth2 firewall local ipv6-name 'LOCAL'" -# ] - - -""" -RETURN = """ -before: - description: The configuration prior to the model invocation. - returned: always - type: list - sample: > - The configuration returned will always be in the same format - of the parameters above. -after: - description: The resulting configuration model invocation. - returned: when changed - type: list - sample: > - The configuration returned will always be in the same format - of the parameters above. -commands: - description: The set of commands pushed to the remote device. - returned: always - type: list - sample: - - "set interfaces ethernet eth1 firewall local ipv6-name 'V6-LOCAL'" - - "set interfaces ethernet eth3 firewall in name 'INBOUND'" -""" - - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.vyos.argspec.firewall_interfaces.firewall_interfaces import Firewall_interfacesArgs -from ansible.module_utils.network.vyos.config.firewall_interfaces.firewall_interfaces import Firewall_interfaces - - -def main(): - """ - Main entry point for module execution - - :returns: the result form module invocation - """ - required_if = [('state', 'merged', ('config',)), - ('state', 'replaced', ('config',)), - ('state', 'overridden', ('config',)), - ('state', 'parsed', ('running_config',))] - mutually_exclusive = [('config', 'running_config')] - - module = AnsibleModule(argument_spec=Firewall_interfacesArgs.argument_spec, - required_if=required_if, - supports_check_mode=True, - mutually_exclusive=mutually_exclusive) - - result = Firewall_interfaces(module).execute_module() - module.exit_json(**result) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/vyos/vyos_firewall_rules.py b/lib/ansible/modules/network/vyos/vyos_firewall_rules.py deleted file mode 100644 index 59ab876aad..0000000000 --- a/lib/ansible/modules/network/vyos/vyos_firewall_rules.py +++ /dev/null @@ -1,1505 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -############################################# -# WARNING # -############################################# -# -# This file is auto generated by the resource -# module builder playbook. -# -# Do not edit this file manually. -# -# Changes to this file will be over written -# by the resource module builder. -# -# Changes should be made in the model used to -# generate this file or in the resource module -# builder template. -# -############################################# - -""" -The module file for vyos_firewall_rules -""" - -from __future__ import absolute_import, division, print_function -__metaclass__ = type - -ANSIBLE_METADATA = { - 'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'network' -} - -DOCUMENTATION = """ ---- -module: vyos_firewall_rules -version_added: '2.10' -short_description: Manage firewall rule-set attributes on VyOS devices -description: This module manages firewall rule-set attributes on VyOS devices -notes: - - Tested against VyOS 1.1.8 (helium). - - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). -author: - - Rohit Thakur (@rohitthakur2590) -options: - config: - description: A dictionary of Firewall rule-set options. - type: list - elements: dict - suboptions: - afi: - description: - - Specifies the type of rule-set. - type: str - choices: ['ipv4', 'ipv6'] - required: True - rule_sets: - description: - - The Firewall rule-set list. - type: list - elements: dict - suboptions: - name: - description: - - Firewall rule set name. - type: str - default_action: - description: - - Default action for rule-set. - - drop (Drop if no prior rules are hit (default)) - - reject (Drop and notify source if no prior rules are hit) - - accept (Accept if no prior rules are hit) - type: str - choices: ['drop', 'reject', 'accept'] - description: - description: - - Rule set description. - type: str - enable_default_log: - description: - - Option to log packets hitting default-action. - type: bool - rules: - description: - - A ditionary that specifies the rule-set configurations. - type: list - elements: dict - suboptions: - number: - description: - - Rule number. - type: int - required: True - description: - description: - - Description of this rule. - type: str - action: - description: - - Specifying the action. - type: str - choices: ['drop', 'reject', 'accept', 'inspect'] - destination: - description: - - Specifying the destination parameters. - type: dict - suboptions: - address: - description: - - Destination ip address subnet or range. - - IPv4/6 address, subnet or range to match. - - Match everything except the specified address, subnet or range. - - Destination ip address subnet or range. - type: str - group: - description: - - Destination group. - type: dict - suboptions: - address_group: - description: - - Group of addresses. - type: str - network_group: - description: - - Group of networks. - type: str - port_group: - description: - - Group of ports. - type: str - port: - description: - - Multiple destination ports can be specified as a comma-separated list. - - The whole list can also be "negated" using '!'. - - For example:'!22,telnet,http,123,1001-1005'. - type: str - disabled: - description: - - Option to disable firewall rule. - type: bool - fragment: - description: - - IP fragment match. - type: str - choices: ['match-frag', 'match-non-frag'] - icmp: - description: - - ICMP type and code information. - type: dict - suboptions: - type_name: - description: - - ICMP type-name. - type: str - choices: ['any', 'echo-reply', 'destination-unreachable', 'network-unreachable', - 'host-unreachable', 'protocol-unreachable', 'port-unreachable', 'fragmentation-needed', - 'source-route-failed', 'network-unknown', 'host-unknown', 'network-prohibited', - 'host-prohibited', 'TOS-network-unreachable', 'TOS-host-unreachable', - 'communication-prohibited', 'host-precedence-violation', - 'precedence-cutoff', 'source-quench', 'redirect', 'network-redirect', 'host-redirect', - 'TOS-network-redirect', 'TOS-host-redirect', 'echo-request', 'router-advertisement', - 'router-solicitation', 'time-exceeded', 'ttl-zero-during-transit', - 'ttl-zero-during-reassembly', 'parameter-problem', 'ip-header-bad', - 'required-option-missing', 'timestamp-request', 'timestamp-reply', 'address-mask-request', - 'address-mask-reply', 'ping', 'pong', 'ttl-exceeded'] - code: - description: - - ICMP code. - type: int - type: - description: - - ICMP type. - type: int - ipsec: - description: - - Inboud ip sec packets. - type: str - choices: ['match-ipsec', 'match-none'] - limit: - description: - - Rate limit using a token bucket filter. - type: dict - suboptions: - burst: - description: - - Maximum number of packets to allow in excess of rate. - type: int - rate: - description: - - format for rate (integer/time unit). - - any one of second, minute, hour or day may be used to specify time unit. - - eg. 1/second implies rule to be matched at an average of once per second. - type: dict - suboptions: - number: - description: - - This is the integer value. - type: int - unit: - description: - - This is the time unit. - type: str - p2p: - description: - - P2P application packets. - type: list - elements: dict - suboptions: - application: - description: - - Name of the application. - type: str - choices: ['all', 'applejuice', 'bittorrent', 'directconnect', 'edonkey', 'gnutella', 'kazaa'] - protocol: - description: - - Protocol to match (protocol name in /etc/protocols or protocol number or all). - - <text> IP protocol name from /etc/protocols (e.g. "tcp" or "udp"). - - <0-255> IP protocol number. - - tcp_udp Both TCP and UDP. - - all All IP protocols. - - (!)All IP protocols except for the specified name or number. - type: str - recent: - description: - - Parameters for matching recently seen sources. - type: dict - suboptions: - count: - description: - - Source addresses seen more than N times. - type: int - time: - description: - - Source addresses seen in the last N seconds. - type: int - source: - description: - - Source parameters. - type: dict - suboptions: - address: - description: - - Source ip address subnet or range. - - IPv4/6 address, subnet or range to match. - - Match everything except the specified address, subnet or range. - - Source ip address subnet or range. - type: str - group: - description: - - Source group. - type: dict - suboptions: - address_group: - description: - - Group of addresses. - type: str - network_group: - description: - - Group of networks. - type: str - port_group: - description: - - Group of ports. - type: str - port: - description: - - Multiple source ports can be specified as a comma-separated list. - - The whole list can also be "negated" using '!'. - - For example:'!22,telnet,http,123,1001-1005'. - type: str - mac_address: - description: - - <MAC address> MAC address to match. - - <!MAC address> Match everything except the specified MAC address. - type: str - state: - description: - - Session state. - type: dict - suboptions: - established: - description: - - Established state. - type: bool - invalid: - description: - - Invalid state. - type: bool - new: - description: - - New state. - type: bool - related: - description: - - Related state. - type: bool - tcp: - description: - - TCP flags to match. - type: dict - suboptions: - flags: - description: - - TCP flags to be matched. - type: str - time: - description: - - Time to match rule. - type: dict - suboptions: - utc: - description: - - Interpret times for startdate, stopdate, starttime and stoptime to be UTC. - type: bool - monthdays: - description: - - Monthdays to match rule on. - type: str - startdate: - description: - - Date to start matching rule. - type: str - starttime: - description: - - Time of day to start matching rule. - type: str - stopdate: - description: - - Date to stop matching rule. - type: str - stoptime: - description: - - Time of day to stop matching rule. - type: str - weekdays: - description: - - Weekdays to match rule on. - type: str - running_config: - description: - - The module, by default, will connect to the remote device and - retrieve the current running-config to use as a base for comparing - against the contents of source. There are times when it is not - desirable to have the task get the current running-config for - every task in a playbook. The I(running_config) argument allows the - implementer to pass in the configuration to use as the base - config for comparison. This value of this option should be the - output received from device by executing command - C(show configuration commands | grep 'firewall' - type: str - state: - description: - - The state the configuration should be left in - type: str - choices: - - merged - - replaced - - overridden - - deleted - - gathered - - rendered - - parsed - default: merged -""" -EXAMPLES = """ -# Using deleted to delete firewall rules based on rule-set name -# -# Before state -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep firewall -# set firewall group address-group 'inbound' -# set firewall name Downlink default-action 'accept' -# set firewall name Downlink description 'IPv4 INBOUND rule set' -# set firewall name Downlink rule 501 action 'accept' -# set firewall name Downlink rule 501 description 'Rule 501 is configured by Ansible' -# set firewall name Downlink rule 501 ipsec 'match-ipsec' -# set firewall name Downlink rule 502 action 'reject' -# set firewall name Downlink rule 502 description 'Rule 502 is configured by Ansible' -# set firewall name Downlink rule 502 ipsec 'match-ipsec' -# -- name: Delete attributes of given firewall rules. - vyos_firewall_rules: - config: - - afi: ipv4 - rule_sets: - - name: 'Downlink' - state: deleted -# -# -# ------------------------ -# Module Execution Results -# ------------------------ -# -# "before": [ -# { -# "afi": "ipv4", -# "rule_sets": [ -# { -# "default_action": "accept", -# "description": "IPv4 INBOUND rule set", -# "name": "Downlink", -# "rules": [ -# { -# "action": "accept", -# "description": "Rule 501 is configured by Ansible", -# "ipsec": "match-ipsec", -# "number": 501 -# }, -# { -# "action": "reject", -# "description": "Rule 502 is configured by Ansible", -# "ipsec": "match-ipsec", -# "number": 502 -# } -# ] -# } -# ] -# } -# ] -# "commands": [ -# "delete firewall name Downlink" -# ] -# -# "after": [] -# After state -# ------------ -# vyos@vyos# run show configuration commands | grep firewall -# set firewall group address-group 'inbound' - - -# Using deleted to delete all the the firewall rules when provided config is empty -# -# Before state -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep firewall -# set firewall group address-group 'inbound' -# set firewall name Downlink default-action 'accept' -# set firewall name Downlink description 'IPv4 INBOUND rule set' -# set firewall name Downlink rule 501 action 'accept' -# set firewall name Downlink rule 501 description 'Rule 501 is configured by Ansible' -# set firewall name Downlink rule 501 ipsec 'match-ipsec' -# set firewall name Downlink rule 502 action 'reject' -# set firewall name Downlink rule 502 description 'Rule 502 is configured by Ansible' -# set firewall name Downlink rule 502 ipsec 'match-ipsec' -# -- name: Delete attributes of given firewall rules. - vyos_firewall_rules: - config: - state: deleted -# -# -# ------------------------ -# Module Execution Results -# ------------------------ -# -# "before": [ -# { -# "afi": "ipv4", -# "rule_sets": [ -# { -# "default_action": "accept", -# "description": "IPv4 INBOUND rule set", -# "name": "Downlink", -# "rules": [ -# { -# "action": "accept", -# "description": "Rule 501 is configured by Ansible", -# "ipsec": "match-ipsec", -# "number": 501 -# }, -# { -# "action": "reject", -# "description": "Rule 502 is configured by Ansible", -# "ipsec": "match-ipsec", -# "number": 502 -# } -# ] -# } -# ] -# } -# ] -# "commands": [ -# "delete firewall name" -# ] -# -# "after": [] -# After state -# ------------ -# vyos@vyos# run show configuration commands | grep firewall -# set firewall group address-group 'inbound' - - -# Using deleted to delete the the firewall rules based on afi -# -# Before state -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep firewall -# set firewall group address-group 'inbound' -# set firewall name Downlink default-action 'accept' -# set firewall name Downlink description 'IPv4 INBOUND rule set' -# set firewall name Downlink rule 501 action 'accept' -# set firewall name Downlink rule 501 description 'Rule 501 is configured by Ansible' -# set firewall name Downlink rule 501 ipsec 'match-ipsec' -# set firewall name Downlink rule 502 action 'reject' -# set firewall name Downlink rule 502 description 'Rule 502 is configured by Ansible' -# set firewall name Downlink rule 502 ipsec 'match-ipsec' -# -- name: Delete attributes of given firewall rules. - vyos_firewall_rules: - config: - - afi: ipv4 - state: deleted -# -# -# ------------------------ -# Module Execution Results -# ------------------------ -# -# "before": [ -# { -# "afi": "ipv4", -# "rule_sets": [ -# { -# "default_action": "accept", -# "description": "IPv4 INBOUND rule set", -# "name": "Downlink", -# "rules": [ -# { -# "action": "accept", -# "description": "Rule 501 is configured by Ansible", -# "ipsec": "match-ipsec", -# "number": 501 -# }, -# { -# "action": "reject", -# "description": "Rule 502 is configured by Ansible", -# "ipsec": "match-ipsec", -# "number": 502 -# } -# ] -# } -# ] -# } -# ] -# "commands": [ -# "delete firewall name", -# ] -# -# "after": [] -# After state -# ------------ -# vyos@vyos# run show configuration commands | grep firewall -# set firewall group address-group 'inbound' - - - -# Using deleted to delete the the firewall rules based on rule number/id -# -# Before state -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep firewall -# set firewall group address-group 'inbound' -# set firewall name Downlink default-action 'accept' -# set firewall name Downlink description 'IPv4 INBOUND rule set' -# set firewall name Downlink rule 501 action 'accept' -# set firewall name Downlink rule 501 description 'Rule 501 is configured by Ansible' -# set firewall name Downlink rule 501 ipsec 'match-ipsec' -# set firewall name Downlink rule 502 action 'reject' -# set firewall name Downlink rule 502 description 'Rule 502 is configured by Ansible' -# set firewall name Downlink rule 502 ipsec 'match-ipsec' -# -- name: Delete attributes of given firewall rules. - vyos_firewall_rules: - config: - - afi: ipv4 - rule_sets: - - name: 'Downlink' - rules: - - number: 501 - state: deleted -# -# -# ------------------------ -# Module Execution Results -# ------------------------ -# -# "before": [ -# { -# "afi": "ipv4", -# "rule_sets": [ -# { -# "default_action": "accept", -# "description": "IPv4 INBOUND rule set", -# "name": "Downlink", -# "rules": [ -# { -# "action": "accept", -# "description": "Rule 501 is configured by Ansible", -# "ipsec": "match-ipsec", -# "number": 501 -# }, -# { -# "action": "reject", -# "description": "Rule 502 is configured by Ansible", -# "ipsec": "match-ipsec", -# "number": 502 -# } -# ] -# } -# ] -# } -# ] -# "commands": [ -# "delete firewall ipv6-name Downlink rule 501" -# ] -# -# "after": [ -# { -# "afi": "ipv4", -# "rule_sets": [ -# { -# "default_action": "accept", -# "description": "IPv4 INBOUND rule set", -# "name": "Downlink", -# "rules": [ -# { -# "action": "reject", -# "description": "Rule 502 is configured by Ansible", -# "ipsec": "match-ipsec", -# "number": 502 -# } -# ] -# } -# ] -# } -# ] -# After state -# ------------ -# vyos@vyos:~$ show configuration commands| grep firewall -# set firewall group address-group 'inbound' -# set firewall name Downlink default-action 'accept' -# set firewall name Downlink description 'IPv4 INBOUND rule set' -# set firewall name Downlink rule 502 action 'reject' -# set firewall name Downlink rule 502 description 'Rule 502 is configured by Ansible' -# set firewall name Downlink rule 502 ipsec 'match-ipsec' - - -# Using merged -# -# Before state: -# ------------- -# -# vyos@vyos# run show configuration commands | grep firewall -# set firewall group address-group 'inbound' -# -- name: Merge the provided configuration with the exisiting running configuration - vyos_firewall_rules: - config: - - afi: 'ipv6' - rule_sets: - - name: 'UPLINK' - description: 'This is ipv6 specific rule-set' - default_action: 'accept' - rules: - - number: 1 - action: 'accept' - description: 'Fwipv6-Rule 1 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 2 - action: 'accept' - description: 'Fwipv6-Rule 2 is configured by Ansible' - ipsec: 'match-ipsec' - - - afi: 'ipv4' - rule_sets: - - name: 'INBOUND' - description: 'IPv4 INBOUND rule set' - default_action: 'accept' - rules: - - number: 101 - action: 'accept' - description: 'Rule 101 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 102 - action: 'reject' - description: 'Rule 102 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 103 - action: 'accept' - description: 'Rule 103 is configured by Ansible' - destination: - group: - address_group: 'inbound' - source: - address: '192.0.2.0' - state: - established: true - new: false - invalid: false - related: true - state: merged -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# before": [] -# -# "commands": [ -# "set firewall ipv6-name UPLINK default-action 'accept'", -# "set firewall ipv6-name UPLINK description 'This is ipv6 specific rule-set'", -# "set firewall ipv6-name UPLINK rule 1 action 'accept'", -# "set firewall ipv6-name UPLINK rule 1", -# "set firewall ipv6-name UPLINK rule 1 description 'Fwipv6-Rule 1 is configured by Ansible'", -# "set firewall ipv6-name UPLINK rule 1 ipsec 'match-ipsec'", -# "set firewall ipv6-name UPLINK rule 2 action 'accept'", -# "set firewall ipv6-name UPLINK rule 2", -# "set firewall ipv6-name UPLINK rule 2 description 'Fwipv6-Rule 2 is configured by Ansible'", -# "set firewall ipv6-name UPLINK rule 2 ipsec 'match-ipsec'", -# "set firewall name INBOUND default-action 'accept'", -# "set firewall name INBOUND description 'IPv4 INBOUND rule set'", -# "set firewall name INBOUND rule 101 action 'accept'", -# "set firewall name INBOUND rule 101", -# "set firewall name INBOUND rule 101 description 'Rule 101 is configured by Ansible'", -# "set firewall name INBOUND rule 101 ipsec 'match-ipsec'", -# "set firewall name INBOUND rule 102 action 'reject'", -# "set firewall name INBOUND rule 102", -# "set firewall name INBOUND rule 102 description 'Rule 102 is configured by Ansible'", -# "set firewall name INBOUND rule 102 ipsec 'match-ipsec'", -# "set firewall name INBOUND rule 103 description 'Rule 103 is configured by Ansible'", -# "set firewall name INBOUND rule 103 destination group address-group inbound", -# "set firewall name INBOUND rule 103", -# "set firewall name INBOUND rule 103 source address 192.0.2.0", -# "set firewall name INBOUND rule 103 state established enable", -# "set firewall name INBOUND rule 103 state related enable", -# "set firewall name INBOUND rule 103 state invalid disable", -# "set firewall name INBOUND rule 103 state new disable", -# "set firewall name INBOUND rule 103 action 'accept'" -# ] -# -# "after": [ -# { -# "afi": "ipv6", -# "rule_sets": [ -# { -# "default_action": "accept", -# "description": "This is ipv6 specific rule-set", -# "name": "UPLINK", -# "rules": [ -# { -# "action": "accept", -# "description": "Fwipv6-Rule 1 is configured by Ansible", -# "ipsec": "match-ipsec", -# "number": 1 -# }, -# { -# "action": "accept", -# "description": "Fwipv6-Rule 2 is configured by Ansible", -# "ipsec": "match-ipsec", -# "number": 2 -# } -# ] -# } -# ] -# }, -# { -# "afi": "ipv4", -# "rule_sets": [ -# { -# "default_action": "accept", -# "description": "IPv4 INBOUND rule set", -# "name": "INBOUND", -# "rules": [ -# { -# "action": "accept", -# "description": "Rule 101 is configured by Ansible", -# "ipsec": "match-ipsec", -# "number": 101 -# }, -# { -# "action": "reject", -# "description": "Rule 102 is configured by Ansible", -# "ipsec": "match-ipsec", -# "number": 102 -# }, -# { -# "action": "accept", -# "description": "Rule 103 is configured by Ansible", -# "destination": { -# "group": { -# "address_group": "inbound" -# } -# }, -# "number": 103, -# "source": { -# "address": "192.0.2.0" -# }, -# "state": { -# "established": true, -# "invalid": false, -# "new": false, -# "related": true -# } -# } -# ] -# } -# ] -# } -# ] -# -# After state: -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep firewall -# set firewall group address-group 'inbound' -# set firewall ipv6-name UPLINK default-action 'accept' -# set firewall ipv6-name UPLINK description 'This is ipv6 specific rule-set' -# set firewall ipv6-name UPLINK rule 1 action 'accept' -# set firewall ipv6-name UPLINK rule 1 description 'Fwipv6-Rule 1 is configured by Ansible' -# set firewall ipv6-name UPLINK rule 1 ipsec 'match-ipsec' -# set firewall ipv6-name UPLINK rule 2 action 'accept' -# set firewall ipv6-name UPLINK rule 2 description 'Fwipv6-Rule 2 is configured by Ansible' -# set firewall ipv6-name UPLINK rule 2 ipsec 'match-ipsec' -# set firewall name INBOUND default-action 'accept' -# set firewall name INBOUND description 'IPv4 INBOUND rule set' -# set firewall name INBOUND rule 101 action 'accept' -# set firewall name INBOUND rule 101 description 'Rule 101 is configured by Ansible' -# set firewall name INBOUND rule 101 ipsec 'match-ipsec' -# set firewall name INBOUND rule 102 action 'reject' -# set firewall name INBOUND rule 102 description 'Rule 102 is configured by Ansible' -# set firewall name INBOUND rule 102 ipsec 'match-ipsec' -# set firewall name INBOUND rule 103 action 'accept' -# set firewall name INBOUND rule 103 description 'Rule 103 is configured by Ansible' -# set firewall name INBOUND rule 103 destination group address-group 'inbound' -# set firewall name INBOUND rule 103 source address '192.0.2.0' -# set firewall name INBOUND rule 103 state established 'enable' -# set firewall name INBOUND rule 103 state invalid 'disable' -# set firewall name INBOUND rule 103 state new 'disable' -# set firewall name INBOUND rule 103 state related 'enable' - - -# Using replaced -# -# Before state: -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep firewall -# set firewall group address-group 'inbound' -# set firewall ipv6-name UPLINK default-action 'accept' -# set firewall ipv6-name UPLINK description 'This is ipv6 specific rule-set' -# set firewall ipv6-name UPLINK rule 1 action 'accept' -# set firewall ipv6-name UPLINK rule 1 description 'Fwipv6-Rule 1 is configured by Ansible' -# set firewall ipv6-name UPLINK rule 1 ipsec 'match-ipsec' -# set firewall ipv6-name UPLINK rule 2 action 'accept' -# set firewall ipv6-name UPLINK rule 2 description 'Fwipv6-Rule 2 is configured by Ansible' -# set firewall ipv6-name UPLINK rule 2 ipsec 'match-ipsec' -# set firewall name INBOUND default-action 'accept' -# set firewall name INBOUND description 'IPv4 INBOUND rule set' -# set firewall name INBOUND rule 101 action 'accept' -# set firewall name INBOUND rule 101 description 'Rule 101 is configured by Ansible' -# set firewall name INBOUND rule 101 ipsec 'match-ipsec' -# set firewall name INBOUND rule 102 action 'reject' -# set firewall name INBOUND rule 102 description 'Rule 102 is configured by Ansible' -# set firewall name INBOUND rule 102 ipsec 'match-ipsec' -# set firewall name INBOUND rule 103 action 'accept' -# set firewall name INBOUND rule 103 description 'Rule 103 is configured by Ansible' -# set firewall name INBOUND rule 103 destination group address-group 'inbound' -# set firewall name INBOUND rule 103 source address '192.0.2.0' -# set firewall name INBOUND rule 103 state established 'enable' -# set firewall name INBOUND rule 103 state invalid 'disable' -# set firewall name INBOUND rule 103 state new 'disable' -# set firewall name INBOUND rule 103 state related 'enable' -# -- name: Replace device configurations of listed firewall rules with provided configurations - vyos_firewall_rules: - config: - - afi: 'ipv6' - rule_sets: - - name: 'UPLINK' - description: 'This is ipv6 specific rule-set' - default_action: 'accept' - - afi: 'ipv4' - rule_sets: - - name: 'INBOUND' - description: 'IPv4 INBOUND rule set' - default_action: 'accept' - rules: - - number: 101 - action: 'accept' - description: 'Rule 101 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 104 - action: 'reject' - description: 'Rule 104 is configured by Ansible' - ipsec: 'match-none' - state: replaced -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# "before": [ -# { -# "afi": "ipv6", -# "rule_sets": [ -# { -# "default_action": "accept", -# "description": "This is ipv6 specific rule-set", -# "name": "UPLINK", -# "rules": [ -# { -# "action": "accept", -# "description": "Fwipv6-Rule 1 is configured by Ansible", -# "ipsec": "match-ipsec", -# "number": 1 -# }, -# { -# "action": "accept", -# "description": "Fwipv6-Rule 2 is configured by Ansible", -# "ipsec": "match-ipsec", -# "number": 2 -# } -# ] -# } -# ] -# }, -# { -# "afi": "ipv4", -# "rule_sets": [ -# { -# "default_action": "accept", -# "description": "IPv4 INBOUND rule set", -# "name": "INBOUND", -# "rules": [ -# { -# "action": "accept", -# "description": "Rule 101 is configured by Ansible", -# "ipsec": "match-ipsec", -# "number": 101 -# }, -# { -# "action": "reject", -# "description": "Rule 102 is configured by Ansible", -# "ipsec": "match-ipsec", -# "number": 102 -# }, -# { -# "action": "accept", -# "description": "Rule 103 is configured by Ansible", -# "destination": { -# "group": { -# "address_group": "inbound" -# } -# }, -# "number": 103, -# "source": { -# "address": "192.0.2.0" -# }, -# "state": { -# "established": true, -# "invalid": false, -# "new": false, -# "related": true -# } -# } -# ] -# } -# ] -# } -# ] -# -# "commands": [ -# "delete firewall ipv6-name UPLINK rule 1", -# "delete firewall ipv6-name UPLINK rule 2", -# "delete firewall name INBOUND rule 102", -# "delete firewall name INBOUND rule 103", -# "set firewall name INBOUND rule 104 action 'reject'", -# "set firewall name INBOUND rule 104 description 'Rule 104 is configured by Ansible'", -# "set firewall name INBOUND rule 104", -# "set firewall name INBOUND rule 104 ipsec 'match-none'" -# ] -# -# "after": [ -# { -# "afi": "ipv6", -# "rule_sets": [ -# { -# "default_action": "accept", -# "description": "This is ipv6 specific rule-set", -# "name": "UPLINK" -# } -# ] -# }, -# { -# "afi": "ipv4", -# "rule_sets": [ -# { -# "default_action": "accept", -# "description": "IPv4 INBOUND rule set", -# "name": "INBOUND", -# "rules": [ -# { -# "action": "accept", -# "description": "Rule 101 is configured by Ansible", -# "ipsec": "match-ipsec", -# "number": 101 -# }, -# { -# "action": "reject", -# "description": "Rule 104 is configured by Ansible", -# "ipsec": "match-none", -# "number": 104 -# } -# ] -# } -# ] -# } -# ] -# -# After state: -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep firewall -# set firewall group address-group 'inbound' -# set firewall ipv6-name UPLINK default-action 'accept' -# set firewall ipv6-name UPLINK description 'This is ipv6 specific rule-set' -# set firewall name INBOUND default-action 'accept' -# set firewall name INBOUND description 'IPv4 INBOUND rule set' -# set firewall name INBOUND rule 101 action 'accept' -# set firewall name INBOUND rule 101 description 'Rule 101 is configured by Ansible' -# set firewall name INBOUND rule 101 ipsec 'match-ipsec' -# set firewall name INBOUND rule 104 action 'reject' -# set firewall name INBOUND rule 104 description 'Rule 104 is configured by Ansible' -# set firewall name INBOUND rule 104 ipsec 'match-none' - - -# Using overridden -# -# Before state -# -------------- -# -# vyos@vyos:~$ show configuration commands| grep firewall -# set firewall group address-group 'inbound' -# set firewall ipv6-name UPLINK default-action 'accept' -# set firewall ipv6-name UPLINK description 'This is ipv6 specific rule-set' -# set firewall name INBOUND default-action 'accept' -# set firewall name INBOUND description 'IPv4 INBOUND rule set' -# set firewall name INBOUND rule 101 action 'accept' -# set firewall name INBOUND rule 101 description 'Rule 101 is configured by Ansible' -# set firewall name INBOUND rule 101 ipsec 'match-ipsec' -# set firewall name INBOUND rule 104 action 'reject' -# set firewall name INBOUND rule 104 description 'Rule 104 is configured by Ansible' -# set firewall name INBOUND rule 104 ipsec 'match-none' -# -- name: Overrides all device configuration with provided configuration - vyos_firewall_rules: - config: - - afi: 'ipv4' - rule_sets: - - name: 'Downlink' - description: 'IPv4 INBOUND rule set' - default_action: 'accept' - rules: - - number: 501 - action: 'accept' - description: 'Rule 501 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 502 - action: 'reject' - description: 'Rule 502 is configured by Ansible' - ipsec: 'match-ipsec' - state: overridden -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# "before": [ -# { -# "afi": "ipv6", -# "rule_sets": [ -# { -# "default_action": "accept", -# "description": "This is ipv6 specific rule-set", -# "name": "UPLINK" -# } -# ] -# }, -# { -# "afi": "ipv4", -# "rule_sets": [ -# { -# "default_action": "accept", -# "description": "IPv4 INBOUND rule set", -# "name": "INBOUND", -# "rules": [ -# { -# "action": "accept", -# "description": "Rule 101 is configured by Ansible", -# "ipsec": "match-ipsec", -# "number": 101 -# }, -# { -# "action": "reject", -# "description": "Rule 104 is configured by Ansible", -# "ipsec": "match-none", -# "number": 104 -# } -# ] -# } -# ] -# } -# ] -# -# "commands": [ -# "delete firewall ipv6-name UPLINK", -# "delete firewall name INBOUND", -# "set firewall name Downlink default-action 'accept'", -# "set firewall name Downlink description 'IPv4 INBOUND rule set'", -# "set firewall name Downlink rule 501 action 'accept'", -# "set firewall name Downlink rule 501", -# "set firewall name Downlink rule 501 description 'Rule 501 is configured by Ansible'", -# "set firewall name Downlink rule 501 ipsec 'match-ipsec'", -# "set firewall name Downlink rule 502 action 'reject'", -# "set firewall name Downlink rule 502", -# "set firewall name Downlink rule 502 description 'Rule 502 is configured by Ansible'", -# "set firewall name Downlink rule 502 ipsec 'match-ipsec'" -# -# -# "after": [ -# { -# "afi": "ipv4", -# "rule_sets": [ -# { -# "default_action": "accept", -# "description": "IPv4 INBOUND rule set", -# "name": "Downlink", -# "rules": [ -# { -# "action": "accept", -# "description": "Rule 501 is configured by Ansible", -# "ipsec": "match-ipsec", -# "number": 501 -# }, -# { -# "action": "reject", -# "description": "Rule 502 is configured by Ansible", -# "ipsec": "match-ipsec", -# "number": 502 -# } -# ] -# } -# ] -# } -# ] -# -# -# After state -# ------------ -# -# vyos@vyos:~$ show configuration commands| grep firewall -# set firewall group address-group 'inbound' -# set firewall name Downlink default-action 'accept' -# set firewall name Downlink description 'IPv4 INBOUND rule set' -# set firewall name Downlink rule 501 action 'accept' -# set firewall name Downlink rule 501 description 'Rule 501 is configured by Ansible' -# set firewall name Downlink rule 501 ipsec 'match-ipsec' -# set firewall name Downlink rule 502 action 'reject' -# set firewall name Downlink rule 502 description 'Rule 502 is configured by Ansible' -# set firewall name Downlink rule 502 ipsec 'match-ipsec' - - -# Using gathered -# -# Before state: -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep firewall -# set firewall group address-group 'inbound' -# set firewall ipv6-name UPLINK default-action 'accept' -# set firewall ipv6-name UPLINK description 'This is ipv6 specific rule-set' -# set firewall ipv6-name UPLINK rule 1 action 'accept' -# set firewall ipv6-name UPLINK rule 1 description 'Fwipv6-Rule 1 is configured by Ansible' -# set firewall ipv6-name UPLINK rule 1 ipsec 'match-ipsec' -# set firewall ipv6-name UPLINK rule 2 action 'accept' -# set firewall ipv6-name UPLINK rule 2 description 'Fwipv6-Rule 2 is configured by Ansible' -# set firewall ipv6-name UPLINK rule 2 ipsec 'match-ipsec' -# set firewall name INBOUND default-action 'accept' -# set firewall name INBOUND description 'IPv4 INBOUND rule set' -# set firewall name INBOUND rule 101 action 'accept' -# set firewall name INBOUND rule 101 description 'Rule 101 is configured by Ansible' -# set firewall name INBOUND rule 101 ipsec 'match-ipsec' -# set firewall name INBOUND rule 102 action 'reject' -# set firewall name INBOUND rule 102 description 'Rule 102 is configured by Ansible' -# set firewall name INBOUND rule 102 ipsec 'match-ipsec' -# set firewall name INBOUND rule 103 action 'accept' -# set firewall name INBOUND rule 103 description 'Rule 103 is configured by Ansible' -# set firewall name INBOUND rule 103 destination group address-group 'inbound' -# set firewall name INBOUND rule 103 source address '192.0.2.0' -# set firewall name INBOUND rule 103 state established 'enable' -# set firewall name INBOUND rule 103 state invalid 'disable' -# set firewall name INBOUND rule 103 state new 'disable' -# set firewall name INBOUND rule 103 state related 'enable' -# -- name: Gather listed firewall rules with provided configurations - vyos_firewall_rules: - config: - state: gathered -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# "gathered": [ -# { -# "afi": "ipv6", -# "rule_sets": [ -# { -# "default_action": "accept", -# "description": "This is ipv6 specific rule-set", -# "name": "UPLINK", -# "rules": [ -# { -# "action": "accept", -# "description": "Fwipv6-Rule 1 is configured by Ansible", -# "ipsec": "match-ipsec", -# "number": 1 -# }, -# { -# "action": "accept", -# "description": "Fwipv6-Rule 2 is configured by Ansible", -# "ipsec": "match-ipsec", -# "number": 2 -# } -# ] -# } -# ] -# }, -# { -# "afi": "ipv4", -# "rule_sets": [ -# { -# "default_action": "accept", -# "description": "IPv4 INBOUND rule set", -# "name": "INBOUND", -# "rules": [ -# { -# "action": "accept", -# "description": "Rule 101 is configured by Ansible", -# "ipsec": "match-ipsec", -# "number": 101 -# }, -# { -# "action": "reject", -# "description": "Rule 102 is configured by Ansible", -# "ipsec": "match-ipsec", -# "number": 102 -# }, -# { -# "action": "accept", -# "description": "Rule 103 is configured by Ansible", -# "destination": { -# "group": { -# "address_group": "inbound" -# } -# }, -# "number": 103, -# "source": { -# "address": "192.0.2.0" -# }, -# "state": { -# "established": true, -# "invalid": false, -# "new": false, -# "related": true -# } -# } -# ] -# } -# ] -# } -# ] -# -# -# After state: -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep firewall -# set firewall group address-group 'inbound' -# set firewall ipv6-name UPLINK default-action 'accept' -# set firewall ipv6-name UPLINK description 'This is ipv6 specific rule-set' -# set firewall ipv6-name UPLINK rule 1 action 'accept' -# set firewall ipv6-name UPLINK rule 1 description 'Fwipv6-Rule 1 is configured by Ansible' -# set firewall ipv6-name UPLINK rule 1 ipsec 'match-ipsec' -# set firewall ipv6-name UPLINK rule 2 action 'accept' -# set firewall ipv6-name UPLINK rule 2 description 'Fwipv6-Rule 2 is configured by Ansible' -# set firewall ipv6-name UPLINK rule 2 ipsec 'match-ipsec' -# set firewall name INBOUND default-action 'accept' -# set firewall name INBOUND description 'IPv4 INBOUND rule set' -# set firewall name INBOUND rule 101 action 'accept' -# set firewall name INBOUND rule 101 description 'Rule 101 is configured by Ansible' -# set firewall name INBOUND rule 101 ipsec 'match-ipsec' -# set firewall name INBOUND rule 102 action 'reject' -# set firewall name INBOUND rule 102 description 'Rule 102 is configured by Ansible' -# set firewall name INBOUND rule 102 ipsec 'match-ipsec' -# set firewall name INBOUND rule 103 action 'accept' -# set firewall name INBOUND rule 103 description 'Rule 103 is configured by Ansible' -# set firewall name INBOUND rule 103 destination group address-group 'inbound' -# set firewall name INBOUND rule 103 source address '192.0.2.0' -# set firewall name INBOUND rule 103 state established 'enable' -# set firewall name INBOUND rule 103 state invalid 'disable' -# set firewall name INBOUND rule 103 state new 'disable' -# set firewall name INBOUND rule 103 state related 'enable' - - -# Using rendered -# -# -- name: Render the commands for provided configuration - vyos_firewall_rules: - config: - - afi: 'ipv6' - rule_sets: - - name: 'UPLINK' - description: 'This is ipv6 specific rule-set' - default_action: 'accept' - - afi: 'ipv4' - rule_sets: - - name: 'INBOUND' - description: 'IPv4 INBOUND rule set' - default_action: 'accept' - rules: - - number: 101 - action: 'accept' - description: 'Rule 101 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 102 - action: 'reject' - description: 'Rule 102 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 103 - action: 'accept' - description: 'Rule 103 is configured by Ansible' - destination: - group: - address_group: 'inbound' - source: - address: '192.0.2.0' - state: - established: true - new: false - invalid: false - related: true - state: rendered -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# -# "rendered": [ -# "set firewall ipv6-name UPLINK default-action 'accept'", -# "set firewall ipv6-name UPLINK description 'This is ipv6 specific rule-set'", -# "set firewall name INBOUND default-action 'accept'", -# "set firewall name INBOUND description 'IPv4 INBOUND rule set'", -# "set firewall name INBOUND rule 101 action 'accept'", -# "set firewall name INBOUND rule 101", -# "set firewall name INBOUND rule 101 description 'Rule 101 is configured by Ansible'", -# "set firewall name INBOUND rule 101 ipsec 'match-ipsec'", -# "set firewall name INBOUND rule 102 action 'reject'", -# "set firewall name INBOUND rule 102", -# "set firewall name INBOUND rule 102 description 'Rule 102 is configured by Ansible'", -# "set firewall name INBOUND rule 102 ipsec 'match-ipsec'", -# "set firewall name INBOUND rule 103 description 'Rule 103 is configured by Ansible'", -# "set firewall name INBOUND rule 103 destination group address-group inbound", -# "set firewall name INBOUND rule 103", -# "set firewall name INBOUND rule 103 source address 192.0.2.0", -# "set firewall name INBOUND rule 103 state established enable", -# "set firewall name INBOUND rule 103 state related enable", -# "set firewall name INBOUND rule 103 state invalid disable", -# "set firewall name INBOUND rule 103 state new disable", -# "set firewall name INBOUND rule 103 action 'accept'" -# ] - - -# Using parsed -# -# -- name: Render the commands for provided configuration - vyos_firewall_rules: - running_config: - "set firewall group address-group 'inbound' - set firewall name Downlink default-action 'accept' - set firewall name Downlink description 'IPv4 INBOUND rule set' - set firewall name Downlink rule 501 action 'accept' - set firewall name Downlink rule 501 description 'Rule 501 is configured by Ansible' - set firewall name Downlink rule 501 ipsec 'match-ipsec' - set firewall name Downlink rule 502 action 'reject' - set firewall name Downlink rule 502 description 'Rule 502 is configured by Ansible' - set firewall name Downlink rule 502 ipsec 'match-ipsec'" - state: parsed -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# -# "parsed": [ -# { -# "afi": "ipv4", -# "rule_sets": [ -# { -# "default_action": "accept", -# "description": "IPv4 INBOUND rule set", -# "name": "Downlink", -# "rules": [ -# { -# "action": "accept", -# "description": "Rule 501 is configured by Ansible", -# "ipsec": "match-ipsec", -# "number": 501 -# }, -# { -# "action": "reject", -# "description": "Rule 502 is configured by Ansible", -# "ipsec": "match-ipsec", -# "number": 502 -# } -# ] -# } -# ] -# } -# ] - - -""" -RETURN = """ -before: - description: The configuration prior to the model invocation. - returned: always - type: list - sample: > - The configuration returned will always be in the same format - of the parameters above. -after: - description: The resulting configuration model invocation. - returned: when changed - type: list - sample: > - The configuration returned will always be in the same format - of the parameters above. -commands: - description: The set of commands pushed to the remote device. - returned: always - type: list - sample: - - "set firewall name Downlink default-action 'accept'" - - "set firewall name Downlink description 'IPv4 INBOUND rule set'" - - "set firewall name Downlink rule 501 action 'accept'" - - "set firewall name Downlink rule 502 description 'Rule 502 is configured by Ansible'" - - "set firewall name Downlink rule 502 ipsec 'match-ipsec'" -""" - - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.vyos.argspec.firewall_rules.firewall_rules import Firewall_rulesArgs -from ansible.module_utils.network.vyos.config.firewall_rules.firewall_rules import Firewall_rules - - -def main(): - """ - Main entry point for module execution - :returns: the result form module invocation - """ - required_if = [('state', 'merged', ('config',)), - ('state', 'replaced', ('config',)), - ('state', 'overridden', ('config',)), - ('state', 'parsed', ('running_config',))] - mutually_exclusive = [('config', 'running_config')] - - module = AnsibleModule(argument_spec=Firewall_rulesArgs.argument_spec, - required_if=required_if, - supports_check_mode=True, - mutually_exclusive=mutually_exclusive) - result = Firewall_rules(module).execute_module() - module.exit_json(**result) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/vyos/vyos_interfaces.py b/lib/ansible/modules/network/vyos/vyos_interfaces.py deleted file mode 100644 index d0be6f672b..0000000000 --- a/lib/ansible/modules/network/vyos/vyos_interfaces.py +++ /dev/null @@ -1,879 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -############################################# -# WARNING # -############################################# -# -# This file is auto generated by the resource -# module builder playbook. -# -# Do not edit this file manually. -# -# Changes to this file will be over written -# by the resource module builder. -# -# Changes should be made in the model used to -# generate this file or in the resource module -# builder template. -# -############################################# - -""" -The module file for vyos_interfaces -""" - -from __future__ import absolute_import, division, print_function -__metaclass__ = type - -ANSIBLE_METADATA = { - 'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'network' -} - -DOCUMENTATION = """ ---- -module: vyos_interfaces -version_added: 2.9 -short_description: Manages interface attributes of VyOS network devices. -description: - - This module manages the interface attributes on VyOS network devices. - - This module supports managing base attributes of Ethernet, Bonding, - VXLAN, Loopback and Virtual Tunnel Interfaces. -notes: - - Tested against VyOS 1.1.8 (helium). - - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). -author: Nilashish Chakraborty (@nilashishc) -options: - config: - description: The provided interfaces configuration. - type: list - suboptions: - name: - description: - - Full name of the interface, e.g. eth0, eth1, bond0, vti1, vxlan2. - type: str - required: True - description: - description: - - Interface description. - type: str - duplex: - description: - - Interface duplex mode. - - Applicable for Ethernet interfaces only. - choices: ['full', 'half', 'auto'] - type: str - enabled: - default: True - description: - - Administrative state of the interface. - - Set the value to C(true) to administratively enable - the interface or C(false) to disable it. - type: bool - mtu: - description: - - MTU for a specific interface. Refer to vendor documentation for valid values. - - Applicable for Ethernet, Bonding, VXLAN and Virtual Tunnel interfaces. - type: int - speed: - description: - - Interface link speed. - - Applicable for Ethernet interfaces only. - type: str - choices: ['auto', '10', '100', '1000', '2500', '10000'] - vifs: - description: - - Virtual sub-interfaces related configuration. - - 802.1Q VLAN interfaces are represented as virtual sub-interfaces in VyOS. - type: list - suboptions: - vlan_id: - description: - - Identifier for the virtual sub-interface. - type: int - description: - description: - - Virtual sub-interface description. - type: str - enabled: - description: - - Administrative state of the virtual sub-interface. - - Set the value to C(true) to administratively enable - the interface or C(false) to disable it. - type: bool - default: True - mtu: - description: - - MTU for the virtual sub-interface. - - Refer to vendor documentation for valid values. - type: int - state: - description: - - The state of the configuration after module completion. - type: str - choices: - - merged - - replaced - - overridden - - deleted - default: merged -""" -EXAMPLES = """ -# Using merged -# -# ------------- -# Before state: -# ------------- -# -# vyos@vyos:~$ show configuration commands | grep interfaces -# set interfaces ethernet eth0 address 'dhcp' -# set interfaces ethernet eth0 address 'dhcpv6' -# set interfaces ethernet eth0 duplex 'auto' -# set interfaces ethernet eth0 hw-id '08:00:27:30:f0:22' -# set interfaces ethernet eth0 smp-affinity 'auto' -# set interfaces ethernet eth0 speed 'auto' -# set interfaces ethernet eth1 hw-id '08:00:27:ea:0f:b9' -# set interfaces ethernet eth1 smp-affinity 'auto' -# set interfaces ethernet eth2 hw-id '08:00:27:c2:98:23' -# set interfaces ethernet eth2 smp-affinity 'auto' -# set interfaces ethernet eth3 hw-id '08:00:27:43:70:8c' -# set interfaces loopback lo - -- name: Merge provided configuration with device configuration - vyos_interfaces: - config: - - name: eth2 - description: 'Configured by Ansible' - enabled: True - vifs: - - vlan_id: 200 - description: "VIF 200 - ETH2" - - - name: eth3 - description: 'Configured by Ansible' - mtu: 1500 - - - name: bond1 - description: 'Bond - 1' - mtu: 1200 - - - name: vti2 - description: 'VTI - 2' - enabled: false - state: merged -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# "before": [ -# { -# "enabled": true, -# "name": "lo" -# }, -# { -# "enabled": true, -# "name": "eth3" -# }, -# { -# "enabled": true, -# "name": "eth2" -# }, -# { -# "enabled": true, -# "name": "eth1" -# }, -# { -# "duplex": "auto", -# "enabled": true, -# "name": "eth0", -# "speed": "auto" -# } -# ] -# -# "commands": [ -# "set interfaces ethernet eth2 description 'Configured by Ansible'", -# "set interfaces ethernet eth2 vif 200", -# "set interfaces ethernet eth2 vif 200 description 'VIF 200 - ETH2'", -# "set interfaces ethernet eth3 description 'Configured by Ansible'", -# "set interfaces ethernet eth3 mtu '1500'", -# "set interfaces bonding bond1", -# "set interfaces bonding bond1 description 'Bond - 1'", -# "set interfaces bonding bond1 mtu '1200'", -# "set interfaces vti vti2", -# "set interfaces vti vti2 description 'VTI - 2'", -# "set interfaces vti vti2 disable" -# ] -# -# "after": [ -# { -# "description": "Bond - 1", -# "enabled": true, -# "mtu": 1200, -# "name": "bond1" -# }, -# { -# "enabled": true, -# "name": "lo" -# }, -# { -# "description": "VTI - 2", -# "enabled": false, -# "name": "vti2" -# }, -# { -# "description": "Configured by Ansible", -# "enabled": true, -# "mtu": 1500, -# "name": "eth3" -# }, -# { -# "description": "Configured by Ansible", -# "enabled": true, -# "name": "eth2", -# "vifs": [ -# { -# "description": "VIF 200 - ETH2", -# "enabled": true, -# "vlan_id": "200" -# } -# ] -# }, -# { -# "enabled": true, -# "name": "eth1" -# }, -# { -# "duplex": "auto", -# "enabled": true, -# "name": "eth0", -# "speed": "auto" -# } -# ] -# -# -# ------------- -# After state: -# ------------- -# -# vyos@vyos:~$ show configuration commands | grep interfaces -# set interfaces bonding bond1 description 'Bond - 1' -# set interfaces bonding bond1 mtu '1200' -# set interfaces ethernet eth0 address 'dhcp' -# set interfaces ethernet eth0 address 'dhcpv6' -# set interfaces ethernet eth0 duplex 'auto' -# set interfaces ethernet eth0 hw-id '08:00:27:30:f0:22' -# set interfaces ethernet eth0 smp-affinity 'auto' -# set interfaces ethernet eth0 speed 'auto' -# set interfaces ethernet eth1 hw-id '08:00:27:ea:0f:b9' -# set interfaces ethernet eth1 smp-affinity 'auto' -# set interfaces ethernet eth2 description 'Configured by Ansible' -# set interfaces ethernet eth2 hw-id '08:00:27:c2:98:23' -# set interfaces ethernet eth2 smp-affinity 'auto' -# set interfaces ethernet eth2 vif 200 description 'VIF 200 - ETH2' -# set interfaces ethernet eth3 description 'Configured by Ansible' -# set interfaces ethernet eth3 hw-id '08:00:27:43:70:8c' -# set interfaces ethernet eth3 mtu '1500' -# set interfaces loopback lo -# set interfaces vti vti2 description 'VTI - 2' -# set interfaces vti vti2 disable -# - - -# Using replaced -# -# ------------- -# Before state: -# ------------- -# -# vyos:~$ show configuration commands | grep eth -# set interfaces bonding bond1 description 'Bond - 1' -# set interfaces bonding bond1 mtu '1400' -# set interfaces ethernet eth0 address 'dhcp' -# set interfaces ethernet eth0 description 'Management Interface for the Appliance' -# set interfaces ethernet eth0 duplex 'auto' -# set interfaces ethernet eth0 hw-id '08:00:27:f3:6c:b5' -# set interfaces ethernet eth0 smp_affinity 'auto' -# set interfaces ethernet eth0 speed 'auto' -# set interfaces ethernet eth1 description 'Configured by Ansible Eng Team' -# set interfaces ethernet eth1 duplex 'full' -# set interfaces ethernet eth1 hw-id '08:00:27:ad:ef:65' -# set interfaces ethernet eth1 smp_affinity 'auto' -# set interfaces ethernet eth1 speed '100' -# set interfaces ethernet eth2 description 'Configured by Ansible' -# set interfaces ethernet eth2 duplex 'full' -# set interfaces ethernet eth2 hw-id '08:00:27:ab:4e:79' -# set interfaces ethernet eth2 mtu '500' -# set interfaces ethernet eth2 smp_affinity 'auto' -# set interfaces ethernet eth2 speed '100' -# set interfaces ethernet eth2 vif 200 description 'Configured by Ansible' -# set interfaces ethernet eth3 description 'Configured by Ansible' -# set interfaces ethernet eth3 duplex 'full' -# set interfaces ethernet eth3 hw-id '08:00:27:17:3c:85' -# set interfaces ethernet eth3 mtu '1500' -# set interfaces ethernet eth3 smp_affinity 'auto' -# set interfaces ethernet eth3 speed '100' -# set interfaces loopback lo -# -# -- name: Replace device configurations of listed interfaces with provided configurations - vyos_interfaces: - config: - - name: eth2 - description: "Replaced by Ansible" - - - name: eth3 - description: "Replaced by Ansible" - - - name: eth1 - description: "Replaced by Ansible" - state: replaced -# -# -# ----------------------- -# Module Execution Result -# ----------------------- -# -# "before": [ -# { -# "description": "Bond - 1", -# "enabled": true, -# "mtu": 1400, -# "name": "bond1" -# }, -# { -# "enabled": true, -# "name": "lo" -# }, -# { -# "description": "Configured by Ansible", -# "duplex": "full", -# "enabled": true, -# "mtu": 1500, -# "name": "eth3", -# "speed": "100" -# }, -# { -# "description": "Configured by Ansible", -# "duplex": "full", -# "enabled": true, -# "mtu": 500, -# "name": "eth2", -# "speed": "100", -# "vifs": [ -# { -# "description": "VIF 200 - ETH2", -# "enabled": true, -# "vlan_id": "200" -# } -# ] -# }, -# { -# "description": "Configured by Ansible Eng Team", -# "duplex": "full", -# "enabled": true, -# "name": "eth1", -# "speed": "100" -# }, -# { -# "description": "Management Interface for the Appliance", -# "duplex": "auto", -# "enabled": true, -# "name": "eth0", -# "speed": "auto" -# } -# ] -# -# "commands": [ -# "delete interfaces ethernet eth2 speed", -# "delete interfaces ethernet eth2 duplex", -# "delete interfaces ethernet eth2 mtu", -# "delete interfaces ethernet eth2 vif 200 description", -# "set interfaces ethernet eth2 description 'Replaced by Ansible'", -# "delete interfaces ethernet eth3 speed", -# "delete interfaces ethernet eth3 duplex", -# "delete interfaces ethernet eth3 mtu", -# "set interfaces ethernet eth3 description 'Replaced by Ansible'", -# "delete interfaces ethernet eth1 speed", -# "delete interfaces ethernet eth1 duplex", -# "set interfaces ethernet eth1 description 'Replaced by Ansible'" -# ] -# -# "after": [ -# { -# "description": "Bond - 1", -# "enabled": true, -# "mtu": 1400, -# "name": "bond1" -# }, -# { -# "enabled": true, -# "name": "lo" -# }, -# { -# "description": "Replaced by Ansible", -# "enabled": true, -# "name": "eth3" -# }, -# { -# "description": "Replaced by Ansible", -# "enabled": true, -# "name": "eth2", -# "vifs": [ -# { -# "enabled": true, -# "vlan_id": "200" -# } -# ] -# }, -# { -# "description": "Replaced by Ansible", -# "enabled": true, -# "name": "eth1" -# }, -# { -# "description": "Management Interface for the Appliance", -# "duplex": "auto", -# "enabled": true, -# "name": "eth0", -# "speed": "auto" -# } -# ] -# -# -# ------------- -# After state: -# ------------- -# -# vyos@vyos:~$ show configuration commands | grep interfaces -# set interfaces bonding bond1 description 'Bond - 1' -# set interfaces bonding bond1 mtu '1400' -# set interfaces ethernet eth0 address 'dhcp' -# set interfaces ethernet eth0 address 'dhcpv6' -# set interfaces ethernet eth0 description 'Management Interface for the Appliance' -# set interfaces ethernet eth0 duplex 'auto' -# set interfaces ethernet eth0 hw-id '08:00:27:30:f0:22' -# set interfaces ethernet eth0 smp-affinity 'auto' -# set interfaces ethernet eth0 speed 'auto' -# set interfaces ethernet eth1 description 'Replaced by Ansible' -# set interfaces ethernet eth1 hw-id '08:00:27:ea:0f:b9' -# set interfaces ethernet eth1 smp-affinity 'auto' -# set interfaces ethernet eth2 description 'Replaced by Ansible' -# set interfaces ethernet eth2 hw-id '08:00:27:c2:98:23' -# set interfaces ethernet eth2 smp-affinity 'auto' -# set interfaces ethernet eth2 vif 200 -# set interfaces ethernet eth3 description 'Replaced by Ansible' -# set interfaces ethernet eth3 hw-id '08:00:27:43:70:8c' -# set interfaces loopback lo -# -# -# Using overridden -# -# -# -------------- -# Before state -# -------------- -# -# vyos@vyos:~$ show configuration commands | grep interfaces -# set interfaces ethernet eth0 address 'dhcp' -# set interfaces ethernet eth0 address 'dhcpv6' -# set interfaces ethernet eth0 description 'Ethernet Interface - 0' -# set interfaces ethernet eth0 duplex 'auto' -# set interfaces ethernet eth0 hw-id '08:00:27:30:f0:22' -# set interfaces ethernet eth0 mtu '1200' -# set interfaces ethernet eth0 smp-affinity 'auto' -# set interfaces ethernet eth0 speed 'auto' -# set interfaces ethernet eth1 description 'Configured by Ansible Eng Team' -# set interfaces ethernet eth1 hw-id '08:00:27:ea:0f:b9' -# set interfaces ethernet eth1 mtu '100' -# set interfaces ethernet eth1 smp-affinity 'auto' -# set interfaces ethernet eth1 vif 100 description 'VIF 100 - ETH1' -# set interfaces ethernet eth1 vif 100 disable -# set interfaces ethernet eth2 description 'Configured by Ansible Team (Admin Down)' -# set interfaces ethernet eth2 disable -# set interfaces ethernet eth2 hw-id '08:00:27:c2:98:23' -# set interfaces ethernet eth2 mtu '600' -# set interfaces ethernet eth2 smp-affinity 'auto' -# set interfaces ethernet eth3 description 'Configured by Ansible Network' -# set interfaces ethernet eth3 hw-id '08:00:27:43:70:8c' -# set interfaces loopback lo -# set interfaces vti vti1 description 'Virtual Tunnel Interface - 1' -# set interfaces vti vti1 mtu '68' -# -# -- name: Overrides all device configuration with provided configuration - vyos_interfaces: - config: - - name: eth0 - description: Outbound Interface For The Appliance - speed: auto - duplex: auto - - - name: eth2 - speed: auto - duplex: auto - - - name: eth3 - mtu: 1200 - state: overridden -# -# -# ------------------------ -# Module Execution Result -# ------------------------ -# -# "before": [ -# { -# "enabled": true, -# "name": "lo" -# }, -# { -# "description": "Virtual Tunnel Interface - 1", -# "enabled": true, -# "mtu": 68, -# "name": "vti1" -# }, -# { -# "description": "Configured by Ansible Network", -# "enabled": true, -# "name": "eth3" -# }, -# { -# "description": "Configured by Ansible Team (Admin Down)", -# "enabled": false, -# "mtu": 600, -# "name": "eth2" -# }, -# { -# "description": "Configured by Ansible Eng Team", -# "enabled": true, -# "mtu": 100, -# "name": "eth1", -# "vifs": [ -# { -# "description": "VIF 100 - ETH1", -# "enabled": false, -# "vlan_id": "100" -# } -# ] -# }, -# { -# "description": "Ethernet Interface - 0", -# "duplex": "auto", -# "enabled": true, -# "mtu": 1200, -# "name": "eth0", -# "speed": "auto" -# } -# ] -# -# "commands": [ -# "delete interfaces vti vti1 description", -# "delete interfaces vti vti1 mtu", -# "delete interfaces ethernet eth1 description", -# "delete interfaces ethernet eth1 mtu", -# "delete interfaces ethernet eth1 vif 100 description", -# "delete interfaces ethernet eth1 vif 100 disable", -# "delete interfaces ethernet eth0 mtu", -# "set interfaces ethernet eth0 description 'Outbound Interface For The Appliance'", -# "delete interfaces ethernet eth2 description", -# "delete interfaces ethernet eth2 mtu", -# "set interfaces ethernet eth2 duplex 'auto'", -# "delete interfaces ethernet eth2 disable", -# "set interfaces ethernet eth2 speed 'auto'", -# "delete interfaces ethernet eth3 description", -# "set interfaces ethernet eth3 mtu '1200'" -# ], -# -# "after": [ -# { -# "enabled": true, -# "name": "lo" -# }, -# { -# "enabled": true, -# "name": "vti1" -# }, -# { -# "enabled": true, -# "mtu": 1200, -# "name": "eth3" -# }, -# { -# "duplex": "auto", -# "enabled": true, -# "name": "eth2", -# "speed": "auto" -# }, -# { -# "enabled": true, -# "name": "eth1", -# "vifs": [ -# { -# "enabled": true, -# "vlan_id": "100" -# } -# ] -# }, -# { -# "description": "Outbound Interface For The Appliance", -# "duplex": "auto", -# "enabled": true, -# "name": "eth0", -# "speed": "auto" -# } -# ] -# -# -# ------------ -# After state -# ------------ -# -# vyos@vyos:~$ show configuration commands | grep interfaces -# set interfaces ethernet eth0 address 'dhcp' -# set interfaces ethernet eth0 address 'dhcpv6' -# set interfaces ethernet eth0 description 'Outbound Interface For The Appliance' -# set interfaces ethernet eth0 duplex 'auto' -# set interfaces ethernet eth0 hw-id '08:00:27:30:f0:22' -# set interfaces ethernet eth0 smp-affinity 'auto' -# set interfaces ethernet eth0 speed 'auto' -# set interfaces ethernet eth1 hw-id '08:00:27:ea:0f:b9' -# set interfaces ethernet eth1 smp-affinity 'auto' -# set interfaces ethernet eth1 vif 100 -# set interfaces ethernet eth2 duplex 'auto' -# set interfaces ethernet eth2 hw-id '08:00:27:c2:98:23' -# set interfaces ethernet eth2 smp-affinity 'auto' -# set interfaces ethernet eth2 speed 'auto' -# set interfaces ethernet eth3 hw-id '08:00:27:43:70:8c' -# set interfaces ethernet eth3 mtu '1200' -# set interfaces loopback lo -# set interfaces vti vti1 -# -# -# Using deleted -# -# -# ------------- -# Before state -# ------------- -# -# vyos@vyos:~$ show configuration commands | grep interfaces -# set interfaces bonding bond0 mtu '1300' -# set interfaces bonding bond1 description 'LAG - 1' -# set interfaces ethernet eth0 address 'dhcp' -# set interfaces ethernet eth0 address 'dhcpv6' -# set interfaces ethernet eth0 description 'Outbound Interface for this appliance' -# set interfaces ethernet eth0 duplex 'auto' -# set interfaces ethernet eth0 hw-id '08:00:27:30:f0:22' -# set interfaces ethernet eth0 smp-affinity 'auto' -# set interfaces ethernet eth0 speed 'auto' -# set interfaces ethernet eth1 description 'Configured by Ansible Network' -# set interfaces ethernet eth1 duplex 'full' -# set interfaces ethernet eth1 hw-id '08:00:27:ea:0f:b9' -# set interfaces ethernet eth1 smp-affinity 'auto' -# set interfaces ethernet eth1 speed '100' -# set interfaces ethernet eth2 description 'Configured by Ansible' -# set interfaces ethernet eth2 disable -# set interfaces ethernet eth2 duplex 'full' -# set interfaces ethernet eth2 hw-id '08:00:27:c2:98:23' -# set interfaces ethernet eth2 mtu '600' -# set interfaces ethernet eth2 smp-affinity 'auto' -# set interfaces ethernet eth2 speed '100' -# set interfaces ethernet eth3 description 'Configured by Ansible Network' -# set interfaces ethernet eth3 duplex 'full' -# set interfaces ethernet eth3 hw-id '08:00:27:43:70:8c' -# set interfaces ethernet eth3 speed '100' -# set interfaces loopback lo -# -# -- name: Delete attributes of given interfaces (Note - This won't delete the interfaces themselves) - vyos_interfaces: - config: - - name: bond1 - - - name: eth1 - - - name: eth2 - - - name: eth3 - state: deleted -# -# -# ------------------------ -# Module Execution Results -# ------------------------ -# -# "before": [ -# { -# "enabled": true, -# "mtu": 1300, -# "name": "bond0" -# }, -# { -# "description": "LAG - 1", -# "enabled": true, -# "name": "bond1" -# }, -# { -# "enabled": true, -# "name": "lo" -# }, -# { -# "description": "Configured by Ansible Network", -# "duplex": "full", -# "enabled": true, -# "name": "eth3", -# "speed": "100" -# }, -# { -# "description": "Configured by Ansible", -# "duplex": "full", -# "enabled": false, -# "mtu": 600, -# "name": "eth2", -# "speed": "100" -# }, -# { -# "description": "Configured by Ansible Network", -# "duplex": "full", -# "enabled": true, -# "name": "eth1", -# "speed": "100" -# }, -# { -# "description": "Outbound Interface for this appliance", -# "duplex": "auto", -# "enabled": true, -# "name": "eth0", -# "speed": "auto" -# } -# ] -# -# "commands": [ -# "delete interfaces bonding bond1 description", -# "delete interfaces ethernet eth1 speed", -# "delete interfaces ethernet eth1 duplex", -# "delete interfaces ethernet eth1 description", -# "delete interfaces ethernet eth2 speed", -# "delete interfaces ethernet eth2 disable", -# "delete interfaces ethernet eth2 duplex", -# "delete interfaces ethernet eth2 disable", -# "delete interfaces ethernet eth2 description", -# "delete interfaces ethernet eth2 disable", -# "delete interfaces ethernet eth2 mtu", -# "delete interfaces ethernet eth2 disable", -# "delete interfaces ethernet eth3 speed", -# "delete interfaces ethernet eth3 duplex", -# "delete interfaces ethernet eth3 description" -# ] -# -# "after": [ -# { -# "enabled": true, -# "mtu": 1300, -# "name": "bond0" -# }, -# { -# "enabled": true, -# "name": "bond1" -# }, -# { -# "enabled": true, -# "name": "lo" -# }, -# { -# "enabled": true, -# "name": "eth3" -# }, -# { -# "enabled": true, -# "name": "eth2" -# }, -# { -# "enabled": true, -# "name": "eth1" -# }, -# { -# "description": "Outbound Interface for this appliance", -# "duplex": "auto", -# "enabled": true, -# "name": "eth0", -# "speed": "auto" -# } -# ] -# -# -# ------------ -# After state -# ------------ -# -# vyos@vyos:~$ show configuration commands | grep interfaces -# set interfaces bonding bond0 mtu '1300' -# set interfaces bonding bond1 -# set interfaces ethernet eth0 address 'dhcp' -# set interfaces ethernet eth0 address 'dhcpv6' -# set interfaces ethernet eth0 description 'Outbound Interface for this appliance' -# set interfaces ethernet eth0 duplex 'auto' -# set interfaces ethernet eth0 hw-id '08:00:27:30:f0:22' -# set interfaces ethernet eth0 smp-affinity 'auto' -# set interfaces ethernet eth0 speed 'auto' -# set interfaces ethernet eth1 hw-id '08:00:27:ea:0f:b9' -# set interfaces ethernet eth1 smp-affinity 'auto' -# set interfaces ethernet eth2 hw-id '08:00:27:c2:98:23' -# set interfaces ethernet eth2 smp-affinity 'auto' -# set interfaces ethernet eth3 hw-id '08:00:27:43:70:8c' -# set interfaces loopback lo -# -# -""" -RETURN = """ -before: - description: The configuration as structured data prior to module invocation. - returned: always - sample: > - The configuration returned will always be in the same format - of the parameters above. - type: list -after: - description: The configuration as structured data after module completion. - returned: when changed - sample: > - The configuration returned will always be in the same format - of the parameters above. - type: list -commands: - description: The set of commands pushed to the remote device. - returned: always - type: list - sample: - - 'set interfaces ethernet eth1 mtu 1200' - - 'set interfaces ethernet eth2 vif 100 description VIF 100' -""" - - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.vyos.argspec.interfaces.interfaces import InterfacesArgs -from ansible.module_utils.network.vyos.config.interfaces.interfaces import Interfaces - - -def main(): - """ - Main entry point for module execution - - :returns: the result form module invocation - """ - module = AnsibleModule(argument_spec=InterfacesArgs.argument_spec, - supports_check_mode=True) - - result = Interfaces(module).execute_module() - module.exit_json(**result) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/vyos/vyos_l3_interfaces.py b/lib/ansible/modules/network/vyos/vyos_l3_interfaces.py deleted file mode 100644 index 77510310c6..0000000000 --- a/lib/ansible/modules/network/vyos/vyos_l3_interfaces.py +++ /dev/null @@ -1,375 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -############################################# -# WARNING # -############################################# -# -# This file is auto generated by the resource -# module builder playbook. -# -# Do not edit this file manually. -# -# Changes to this file will be over written -# by the resource module builder. -# -# Changes should be made in the model used to -# generate this file or in the resource module -# builder template. -# -############################################# - -""" -The module file for vyos_l3_interfaces -""" - -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -ANSIBLE_METADATA = { - 'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'network' -} - -DOCUMENTATION = """ ---- -module: vyos_l3_interfaces -version_added: 2.9 -short_description: Manages L3 interface attributes of VyOS network devices. -description: This module manages the L3 interface attributes on VyOS network devices. -notes: - - Tested against VyOS 1.1.8 (helium). - - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). -author: Nilashish Chakraborty (@NilashishC) -options: - config: - description: The provided L3 interfaces configuration. - type: list - elements: dict - suboptions: - name: - description: - - Full name of the interface, e.g. eth0, eth1. - type: str - required: True - ipv4: - description: - - List of IPv4 addresses of the interface. - type: list - elements: dict - suboptions: - address: - description: - - IPv4 address of the interface. - type: str - ipv6: - description: - - List of IPv6 addresses of the interface. - type: list - elements: dict - suboptions: - address: - description: - - IPv6 address of the interface. - type: str - vifs: - description: - - Virtual sub-interfaces L3 configurations. - elements: dict - type: list - suboptions: - vlan_id: - description: - - Identifier for the virtual sub-interface. - type: int - ipv4: - description: - - List of IPv4 addresses of the virtual interface. - type: list - elements: dict - suboptions: - address: - description: - - IPv4 address of the virtual interface. - type: str - ipv6: - description: - - List of IPv6 addresses of the virtual interface. - type: list - elements: dict - suboptions: - address: - description: - - IPv6 address of the virtual interface. - type: str - state: - description: - - The state of the configuration after module completion. - type: str - choices: - - merged - - replaced - - overridden - - deleted - default: merged - -""" -EXAMPLES = """ -# Using merged -# -# Before state: -# ------------- -# -# vyos:~$ show configuration commands | grep -e eth[2,3] -# set interfaces ethernet eth2 hw-id '08:00:27:c2:98:23' -# set interfaces ethernet eth3 hw-id '08:00:27:43:70:8c' -# set interfaces ethernet eth3 vif 101 -# set interfaces ethernet eth3 vif 102 - -- name: Merge provided configuration with device configuration - vyos_l3_interfaces: - config: - - name: eth2 - ipv4: - - address: 192.0.2.10/28 - - address: 198.51.100.40/27 - ipv6: - - address: 2001:db8:100::2/32 - - address: 2001:db8:400::10/32 - - - name: eth3 - ipv4: - - address: 203.0.113.65/26 - vifs: - - vlan_id: 101 - ipv4: - - address: 192.0.2.71/28 - - address: 198.51.100.131/25 - - vlan_id: 102 - ipv6: - - address: 2001:db8:1000::5/38 - - address: 2001:db8:1400::3/38 - state: merged - -# After state: -# ------------- -# -# vyos:~$ show configuration commands | grep -e eth[2,3] -# set interfaces ethernet eth2 address '192.0.2.10/28' -# set interfaces ethernet eth2 address '198.51.100.40/27' -# set interfaces ethernet eth2 address '2001:db8:100::2/32' -# set interfaces ethernet eth2 address '2001:db8:400::10/32' -# set interfaces ethernet eth2 hw-id '08:00:27:c2:98:23' -# set interfaces ethernet eth3 address '203.0.113.65/26' -# set interfaces ethernet eth3 hw-id '08:00:27:43:70:8c' -# set interfaces ethernet eth3 vif 101 address '192.0.2.71/28' -# set interfaces ethernet eth3 vif 101 address '198.51.100.131/25' -# set interfaces ethernet eth3 vif 102 address '2001:db8:1000::5/38' -# set interfaces ethernet eth3 vif 102 address '2001:db8:1400::3/38' -# set interfaces ethernet eth3 vif 102 address '2001:db8:4000::2/34' - - -# Using replaced -# -# Before state: -# ------------- -# -# vyos:~$ show configuration commands | grep eth -# set interfaces ethernet eth0 address 'dhcp' -# set interfaces ethernet eth0 duplex 'auto' -# set interfaces ethernet eth0 hw-id '08:00:27:30:f0:22' -# set interfaces ethernet eth0 smp-affinity 'auto' -# set interfaces ethernet eth0 speed 'auto' -# set interfaces ethernet eth1 hw-id '08:00:27:EA:0F:B9' -# set interfaces ethernet eth1 address '192.0.2.14/24' -# set interfaces ethernet eth2 address '192.0.2.10/24' -# set interfaces ethernet eth2 address '192.0.2.11/24' -# set interfaces ethernet eth2 address '2001:db8::10/32' -# set interfaces ethernet eth2 address '2001:db8::11/32' -# set interfaces ethernet eth2 hw-id '08:00:27:c2:98:23' -# set interfaces ethernet eth3 address '198.51.100.10/24' -# set interfaces ethernet eth3 hw-id '08:00:27:43:70:8c' -# set interfaces ethernet eth3 vif 101 address '198.51.100.130/25' -# set interfaces ethernet eth3 vif 101 address '198.51.100.131/25' -# set interfaces ethernet eth3 vif 102 address '2001:db8:4000::3/34' -# set interfaces ethernet eth3 vif 102 address '2001:db8:4000::2/34' -# -- name: Replace device configurations of listed interfaces with provided configurations - vyos_l3_interfaces: - config: - - name: eth2 - ipv4: - - address: 192.0.2.10/24 - - - name: eth3 - ipv6: - - address: 2001:db8::11/32 - state: replaced - -# After state: -# ------------- -# -# vyos:~$ show configuration commands | grep eth -# set interfaces ethernet eth0 address 'dhcp' -# set interfaces ethernet eth0 duplex 'auto' -# set interfaces ethernet eth0 hw-id '08:00:27:30:f0:22' -# set interfaces ethernet eth0 smp-affinity 'auto' -# set interfaces ethernet eth0 speed 'auto' -# set interfaces ethernet eth1 hw-id '08:00:27:EA:0F:B9' -# set interfaces ethernet eth1 address '192.0.2.14/24' -# set interfaces ethernet eth2 address '192.0.2.10/24' -# set interfaces ethernet eth2 hw-id '08:00:27:c2:98:23' -# set interfaces ethernet eth3 hw-id '08:00:27:43:70:8c' -# set interfaces ethernet eth3 address '2001:db8::11/32' -# set interfaces ethernet eth3 vif 101 -# set interfaces ethernet eth3 vif 102 - - -# Using overridden -# -# Before state -# -------------- -# -# vyos@vyos-appliance:~$ show configuration commands | grep eth -# set interfaces ethernet eth0 address 'dhcp' -# set interfaces ethernet eth0 duplex 'auto' -# set interfaces ethernet eth0 hw-id '08:00:27:30:f0:22' -# set interfaces ethernet eth0 smp-affinity 'auto' -# set interfaces ethernet eth0 speed 'auto' -# set interfaces ethernet eth1 hw-id '08:00:27:EA:0F:B9' -# set interfaces ethernet eth1 address '192.0.2.14/24' -# set interfaces ethernet eth2 address '192.0.2.10/24' -# set interfaces ethernet eth2 address '192.0.2.11/24' -# set interfaces ethernet eth2 address '2001:db8::10/32' -# set interfaces ethernet eth2 address '2001:db8::11/32' -# set interfaces ethernet eth2 hw-id '08:00:27:c2:98:23' -# set interfaces ethernet eth3 address '198.51.100.10/24' -# set interfaces ethernet eth3 hw-id '08:00:27:43:70:8c' -# set interfaces ethernet eth3 vif 101 address '198.51.100.130/25' -# set interfaces ethernet eth3 vif 101 address '198.51.100.131/25' -# set interfaces ethernet eth3 vif 102 address '2001:db8:4000::3/34' -# set interfaces ethernet eth3 vif 102 address '2001:db8:4000::2/34' - -- name: Overrides all device configuration with provided configuration - vyos_l3_interfaces: - config: - - name: eth0 - ipv4: - - address: dhcp - ipv6: - - address: dhcpv6 - state: overridden - -# After state -# ------------ -# -# vyos@vyos-appliance:~$ show configuration commands | grep eth -# set interfaces ethernet eth0 address 'dhcp' -# set interfaces ethernet eth0 address 'dhcpv6' -# set interfaces ethernet eth0 duplex 'auto' -# set interfaces ethernet eth0 hw-id '08:00:27:30:f0:22' -# set interfaces ethernet eth0 smp-affinity 'auto' -# set interfaces ethernet eth0 speed 'auto' -# set interfaces ethernet eth1 hw-id '08:00:27:EA:0F:B9' -# set interfaces ethernet eth2 hw-id '08:00:27:c2:98:23' -# set interfaces ethernet eth3 hw-id '08:00:27:43:70:8c' -# set interfaces ethernet eth3 vif 101 -# set interfaces ethernet eth3 vif 102 - - -# Using deleted -# -# Before state -# ------------- -# vyos@vyos-appliance:~$ show configuration commands | grep eth -# set interfaces ethernet eth0 address 'dhcp' -# set interfaces ethernet eth0 duplex 'auto' -# set interfaces ethernet eth0 hw-id '08:00:27:30:f0:22' -# set interfaces ethernet eth0 smp-affinity 'auto' -# set interfaces ethernet eth0 speed 'auto' -# set interfaces ethernet eth1 hw-id '08:00:27:EA:0F:B9' -# set interfaces ethernet eth1 address '192.0.2.14/24' -# set interfaces ethernet eth2 address '192.0.2.10/24' -# set interfaces ethernet eth2 address '192.0.2.11/24' -# set interfaces ethernet eth2 address '2001:db8::10/32' -# set interfaces ethernet eth2 address '2001:db8::11/32' -# set interfaces ethernet eth2 hw-id '08:00:27:c2:98:23' -# set interfaces ethernet eth3 address '198.51.100.10/24' -# set interfaces ethernet eth3 hw-id '08:00:27:43:70:8c' -# set interfaces ethernet eth3 vif 101 address '198.51.100.130/25' -# set interfaces ethernet eth3 vif 101 address '198.51.100.131/25' -# set interfaces ethernet eth3 vif 102 address '2001:db8:4000::3/34' -# set interfaces ethernet eth3 vif 102 address '2001:db8:4000::2/34' - -- name: Delete L3 attributes of given interfaces (Note - This won't delete the interface itself) - vyos_l3_interfaces: - config: - - name: eth1 - - name: eth2 - - name: eth3 - state: deleted - -# After state -# ------------ -# vyos@vyos-appliance:~$ show configuration commands | grep eth -# set interfaces ethernet eth0 address 'dhcp' -# set interfaces ethernet eth0 duplex 'auto' -# set interfaces ethernet eth0 hw-id '08:00:27:f3:6c:b5' -# set interfaces ethernet eth0 smp_affinity 'auto' -# set interfaces ethernet eth0 speed 'auto' -# set interfaces ethernet eth1 hw-id '08:00:27:ad:ef:65' -# set interfaces ethernet eth1 smp_affinity 'auto' -# set interfaces ethernet eth2 hw-id '08:00:27:ab:4e:79' -# set interfaces ethernet eth2 smp_affinity 'auto' -# set interfaces ethernet eth3 hw-id '08:00:27:17:3c:85' -# set interfaces ethernet eth3 smp_affinity 'auto' - - -""" -RETURN = """ -before: - description: The configuration as structured data prior to module invocation. - returned: always - type: list - sample: > - The configuration returned will always be in the same format - of the parameters above. -after: - description: The configuration as structured data after module completion. - returned: when changed - type: list - sample: > - The configuration returned will always be in the same format - of the parameters above. -commands: - description: The set of commands pushed to the remote device. - returned: always - type: list - sample: ['set interfaces ethernet eth1 192.0.2.14/2', 'set interfaces ethernet eth3 vif 101 address 198.51.100.130/25'] -""" - - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.vyos.argspec.l3_interfaces.l3_interfaces import L3_interfacesArgs -from ansible.module_utils.network.vyos.config.l3_interfaces.l3_interfaces import L3_interfaces - - -def main(): - """ - Main entry point for module execution - - :returns: the result form module invocation - """ - module = AnsibleModule(argument_spec=L3_interfacesArgs.argument_spec, - supports_check_mode=True) - - result = L3_interfaces(module).execute_module() - module.exit_json(**result) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/vyos/vyos_lag_interfaces.py b/lib/ansible/modules/network/vyos/vyos_lag_interfaces.py deleted file mode 100644 index 5f79cf80b2..0000000000 --- a/lib/ansible/modules/network/vyos/vyos_lag_interfaces.py +++ /dev/null @@ -1,561 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -############################################# -# WARNING # -############################################# -# -# This file is auto generated by the resource -# module builder playbook. -# -# Do not edit this file manually. -# -# Changes to this file will be over written -# by the resource module builder. -# -# Changes should be made in the model used to -# generate this file or in the resource module -# builder template. -# -############################################# - -""" -The module file for vyos_lag_interfaces -""" - -from __future__ import absolute_import, division, print_function -__metaclass__ = type - -ANSIBLE_METADATA = { - 'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'network' -} - -DOCUMENTATION = """ ---- -module: vyos_lag_interfaces -version_added: 2.9 -short_description: Manages attributes of link aggregation groups on VyOS network devices. -description: This module manages attributes of link aggregation groups on VyOS network devices. -notes: - - Tested against VyOS 1.1.8 (helium). - - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). -author: Rohit Thakur (@rohitthakur2590) -options: - config: - description: A list of link aggregation group configurations. - type: list - suboptions: - name: - description: - - Name of the link aggregation group (LAG) or bond. - type: str - required: True - mode: - description: - - LAG or bond mode. - type: str - choices: - - 802.3ad - - active-backup - - broadcast - - round-robin - - transmit-load-balance - - adaptive-load-balance - - xor-hash - members: - description: - - List of member interfaces for the LAG (bond). - type: list - suboptions: - member: - description: - - Name of the member interface. - type: str - primary: - description: - - Primary device interfaces for the LAG (bond). - type: str - hash_policy: - description: - - LAG or bonding transmit hash policy. - type: str - choices: - - layer2 - - layer2+3 - - layer3+4 - arp_monitor: - description: - - ARP Link monitoring parameters. - type: dict - suboptions: - interval: - description: - - ARP link monitoring frequency in milliseconds. - type: int - target: - description: - - IP address to use for ARP monitoring. - type: list - state: - description: - - The state of the configuration after module completion. - type: str - choices: - - merged - - replaced - - overridden - - deleted - default: merged - -""" -EXAMPLES = """ -# Using merged -# -# Before state: -# ------------- -# -# vyos@vyos:~$ show configuration commands | grep bond -# set interfaces bonding bond2 -# set interfaces bonding bond3 -# -- name: Merge provided configuration with device configuration - vyos_lag_interfaces: - config: - - name: bond2 - mode: active-backup - members: - - member: eth2 - - member: eth1 - hash_policy: layer2 - primary: eth2 - - - name: 'bond3' - mode: 'active-backup' - hash_policy: 'layer2+3' - members: - - member: eth3 - primary: 'eth3' - state: merged -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# "before": [ -# { -# "name": "bond2" -# }, -# { -# "name": "bond3" -# } -# ], -# -# "commands": [ -# "set interfaces bonding bond2 hash-policy 'layer2'", -# "set interfaces bonding bond2 mode 'active-backup'", -# "set interfaces ethernet eth2 bond-group bond2", -# "set interfaces ethernet eth1 bond-group bond2", -# "set interfaces bonding bond2 primary 'eth2'", -# "set interfaces bonding bond3 hash-policy 'layer2+3'", -# "set interfaces bonding bond3 mode 'active-backup'", -# "set interfaces ethernet eth3 bond-group bond3", -# "set interfaces bonding bond3 primary 'eth3'" -# ] -# -# "after": [ -# { -# "hash_policy": "layer2", -# "members": [ -# { -# "member": "eth1" -# }, -# { -# "member": "eth2" -# } -# ], -# "mode": "active-backup", -# "name": "bond2", -# "primary": "eth2" -# }, -# { -# "hash_policy": "layer2+3", -# "members": [ -# { -# "member": "eth3" -# } -# ], -# "mode": "active-backup", -# "name": "bond3", -# "primary": "eth3" -# } -# ] -# -# After state: -# ------------- -# -# vyos@vyos:~$ show configuration commands | grep bond -# set interfaces bonding bond2 hash-policy 'layer2' -# set interfaces bonding bond2 mode 'active-backup' -# set interfaces bonding bond2 primary 'eth2' -# set interfaces bonding bond3 hash-policy 'layer2+3' -# set interfaces bonding bond3 mode 'active-backup' -# set interfaces bonding bond3 primary 'eth3' -# set interfaces ethernet eth1 bond-group 'bond2' -# set interfaces ethernet eth2 bond-group 'bond2' -# set interfaces ethernet eth3 bond-group 'bond3' - - -# Using replaced -# -# Before state: -# ------------- -# -# vyos@vyos:~$ show configuration commands | grep bond -# set interfaces bonding bond2 hash-policy 'layer2' -# set interfaces bonding bond2 mode 'active-backup' -# set interfaces bonding bond2 primary 'eth2' -# set interfaces bonding bond3 hash-policy 'layer2+3' -# set interfaces bonding bond3 mode 'active-backup' -# set interfaces bonding bond3 primary 'eth3' -# set interfaces ethernet eth1 bond-group 'bond2' -# set interfaces ethernet eth2 bond-group 'bond2' -# set interfaces ethernet eth3 bond-group 'bond3' -# -- name: Replace device configurations of listed LAGs with provided configurations - vyos_lag_interfaces: - config: - - name: bond3 - mode: '802.3ad' - hash_policy: 'layer2' - members: - - member: eth3 - state: replaced -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# "before": [ -# { -# "hash_policy": "layer2", -# "members": [ -# { -# "member": "eth1" -# }, -# { -# "member": "eth2" -# } -# ], -# "mode": "active-backup", -# "name": "bond2", -# "primary": "eth2" -# }, -# { -# "hash_policy": "layer2+3", -# "members": [ -# { -# "member": "eth3" -# } -# ], -# "mode": "active-backup", -# "name": "bond3", -# "primary": "eth3" -# } -# ], -# -# "commands": [ -# "delete interfaces bonding bond3 primary", -# "set interfaces bonding bond3 hash-policy 'layer2'", -# "set interfaces bonding bond3 mode '802.3ad'" -# ], -# -# "after": [ -# { -# "hash_policy": "layer2", -# "members": [ -# { -# "member": "eth1" -# }, -# { -# "member": "eth2" -# } -# ], -# "mode": "active-backup", -# "name": "bond2", -# "primary": "eth2" -# }, -# { -# "hash_policy": "layer2", -# "members": [ -# { -# "member": "eth3" -# } -# ], -# "mode": "802.3ad", -# "name": "bond3" -# } -# ], -# -# After state: -# ------------- -# -# vyos@vyos:~$ show configuration commands | grep bond -# set interfaces bonding bond2 hash-policy 'layer2' -# set interfaces bonding bond2 mode 'active-backup' -# set interfaces bonding bond2 primary 'eth2' -# set interfaces bonding bond3 hash-policy 'layer2' -# set interfaces bonding bond3 mode '802.3ad' -# set interfaces ethernet eth1 bond-group 'bond2' -# set interfaces ethernet eth2 bond-group 'bond2' -# set interfaces ethernet eth3 bond-group 'bond3' - - -# Using overridden -# -# Before state -# -------------- -# -# vyos@vyos:~$ show configuration commands | grep bond -# set interfaces bonding bond2 hash-policy 'layer2' -# set interfaces bonding bond2 mode 'active-backup' -# set interfaces bonding bond2 primary 'eth2' -# set interfaces bonding bond3 hash-policy 'layer2' -# set interfaces bonding bond3 mode '802.3ad' -# set interfaces ethernet eth1 bond-group 'bond2' -# set interfaces ethernet eth2 bond-group 'bond2' -# set interfaces ethernet eth3 bond-group 'bond3' -# -- name: Overrides all device configuration with provided configuration - vyos_lag_interfaces: - config: - - name: bond3 - mode: active-backup - members: - - member: eth1 - - member: eth2 - - member: eth3 - primary: eth3 - hash_policy: layer2 - state: overridden -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# "before": [ -# { -# "hash_policy": "layer2", -# "members": [ -# { -# "member": "eth1" -# }, -# { -# "member": "eth2" -# } -# ], -# "mode": "active-backup", -# "name": "bond2", -# "primary": "eth2" -# }, -# { -# "hash_policy": "layer2", -# "members": [ -# { -# "member": "eth3" -# } -# ], -# "mode": "802.3ad", -# "name": "bond3" -# } -# ], -# -# "commands": [ -# "delete interfaces bonding bond2 hash-policy", -# "delete interfaces ethernet eth1 bond-group bond2", -# "delete interfaces ethernet eth2 bond-group bond2", -# "delete interfaces bonding bond2 mode", -# "delete interfaces bonding bond2 primary", -# "set interfaces bonding bond3 mode 'active-backup'", -# "set interfaces ethernet eth1 bond-group bond3", -# "set interfaces ethernet eth2 bond-group bond3", -# "set interfaces bonding bond3 primary 'eth3'" -# ], -# -# "after": [ -# { -# "name": "bond2" -# }, -# { -# "hash_policy": "layer2", -# "members": [ -# { -# "member": "eth1" -# }, -# { -# "member": "eth2" -# }, -# { -# "member": "eth3" -# } -# ], -# "mode": "active-backup", -# "name": "bond3", -# "primary": "eth3" -# } -# ], -# -# -# After state -# ------------ -# -# vyos@vyos:~$ show configuration commands | grep bond -# set interfaces bonding bond2 -# set interfaces bonding bond3 hash-policy 'layer2' -# set interfaces bonding bond3 mode 'active-backup' -# set interfaces bonding bond3 primary 'eth3' -# set interfaces ethernet eth1 bond-group 'bond3' -# set interfaces ethernet eth2 bond-group 'bond3' -# set interfaces ethernet eth3 bond-group 'bond3' - - -# Using deleted -# -# Before state -# ------------- -# -# vyos@vyos:~$ show configuration commands | grep bond -# set interfaces bonding bond2 hash-policy 'layer2' -# set interfaces bonding bond2 mode 'active-backup' -# set interfaces bonding bond2 primary 'eth2' -# set interfaces bonding bond3 hash-policy 'layer2+3' -# set interfaces bonding bond3 mode 'active-backup' -# set interfaces bonding bond3 primary 'eth3' -# set interfaces ethernet eth1 bond-group 'bond2' -# set interfaces ethernet eth2 bond-group 'bond2' -# set interfaces ethernet eth3 bond-group 'bond3' -# -- name: Delete LAG attributes of given interfaces (Note This won't delete the interface itself) - vyos_lag_interfaces: - config: - - name: bond2 - - name: bond3 - state: deleted -# -# -# ------------------------ -# Module Execution Results -# ------------------------ -# -# "before": [ -# { -# "hash_policy": "layer2", -# "members": [ -# { -# "member": "eth1" -# }, -# { -# "member": "eth2" -# } -# ], -# "mode": "active-backup", -# "name": "bond2", -# "primary": "eth2" -# }, -# { -# "hash_policy": "layer2+3", -# "members": [ -# { -# "member": "eth3" -# } -# ], -# "mode": "active-backup", -# "name": "bond3", -# "primary": "eth3" -# } -# ], -# "commands": [ -# "delete interfaces bonding bond2 hash-policy", -# "delete interfaces ethernet eth1 bond-group bond2", -# "delete interfaces ethernet eth2 bond-group bond2", -# "delete interfaces bonding bond2 mode", -# "delete interfaces bonding bond2 primary", -# "delete interfaces bonding bond3 hash-policy", -# "delete interfaces ethernet eth3 bond-group bond3", -# "delete interfaces bonding bond3 mode", -# "delete interfaces bonding bond3 primary" -# ], -# -# "after": [ -# { -# "name": "bond2" -# }, -# { -# "name": "bond3" -# } -# ], -# -# After state -# ------------ -# vyos@vyos:~$ show configuration commands | grep bond -# set interfaces bonding bond2 -# set interfaces bonding bond3 - - -""" -RETURN = """ -before: - description: The configuration as structured data prior to module invocation. - returned: always - type: list - sample: > - The configuration returned will always be in the same format - of the parameters above. -after: - description: The configuration as structured data after module completion. - returned: when changed - type: list - sample: > - The configuration returned will always be in the same format - of the parameters above. -commands: - description: The set of commands pushed to the remote device. - returned: always - type: list - sample: - - 'set interfaces bonding bond2' - - 'set interfaces bonding bond2 hash-policy layer2' -""" - - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.vyos.argspec.lag_interfaces. \ - lag_interfaces import Lag_interfacesArgs -from ansible.module_utils.network.vyos.config.lag_interfaces.lag_interfaces import Lag_interfaces - - -def main(): - """ - Main entry point for module execution - - :returns: the result form module invocation - """ - required_if = [('state', 'merged', ('config',)), - ('state', 'replaced', ('config',)), - ('state', 'overridden', ('config',))] - module = AnsibleModule(argument_spec=Lag_interfacesArgs.argument_spec, required_if=required_if, - supports_check_mode=True) - - result = Lag_interfaces(module).execute_module() - module.exit_json(**result) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/vyos/vyos_lldp_global.py b/lib/ansible/modules/network/vyos/vyos_lldp_global.py deleted file mode 100644 index b10f396ab1..0000000000 --- a/lib/ansible/modules/network/vyos/vyos_lldp_global.py +++ /dev/null @@ -1,323 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -############################################# -# WARNING # -############################################# -# -# This file is auto generated by the resource -# module builder playbook. -# -# Do not edit this file manually. -# -# Changes to this file will be over written -# by the resource module builder. -# -# Changes should be made in the model used to -# generate this file or in the resource module -# builder template. -# -############################################# - -""" -The module file for vyos_lldp_global -""" - -from __future__ import absolute_import, division, print_function -__metaclass__ = type - -ANSIBLE_METADATA = { - 'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'network' -} - -DOCUMENTATION = """ ---- -module: vyos_lldp_global -version_added: 2.9 -short_description: Manage link layer discovery protocol (LLDP) attributes on VyOS devices.. -description: This module manages link layer discovery protocol (LLDP) attributes on VyOS devices. -notes: - - Tested against VyOS 1.1.8 (helium). - - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). -author: - - Rohit Thakur (@rohitthakur2590) -options: - config: - description: The provided link layer discovery protocol (LLDP) configuration. - type: dict - suboptions: - enable: - description: - - This argument is a boolean value to enable or disable LLDP. - type: bool - address: - description: - - This argument defines management-address. - type: str - snmp: - description: - - This argument enable the SNMP queries to LLDP database. - type: str - legacy_protocols: - description: - - List of the supported legacy protocols. - type: list - choices: - - cdp - - edp - - fdp - - sonmp - state: - description: - - The state of the configuration after module completion. - type: str - choices: - - merged - - replaced - - deleted - default: merged -""" -EXAMPLES = """ -# Using merged -# -# Before state: -# ------------- -# -# vyos@vyos:~$ show configuration commands|grep lldp -# vyos@vyos:~$ -# -- name: Merge provided configuration with device configuration - vyos_lldp_global: - config: - legacy_protocols: - - 'fdp' - - 'cdp' - snmp: 'enable' - address: 192.0.2.11 - state: merged -# -# -# ------------------------ -# Module Execution Results -# ------------------------ -# -# "before": [] -# -# "commands": [ -# "set service lldp legacy-protocols fdp", -# "set service lldp legacy-protocols cdp", -# "set service lldp snmp enable", -# "set service lldp management-address '192.0.2.11'" -# ] -# -# "after": [ -# { -# "snmp": "enable" -# }, -# { -# "address": "192.0.2.11" -# }, -# { -# "legacy_protocols": [ -# "cdp", -# "fdp" -# ] -# } -# { -# "enable": true -# } -# ] -# -# After state: -# ------------- -# -# set service lldp legacy-protocols cdp -# set service lldp legacy-protocols fdp -# set service lldp management-address '192.0.2.11' -# set service lldp snmp enable - - -# Using replaced -# -# Before state: -# ------------- -# -# vyos@vyos:~$ show configuration commands | grep lldp -# set service lldp legacy-protocols cdp -# set service lldp legacy-protocols fdp -# set service lldp management-address '192.0.2.11' -# set service lldp snmp enable -# -- name: Replace device configurations with provided configurations - vyos_lldp_global: - config: - legacy_protocols: - - 'edp' - - 'sonmp' - - 'cdp' - address: 192.0.2.14 - state: replaced -# -# -# ------------------------ -# Module Execution Results -# ------------------------ -# -# -# "before": [ -# { -# "snmp": "enable" -# }, -# { -# "address": "192.0.2.11" -# }, -# { -# "legacy_protocols": [ -# "cdp", -# "fdp" -# ] -# } -# { -# "enable": true -# } -# ] -# "commands": [ -# "delete service lldp snmp", -# "delete service lldp legacy-protocols fdp", -# "set service lldp management-address '192.0.2.14'", -# "set service lldp legacy-protocols edp", -# "set service lldp legacy-protocols sonmp" -# ] -# -# "after": [ -# { -# "address": "192.0.2.14" -# }, -# { -# "legacy_protocols": [ -# "cdp", -# "edp", -# "sonmp" -# ] -# } -# { -# "enable": true -# } -# ] -# -# After state: -# ------------- -# -# vyos@vyos:~$ show configuration commands|grep lldp -# set service lldp legacy-protocols cdp -# set service lldp legacy-protocols edp -# set service lldp legacy-protocols sonmp -# set service lldp management-address '192.0.2.14' - - -# Using deleted -# -# Before state -# ------------- -# vyos@vyos:~$ show configuration commands|grep lldp -# set service lldp legacy-protocols cdp -# set service lldp legacy-protocols edp -# set service lldp legacy-protocols sonmp -# set service lldp management-address '192.0.2.14' -# -- name: Delete attributes of given lldp service (This won't delete the LLDP service itself) - vyos_lldp_global: - config: - state: deleted -# -# -# ------------------------ -# Module Execution Results -# ------------------------ -# -# "before": [ -# { -# "address": "192.0.2.14" -# }, -# { -# "legacy_protocols": [ -# "cdp", -# "edp", -# "sonmp" -# ] -# } -# { -# "enable": true -# } -# ] -# -# "commands": [ -# "delete service lldp management-address", -# "delete service lldp legacy-protocols" -# ] -# -# "after": [ -# { -# "enable": true -# } -# ] -# -# After state -# ------------ -# vyos@vyos:~$ show configuration commands | grep lldp -# set service lldp - - -""" -RETURN = """ -before: - description: The configuration as structured data prior to module invocation. - returned: always - type: list - sample: > - The configuration returned will always be in the same format - of the parameters above. -after: - description: The configuration as structured data after module completion. - returned: when changed - type: list - sample: > - The configuration returned will always be in the same format - of the parameters above. -commands: - description: The set of commands pushed to the remote device. - returned: always - type: list - sample: - - set service lldp legacy-protocols sonmp - - set service lldp management-address '192.0.2.14' -""" - - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.vyos.argspec.lldp_global.lldp_global import Lldp_globalArgs -from ansible.module_utils.network.vyos.config.lldp_global.lldp_global import Lldp_global - - -def main(): - """ - Main entry point for module execution - - :returns: the result form module invocation - """ - required_if = [('state', 'merged', ('config',)), - ('state', 'replaced', ('config',))] - module = AnsibleModule(argument_spec=Lldp_globalArgs.argument_spec, required_if=required_if, - supports_check_mode=True) - - result = Lldp_global(module).execute_module() - module.exit_json(**result) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/vyos/vyos_lldp_interfaces.py b/lib/ansible/modules/network/vyos/vyos_lldp_interfaces.py deleted file mode 100644 index 32b2f75524..0000000000 --- a/lib/ansible/modules/network/vyos/vyos_lldp_interfaces.py +++ /dev/null @@ -1,507 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -############################################# -# WARNING # -############################################# -# -# This file is auto generated by the resource -# module builder playbook. -# -# Do not edit this file manually. -# -# Changes to this file will be over written -# by the resource module builder. -# -# Changes should be made in the model used to -# generate this file or in the resource module -# builder template. -# -############################################# - -""" -The module file for vyos_lldp_interfaces -""" - -from __future__ import absolute_import, division, print_function -__metaclass__ = type - -ANSIBLE_METADATA = { - 'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'network' -} - -DOCUMENTATION = """ ---- -module: vyos_lldp_interfaces -version_added: 2.9 -short_description: Manages attributes of lldp interfaces on VyOS devices. -description: This module manages attributes of lldp interfaces on VyOS network devices. -notes: - - Tested against VyOS 1.1.8 (helium). - - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). -author: - - Rohit Thakur (@rohitthakur2590) -options: - config: - description: A list of lldp interfaces configurations. - type: list - suboptions: - name: - description: - - Name of the lldp interface. - type: str - required: True - enable: - description: - - to disable lldp on the interface. - type: bool - default: True - location: - description: - - LLDP-MED location data. - type: dict - suboptions: - civic_based: - description: - - Civic-based location data. - type: dict - suboptions: - ca_info: - description: LLDP-MED address info - type: list - suboptions: - ca_type: - description: LLDP-MED Civic Address type. - type: int - required: True - ca_value: - description: LLDP-MED Civic Address value. - type: str - required: True - country_code: - description: Country Code - type: str - required: True - coordinate_based: - description: - - Coordinate-based location. - type: dict - suboptions: - altitude: - description: Altitude in meters. - type: int - datum: - description: Coordinate datum type. - type: str - choices: - - WGS84 - - NAD83 - - MLLW - latitude: - description: Latitude. - type: str - required: True - longitude: - description: Longitude. - type: str - required: True - elin: - description: Emergency Call Service ELIN number (between 10-25 numbers). - type: str - state: - description: - - The state of the configuration after module completion. - type: str - choices: - - merged - - replaced - - overridden - - deleted - default: merged - -""" -EXAMPLES = """ -# Using merged -# -# Before state: -# ------------- -# -# vyos@vyos:~$ show configuration commands | grep lldp -# -- name: Merge provided configuration with device configuration - vyos_lldp_interfaces: - config: - - name: 'eth1' - location: - civic_based: - country_code: 'US' - ca_info: - - ca_type: 0 - ca_value: 'ENGLISH' - - - name: 'eth2' - location: - coordinate_based: - altitude: 2200 - datum: 'WGS84' - longitude: '222.267255W' - latitude: '33.524449N' - state: merged -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# before": [] -# -# "commands": [ -# "set service lldp interface eth1 location civic-based country-code 'US'", -# "set service lldp interface eth1 location civic-based ca-type 0 ca-value 'ENGLISH'", -# "set service lldp interface eth1", -# "set service lldp interface eth2 location coordinate-based latitude '33.524449N'", -# "set service lldp interface eth2 location coordinate-based altitude '2200'", -# "set service lldp interface eth2 location coordinate-based datum 'WGS84'", -# "set service lldp interface eth2 location coordinate-based longitude '222.267255W'", -# "set service lldp interface eth2 location coordinate-based latitude '33.524449N'", -# "set service lldp interface eth2 location coordinate-based altitude '2200'", -# "set service lldp interface eth2 location coordinate-based datum 'WGS84'", -# "set service lldp interface eth2 location coordinate-based longitude '222.267255W'", -# "set service lldp interface eth2" -# -# "after": [ -# { -# "location": { -# "coordinate_based": { -# "altitude": 2200, -# "datum": "WGS84", -# "latitude": "33.524449N", -# "longitude": "222.267255W" -# } -# }, -# "name": "eth2" -# }, -# { -# "location": { -# "civic_based": { -# "ca_info": [ -# { -# "ca_type": 0, -# "ca_value": "ENGLISH" -# } -# ], -# "country_code": "US" -# } -# }, -# "name": "eth1" -# } -# ], -# -# After state: -# ------------- -# -# vyos@vyos:~$ show configuration commands | grep lldp -# set service lldp interface eth1 location civic-based ca-type 0 ca-value 'ENGLISH' -# set service lldp interface eth1 location civic-based country-code 'US' -# set service lldp interface eth2 location coordinate-based altitude '2200' -# set service lldp interface eth2 location coordinate-based datum 'WGS84' -# set service lldp interface eth2 location coordinate-based latitude '33.524449N' -# set service lldp interface eth2 location coordinate-based longitude '222.267255W' - - -# Using replaced -# -# Before state: -# ------------- -# -# vyos@vyos:~$ show configuration commands | grep lldp -# set service lldp interface eth1 location civic-based ca-type 0 ca-value 'ENGLISH' -# set service lldp interface eth1 location civic-based country-code 'US' -# set service lldp interface eth2 location coordinate-based altitude '2200' -# set service lldp interface eth2 location coordinate-based datum 'WGS84' -# set service lldp interface eth2 location coordinate-based latitude '33.524449N' -# set service lldp interface eth2 location coordinate-based longitude '222.267255W' -# -- name: Replace device configurations of listed LLDP interfaces with provided configurations - vyos_lldp_interfaces: - config: - - name: 'eth2' - location: - civic_based: - country_code: 'US' - ca_info: - - ca_type: 0 - ca_value: 'ENGLISH' - - - name: 'eth1' - location: - coordinate_based: - altitude: 2200 - datum: 'WGS84' - longitude: '222.267255W' - latitude: '33.524449N' - state: replaced -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# "before": [ -# { -# "location": { -# "coordinate_based": { -# "altitude": 2200, -# "datum": "WGS84", -# "latitude": "33.524449N", -# "longitude": "222.267255W" -# } -# }, -# "name": "eth2" -# }, -# { -# "location": { -# "civic_based": { -# "ca_info": [ -# { -# "ca_type": 0, -# "ca_value": "ENGLISH" -# } -# ], -# "country_code": "US" -# } -# }, -# "name": "eth1" -# } -# ] -# -# "commands": [ -# "delete service lldp interface eth2 location", -# "set service lldp interface eth2 'disable'", -# "set service lldp interface eth2 location civic-based country-code 'US'", -# "set service lldp interface eth2 location civic-based ca-type 0 ca-value 'ENGLISH'", -# "delete service lldp interface eth1 location", -# "set service lldp interface eth1 'disable'", -# "set service lldp interface eth1 location coordinate-based latitude '33.524449N'", -# "set service lldp interface eth1 location coordinate-based altitude '2200'", -# "set service lldp interface eth1 location coordinate-based datum 'WGS84'", -# "set service lldp interface eth1 location coordinate-based longitude '222.267255W'" -# ] -# -# "after": [ -# { -# "location": { -# "civic_based": { -# "ca_info": [ -# { -# "ca_type": 0, -# "ca_value": "ENGLISH" -# } -# ], -# "country_code": "US" -# } -# }, -# "name": "eth2" -# }, -# { -# "location": { -# "coordinate_based": { -# "altitude": 2200, -# "datum": "WGS84", -# "latitude": "33.524449N", -# "longitude": "222.267255W" -# } -# }, -# "name": "eth1" -# } -# ] -# -# After state: -# ------------- -# -# vyos@vyos:~$ show configuration commands | grep lldp -# set service lldp interface eth1 'disable' -# set service lldp interface eth1 location coordinate-based altitude '2200' -# set service lldp interface eth1 location coordinate-based datum 'WGS84' -# set service lldp interface eth1 location coordinate-based latitude '33.524449N' -# set service lldp interface eth1 location coordinate-based longitude '222.267255W' -# set service lldp interface eth2 'disable' -# set service lldp interface eth2 location civic-based ca-type 0 ca-value 'ENGLISH' -# set service lldp interface eth2 location civic-based country-code 'US' - - -# Using overridden -# -# Before state -# -------------- -# -# vyos@vyos:~$ show configuration commands | grep lldp -# set service lldp interface eth1 'disable' -# set service lldp interface eth1 location coordinate-based altitude '2200' -# set service lldp interface eth1 location coordinate-based datum 'WGS84' -# set service lldp interface eth1 location coordinate-based latitude '33.524449N' -# set service lldp interface eth1 location coordinate-based longitude '222.267255W' -# set service lldp interface eth2 'disable' -# set service lldp interface eth2 location civic-based ca-type 0 ca-value 'ENGLISH' -# set service lldp interface eth2 location civic-based country-code 'US' -# -- name: Overrides all device configuration with provided configuration - vyos_lag_interfaces: - config: - - name: 'eth2' - location: - elin: 0000000911 - - state: overridden -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# "before": [ -# { -# "enable": false, -# "location": { -# "civic_based": { -# "ca_info": [ -# { -# "ca_type": 0, -# "ca_value": "ENGLISH" -# } -# ], -# "country_code": "US" -# } -# }, -# "name": "eth2" -# }, -# { -# "enable": false, -# "location": { -# "coordinate_based": { -# "altitude": 2200, -# "datum": "WGS84", -# "latitude": "33.524449N", -# "longitude": "222.267255W" -# } -# }, -# "name": "eth1" -# } -# ] -# -# "commands": [ -# "delete service lldp interface eth2 location", -# "delete service lldp interface eth2 disable", -# "set service lldp interface eth2 location elin 0000000911" -# -# -# "after": [ -# { -# "location": { -# "elin": 0000000911 -# }, -# "name": "eth2" -# } -# ] -# -# -# After state -# ------------ -# -# vyos@vyos# run show configuration commands | grep lldp -# set service lldp interface eth2 location elin '0000000911' - - -# Using deleted -# -# Before state -# ------------- -# -# vyos@vyos# run show configuration commands | grep lldp -# set service lldp interface eth2 location elin '0000000911' -# -- name: Delete lldp interface attributes of given interfaces. - vyos_lag_interfaces: - config: - - name: 'eth2' - state: deleted -# -# -# ------------------------ -# Module Execution Results -# ------------------------ -# - "before": [ - { - "location": { - "elin": 0000000911 - }, - "name": "eth2" - } - ] -# "commands": [ -# "commands": [ -# "delete service lldp interface eth2" -# ] -# -# "after": [] -# After state -# ------------ -# vyos@vyos# run show configuration commands | grep lldp -# set service 'lldp' - - -""" -RETURN = """ -before: - description: The configuration as structured data prior to module invocation. - returned: always - type: list - sample: > - The configuration returned will always be in the same format - of the parameters above. -after: - description: The configuration as structured data after module completion. - returned: when changed - type: list - sample: > - The configuration returned will always be in the same format - of the parameters above. -commands: - description: The set of commands pushed to the remote device. - returned: always - type: list - sample: - - "set service lldp interface eth2 'disable'" - - "delete service lldp interface eth1 location" -""" - - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.vyos.argspec.lldp_interfaces.lldp_interfaces import Lldp_interfacesArgs -from ansible.module_utils.network.vyos.config.lldp_interfaces.lldp_interfaces import Lldp_interfaces - - -def main(): - """ - Main entry point for module execution - - :returns: the result form module invocation - """ - required_if = [('state', 'merged', ('config',)), - ('state', 'replaced', ('config',)), - ('state', 'overridden', ('config',))] - module = AnsibleModule(argument_spec=Lldp_interfacesArgs.argument_spec, required_if=required_if, - supports_check_mode=True) - - result = Lldp_interfaces(module).execute_module() - module.exit_json(**result) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/vyos/vyos_logging.py b/lib/ansible/modules/network/vyos/vyos_logging.py deleted file mode 100644 index 6d9911da07..0000000000 --- a/lib/ansible/modules/network/vyos/vyos_logging.py +++ /dev/null @@ -1,264 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'network'} - -DOCUMENTATION = """ ---- -module: vyos_logging -version_added: "2.4" -author: "Trishna Guha (@trishnaguha)" -short_description: Manage logging on network devices -description: - - This module provides declarative management of logging - on Vyatta Vyos devices. -notes: - - Tested against VyOS 1.1.8 (helium). - - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). -options: - dest: - description: - - Destination of the logs. - choices: ['console', 'file', 'global', 'host', 'user'] - name: - description: - - If value of C(dest) is I(file) it indicates file-name, - for I(user) it indicates username and for I(host) indicates - the host name to be notified. - facility: - description: - - Set logging facility. - level: - description: - - Set logging severity levels. - aggregate: - description: List of logging definitions. - state: - description: - - State of the logging configuration. - default: present - choices: ['present', 'absent'] -extends_documentation_fragment: vyos -""" - -EXAMPLES = """ -- name: configure console logging - vyos_logging: - dest: console - facility: all - level: crit - -- name: remove console logging configuration - vyos_logging: - dest: console - state: absent - -- name: configure file logging - vyos_logging: - dest: file - name: test - facility: local3 - level: err - -- name: Add logging aggregate - vyos_logging: - aggregate: - - { dest: file, name: test1, facility: all, level: info } - - { dest: file, name: test2, facility: news, level: debug } - state: present - -- name: Remove logging aggregate - vyos_logging: - aggregate: - - { dest: console, facility: all, level: info } - - { dest: console, facility: daemon, level: warning } - - { dest: file, name: test2, facility: news, level: debug } - state: absent -""" - -RETURN = """ -commands: - description: The list of configuration mode commands to send to the device - returned: always - type: list - sample: - - set system syslog global facility all level notice -""" - -import re - -from copy import deepcopy - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.common.utils import remove_default_spec -from ansible.module_utils.network.vyos.vyos import get_config, load_config -from ansible.module_utils.network.vyos.vyos import vyos_argument_spec - - -def spec_to_commands(updates, module): - commands = list() - want, have = updates - - for w in want: - dest = w['dest'] - name = w['name'] - facility = w['facility'] - level = w['level'] - state = w['state'] - del w['state'] - - if state == 'absent' and w in have: - if w['name']: - commands.append('delete system syslog {0} {1} facility {2} level {3}'.format( - dest, name, facility, level)) - else: - commands.append('delete system syslog {0} facility {1} level {2}'.format( - dest, facility, level)) - elif state == 'present' and w not in have: - if w['name']: - commands.append('set system syslog {0} {1} facility {2} level {3}'.format( - dest, name, facility, level)) - else: - commands.append('set system syslog {0} facility {1} level {2}'.format( - dest, facility, level)) - - return commands - - -def config_to_dict(module): - data = get_config(module) - obj = [] - - for line in data.split('\n'): - if line.startswith('set system syslog'): - match = re.search(r'set system syslog (\S+)', line, re.M) - dest = match.group(1) - if dest == 'host': - match = re.search(r'host (\S+)', line, re.M) - name = match.group(1) - elif dest == 'file': - match = re.search(r'file (\S+)', line, re.M) - name = match.group(1) - elif dest == 'user': - match = re.search(r'user (\S+)', line, re.M) - name = match.group(1) - else: - name = None - - if 'facility' in line: - match = re.search(r'facility (\S+)', line, re.M) - facility = match.group(1) - if 'level' in line: - match = re.search(r'level (\S+)', line, re.M) - level = match.group(1).strip("'") - - obj.append({'dest': dest, - 'name': name, - 'facility': facility, - 'level': level}) - - return obj - - -def map_params_to_obj(module, required_if=None): - obj = [] - - aggregate = module.params.get('aggregate') - if aggregate: - for item in aggregate: - for key in item: - if item.get(key) is None: - item[key] = module.params[key] - - module._check_required_if(required_if, item) - obj.append(item.copy()) - - else: - if module.params['dest'] not in ('host', 'file', 'user'): - module.params['name'] = None - - obj.append({ - 'dest': module.params['dest'], - 'name': module.params['name'], - 'facility': module.params['facility'], - 'level': module.params['level'], - 'state': module.params['state'] - }) - - return obj - - -def main(): - """ main entry point for module execution - """ - element_spec = dict( - dest=dict(type='str', choices=['console', 'file', 'global', 'host', 'user']), - name=dict(type='str'), - facility=dict(type='str'), - level=dict(type='str'), - state=dict(default='present', choices=['present', 'absent']), - ) - - aggregate_spec = deepcopy(element_spec) - - # remove default in aggregate spec, to handle common arguments - remove_default_spec(aggregate_spec) - - argument_spec = dict( - aggregate=dict(type='list', elements='dict', options=aggregate_spec), - ) - - argument_spec.update(element_spec) - - argument_spec.update(vyos_argument_spec) - required_if = [('dest', 'host', ['name', 'facility', 'level']), - ('dest', 'file', ['name', 'facility', 'level']), - ('dest', 'user', ['name', 'facility', 'level']), - ('dest', 'console', ['facility', 'level']), - ('dest', 'global', ['facility', 'level'])] - - module = AnsibleModule(argument_spec=argument_spec, - required_if=required_if, - supports_check_mode=True) - - warnings = list() - - result = {'changed': False} - if warnings: - result['warnings'] = warnings - want = map_params_to_obj(module, required_if=required_if) - have = config_to_dict(module) - - commands = spec_to_commands((want, have), module) - result['commands'] = commands - - if commands: - commit = not module.check_mode - load_config(module, commands, commit=commit) - result['changed'] = True - - module.exit_json(**result) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/vyos/vyos_ping.py b/lib/ansible/modules/network/vyos/vyos_ping.py deleted file mode 100644 index 4364e3d393..0000000000 --- a/lib/ansible/modules/network/vyos/vyos_ping.py +++ /dev/null @@ -1,248 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# - -from __future__ import absolute_import, division, print_function -__metaclass__ = type - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - -DOCUMENTATION = """ ---- -module: vyos_ping -short_description: Tests reachability using ping from VyOS network devices -description: - - Tests reachability using ping from a VyOS device to a remote destination. - - Tested against VyOS 1.1.8 (helium) - - For a general purpose network module, see the M(net_ping) module. - - For Windows targets, use the M(win_ping) module instead. - - For targets running Python, use the M(ping) module instead. -author: - - Nilashish Chakraborty (@NilashishC) -version_added: '2.8' -options: - dest: - description: - - The IP Address or hostname (resolvable by the device) of the remote node. - required: true - count: - description: - - Number of packets to send to check reachability. - type: int - default: 5 - source: - description: - - The source interface or IP Address to use while sending the ping packet(s). - ttl: - description: - - The time-to-live value for the ICMP packet(s). - type: int - size: - description: - - Determines the size (in bytes) of the ping packet(s). - type: int - interval: - description: - - Determines the interval (in seconds) between consecutive pings. - type: int - state: - description: - - Determines if the expected result is success or fail. - choices: [ absent, present ] - default: present -notes: - - Tested against VyOS 1.1.8 (helium). - - For a general purpose network module, see the M(net_ping) module. - - For Windows targets, use the M(win_ping) module instead. - - For targets running Python, use the M(ping) module instead. - - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). -extends_documentation_fragment: vyos -""" - -EXAMPLES = """ -- name: Test reachability to 10.10.10.10 - vyos_ping: - dest: 10.10.10.10 - -- name: Test reachability to 10.20.20.20 using source and ttl set - vyos_ping: - dest: 10.20.20.20 - source: eth0 - ttl: 128 - -- name: Test unreachability to 10.30.30.30 using interval - vyos_ping: - dest: 10.30.30.30 - interval: 3 - state: absent - -- name: Test reachability to 10.40.40.40 setting count and source - vyos_ping: - dest: 10.40.40.40 - source: eth1 - count: 20 - size: 512 -""" - -RETURN = """ -commands: - description: List of commands sent. - returned: always - type: list - sample: ["ping 10.8.38.44 count 10 interface eth0 ttl 128"] -packet_loss: - description: Percentage of packets lost. - returned: always - type: str - sample: "0%" -packets_rx: - description: Packets successfully received. - returned: always - type: int - sample: 20 -packets_tx: - description: Packets successfully transmitted. - returned: always - type: int - sample: 20 -rtt: - description: The round trip time (RTT) stats. - returned: when ping succeeds - type: dict - sample: {"avg": 2, "max": 8, "min": 1, "mdev": 24} -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.vyos.vyos import run_commands -from ansible.module_utils.network.vyos.vyos import vyos_argument_spec -import re - - -def main(): - """ main entry point for module execution - """ - argument_spec = dict( - count=dict(type="int", default=5), - dest=dict(type="str", required=True), - source=dict(type="str"), - ttl=dict(type='int'), - size=dict(type='int'), - interval=dict(type='int'), - state=dict(type="str", choices=["absent", "present"], default="present"), - ) - - argument_spec.update(vyos_argument_spec) - - module = AnsibleModule(argument_spec=argument_spec) - - count = module.params["count"] - dest = module.params["dest"] - source = module.params["source"] - size = module.params["size"] - ttl = module.params["ttl"] - interval = module.params["interval"] - - warnings = list() - - results = {} - if warnings: - results["warnings"] = warnings - - results["commands"] = [build_ping(dest, count, size, interval, source, ttl)] - - ping_results = run_commands(module, commands=results["commands"]) - ping_results_list = ping_results[0].split("\n") - - rtt_info, rate_info = None, None - for line in ping_results_list: - if line.startswith('rtt'): - rtt_info = line - if line.startswith('%s packets transmitted' % count): - rate_info = line - - if rtt_info: - rtt = parse_rtt(rtt_info) - for k, v in rtt.items(): - if rtt[k] is not None: - rtt[k] = int(v) - results["rtt"] = rtt - - pkt_loss, rx, tx = parse_rate(rate_info) - results["packet_loss"] = str(pkt_loss) + "%" - results["packets_rx"] = int(rx) - results["packets_tx"] = int(tx) - - validate_results(module, pkt_loss, results) - - module.exit_json(**results) - - -def build_ping(dest, count, size=None, interval=None, source=None, ttl=None): - cmd = "ping {0} count {1}".format(dest, str(count)) - - if source: - cmd += " interface {0}".format(source) - - if ttl: - cmd += " ttl {0}".format(str(ttl)) - - if size: - cmd += " size {0}".format(str(size)) - - if interval: - cmd += " interval {0}".format(str(interval)) - - return cmd - - -def parse_rate(rate_info): - rate_re = re.compile( - r"(?P<tx>\d+) (?:\w+) (?:\w+), (?P<rx>\d+) (?:\w+), (?P<pkt_loss>\d+)% (?:\w+) (?:\w+), (?:\w+) (?P<time>\d+)") - rate_err_re = re.compile( - r"(?P<tx>\d+) (?:\w+) (?:\w+), (?P<rx>\d+) (?:\w+), (?:[+-])(?P<err>\d+) (?:\w+), (?P<pkt_loss>\d+)% (?:\w+) (?:\w+), (?:\w+) (?P<time>\d+)") - - if rate_re.match(rate_info): - rate = rate_re.match(rate_info) - elif rate_err_re.match(rate_info): - rate = rate_err_re.match(rate_info) - - return rate.group("pkt_loss"), rate.group("rx"), rate.group("tx") - - -def parse_rtt(rtt_info): - rtt_re = re.compile( - r"rtt (?:.*)=(?:\s*)(?P<min>\d*).(?:\d*)/(?P<avg>\d*).(?:\d*)/(?P<max>\d+).(?:\d*)/(?P<mdev>\d*)") - rtt = rtt_re.match(rtt_info) - - return rtt.groupdict() - - -def validate_results(module, loss, results): - state = module.params["state"] - if state == "present" and int(loss) == 100: - module.fail_json(msg="Ping failed unexpectedly", **results) - elif state == "absent" and int(loss) < 100: - module.fail_json(msg="Ping succeeded unexpectedly", **results) - - -if __name__ == "__main__": - main() diff --git a/lib/ansible/modules/network/vyos/vyos_static_routes.py b/lib/ansible/modules/network/vyos/vyos_static_routes.py deleted file mode 100644 index 95bb738094..0000000000 --- a/lib/ansible/modules/network/vyos/vyos_static_routes.py +++ /dev/null @@ -1,1147 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -# Copyright 2019 Red Hat -# GNU General Public License v3.0+ -# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -############################################# -# WARNING # -############################################# -# -# This file is auto generated by the resource -# module builder playbook. -# -# Do not edit this file manually. -# -# Changes to this file will be over written -# by the resource module builder. -# -# Changes should be made in the model used to -# generate this file or in the resource module -# builder template. -# -############################################# - -""" -The module file for vyos_static_routes -""" - -from __future__ import absolute_import, division, print_function -__metaclass__ = type - -ANSIBLE_METADATA = { - 'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'network' -} - -DOCUMENTATION = """ ---- -module: vyos_static_routes -version_added: '2.10' -short_description: Manages attributes of static routes on VyOS network devices. -description: This module manages attributes of static routes on VyOS network devices. -notes: - - Tested against VyOS 1.1.8 (helium). - - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). -author: - - Rohit Thakur (@rohitthakur2590) -options: - config: - description: A provided static route configuration. - type: list - elements: dict - suboptions: - address_families: - description: A dictionary specifying the address family to which the static route(s) belong. - type: list - elements: dict - suboptions: - afi: - description: - - Specifies the type of route. - type: str - choices: ['ipv4', 'ipv6'] - required: True - routes: - description: A ditionary that specify the static route configurations. - type: list - elements: dict - suboptions: - dest: - description: - - An IPv4/v6 address in CIDR notation that specifies the destination network for the static route. - type: str - required: True - blackhole_config: - description: - - Configured to silently discard packets. - type: dict - suboptions: - type: - description: - - This is to configure only blackhole. - type: str - distance: - description: - - Distance for the route. - type: int - next_hops: - description: - - Next hops to the specified destination. - type: list - elements: dict - suboptions: - forward_router_address: - description: - - The IP address of the next hop that can be used to reach the destination network. - type: str - required: True - enabled: - description: - - Disable IPv4/v6 next-hop static route. - type: bool - admin_distance: - description: - - Distance value for the route. - type: int - interface: - description: - - Name of the outgoing interface. - type: str - running_config: - description: - - The module, by default, will connect to the remote device and - retrieve the current running-config to use as a base for comparing - against the contents of source. There are times when it is not - desirable to have the task get the current running-config for - every task in a playbook. The I(running_config) argument allows the - implementer to pass in the configuration to use as the base - config for comparison. This value of this option should be the - output received from device by executing command - C(show configuration commands | grep 'static route') - type: str - state: - description: - - The state of the configuration after module completion. - type: str - choices: - - merged - - replaced - - overridden - - deleted - - gathered - - rendered - - parsed - default: merged -""" -EXAMPLES = """ -# Using merged -# -# Before state: -# ------------- -# -# vyos@vyos:~$ show configuration commands | grep static -# -- name: Merge the provided configuration with the exisiting running configuration - vyos_static_routes: - config: - - address_families: - - afi: 'ipv4' - routes: - - dest: 192.0.2.32/28 - blackhole_config: - type: 'blackhole' - next_hops: - - forward_router_address: 192.0.2.6 - - forward_router_address: 192.0.2.7 - - address_families: - - afi: 'ipv6' - routes: - - dest: 2001:db8:1000::/36 - blackhole_config: - distance: 2 - next_hops: - - forward_router_address: 2001:db8:2000:2::1 - - forward_router_address: 2001:db8:2000:2::2 - state: merged -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# before": [] -# -# "commands": [ -# "set protocols static route 192.0.2.32/28", -# "set protocols static route 192.0.2.32/28 blackhole", -# "set protocols static route 192.0.2.32/28 next-hop '192.0.2.6'", -# "set protocols static route 192.0.2.32/28 next-hop '192.0.2.7'", -# "set protocols static route6 2001:db8:1000::/36", -# "set protocols static route6 2001:db8:1000::/36 blackhole distance '2'", -# "set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1'", -# "set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'" -# ] -# -# "after": [ -# { -# "address_families": [ -# { -# "afi": "ipv4", -# "routes": [ -# { -# "blackhole_config": { -# "type": "blackhole" -# }, -# "dest": "192.0.2.32/28", -# "next_hops": [ -# { -# "forward_router_address": "192.0.2.6" -# }, -# { -# "forward_router_address": "192.0.2.7" -# } -# ] -# } -# ] -# }, -# { -# "afi": "ipv6", -# "routes": [ -# { -# "blackhole_config": { -# "distance": 2 -# }, -# "dest": "2001:db8:1000::/36", -# "next_hops": [ -# { -# "forward_router_address": "2001:db8:2000:2::1" -# }, -# { -# "forward_router_address": "2001:db8:2000:2::2" -# } -# ] -# } -# ] -# } -# ] -# } -# ] -# -# After state: -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep static -# set protocols static route 192.0.2.32/28 'blackhole' -# set protocols static route 192.0.2.32/28 next-hop '192.0.2.6' -# set protocols static route 192.0.2.32/28 next-hop '192.0.2.7' -# set protocols static route6 2001:db8:1000::/36 blackhole distance '2' -# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1' -# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2' - - -# Using replaced -# -# Before state: -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep static -# set protocols static route 192.0.2.32/28 'blackhole' -# set protocols static route 192.0.2.32/28 next-hop '192.0.2.6' -# set protocols static route 192.0.2.32/28 next-hop '192.0.2.7' -# set protocols static route 192.0.2.33/28 'blackhole' -# set protocols static route 192.0.2.33/28 next-hop '192.0.2.3' -# set protocols static route 192.0.2.33/28 next-hop '192.0.2.4' -# set protocols static route6 2001:db8:1000::/36 blackhole distance '2' -# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1' -# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2' -# -- name: Replace device configurations of listed static routes with provided configurations - vyos_static_routes: - config: - - address_families: - - afi: 'ipv4' - routes: - - dest: 192.0.2.32/28 - blackhole_config: - distance: 2 - next_hops: - - forward_router_address: 192.0.2.7 - enabled: false - - forward_router_address: 192.0.2.9 - state: replaced -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# "before": [ -# { -# "address_families": [ -# { -# "afi": "ipv4", -# "routes": [ -# { -# "blackhole_config": { -# "type": "blackhole" -# }, -# "dest": "192.0.2.32/28", -# "next_hops": [ -# { -# "forward_router_address": "192.0.2.6" -# }, -# { -# "forward_router_address": "192.0.2.7" -# } -# ] -# }, -# { -# "blackhole_config": { -# "type": "blackhole" -# }, -# "dest": "192.0.2.33/28", -# "next_hops": [ -# { -# "forward_router_address": "192.0.2.3" -# }, -# { -# "forward_router_address": "192.0.2.4" -# } -# ] -# } -# ] -# }, -# { -# "afi": "ipv6", -# "routes": [ -# { -# "blackhole_config": { -# "distance": 2 -# }, -# "dest": "2001:db8:1000::/36", -# "next_hops": [ -# { -# "forward_router_address": "2001:db8:2000:2::1" -# }, -# { -# "forward_router_address": "2001:db8:2000:2::2" -# } -# ] -# } -# ] -# } -# ] -# } -# ] -# -# "commands": [ -# "delete protocols static route 192.0.2.32/28 next-hop '192.0.2.6'", -# "delete protocols static route 192.0.2.32/28 next-hop '192.0.2.7'", -# "set protocols static route 192.0.2.32/28 next-hop 192.0.2.7 'disable'", -# "set protocols static route 192.0.2.32/28 next-hop '192.0.2.7'", -# "set protocols static route 192.0.2.32/28 next-hop '192.0.2.9'", -# "set protocols static route 192.0.2.32/28 blackhole distance '2'" -# ] -# -# "after": [ -# { -# "address_families": [ -# { -# "afi": "ipv4", -# "routes": [ -# { -# "blackhole_config": { -# "distance": 2 -# }, -# "dest": "192.0.2.32/28", -# "next_hops": [ -# { -# "enabled": false, -# "forward_router_address": "192.0.2.7" -# }, -# { -# "forward_router_address": "192.0.2.9" -# } -# ] -# }, -# { -# "blackhole_config": { -# "type": "blackhole" -# }, -# "dest": "192.0.2.33/28", -# "next_hops": [ -# { -# "forward_router_address": "192.0.2.3" -# }, -# { -# "forward_router_address": "192.0.2.4" -# } -# ] -# } -# ] -# }, -# { -# "afi": "ipv6", -# "routes": [ -# { -# "blackhole_config": { -# "distance": 2 -# }, -# "dest": "2001:db8:1000::/36", -# "next_hops": [ -# { -# "forward_router_address": "2001:db8:2000:2::1" -# }, -# { -# "forward_router_address": "2001:db8:2000:2::2" -# } -# ] -# } -# ] -# } -# ] -# } -# ] -# -# After state: -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep static -# set protocols static route 192.0.2.32/28 blackhole distance '2' -# set protocols static route 192.0.2.32/28 next-hop 192.0.2.7 'disable' -# set protocols static route 192.0.2.32/28 next-hop '192.0.2.9' -# set protocols static route 192.0.2.33/28 'blackhole' -# set protocols static route 192.0.2.33/28 next-hop '192.0.2.3' -# set protocols static route 192.0.2.33/28 next-hop '192.0.2.4' -# set protocols static route6 2001:db8:1000::/36 blackhole distance '2' -# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1' -# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2' - - -# Using overridden -# -# Before state -# -------------- -# -# vyos@vyos:~$ show configuration commands| grep static -# set protocols static route 192.0.2.32/28 blackhole distance '2' -# set protocols static route 192.0.2.32/28 next-hop 192.0.2.7 'disable' -# set protocols static route 192.0.2.32/28 next-hop '192.0.2.9' -# set protocols static route6 2001:db8:1000::/36 blackhole distance '2' -# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1' -# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2' -# -- name: Overrides all device configuration with provided configuration - vyos_static_routes: - config: - - address_families: - - afi: 'ipv4' - routes: - - dest: 198.0.2.48/28 - next_hops: - - forward_router_address: 192.0.2.18 - state: overridden -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# "before": [ -# { -# "address_families": [ -# { -# "afi": "ipv4", -# "routes": [ -# { -# "blackhole_config": { -# "distance": 2 -# }, -# "dest": "192.0.2.32/28", -# "next_hops": [ -# { -# "enabled": false, -# "forward_router_address": "192.0.2.7" -# }, -# { -# "forward_router_address": "192.0.2.9" -# } -# ] -# } -# ] -# }, -# { -# "afi": "ipv6", -# "routes": [ -# { -# "blackhole_config": { -# "distance": 2 -# }, -# "dest": "2001:db8:1000::/36", -# "next_hops": [ -# { -# "forward_router_address": "2001:db8:2000:2::1" -# }, -# { -# "forward_router_address": "2001:db8:2000:2::2" -# } -# ] -# } -# ] -# } -# ] -# } -# ] -# -# "commands": [ -# "delete protocols static route 192.0.2.32/28", -# "delete protocols static route6 2001:db8:1000::/36", -# "set protocols static route 198.0.2.48/28", -# "set protocols static route 198.0.2.48/28 next-hop '192.0.2.18'" -# -# -# "after": [ -# { -# "address_families": [ -# { -# "afi": "ipv4", -# "routes": [ -# { -# "dest": "198.0.2.48/28", -# "next_hops": [ -# { -# "forward_router_address": "192.0.2.18" -# } -# ] -# } -# ] -# } -# ] -# } -# ] -# -# -# After state -# ------------ -# -# vyos@vyos:~$ show configuration commands| grep static -# set protocols static route 198.0.2.48/28 next-hop '192.0.2.18' - - -# Using deleted to delete static route based on destination -# -# Before state -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep static -# set protocols static route 192.0.2.32/28 'blackhole' -# set protocols static route 192.0.2.32/28 next-hop '192.0.2.6' -# set protocols static route 192.0.2.32/28 next-hop '192.0.2.7' -# set protocols static route6 2001:db8:1000::/36 blackhole distance '2' -# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1' -# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2' -# -- name: Delete static route per destination. - vyos_static_routes: - config: - - address_families: - - afi: 'ipv4' - routes: - - dest: '192.0.2.32/28' - - afi: 'ipv6' - routes: - - dest: '2001:db8:1000::/36' - state: deleted -# -# -# ------------------------ -# Module Execution Results -# ------------------------ -# -# "before": [ -# { -# "address_families": [ -# { -# "afi": "ipv4", -# "routes": [ -# { -# "blackhole_config": { -# "type": "blackhole" -# }, -# "dest": "192.0.2.32/28", -# "next_hops": [ -# { -# "forward_router_address": "192.0.2.6" -# }, -# { -# "forward_router_address": "192.0.2.7" -# } -# ] -# } -# ] -# }, -# { -# "afi": "ipv6", -# "routes": [ -# { -# "blackhole_config": { -# "distance": 2 -# }, -# "dest": "2001:db8:1000::/36", -# "next_hops": [ -# { -# "forward_router_address": "2001:db8:2000:2::1" -# }, -# { -# "forward_router_address": "2001:db8:2000:2::2" -# } -# ] -# } -# ] -# } -# ] -# } -# ] -# "commands": [ -# "delete protocols static route 192.0.2.32/28", -# "delete protocols static route6 2001:db8:1000::/36" -# ] -# -# "after": [] -# After state -# ------------ -# vyos@vyos# run show configuration commands | grep static -# set protocols 'static' - - -# Using deleted to delete static route based on afi -# -# Before state -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep static -# set protocols static route 192.0.2.32/28 'blackhole' -# set protocols static route 192.0.2.32/28 next-hop '192.0.2.6' -# set protocols static route 192.0.2.32/28 next-hop '192.0.2.7' -# set protocols static route6 2001:db8:1000::/36 blackhole distance '2' -# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1' -# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2' -# -- name: Delete static route based on afi. - vyos_static_routes: - config: - - address_families: - - afi: 'ipv4' - - afi: 'ipv6' - state: deleted -# -# -# ------------------------ -# Module Execution Results -# ------------------------ -# -# "before": [ -# { -# "address_families": [ -# { -# "afi": "ipv4", -# "routes": [ -# { -# "blackhole_config": { -# "type": "blackhole" -# }, -# "dest": "192.0.2.32/28", -# "next_hops": [ -# { -# "forward_router_address": "192.0.2.6" -# }, -# { -# "forward_router_address": "192.0.2.7" -# } -# ] -# } -# ] -# }, -# { -# "afi": "ipv6", -# "routes": [ -# { -# "blackhole_config": { -# "distance": 2 -# }, -# "dest": "2001:db8:1000::/36", -# "next_hops": [ -# { -# "forward_router_address": "2001:db8:2000:2::1" -# }, -# { -# "forward_router_address": "2001:db8:2000:2::2" -# } -# ] -# } -# ] -# } -# ] -# } -# ] -# "commands": [ -# "delete protocols static route", -# "delete protocols static route6" -# ] -# -# "after": [] -# After state -# ------------ -# vyos@vyos# run show configuration commands | grep static -# set protocols 'static' - - -# Using deleted to delete all the static routes when passes config is empty -# -# Before state -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep static -# set protocols static route 192.0.2.32/28 'blackhole' -# set protocols static route 192.0.2.32/28 next-hop '192.0.2.6' -# set protocols static route 192.0.2.32/28 next-hop '192.0.2.7' -# set protocols static route6 2001:db8:1000::/36 blackhole distance '2' -# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1' -# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2' -# -- name: Delete all the static routes. - vyos_static_routes: - config: - state: deleted -# -# -# ------------------------ -# Module Execution Results -# ------------------------ -# -# "before": [ -# { -# "address_families": [ -# { -# "afi": "ipv4", -# "routes": [ -# { -# "blackhole_config": { -# "type": "blackhole" -# }, -# "dest": "192.0.2.32/28", -# "next_hops": [ -# { -# "forward_router_address": "192.0.2.6" -# }, -# { -# "forward_router_address": "192.0.2.7" -# } -# ] -# } -# ] -# }, -# { -# "afi": "ipv6", -# "routes": [ -# { -# "blackhole_config": { -# "distance": 2 -# }, -# "dest": "2001:db8:1000::/36", -# "next_hops": [ -# { -# "forward_router_address": "2001:db8:2000:2::1" -# }, -# { -# "forward_router_address": "2001:db8:2000:2::2" -# } -# ] -# } -# ] -# } -# ] -# } -# ] -# "commands": [ -# "delete protocols static route", -# "delete protocols static route6" -# ] -# -# "after": [] -# After state -# ------------ -# vyos@vyos# run show configuration commands | grep static -# set protocols 'static' - - -# Using deleted to delete static route based on next-hop -# -# Before state -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep static -# set protocols static route 192.0.2.32/28 'blackhole' -# set protocols static route 192.0.2.32/28 next-hop '192.0.2.6' -# set protocols static route 192.0.2.32/28 next-hop '192.0.2.7' -# set protocols static route6 2001:db8:1000::/36 blackhole distance '2' -# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1' -# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2' -# -- name: Delete static routes per next-hops - vyos_static_routes: - config: - - address_families: - - afi: 'ipv4' - routes: - - dest: '192.0.2.32/28' - next-hops: - - forward_router_address: '192.0.2.6' - - afi: 'ipv6' - routes: - - dest: '2001:db8:1000::/36' - next-hops: - - forward_router_address: '2001:db8:2000:2::1' - state: deleted -# -# -# ------------------------ -# Module Execution Results -# ------------------------ -# -# "before": [ -# { -# "address_families": [ -# { -# "afi": "ipv4", -# "routes": [ -# { -# "blackhole_config": { -# "type": "blackhole" -# }, -# "dest": "192.0.2.32/28", -# "next_hops": [ -# { -# "forward_router_address": "192.0.2.6" -# }, -# { -# "forward_router_address": "192.0.2.7" -# } -# ] -# } -# ] -# }, -# { -# "afi": "ipv6", -# "routes": [ -# { -# "blackhole_config": { -# "distance": 2 -# }, -# "dest": "2001:db8:1000::/36", -# "next_hops": [ -# { -# "forward_router_address": "2001:db8:2000:2::1" -# }, -# { -# "forward_router_address": "2001:db8:2000:2::2" -# } -# ] -# } -# ] -# } -# ] -# } -# ] -# "commands": [ -# "delete protocols static route 192.0.2.32/28 next-hop '192.0.2.6'", -# "delete protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1'" -# ] -# -# "after": [ -# { -# "address_families": [ -# { -# "afi": "ipv4", -# "routes": [ -# { -# "blackhole_config": { -# "type": "blackhole" -# }, -# "dest": "192.0.2.32/28", -# "next_hops": [ -# { -# "forward_router_address": "192.0.2.7" -# } -# ] -# } -# ] -# }, -# { -# "afi": "ipv6", -# "routes": [ -# { -# "blackhole_config": { -# "distance": 2 -# }, -# "dest": "2001:db8:1000::/36", -# "next_hops": [ -# { -# "forward_router_address": "2001:db8:2000:2::2" -# } -# ] -# } -# ] -# } -# ] -# } -# ] -# After state -# ------------ -# vyos@vyos:~$ show configuration commands| grep static -# set protocols static route 192.0.2.32/28 'blackhole' -# set protocols static route 192.0.2.32/28 next-hop '192.0.2.7' -# set protocols static route6 2001:db8:1000::/36 blackhole distance '2' -# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2' - - -# Using rendered -# -# -- name: Render the commands for provided configuration - vyos_static_routes: - config: - - address_families: - - afi: 'ipv4' - routes: - - dest: 192.0.2.32/28 - blackhole_config: - type: 'blackhole' - next_hops: - - forward_router_address: 192.0.2.6 - - forward_router_address: 192.0.2.7 - - address_families: - - afi: 'ipv6' - routes: - - dest: 2001:db8:1000::/36 - blackhole_config: - distance: 2 - next_hops: - - forward_router_address: 2001:db8:2000:2::1 - - forward_router_address: 2001:db8:2000:2::2 - state: rendered -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# -# "rendered": [ -# "set protocols static route 192.0.2.32/28", -# "set protocols static route 192.0.2.32/28 blackhole", -# "set protocols static route 192.0.2.32/28 next-hop '192.0.2.6'", -# "set protocols static route 192.0.2.32/28 next-hop '192.0.2.7'", -# "set protocols static route6 2001:db8:1000::/36", -# "set protocols static route6 2001:db8:1000::/36 blackhole distance '2'", -# "set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1'", -# "set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'" -# ] - - -# Using parsed -# -# -- name: Render the commands for provided configuration - vyos_static_routes: - running_config: - "set protocols static route 192.0.2.32/28 'blackhole' - set protocols static route 192.0.2.32/28 next-hop '192.0.2.6' - set protocols static route 192.0.2.32/28 next-hop '192.0.2.7' - set protocols static route6 2001:db8:1000::/36 blackhole distance '2' - set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1' - set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'" - state: parsed -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# -# "parsed": [ -# { -# "address_families": [ -# { -# "afi": "ipv4", -# "routes": [ -# { -# "blackhole_config": { -# "distance": 2 -# }, -# "dest": "192.0.2.32/28", -# "next_hops": [ -# { -# "forward_router_address": "2001:db8:2000:2::2" -# } -# ] -# } -# ] -# }, -# { -# "afi": "ipv6", -# "routes": [ -# { -# "blackhole_config": { -# "distance": 2 -# }, -# "dest": "2001:db8:1000::/36", -# "next_hops": [ -# { -# "forward_router_address": "2001:db8:2000:2::2" -# } -# ] -# } -# ] -# } -# ] -# } -# ] - - -# Using gathered -# -# Before state: -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep static -# set protocols static route 192.0.2.32/28 'blackhole' -# set protocols static route 192.0.2.32/28 next-hop '192.0.2.6' -# set protocols static route 192.0.2.32/28 next-hop '192.0.2.7' -# set protocols static route6 2001:db8:1000::/36 blackhole distance '2' -# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1' -# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2' -# -- name: Gather listed static routes with provided configurations - vyos_static_routes: - config: - state: gathered -# -# -# ------------------------- -# Module Execution Result -# ------------------------- -# -# "gathered": [ -# { -# "address_families": [ -# { -# "afi": "ipv4", -# "routes": [ -# { -# "blackhole_config": { -# "type": "blackhole" -# }, -# "dest": "192.0.2.32/28", -# "next_hops": [ -# { -# "forward_router_address": "192.0.2.6" -# }, -# { -# "forward_router_address": "192.0.2.7" -# } -# ] -# } -# ] -# }, -# { -# "afi": "ipv6", -# "routes": [ -# { -# "blackhole_config": { -# "distance": 2 -# }, -# "dest": "2001:db8:1000::/36", -# "next_hops": [ -# { -# "forward_router_address": "2001:db8:2000:2::1" -# }, -# { -# "forward_router_address": "2001:db8:2000:2::2" -# } -# ] -# } -# ] -# } -# ] -# } -# ] -# -# -# After state: -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep static -# set protocols static route 192.0.2.32/28 'blackhole' -# set protocols static route 192.0.2.32/28 next-hop '192.0.2.6' -# set protocols static route 192.0.2.32/28 next-hop '192.0.2.7' -# set protocols static route6 2001:db8:1000::/36 blackhole distance '2' -# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1' -# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2' - - -""" -RETURN = """ -before: - description: The configuration prior to the model invocation. - returned: always - type: list - sample: > - The configuration returned will always be in the same format - of the parameters above. -after: - description: The resulting configuration model invocation. - returned: when changed - type: list - sample: > - The configuration returned will always be in the same format - of the parameters above. -commands: - description: The set of commands pushed to the remote device. - returned: always - type: list - sample: - - "set protocols static route 192.0.2.32/28 next-hop '192.0.2.6'" - - "set protocols static route 192.0.2.32/28 'blackhole'" -""" - - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.vyos.argspec.static_routes.static_routes import Static_routesArgs -from ansible.module_utils.network.vyos.config.static_routes.static_routes import Static_routes - - -def main(): - """ - Main entry point for module execution - - :returns: the result form module invocation - """ - required_if = [('state', 'merged', ('config',)), - ('state', 'replaced', ('config',)), - ('state', 'overridden', ('config',)), - ('state', 'parsed', ('running_config',))] - mutually_exclusive = [('config', 'running_config')] - - module = AnsibleModule(argument_spec=Static_routesArgs.argument_spec, - required_if=required_if, - supports_check_mode=True, - mutually_exclusive=mutually_exclusive) - result = Static_routes(module).execute_module() - module.exit_json(**result) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/vyos/vyos_system.py b/lib/ansible/modules/network/vyos/vyos_system.py deleted file mode 100644 index 0d59e4580d..0000000000 --- a/lib/ansible/modules/network/vyos/vyos_system.py +++ /dev/null @@ -1,212 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'network'} - - -DOCUMENTATION = """ ---- -module: "vyos_system" -version_added: "2.3" -author: "Nathaniel Case (@Qalthos)" -short_description: Run `set system` commands on VyOS devices -description: - - Runs one or more commands on remote devices running VyOS. - This module can also be introspected to validate key parameters before - returning successfully. -extends_documentation_fragment: vyos -notes: - - Tested against VyOS 1.1.8 (helium). - - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). -options: - host_name: - description: - - Configure the device hostname parameter. This option takes an ASCII string value. - domain_name: - description: - - The new domain name to apply to the device. - name_servers: - description: - - A list of name servers to use with the device. Mutually exclusive with - I(domain_search) - aliases: ['name_server'] - domain_search: - description: - - A list of domain names to search. Mutually exclusive with - I(name_server) - state: - description: - - Whether to apply (C(present)) or remove (C(absent)) the settings. - default: present - choices: ['present', 'absent'] -""" - -RETURN = """ -commands: - description: The list of configuration mode commands to send to the device - returned: always - type: list - sample: - - set system hostname vyos01 - - set system domain-name foo.example.com -""" - -EXAMPLES = """ -- name: configure hostname and domain-name - vyos_system: - host_name: vyos01 - domain_name: test.example.com - -- name: remove all configuration - vyos_system: - state: absent - -- name: configure name servers - vyos_system: - name_servers - - 8.8.8.8 - - 8.8.4.4 - -- name: configure domain search suffixes - vyos_system: - domain_search: - - sub1.example.com - - sub2.example.com -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.vyos.vyos import get_config, load_config -from ansible.module_utils.network.vyos.vyos import vyos_argument_spec - - -def spec_key_to_device_key(key): - device_key = key.replace('_', '-') - - # domain-search is longer than just it's key - if device_key == 'domain-search': - device_key += ' domain' - - return device_key - - -def config_to_dict(module): - data = get_config(module) - - config = {'domain_search': [], 'name_server': []} - - for line in data.split('\n'): - if line.startswith('set system host-name'): - config['host_name'] = line[22:-1] - elif line.startswith('set system domain-name'): - config['domain_name'] = line[24:-1] - elif line.startswith('set system domain-search domain'): - config['domain_search'].append(line[33:-1]) - elif line.startswith('set system name-server'): - config['name_server'].append(line[24:-1]) - - return config - - -def spec_to_commands(want, have): - commands = [] - - state = want.pop('state') - - # state='absent' by itself has special meaning - if state == 'absent' and all(v is None for v in want.values()): - # Clear everything - for key in have: - commands.append('delete system %s' % spec_key_to_device_key(key)) - - for key in want: - if want[key] is None: - continue - - current = have.get(key) - proposed = want[key] - device_key = spec_key_to_device_key(key) - - # These keys are lists which may need to be reconciled with the device - if key in ['domain_search', 'name_server']: - if not proposed: - # Empty list was passed, delete all values - commands.append("delete system %s" % device_key) - for config in proposed: - if state == 'absent' and config in current: - commands.append("delete system %s '%s'" % (device_key, config)) - elif state == 'present' and config not in current: - commands.append("set system %s '%s'" % (device_key, config)) - else: - if state == 'absent' and current and proposed: - commands.append('delete system %s' % device_key) - elif state == 'present' and proposed and proposed != current: - commands.append("set system %s '%s'" % (device_key, proposed)) - - return commands - - -def map_param_to_obj(module): - return { - 'host_name': module.params['host_name'], - 'domain_name': module.params['domain_name'], - 'domain_search': module.params['domain_search'], - 'name_server': module.params['name_server'], - 'state': module.params['state'] - } - - -def main(): - argument_spec = dict( - host_name=dict(type='str'), - domain_name=dict(type='str'), - domain_search=dict(type='list'), - name_server=dict(type='list', aliases=['name_servers']), - state=dict(type='str', default='present', choices=['present', 'absent']), - ) - - argument_spec.update(vyos_argument_spec) - - module = AnsibleModule( - argument_spec=argument_spec, - supports_check_mode=True, - mutually_exclusive=[('domain_name', 'domain_search')], - ) - - warnings = list() - - result = {'changed': False, 'warnings': warnings} - - want = map_param_to_obj(module) - have = config_to_dict(module) - - commands = spec_to_commands(want, have) - result['commands'] = commands - - if commands: - commit = not module.check_mode - load_config(module, commands, commit=commit) - result['changed'] = True - - module.exit_json(**result) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/vyos/vyos_user.py b/lib/ansible/modules/network/vyos/vyos_user.py deleted file mode 100644 index f60467f87c..0000000000 --- a/lib/ansible/modules/network/vyos/vyos_user.py +++ /dev/null @@ -1,332 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# (c) 2017, Ansible by Red Hat, inc -# -# This file is part of Ansible by Red Hat -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'network'} - -DOCUMENTATION = """ ---- -module: vyos_user -version_added: "2.4" -author: "Trishna Guha (@trishnaguha)" -short_description: Manage the collection of local users on VyOS device -description: - - This module provides declarative management of the local usernames - configured on network devices. It allows playbooks to manage - either individual usernames or the collection of usernames in the - current running config. It also supports purging usernames from the - configuration that are not explicitly defined. -notes: - - Tested against VyOS 1.1.8 (helium). - - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). -options: - aggregate: - description: - - The set of username objects to be configured on the remote - VyOS device. The list entries can either be the username or - a hash of username and properties. This argument is mutually - exclusive with the C(name) argument. - aliases: ['users', 'collection'] - name: - description: - - The username to be configured on the VyOS device. - This argument accepts a string value and is mutually exclusive - with the C(aggregate) argument. - Please note that this option is not same as C(provider username). - full_name: - description: - - The C(full_name) argument provides the full name of the user - account to be created on the remote device. This argument accepts - any text string value. - configured_password: - description: - - The password to be configured on the VyOS device. The - password needs to be provided in clear and it will be encrypted - on the device. - Please note that this option is not same as C(provider password). - update_password: - description: - - Since passwords are encrypted in the device running config, this - argument will instruct the module when to change the password. When - set to C(always), the password will always be updated in the device - and when set to C(on_create) the password will be updated only if - the username is created. - default: always - choices: ['on_create', 'always'] - level: - description: - - The C(level) argument configures the level of the user when logged - into the system. This argument accepts string values admin or operator. - aliases: ['role'] - purge: - description: - - Instructs the module to consider the - resource definition absolute. It will remove any previously - configured usernames on the device with the exception of the - `admin` user (the current defined set of users). - type: bool - default: false - state: - description: - - Configures the state of the username definition - as it relates to the device operational configuration. When set - to I(present), the username(s) should be configured in the device active - configuration and when set to I(absent) the username(s) should not be - in the device active configuration - default: present - choices: ['present', 'absent'] -extends_documentation_fragment: vyos -""" - -EXAMPLES = """ -- name: create a new user - vyos_user: - name: ansible - configured_password: password - state: present -- name: remove all users except admin - vyos_user: - purge: yes -- name: set multiple users to level operator - vyos_user: - aggregate: - - name: netop - - name: netend - level: operator - state: present -- name: Change Password for User netop - vyos_user: - name: netop - configured_password: "{{ new_password }}" - update_password: always - state: present -""" - -RETURN = """ -commands: - description: The list of configuration mode commands to send to the device - returned: always - type: list - sample: - - set system login user test level operator - - set system login user authentication plaintext-password password -""" - -import re - -from copy import deepcopy -from functools import partial - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.common.utils import remove_default_spec -from ansible.module_utils.network.vyos.vyos import get_config, load_config -from ansible.module_utils.six import iteritems -from ansible.module_utils.network.vyos.vyos import vyos_argument_spec - - -def validate_level(value, module): - if value not in ('admin', 'operator'): - module.fail_json(msg='level must be either admin or operator, got %s' % value) - - -def spec_to_commands(updates, module): - commands = list() - update_password = module.params['update_password'] - - def needs_update(want, have, x): - return want.get(x) and (want.get(x) != have.get(x)) - - def add(command, want, x): - command.append('set system login user %s %s' % (want['name'], x)) - - for update in updates: - want, have = update - - if want['state'] == 'absent': - commands.append('delete system login user %s' % want['name']) - continue - - if needs_update(want, have, 'level'): - add(commands, want, "level %s" % want['level']) - - if needs_update(want, have, 'full_name'): - add(commands, want, "full-name %s" % want['full_name']) - - if needs_update(want, have, 'configured_password'): - if update_password == 'always' or not have: - add(commands, want, 'authentication plaintext-password %s' % want['configured_password']) - - return commands - - -def parse_level(data): - match = re.search(r'level (\S+)', data, re.M) - if match: - level = match.group(1)[1:-1] - return level - - -def parse_full_name(data): - match = re.search(r'full-name (\S+)', data, re.M) - if match: - full_name = match.group(1)[1:-1] - return full_name - - -def config_to_dict(module): - data = get_config(module) - - match = re.findall(r'^set system login user (\S+)', data, re.M) - if not match: - return list() - - instances = list() - - for user in set(match): - regex = r' %s .+$' % user - cfg = re.findall(regex, data, re.M) - cfg = '\n'.join(cfg) - obj = { - 'name': user, - 'state': 'present', - 'configured_password': None, - 'level': parse_level(cfg), - 'full_name': parse_full_name(cfg) - } - instances.append(obj) - - return instances - - -def get_param_value(key, item, module): - # if key doesn't exist in the item, get it from module.params - if not item.get(key): - value = module.params[key] - - # validate the param value (if validator func exists) - validator = globals().get('validate_%s' % key) - if all((value, validator)): - validator(value, module) - - return value - - -def map_params_to_obj(module): - aggregate = module.params['aggregate'] - if not aggregate: - if not module.params['name'] and module.params['purge']: - return list() - else: - users = [{'name': module.params['name']}] - else: - users = list() - for item in aggregate: - if not isinstance(item, dict): - users.append({'name': item}) - else: - users.append(item) - - objects = list() - - for item in users: - get_value = partial(get_param_value, item=item, module=module) - item['configured_password'] = get_value('configured_password') - item['full_name'] = get_value('full_name') - item['level'] = get_value('level') - item['state'] = get_value('state') - objects.append(item) - - return objects - - -def update_objects(want, have): - updates = list() - for entry in want: - item = next((i for i in have if i['name'] == entry['name']), None) - if item is None: - updates.append((entry, {})) - elif item: - for key, value in iteritems(entry): - if value and value != item[key]: - updates.append((entry, item)) - return updates - - -def main(): - """ main entry point for module execution - """ - element_spec = dict( - name=dict(), - - full_name=dict(), - level=dict(aliases=['role']), - - configured_password=dict(no_log=True), - update_password=dict(default='always', choices=['on_create', 'always']), - - state=dict(default='present', choices=['present', 'absent']) - ) - - aggregate_spec = deepcopy(element_spec) - aggregate_spec['name'] = dict(required=True) - - # remove default in aggregate spec, to handle common arguments - remove_default_spec(aggregate_spec) - - argument_spec = dict( - aggregate=dict(type='list', elements='dict', options=aggregate_spec, aliases=['users', 'collection']), - purge=dict(type='bool', default=False) - ) - - argument_spec.update(element_spec) - argument_spec.update(vyos_argument_spec) - - mutually_exclusive = [('name', 'aggregate')] - module = AnsibleModule(argument_spec=argument_spec, - mutually_exclusive=mutually_exclusive, - supports_check_mode=True) - - warnings = list() - result = {'changed': False, 'warnings': warnings} - - want = map_params_to_obj(module) - have = config_to_dict(module) - commands = spec_to_commands(update_objects(want, have), module) - - if module.params['purge']: - want_users = [x['name'] for x in want] - have_users = [x['name'] for x in have] - for item in set(have_users).difference(want_users): - commands.append('delete system login user %s' % item) - - result['commands'] = commands - - if commands: - commit = not module.check_mode - load_config(module, commands, commit=commit) - result['changed'] = True - - module.exit_json(**result) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/network/vyos/vyos_vlan.py b/lib/ansible/modules/network/vyos/vyos_vlan.py deleted file mode 100644 index 0bf191f3f9..0000000000 --- a/lib/ansible/modules/network/vyos/vyos_vlan.py +++ /dev/null @@ -1,331 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# Copyright: (c) 2017, Ansible by Red Hat, inc -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -from __future__ import absolute_import, division, print_function -__metaclass__ = type - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'network'} - -DOCUMENTATION = """ ---- -module: vyos_vlan -version_added: "2.5" -author: "Trishna Guha (@trishnaguha)" -short_description: Manage VLANs on VyOS network devices -description: - - This module provides declarative management of VLANs - on VyOS network devices. -notes: - - Tested against VyOS 1.1.8 (helium). - - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). -options: - name: - description: - - Name of the VLAN. - address: - description: - - Configure Virtual interface address. - vlan_id: - description: - - ID of the VLAN. Range 0-4094. - required: true - interfaces: - description: - - List of interfaces that should be associated to the VLAN. - required: true - associated_interfaces: - description: - - This is a intent option and checks the operational state of the for given vlan C(name) - for associated interfaces. If the value in the C(associated_interfaces) does not match with - the operational state of vlan on device it will result in failure. - version_added: "2.5" - delay: - description: - - Delay the play should wait to check for declarative intent params values. - default: 10 - aggregate: - description: List of VLANs definitions. - purge: - description: - - Purge VLANs not defined in the I(aggregate) parameter. - default: no - type: bool - state: - description: - - State of the VLAN configuration. - default: present - choices: ['present', 'absent'] -extends_documentation_fragment: vyos -""" - -EXAMPLES = """ -- name: Create vlan - vyos_vlan: - vlan_id: 100 - name: vlan-100 - interfaces: eth1 - state: present - -- name: Add interfaces to VLAN - vyos_vlan: - vlan_id: 100 - interfaces: - - eth1 - - eth2 - -- name: Configure virtual interface address - vyos_vlan: - vlan_id: 100 - interfaces: eth1 - address: 172.26.100.37/24 - -- name: vlan interface config + intent - vyos_vlan: - vlan_id: 100 - interfaces: eth0 - associated_interfaces: - - eth0 - -- name: vlan intent check - vyos_vlan: - vlan_id: 100 - associated_interfaces: - - eth3 - - eth4 - -- name: Delete vlan - vyos_vlan: - vlan_id: 100 - interfaces: eth1 - state: absent -""" - -RETURN = """ -commands: - description: The list of configuration mode commands to send to the device - returned: always - type: list - sample: - - set interfaces ethernet eth1 vif 100 description VLAN 100 - - set interfaces ethernet eth1 vif 100 address 172.26.100.37/24 - - delete interfaces ethernet eth1 vif 100 -""" -import re -import time - -from copy import deepcopy - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.common.utils import remove_default_spec -from ansible.module_utils.network.vyos.vyos import load_config, run_commands -from ansible.module_utils.network.vyos.vyos import vyos_argument_spec - - -def search_obj_in_list(vlan_id, lst): - obj = list() - for o in lst: - if o['vlan_id'] == vlan_id: - obj.append(o) - return obj - - -def map_obj_to_commands(updates, module): - commands = list() - want, have = updates - purge = module.params['purge'] - - for w in want: - vlan_id = w['vlan_id'] - name = w['name'] - address = w['address'] - state = w['state'] - - obj_in_have = search_obj_in_list(vlan_id, have) - - if state == 'absent': - if obj_in_have: - for obj in obj_in_have: - for i in obj['interfaces']: - commands.append('delete interfaces ethernet {0} vif {1}'.format(i, vlan_id)) - - elif state == 'present': - if not obj_in_have: - if w['interfaces'] and w['vlan_id']: - for i in w['interfaces']: - cmd = 'set interfaces ethernet {0} vif {1}'.format(i, vlan_id) - if w['name']: - commands.append(cmd + ' description {0}'.format(name)) - elif w['address']: - commands.append(cmd + ' address {0}'.format(address)) - else: - commands.append(cmd) - - if purge: - for h in have: - obj_in_want = search_obj_in_list(h['vlan_id'], want) - if not obj_in_want: - for i in h['interfaces']: - commands.append('delete interfaces ethernet {0} vif {1}'.format(i, h['vlan_id'])) - - return commands - - -def map_params_to_obj(module): - obj = [] - aggregate = module.params.get('aggregate') - if aggregate: - for item in aggregate: - for key in item: - if item.get(key) is None: - item[key] = module.params[key] - - d = item.copy() - - if not d['vlan_id']: - module.fail_json(msg='vlan_id is required') - - d['vlan_id'] = str(d['vlan_id']) - module._check_required_one_of(module.required_one_of, item) - - obj.append(d) - else: - obj.append({ - 'vlan_id': str(module.params['vlan_id']), - 'name': module.params['name'], - 'address': module.params['address'], - 'state': module.params['state'], - 'interfaces': module.params['interfaces'], - 'associated_interfaces': module.params['associated_interfaces'] - }) - - return obj - - -def map_config_to_obj(module): - objs = [] - - output = run_commands(module, 'show interfaces') - lines = output[0].strip().splitlines()[3:] - - for l in lines: - splitted_line = re.split(r'\s{2,}', l.strip()) - obj = {} - - eth = splitted_line[0].strip("'") - if eth.startswith('eth'): - obj['interfaces'] = [] - if '.' in eth: - interface = eth.split('.')[0] - obj['interfaces'].append(interface) - obj['vlan_id'] = eth.split('.')[-1] - else: - obj['interfaces'].append(eth) - obj['vlan_id'] = None - - if splitted_line[1].strip("'") != '-': - obj['address'] = splitted_line[1].strip("'") - - if len(splitted_line) > 3: - obj['name'] = splitted_line[3].strip("'") - obj['state'] = 'present' - objs.append(obj) - - return objs - - -def check_declarative_intent_params(want, module, result): - - have = None - obj_interface = list() - is_delay = False - - for w in want: - if w.get('associated_interfaces') is None: - continue - - if result['changed'] and not is_delay: - time.sleep(module.params['delay']) - is_delay = True - - if have is None: - have = map_config_to_obj(module) - - obj_in_have = search_obj_in_list(w['vlan_id'], have) - if obj_in_have: - for obj in obj_in_have: - obj_interface.extend(obj['interfaces']) - - for w in want: - if w.get('associated_interfaces') is None: - continue - for i in w['associated_interfaces']: - if (set(obj_interface) - set(w['associated_interfaces'])) != set([]): - module.fail_json(msg='Interface {0} not configured on vlan {1}'.format(i, w['vlan_id'])) - - -def main(): - """ main entry point for module execution - """ - element_spec = dict( - vlan_id=dict(type='int'), - name=dict(), - address=dict(), - interfaces=dict(type='list'), - associated_interfaces=dict(type='list'), - delay=dict(default=10, type='int'), - state=dict(default='present', - choices=['present', 'absent']) - ) - - aggregate_spec = deepcopy(element_spec) - - # remove default in aggregate spec, to handle common arguments - remove_default_spec(aggregate_spec) - - argument_spec = dict( - aggregate=dict(type='list', elements='dict', options=aggregate_spec), - purge=dict(default=False, type='bool') - ) - - argument_spec.update(element_spec) - argument_spec.update(vyos_argument_spec) - - required_one_of = [['vlan_id', 'aggregate'], - ['aggregate', 'interfaces', 'associated_interfaces']] - - mutually_exclusive = [['vlan_id', 'aggregate']] - module = AnsibleModule(argument_spec=argument_spec, - supports_check_mode=True, - required_one_of=required_one_of, - mutually_exclusive=mutually_exclusive) - - warnings = list() - result = {'changed': False} - - if warnings: - result['warnings'] = warnings - - want = map_params_to_obj(module) - have = map_config_to_obj(module) - - commands = map_obj_to_commands((want, have), module) - result['commands'] = commands - - if commands: - commit = not module.check_mode - load_config(module, commands, commit=commit) - result['changed'] = True - - check_declarative_intent_params(want, module, result) - - module.exit_json(**result) - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/plugins/action/vyos.py b/lib/ansible/plugins/action/vyos.py deleted file mode 100644 index 9347c54ef5..0000000000 --- a/lib/ansible/plugins/action/vyos.py +++ /dev/null @@ -1,91 +0,0 @@ -# -# (c) 2016 Red Hat Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -import sys -import copy - -from ansible.plugins.action.network import ActionModule as ActionNetworkModule -from ansible.module_utils.network.common.utils import load_provider -from ansible.module_utils.network.vyos.vyos import vyos_provider_spec -from ansible.utils.display import Display - -display = Display() - - -class ActionModule(ActionNetworkModule): - - def run(self, tmp=None, task_vars=None): - del tmp # tmp no longer has any effect - - module_name = self._task.action.split('.')[-1] - self._config_module = True if module_name == 'vyos_config' else False - persistent_connection = self._play_context.connection.split('.')[-1] - warnings = [] - - if persistent_connection == 'network_cli': - provider = self._task.args.get('provider', {}) - if any(provider.values()): - display.warning('provider is unnecessary when using network_cli and will be ignored') - del self._task.args['provider'] - elif self._play_context.connection == 'local': - provider = load_provider(vyos_provider_spec, self._task.args) - pc = copy.deepcopy(self._play_context) - pc.connection = 'ansible.netcommon.network_cli' - pc.network_os = 'vyos.vyos.vyos' - pc.remote_addr = provider['host'] or self._play_context.remote_addr - pc.port = int(provider['port'] or self._play_context.port or 22) - pc.remote_user = provider['username'] or self._play_context.connection_user - pc.password = provider['password'] or self._play_context.password - pc.private_key_file = provider['ssh_keyfile'] or self._play_context.private_key_file - - connection = self._shared_loader_obj.connection_loader.get('ansible.netcommon.persistent', pc, sys.stdin, - task_uuid=self._task._uuid) - - # TODO: Remove below code after ansible minimal is cut out - if connection is None: - pc.connection = 'network_cli' - pc.network_os = 'vyos' - connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin, task_uuid=self._task._uuid) - - display.vvv('using connection plugin %s (was local)' % pc.connection, pc.remote_addr) - - command_timeout = int(provider['timeout']) if provider['timeout'] else connection.get_option('persistent_command_timeout') - connection.set_options(direct={'persistent_command_timeout': command_timeout}) - - socket_path = connection.run() - display.vvvv('socket_path: %s' % socket_path, pc.remote_addr) - if not socket_path: - return {'failed': True, - 'msg': 'unable to open shell. Please see: ' + - 'https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell'} - - task_vars['ansible_socket'] = socket_path - warnings.append(['connection local support for this module is deprecated and will be removed in version 2.14, use connection %s' % pc.connection]) - else: - return {'failed': True, 'msg': 'Connection type %s is not valid for this module' % self._play_context.connection} - - result = super(ActionModule, self).run(task_vars=task_vars) - if warnings: - if 'warnings' in result: - result['warnings'].extend(warnings) - else: - result['warnings'] = warnings - return result diff --git a/lib/ansible/plugins/cliconf/vyos.py b/lib/ansible/plugins/cliconf/vyos.py deleted file mode 100644 index 1b539d55ff..0000000000 --- a/lib/ansible/plugins/cliconf/vyos.py +++ /dev/null @@ -1,274 +0,0 @@ -# -# (c) 2017 Red Hat Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -DOCUMENTATION = """ ---- -author: Ansible Networking Team -cliconf: vyos -short_description: Use vyos cliconf to run command on VyOS platform -description: - - This vyos plugin provides low level abstraction apis for - sending and receiving CLI commands from VyOS network devices. -version_added: "2.4" -""" - -import re -import json - -from ansible.errors import AnsibleConnectionFailure -from ansible.module_utils._text import to_text -from ansible.module_utils.common._collections_compat import Mapping -from ansible.module_utils.network.common.config import NetworkConfig -from ansible.module_utils.network.common.utils import to_list -from ansible.plugins.cliconf import CliconfBase - - -class Cliconf(CliconfBase): - - def get_device_info(self): - device_info = {} - - device_info['network_os'] = 'vyos' - reply = self.get('show version') - data = to_text(reply, errors='surrogate_or_strict').strip() - - match = re.search(r'Version:\s*(.*)', data) - if match: - device_info['network_os_version'] = match.group(1) - - match = re.search(r'HW model:\s*(\S+)', data) - if match: - device_info['network_os_model'] = match.group(1) - - reply = self.get('show host name') - device_info['network_os_hostname'] = to_text(reply, errors='surrogate_or_strict').strip() - - return device_info - - def get_config(self, flags=None, format=None): - if format: - option_values = self.get_option_values() - if format not in option_values['format']: - raise ValueError("'format' value %s is invalid. Valid values of format are %s" % (format, ', '.join(option_values['format']))) - - if not flags: - flags = [] - - if format == 'text': - command = 'show configuration' - else: - command = 'show configuration commands' - - command += ' '.join(to_list(flags)) - command = command.strip() - - out = self.send_command(command) - return out - - def edit_config(self, candidate=None, commit=True, replace=None, comment=None): - resp = {} - operations = self.get_device_operations() - self.check_edit_config_capability(operations, candidate, commit, replace, comment) - - results = [] - requests = [] - self.send_command('configure') - for cmd in to_list(candidate): - if not isinstance(cmd, Mapping): - cmd = {'command': cmd} - - results.append(self.send_command(**cmd)) - requests.append(cmd['command']) - out = self.get('compare') - out = to_text(out, errors='surrogate_or_strict') - diff_config = out if not out.startswith('No changes') else None - - if diff_config: - if commit: - try: - self.commit(comment) - except AnsibleConnectionFailure as e: - msg = 'commit failed: %s' % e.message - self.discard_changes() - raise AnsibleConnectionFailure(msg) - else: - self.send_command('exit') - else: - self.discard_changes() - else: - self.send_command('exit') - if to_text(self._connection.get_prompt(), errors='surrogate_or_strict').strip().endswith('#'): - self.discard_changes() - - if diff_config: - resp['diff'] = diff_config - resp['response'] = results - resp['request'] = requests - return resp - - def get(self, command=None, prompt=None, answer=None, sendonly=False, output=None, newline=True, check_all=False): - if not command: - raise ValueError('must provide value of command to execute') - if output: - raise ValueError("'output' value %s is not supported for get" % output) - - return self.send_command(command=command, prompt=prompt, answer=answer, sendonly=sendonly, newline=newline, check_all=check_all) - - def commit(self, comment=None): - if comment: - command = 'commit comment "{0}"'.format(comment) - else: - command = 'commit' - self.send_command(command) - - def discard_changes(self): - self.send_command('exit discard') - - def get_diff(self, candidate=None, running=None, diff_match='line', diff_ignore_lines=None, path=None, diff_replace=None): - diff = {} - device_operations = self.get_device_operations() - option_values = self.get_option_values() - - if candidate is None and device_operations['supports_generate_diff']: - raise ValueError("candidate configuration is required to generate diff") - - if diff_match not in option_values['diff_match']: - raise ValueError("'match' value %s in invalid, valid values are %s" % (diff_match, ', '.join(option_values['diff_match']))) - - if diff_replace: - raise ValueError("'replace' in diff is not supported") - - if diff_ignore_lines: - raise ValueError("'diff_ignore_lines' in diff is not supported") - - if path: - raise ValueError("'path' in diff is not supported") - - set_format = candidate.startswith('set') or candidate.startswith('delete') - candidate_obj = NetworkConfig(indent=4, contents=candidate) - if not set_format: - config = [c.line for c in candidate_obj.items] - commands = list() - # this filters out less specific lines - for item in config: - for index, entry in enumerate(commands): - if item.startswith(entry): - del commands[index] - break - commands.append(item) - - candidate_commands = ['set %s' % cmd.replace(' {', '') for cmd in commands] - - else: - candidate_commands = str(candidate).strip().split('\n') - - if diff_match == 'none': - diff['config_diff'] = list(candidate_commands) - return diff - - running_commands = [str(c).replace("'", '') for c in running.splitlines()] - - updates = list() - visited = set() - - for line in candidate_commands: - item = str(line).replace("'", '') - - if not item.startswith('set') and not item.startswith('delete'): - raise ValueError('line must start with either `set` or `delete`') - - elif item.startswith('set') and item not in running_commands: - updates.append(line) - - elif item.startswith('delete'): - if not running_commands: - updates.append(line) - else: - item = re.sub(r'delete', 'set', item) - for entry in running_commands: - if entry.startswith(item) and line not in visited: - updates.append(line) - visited.add(line) - - diff['config_diff'] = list(updates) - return diff - - def run_commands(self, commands=None, check_rc=True): - if commands is None: - raise ValueError("'commands' value is required") - - responses = list() - for cmd in to_list(commands): - if not isinstance(cmd, Mapping): - cmd = {'command': cmd} - - output = cmd.pop('output', None) - if output: - raise ValueError("'output' value %s is not supported for run_commands" % output) - - try: - out = self.send_command(**cmd) - except AnsibleConnectionFailure as e: - if check_rc: - raise - out = getattr(e, 'err', e) - - responses.append(out) - - return responses - - def get_device_operations(self): - return { - 'supports_diff_replace': False, - 'supports_commit': True, - 'supports_rollback': False, - 'supports_defaults': False, - 'supports_onbox_diff': True, - 'supports_commit_comment': True, - 'supports_multiline_delimiter': False, - 'supports_diff_match': True, - 'supports_diff_ignore_lines': False, - 'supports_generate_diff': False, - 'supports_replace': False - } - - def get_option_values(self): - return { - 'format': ['text', 'set'], - 'diff_match': ['line', 'none'], - 'diff_replace': [], - 'output': [] - } - - def get_capabilities(self): - result = super(Cliconf, self).get_capabilities() - result['rpc'] += ['commit', 'discard_changes', 'get_diff', 'run_commands'] - result['device_operations'] = self.get_device_operations() - result.update(self.get_option_values()) - return json.dumps(result) - - def set_cli_prompt_context(self): - """ - Make sure we are in the operational cli mode - :return: None - """ - if self._connection.connected: - self._update_cli_prompt_context(config_context='#', exit_command='exit discard') diff --git a/lib/ansible/plugins/doc_fragments/vyos.py b/lib/ansible/plugins/doc_fragments/vyos.py deleted file mode 100644 index 12d06913a3..0000000000 --- a/lib/ansible/plugins/doc_fragments/vyos.py +++ /dev/null @@ -1,65 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright: (c) 2015, Peter Sprygada <psprygada@ansible.com> -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - - -class ModuleDocFragment(object): - - # Standard files documentation fragment - DOCUMENTATION = r''' -options: - provider: - description: - - B(Deprecated) - - "Starting with Ansible 2.5 we recommend using C(connection: network_cli)." - - For more information please see the L(Network Guide, ../network/getting_started/network_differences.html#multiple-communication-protocols). - - HORIZONTALLINE - - A dict object containing connection details. - type: dict - suboptions: - host: - description: - - Specifies the DNS host name or address for connecting to the remote - device over the specified transport. The value of host is used as - the destination address for the transport. - type: str - required: true - port: - description: - - Specifies the port to use when building the connection to the remote - device. - type: int - default: 22 - username: - description: - - Configures the username to use to authenticate the connection to - the remote device. This value is used to authenticate - the SSH session. If the value is not specified in the task, the - value of environment variable C(ANSIBLE_NET_USERNAME) will be used instead. - type: str - password: - description: - - Specifies the password to use to authenticate the connection to - the remote device. This value is used to authenticate - the SSH session. If the value is not specified in the task, the - value of environment variable C(ANSIBLE_NET_PASSWORD) will be used instead. - type: str - timeout: - description: - - Specifies the timeout in seconds for communicating with the network device - for either connecting or sending commands. If the timeout is - exceeded before the operation is completed, the module will error. - type: int - default: 10 - ssh_keyfile: - description: - - Specifies the SSH key to use to authenticate the connection to - the remote device. This value is the path to the - key used to authenticate the SSH session. If the value is not specified - in the task, the value of environment variable C(ANSIBLE_NET_SSH_KEYFILE) - will be used instead. - type: path -notes: - - For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide <network_guide>` -''' diff --git a/lib/ansible/plugins/terminal/vyos.py b/lib/ansible/plugins/terminal/vyos.py deleted file mode 100644 index a68a0323be..0000000000 --- a/lib/ansible/plugins/terminal/vyos.py +++ /dev/null @@ -1,50 +0,0 @@ -# -# (c) 2016 Red Hat Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -import os -import re - -from ansible.plugins.terminal import TerminalBase -from ansible.errors import AnsibleConnectionFailure - - -class TerminalModule(TerminalBase): - - terminal_stdout_re = [ - re.compile(br"[\r\n]?[\w+\-\.:\/\[\]]+(?:\([^\)]+\)){,3}(?:>|#) ?$"), - re.compile(br"\@[\w\-\.]+:\S+?[>#\$] ?$") - ] - - terminal_stderr_re = [ - re.compile(br"\n\s*Invalid command:"), - re.compile(br"\nCommit failed"), - re.compile(br"\n\s+Set failed"), - ] - - terminal_length = os.getenv('ANSIBLE_VYOS_TERMINAL_LENGTH', 10000) - - def on_open_shell(self): - try: - for cmd in (b'set terminal length 0', b'set terminal width 512'): - self._exec_cli_command(cmd) - self._exec_cli_command(b'set terminal length %d' % self.terminal_length) - except AnsibleConnectionFailure: - raise AnsibleConnectionFailure('unable to set terminal parameters') diff --git a/test/integration/targets/vyos_banner/aliases b/test/integration/targets/vyos_banner/aliases deleted file mode 100644 index 8071e1f75b..0000000000 --- a/test/integration/targets/vyos_banner/aliases +++ /dev/null @@ -1 +0,0 @@ -shippable/vyos/group1 diff --git a/test/integration/targets/vyos_banner/defaults/main.yaml b/test/integration/targets/vyos_banner/defaults/main.yaml deleted file mode 100644 index 9ef5ba5165..0000000000 --- a/test/integration/targets/vyos_banner/defaults/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -testcase: "*" -test_items: [] diff --git a/test/integration/targets/vyos_banner/tasks/cli.yaml b/test/integration/targets/vyos_banner/tasks/cli.yaml deleted file mode 100644 index 890d3acf3e..0000000000 --- a/test/integration/targets/vyos_banner/tasks/cli.yaml +++ /dev/null @@ -1,22 +0,0 @@ ---- -- name: collect all cli test cases - find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - register: test_cases - delegate_to: localhost - -- name: set test_items - set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - -- name: run test case (connection=network_cli) - include: "{{ test_case_to_run }} ansible_connection=network_cli" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - -- name: run test case (connection=local) - include: "{{ test_case_to_run }} ansible_connection=local" - with_first_found: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run diff --git a/test/integration/targets/vyos_banner/tasks/main.yaml b/test/integration/targets/vyos_banner/tasks/main.yaml deleted file mode 100644 index d4cf26fc4a..0000000000 --- a/test/integration/targets/vyos_banner/tasks/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -- {include: cli.yaml, tags: ['cli']} diff --git a/test/integration/targets/vyos_banner/tests/cli/basic-no-login.yaml b/test/integration/targets/vyos_banner/tests/cli/basic-no-login.yaml deleted file mode 100644 index d513d2e184..0000000000 --- a/test/integration/targets/vyos_banner/tests/cli/basic-no-login.yaml +++ /dev/null @@ -1,41 +0,0 @@ ---- -- debug: - msg: "cli/basic-no-login.yaml on connection={{ ansible_connection }}" - -- name: Setup - vyos_banner: - banner: pre-login - text: | - Junk pre-login banner - over multiple lines - state: present - -- name: remove pre-login - vyos_banner: - banner: pre-login - state: absent - register: result - -- debug: - msg: "{{ result }}" - -- assert: - that: - - "result.changed == true" - - "'delete system login banner pre-login' in result.commands" - -- name: remove pre-login (idempotent) - vyos_banner: - banner: pre-login - state: absent - register: result - -- assert: - that: - - "result.changed == false" - - "result.commands | length == 0" - - -# FIXME add in tests for everything defined in docs -# FIXME Test state:absent + test: -# FIXME Without powers ensure "privileged mode required" diff --git a/test/integration/targets/vyos_banner/tests/cli/basic-post-login.yaml b/test/integration/targets/vyos_banner/tests/cli/basic-post-login.yaml deleted file mode 100644 index bda84a8c8b..0000000000 --- a/test/integration/targets/vyos_banner/tests/cli/basic-post-login.yaml +++ /dev/null @@ -1,47 +0,0 @@ ---- -- debug: - msg: "cli/basic-post-login.yaml on connection={{ ansible_connection }}" - -- name: setup - remove post-login - vyos_banner: - banner: post-login - state: absent - -- name: Set post-login - vyos_banner: - banner: post-login - text: | - this is my post-login banner - that has a multiline - string - state: present - register: result - -- debug: - msg: "{{ result }}" - -- assert: - that: - - "result.changed == true" - - "'this is my post-login banner' in result.commands[0]" - - "'that has a multiline' in result.commands[0]" - -- name: Set post-login again (idempotent) - vyos_banner: - banner: post-login - text: | - this is my post-login banner - that has a multiline - string - state: present - register: result - -- assert: - that: - - "result.changed == false" - - "result.commands | length == 0" - - -# FIXME add in tests for everything defined in docs -# FIXME Test state:absent + test: -# FIXME Without powers ensure "privileged mode required" diff --git a/test/integration/targets/vyos_banner/tests/cli/basic-pre-login.yaml b/test/integration/targets/vyos_banner/tests/cli/basic-pre-login.yaml deleted file mode 100644 index eb66a73b44..0000000000 --- a/test/integration/targets/vyos_banner/tests/cli/basic-pre-login.yaml +++ /dev/null @@ -1,47 +0,0 @@ ---- -- debug: - msg: "cli/basic-pre-login.yaml on connection={{ ansible_connection }}" - -- name: setup - remove pre-login - vyos_banner: - banner: pre-login - state: absent - -- name: Set pre-login - vyos_banner: - banner: pre-login - text: | - this is my pre-login banner - that has a multiline - string - state: present - register: result - -- debug: - msg: "{{ result }}" - -- assert: - that: - - "result.changed == true" - - "'this is my pre-login banner' in result.commands[0]" - - "'that has a multiline' in result.commands[0]" - -- name: Set pre-login again (idempotent) - vyos_banner: - banner: pre-login - text: | - this is my pre-login banner - that has a multiline - string - state: present - register: result - -- assert: - that: - - "result.changed == false" - - "result.commands | length == 0" - - -# FIXME add in tests for everything defined in docs -# FIXME Test state:absent + test: -# FIXME Without powers ensure "privileged mode required" diff --git a/test/integration/targets/vyos_command/aliases b/test/integration/targets/vyos_command/aliases deleted file mode 100644 index 8071e1f75b..0000000000 --- a/test/integration/targets/vyos_command/aliases +++ /dev/null @@ -1 +0,0 @@ -shippable/vyos/group1 diff --git a/test/integration/targets/vyos_command/defaults/main.yaml b/test/integration/targets/vyos_command/defaults/main.yaml deleted file mode 100644 index 9ef5ba5165..0000000000 --- a/test/integration/targets/vyos_command/defaults/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -testcase: "*" -test_items: [] diff --git a/test/integration/targets/vyos_command/tasks/cli.yaml b/test/integration/targets/vyos_command/tasks/cli.yaml deleted file mode 100644 index 890d3acf3e..0000000000 --- a/test/integration/targets/vyos_command/tasks/cli.yaml +++ /dev/null @@ -1,22 +0,0 @@ ---- -- name: collect all cli test cases - find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - register: test_cases - delegate_to: localhost - -- name: set test_items - set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - -- name: run test case (connection=network_cli) - include: "{{ test_case_to_run }} ansible_connection=network_cli" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - -- name: run test case (connection=local) - include: "{{ test_case_to_run }} ansible_connection=local" - with_first_found: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run diff --git a/test/integration/targets/vyos_command/tasks/main.yaml b/test/integration/targets/vyos_command/tasks/main.yaml deleted file mode 100644 index d4cf26fc4a..0000000000 --- a/test/integration/targets/vyos_command/tasks/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -- {include: cli.yaml, tags: ['cli']} diff --git a/test/integration/targets/vyos_command/tests/cli/bad_operator.yaml b/test/integration/targets/vyos_command/tests/cli/bad_operator.yaml deleted file mode 100644 index 4e199bcc4e..0000000000 --- a/test/integration/targets/vyos_command/tests/cli/bad_operator.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -- debug: msg="START cli/bad_operator.yaml on connection={{ ansible_connection }}" - -- name: test bad operator - vyos_command: - commands: - - show version - - show interfaces - wait_for: - - result[0] is 'VyOS' - register: result - ignore_errors: true - -- assert: - that: - - result.failed == true - - result.msg is defined - -- debug: msg="END cli/bad_operator.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/vyos_command/tests/cli/cli_command.yaml b/test/integration/targets/vyos_command/tests/cli/cli_command.yaml deleted file mode 100644 index 12e3394376..0000000000 --- a/test/integration/targets/vyos_command/tests/cli/cli_command.yaml +++ /dev/null @@ -1,41 +0,0 @@ ---- -- debug: - msg: "START cli/cli_command.yaml on connection={{ ansible_connection }}" - -- block: - - name: get output for single command - cli_command: - command: show version - register: result - - - assert: - that: - - "result.changed == false" - - "result.stdout is defined" - - - name: send invalid command - cli_command: - command: 'show foo' - register: result - ignore_errors: true - - - assert: - that: - - "result.failed == true" - - "result.msg is defined" - when: "ansible_connection == 'network_cli'" - -- block: - - name: test failure for local connection - cli_command: - command: show version - register: result - ignore_errors: true - - - assert: - that: - - 'result.failed == true' - - "'Connection type local is not valid for this module' in result.msg" - when: "ansible_connection == 'local'" - -- debug: msg="END cli/cli_command.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/vyos_command/tests/cli/contains.yaml b/test/integration/targets/vyos_command/tests/cli/contains.yaml deleted file mode 100644 index 85c6e86a18..0000000000 --- a/test/integration/targets/vyos_command/tests/cli/contains.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -- debug: msg="START cli/contains.yaml on connection={{ ansible_connection }}" - -- name: test contains operator - vyos_command: - commands: - - show version - - show interface - wait_for: - - result[0] contains VyOS - - result[1] contains eth0 - register: result - -- assert: - that: - - result.changed == false - - result.stdout is defined - - result.stdout_lines is defined - -- debug: msg="END cli/contains.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/vyos_command/tests/cli/invalid.yaml b/test/integration/targets/vyos_command/tests/cli/invalid.yaml deleted file mode 100644 index 24c1dea78c..0000000000 --- a/test/integration/targets/vyos_command/tests/cli/invalid.yaml +++ /dev/null @@ -1,22 +0,0 @@ ---- -- debug: msg="START cli/invalid.yaml on connection={{ ansible_connection }}" - -- name: run invalid command - vyos_command: - commands: show foo - register: result - ignore_errors: true - -- assert: {that: result.failed} - -- name: run commands that include invalid command - vyos_command: - commands: - - show version - - show foo - register: result - ignore_errors: true - -- assert: {that: result.failed} - -- debug: msg="END cli/invalid.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/vyos_command/tests/cli/output.yaml b/test/integration/targets/vyos_command/tests/cli/output.yaml deleted file mode 100644 index 8be8709776..0000000000 --- a/test/integration/targets/vyos_command/tests/cli/output.yaml +++ /dev/null @@ -1,44 +0,0 @@ ---- -- debug: msg="START cli/output.yaml on connection={{ ansible_connection }}" - -- name: get output for single command - vyos_command: - commands: show version - register: result - -- assert: - that: - - result.changed == false - - result.stdout is defined - - result.stdout_lines is defined - -- name: get output for multiple commands - vyos_command: - commands: - - show version - - show interfaces - register: result - -- assert: - that: - - result.changed == false - - result.stdout is defined - - result.stdout | length == 2 - -- name: Get output for multiple commands that call less explicitly - vyos_command: - commands: - # NOTE: We only test show commands that will output <ANSIBLE_VYOS_TERMINAL_LENGTH - # Otherwise you will get ": "command timeout triggered" - - show hardware cpu detail - - show hardware mem - - show license - register: result - -- assert: - that: - - result.changed == false - - result.stdout_lines is defined - - result.stdout_lines[2] | length >= 20 - -- debug: msg="END cli/output.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/vyos_command/tests/cli/timeout.yaml b/test/integration/targets/vyos_command/tests/cli/timeout.yaml deleted file mode 100644 index e1da173dc4..0000000000 --- a/test/integration/targets/vyos_command/tests/cli/timeout.yaml +++ /dev/null @@ -1,18 +0,0 @@ ---- -- debug: msg="START cli/timeout.yaml on connection={{ ansible_connection }}" - -- name: test bad condition - vyos_command: - commands: - - show version - wait_for: - - result[0] contains bad_value_string - register: result - ignore_errors: true - -- assert: - that: - - result.failed == true - - result.msg is defined - -- debug: msg="END cli/timeout.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/vyos_config/aliases b/test/integration/targets/vyos_config/aliases deleted file mode 100644 index 8071e1f75b..0000000000 --- a/test/integration/targets/vyos_config/aliases +++ /dev/null @@ -1 +0,0 @@ -shippable/vyos/group1 diff --git a/test/integration/targets/vyos_config/defaults/main.yaml b/test/integration/targets/vyos_config/defaults/main.yaml deleted file mode 100644 index 9ef5ba5165..0000000000 --- a/test/integration/targets/vyos_config/defaults/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -testcase: "*" -test_items: [] diff --git a/test/integration/targets/vyos_config/tasks/cli.yaml b/test/integration/targets/vyos_config/tasks/cli.yaml deleted file mode 100644 index 890d3acf3e..0000000000 --- a/test/integration/targets/vyos_config/tasks/cli.yaml +++ /dev/null @@ -1,22 +0,0 @@ ---- -- name: collect all cli test cases - find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - register: test_cases - delegate_to: localhost - -- name: set test_items - set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - -- name: run test case (connection=network_cli) - include: "{{ test_case_to_run }} ansible_connection=network_cli" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - -- name: run test case (connection=local) - include: "{{ test_case_to_run }} ansible_connection=local" - with_first_found: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run diff --git a/test/integration/targets/vyos_config/tasks/cli_config.yaml b/test/integration/targets/vyos_config/tasks/cli_config.yaml deleted file mode 100644 index f5d5b551fb..0000000000 --- a/test/integration/targets/vyos_config/tasks/cli_config.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -- name: collect all cli_config test cases - find: - paths: "{{ role_path }}/tests/cli_config" - patterns: "{{ testcase }}.yaml" - register: test_cases - delegate_to: localhost - -- name: set test_items - set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - -- name: run test case (connection=network_cli) - include: "{{ test_case_to_run }} ansible_connection=network_cli" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run diff --git a/test/integration/targets/vyos_config/tasks/main.yaml b/test/integration/targets/vyos_config/tasks/main.yaml deleted file mode 100644 index 13977a44b1..0000000000 --- a/test/integration/targets/vyos_config/tasks/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -- {include: cli.yaml, tags: ['cli']} -- {include: cli_config.yaml, tags: ['cli_config']} diff --git a/test/integration/targets/vyos_config/tests/cli/backup.yaml b/test/integration/targets/vyos_config/tests/cli/backup.yaml deleted file mode 100644 index cdf41b1f12..0000000000 --- a/test/integration/targets/vyos_config/tests/cli/backup.yaml +++ /dev/null @@ -1,113 +0,0 @@ ---- -- debug: msg="START vyos/backup.yaml on connection={{ ansible_connection }}" - -- name: collect any backup files - find: - paths: "{{ role_path }}/backup" - pattern: "{{ inventory_hostname_short }}_config*" - register: backup_files - connection: local - -- name: delete backup files - file: - path: "{{ item.path }}" - state: absent - with_items: "{{backup_files.files|default([])}}" - -- name: take configure backup - vyos_config: - backup: true - register: result - -- assert: - that: - - "result.changed == true" - -- name: collect any backup files - find: - paths: "{{ role_path }}/backup" - pattern: "{{ inventory_hostname_short }}_config*" - register: backup_files - connection: local - -- assert: - that: - - "backup_files.files is defined" - -- name: delete configurable backup file path - file: - path: "{{ item }}" - state: absent - with_items: - - "{{ role_path }}/backup_test_dir/" - - "{{ role_path }}/backup/backup.cfg" - -- name: take configuration backup in custom filename and directory path - vyos_config: - backup: true - backup_options: - filename: backup.cfg - dir_path: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}" - become: true - register: result - -- assert: - that: - - "result.changed == true" - -- name: check if the backup file-1 exist - find: - paths: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}/backup.cfg" - register: backup_file - connection: local - -- assert: - that: - - "backup_file.files is defined" - -- name: take configuration backup in custom filename - vyos_config: - backup: true - backup_options: - filename: backup.cfg - become: true - register: result - -- assert: - that: - - "result.changed == true" - -- name: check if the backup file-2 exist - find: - paths: "{{ role_path }}/backup/backup.cfg" - register: backup_file - connection: local - -- assert: - that: - - "backup_file.files is defined" - -- name: take configuration backup in custom path and default filename - vyos_config: - backup: true - backup_options: - dir_path: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}" - become: true - register: result - -- assert: - that: - - "result.changed == true" - -- name: check if the backup file-3 exist - find: - paths: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}" - pattern: "{{ inventory_hostname_short }}_config*" - register: backup_file - connection: local - -- assert: - that: - - "backup_file.files is defined" - -- debug: msg="END vyos/backup.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/vyos_config/tests/cli/check_config.yaml b/test/integration/targets/vyos_config/tests/cli/check_config.yaml deleted file mode 100644 index 1924049362..0000000000 --- a/test/integration/targets/vyos_config/tests/cli/check_config.yaml +++ /dev/null @@ -1,63 +0,0 @@ ---- -- debug: msg="START cli/config_check.yaml on connection={{ ansible_connection }}" - -- name: setup- ensure interface is not present - vyos_config: - lines: delete interfaces loopback lo - -- name: setup- create interface - vyos_config: - lines: - - interfaces - - interfaces loopback lo - - interfaces loopback lo description test - register: result - -# note collapsing the duplicate lines doesn't work if -# lines: -# - interfaces loopback lo description test -# - interfaces loopback lo -# - interfaces - -- name: Check that multiple duplicate lines collapse into a single commands - assert: - that: - - "{{ result.commands|length }} == 1" - -- name: Check that set is correctly prepended - assert: - that: - - "result.commands[0] == 'set interfaces loopback lo description test'" - -- name: configure config_check config command - vyos_config: - lines: delete interfaces loopback lo - register: result - -- assert: - that: - - "result.changed == true" - -- name: check config_check config command idempontent - vyos_config: - lines: delete interfaces loopback lo - register: result - -- assert: - that: - - "result.changed == false" - -- name: check multiple line config filter is working - vyos_config: - lines: - - set system login user esa level admin - - set system login user esa authentication encrypted-password '!abc!' - - set system login user vyos level admin - - set system login user vyos authentication encrypted-password 'abc' - register: result - -- assert: - that: - - "{{ result.filtered|length }} == 2" - -- debug: msg="END cli/config_check.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/vyos_config/tests/cli/comment.yaml b/test/integration/targets/vyos_config/tests/cli/comment.yaml deleted file mode 100644 index 3c71dfc64d..0000000000 --- a/test/integration/targets/vyos_config/tests/cli/comment.yaml +++ /dev/null @@ -1,34 +0,0 @@ ---- -- debug: msg="START cli/comment.yaml on connection={{ ansible_connection }}" - -- name: setup - vyos_config: - lines: set system host-name {{ inventory_hostname_short }} - match: none - -- name: configure using comment - vyos_config: - lines: set system host-name foo - comment: this is a test - register: result - -- assert: - that: - - "result.changed == true" - - "'set system host-name foo' in result.commands" - -- name: collect system commits - vyos_command: - commands: show system commit - register: result - -- assert: - that: - - "'this is a test' in result.stdout_lines[0][1]" - -- name: teardown - vyos_config: - lines: set system host-name {{ inventory_hostname_short }} - match: none - -- debug: msg="END cli/comment.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/vyos_config/tests/cli/config.cfg b/test/integration/targets/vyos_config/tests/cli/config.cfg deleted file mode 100644 index 36c98f19aa..0000000000 --- a/test/integration/targets/vyos_config/tests/cli/config.cfg +++ /dev/null @@ -1,3 +0,0 @@ - set service lldp - set protocols static - diff --git a/test/integration/targets/vyos_config/tests/cli/save.yaml b/test/integration/targets/vyos_config/tests/cli/save.yaml deleted file mode 100644 index 7b058a7be3..0000000000 --- a/test/integration/targets/vyos_config/tests/cli/save.yaml +++ /dev/null @@ -1,54 +0,0 @@ ---- -- debug: msg="START cli/save.yaml on connection={{ ansible_connection }}" - -- name: setup - vyos_config: - lines: set system host-name {{ inventory_hostname_short }} - match: none - -- name: configure hostaname and save - vyos_config: - lines: set system host-name foo - save: true - register: result - -- assert: - that: - - "result.changed == true" - - "'set system host-name foo' in result.commands" - -- name: configure hostaname and don't save - vyos_config: - lines: set system host-name bar - register: result - -- assert: - that: - - "result.changed == true" - - "'set system host-name bar' in result.commands" - -- name: save config - vyos_config: - save: true - register: result - -- assert: - that: - - "result.changed == true" - -- name: save config again - vyos_config: - save: true - register: result - -- assert: - that: - - "result.changed == false" - -- name: teardown - vyos_config: - lines: set system host-name {{ inventory_hostname_short }} - match: none - save: true - -- debug: msg="END cli/simple.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/vyos_config/tests/cli/simple.yaml b/test/integration/targets/vyos_config/tests/cli/simple.yaml deleted file mode 100644 index d9185affa8..0000000000 --- a/test/integration/targets/vyos_config/tests/cli/simple.yaml +++ /dev/null @@ -1,53 +0,0 @@ ---- -- debug: msg="START cli/simple.yaml on connection={{ ansible_connection }}" - -- name: setup - vyos_config: - lines: set system host-name {{ inventory_hostname_short }} - match: none - -- name: configure simple config command - vyos_config: - lines: set system host-name foo - register: result - -- assert: - that: - - "result.changed == true" - - "'set system host-name foo' in result.commands" - -- name: check simple config command idempontent - vyos_config: - lines: set system host-name foo - register: result - -- assert: - that: - - "result.changed == false" - -- name: Delete services - vyos_config: &del - lines: - - delete service lldp - - delete protocols static - -- name: Configuring when commands starts with whitespaces - vyos_config: - src: "{{ role_path }}/tests/cli/config.cfg" - register: result - -- assert: - that: - - "result.changed == true" - - '"set service lldp" in result.commands' - - '"set protocols static" in result.commands' - -- name: Delete services - vyos_config: *del - -- name: teardown - vyos_config: - lines: set system host-name {{ inventory_hostname_short }} - match: none - -- debug: msg="END cli/simple.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/vyos_config/tests/cli_config/cli_backup.yaml b/test/integration/targets/vyos_config/tests/cli_config/cli_backup.yaml deleted file mode 100644 index 9bce0d8d80..0000000000 --- a/test/integration/targets/vyos_config/tests/cli_config/cli_backup.yaml +++ /dev/null @@ -1,114 +0,0 @@ ---- -- debug: msg="END cli_config/backup.yaml on connection={{ ansible_connection }}" - -- name: delete configurable backup file path - file: - path: "{{ item }}" - state: absent - with_items: - - "{{ role_path }}/backup_test_dir/" - - "{{ role_path }}/backup/backup.cfg" - -- name: collect any backup files - find: - paths: "{{ role_path }}/backup" - pattern: "{{ inventory_hostname_short }}_config*" - register: backup_files - connection: local - -- name: delete backup files - file: - path: "{{ item.path }}" - state: absent - with_items: "{{backup_files.files|default([])}}" - -- name: take config backup - cli_config: - backup: true - become: true - register: result - -- assert: - that: - - "result.changed == true" - -- name: collect any backup files - find: - paths: "{{ role_path }}/backup" - pattern: "{{ inventory_hostname_short }}_config*" - register: backup_files - connection: local - -- assert: - that: - - "backup_files.files is defined" - -- name: take configuration backup in custom filename and directory path - cli_config: - backup: true - backup_options: - filename: backup.cfg - dir_path: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}" - become: true - register: result - -- assert: - that: - - "result.changed == true" - -- name: check if the backup file-1 exist - find: - paths: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}/backup.cfg" - register: backup_file - connection: local - -- assert: - that: - - "backup_file.files is defined" - -- name: take configuration backup in custom filename - cli_config: - backup: true - backup_options: - filename: backup.cfg - become: true - register: result - -- assert: - that: - - "result.changed == true" - -- name: check if the backup file-2 exist - find: - paths: "{{ role_path }}/backup/backup.cfg" - register: backup_file - connection: local - -- assert: - that: - - "backup_file.files is defined" - -- name: take configuration backup in custom path and default filename - cli_config: - backup: true - backup_options: - dir_path: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}" - become: true - register: result - -- assert: - that: - - "result.changed == true" - -- name: check if the backup file-3 exist - find: - paths: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}" - pattern: "{{ inventory_hostname_short }}_config*" - register: backup_file - connection: local - -- assert: - that: - - "backup_file.files is defined" - -- debug: msg="END cli_config/backup.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/vyos_config/tests/cli_config/cli_basic.yaml b/test/integration/targets/vyos_config/tests/cli_config/cli_basic.yaml deleted file mode 100644 index e83db1ea84..0000000000 --- a/test/integration/targets/vyos_config/tests/cli_config/cli_basic.yaml +++ /dev/null @@ -1,28 +0,0 @@ ---- -- debug: msg="START cli_config/cli_basic.yaml on connection={{ ansible_connection }}" - -- name: setup - remove interface description - cli_config: &rm - config: delete interfaces loopback lo description - -- name: configure device with config - cli_config: &conf - config: set interfaces loopback lo description 'this is a test' - register: result - -- assert: - that: - - "result.changed == true" - -- name: Idempotence - cli_config: *conf - register: result - -- assert: - that: - - "result.changed == false" - -- name: teardown - cli_config: *rm - -- debug: msg="END cli_config/cli_basic.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/vyos_config/tests/cli_config/cli_comment.yaml b/test/integration/targets/vyos_config/tests/cli_config/cli_comment.yaml deleted file mode 100644 index 163f05ee41..0000000000 --- a/test/integration/targets/vyos_config/tests/cli_config/cli_comment.yaml +++ /dev/null @@ -1,30 +0,0 @@ ---- -- debug: msg="START cli_config/cli_comment.yaml on connection={{ ansible_connection }}" - -- name: setup - cli_config: &rm - config: set system host-name {{ inventory_hostname_short }} - -- name: configure using comment - cli_config: - config: set system host-name foo - commit_comment: this is a test - register: result - -- assert: - that: - - "result.changed == true" - -- name: collect system commits - vyos_command: - commands: show system commit - register: result - -- assert: - that: - - "'this is a test' in result.stdout_lines[0][1]" - -- name: teardown - cli_config: *rm - -- debug: msg="END cli_config/cli_comment.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/vyos_facts/aliases b/test/integration/targets/vyos_facts/aliases deleted file mode 100644 index 8071e1f75b..0000000000 --- a/test/integration/targets/vyos_facts/aliases +++ /dev/null @@ -1 +0,0 @@ -shippable/vyos/group1 diff --git a/test/integration/targets/vyos_facts/defaults/main.yaml b/test/integration/targets/vyos_facts/defaults/main.yaml deleted file mode 100644 index 9ef5ba5165..0000000000 --- a/test/integration/targets/vyos_facts/defaults/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -testcase: "*" -test_items: [] diff --git a/test/integration/targets/vyos_facts/tasks/cli.yaml b/test/integration/targets/vyos_facts/tasks/cli.yaml deleted file mode 100644 index 890d3acf3e..0000000000 --- a/test/integration/targets/vyos_facts/tasks/cli.yaml +++ /dev/null @@ -1,22 +0,0 @@ ---- -- name: collect all cli test cases - find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - register: test_cases - delegate_to: localhost - -- name: set test_items - set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - -- name: run test case (connection=network_cli) - include: "{{ test_case_to_run }} ansible_connection=network_cli" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - -- name: run test case (connection=local) - include: "{{ test_case_to_run }} ansible_connection=local" - with_first_found: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run diff --git a/test/integration/targets/vyos_facts/tasks/main.yaml b/test/integration/targets/vyos_facts/tasks/main.yaml deleted file mode 100644 index d4cf26fc4a..0000000000 --- a/test/integration/targets/vyos_facts/tasks/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -- {include: cli.yaml, tags: ['cli']} diff --git a/test/integration/targets/vyos_facts/tests/cli/basic_facts.yaml b/test/integration/targets/vyos_facts/tests/cli/basic_facts.yaml deleted file mode 100644 index 322ec033d1..0000000000 --- a/test/integration/targets/vyos_facts/tests/cli/basic_facts.yaml +++ /dev/null @@ -1,46 +0,0 @@ ---- -- name: get host name - vyos_command: - commands: - - show host name - register: vyos_host - -- name: get version info - vyos_command: - commands: - - show version - register: vyos_version - -- name: collect all facts from the device - vyos_facts: - gather_subset: all - register: result - -- name: "check that hostname is present" - assert: - that: - # hostname - - result.ansible_facts.ansible_net_hostname == vyos_host.stdout[0] - -- name: "check that subsets are present" - assert: - that: - # subsets - - "'neighbors' in result.ansible_facts.ansible_net_gather_subset" - - "'default' in result.ansible_facts.ansible_net_gather_subset" - - "'config' in result.ansible_facts.ansible_net_gather_subset" - -- name: "check that version info is present" - assert: - that: - # version info - - result.ansible_facts.ansible_net_version in vyos_version.stdout_lines[0][0] - - result.ansible_facts.ansible_net_model in vyos_version.stdout_lines[0][9] - - result.ansible_facts.ansible_net_serialnum in vyos_version.stdout_lines[0][10] - -- name: "check that config info is present" - assert: - that: - # config info - - result.ansible_facts.ansible_net_commits is defined - - result.ansible_facts.ansible_net_config is defined diff --git a/test/integration/targets/vyos_firewall_global/defaults/main.yaml b/test/integration/targets/vyos_firewall_global/defaults/main.yaml deleted file mode 100644 index 164afead28..0000000000 --- a/test/integration/targets/vyos_firewall_global/defaults/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -testcase: "[^_].*" -test_items: [] diff --git a/test/integration/targets/vyos_firewall_global/meta/main.yaml b/test/integration/targets/vyos_firewall_global/meta/main.yaml deleted file mode 100644 index f88bce5567..0000000000 --- a/test/integration/targets/vyos_firewall_global/meta/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ -dependencies: - - prepare_vyos_tests diff --git a/test/integration/targets/vyos_firewall_global/tasks/cli.yaml b/test/integration/targets/vyos_firewall_global/tasks/cli.yaml deleted file mode 100644 index 655e51ee63..0000000000 --- a/test/integration/targets/vyos_firewall_global/tasks/cli.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -- name: Collect all cli test cases - find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - use_regex: true - register: test_cases - delegate_to: localhost - -- name: Set test_items - set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test case (connection=network_cli) - include: "{{ test_case_to_run }}" - vars: - ansible_connection: network_cli - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run diff --git a/test/integration/targets/vyos_firewall_global/tasks/main.yaml b/test/integration/targets/vyos_firewall_global/tasks/main.yaml deleted file mode 100644 index d4cf26fc4a..0000000000 --- a/test/integration/targets/vyos_firewall_global/tasks/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -- {include: cli.yaml, tags: ['cli']} diff --git a/test/integration/targets/vyos_firewall_global/tests/cli/_parsed_config.cfg b/test/integration/targets/vyos_firewall_global/tests/cli/_parsed_config.cfg deleted file mode 100644 index 45446bdb08..0000000000 --- a/test/integration/targets/vyos_firewall_global/tests/cli/_parsed_config.cfg +++ /dev/null @@ -1,19 +0,0 @@ -set firewall all-ping 'enable' -set firewall broadcast-ping 'enable' -set firewall config-trap 'enable' -set firewall group address-group MGMT-HOSTS address '192.0.1.1' -set firewall group address-group MGMT-HOSTS address '192.0.1.3' -set firewall group address-group MGMT-HOSTS address '192.0.1.5' -set firewall group address-group MGMT-HOSTS description 'This group has the Management hosts address list' -set firewall group network-group MGMT description 'This group has the Management network addresses' -set firewall group network-group MGMT network '192.0.1.0/24' -set firewall ip-src-route 'enable' -set firewall log-martians 'enable' -set firewall receive-redirects 'disable' -set firewall send-redirects 'enable' -set firewall source-validation 'strict' -set firewall state-policy established action 'accept' -set firewall state-policy established log 'enable' -set firewall state-policy invalid action 'reject' -set firewall syn-cookies 'enable' -set firewall twa-hazards-protection 'enable' diff --git a/test/integration/targets/vyos_firewall_global/tests/cli/_populate.yaml b/test/integration/targets/vyos_firewall_global/tests/cli/_populate.yaml deleted file mode 100644 index 5417bad9ac..0000000000 --- a/test/integration/targets/vyos_firewall_global/tests/cli/_populate.yaml +++ /dev/null @@ -1,25 +0,0 @@ ---- -- name: Setup - cli_config: - config: "{{ lines }}" - vars: - lines: | - set firewall all-ping 'enable' - set firewall broadcast-ping 'enable' - set firewall config-trap 'enable' - set firewall group address-group MGMT-HOSTS address '192.0.1.1' - set firewall group address-group MGMT-HOSTS address '192.0.1.3' - set firewall group address-group MGMT-HOSTS address '192.0.1.5' - set firewall group address-group MGMT-HOSTS description 'This group has the Management hosts address list' - set firewall group network-group MGMT description 'This group has the Management network addresses' - set firewall group network-group MGMT network '192.0.1.0/24' - set firewall ip-src-route 'enable' - set firewall log-martians 'enable' - set firewall receive-redirects 'disable' - set firewall send-redirects 'enable' - set firewall source-validation 'strict' - set firewall state-policy established action 'accept' - set firewall state-policy established log 'enable' - set firewall state-policy invalid action 'reject' - set firewall syn-cookies 'enable' - set firewall twa-hazards-protection 'enable' diff --git a/test/integration/targets/vyos_firewall_global/tests/cli/_remove_config.yaml b/test/integration/targets/vyos_firewall_global/tests/cli/_remove_config.yaml deleted file mode 100644 index e56093b389..0000000000 --- a/test/integration/targets/vyos_firewall_global/tests/cli/_remove_config.yaml +++ /dev/null @@ -1,7 +0,0 @@ ---- -- name: Remove Config - cli_config: - config: "{{ lines }}" - vars: - lines: | - delete firewall diff --git a/test/integration/targets/vyos_firewall_global/tests/cli/deleted.yaml b/test/integration/targets/vyos_firewall_global/tests/cli/deleted.yaml deleted file mode 100644 index 8cce6c94d9..0000000000 --- a/test/integration/targets/vyos_firewall_global/tests/cli/deleted.yaml +++ /dev/null @@ -1,44 +0,0 @@ ---- -- debug: - msg: "Start vyos_firewall_global deleted integration tests ansible_connection={{ ansible_connection }}" - -- include_tasks: _populate.yaml - -- block: - - name: Delete attributes of firewall. - vyos_firewall_global: &deleted - config: - state: deleted - register: result - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ populate == result['before'] }}" - - - name: Assert that the correct set of commands were generated - assert: - that: - - "{{ deleted['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that the after dicts were correctly generated - assert: - that: - - "{{ deleted['after'] == result['after'] }}" - - - name: Delete attributes of given interfaces (IDEMPOTENT) - vyos_firewall_global: *deleted - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result.changed == false" - - "result.commands|length == 0" - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ deleted['after'] == result['before'] }}" - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_firewall_global/tests/cli/empty_config.yaml b/test/integration/targets/vyos_firewall_global/tests/cli/empty_config.yaml deleted file mode 100644 index 0edd88083e..0000000000 --- a/test/integration/targets/vyos_firewall_global/tests/cli/empty_config.yaml +++ /dev/null @@ -1,47 +0,0 @@ ---- -- debug: - msg: "START vyos_firewall_global empty_config integration tests on connection={{ ansible_connection }}" - -- name: Merged with empty config should give appropriate error message - vyos_firewall_global: - config: - state: merged - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state merged' - -- name: Replaced with empty config should give appropriate error message - vyos_firewall_global: - config: - state: replaced - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state replaced' - -- name: Parsed with empty running_config should give appropriate error message - vyos_firewall_global: - running_config: - state: parsed - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of running_config parameter must not be empty for state parsed' - -- name: Rendered with empty config should give appropriate error message - vyos_firewall_global: - config: - state: rendered - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/test/integration/targets/vyos_firewall_global/tests/cli/gathered.yaml b/test/integration/targets/vyos_firewall_global/tests/cli/gathered.yaml deleted file mode 100644 index 0aca48bbed..0000000000 --- a/test/integration/targets/vyos_firewall_global/tests/cli/gathered.yaml +++ /dev/null @@ -1,31 +0,0 @@ ---- -- debug: - msg: "START vyos_firewall_global gathered integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Merge the provided configuration with the exisiting running configuration - vyos_firewall_global: &gathered - config: - state: gathered - register: result - - - name: Assert that gathered dicts was correctly generated - assert: - that: - - "{{ populate == result['gathered'] }}" - - - name: Gather the existing running configuration (IDEMPOTENT) - vyos_firewall_global: *gathered - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_firewall_global/tests/cli/merged.yaml b/test/integration/targets/vyos_firewall_global/tests/cli/merged.yaml deleted file mode 100644 index 3bd433aae0..0000000000 --- a/test/integration/targets/vyos_firewall_global/tests/cli/merged.yaml +++ /dev/null @@ -1,76 +0,0 @@ ---- -- debug: - msg: "START vyos_firewall_global merged integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- block: - - name: Merge the provided configuration with the exisiting running configuration - vyos_firewall_global: &merged - config: - validation: strict - config_trap: True - log_martians: True - syn_cookies: True - twa_hazards_protection: True - ping: - all: True - broadcast: True - state_policy: - - connection_type: 'established' - action: 'accept' - log: True - - connection_type: 'invalid' - action: 'reject' - route_redirects: - - afi: 'ipv4' - ip_src_route: True - icmp_redirects: - send: True - receive: False - group: - address_group: - - name: 'MGMT-HOSTS' - description: 'This group has the Management hosts address list' - members: - - address: 192.0.1.1 - - address: 192.0.1.3 - - address: 192.0.1.5 - network_group: - - name: 'MGMT' - description: 'This group has the Management network addresses' - members: - - address: 192.0.1.0/24 - state: merged - register: result - - - name: Assert that before dicts were correctly generated - assert: - that: "{{ merged['before'] == result['before'] }}" - - - name: Assert that correct set of commands were generated - assert: - that: - - "{{ merged['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that after dicts was correctly generated - assert: - that: - - "{{ merged['after'] == result['after'] }}" - - - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) - vyos_firewall_global: *merged - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - - - name: Assert that before dicts were correctly generated - assert: - that: - - "{{ merged['after'] == result['before'] }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_firewall_global/tests/cli/parsed.yaml b/test/integration/targets/vyos_firewall_global/tests/cli/parsed.yaml deleted file mode 100644 index 24e77fa7ca..0000000000 --- a/test/integration/targets/vyos_firewall_global/tests/cli/parsed.yaml +++ /dev/null @@ -1,39 +0,0 @@ ---- -- debug: - msg: "START vyos_firewall_global parsed integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Gather firewall_global facts - vyos_facts: - gather_subset: - - default - gather_network_resources: - - firewall_global - register: firewall_global_facts - - - name: Provide the running configuration for parsing (config to be parsed) - vyos_firewall_global: &parsed - running_config: - "{{ lookup('file', '_parsed_config.cfg') }}" - state: parsed - register: result - - - name: Assert that correct parsing done - assert: - that: "{{ ansible_facts['network_resources']['firewall_global'] == result['parsed'] }}" - - - name: Gather the existing running configuration (IDEMPOTENT) - vyos_firewall_global: *parsed - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_firewall_global/tests/cli/rendered.yaml b/test/integration/targets/vyos_firewall_global/tests/cli/rendered.yaml deleted file mode 100644 index 7a92bb314c..0000000000 --- a/test/integration/targets/vyos_firewall_global/tests/cli/rendered.yaml +++ /dev/null @@ -1,69 +0,0 @@ ---- -- debug: - msg: "START vyos_firewall_global rendered integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Structure provided configuration into device specific commands - vyos_firewall_global: &rendered - config: - validation: strict - config_trap: True - log_martians: True - syn_cookies: True - twa_hazards_protection: True - ping: - all: True - broadcast: True - state_policy: - - connection_type: 'established' - action: 'accept' - log: True - - connection_type: 'invalid' - action: 'reject' - route_redirects: - - afi: 'ipv4' - ip_src_route: True - icmp_redirects: - send: True - receive: False - group: - address_group: - - name: 'SALES-HOSTS' - description: 'Sales office hosts address list' - members: - - address: 192.0.2.1 - - address: 192.0.2.2 - - address: 192.0.2.3 - - name: 'ENG-HOSTS' - description: 'Sales office hosts address list' - members: - - address: 192.0.3.1 - - address: 192.0.3.2 - network_group: - - name: 'MGMT' - description: 'This group has the Management network addresses' - members: - - address: 192.0.1.0/24 - state: rendered - register: result - - - name: Assert that correct set of commands were generated - assert: - that: - - "{{ rendered['commands'] | symmetric_difference(result['rendered']) |length == 0 }}" - - - name: Structure provided configuration into device specific commands (IDEMPOTENT) - vyos_firewall_global: *rendered - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_firewall_global/tests/cli/replaced.yaml b/test/integration/targets/vyos_firewall_global/tests/cli/replaced.yaml deleted file mode 100644 index 57a4f71b3a..0000000000 --- a/test/integration/targets/vyos_firewall_global/tests/cli/replaced.yaml +++ /dev/null @@ -1,84 +0,0 @@ ---- -- debug: - msg: "START vyos_firewall_global replaced integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Replace device configurations of listed firewall with provided configurations - vyos_firewall_global: &replaced - config: - validation: strict - config_trap: True - log_martians: True - syn_cookies: True - twa_hazards_protection: True - ping: - all: True - broadcast: True - state_policy: - - connection_type: 'established' - action: 'accept' - log: True - - connection_type: 'invalid' - action: 'reject' - route_redirects: - - afi: 'ipv4' - ip_src_route: True - icmp_redirects: - send: True - receive: False - group: - address_group: - - name: 'SALES-HOSTS' - description: 'Sales office hosts address list' - members: - - address: 192.0.2.1 - - address: 192.0.2.2 - - address: 192.0.2.3 - - name: 'ENG-HOSTS' - description: 'Sales office hosts address list' - members: - - address: 192.0.3.1 - - address: 192.0.3.2 - network_group: - - name: 'MGMT' - description: 'This group has the Management network addresses' - members: - - address: 192.0.1.0/24 - state: replaced - register: result - - - name: Assert that correct set of commands were generated - assert: - that: - - "{{ replaced['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that before dicts are correctly generated - assert: - that: - - "{{ populate == result['before'] }}" - - - name: Assert that after dict is correctly generated - assert: - that: - - "{{ replaced['after'] == result['after'] }}" - - - name: Replace device configurations of listed firewall with provided configurarions (IDEMPOTENT) - vyos_firewall_global: *replaced - register: result - - - name: Assert that task was idempotent - assert: - that: - - "result['changed'] == false" - - - name: Assert that before dict is correctly generated - assert: - that: - - "{{ replaced['after'] == result['before'] }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_firewall_global/tests/cli/rtt.yaml b/test/integration/targets/vyos_firewall_global/tests/cli/rtt.yaml deleted file mode 100644 index e092afd784..0000000000 --- a/test/integration/targets/vyos_firewall_global/tests/cli/rtt.yaml +++ /dev/null @@ -1,83 +0,0 @@ ---- -- debug: - msg: "START vyos_firewall_global round trip integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- block: - - name: Apply the provided configuration (base config) - vyos_firewall_global: - config: - validation: strict - config_trap: True - log_martians: True - syn_cookies: True - twa_hazards_protection: True - ping: - all: True - broadcast: True - state_policy: - - connection_type: 'established' - action: 'accept' - log: True - - connection_type: 'invalid' - action: 'reject' - route_redirects: - - afi: 'ipv4' - ip_src_route: True - icmp_redirects: - send: True - receive: False - group: - address_group: - - name: 'MGMT-HOSTS' - description: 'This group has the Management hosts address list' - members: - - address: 192.0.1.1 - - address: 192.0.1.3 - - address: 192.0.1.5 - network_group: - - name: 'MGMT' - description: 'This group has the Management network addresses' - members: - - address: 192.0.1.0/24 - state: merged - register: base_config - - - name: Gather firewall_global facts - vyos_facts: - gather_subset: - - default - gather_network_resources: - - firewall_global - - - name: Apply the provided configuration (config to be reverted) - vyos_firewall_global: - config: - validation: strict - config_trap: False - log_martians: False - syn_cookies: False - twa_hazards_protection: False - ping: - all: False - broadcast: False - state: merged - register: result - - - name: Assert that changes were applied - assert: - that: "{{ round_trip['after'] == result['after'] }}" - - - name: Revert back to base config using facts round trip - vyos_firewall_global: - config: "{{ ansible_facts['network_resources']['firewall_global'] }}" - state: replaced - register: revert - - - name: Assert that config was reverted - assert: - that: "{{ base_config['after'] == revert['after']}}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_firewall_global/vars/main.yaml b/test/integration/targets/vyos_firewall_global/vars/main.yaml deleted file mode 100644 index 409104ebcb..0000000000 --- a/test/integration/targets/vyos_firewall_global/vars/main.yaml +++ /dev/null @@ -1,218 +0,0 @@ ---- -merged: - before: [] - - - commands: - - "set firewall group address-group MGMT-HOSTS address 192.0.1.1" - - "set firewall group address-group MGMT-HOSTS address 192.0.1.3" - - "set firewall group address-group MGMT-HOSTS address 192.0.1.5" - - "set firewall group address-group MGMT-HOSTS description 'This group has the Management hosts address list'" - - "set firewall group address-group MGMT-HOSTS" - - "set firewall group network-group MGMT network 192.0.1.0/24" - - "set firewall group network-group MGMT description 'This group has the Management network addresses'" - - "set firewall group network-group MGMT" - - "set firewall ip-src-route 'enable'" - - "set firewall receive-redirects 'disable'" - - "set firewall send-redirects 'enable'" - - "set firewall config-trap 'enable'" - - "set firewall state-policy established action 'accept'" - - "set firewall state-policy established log 'enable'" - - "set firewall state-policy invalid action 'reject'" - - "set firewall broadcast-ping 'enable'" - - "set firewall all-ping 'enable'" - - "set firewall log-martians 'enable'" - - "set firewall twa-hazards-protection 'enable'" - - "set firewall syn-cookies 'enable'" - - "set firewall source-validation 'strict'" - - after: - config_trap: true - group: - address_group: - - members: - - address: 192.0.1.1 - - address: 192.0.1.3 - - address: 192.0.1.5 - description: This group has the Management hosts address list - name: MGMT-HOSTS - network_group: - - members: - - address: 192.0.1.0/24 - description: This group has the Management network addresses - name: MGMT - log_martians: true - ping: - all: true - broadcast: true - route_redirects: - - afi: ipv4 - icmp_redirects: - receive: false - send: true - ip_src_route: true - syn_cookies: true - state_policy: - - action: accept - connection_type: established - log: true - - action: reject - connection_type: invalid - twa_hazards_protection: true - validation: strict - -populate: - validation: strict - config_trap: True - log_martians: True - syn_cookies: True - twa_hazards_protection: True - ping: - all: True - broadcast: True - state_policy: - - connection_type: 'established' - action: 'accept' - log: True - - connection_type: 'invalid' - action: 'reject' - route_redirects: - - afi: 'ipv4' - ip_src_route: True - icmp_redirects: - send: True - receive: False - group: - address_group: - - name: 'MGMT-HOSTS' - description: 'This group has the Management hosts address list' - members: - - address: 192.0.1.1 - - address: 192.0.1.3 - - address: 192.0.1.5 - network_group: - - name: 'MGMT' - description: 'This group has the Management network addresses' - members: - - address: 192.0.1.0/24 - -replaced: - commands: - - "delete firewall group address-group MGMT-HOSTS" - - "set firewall group address-group SALES-HOSTS address 192.0.2.1" - - "set firewall group address-group SALES-HOSTS address 192.0.2.2" - - "set firewall group address-group SALES-HOSTS address 192.0.2.3" - - "set firewall group address-group SALES-HOSTS description 'Sales office hosts address list'" - - "set firewall group address-group SALES-HOSTS" - - "set firewall group address-group ENG-HOSTS address 192.0.3.1" - - "set firewall group address-group ENG-HOSTS address 192.0.3.2" - - "set firewall group address-group ENG-HOSTS description 'Sales office hosts address list'" - - "set firewall group address-group ENG-HOSTS" - - after: - config_trap: true - group: - address_group: - - members: - - address: 192.0.3.1 - - address: 192.0.3.2 - description: 'Sales office hosts address list' - name: 'ENG-HOSTS' - - members: - - address: 192.0.2.1 - - address: 192.0.2.2 - - address: 192.0.2.3 - description: 'Sales office hosts address list' - name: 'SALES-HOSTS' - network_group: - - members: - - address: 192.0.1.0/24 - description: 'This group has the Management network addresses' - name: 'MGMT' - log_martians: true - ping: - all: true - broadcast: true - route_redirects: - - afi: 'ipv4' - icmp_redirects: - receive: false - send: true - ip_src_route: true - state_policy: - - action: 'accept' - connection_type: 'established' - log: true - - action: 'reject' - connection_type: 'invalid' - syn_cookies: true - twa_hazards_protection: true - validation: strict -rendered: - commands: - - set firewall group address-group SALES-HOSTS address 192.0.2.1 - - set firewall group address-group SALES-HOSTS address 192.0.2.2 - - set firewall group address-group SALES-HOSTS address 192.0.2.3 - - set firewall group address-group SALES-HOSTS description 'Sales office hosts address list' - - set firewall group address-group SALES-HOSTS - - set firewall group address-group ENG-HOSTS address 192.0.3.1 - - set firewall group address-group ENG-HOSTS address 192.0.3.2 - - set firewall group address-group ENG-HOSTS description 'Sales office hosts address list' - - set firewall group address-group ENG-HOSTS - - set firewall group network-group MGMT network 192.0.1.0/24 - - set firewall group network-group MGMT description 'This group has the Management network addresses' - - set firewall group network-group MGMT - - set firewall ip-src-route 'enable' - - set firewall receive-redirects 'disable' - - set firewall send-redirects 'enable' - - set firewall config-trap 'enable' - - set firewall state-policy established action 'accept' - - set firewall state-policy established log 'enable' - - set firewall state-policy invalid action 'reject' - - set firewall broadcast-ping 'enable' - - set firewall all-ping 'enable' - - set firewall log-martians 'enable' - - set firewall twa-hazards-protection 'enable' - - set firewall syn-cookies 'enable' - - set firewall source-validation 'strict' -deleted: - commands: - - "delete firewall " - - after: [] - -round_trip: - after: - validation: strict - config_trap: False - log_martians: False - syn_cookies: False - twa_hazards_protection: False - ping: - all: False - broadcast: False - state_policy: - - connection_type: 'established' - action: 'accept' - log: True - - connection_type: 'invalid' - action: 'reject' - route_redirects: - - afi: 'ipv4' - ip_src_route: True - icmp_redirects: - send: True - receive: False - group: - address_group: - - name: 'MGMT-HOSTS' - description: 'This group has the Management hosts address list' - members: - - address: 192.0.1.1 - - address: 192.0.1.3 - - address: 192.0.1.5 - network_group: - - name: 'MGMT' - description: 'This group has the Management network addresses' - members: - - address: 192.0.1.0/24 diff --git a/test/integration/targets/vyos_firewall_interfaces/1 b/test/integration/targets/vyos_firewall_interfaces/1 deleted file mode 100644 index 70ae90f3e6..0000000000 --- a/test/integration/targets/vyos_firewall_interfaces/1 +++ /dev/null @@ -1,120 +0,0 @@ ---- -merged: - before: [] - - - commands: - - "set interfaces ethernet eth1 firewall in name 'INBOUND'" - - "set interfaces ethernet eth1 firewall out name 'OUTBOUND'" - - "set interfaces ethernet eth1 firewall local name 'LOCAL'" - - "set interfaces ethernet eth1 firewall local ipv6-name 'V6-LOCAL'" - - "set interfaces ethernet eth3 firewall in name 'INBOUND'" - - "set interfaces ethernet eth3 firewall out name 'OUTBOUND'" - - "set interfaces ethernet eth3 firewall local name 'LOCAL'" - - "set interfaces ethernet eth3 firewall local ipv6-name 'V6-LOCAL'" - - after: - - name: 'eth1' - access_rules: - - afi: 'ipv4' - rules: - - name: 'INBOUND' - direction: 'in' - - name: 'OUBOUND' - direction: 'out' - - afi: 'ipv6' - rules: - - name: 'V6-LOCAL' - direction: 'local' - -populate: - - name: 'eth1' - access_rules: - - afi: 'ipv4' - rules: - - name: 'INBOUND' - direction: 'in' - - name: 'OUBOUND' - direction: 'out' - - afi: 'ipv6' - rules: - - name: 'LOCAL' - direction: 'local' - -replaced: - commands: - - "delete service lldp interface eth2 location" - - "set service lldp interface eth2 'disable'" - - "set service lldp interface eth2 location civic-based country-code 'US'" - - "set service lldp interface eth2 location civic-based ca-type 0 ca-value 'ENGLISH'" - - "delete service lldp interface eth1 location" - - "set service lldp interface eth1 'disable'" - - "set service lldp interface eth1 location coordinate-based latitude '33.524449N'" - - "set service lldp interface eth1 location coordinate-based altitude '2200'" - - "set service lldp interface eth1 location coordinate-based datum 'WGS84'" - - "set service lldp interface eth1 location coordinate-based longitude '222.267255W'" - - after: - - name: 'eth2' - enable: false - location: - civic_based: - country_code: 'US' - ca_info: - - ca_type: 0 - ca_value: 'ENGLISH' - - - name: 'eth1' - enable: false - location: - coordinate_based: - altitude: 2200 - datum: 'WGS84' - longitude: '222.267255W' - latitude: '33.524449N' - -populate_intf: - - name: 'eth2' - enable: false - location: - civic_based: - country_code: 'US' - ca_info: - - ca_type: 0 - ca_value: 'ENGLISH' - -overridden: - commands: - - "delete service lldp interface eth2 location" - - "delete service lldp interface eth2 'disable'" - - "set service lldp interface eth2 location elin '0000000911'" - - after: - - name: 'eth2' - location: - elin: 0000000911 - -deleted: - commands: - - "delete service lldp interface eth1" - - "delete service lldp interface eth2" - - after: [] - -round_trip: - after: - - name: 'eth1' - location: - civic_based: - country_code: 'US' - ca_info: - - ca_type: 0 - ca_value: 'ENGLISH' - - - name: 'eth2' - location: - coordinate_based: - altitude: 2200 - datum: 'WGS84' - longitude: '222.267255W' - latitude: '33.524449N' diff --git a/test/integration/targets/vyos_firewall_interfaces/defaults/main.yaml b/test/integration/targets/vyos_firewall_interfaces/defaults/main.yaml deleted file mode 100644 index 164afead28..0000000000 --- a/test/integration/targets/vyos_firewall_interfaces/defaults/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -testcase: "[^_].*" -test_items: [] diff --git a/test/integration/targets/vyos_firewall_interfaces/meta/main.yaml b/test/integration/targets/vyos_firewall_interfaces/meta/main.yaml deleted file mode 100644 index 7413320e48..0000000000 --- a/test/integration/targets/vyos_firewall_interfaces/meta/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dependencies: - - prepare_vyos_tests diff --git a/test/integration/targets/vyos_firewall_interfaces/tasks/cli.yaml b/test/integration/targets/vyos_firewall_interfaces/tasks/cli.yaml deleted file mode 100644 index 655e51ee63..0000000000 --- a/test/integration/targets/vyos_firewall_interfaces/tasks/cli.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -- name: Collect all cli test cases - find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - use_regex: true - register: test_cases - delegate_to: localhost - -- name: Set test_items - set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test case (connection=network_cli) - include: "{{ test_case_to_run }}" - vars: - ansible_connection: network_cli - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run diff --git a/test/integration/targets/vyos_firewall_interfaces/tasks/main.yaml b/test/integration/targets/vyos_firewall_interfaces/tasks/main.yaml deleted file mode 100644 index d4cf26fc4a..0000000000 --- a/test/integration/targets/vyos_firewall_interfaces/tasks/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -- {include: cli.yaml, tags: ['cli']} diff --git a/test/integration/targets/vyos_firewall_interfaces/tests/cli/_parsed_config.cfg b/test/integration/targets/vyos_firewall_interfaces/tests/cli/_parsed_config.cfg deleted file mode 100644 index 54696e8d4e..0000000000 --- a/test/integration/targets/vyos_firewall_interfaces/tests/cli/_parsed_config.cfg +++ /dev/null @@ -1,10 +0,0 @@ -set interfaces ethernet eth1 firewall in name 'INBOUND' -set interfaces ethernet eth1 firewall out name 'OUTBOUND' -set interfaces ethernet eth1 firewall local name 'LOCAL' -set interfaces ethernet eth1 firewall local ipv6-name 'V6-LOCAL' -set interfaces ethernet eth2 firewall in name 'INBOUND' -set interfaces ethernet eth2 firewall out name 'OUTBOUND' -set interfaces ethernet eth2 firewall local name 'LOCAL' -set interfaces ethernet eth2 firewall local ipv6-name 'V6-LOCAL' -set interfaces ethernet eth0 - diff --git a/test/integration/targets/vyos_firewall_interfaces/tests/cli/_populate.yaml b/test/integration/targets/vyos_firewall_interfaces/tests/cli/_populate.yaml deleted file mode 100644 index 99abf94d5d..0000000000 --- a/test/integration/targets/vyos_firewall_interfaces/tests/cli/_populate.yaml +++ /dev/null @@ -1,15 +0,0 @@ ---- -- name: Setup - cli_config: - config: "{{ lines }}" - vars: - lines: | - set interfaces ethernet eth1 firewall in name 'INBOUND' - set interfaces ethernet eth1 firewall out name 'OUTBOUND' - set interfaces ethernet eth1 firewall local name 'LOCAL' - set interfaces ethernet eth1 firewall local ipv6-name 'V6-LOCAL' - set interfaces ethernet eth2 firewall in name 'INBOUND' - set interfaces ethernet eth2 firewall out name 'OUTBOUND' - set interfaces ethernet eth2 firewall local name 'LOCAL' - set interfaces ethernet eth2 firewall local ipv6-name 'V6-LOCAL' - diff --git a/test/integration/targets/vyos_firewall_interfaces/tests/cli/_populate_rule_sets.yaml b/test/integration/targets/vyos_firewall_interfaces/tests/cli/_populate_rule_sets.yaml deleted file mode 100644 index e5d15fe008..0000000000 --- a/test/integration/targets/vyos_firewall_interfaces/tests/cli/_populate_rule_sets.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- name: Setup - cli_config: - config: "{{ lines }}" - vars: - lines: | - set firewall name 'INBOUND' - set firewall name 'OUTBOUND' - set firewall name 'LOCAL' - set firewall ipv6-name 'V6-LOCAL' diff --git a/test/integration/targets/vyos_firewall_interfaces/tests/cli/_remove_config.yaml b/test/integration/targets/vyos_firewall_interfaces/tests/cli/_remove_config.yaml deleted file mode 100644 index 843ce31234..0000000000 --- a/test/integration/targets/vyos_firewall_interfaces/tests/cli/_remove_config.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -- name: Remove Config - cli_config: - config: "{{ lines }}" - vars: - lines: | - delete interfaces ethernet eth1 firewall - delete interfaces ethernet eth2 firewall diff --git a/test/integration/targets/vyos_firewall_interfaces/tests/cli/_remove_firewall_config.yaml b/test/integration/targets/vyos_firewall_interfaces/tests/cli/_remove_firewall_config.yaml deleted file mode 100644 index 7755d9fe7f..0000000000 --- a/test/integration/targets/vyos_firewall_interfaces/tests/cli/_remove_firewall_config.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- name: Remove Config - cli_config: - config: "{{ lines }}" - vars: - lines: | - delete firewall name INBOUND - delete firewall name OUTBOUND - delete firewall name LOCAL - delete firewall ipv6-name V6-LOCAL diff --git a/test/integration/targets/vyos_firewall_interfaces/tests/cli/deleted.yaml b/test/integration/targets/vyos_firewall_interfaces/tests/cli/deleted.yaml deleted file mode 100644 index c9c464ab3c..0000000000 --- a/test/integration/targets/vyos_firewall_interfaces/tests/cli/deleted.yaml +++ /dev/null @@ -1,50 +0,0 @@ ---- -- debug: - msg: "Start vyos_firewall_interfaces deleted integration tests ansible_connection={{ ansible_connection }}" - -- include_tasks: _populate_rule_sets.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Delete attributes of given firewall rules. - vyos_firewall_interfaces: &deleted - config: - - name: 'eth1' - - name: 'eth2' - state: deleted - register: result - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that the correct set of commands were generated - assert: - that: - - "{{ deleted['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that the after dicts were correctly generated - assert: - that: - - "{{ deleted['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Delete attributes of given interfaces (IDEMPOTENT) - vyos_firewall_interfaces: *deleted - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result.changed == false" - - "result.commands|length == 0" - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ deleted['after'] | symmetric_difference(result['before']) |length == 0 }}" - always: - - include_tasks: _remove_config.yaml - - - include_tasks: _remove_firewall_config.yaml diff --git a/test/integration/targets/vyos_firewall_interfaces/tests/cli/deleted_afi.yaml b/test/integration/targets/vyos_firewall_interfaces/tests/cli/deleted_afi.yaml deleted file mode 100644 index 175a59f83b..0000000000 --- a/test/integration/targets/vyos_firewall_interfaces/tests/cli/deleted_afi.yaml +++ /dev/null @@ -1,56 +0,0 @@ ---- -- debug: - msg: "Start vyos_firewall_interfaces deleted integration tests ansible_connection={{ ansible_connection }}" - -- include_tasks: _populate_rule_sets.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Delete firewall interfaces based on IP address type provided. - vyos_firewall_interfaces: &deleted_afi - config: - - name: 'eth1' - access_rules: - - afi: 'ipv4' - - afi: 'ipv6' - - name: 'eth2' - access_rules: - - afi: 'ipv4' - - afi: 'ipv6' - state: deleted - register: result - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that the correct set of commands were generated - assert: - that: - - "{{ deleted_afi['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that the after dicts were correctly generated - assert: - that: - - "{{ deleted_afi['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Delete attributes of given interfaces (IDEMPOTENT) - vyos_firewall_interfaces: *deleted_afi - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result.changed == false" - - "result.commands|length == 0" - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ deleted_afi['after'] | symmetric_difference(result['before']) |length == 0 }}" - always: - - include_tasks: _remove_config.yaml - - - include_tasks: _remove_firewall_config.yaml diff --git a/test/integration/targets/vyos_firewall_interfaces/tests/cli/deleted_all.yaml b/test/integration/targets/vyos_firewall_interfaces/tests/cli/deleted_all.yaml deleted file mode 100644 index 38495d4839..0000000000 --- a/test/integration/targets/vyos_firewall_interfaces/tests/cli/deleted_all.yaml +++ /dev/null @@ -1,48 +0,0 @@ ---- -- debug: - msg: "Start vyos_firewall_interfaces deleted integration tests ansible_connection={{ ansible_connection }}" - -- include_tasks: _populate_rule_sets.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Delete all the firewall interfaces. - vyos_firewall_interfaces: &deleted_all - config: - state: deleted - register: result - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that the correct set of commands were generated - assert: - that: - - "{{ deleted['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that the after dicts were correctly generated - assert: - that: - - "{{ deleted['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Delete attributes of given interfaces (IDEMPOTENT) - vyos_firewall_interfaces: *deleted_all - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result.changed == false" - - "result.commands|length == 0" - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ deleted['after'] | symmetric_difference(result['before']) |length == 0 }}" - always: - - include_tasks: _remove_config.yaml - - - include_tasks: _remove_firewall_config.yaml diff --git a/test/integration/targets/vyos_firewall_interfaces/tests/cli/deleted_single.yaml b/test/integration/targets/vyos_firewall_interfaces/tests/cli/deleted_single.yaml deleted file mode 100644 index 70c58fc255..0000000000 --- a/test/integration/targets/vyos_firewall_interfaces/tests/cli/deleted_single.yaml +++ /dev/null @@ -1,54 +0,0 @@ ---- -- debug: - msg: "Start vyos_firewall_interfaces deleted integration tests ansible_connection={{ ansible_connection }}" - -- include_tasks: _populate_rule_sets.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Delete firewall interface. - vyos_firewall_interfaces: &deleted_single - config: - - name: 'eth1' - access_rules: - - afi: 'ipv4' - rules: - - direction: 'in' - name: 'INBOUND' - state: deleted - register: result - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that the correct set of commands were generated - assert: - that: - - "{{ deleted_single['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that the after dicts were correctly generated - assert: - that: - - "{{ deleted_single['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Delete attributes of given interfaces (IDEMPOTENT) - vyos_firewall_interfaces: *deleted_single - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result.changed == false" - - "result.commands|length == 0" - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ deleted_single['after'] | symmetric_difference(result['before']) |length == 0 }}" - always: - - include_tasks: _remove_config.yaml - - - include_tasks: _remove_firewall_config.yaml diff --git a/test/integration/targets/vyos_firewall_interfaces/tests/cli/empty_config.yaml b/test/integration/targets/vyos_firewall_interfaces/tests/cli/empty_config.yaml deleted file mode 100644 index 0881d5f8bc..0000000000 --- a/test/integration/targets/vyos_firewall_interfaces/tests/cli/empty_config.yaml +++ /dev/null @@ -1,58 +0,0 @@ ---- -- debug: - msg: "START vyos_firewall_interfaces empty_config integration tests on connection={{ ansible_connection }}" - -- name: Merged with empty config should give appropriate error message - vyos_firewall_interfaces: - config: - state: merged - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state merged' - -- name: Replaced with empty config should give appropriate error message - vyos_firewall_interfaces: - config: - state: replaced - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state replaced' - -- name: Overridden with empty config should give appropriate error message - vyos_firewall_interfaces: - config: - state: overridden - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state overridden' - -- name: Parsed with empty running_config should give appropriate error message - vyos_firewall_interfaces: - running_config: - state: parsed - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of running_config parameter must not be empty for state parsed' - -- name: Rendered with empty config should give appropriate error message - vyos_firewall_interfaces: - config: - state: rendered - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/test/integration/targets/vyos_firewall_interfaces/tests/cli/gathered.yaml b/test/integration/targets/vyos_firewall_interfaces/tests/cli/gathered.yaml deleted file mode 100644 index 2536476b8f..0000000000 --- a/test/integration/targets/vyos_firewall_interfaces/tests/cli/gathered.yaml +++ /dev/null @@ -1,37 +0,0 @@ ---- -- debug: - msg: "START vyos_firewall_interfaces gathered integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _remove_firewall_config.yaml - -- include_tasks: _populate_rule_sets.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Merge the provided configuration with the exisiting running configuration - vyos_firewall_interfaces: &gathered - config: - state: gathered - register: result - - - name: Assert that gathered dicts was correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['gathered']) |length == 0 }}" - - - name: Gather the existing running configuration (IDEMPOTENT) - vyos_firewall_interfaces: *gathered - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - - always: - - include_tasks: _remove_config.yaml - - - include_tasks: _remove_firewall_config.yaml diff --git a/test/integration/targets/vyos_firewall_interfaces/tests/cli/merged.yaml b/test/integration/targets/vyos_firewall_interfaces/tests/cli/merged.yaml deleted file mode 100644 index fb0733809b..0000000000 --- a/test/integration/targets/vyos_firewall_interfaces/tests/cli/merged.yaml +++ /dev/null @@ -1,75 +0,0 @@ ---- -- debug: - msg: "START vyos_firewall_interfaces merged integration tests on connection={{ ansible_connection }}" - -- include_tasks: _populate_rule_sets.yaml - -- include_tasks: _remove_config.yaml - -- block: - - name: Merge the provided configuration with the exisiting running configuration - vyos_firewall_interfaces: &merged - config: - - name: 'eth1' - access_rules: - - afi: 'ipv4' - rules: - - direction: 'in' - name: 'INBOUND' - - direction: 'local' - name: 'LOCAL' - - direction: 'out' - name: 'OUTBOUND' - - afi: 'ipv6' - rules: - - direction: 'local' - name: 'V6-LOCAL' - - name: 'eth2' - access_rules: - - afi: 'ipv4' - rules: - - direction: 'in' - name: 'INBOUND' - - direction: 'local' - name: 'LOCAL' - - direction: 'out' - name: 'OUTBOUND' - - afi: 'ipv6' - rules: - - direction: 'local' - name: 'V6-LOCAL' - state: merged - register: result - - - name: Assert that before dicts were correctly generated - assert: - that: "{{ merged['before'] | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that correct set of commands were generated - assert: - that: - - "{{ merged['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that after dicts was correctly generated - assert: - that: - - "{{ merged['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) - vyos_firewall_interfaces: *merged - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - - - name: Assert that before dicts were correctly generated - assert: - that: - - "{{ merged['after'] | symmetric_difference(result['before']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml - - - include_tasks: _remove_firewall_config.yaml diff --git a/test/integration/targets/vyos_firewall_interfaces/tests/cli/merged_edit.yaml b/test/integration/targets/vyos_firewall_interfaces/tests/cli/merged_edit.yaml deleted file mode 100644 index 1393a5b10d..0000000000 --- a/test/integration/targets/vyos_firewall_interfaces/tests/cli/merged_edit.yaml +++ /dev/null @@ -1,59 +0,0 @@ ---- -- debug: - msg: "START vyos_firewall_interfaces merged integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _remove_firewall_config.yaml - -- include_tasks: _populate_rule_sets.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Merge the provided configuration with the exisiting running configuration - vyos_firewall_interfaces: &merged_edit - config: - - name: 'eth1' - access_rules: - - afi: 'ipv4' - rules: - - direction: 'in' - name: 'OUTBOUND' - - direction: 'out' - name: 'INBOUND' - state: merged - register: result - - - name: Assert that before dicts were correctly generated - assert: - that: "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that correct set of commands were generated - assert: - that: - - "{{ merged_edit['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that after dicts was correctly generated - assert: - that: - - "{{ merged_edit['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) - vyos_firewall_interfaces: *merged_edit - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - - - name: Assert that before dicts were correctly generated - assert: - that: - - "{{ merged_edit['after'] | symmetric_difference(result['before']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml - - - include_tasks: _remove_firewall_config.yaml diff --git a/test/integration/targets/vyos_firewall_interfaces/tests/cli/overridden.yaml b/test/integration/targets/vyos_firewall_interfaces/tests/cli/overridden.yaml deleted file mode 100644 index daf3414518..0000000000 --- a/test/integration/targets/vyos_firewall_interfaces/tests/cli/overridden.yaml +++ /dev/null @@ -1,58 +0,0 @@ ---- -- debug: - msg: "START vyos_firewall_interfaces overridden integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _remove_firewall_config.yaml - -- include_tasks: _populate_rule_sets.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Overrides all device configuration with provided configuration - vyos_firewall_interfaces: &overridden - config: - - name: 'eth2' - access_rules: - - afi: 'ipv4' - rules: - - name: 'INBOUND' - direction: 'out' - state: overridden - register: result - - - name: Assert that before dicts were correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that correct commands were generated - assert: - that: - - "{{ overridden['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that after dicts were correctly generated - assert: - that: - - "{{ overridden['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Overrides all device configuration with provided configurations (IDEMPOTENT) - vyos_firewall_interfaces: *overridden - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - - - name: Assert that before dicts were correctly generated - assert: - that: - - "{{ overridden['after'] | symmetric_difference(result['before']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml - - - include_tasks: _remove_firewall_config.yaml diff --git a/test/integration/targets/vyos_firewall_interfaces/tests/cli/parsed.yaml b/test/integration/targets/vyos_firewall_interfaces/tests/cli/parsed.yaml deleted file mode 100644 index 646af8b847..0000000000 --- a/test/integration/targets/vyos_firewall_interfaces/tests/cli/parsed.yaml +++ /dev/null @@ -1,44 +0,0 @@ ---- -- debug: - msg: "START vyos_firewall_interfaces parsed integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _remove_firewall_config.yaml - -- include_tasks: _populate_rule_sets.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Gather firewall_interfaces facts - vyos_facts: - gather_subset: - - default - gather_network_resources: - - firewall_interfaces - register: firewall_interfaces_facts - - - name: Provide the running configuration for parsing (config to be parsed) - vyos_firewall_interfaces: &parsed - running_config: - "{{ lookup('file', '_parsed_config.cfg') }}" - state: parsed - register: result - - - name: Assert that correct parsing done - assert: - that: "{{ ansible_facts['network_resources']['firewall_interfaces'] | symmetric_difference(result['parsed']) |length == 0 }}" - - - name: Gather the existing running configuration (IDEMPOTENT) - vyos_firewall_interfaces: *parsed - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - always: - - include_tasks: _remove_config.yaml - - - include_tasks: _remove_firewall_config.yaml diff --git a/test/integration/targets/vyos_firewall_interfaces/tests/cli/rendered.yaml b/test/integration/targets/vyos_firewall_interfaces/tests/cli/rendered.yaml deleted file mode 100644 index ff969ede61..0000000000 --- a/test/integration/targets/vyos_firewall_interfaces/tests/cli/rendered.yaml +++ /dev/null @@ -1,55 +0,0 @@ ---- -- debug: - msg: "START vyos_firewall_interfaces rendered integration tests on connection={{ ansible_connection }}" - -- block: - - name: Structure provided configuration into device specific commands - vyos_firewall_interfaces: &rendered - config: - - name: 'eth1' - access_rules: - - afi: 'ipv4' - rules: - - name: 'INBOUND' - direction: 'in' - - name: 'OUTBOUND' - direction: 'out' - - name: 'LOCAL' - direction: 'local' - - afi: 'ipv6' - rules: - - name: 'V6-LOCAL' - direction: 'local' - - name: 'eth2' - access_rules: - - afi: 'ipv4' - rules: - - name: 'INBOUND' - direction: 'in' - - name: 'OUTBOUND' - direction: 'out' - - name: 'LOCAL' - direction: 'local' - - afi: 'ipv6' - rules: - - name: 'V6-LOCAL' - direction: 'local' - state: rendered - register: result - - - name: Assert that correct set of commands were generated - assert: - that: - - "{{ rendered['commands'] | symmetric_difference(result['rendered']) |length == 0 }}" - - - name: Structure provided configuration into device specific commands (IDEMPOTENT) - vyos_firewall_interfaces: *rendered - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_firewall_interfaces/tests/cli/replaced.yaml b/test/integration/targets/vyos_firewall_interfaces/tests/cli/replaced.yaml deleted file mode 100644 index cd349ae239..0000000000 --- a/test/integration/targets/vyos_firewall_interfaces/tests/cli/replaced.yaml +++ /dev/null @@ -1,68 +0,0 @@ ---- -- debug: - msg: "START vyos_firewall_interfaces replaced integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _remove_firewall_config.yaml - -- include_tasks: _populate_rule_sets.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Replace device configurations of listed firewall rules with provided configurations - vyos_firewall_interfaces: &replaced - config: - - name: 'eth1' - access_rules: - - afi: 'ipv4' - rules: - - name: 'OUTBOUND' - direction: 'out' - - afi: 'ipv6' - rules: - - name: 'V6-LOCAL' - direction: 'local' - - name: 'eth2' - access_rules: - - afi: 'ipv4' - rules: - - name: 'INBOUND' - direction: 'in' - state: replaced - register: result - - - name: Assert that correct set of commands were generated - assert: - that: - - "{{ replaced['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that before dicts are correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that after dict is correctly generated - assert: - that: - - "{{ replaced['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Replace device configurations of listed firewall rules with provided configurarions (IDEMPOTENT) - vyos_firewall_interfaces: *replaced - register: result - - - name: Assert that task was idempotent - assert: - that: - - "result['changed'] == false" - - - name: Assert that before dict is correctly generated - assert: - that: - - "{{ replaced['after'] | symmetric_difference(result['before']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml - - - include_tasks: _remove_firewall_config.yaml diff --git a/test/integration/targets/vyos_firewall_interfaces/tests/cli/rtt.yaml b/test/integration/targets/vyos_firewall_interfaces/tests/cli/rtt.yaml deleted file mode 100644 index 0d06069fb5..0000000000 --- a/test/integration/targets/vyos_firewall_interfaces/tests/cli/rtt.yaml +++ /dev/null @@ -1,76 +0,0 @@ ---- -- debug: - msg: "START vyos_firewall_interfaces round trip integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _remove_firewall_config.yaml - -- include_tasks: _populate_rule_sets.yaml - -- block: - - name: Apply the provided configuration (base config) - vyos_firewall_interfaces: - config: - - name: 'eth1' - access_rules: - - afi: 'ipv4' - rules: - - name: 'INBOUND' - direction: 'in' - - name: 'OUTBOUND' - direction: 'out' - - name: 'LOCAL' - direction: 'local' - - afi: 'ipv6' - rules: - - name: 'V6-LOCAL' - direction: 'local' - state: merged - register: base_config - - - name: Gather firewall_interfaces facts - vyos_facts: - gather_subset: - - default - gather_network_resources: - - firewall_interfaces - - - name: Apply the provided configuration (config to be reverted) - vyos_firewall_interfaces: - config: - - name: 'eth2' - access_rules: - - afi: 'ipv4' - rules: - - name: 'INBOUND' - direction: 'in' - - name: 'OUTBOUND' - direction: 'out' - - name: 'LOCAL' - direction: 'local' - - afi: 'ipv6' - rules: - - name: 'V6-LOCAL' - direction: 'local' - state: merged - register: result - - - name: Assert that changes were applied - assert: - that: "{{ round_trip['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Revert back to base config using facts round trip - vyos_firewall_interfaces: - config: "{{ ansible_facts['network_resources']['firewall_interfaces'] }}" - state: overridden - register: revert - - - name: Assert that config was reverted - assert: - that: "{{ base_config['after'] | symmetric_difference(revert['after']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml - - - include_tasks: _remove_firewall_config.yaml diff --git a/test/integration/targets/vyos_firewall_interfaces/vars/main.yaml b/test/integration/targets/vyos_firewall_interfaces/vars/main.yaml deleted file mode 100644 index fa21a500fe..0000000000 --- a/test/integration/targets/vyos_firewall_interfaces/vars/main.yaml +++ /dev/null @@ -1,294 +0,0 @@ ---- -merged: - before: - - name: eth0 - - name: eth1 - - name: eth2 - - commands: - - "set interfaces ethernet eth1 firewall in name 'INBOUND'" - - "set interfaces ethernet eth1 firewall out name 'OUTBOUND'" - - "set interfaces ethernet eth1 firewall local name 'LOCAL'" - - "set interfaces ethernet eth1 firewall local ipv6-name 'V6-LOCAL'" - - "set interfaces ethernet eth2 firewall in name 'INBOUND'" - - "set interfaces ethernet eth2 firewall out name 'OUTBOUND'" - - "set interfaces ethernet eth2 firewall local name 'LOCAL'" - - "set interfaces ethernet eth2 firewall local ipv6-name 'V6-LOCAL'" - - after: - - name: eth0 - - access_rules: - - afi: ipv4 - rules: - - direction: in - name: INBOUND - - direction: local - name: LOCAL - - direction: out - name: OUTBOUND - - afi: ipv6 - rules: - - direction: local - name: V6-LOCAL - name: eth1 - - access_rules: - - afi: ipv4 - rules: - - direction: in - name: INBOUND - - direction: local - name: LOCAL - - direction: out - name: OUTBOUND - - afi: ipv6 - rules: - - direction: local - name: V6-LOCAL - name: eth2 - -populate: - - name: eth0 - - access_rules: - - afi: ipv4 - rules: - - direction: in - name: INBOUND - - direction: local - name: LOCAL - - direction: out - name: OUTBOUND - - afi: ipv6 - rules: - - direction: local - name: V6-LOCAL - name: eth1 - - access_rules: - - afi: ipv4 - rules: - - direction: in - name: INBOUND - - direction: local - name: LOCAL - - direction: out - name: OUTBOUND - - afi: ipv6 - rules: - - direction: local - name: V6-LOCAL - name: eth2 - -merged_edit: - commands: - - "set interfaces ethernet eth1 firewall in name 'OUTBOUND'" - - "set interfaces ethernet eth1 firewall out name 'INBOUND'" - - after: - - name: eth0 - - access_rules: - - afi: ipv4 - rules: - - direction: in - name: OUTBOUND - - direction: local - name: LOCAL - - direction: out - name: INBOUND - - afi: ipv6 - rules: - - direction: local - name: V6-LOCAL - name: eth1 - - access_rules: - - afi: ipv4 - rules: - - direction: in - name: INBOUND - - direction: local - name: LOCAL - - direction: out - name: OUTBOUND - - afi: ipv6 - rules: - - direction: local - name: V6-LOCAL - name: eth2 -replaced: - commands: - - "delete interfaces ethernet eth2 firewall out name" - - "delete interfaces ethernet eth2 firewall local name" - - "delete interfaces ethernet eth2 firewall local ipv6-name" - - "delete interfaces ethernet eth1 firewall local name" - - "delete interfaces ethernet eth1 firewall in name" - - after: - - name: eth0 - - access_rules: - - afi: ipv4 - rules: - - direction: out - name: OUTBOUND - - afi: ipv6 - rules: - - direction: local - name: V6-LOCAL - name: eth1 - - access_rules: - - afi: ipv4 - rules: - - direction: in - name: INBOUND - name: eth2 - -overridden: - before: - - access_rules: - - afi: ipv4 - rules: - - direction: in - name: INBOUND - - direction: local - name: LOCAL - - direction: out - name: OUTBOUND - - afi: ipv6 - rules: - - direction: local - name: V6-LOCAL - name: eth1 - - access_rules: - - afi: ipv4 - rules: - - name: INBOUND - direction: in - - name: LOCAL - direction: local - - name: OUTBOUND - direction: out - - afi: ipv6 - rules: - - name: V6-LOCAL - direction: local - name: eth2 - commands: - - "delete interfaces ethernet eth1 firewall" - - "delete interfaces ethernet eth2 firewall in name" - - "delete interfaces ethernet eth2 firewall local name" - - "delete interfaces ethernet eth2 firewall local ipv6-name" - - "set interfaces ethernet eth2 firewall out name 'INBOUND'" - - after: - - name: eth0 - - name: eth1 - - access_rules: - - afi: ipv4 - rules: - - name: INBOUND - direction: out - name: eth2 - -deleted: - commands: - - "delete interfaces ethernet eth1 firewall" - - "delete interfaces ethernet eth2 firewall" - - after: - - name: eth0 - - name: eth1 - - name: eth2 - -deleted_afi: - commands: - - "delete interfaces ethernet eth1 firewall in name" - - "delete interfaces ethernet eth1 firewall local name" - - "delete interfaces ethernet eth1 firewall out name" - - "delete interfaces ethernet eth1 firewall local ipv6-name" - - "delete interfaces ethernet eth2 firewall in name" - - "delete interfaces ethernet eth2 firewall local name" - - "delete interfaces ethernet eth2 firewall out name" - - "delete interfaces ethernet eth2 firewall local ipv6-name" - - after: - - name: eth0 - - access_rules: - - afi: ipv4 - - afi: ipv6 - name: eth1 - - access_rules: - - afi: ipv4 - - afi: ipv6 - name: eth2 - -deleted_single: - commands: - - "delete interfaces ethernet eth1 firewall in name 'INBOUND'" - after: - - name: eth0 - - access_rules: - - afi: ipv4 - rules: - - direction: local - name: LOCAL - - direction: out - name: OUTBOUND - - afi: ipv6 - rules: - - direction: local - name: V6-LOCAL - name: eth1 - - access_rules: - - afi: ipv4 - rules: - - direction: in - name: INBOUND - - direction: local - name: LOCAL - - direction: out - name: OUTBOUND - - afi: ipv6 - rules: - - direction: local - name: V6-LOCAL - name: eth2 - -rendered: - commands: - - "set interfaces ethernet eth1 firewall in name 'INBOUND'" - - "set interfaces ethernet eth1 firewall out name 'OUTBOUND'" - - "set interfaces ethernet eth1 firewall local name 'LOCAL'" - - "set interfaces ethernet eth1 firewall local ipv6-name 'V6-LOCAL'" - - "set interfaces ethernet eth2 firewall in name 'INBOUND'" - - "set interfaces ethernet eth2 firewall out name 'OUTBOUND'" - - "set interfaces ethernet eth2 firewall local name 'LOCAL'" - - "set interfaces ethernet eth2 firewall local ipv6-name 'V6-LOCAL'" - -round_trip: - after: - - name: eth0 - - access_rules: - - afi: ipv4 - rules: - - direction: in - name: INBOUND - - direction: local - name: LOCAL - - direction: out - name: OUTBOUND - - afi: ipv6 - rules: - - direction: local - name: V6-LOCAL - name: eth1 - - name: eth2 - access_rules: - - afi: ipv4 - rules: - - direction: in - name: INBOUND - - direction: local - name: LOCAL - - direction: out - name: OUTBOUND - - afi: ipv6 - rules: - - direction: local - name: V6-LOCAL diff --git a/test/integration/targets/vyos_firewall_rules/aliases b/test/integration/targets/vyos_firewall_rules/aliases deleted file mode 100644 index 8071e1f75b..0000000000 --- a/test/integration/targets/vyos_firewall_rules/aliases +++ /dev/null @@ -1 +0,0 @@ -shippable/vyos/group1 diff --git a/test/integration/targets/vyos_firewall_rules/defaults/main.yaml b/test/integration/targets/vyos_firewall_rules/defaults/main.yaml deleted file mode 100644 index 164afead28..0000000000 --- a/test/integration/targets/vyos_firewall_rules/defaults/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -testcase: "[^_].*" -test_items: [] diff --git a/test/integration/targets/vyos_firewall_rules/meta/main.yaml b/test/integration/targets/vyos_firewall_rules/meta/main.yaml deleted file mode 100644 index 7413320e48..0000000000 --- a/test/integration/targets/vyos_firewall_rules/meta/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dependencies: - - prepare_vyos_tests diff --git a/test/integration/targets/vyos_firewall_rules/tasks/cli.yaml b/test/integration/targets/vyos_firewall_rules/tasks/cli.yaml deleted file mode 100644 index 655e51ee63..0000000000 --- a/test/integration/targets/vyos_firewall_rules/tasks/cli.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -- name: Collect all cli test cases - find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - use_regex: true - register: test_cases - delegate_to: localhost - -- name: Set test_items - set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test case (connection=network_cli) - include: "{{ test_case_to_run }}" - vars: - ansible_connection: network_cli - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run diff --git a/test/integration/targets/vyos_firewall_rules/tasks/main.yaml b/test/integration/targets/vyos_firewall_rules/tasks/main.yaml deleted file mode 100644 index d4cf26fc4a..0000000000 --- a/test/integration/targets/vyos_firewall_rules/tasks/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -- {include: cli.yaml, tags: ['cli']} diff --git a/test/integration/targets/vyos_firewall_rules/tests/cli/_parsed_config.cfg b/test/integration/targets/vyos_firewall_rules/tests/cli/_parsed_config.cfg deleted file mode 100644 index b54c10948c..0000000000 --- a/test/integration/targets/vyos_firewall_rules/tests/cli/_parsed_config.cfg +++ /dev/null @@ -1,25 +0,0 @@ -set firewall group address-group 'inbound' -set firewall ipv6-name UPLINK default-action 'accept' -set firewall ipv6-name UPLINK description 'This is ipv6 specific rule-set' -set firewall ipv6-name UPLINK rule 1 action 'accept' -set firewall ipv6-name UPLINK rule 1 description 'Fwipv6-Rule 1 is configured by Ansible' -set firewall ipv6-name UPLINK rule 1 ipsec 'match-ipsec' -set firewall ipv6-name UPLINK rule 2 action 'accept' -set firewall ipv6-name UPLINK rule 2 description 'Fwipv6-Rule 2 is configured by Ansible' -set firewall ipv6-name UPLINK rule 2 ipsec 'match-ipsec' -set firewall name INBOUND default-action 'accept' -set firewall name INBOUND description 'IPv4 INBOUND rule set' -set firewall name INBOUND rule 101 action 'accept' -set firewall name INBOUND rule 101 description 'Rule 101 is configured by Ansible' -set firewall name INBOUND rule 101 ipsec 'match-ipsec' -set firewall name INBOUND rule 102 action 'reject' -set firewall name INBOUND rule 102 description 'Rule 102 is configured by Ansible' -set firewall name INBOUND rule 102 ipsec 'match-ipsec' -set firewall name INBOUND rule 103 action 'accept' -set firewall name INBOUND rule 103 description 'Rule 103 is configured by Ansible' -set firewall name INBOUND rule 103 destination group address-group 'inbound' -set firewall name INBOUND rule 103 source address '192.0.2.0' -set firewall name INBOUND rule 103 state established 'enable' -set firewall name INBOUND rule 103 state invalid 'disable' -set firewall name INBOUND rule 103 state new 'disable' -set firewall name INBOUND rule 103 state related 'enable' diff --git a/test/integration/targets/vyos_firewall_rules/tests/cli/_populate.yaml b/test/integration/targets/vyos_firewall_rules/tests/cli/_populate.yaml deleted file mode 100644 index ae6e17a188..0000000000 --- a/test/integration/targets/vyos_firewall_rules/tests/cli/_populate.yaml +++ /dev/null @@ -1,31 +0,0 @@ ---- -- name: Setup - cli_config: - config: "{{ lines }}" - vars: - lines: | - set firewall group address-group 'inbound' - set firewall ipv6-name UPLINK default-action 'accept' - set firewall ipv6-name UPLINK description 'This is ipv6 specific rule-set' - set firewall ipv6-name UPLINK rule 1 action 'accept' - set firewall ipv6-name UPLINK rule 1 description 'Fwipv6-Rule 1 is configured by Ansible' - set firewall ipv6-name UPLINK rule 1 ipsec 'match-ipsec' - set firewall ipv6-name UPLINK rule 2 action 'accept' - set firewall ipv6-name UPLINK rule 2 description 'Fwipv6-Rule 2 is configured by Ansible' - set firewall ipv6-name UPLINK rule 2 ipsec 'match-ipsec' - set firewall name INBOUND default-action 'accept' - set firewall name INBOUND description 'IPv4 INBOUND rule set' - set firewall name INBOUND rule 101 action 'accept' - set firewall name INBOUND rule 101 description 'Rule 101 is configured by Ansible' - set firewall name INBOUND rule 101 ipsec 'match-ipsec' - set firewall name INBOUND rule 102 action 'reject' - set firewall name INBOUND rule 102 description 'Rule 102 is configured by Ansible' - set firewall name INBOUND rule 102 ipsec 'match-ipsec' - set firewall name INBOUND rule 103 action 'accept' - set firewall name INBOUND rule 103 description 'Rule 103 is configured by Ansible' - set firewall name INBOUND rule 103 destination group address-group 'inbound' - set firewall name INBOUND rule 103 source address '192.0.2.0' - set firewall name INBOUND rule 103 state established 'enable' - set firewall name INBOUND rule 103 state invalid 'disable' - set firewall name INBOUND rule 103 state new 'disable' - set firewall name INBOUND rule 103 state related 'enable' diff --git a/test/integration/targets/vyos_firewall_rules/tests/cli/_remove_config.yaml b/test/integration/targets/vyos_firewall_rules/tests/cli/_remove_config.yaml deleted file mode 100644 index 9a9aff9103..0000000000 --- a/test/integration/targets/vyos_firewall_rules/tests/cli/_remove_config.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -- name: Remove Config - cli_config: - config: "{{ lines }}" - vars: - lines: | - delete firewall ipv6-name - delete firewall name diff --git a/test/integration/targets/vyos_firewall_rules/tests/cli/deleted.yaml b/test/integration/targets/vyos_firewall_rules/tests/cli/deleted.yaml deleted file mode 100644 index 881c19349b..0000000000 --- a/test/integration/targets/vyos_firewall_rules/tests/cli/deleted.yaml +++ /dev/null @@ -1,50 +0,0 @@ ---- -- debug: - msg: "Start vyos_firewall_rules deleted integration tests ansible_connection={{ ansible_connection }}" - -- include_tasks: _populate.yaml - -- block: - - name: Delete firewall rule set. - vyos_firewall_rules: &deleted_rs - config: - - afi: 'ipv6' - rule_sets: - - name: 'UPLINK' - - afi: 'ipv4' - rule_sets: - - name: 'INBOUND' - state: deleted - register: result - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that the correct set of commands were generated - assert: - that: - - "{{ deleted_rs['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that the after dicts were correctly generated - assert: - that: - - "{{ deleted_rs['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Delete attributes of given interfaces (IDEMPOTENT) - vyos_firewall_rules: *deleted_rs - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result.changed == false" - - "result.commands|length == 0" - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ deleted_rs['after'] | symmetric_difference(result['before']) |length == 0 }}" - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_firewall_rules/tests/cli/deleted_afi.yaml b/test/integration/targets/vyos_firewall_rules/tests/cli/deleted_afi.yaml deleted file mode 100644 index 1502e86bf4..0000000000 --- a/test/integration/targets/vyos_firewall_rules/tests/cli/deleted_afi.yaml +++ /dev/null @@ -1,46 +0,0 @@ ---- -- debug: - msg: "Start vyos_firewall_rules deleted integration tests ansible_connection={{ ansible_connection }}" - -- include_tasks: _populate.yaml - -- block: - - name: Delete firewall rule. - vyos_firewall_rules: &deleted_afi - config: - - afi: 'ipv6' - - afi: 'ipv4' - state: deleted - register: result - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that the correct set of commands were generated - assert: - that: - - "{{ deleted_afi_all['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that the after dicts were correctly generated - assert: - that: - - "{{ deleted_afi_all['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Delete attributes of given interfaces (IDEMPOTENT) - vyos_firewall_rules: *deleted_afi - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result.changed == false" - - "result.commands|length == 0" - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ deleted_afi_all['after'] | symmetric_difference(result['before']) |length == 0 }}" - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_firewall_rules/tests/cli/deleted_all.yaml b/test/integration/targets/vyos_firewall_rules/tests/cli/deleted_all.yaml deleted file mode 100644 index 60c7a67284..0000000000 --- a/test/integration/targets/vyos_firewall_rules/tests/cli/deleted_all.yaml +++ /dev/null @@ -1,44 +0,0 @@ ---- -- debug: - msg: "Start vyos_firewall_rules deleted integration tests ansible_connection={{ ansible_connection }}" - -- include_tasks: _populate.yaml - -- block: - - name: Delete all the firewall rules. - vyos_firewall_rules: &deleted_all - config: - state: deleted - register: result - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that the correct set of commands were generated - assert: - that: - - "{{ deleted_afi_all['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that the after dicts were correctly generated - assert: - that: - - "{{ deleted_afi_all['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Delete attributes of given interfaces (IDEMPOTENT) - vyos_firewall_rules: *deleted_all - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result.changed == false" - - "result.commands|length == 0" - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ deleted_afi_all['after'] | symmetric_difference(result['before']) |length == 0 }}" - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_firewall_rules/tests/cli/deleted_rule.yaml b/test/integration/targets/vyos_firewall_rules/tests/cli/deleted_rule.yaml deleted file mode 100644 index 7ecdcb380c..0000000000 --- a/test/integration/targets/vyos_firewall_rules/tests/cli/deleted_rule.yaml +++ /dev/null @@ -1,49 +0,0 @@ ---- -- debug: - msg: "Start vyos_firewall_rules deleted integration tests ansible_connection={{ ansible_connection }}" - -- include_tasks: _populate.yaml - -- block: - - name: Delete firewall rule. - vyos_firewall_rules: &deleted_r - config: - - afi: 'ipv6' - rule_sets: - - name: 'UPLINK' - rules: - - number: 1 - state: deleted - register: result - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that the correct set of commands were generated - assert: - that: - - "{{ deleted_r['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that the after dicts were correctly generated - assert: - that: - - "{{ deleted_r['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Delete attributes of given interfaces (IDEMPOTENT) - vyos_firewall_rules: *deleted_r - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result.changed == false" - - "result.commands|length == 0" - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ deleted_r['after'] | symmetric_difference(result['before']) |length == 0 }}" - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_firewall_rules/tests/cli/empty_config.yaml b/test/integration/targets/vyos_firewall_rules/tests/cli/empty_config.yaml deleted file mode 100644 index 262b3059e5..0000000000 --- a/test/integration/targets/vyos_firewall_rules/tests/cli/empty_config.yaml +++ /dev/null @@ -1,58 +0,0 @@ ---- -- debug: - msg: "START vyos_firewall_rules empty_config integration tests on connection={{ ansible_connection }}" - -- name: Merged with empty config should give appropriate error message - vyos_firewall_rules: - config: - state: merged - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state merged' - -- name: Replaced with empty config should give appropriate error message - vyos_firewall_rules: - config: - state: replaced - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state replaced' - -- name: Overridden with empty config should give appropriate error message - vyos_firewall_rules: - config: - state: overridden - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state overridden' - -- name: Parsed with empty running_config should give appropriate error message - vyos_firewall_rules: - running_config: - state: parsed - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of running_config parameter must not be empty for state parsed' - -- name: Rendered with empty config should give appropriate error message - vyos_firewall_rules: - config: - state: rendered - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/test/integration/targets/vyos_firewall_rules/tests/cli/gathered.yaml b/test/integration/targets/vyos_firewall_rules/tests/cli/gathered.yaml deleted file mode 100644 index 5a0bac753b..0000000000 --- a/test/integration/targets/vyos_firewall_rules/tests/cli/gathered.yaml +++ /dev/null @@ -1,31 +0,0 @@ ---- -- debug: - msg: "START vyos_firewall_rules gathered integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Merge the provided configuration with the exisiting running configuration - vyos_firewall_rules: &gathered - config: - state: gathered - register: result - - - name: Assert that gathered dicts was correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['gathered']) |length == 0 }}" - - - name: Gather the existing running configuration (IDEMPOTENT) - vyos_firewall_rules: *gathered - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_firewall_rules/tests/cli/merged.yaml b/test/integration/targets/vyos_firewall_rules/tests/cli/merged.yaml deleted file mode 100644 index 596f4a143d..0000000000 --- a/test/integration/targets/vyos_firewall_rules/tests/cli/merged.yaml +++ /dev/null @@ -1,87 +0,0 @@ ---- -- debug: - msg: "START vyos_firewall_rules merged integration tests on connection={{ ansible_connection }}" - -- include_tasks: _populate.yaml - -- include_tasks: _remove_config.yaml - -- block: - - name: Merge the provided configuration with the exisiting running configuration - vyos_firewall_rules: &merged - config: - - afi: 'ipv6' - rule_sets: - - name: 'UPLINK' - description: 'This is ipv6 specific rule-set' - default_action: 'accept' - rules: - - number: 1 - action: 'accept' - description: 'Fwipv6-Rule 1 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 2 - action: 'accept' - description: 'Fwipv6-Rule 2 is configured by Ansible' - ipsec: 'match-ipsec' - - - afi: 'ipv4' - rule_sets: - - name: 'INBOUND' - description: 'IPv4 INBOUND rule set' - default_action: 'accept' - rules: - - number: 101 - action: 'accept' - description: 'Rule 101 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 102 - action: 'reject' - description: 'Rule 102 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 103 - action: 'accept' - description: 'Rule 103 is configured by Ansible' - destination: - group: - address_group: 'inbound' - source: - address: '192.0.2.0' - state: - established: true - new: false - invalid: false - related: true - state: merged - register: result - - - name: Assert that before dicts were correctly generated - assert: - that: "{{ merged['before'] | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that correct set of commands were generated - assert: - that: - - "{{ merged['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that after dicts was correctly generated - assert: - that: - - "{{ merged['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) - vyos_firewall_rules: *merged - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - - - name: Assert that before dicts were correctly generated - assert: - that: - - "{{ merged['after'] | symmetric_difference(result['before']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_firewall_rules/tests/cli/overridden.yaml b/test/integration/targets/vyos_firewall_rules/tests/cli/overridden.yaml deleted file mode 100644 index d902f4791e..0000000000 --- a/test/integration/targets/vyos_firewall_rules/tests/cli/overridden.yaml +++ /dev/null @@ -1,60 +0,0 @@ ---- -- debug: - msg: "START vyos_firewall_rules overridden integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Overrides all device configuration with provided configuration - vyos_firewall_rules: &overridden - config: - - afi: 'ipv4' - rule_sets: - - name: 'Downlink' - description: 'IPv4 INBOUND rule set' - default_action: 'accept' - rules: - - number: 501 - action: 'accept' - description: 'Rule 501 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 502 - action: 'reject' - description: 'Rule 502 is configured by Ansible' - ipsec: 'match-ipsec' - state: overridden - register: result - - - name: Assert that before dicts were correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that correct commands were generated - assert: - that: - - "{{ overridden['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that after dicts were correctly generated - assert: - that: - - "{{ overridden['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Overrides all device configuration with provided configurations (IDEMPOTENT) - vyos_firewall_rules: *overridden - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - - - name: Assert that before dicts were correctly generated - assert: - that: - - "{{ overridden['after'] | symmetric_difference(result['before']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_firewall_rules/tests/cli/parsed.yaml b/test/integration/targets/vyos_firewall_rules/tests/cli/parsed.yaml deleted file mode 100644 index 7fb066da00..0000000000 --- a/test/integration/targets/vyos_firewall_rules/tests/cli/parsed.yaml +++ /dev/null @@ -1,39 +0,0 @@ ---- -- debug: - msg: "START vyos_firewall_rules parsed integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Gather firewall_rules facts - vyos_facts: - gather_subset: - - default - gather_network_resources: - - firewall_rules - register: firewall_rules_facts - - - name: Provide the running configuration for parsing (config to be parsed) - vyos_firewall_rules: &parsed - running_config: - "{{ lookup('file', '_parsed_config.cfg') }}" - state: parsed - register: result - - - name: Assert that correct parsing done - assert: - that: "{{ ansible_facts['network_resources']['firewall_rules'] | symmetric_difference(result['parsed']) |length == 0 }}" - - - name: Gather the existing running configuration (IDEMPOTENT) - vyos_firewall_rules: *parsed - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_firewall_rules/tests/cli/rendered.yaml b/test/integration/targets/vyos_firewall_rules/tests/cli/rendered.yaml deleted file mode 100644 index 958550e211..0000000000 --- a/test/integration/targets/vyos_firewall_rules/tests/cli/rendered.yaml +++ /dev/null @@ -1,63 +0,0 @@ ---- -- debug: - msg: "START vyos_firewall_rules rendered integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Structure provided configuration into device specific commands - vyos_firewall_rules: &rendered - config: - - afi: 'ipv6' - rule_sets: - - name: 'UPLINK' - description: 'This is ipv6 specific rule-set' - default_action: 'accept' - - afi: 'ipv4' - rule_sets: - - name: 'INBOUND' - description: 'IPv4 INBOUND rule set' - default_action: 'accept' - rules: - - number: 101 - action: 'accept' - description: 'Rule 101 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 102 - action: 'reject' - description: 'Rule 102 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 103 - action: 'accept' - description: 'Rule 103 is configured by Ansible' - destination: - group: - address_group: 'inbound' - source: - address: '192.0.2.0' - state: - established: true - new: false - invalid: false - related: true - state: rendered - register: result - - - name: Assert that correct set of commands were generated - assert: - that: - - "{{ rendered['commands'] | symmetric_difference(result['rendered']) |length == 0 }}" - - - name: Structure provided configuration into device specific commands (IDEMPOTENT) - vyos_firewall_rules: *rendered - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_firewall_rules/tests/cli/replaced.yaml b/test/integration/targets/vyos_firewall_rules/tests/cli/replaced.yaml deleted file mode 100644 index 164ff18707..0000000000 --- a/test/integration/targets/vyos_firewall_rules/tests/cli/replaced.yaml +++ /dev/null @@ -1,65 +0,0 @@ ---- -- debug: - msg: "START vyos_firewall_rules replaced integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Replace device configurations of listed firewall rules with provided configurations - vyos_firewall_rules: &replaced - config: - - afi: 'ipv6' - rule_sets: - - name: 'UPLINK' - description: 'This is ipv6 specific rule-set' - default_action: 'accept' - - afi: 'ipv4' - rule_sets: - - name: 'INBOUND' - description: 'IPv4 INBOUND rule set' - default_action: 'accept' - rules: - - number: 101 - action: 'accept' - description: 'Rule 101 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 104 - action: 'reject' - description: 'Rule 104 is configured by Ansible' - ipsec: 'match-none' - state: replaced - register: result - - - name: Assert that correct set of commands were generated - assert: - that: - - "{{ replaced['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that before dicts are correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that after dict is correctly generated - assert: - that: - - "{{ replaced['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Replace device configurations of listed firewall rules with provided configurarions (IDEMPOTENT) - vyos_firewall_rules: *replaced - register: result - - - name: Assert that task was idempotent - assert: - that: - - "result['changed'] == false" - - - name: Assert that before dict is correctly generated - assert: - that: - - "{{ replaced['after'] | symmetric_difference(result['before']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_firewall_rules/tests/cli/rtt.yaml b/test/integration/targets/vyos_firewall_rules/tests/cli/rtt.yaml deleted file mode 100644 index 921defb9d6..0000000000 --- a/test/integration/targets/vyos_firewall_rules/tests/cli/rtt.yaml +++ /dev/null @@ -1,87 +0,0 @@ ---- -- debug: - msg: "START vyos_firewall_rules round trip integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- block: - - name: Apply the provided configuration (base config) - vyos_firewall_rules: - config: - - afi: 'ipv6' - rule_sets: - - name: 'UPLINK' - description: 'This is ipv6 specific rule-set' - default_action: 'accept' - rules: - - number: 1 - action: 'accept' - description: 'Fwipv6-Rule 1 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 2 - action: 'accept' - description: 'Fwipv6-Rule 2 is configured by Ansible' - ipsec: 'match-ipsec' - - - afi: 'ipv4' - rule_sets: - - name: 'INBOUND' - description: 'IPv4 INBOUND rule set' - default_action: 'accept' - rules: - - number: 101 - action: 'accept' - description: 'Rule 101 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 102 - action: 'reject' - description: 'Rule 102 is configured by Ansible' - ipsec: 'match-ipsec' - state: merged - register: base_config - - - name: Gather firewall_rules facts - vyos_facts: - gather_subset: - - default - gather_network_resources: - - firewall_rules - - - name: Apply the provided configuration (config to be reverted) - vyos_firewall_rules: - config: - - afi: 'ipv4' - rule_sets: - - name: 'INBOUND' - description: 'IPv4 INBOUND rule set' - default_action: 'accept' - rules: - - number: 103 - action: 'accept' - description: 'Rule 103 is configured by Ansible' - source: - address: '192.0.2.0' - state: - established: true - new: false - invalid: false - related: true - state: merged - register: result - - - name: Assert that changes were applied - assert: - that: "{{ round_trip['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Revert back to base config using facts round trip - vyos_firewall_rules: - config: "{{ ansible_facts['network_resources']['firewall_rules'] }}" - state: overridden - register: revert - - - name: Assert that config was reverted - assert: - that: "{{ base_config['after'] | symmetric_difference(revert['after']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_firewall_rules/vars/main.yaml b/test/integration/targets/vyos_firewall_rules/vars/main.yaml deleted file mode 100644 index 64032cd307..0000000000 --- a/test/integration/targets/vyos_firewall_rules/vars/main.yaml +++ /dev/null @@ -1,327 +0,0 @@ ---- -merged: - before: [] - - - commands: - - "set firewall ipv6-name UPLINK default-action 'accept'" - - "set firewall ipv6-name UPLINK description 'This is ipv6 specific rule-set'" - - "set firewall ipv6-name UPLINK rule 1 action 'accept'" - - "set firewall ipv6-name UPLINK rule 1" - - "set firewall ipv6-name UPLINK rule 1 description 'Fwipv6-Rule 1 is configured by Ansible'" - - "set firewall ipv6-name UPLINK rule 1 ipsec 'match-ipsec'" - - "set firewall ipv6-name UPLINK rule 2 action 'accept'" - - "set firewall ipv6-name UPLINK rule 2" - - "set firewall ipv6-name UPLINK rule 2 description 'Fwipv6-Rule 2 is configured by Ansible'" - - "set firewall ipv6-name UPLINK rule 2 ipsec 'match-ipsec'" - - "set firewall name INBOUND default-action 'accept'" - - "set firewall name INBOUND description 'IPv4 INBOUND rule set'" - - "set firewall name INBOUND rule 101 action 'accept'" - - "set firewall name INBOUND rule 101" - - "set firewall name INBOUND rule 101 description 'Rule 101 is configured by Ansible'" - - "set firewall name INBOUND rule 101 ipsec 'match-ipsec'" - - "set firewall name INBOUND rule 102 action 'reject'" - - "set firewall name INBOUND rule 102" - - "set firewall name INBOUND rule 102 description 'Rule 102 is configured by Ansible'" - - "set firewall name INBOUND rule 102 ipsec 'match-ipsec'" - - "set firewall name INBOUND rule 103 description 'Rule 103 is configured by Ansible'" - - "set firewall name INBOUND rule 103 destination group address-group inbound" - - "set firewall name INBOUND rule 103" - - "set firewall name INBOUND rule 103 source address 192.0.2.0" - - "set firewall name INBOUND rule 103 state established enable" - - "set firewall name INBOUND rule 103 state related enable" - - "set firewall name INBOUND rule 103 state invalid disable" - - "set firewall name INBOUND rule 103 state new disable" - - "set firewall name INBOUND rule 103 action 'accept'" - - after: - - afi: 'ipv6' - rule_sets: - - name: 'UPLINK' - description: 'This is ipv6 specific rule-set' - default_action: 'accept' - rules: - - number: 1 - action: 'accept' - description: 'Fwipv6-Rule 1 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 2 - action: 'accept' - description: 'Fwipv6-Rule 2 is configured by Ansible' - ipsec: 'match-ipsec' - - - afi: 'ipv4' - rule_sets: - - name: 'INBOUND' - description: 'IPv4 INBOUND rule set' - default_action: 'accept' - rules: - - number: 101 - action: 'accept' - description: 'Rule 101 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 102 - action: 'reject' - description: 'Rule 102 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 103 - action: 'accept' - description: 'Rule 103 is configured by Ansible' - destination: - group: - address_group: 'inbound' - source: - address: '192.0.2.0' - state: - established: true - new: false - invalid: false - related: true - -populate: - - afi: 'ipv6' - rule_sets: - - name: 'UPLINK' - description: 'This is ipv6 specific rule-set' - default_action: 'accept' - rules: - - number: 1 - action: 'accept' - description: 'Fwipv6-Rule 1 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 2 - action: 'accept' - description: 'Fwipv6-Rule 2 is configured by Ansible' - ipsec: 'match-ipsec' - - - afi: 'ipv4' - rule_sets: - - name: 'INBOUND' - description: 'IPv4 INBOUND rule set' - default_action: 'accept' - rules: - - number: 101 - action: 'accept' - description: 'Rule 101 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 102 - action: 'reject' - description: 'Rule 102 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 103 - action: 'accept' - description: 'Rule 103 is configured by Ansible' - destination: - group: - address_group: 'inbound' - source: - address: '192.0.2.0' - state: - established: true - new: false - invalid: false - related: true - -replaced: - commands: - - "delete firewall ipv6-name UPLINK rule 1" - - "delete firewall ipv6-name UPLINK rule 2" - - "delete firewall name INBOUND rule 102" - - "delete firewall name INBOUND rule 103" - - "set firewall name INBOUND rule 104 action 'reject'" - - "set firewall name INBOUND rule 104 description 'Rule 104 is configured by Ansible'" - - "set firewall name INBOUND rule 104" - - "set firewall name INBOUND rule 104 ipsec 'match-none'" - - after: - - afi: 'ipv6' - rule_sets: - - name: 'UPLINK' - description: 'This is ipv6 specific rule-set' - default_action: 'accept' - - afi: 'ipv4' - rule_sets: - - name: 'INBOUND' - description: 'IPv4 INBOUND rule set' - default_action: 'accept' - rules: - - number: 101 - action: 'accept' - description: 'Rule 101 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 104 - action: 'reject' - description: 'Rule 104 is configured by Ansible' - ipsec: 'match-none' -overridden: - before: - - afi: 'ipv6' - rule_sets: - - name: 'UPLINK' - description: 'This is ipv6 specific rule-set' - default_action: 'accept' - - afi: 'ipv4' - rule_sets: - - name: 'INBOUND' - description: 'IPv4 INBOUND rule set' - default_action: 'accept' - rules: - - number: 101 - action: 'accept' - description: 'Rule 101 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 104 - action: 'reject' - description: 'Rule 104 is configured by Ansible' - ipsec: 'match-none' - commands: - - "delete firewall ipv6-name UPLINK" - - "delete firewall name INBOUND" - - "set firewall name Downlink default-action 'accept'" - - "set firewall name Downlink description 'IPv4 INBOUND rule set'" - - "set firewall name Downlink rule 501 action 'accept'" - - "set firewall name Downlink rule 501" - - "set firewall name Downlink rule 501 description 'Rule 501 is configured by Ansible'" - - "set firewall name Downlink rule 501 ipsec 'match-ipsec'" - - "set firewall name Downlink rule 502 action 'reject'" - - "set firewall name Downlink rule 502" - - "set firewall name Downlink rule 502 description 'Rule 502 is configured by Ansible'" - - "set firewall name Downlink rule 502 ipsec 'match-ipsec'" - - after: - - afi: 'ipv4' - rule_sets: - - name: 'Downlink' - description: 'IPv4 INBOUND rule set' - default_action: 'accept' - rules: - - number: 501 - action: 'accept' - description: 'Rule 501 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 502 - action: 'reject' - description: 'Rule 502 is configured by Ansible' - ipsec: 'match-ipsec' -rendered: - commands: - - "set firewall ipv6-name UPLINK default-action 'accept'" - - "set firewall ipv6-name UPLINK description 'This is ipv6 specific rule-set'" - - "set firewall name INBOUND default-action 'accept'" - - "set firewall name INBOUND description 'IPv4 INBOUND rule set'" - - "set firewall name INBOUND rule 101 action 'accept'" - - "set firewall name INBOUND rule 101" - - "set firewall name INBOUND rule 101 description 'Rule 101 is configured by Ansible'" - - "set firewall name INBOUND rule 101 ipsec 'match-ipsec'" - - "set firewall name INBOUND rule 102 action 'reject'" - - "set firewall name INBOUND rule 102" - - "set firewall name INBOUND rule 102 description 'Rule 102 is configured by Ansible'" - - "set firewall name INBOUND rule 102 ipsec 'match-ipsec'" - - "set firewall name INBOUND rule 103 description 'Rule 103 is configured by Ansible'" - - "set firewall name INBOUND rule 103 destination group address-group inbound" - - "set firewall name INBOUND rule 103" - - "set firewall name INBOUND rule 103 source address 192.0.2.0" - - "set firewall name INBOUND rule 103 state established enable" - - "set firewall name INBOUND rule 103 state related enable" - - "set firewall name INBOUND rule 103 state invalid disable" - - "set firewall name INBOUND rule 103 state new disable" - - "set firewall name INBOUND rule 103 action 'accept'" - -deleted_rs: - commands: - - "delete firewall ipv6-name UPLINK" - - "delete firewall name INBOUND" - - after: [] - -deleted_afi_all: - commands: - - "delete firewall ipv6-name" - - "delete firewall name" - - after: [] - -deleted_r: - commands: - - "delete firewall ipv6-name UPLINK rule 1" - - after: - - afi: 'ipv6' - rule_sets: - - name: 'UPLINK' - description: 'This is ipv6 specific rule-set' - default_action: 'accept' - rules: - - number: 2 - action: 'accept' - description: 'Fwipv6-Rule 2 is configured by Ansible' - ipsec: 'match-ipsec' - - - afi: 'ipv4' - rule_sets: - - name: 'INBOUND' - description: 'IPv4 INBOUND rule set' - default_action: 'accept' - rules: - - number: 101 - action: 'accept' - description: 'Rule 101 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 102 - action: 'reject' - description: 'Rule 102 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 103 - action: 'accept' - description: 'Rule 103 is configured by Ansible' - destination: - group: - address_group: 'inbound' - source: - address: '192.0.2.0' - state: - established: true - new: false - invalid: false - related: true - -round_trip: - after: - - afi: 'ipv6' - rule_sets: - - name: 'UPLINK' - description: 'This is ipv6 specific rule-set' - default_action: 'accept' - rules: - - number: 1 - action: 'accept' - description: 'Fwipv6-Rule 1 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 2 - action: 'accept' - description: 'Fwipv6-Rule 2 is configured by Ansible' - ipsec: 'match-ipsec' - - afi: 'ipv4' - rule_sets: - - name: 'INBOUND' - description: 'IPv4 INBOUND rule set' - default_action: 'accept' - rules: - - number: 101 - action: 'accept' - description: 'Rule 101 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 102 - action: 'reject' - description: 'Rule 102 is configured by Ansible' - ipsec: 'match-ipsec' - - number: 103 - action: 'accept' - description: 'Rule 103 is configured by Ansible' - source: - address: '192.0.2.0' - state: - established: true - new: false - invalid: false - related: true diff --git a/test/integration/targets/vyos_interface/defaults/main.yaml b/test/integration/targets/vyos_interface/defaults/main.yaml deleted file mode 100644 index 9ef5ba5165..0000000000 --- a/test/integration/targets/vyos_interface/defaults/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -testcase: "*" -test_items: [] diff --git a/test/integration/targets/vyos_interface/tasks/cli.yaml b/test/integration/targets/vyos_interface/tasks/cli.yaml deleted file mode 100644 index 890d3acf3e..0000000000 --- a/test/integration/targets/vyos_interface/tasks/cli.yaml +++ /dev/null @@ -1,22 +0,0 @@ ---- -- name: collect all cli test cases - find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - register: test_cases - delegate_to: localhost - -- name: set test_items - set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - -- name: run test case (connection=network_cli) - include: "{{ test_case_to_run }} ansible_connection=network_cli" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - -- name: run test case (connection=local) - include: "{{ test_case_to_run }} ansible_connection=local" - with_first_found: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run diff --git a/test/integration/targets/vyos_interface/tasks/main.yaml b/test/integration/targets/vyos_interface/tasks/main.yaml deleted file mode 100644 index d4cf26fc4a..0000000000 --- a/test/integration/targets/vyos_interface/tasks/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -- {include: cli.yaml, tags: ['cli']} diff --git a/test/integration/targets/vyos_interface/tests/cli/basic.yaml b/test/integration/targets/vyos_interface/tests/cli/basic.yaml deleted file mode 100644 index 9e1f9dc68a..0000000000 --- a/test/integration/targets/vyos_interface/tests/cli/basic.yaml +++ /dev/null @@ -1,220 +0,0 @@ ---- -- debug: msg="START cli/basic.yaml on connection={{ ansible_connection }}" - -- name: Run vyos lsmod command - vyos_command: - commands: - - lsmod - register: lsmod_out - -- name: Set up - delete interface - vyos_interface: - name: eth1 - state: absent - -- name: Set up - Create interface - vyos_interface: - name: eth1 - state: present - description: test-interface - register: result - -- assert: - that: - - 'result.changed == true' - - '"set interfaces ethernet eth1" in result.commands' - - '"set interfaces ethernet eth1 description ''test-interface''" in result.commands' - -- name: Configure interface params - vyos_interface: - name: eth1 - state: present - description: test-interface-1 - speed: 100 - duplex: half - mtu: 256 - when: "'virtio_net' not in lsmod_out.stdout[0]" - register: result - -- assert: - that: - - 'result.changed == true' - - '"set interfaces ethernet eth1 description ''test-interface-1''" in result.commands' - - '"set interfaces ethernet eth1 speed 100" in result.commands' - - '"set interfaces ethernet eth1 duplex half" in result.commands' - - '"set interfaces ethernet eth1 mtu 256" in result.commands' - when: "'virtio_net' not in lsmod_out.stdout[0]" - -- name: Configure interface params (idempotent) - vyos_interface: - name: eth1 - state: present - description: test-interface-1 - speed: 100 - duplex: half - mtu: 256 - register: result - when: "'virtio_net' not in lsmod_out.stdout[0]" - -- assert: - that: - - 'result.changed == false' - when: "'virtio' not in lsmod_out.stdout[0]" - -- name: Change interface params - vyos_interface: - name: eth1 - state: present - description: test-interface-2 - speed: 1000 - duplex: full - mtu: 512 - register: result - when: "'virtio_net' not in lsmod_out.stdout[0]" - -- assert: - that: - - 'result.changed == true' - - '"set interfaces ethernet eth1 description ''test-interface-2''" in result.commands' - - '"set interfaces ethernet eth1 speed 1000" in result.commands' - - '"set interfaces ethernet eth1 duplex full" in result.commands' - - '"set interfaces ethernet eth1 mtu 512" in result.commands' - when: "'virtio_net' not in lsmod_out.stdout[0]" - -- name: Disable interface - vyos_interface: - name: eth1 - enabled: false - register: result - -- assert: - that: - - 'result.changed == true' - - '"set interfaces ethernet eth1 disable" in result.commands' - -- name: Enable interface - vyos_interface: - name: eth1 - enabled: true - register: result - -- assert: - that: - - 'result.changed == true' - - '"delete interfaces ethernet eth1 disable" in result.commands' - -- name: Delete interface - vyos_interface: - name: eth1 - state: absent - register: result - -- assert: - that: - - 'result.changed == true' - - '"delete interfaces ethernet eth1" in result.commands' - -- name: Delete interface (idempotent) - vyos_interface: - name: eth1 - state: absent - register: result - -- assert: - that: - - 'result.changed == false' - -- name: Aggregate setup- delete interface - vyos_interface: - name: eth2 - state: absent - register: result - -- name: Set interface on aggregate - vyos_interface: - aggregate: - - {name: eth1, description: test-interface-1, speed: 100, duplex: half, mtu: 512} - - {name: eth2, description: test-interface-2, speed: 1000, duplex: full, mtu: 256} - register: result - when: "'virtio_net' not in lsmod_out.stdout[0]" - -- assert: - that: - - 'result.changed == true' - - '"set interfaces ethernet eth1 description ''test-interface-1''" in result.commands' - - '"set interfaces ethernet eth1 speed 100" in result.commands' - - '"set interfaces ethernet eth1 duplex half" in result.commands' - - '"set interfaces ethernet eth1 mtu 512" in result.commands' - - '"set interfaces ethernet eth2 description ''test-interface-2''" in result.commands' - - '"set interfaces ethernet eth2 speed 1000" in result.commands' - - '"set interfaces ethernet eth2 duplex full" in result.commands' - - '"set interfaces ethernet eth2 mtu 256" in result.commands' - when: "'virtio_net' not in lsmod_out.stdout[0]" - -- name: Set interface on aggregate (idempotent) - vyos_interface: - aggregate: - - {name: eth1, description: test-interface-1, speed: 100, duplex: half, mtu: 512} - - {name: eth2, description: test-interface-2, speed: 1000, duplex: full, mtu: 256} - register: result - when: "'virtio_net' not in lsmod_out.stdout[0]" - -- assert: - that: - - 'result.changed == false' - when: "'virtio_net' not in lsmod_out.stdout[0]" - -- name: Disable interface on aggregate - vyos_interface: - aggregate: - - name: eth1 - - name: eth2 - description: test-interface - enabled: false - register: result - -- assert: - that: - - 'result.changed == true' - - '"set interfaces ethernet eth1 disable" in result.commands' - - '"set interfaces ethernet eth2 disable" in result.commands' - -- name: Enable interface on aggregate - vyos_interface: - aggregate: - - name: eth1 - - name: eth2 - enabled: true - register: result - -- assert: - that: - - 'result.changed == true' - - '"delete interfaces ethernet eth1 disable" in result.commands' - - '"delete interfaces ethernet eth2 disable" in result.commands' - -- name: Delete interface aggregate - vyos_interface: - aggregate: - - name: eth1 - - name: eth2 - state: absent - register: result - -- assert: - that: - - 'result.changed == true' - - '"delete interfaces ethernet eth1" in result.commands' - - '"delete interfaces ethernet eth2" in result.commands' - -- name: Delete interface aggregate (idempotent) - vyos_interface: - aggregate: - - name: eth1 - - name: eth2 - state: absent - register: result - -- assert: - that: - - 'result.changed == false' diff --git a/test/integration/targets/vyos_interface/tests/cli/intent.yaml b/test/integration/targets/vyos_interface/tests/cli/intent.yaml deleted file mode 100644 index f355255931..0000000000 --- a/test/integration/targets/vyos_interface/tests/cli/intent.yaml +++ /dev/null @@ -1,157 +0,0 @@ ---- -- debug: msg="START cli/intent.yaml on connection={{ ansible_connection }}" - -# To be able to run the lldp test we need to have a neighbor configured to talk to -# In DCI & Zuul we (currently) only spin up a single network VM, so we can't configure a neighbor -# In the future when we have multi-network-nodes running we can run these tests again -# https://github.com/ansible/ansible/issues/39667 - -- name: Detect if we have existing lldp neighbors configured - vyos_command: - commands: - - show lldp neighbors detail - register: neighbors_out - -- name: Should we run lldp tests? - set_fact: - run_lldp_tests: "'PortDescr: eth0' in neighbors_out.stdout[0]" - -- name: Enable LLDP service - vyos_lldp: - state: present - when: run_lldp_tests - -- name: Create LLDP configuration - vyos_lldp_interface: - name: eth1 - state: present - when: run_lldp_tests - -- name: Setup (interface is up) - vyos_interface: - name: eth1 - enabled: true - state: present - register: result - -- name: Check intent arguments - vyos_interface: - name: eth1 - state: up - register: result - -- assert: - that: - - "result.failed == false" - -- name: Check lldp neighbors intent arguments - vyos_interface: - name: eth0 - neighbors: - - port: eth0 - when: run_lldp_tests - register: result - -- assert: - that: - - "result.failed == false" - when: run_lldp_tests - -- name: Check intent arguments (failed condition) - vyos_interface: - name: eth1 - state: down - ignore_errors: true - register: result - -- assert: - that: - - "result.failed == true" - - "'state eq(down)' in result.failed_conditions" - -- name: Check lldp neighbors intent arguments (failed) - vyos_interface: - name: eth0 - neighbors: - - port: dummy_port - host: dummy_host - ignore_errors: true - when: run_lldp_tests - register: result - -- assert: - that: - - "result.failed == true" - - "'host dummy_host' in result.failed_conditions" - - "'port dummy_port' in result.failed_conditions" - when: run_lldp_tests - -- name: Config + intent - vyos_interface: - name: eth1 - enabled: false - state: down - register: result - -- assert: - that: - - "result.failed == false" - -- name: Config + intent (fail) - vyos_interface: - name: eth1 - enabled: false - state: up - ignore_errors: true - register: result - -- assert: - that: - - "result.failed == true" - - "'state eq(up)' in result.failed_conditions" - -- name: Aggregate config + intent (pass) - vyos_interface: - aggregate: - - name: eth1 - enabled: true - state: up - ignore_errors: true - register: result - -- assert: - that: - - "result.failed == false" - -- name: Check lldp neighbors intent aggregate arguments - vyos_interface: - aggregate: - - name: eth0 - neighbors: - - port: eth0 - when: run_lldp_tests - register: result - -- assert: - that: - - "result.failed == false" - when: run_lldp_tests - -- name: Check lldp neighbors intent aggregate arguments (failed) - vyos_interface: - aggregate: - - name: eth0 - neighbors: - - port: eth0 - - port: dummy_port - host: dummy_host - ignore_errors: true - when: run_lldp_tests - register: result - -- assert: - that: - - "result.failed == true" - - "'host dummy_host' in result.failed_conditions" - - "'port dummy_port' in result.failed_conditions" - when: run_lldp_tests diff --git a/test/integration/targets/vyos_interface/tests/cli/net_interface.yaml b/test/integration/targets/vyos_interface/tests/cli/net_interface.yaml deleted file mode 100644 index ced273d5f5..0000000000 --- a/test/integration/targets/vyos_interface/tests/cli/net_interface.yaml +++ /dev/null @@ -1,56 +0,0 @@ ---- -- debug: msg="START vyos cli/net_interface.yaml on connection={{ ansible_connection }}" - -# Add minimal testcase to check args are passed correctly to -# implementation module and module run is successful. - -- name: Run vyos lsmod command - vyos_command: - commands: - - lsmod - register: lsmod_out - -- name: Set up - delete interface - net_interface: - name: eth1 - state: absent - -- name: Create interface using platform agnostic module - net_interface: - name: eth1 - state: present - description: test-interface - register: result - -- assert: - that: - - 'result.changed == true' - - '"set interfaces ethernet eth1" in result.commands' - - '"set interfaces ethernet eth1 description ''test-interface''" in result.commands' - -- name: Configure interface params using platform agnostic module - net_interface: - name: eth1 - state: present - description: test-interface-1 - speed: 100 - duplex: half - mtu: 256 - when: "'virtio_net' not in lsmod_out.stdout[0]" - register: result - -- assert: - that: - - 'result.changed == true' - - '"set interfaces ethernet eth1 description ''test-interface-1''" in result.commands' - - '"set interfaces ethernet eth1 speed 100" in result.commands' - - '"set interfaces ethernet eth1 duplex half" in result.commands' - - '"set interfaces ethernet eth1 mtu 256" in result.commands' - when: "'virtio_net' not in lsmod_out.stdout[0]" - -- name: teardown - delete interface - net_interface: - name: eth1 - state: absent - -- debug: msg="END vyos cli/net_interface.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/vyos_interfaces/defaults/main.yaml b/test/integration/targets/vyos_interfaces/defaults/main.yaml deleted file mode 100644 index 164afead28..0000000000 --- a/test/integration/targets/vyos_interfaces/defaults/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -testcase: "[^_].*" -test_items: [] diff --git a/test/integration/targets/vyos_interfaces/meta/main.yaml b/test/integration/targets/vyos_interfaces/meta/main.yaml deleted file mode 100644 index 7413320e48..0000000000 --- a/test/integration/targets/vyos_interfaces/meta/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dependencies: - - prepare_vyos_tests diff --git a/test/integration/targets/vyos_interfaces/tasks/cli.yaml b/test/integration/targets/vyos_interfaces/tasks/cli.yaml deleted file mode 100644 index 655e51ee63..0000000000 --- a/test/integration/targets/vyos_interfaces/tasks/cli.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -- name: Collect all cli test cases - find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - use_regex: true - register: test_cases - delegate_to: localhost - -- name: Set test_items - set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test case (connection=network_cli) - include: "{{ test_case_to_run }}" - vars: - ansible_connection: network_cli - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run diff --git a/test/integration/targets/vyos_interfaces/tasks/main.yaml b/test/integration/targets/vyos_interfaces/tasks/main.yaml deleted file mode 100644 index d4cf26fc4a..0000000000 --- a/test/integration/targets/vyos_interfaces/tasks/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -- {include: cli.yaml, tags: ['cli']} diff --git a/test/integration/targets/vyos_interfaces/tests/cli/_populate.yaml b/test/integration/targets/vyos_interfaces/tests/cli/_populate.yaml deleted file mode 100644 index 7dcab364a7..0000000000 --- a/test/integration/targets/vyos_interfaces/tests/cli/_populate.yaml +++ /dev/null @@ -1,17 +0,0 @@ ---- -- name: Setup - cli_config: - config: "{{ lines }}" - vars: - lines: | - set interfaces ethernet "{{ intf }}" description 'Configured by Ansible' - set interfaces ethernet "{{ intf }}" speed 'auto' - set interfaces ethernet "{{ intf }}" duplex 'auto' - set interfaces ethernet "{{ intf }}" mtu '1500' - set interfaces ethernet "{{ intf }}" vif 200 - set interfaces ethernet "{{ intf }}" vif 200 description 'VIF - 200' - loop: - - eth1 - - eth2 - loop_control: - loop_var: intf diff --git a/test/integration/targets/vyos_interfaces/tests/cli/_remove_config.yaml b/test/integration/targets/vyos_interfaces/tests/cli/_remove_config.yaml deleted file mode 100644 index c9329c0df5..0000000000 --- a/test/integration/targets/vyos_interfaces/tests/cli/_remove_config.yaml +++ /dev/null @@ -1,17 +0,0 @@ ---- -- name: Remove Config - cli_config: - config: "{{ lines }}" - vars: - lines: | - delete interfaces ethernet "{{ intf }}" description - delete interfaces ethernet "{{ intf }}" speed - delete interfaces ethernet "{{ intf }}" duplex - delete interfaces ethernet "{{ intf }}" mtu - delete interfaces ethernet "{{ intf }}" disable - delete interfaces ethernet "{{ intf }}" vif - loop: - - eth1 - - eth2 - loop_control: - loop_var: intf diff --git a/test/integration/targets/vyos_interfaces/tests/cli/deleted.yaml b/test/integration/targets/vyos_interfaces/tests/cli/deleted.yaml deleted file mode 100644 index 69e8705476..0000000000 --- a/test/integration/targets/vyos_interfaces/tests/cli/deleted.yaml +++ /dev/null @@ -1,46 +0,0 @@ ---- -- debug: - msg: "Start vyos_interfaces deleted integration tests ansible_connection={{ ansible_connection }}" - -- include_tasks: _populate.yaml - -- block: - - name: Delete attributes of given interfaces - vyos_interfaces: &deleted - config: - - name: eth1 - - name: eth2 - state: deleted - register: result - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that the correct set of commands were generated - assert: - that: - - "{{ deleted['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that the after dicts were correctly generated - assert: - that: - - "{{ deleted['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Delete attributes of given interfaces (IDEMPOTENT) - vyos_interfaces: *deleted - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result.changed == false" - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ deleted['after'] | symmetric_difference(result['before']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_interfaces/tests/cli/empty_config.yaml b/test/integration/targets/vyos_interfaces/tests/cli/empty_config.yaml deleted file mode 100644 index ae9b5acf23..0000000000 --- a/test/integration/targets/vyos_interfaces/tests/cli/empty_config.yaml +++ /dev/null @@ -1,36 +0,0 @@ ---- -- debug: - msg: "START vyos_interfaces empty_config integration tests on connection={{ ansible_connection }}" - -- name: Merged with empty config should give appropriate error message - vyos_interfaces: - config: - state: merged - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state merged' - -- name: Replaced with empty config should give appropriate error message - vyos_interfaces: - config: - state: replaced - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state replaced' - -- name: Overridden with empty config should give appropriate error message - vyos_interfaces: - config: - state: overridden - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state overridden' diff --git a/test/integration/targets/vyos_interfaces/tests/cli/merged.yaml b/test/integration/targets/vyos_interfaces/tests/cli/merged.yaml deleted file mode 100644 index 5b2dd81a0c..0000000000 --- a/test/integration/targets/vyos_interfaces/tests/cli/merged.yaml +++ /dev/null @@ -1,59 +0,0 @@ ---- -- debug: - msg: "START vyos_interfaces merged integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- block: - - name: Merge the provided configuration with the exisiting running configuration - vyos_interfaces: &merged - config: - - name: eth1 - description: "Configured by Ansible - Interface 1" - mtu: 1500 - speed: auto - duplex: auto - vifs: - - vlan_id: 100 - description: "Eth1 - VIF 100" - mtu: 400 - - - vlan_id: 101 - description: "Eth1 - VIF 101" - - - name: eth2 - description: "Configured by Ansible - Interface 2 (ADMIN DOWN)" - mtu: 600 - enabled: false - state: merged - register: result - - - name: Assert that before dicts were correctly generated - assert: - that: "{{ merged['before'] | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that correct set of commands were generated - assert: - that: - - "{{ merged['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that after dicts was correctly generated - assert: - that: - - "{{ merged['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) - vyos_interfaces: *merged - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - - - name: Assert that before dicts were correctly generated - assert: - that: - - "{{ merged['after'] | symmetric_difference(result['before']) |length == 0 }}" - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_interfaces/tests/cli/overridden.yaml b/test/integration/targets/vyos_interfaces/tests/cli/overridden.yaml deleted file mode 100644 index e79ff8ed57..0000000000 --- a/test/integration/targets/vyos_interfaces/tests/cli/overridden.yaml +++ /dev/null @@ -1,52 +0,0 @@ ---- -- debug: - msg: "START vyos_interfaces overridden integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Overrides all device configuration with provided configuration - vyos_interfaces: &overridden - config: - - name: eth0 - speed: "auto" - duplex: "auto" - - name: eth2 - description: "Overridden by Ansible" - mtu: 1200 - state: overridden - register: result - - - name: Assert that before dicts were correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that correct commands were generated - assert: - that: - - "{{ overridden['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that after dicts were correctly generated - assert: - that: - - "{{ overridden['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Overrides all device configuration with provided configurations (IDEMPOTENT) - vyos_interfaces: *overridden - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - - - name: Assert that before dicts were correctly generated - assert: - that: - - "{{ overridden['after'] | symmetric_difference(result['before']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_interfaces/tests/cli/replaced.yaml b/test/integration/targets/vyos_interfaces/tests/cli/replaced.yaml deleted file mode 100644 index d38e6b6b8d..0000000000 --- a/test/integration/targets/vyos_interfaces/tests/cli/replaced.yaml +++ /dev/null @@ -1,55 +0,0 @@ ---- -- debug: - msg: "START vyos_interfaces replaced integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Replace device configurations of listed interfaces with provided configurations - vyos_interfaces: &replaced - config: - - name: eth1 - description: "Replaced by Ansible" - vifs: - - vlan_id: 100 - description: "VIF 100 - Replaced by Ansible" - - - name: eth2 - mtu: 1400 - description: "Replaced by Ansible" - state: replaced - register: result - - - name: Assert that correct set of commands were generated - assert: - that: - - "{{ replaced['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that before dicts are correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that after dict is correctly generated - assert: - that: - - "{{ replaced['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Replace device configurations of listed interfaces with provided configurarions (IDEMPOTENT) - vyos_interfaces: *replaced - register: result - - - name: Assert that task was idempotent - assert: - that: - - "result['changed'] == false" - - - name: Assert that before dict is correctly generated - assert: - that: - - "{{ replaced['after'] | symmetric_difference(result['before']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_interfaces/tests/cli/rtt.yaml b/test/integration/targets/vyos_interfaces/tests/cli/rtt.yaml deleted file mode 100644 index 2b5ee9de8d..0000000000 --- a/test/integration/targets/vyos_interfaces/tests/cli/rtt.yaml +++ /dev/null @@ -1,78 +0,0 @@ ---- -- debug: - msg: "START vyos_interfaces round trip integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- block: - - name: Apply the provided configuration (base config) - vyos_interfaces: - config: - - name: eth0 - enabled: true - duplex: "auto" - speed: "auto" - - - name: eth1 - description: "Interface - 1" - mtu: 1500 - vifs: - - vlan_id: 100 - description: "Eth1 - VIF 100" - mtu: 200 - - - vlan_id: 101 - enabled: false - - - name: eth2 - description: "Interface - 2" - enabled: true - mtu: 900 - state: merged - register: base_config - - - name: Gather interfaces facts - vyos_facts: - gather_subset: - - default - gather_network_resources: - - interfaces - - - name: Apply the provided configuration (config to be reverted) - vyos_interfaces: - config: - - name: eth1 - description: "Interface 1 - Description (WILL BE REVERTED)" - mtu: 1200 - vifs: - - vlan_id: 100 - description: "Eth1 - VIF 100 (WILL BE REVERTED)" - mtu: 400 - - - vlan_id: 101 - description: "Eth1 - VIF 101 (WILL BE REMOVED)" - enabled: true - - - name: eth2 - description: "Interface 2 (ADMIN DOWN) (WILL BE REVERTED)" - mtu: 600 - enabled: false - state: merged - register: result - - - name: Assert that changes were applied - assert: - that: "{{ round_trip['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Revert back to base config using facts round trip - vyos_interfaces: - config: "{{ ansible_facts['network_resources']['interfaces'] }}" - state: replaced - register: revert - - - name: Assert that config was reverted - assert: - that: "{{ base_config['after'] | symmetric_difference(revert['after']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_interfaces/vars/main.yaml b/test/integration/targets/vyos_interfaces/vars/main.yaml deleted file mode 100644 index b973752289..0000000000 --- a/test/integration/targets/vyos_interfaces/vars/main.yaml +++ /dev/null @@ -1,209 +0,0 @@ ---- -merged: - before: - - name: "eth0" - enabled: true - speed: "auto" - duplex: "auto" - - - name: "eth1" - enabled: true - - - name: "eth2" - enabled: true - - commands: - - "set interfaces ethernet eth1 description 'Configured by Ansible - Interface 1'" - - "set interfaces ethernet eth1 mtu '1500'" - - "set interfaces ethernet eth1 duplex 'auto'" - - "set interfaces ethernet eth1 speed 'auto'" - - "set interfaces ethernet eth1 vif 100 description 'Eth1 - VIF 100'" - - "set interfaces ethernet eth1 vif 100 mtu '400'" - - "set interfaces ethernet eth1 vif 101 description 'Eth1 - VIF 101'" - - "set interfaces ethernet eth2 description 'Configured by Ansible - Interface 2 (ADMIN DOWN)'" - - "set interfaces ethernet eth2 mtu '600'" - - "set interfaces ethernet eth2 disable" - - after: - - name: "eth0" - enabled: true - duplex: "auto" - speed: "auto" - - - name: "eth1" - description: "Configured by Ansible - Interface 1" - mtu: 1500 - speed: "auto" - duplex: "auto" - enabled: true - vifs: - - vlan_id: 100 - description: "Eth1 - VIF 100" - mtu: 400 - enabled: true - - - vlan_id: 101 - description: "Eth1 - VIF 101" - enabled: true - - - name: "eth2" - description: "Configured by Ansible - Interface 2 (ADMIN DOWN)" - mtu: 600 - enabled: false - -populate: - - name: "eth1" - enabled: true - speed: "auto" - duplex: "auto" - description: "Configured by Ansible" - mtu: 1500 - vifs: - - vlan_id: 200 - enabled: true - description: "VIF - 200" - - - name: "eth2" - enabled: true - speed: "auto" - duplex: "auto" - description: "Configured by Ansible" - mtu: 1500 - vifs: - - vlan_id: 200 - enabled: true - description: "VIF - 200" - - - name: "eth0" - enabled: true - duplex: "auto" - speed: "auto" - -replaced: - commands: - - "delete interfaces ethernet eth1 mtu" - - "delete interfaces ethernet eth1 speed" - - "delete interfaces ethernet eth1 duplex" - - "delete interfaces ethernet eth1 vif 200 description" - - "set interfaces ethernet eth1 description 'Replaced by Ansible'" - - "set interfaces ethernet eth1 vif 100 description 'VIF 100 - Replaced by Ansible'" - - "delete interfaces ethernet eth2 speed" - - "delete interfaces ethernet eth2 duplex" - - "delete interfaces ethernet eth2 vif 200 description" - - "set interfaces ethernet eth2 description 'Replaced by Ansible'" - - "set interfaces ethernet eth2 mtu '1400'" - - after: - - name: "eth1" - description: "Replaced by Ansible" - enabled: true - vifs: - - vlan_id: 100 - enabled: true - description: "VIF 100 - Replaced by Ansible" - - - vlan_id: 200 - enabled: true - - - name: "eth2" - mtu: 1400 - description: "Replaced by Ansible" - enabled: true - vifs: - - vlan_id: 200 - enabled: true - - - name: "eth0" - enabled: true - duplex: "auto" - speed: "auto" - -overridden: - commands: - - "delete interfaces ethernet eth1 description" - - "delete interfaces ethernet eth1 speed" - - "delete interfaces ethernet eth1 duplex" - - "delete interfaces ethernet eth1 mtu" - - "delete interfaces ethernet eth1 vif 200 description" - - "delete interfaces ethernet eth2 speed" - - "delete interfaces ethernet eth2 duplex" - - "delete interfaces ethernet eth2 vif 200 description" - - "set interfaces ethernet eth2 description 'Overridden by Ansible'" - - "set interfaces ethernet eth2 mtu '1200'" - - after: - - name: "eth0" - enabled: true - speed: "auto" - duplex: "auto" - - - name: "eth1" - enabled: true - vifs: - - vlan_id: 200 - enabled: true - - - name: "eth2" - enabled: true - description: "Overridden by Ansible" - mtu: 1200 - vifs: - - vlan_id: 200 - enabled: true - -deleted: - commands: - - "delete interfaces ethernet eth1 description" - - "delete interfaces ethernet eth1 speed" - - "delete interfaces ethernet eth1 duplex" - - "delete interfaces ethernet eth1 mtu" - - "delete interfaces ethernet eth1 vif 200 description" - - "delete interfaces ethernet eth2 description" - - "delete interfaces ethernet eth2 speed" - - "delete interfaces ethernet eth2 duplex" - - "delete interfaces ethernet eth2 mtu" - - "delete interfaces ethernet eth2 vif 200 description" - - after: - - name: "eth0" - enabled: true - speed: "auto" - duplex: "auto" - - - name: "eth1" - enabled: true - vifs: - - vlan_id: 200 - enabled: true - - - name: "eth2" - enabled: true - vifs: - - vlan_id: 200 - enabled: true - -round_trip: - after: - - name: "eth0" - enabled: true - speed: "auto" - duplex: "auto" - - - name: "eth1" - description: "Interface 1 - Description (WILL BE REVERTED)" - enabled: true - mtu: 1200 - vifs: - - vlan_id: 100 - description: "Eth1 - VIF 100 (WILL BE REVERTED)" - mtu: 400 - enabled: true - - - vlan_id: 101 - description: "Eth1 - VIF 101 (WILL BE REMOVED)" - enabled: true - - - name: "eth2" - description: "Interface 2 (ADMIN DOWN) (WILL BE REVERTED)" - mtu: 600 - enabled: false diff --git a/test/integration/targets/vyos_l3_interface/defaults/main.yaml b/test/integration/targets/vyos_l3_interface/defaults/main.yaml deleted file mode 100644 index 9ef5ba5165..0000000000 --- a/test/integration/targets/vyos_l3_interface/defaults/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -testcase: "*" -test_items: [] diff --git a/test/integration/targets/vyos_l3_interface/tasks/cli.yaml b/test/integration/targets/vyos_l3_interface/tasks/cli.yaml deleted file mode 100644 index 890d3acf3e..0000000000 --- a/test/integration/targets/vyos_l3_interface/tasks/cli.yaml +++ /dev/null @@ -1,22 +0,0 @@ ---- -- name: collect all cli test cases - find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - register: test_cases - delegate_to: localhost - -- name: set test_items - set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - -- name: run test case (connection=network_cli) - include: "{{ test_case_to_run }} ansible_connection=network_cli" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - -- name: run test case (connection=local) - include: "{{ test_case_to_run }} ansible_connection=local" - with_first_found: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run diff --git a/test/integration/targets/vyos_l3_interface/tasks/main.yaml b/test/integration/targets/vyos_l3_interface/tasks/main.yaml deleted file mode 100644 index d4cf26fc4a..0000000000 --- a/test/integration/targets/vyos_l3_interface/tasks/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -- {include: cli.yaml, tags: ['cli']} diff --git a/test/integration/targets/vyos_l3_interface/tests/cli/basic.yaml b/test/integration/targets/vyos_l3_interface/tests/cli/basic.yaml deleted file mode 100644 index 4eac2abe56..0000000000 --- a/test/integration/targets/vyos_l3_interface/tests/cli/basic.yaml +++ /dev/null @@ -1,203 +0,0 @@ ---- -- debug: msg="START cli/basic.yaml on connection={{ ansible_connection }}" - -- name: Remove IP address - vyos_l3_interface: - name: eth1 - state: absent - -- name: Remove IP address - vyos_l3_interface: - name: eth2 - state: absent - -- name: Set IPv4 address - vyos_l3_interface: - name: eth1 - ipv4: 192.168.2.10/24 - register: result - -- assert: - that: - - 'result.changed == true' - - '"set interfaces ethernet eth1 address 192.168.2.10/24" in result.commands' - -- name: Set IPv4 address (idempotent) - vyos_l3_interface: - name: eth1 - ipv4: 192.168.2.10/24 - register: result - -- assert: - that: - - 'result.changed == false' - -- name: Set IPv6 address - vyos_l3_interface: - name: eth1 - ipv6: fd5d:12c9:2201:1::1/64 - register: result - -- assert: - that: - - 'result.changed == true' - - '"set interfaces ethernet eth1 address fd5d:12c9:2201:1::1/64" in result.commands' - -- name: Set IPv6 address (idempotent) - vyos_l3_interface: - name: eth1 - ipv6: fd5d:12c9:2201:1::1/64 - register: result - -- assert: - that: - - 'result.changed == false' - -- name: Remove all IP addresses - vyos_l3_interface: - name: eth1 - state: absent - register: result - -- assert: - that: - - 'result.changed == true' - - '"delete interfaces ethernet eth1 address" in result.commands' - -- name: Remove all IP addresses again (idempotent) - vyos_l3_interface: - name: eth1 - state: absent - register: result - -- assert: - that: - - 'result.changed == false' - -- name: Set IPv4 and IPv6 address - vyos_l3_interface: - name: eth1 - ipv4: 192.168.2.10/24 - ipv6: fd5d:12c9:2201:1::1/64 - register: result - -- assert: - that: - - 'result.changed == true' - - '"set interfaces ethernet eth1 address 192.168.2.10/24" in result.commands' - - '"set interfaces ethernet eth1 address fd5d:12c9:2201:1::1/64" in result.commands' - -- name: Set IPv4 and IPv6 address again (idempotent) - vyos_l3_interface: - name: eth1 - ipv4: 192.168.2.10/24 - ipv6: fd5d:12c9:2201:1::1/64 - register: result - -- assert: - that: - - 'result.changed == false' - -- name: Remove IPv4 address - vyos_l3_interface: - name: eth1 - ipv4: 192.168.2.10/24 - state: absent - register: result - -- assert: - that: - - 'result.changed == true' - - '"delete interfaces ethernet eth1 address 192.168.2.10/24" in result.commands' - -- name: Remove IPv4 address again (idempotent) - vyos_l3_interface: - name: eth1 - ipv4: 192.168.2.10/24 - state: absent - register: result - -- assert: - that: - - 'result.changed == false' - -- name: Remove IPv6 address - vyos_l3_interface: - name: eth1 - ipv6: fd5d:12c9:2201:1::1/64 - state: absent - register: result - -- assert: - that: - - 'result.changed == true' - - '"delete interfaces ethernet eth1 address fd5d:12c9:2201:1::1/64" in result.commands' - -- name: Remove IPv6 address again (idempotent) - vyos_l3_interface: - name: eth1 - ipv6: fd5d:12c9:2201:1::1/64 - state: absent - register: result - -- assert: - that: - - 'result.changed == false' - -- name: Set IP addresses on aggregate - vyos_l3_interface: - aggregate: - - {name: eth1, ipv4: 192.168.2.10/24} - - {name: eth2, ipv4: 192.168.3.10/24, ipv6: "fd5d:12c9:2201:1::1/64"} - - {name: eth2, ipv4: 192.168.4.10/24} - register: result - -- assert: - that: - - 'result.changed == true' - - '"set interfaces ethernet eth1 address 192.168.2.10/24" in result.commands' - - '"set interfaces ethernet eth2 address 192.168.3.10/24" in result.commands' - - '"set interfaces ethernet eth2 address fd5d:12c9:2201:1::1/64" in result.commands' - - '"set interfaces ethernet eth2 address 192.168.4.10/24" in result.commands' - -- name: Set IP addresses on aggregate (idempotent) - vyos_l3_interface: - aggregate: - - {name: eth1, ipv4: 192.168.2.10/24} - - {name: eth2, ipv4: 192.168.3.10/24, ipv6: "fd5d:12c9:2201:1::1/64"} - - {name: eth2, ipv4: 192.168.4.10/24} - register: result - -- assert: - that: - - 'result.changed == false' - -- name: Remove IP addresses on aggregate - vyos_l3_interface: - aggregate: - - {name: eth1, ipv4: 192.168.2.10/24} - - {name: eth2, ipv4: 192.168.3.10/24, ipv6: "fd5d:12c9:2201:1::1/64"} - - {name: eth2, ipv4: 192.168.4.10/24} - state: absent - register: result - -- assert: - that: - - 'result.changed == true' - - '"delete interfaces ethernet eth1 address 192.168.2.10/24" in result.commands' - - '"delete interfaces ethernet eth2 address 192.168.3.10/24" in result.commands' - - '"delete interfaces ethernet eth2 address fd5d:12c9:2201:1::1/64" in result.commands' - - '"delete interfaces ethernet eth2 address 192.168.4.10/24" in result.commands' - -- name: Remove IP addresses on aggregate (idempotent) - vyos_l3_interface: - aggregate: - - {name: eth1, ipv4: 192.168.2.10/24} - - {name: eth2, ipv4: 192.168.3.10/24, ipv6: "fd5d:12c9:2201:1::1/64"} - - {name: eth2, ipv4: 192.168.4.10/24} - state: absent - register: result - -- assert: - that: - - 'result.changed == false' diff --git a/test/integration/targets/vyos_l3_interfaces/defaults/main.yaml b/test/integration/targets/vyos_l3_interfaces/defaults/main.yaml deleted file mode 100644 index 164afead28..0000000000 --- a/test/integration/targets/vyos_l3_interfaces/defaults/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -testcase: "[^_].*" -test_items: [] diff --git a/test/integration/targets/vyos_l3_interfaces/meta/main.yml b/test/integration/targets/vyos_l3_interfaces/meta/main.yml deleted file mode 100644 index 7413320e48..0000000000 --- a/test/integration/targets/vyos_l3_interfaces/meta/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dependencies: - - prepare_vyos_tests diff --git a/test/integration/targets/vyos_l3_interfaces/tasks/cli.yaml b/test/integration/targets/vyos_l3_interfaces/tasks/cli.yaml deleted file mode 100644 index 337e34133b..0000000000 --- a/test/integration/targets/vyos_l3_interfaces/tasks/cli.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -- name: Collect all cli test cases - find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - use_regex: true - register: test_cases - delegate_to: localhost - -- name: Set test_items - set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - delegate_to: localhost - -- name: Run test case (connection=network_cli) - include: "{{ test_case_to_run }}" - vars: - ansible_connection: network_cli - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run diff --git a/test/integration/targets/vyos_l3_interfaces/tasks/main.yaml b/test/integration/targets/vyos_l3_interfaces/tasks/main.yaml deleted file mode 100644 index d4cf26fc4a..0000000000 --- a/test/integration/targets/vyos_l3_interfaces/tasks/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -- {include: cli.yaml, tags: ['cli']} diff --git a/test/integration/targets/vyos_l3_interfaces/tests/cli/_populate.yaml b/test/integration/targets/vyos_l3_interfaces/tests/cli/_populate.yaml deleted file mode 100644 index d253bd1438..0000000000 --- a/test/integration/targets/vyos_l3_interfaces/tests/cli/_populate.yaml +++ /dev/null @@ -1,11 +0,0 @@ ---- -- name: Setup - cli_config: - config: "{{ lines }}" - vars: - lines: | - set interfaces ethernet eth1 address '192.0.2.14/24' - set interfaces ethernet eth2 address '192.0.2.10/24' - set interfaces ethernet eth2 address '192.0.2.11/24' - set interfaces ethernet eth2 address '2001:db8::10/32' - set interfaces ethernet eth2 address '2001:db8::12/32' diff --git a/test/integration/targets/vyos_l3_interfaces/tests/cli/_remove_config.yaml b/test/integration/targets/vyos_l3_interfaces/tests/cli/_remove_config.yaml deleted file mode 100644 index 31af5ba961..0000000000 --- a/test/integration/targets/vyos_l3_interfaces/tests/cli/_remove_config.yaml +++ /dev/null @@ -1,13 +0,0 @@ ---- -- name: Remove Config - cli_config: - config: "{{ lines }}" - vars: - lines: | - delete interfaces ethernet "{{ intf }}" address - delete interfaces ethernet "{{ intf }}" vif - loop: - - eth1 - - eth2 - loop_control: - loop_var: intf diff --git a/test/integration/targets/vyos_l3_interfaces/tests/cli/deleted.yaml b/test/integration/targets/vyos_l3_interfaces/tests/cli/deleted.yaml deleted file mode 100644 index 568e05b50c..0000000000 --- a/test/integration/targets/vyos_l3_interfaces/tests/cli/deleted.yaml +++ /dev/null @@ -1,48 +0,0 @@ ---- -- debug: - msg: "Start vyos_interfaces deleted integration tests ansible_connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- block: - - include_tasks: _populate.yaml - - - name: Delete attributes of given interfaces - vyos_l3_interfaces: &deleted - config: - - name: eth1 - - name: eth2 - state: deleted - register: result - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that the correct set of commands were generated - assert: - that: - - "{{ deleted['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that the after dicts were correctly generated - assert: - that: - - "{{ deleted['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Delete attributes of given interfaces (IDEMPOTENT) - vyos_l3_interfaces: *deleted - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result.changed == false" - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ deleted['after'] | symmetric_difference(result['before']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_l3_interfaces/tests/cli/empty_config.yaml b/test/integration/targets/vyos_l3_interfaces/tests/cli/empty_config.yaml deleted file mode 100644 index 4859dca2ec..0000000000 --- a/test/integration/targets/vyos_l3_interfaces/tests/cli/empty_config.yaml +++ /dev/null @@ -1,36 +0,0 @@ ---- -- debug: - msg: "START vyos_l3_interfaces empty_config integration tests on connection={{ ansible_connection }}" - -- name: Merged with empty config should give appropriate error message - vyos_l3_interfaces: - config: - state: merged - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state merged' - -- name: Replaced with empty config should give appropriate error message - vyos_l3_interfaces: - config: - state: replaced - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state replaced' - -- name: Overridden with empty config should give appropriate error message - vyos_l3_interfaces: - config: - state: overridden - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state overridden' diff --git a/test/integration/targets/vyos_l3_interfaces/tests/cli/merged.yaml b/test/integration/targets/vyos_l3_interfaces/tests/cli/merged.yaml deleted file mode 100644 index ec6c3db09b..0000000000 --- a/test/integration/targets/vyos_l3_interfaces/tests/cli/merged.yaml +++ /dev/null @@ -1,58 +0,0 @@ ---- -- debug: - msg: "START vyos_l3_interfaces merged integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- block: - - name: Merge the provided configuration with the exisiting running configuration - vyos_l3_interfaces: &merged - config: - - name: eth1 - ipv4: - - address: 192.0.2.10/24 - ipv6: - - address: 2001:db8::10/32 - - - name: eth2 - ipv4: - - address: 198.51.100.10/24 - vifs: - - vlan_id: 101 - ipv4: - - address: 198.51.100.130/25 - ipv6: - - address: 2001:db8::20/32 - state: merged - register: result - - - name: Assert that before dicts were correctly generated - assert: - that: "{{ merged['before'] | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that correct set of commands were generated - assert: - that: - - "{{ merged['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that after dicts was correctly generated - assert: - that: - - "{{ merged['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) - vyos_l3_interfaces: *merged - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - - - name: Assert that before dicts were correctly generated - assert: - that: - - "{{ merged['after'] | symmetric_difference(result['before']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_l3_interfaces/tests/cli/overridden.yaml b/test/integration/targets/vyos_l3_interfaces/tests/cli/overridden.yaml deleted file mode 100644 index c33b8b1190..0000000000 --- a/test/integration/targets/vyos_l3_interfaces/tests/cli/overridden.yaml +++ /dev/null @@ -1,52 +0,0 @@ ---- -- debug: - msg: "START vyos_l3_interfaces merged integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- block: - - include_tasks: _populate.yaml - - - name: Overrides all device configuration with provided configuration - vyos_l3_interfaces: &overridden - config: - - name: eth0 - ipv4: - - address: dhcp - - name: eth1 - ipv4: - - address: "192.0.2.15/24" - state: overridden - register: result - - - name: Assert that before dicts were correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that correct commands were generated - assert: - that: - - "{{ overridden['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that after dicts were correctly generated - assert: - that: - - "{{ overridden['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Overrides all device configuration with provided configurations (IDEMPOTENT) - vyos_l3_interfaces: *overridden - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - - - name: Assert that before dicts were correctly generated - assert: - that: - - "{{ overridden['after'] | symmetric_difference(result['before']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_l3_interfaces/tests/cli/replaced.yaml b/test/integration/targets/vyos_l3_interfaces/tests/cli/replaced.yaml deleted file mode 100644 index 51b372def3..0000000000 --- a/test/integration/targets/vyos_l3_interfaces/tests/cli/replaced.yaml +++ /dev/null @@ -1,52 +0,0 @@ ---- -- debug: - msg: "START vyos_l3_interfaces replaced integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- block: - - include_tasks: _populate.yaml - - - name: Replace device configurations of listed interfaces with provided configurations - vyos_l3_interfaces: &replaced - config: - - name: eth1 - ipv4: - - address: 192.0.2.19/24 - - name: eth2 - ipv6: - - address: 2001:db8::11/32 - state: replaced - register: result - - - name: Assert that correct set of commands were generated - assert: - that: - - "{{ replaced['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that before dicts are correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that after dict is correctly generated - assert: - that: - - "{{ replaced['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Replace device configurations of listed interfaces with provided configurarions (IDEMPOTENT) - vyos_l3_interfaces: *replaced - register: result - - - name: Assert that task was idempotent - assert: - that: - - "result['changed'] == false" - - - name: Assert that before dict is correctly generated - assert: - that: - - "{{ replaced['after'] | symmetric_difference(result['before']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_l3_interfaces/vars/main.yaml b/test/integration/targets/vyos_l3_interfaces/vars/main.yaml deleted file mode 100644 index 1241763451..0000000000 --- a/test/integration/targets/vyos_l3_interfaces/vars/main.yaml +++ /dev/null @@ -1,114 +0,0 @@ ---- -merged: - before: - - name: "eth0" - ipv4: - - address: "dhcp" - - - name: "eth1" - - - name: "eth2" - - commands: - - "set interfaces ethernet eth1 address '192.0.2.10/24'" - - "set interfaces ethernet eth1 address '2001:db8::10/32'" - - "set interfaces ethernet eth2 address '198.51.100.10/24'" - - "set interfaces ethernet eth2 vif 101 address '198.51.100.130/25'" - - "set interfaces ethernet eth2 vif 101 address '2001:db8::20/32'" - - after: - - name: "eth0" - ipv4: - - address: "dhcp" - - - name: "eth1" - ipv4: - - address: "192.0.2.10/24" - ipv6: - - address: "2001:db8::10/32" - - - name: "eth2" - ipv4: - - address: "198.51.100.10/24" - vifs: - - vlan_id: 101 - ipv4: - - address: "198.51.100.130/25" - ipv6: - - address: "2001:db8::20/32" - -populate: - - name: "eth1" - ipv4: - - address: "192.0.2.14/24" - - - name: "eth2" - ipv4: - - address: "192.0.2.10/24" - - address: "192.0.2.11/24" - ipv6: - - address: "2001:db8::10/32" - - address: "2001:db8::12/32" - - - name: "eth0" - ipv4: - - address: "dhcp" - -replaced: - commands: - - "delete interfaces ethernet eth2 address '192.0.2.10/24'" - - "delete interfaces ethernet eth2 address '192.0.2.11/24'" - - "delete interfaces ethernet eth2 address '2001:db8::10/32'" - - "delete interfaces ethernet eth2 address '2001:db8::12/32'" - - "set interfaces ethernet eth2 address '2001:db8::11/32'" - - "delete interfaces ethernet eth1 address '192.0.2.14/24'" - - "set interfaces ethernet eth1 address '192.0.2.19/24'" - - after: - - name: "eth2" - ipv6: - - address: "2001:db8::11/32" - - - name: "eth1" - ipv4: - - address: "192.0.2.19/24" - - - name: "eth0" - ipv4: - - address: "dhcp" - -overridden: - commands: - - delete interfaces ethernet eth1 address '192.0.2.14/24' - - set interfaces ethernet eth1 address '192.0.2.15/24' - - delete interfaces ethernet eth2 address '192.0.2.10/24' - - delete interfaces ethernet eth2 address '192.0.2.11/24' - - delete interfaces ethernet eth2 address '2001:db8::10/32' - - delete interfaces ethernet eth2 address '2001:db8::12/32' - - after: - - name: "eth0" - ipv4: - - address: "dhcp" - - - name: "eth1" - ipv4: - - address: "192.0.2.15/24" - - - name: "eth2" - -deleted: - commands: - - delete interfaces ethernet eth1 address '192.0.2.14/24' - - delete interfaces ethernet eth2 address '192.0.2.10/24' - - delete interfaces ethernet eth2 address '192.0.2.11/24' - - delete interfaces ethernet eth2 address '2001:db8::10/32' - - delete interfaces ethernet eth2 address '2001:db8::12/32' - after: - - name: "eth0" - ipv4: - - address: "dhcp" - - - name: "eth1" - - - name: "eth2" diff --git a/test/integration/targets/vyos_lag_interfaces/defaults/main.yaml b/test/integration/targets/vyos_lag_interfaces/defaults/main.yaml deleted file mode 100644 index 164afead28..0000000000 --- a/test/integration/targets/vyos_lag_interfaces/defaults/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -testcase: "[^_].*" -test_items: [] diff --git a/test/integration/targets/vyos_lag_interfaces/meta/main.yaml b/test/integration/targets/vyos_lag_interfaces/meta/main.yaml deleted file mode 100644 index 7413320e48..0000000000 --- a/test/integration/targets/vyos_lag_interfaces/meta/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dependencies: - - prepare_vyos_tests diff --git a/test/integration/targets/vyos_lag_interfaces/tasks/cli.yaml b/test/integration/targets/vyos_lag_interfaces/tasks/cli.yaml deleted file mode 100644 index 655e51ee63..0000000000 --- a/test/integration/targets/vyos_lag_interfaces/tasks/cli.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -- name: Collect all cli test cases - find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - use_regex: true - register: test_cases - delegate_to: localhost - -- name: Set test_items - set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test case (connection=network_cli) - include: "{{ test_case_to_run }}" - vars: - ansible_connection: network_cli - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run diff --git a/test/integration/targets/vyos_lag_interfaces/tasks/main.yaml b/test/integration/targets/vyos_lag_interfaces/tasks/main.yaml deleted file mode 100644 index d4cf26fc4a..0000000000 --- a/test/integration/targets/vyos_lag_interfaces/tasks/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -- {include: cli.yaml, tags: ['cli']} diff --git a/test/integration/targets/vyos_lag_interfaces/tests/cli/_add_bond.yaml b/test/integration/targets/vyos_lag_interfaces/tests/cli/_add_bond.yaml deleted file mode 100644 index 72cf397859..0000000000 --- a/test/integration/targets/vyos_lag_interfaces/tests/cli/_add_bond.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -- name: Add Bond - cli_config: - config: "{{ lines }}" - vars: - lines: | - set interfaces bonding bond0 - set interfaces bonding bond1 diff --git a/test/integration/targets/vyos_lag_interfaces/tests/cli/_populate.yaml b/test/integration/targets/vyos_lag_interfaces/tests/cli/_populate.yaml deleted file mode 100644 index f644bd935f..0000000000 --- a/test/integration/targets/vyos_lag_interfaces/tests/cli/_populate.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -- name: Setup - cli_config: - config: "{{ lines }}" - vars: - lines: | - set interfaces bonding bond0 - set interfaces bonding bond0 hash-policy 'layer2' - set interfaces bonding bond0 mode 'active-backup' - set interfaces ethernet eth1 bond-group bond0 - set interfaces bonding bond1 - set interfaces bonding bond0 primary 'eth1' - set interfaces bonding bond1 hash-policy 'layer2+3' - set interfaces bonding bond1 mode 'active-backup' - set interfaces ethernet eth2 bond-group bond1 - set interfaces bonding bond1 primary 'eth2' diff --git a/test/integration/targets/vyos_lag_interfaces/tests/cli/_remove_bond.yaml b/test/integration/targets/vyos_lag_interfaces/tests/cli/_remove_bond.yaml deleted file mode 100644 index 2fbfaa0535..0000000000 --- a/test/integration/targets/vyos_lag_interfaces/tests/cli/_remove_bond.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -- name: Remove Bond - cli_config: - config: "{{ lines }}" - vars: - lines: | - delete interfaces bonding bond0 - delete interfaces bonding bond1 diff --git a/test/integration/targets/vyos_lag_interfaces/tests/cli/_remove_config.yaml b/test/integration/targets/vyos_lag_interfaces/tests/cli/_remove_config.yaml deleted file mode 100644 index 37e61c1da7..0000000000 --- a/test/integration/targets/vyos_lag_interfaces/tests/cli/_remove_config.yaml +++ /dev/null @@ -1,14 +0,0 @@ ---- -- name: Remove Config - cli_config: - config: "{{ lines }}" - vars: - lines: | - delete interfaces bonding bond0 hash-policy - delete interfaces ethernet eth1 bond-group bond0 - delete interfaces bonding bond0 mode - delete interfaces bonding bond0 primary - delete interfaces bonding bond1 hash-policy - delete interfaces ethernet eth2 bond-group bond1 - delete interfaces bonding bond1 mode - delete interfaces bonding bond1 primary diff --git a/test/integration/targets/vyos_lag_interfaces/tests/cli/deleted.yaml b/test/integration/targets/vyos_lag_interfaces/tests/cli/deleted.yaml deleted file mode 100644 index be635d2936..0000000000 --- a/test/integration/targets/vyos_lag_interfaces/tests/cli/deleted.yaml +++ /dev/null @@ -1,46 +0,0 @@ ---- -- debug: - msg: "Start vyos_lag_interfaces deleted integration tests ansible_connection={{ ansible_connection }}" - -- include_tasks: _populate.yaml - -- block: - - name: Delete attributes of given LAG interfaces. - vyos_lag_interfaces: &deleted - config: - - name: bond0 - - name: bond1 - state: deleted - register: result - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that the correct set of commands were generated - assert: - that: - - "{{ deleted['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that the after dicts were correctly generated - assert: - that: - - "{{ deleted['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Delete attributes of given interfaces (IDEMPOTENT) - vyos_lag_interfaces: *deleted - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result.changed == false" - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ deleted['after'] | symmetric_difference(result['before']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_lag_interfaces/tests/cli/empty_config.yaml b/test/integration/targets/vyos_lag_interfaces/tests/cli/empty_config.yaml deleted file mode 100644 index 6590bb1d3d..0000000000 --- a/test/integration/targets/vyos_lag_interfaces/tests/cli/empty_config.yaml +++ /dev/null @@ -1,36 +0,0 @@ ---- -- debug: - msg: "START vyos_lag_interfaces empty_config integration tests on connection={{ ansible_connection }}" - -- name: Merged with empty config should give appropriate error message - vyos_lag_interfaces: - config: - state: merged - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state merged' - -- name: Replaced with empty config should give appropriate error message - vyos_lag_interfaces: - config: - state: replaced - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state replaced' - -- name: Overridden with empty config should give appropriate error message - vyos_lag_interfaces: - config: - state: overridden - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state overridden' diff --git a/test/integration/targets/vyos_lag_interfaces/tests/cli/merged.yaml b/test/integration/targets/vyos_lag_interfaces/tests/cli/merged.yaml deleted file mode 100644 index d621e33681..0000000000 --- a/test/integration/targets/vyos_lag_interfaces/tests/cli/merged.yaml +++ /dev/null @@ -1,60 +0,0 @@ ---- -- debug: - msg: "START vyos_lag_interfaces merged integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _remove_bond.yaml - -- include_tasks: _add_bond.yaml - -- block: - - name: Merge the provided configuration with the exisiting running configuration - vyos_lag_interfaces: &merged - config: - - name: bond0 - hash_policy: "layer2" - mode: "active-backup" - members: - - member: eth1 - primary: eth1 - - - name: bond1 - hash_policy: "layer2+3" - mode: "active-backup" - members: - - member: eth2 - primary: eth2 - state: merged - register: result - - - name: Assert that before dicts were correctly generated - assert: - that: "{{ merged['before'] | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that correct set of commands were generated - assert: - that: - - "{{ merged['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that after dicts was correctly generated - assert: - that: - - "{{ merged['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) - vyos_lag_interfaces: *merged - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - - - name: Assert that before dicts were correctly generated - assert: - that: - - "{{ merged['after'] | symmetric_difference(result['before']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_lag_interfaces/tests/cli/overridden.yaml b/test/integration/targets/vyos_lag_interfaces/tests/cli/overridden.yaml deleted file mode 100644 index 05bec8e2a3..0000000000 --- a/test/integration/targets/vyos_lag_interfaces/tests/cli/overridden.yaml +++ /dev/null @@ -1,54 +0,0 @@ ---- -- debug: - msg: "START vyos_lag_interfaces overridden integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _remove_bond.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Overrides all device configuration with provided configuration - vyos_lag_interfaces: &overridden - config: - - name: bond1 - mode: "active-backup" - members: - - member: eth2 - primary: eth2 - hash_policy: layer2 - state: overridden - register: result - - - name: Assert that before dicts were correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that correct commands were generated - assert: - that: - - "{{ overridden['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that after dicts were correctly generated - assert: - that: - - "{{ overridden['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Overrides all device configuration with provided configurations (IDEMPOTENT) - vyos_lag_interfaces: *overridden - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - - - name: Assert that before dicts were correctly generated - assert: - that: - - "{{ overridden['after'] | symmetric_difference(result['before']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_lag_interfaces/tests/cli/replaced.yaml b/test/integration/targets/vyos_lag_interfaces/tests/cli/replaced.yaml deleted file mode 100644 index c1b721fc2a..0000000000 --- a/test/integration/targets/vyos_lag_interfaces/tests/cli/replaced.yaml +++ /dev/null @@ -1,51 +0,0 @@ ---- -- debug: - msg: "START vyos_lag_interfaces replaced integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Replace device configurations of listed LAG interfaces with provided configurations - vyos_lag_interfaces: &replaced - config: - - name: bond1 - mode: "802.3ad" - hash_policy: "layer2" - members: - - member: eth2 - state: replaced - register: result - - - name: Assert that correct set of commands were generated - assert: - that: - - "{{ replaced['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that before dicts are correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that after dict is correctly generated - assert: - that: - - "{{ replaced['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Replace device configurations of listed LAG interfaces with provided configurarions (IDEMPOTENT) - vyos_lag_interfaces: *replaced - register: result - - - name: Assert that task was idempotent - assert: - that: - - "result['changed'] == false" - - - name: Assert that before dict is correctly generated - assert: - that: - - "{{ replaced['after'] | symmetric_difference(result['before']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_lag_interfaces/tests/cli/rtt.yaml b/test/integration/targets/vyos_lag_interfaces/tests/cli/rtt.yaml deleted file mode 100644 index 7521d8e6ac..0000000000 --- a/test/integration/targets/vyos_lag_interfaces/tests/cli/rtt.yaml +++ /dev/null @@ -1,69 +0,0 @@ ---- -- debug: - msg: "START vyos_lag_interfaces round trip integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _remove_bond.yaml - -- block: - - name: Apply the provided configuration (base config) - vyos_lag_interfaces: - config: - - name: bond0 - hash_policy: "layer2" - mode: "active-backup" - members: - - member: eth1 - primary: eth1 - - - name: bond1 - hash_policy: "layer2+3" - mode: "active-backup" - members: - - member: eth2 - primary: eth2 - - state: merged - register: base_config - - - name: Gather lag_interfaces facts - vyos_facts: - gather_subset: - - default - gather_network_resources: - - lag_interfaces - - - name: Apply the provided configuration (config to be reverted) - vyos_lag_interfaces: - config: - - name: bond0 - hash_policy: "layer2+3" - mode: "802.3ad" - members: - - member: eth1 - - - name: bond1 - hash_policy: "layer2" - mode: "xor-hash" - members: - - member: eth2 - state: merged - register: result - - - name: Assert that changes were applied - assert: - that: "{{ round_trip['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Revert back to base config using facts round trip - vyos_lag_interfaces: - config: "{{ ansible_facts['network_resources']['lag_interfaces'] }}" - state: overridden - register: revert - - - name: Assert that config was reverted - assert: - that: "{{ base_config['after'] | symmetric_difference(revert['after']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_lag_interfaces/vars/main.yaml b/test/integration/targets/vyos_lag_interfaces/vars/main.yaml deleted file mode 100644 index 8726e399c2..0000000000 --- a/test/integration/targets/vyos_lag_interfaces/vars/main.yaml +++ /dev/null @@ -1,115 +0,0 @@ ---- -merged: - before: - - name: "bond0" - - - name: "bond1" - - commands: - - "set interfaces bonding bond0 hash-policy 'layer2'" - - "set interfaces bonding bond0 mode 'active-backup'" - - "set interfaces ethernet eth1 bond-group 'bond0'" - - "set interfaces bonding bond0 primary 'eth1'" - - "set interfaces bonding bond1 hash-policy 'layer2+3'" - - "set interfaces bonding bond1 mode 'active-backup'" - - "set interfaces ethernet eth2 bond-group 'bond1'" - - "set interfaces bonding bond1 primary 'eth2'" - - after: - - name: "bond0" - hash_policy: "layer2" - members: - - member: eth1 - mode: "active-backup" - primary: eth1 - - - name: "bond1" - hash_policy: "layer2+3" - members: - - member: eth2 - mode: "active-backup" - primary: eth2 - -populate: - - name: "bond0" - hash_policy: "layer2" - members: - - member: eth1 - mode: "active-backup" - primary: eth1 - - - name: "bond1" - hash_policy: "layer2+3" - members: - - member: eth2 - mode: "active-backup" - primary: eth2 - -replaced: - commands: - - "delete interfaces bonding bond1 primary" - - "set interfaces bonding bond1 hash-policy 'layer2'" - - "set interfaces bonding bond1 mode '802.3ad'" - - after: - - name: "bond0" - hash_policy: "layer2" - members: - - member: eth1 - mode: "active-backup" - primary: eth1 - - - name: "bond1" - hash_policy: "layer2" - members: - - member: eth2 - mode: "802.3ad" - -overridden: - commands: - - "delete interfaces bonding bond0 hash-policy" - - "delete interfaces ethernet eth1 bond-group 'bond0'" - - "delete interfaces bonding bond0 mode" - - "delete interfaces bonding bond0 primary" - - "set interfaces bonding bond1 hash-policy 'layer2'" - - after: - - name: "bond0" - - name: "bond1" - hash_policy: "layer2" - members: - - member: eth2 - mode: "active-backup" - primary: eth2 - -deleted: - commands: - - "delete interfaces bonding bond0 hash-policy" - - "delete interfaces ethernet eth1 bond-group 'bond0'" - - "delete interfaces bonding bond0 mode" - - "delete interfaces bonding bond0 primary" - - "delete interfaces bonding bond1 hash-policy" - - "delete interfaces ethernet eth2 bond-group 'bond1'" - - "delete interfaces bonding bond1 mode" - - "delete interfaces bonding bond1 primary" - - after: - - name: "bond0" - - - name: "bond1" - -round_trip: - after: - - name: "bond0" - hash_policy: "layer2+3" - members: - - member: eth1 - mode: "802.3ad" - primary: eth1 - - - name: "bond1" - hash_policy: "layer2" - members: - - member: eth2 - mode: "xor-hash" - primary: eth2 diff --git a/test/integration/targets/vyos_linkagg/defaults/main.yaml b/test/integration/targets/vyos_linkagg/defaults/main.yaml deleted file mode 100644 index 9ef5ba5165..0000000000 --- a/test/integration/targets/vyos_linkagg/defaults/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -testcase: "*" -test_items: [] diff --git a/test/integration/targets/vyos_linkagg/tasks/cli.yaml b/test/integration/targets/vyos_linkagg/tasks/cli.yaml deleted file mode 100644 index 890d3acf3e..0000000000 --- a/test/integration/targets/vyos_linkagg/tasks/cli.yaml +++ /dev/null @@ -1,22 +0,0 @@ ---- -- name: collect all cli test cases - find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - register: test_cases - delegate_to: localhost - -- name: set test_items - set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - -- name: run test case (connection=network_cli) - include: "{{ test_case_to_run }} ansible_connection=network_cli" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - -- name: run test case (connection=local) - include: "{{ test_case_to_run }} ansible_connection=local" - with_first_found: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run diff --git a/test/integration/targets/vyos_linkagg/tasks/main.yaml b/test/integration/targets/vyos_linkagg/tasks/main.yaml deleted file mode 100644 index d4cf26fc4a..0000000000 --- a/test/integration/targets/vyos_linkagg/tasks/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -- {include: cli.yaml, tags: ['cli']} diff --git a/test/integration/targets/vyos_linkagg/tests/cli/basic.yaml b/test/integration/targets/vyos_linkagg/tests/cli/basic.yaml deleted file mode 100644 index 48fc6402f5..0000000000 --- a/test/integration/targets/vyos_linkagg/tests/cli/basic.yaml +++ /dev/null @@ -1,184 +0,0 @@ ---- -- debug: msg="cli/basic.yaml on connection={{ ansible_connection }}" - -- name: Remove linkagg - vyos_linkagg: - name: bond0 - state: absent - -- name: Remove linkagg - vyos_linkagg: - name: bond1 - state: absent - -- name: Create linkagg - vyos_linkagg: - name: bond0 - members: - - eth1 - state: present - register: result - -- assert: - that: - - 'result.changed == true' - - '"set interfaces bonding bond0 mode 802.3ad" in result.commands' - - '"set interfaces ethernet eth1 bond-group bond0" in result.commands' - -- name: Create linkagg again (idempotent) - vyos_linkagg: - name: bond0 - members: - - eth1 - state: present - register: result - -- assert: - that: - - 'result.changed == false' - -- name: Add linkagg member - vyos_linkagg: - name: bond0 - members: - - eth2 - state: present - register: result - -- assert: - that: - - 'result.changed == true' - - '"set interfaces ethernet eth2 bond-group bond0" in result.commands' - -- name: Add linkagg member again (idempotent) - vyos_linkagg: - name: bond0 - members: - - eth2 - state: present - register: result - -- assert: - that: - - 'result.changed == false' - -- name: Disable linkagg - vyos_linkagg: - name: bond0 - state: down - register: result - -- assert: - that: - - 'result.changed == true' - - '"set interfaces bonding bond0 disable" in result.commands' - -- name: Disable linkagg again (idempotent) - vyos_linkagg: - name: bond0 - state: down - register: result - -- assert: - that: - - 'result.changed == false' - -- name: Enable linkagg - vyos_linkagg: - name: bond0 - state: up - register: result - -- assert: - that: - - 'result.changed == true' - - '"delete interfaces bonding bond0 disable" in result.commands[0]' - -- name: Enable linkagg again (idempotent) - vyos_linkagg: - name: bond0 - state: up - register: result - -- assert: - that: - - 'result.changed == false' - -- name: Remove linkagg - vyos_linkagg: - name: bond0 - state: absent - register: result - -- assert: - that: - - 'result.changed == true' - - '"delete interfaces ethernet eth1 bond-group" in result.commands' - - '"delete interfaces ethernet eth2 bond-group" in result.commands' - - '"delete interfaces bonding bond0" in result.commands' - -- name: Remove linkagg again (idempotent) - vyos_linkagg: - name: bond0 - state: absent - register: result - -- assert: - that: - - 'result.changed == false' - -- name: Create collection of linkagg definitions - vyos_linkagg: - aggregate: - - {name: bond0, members: [eth1]} - - {name: bond1, members: [eth2]} - state: present - register: result - -- assert: - that: - - 'result.changed == true' - - '"set interfaces bonding bond0 mode 802.3ad" in result.commands' - - '"set interfaces ethernet eth1 bond-group bond0" in result.commands' - - '"set interfaces bonding bond1 mode 802.3ad" in result.commands' - - '"set interfaces ethernet eth2 bond-group bond1" in result.commands' - -- name: Create collection of linkagg definitions again (idempotent) - vyos_linkagg: - aggregate: - - {name: bond0, members: [eth1]} - - {name: bond1, members: [eth2]} - state: present - register: result - -- assert: - that: - - 'result.changed == false' - -- name: Remove collection of linkagg definitions - vyos_linkagg: - aggregate: - - name: bond0 - - name: bond1 - state: absent - register: result - -- assert: - that: - - 'result.changed == true' - - '"delete interfaces ethernet eth1 bond-group" in result.commands' - - '"delete interfaces bonding bond0" in result.commands' - - '"delete interfaces ethernet eth2 bond-group" in result.commands' - - '"delete interfaces bonding bond1" in result.commands' - -- name: Remove collection of linkagg definitions again (idempotent) - vyos_linkagg: - aggregate: - - name: bond0 - - name: bond1 - state: absent - register: result - -- assert: - that: - - 'result.changed == false' diff --git a/test/integration/targets/vyos_linkagg/tests/cli/net_linkagg.yaml b/test/integration/targets/vyos_linkagg/tests/cli/net_linkagg.yaml deleted file mode 100644 index 93f98e7aed..0000000000 --- a/test/integration/targets/vyos_linkagg/tests/cli/net_linkagg.yaml +++ /dev/null @@ -1,31 +0,0 @@ ---- -- debug: msg="START vyos cli/net_linkagg.yaml on connection={{ ansible_connection }}" - -# Add minimal testcase to check args are passed correctly to -# implementation module and module run is successful. - -- name: Remove linkagg - set - net_linkagg: - name: bond0 - state: absent - -- name: Create linkagg using platform agnostic module - net_linkagg: - name: bond0 - members: - - eth1 - state: present - register: result - -- assert: - that: - - 'result.changed == true' - - '"set interfaces bonding bond0 mode 802.3ad" in result.commands' - - '"set interfaces ethernet eth1 bond-group bond0" in result.commands' - -- name: Remove linkagg - teardown - net_linkagg: - name: bond0 - state: absent - -- debug: msg="END vyos cli/net_linkagg.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/vyos_lldp/aliases b/test/integration/targets/vyos_lldp/aliases deleted file mode 100644 index 8071e1f75b..0000000000 --- a/test/integration/targets/vyos_lldp/aliases +++ /dev/null @@ -1 +0,0 @@ -shippable/vyos/group1 diff --git a/test/integration/targets/vyos_lldp/defaults/main.yaml b/test/integration/targets/vyos_lldp/defaults/main.yaml deleted file mode 100644 index 9ef5ba5165..0000000000 --- a/test/integration/targets/vyos_lldp/defaults/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -testcase: "*" -test_items: [] diff --git a/test/integration/targets/vyos_lldp/tasks/cli.yaml b/test/integration/targets/vyos_lldp/tasks/cli.yaml deleted file mode 100644 index 890d3acf3e..0000000000 --- a/test/integration/targets/vyos_lldp/tasks/cli.yaml +++ /dev/null @@ -1,22 +0,0 @@ ---- -- name: collect all cli test cases - find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - register: test_cases - delegate_to: localhost - -- name: set test_items - set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - -- name: run test case (connection=network_cli) - include: "{{ test_case_to_run }} ansible_connection=network_cli" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - -- name: run test case (connection=local) - include: "{{ test_case_to_run }} ansible_connection=local" - with_first_found: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run diff --git a/test/integration/targets/vyos_lldp/tasks/main.yaml b/test/integration/targets/vyos_lldp/tasks/main.yaml deleted file mode 100644 index d4cf26fc4a..0000000000 --- a/test/integration/targets/vyos_lldp/tasks/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -- {include: cli.yaml, tags: ['cli']} diff --git a/test/integration/targets/vyos_lldp/tests/cli/basic.yaml b/test/integration/targets/vyos_lldp/tests/cli/basic.yaml deleted file mode 100644 index bc7774f0ee..0000000000 --- a/test/integration/targets/vyos_lldp/tests/cli/basic.yaml +++ /dev/null @@ -1,44 +0,0 @@ ---- -- debug: msg="START cli/basic.yaml on connection={{ ansible_connection }}" - -- name: Make sure LLDP is not running before tests - vyos_config: - lines: delete service lldp - -- name: Enable LLDP service - vyos_lldp: - state: present - register: result - -- assert: - that: - - 'result.changed == true' - - '"set service lldp" in result.commands' - -- name: Enable LLDP service again (idempotent) - vyos_lldp: - state: present - register: result - -- assert: - that: - - 'result.changed == false' - -- name: Disable LLDP service - vyos_lldp: - state: absent - register: result - -- assert: - that: - - 'result.changed == true' - - '"delete service lldp" in result.commands' - -- name: - vyos_lldp: - state: absent - register: result - -- assert: - that: - - 'result.changed == false' diff --git a/test/integration/targets/vyos_lldp/tests/cli/net_lldp.yaml b/test/integration/targets/vyos_lldp/tests/cli/net_lldp.yaml deleted file mode 100644 index cf8f97cb8a..0000000000 --- a/test/integration/targets/vyos_lldp/tests/cli/net_lldp.yaml +++ /dev/null @@ -1,25 +0,0 @@ ---- -- debug: msg="START vyos cli/net_lldp.yaml on connection={{ ansible_connection }}" - -# Add minimal testcase to check args are passed correctly to -# implementation module and module run is successful. - -- name: Make sure LLDP is not running - setup - vyos_config: - lines: delete service lldp - -- name: Enable LLDP service using platform agnostic module - net_lldp: - state: present - register: result - -- assert: - that: - - 'result.changed == true' - - '"set service lldp" in result.commands' - -- name: Make sure LLDP is not running - teardown - vyos_config: - lines: delete service lldp - -- debug: msg="END vyos cli/net_lldp.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/vyos_lldp_global/aliases b/test/integration/targets/vyos_lldp_global/aliases deleted file mode 100644 index 8071e1f75b..0000000000 --- a/test/integration/targets/vyos_lldp_global/aliases +++ /dev/null @@ -1 +0,0 @@ -shippable/vyos/group1 diff --git a/test/integration/targets/vyos_lldp_global/defaults/main.yaml b/test/integration/targets/vyos_lldp_global/defaults/main.yaml deleted file mode 100644 index 164afead28..0000000000 --- a/test/integration/targets/vyos_lldp_global/defaults/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -testcase: "[^_].*" -test_items: [] diff --git a/test/integration/targets/vyos_lldp_global/tasks/cli.yaml b/test/integration/targets/vyos_lldp_global/tasks/cli.yaml deleted file mode 100644 index 655e51ee63..0000000000 --- a/test/integration/targets/vyos_lldp_global/tasks/cli.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -- name: Collect all cli test cases - find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - use_regex: true - register: test_cases - delegate_to: localhost - -- name: Set test_items - set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test case (connection=network_cli) - include: "{{ test_case_to_run }}" - vars: - ansible_connection: network_cli - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run diff --git a/test/integration/targets/vyos_lldp_global/tasks/main.yaml b/test/integration/targets/vyos_lldp_global/tasks/main.yaml deleted file mode 100644 index d4cf26fc4a..0000000000 --- a/test/integration/targets/vyos_lldp_global/tasks/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -- {include: cli.yaml, tags: ['cli']} diff --git a/test/integration/targets/vyos_lldp_global/tests/cli/_populate.yaml b/test/integration/targets/vyos_lldp_global/tests/cli/_populate.yaml deleted file mode 100644 index 183c9a5c10..0000000000 --- a/test/integration/targets/vyos_lldp_global/tests/cli/_populate.yaml +++ /dev/null @@ -1,9 +0,0 @@ ---- -- name: Setup - cli_config: - config: "{{ lines }}" - vars: - lines: | - set service lldp - set service lldp legacy-protocols 'cdp' - set service lldp management-address '192.0.2.17' diff --git a/test/integration/targets/vyos_lldp_global/tests/cli/_remove_config.yaml b/test/integration/targets/vyos_lldp_global/tests/cli/_remove_config.yaml deleted file mode 100644 index 3a0abf22ab..0000000000 --- a/test/integration/targets/vyos_lldp_global/tests/cli/_remove_config.yaml +++ /dev/null @@ -1,9 +0,0 @@ ---- -- name: Remove Config - cli_config: - config: "{{ lines }}" - vars: - lines: | - delete service lldp legacy-protocols - delete service lldp management-address - delete service lldp diff --git a/test/integration/targets/vyos_lldp_global/tests/cli/deleted.yaml b/test/integration/targets/vyos_lldp_global/tests/cli/deleted.yaml deleted file mode 100644 index 324ab18484..0000000000 --- a/test/integration/targets/vyos_lldp_global/tests/cli/deleted.yaml +++ /dev/null @@ -1,44 +0,0 @@ ---- -- debug: - msg: "Start vyos_lldp_global deleted integration tests ansible_connection={{ ansible_connection }}" - -- include_tasks: _populate.yaml - -- block: - - name: Delete attributes of LLDP service. - vyos_lldp_global: &deleted - config: - state: deleted - register: result - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ populate == result['before']}}" - - - name: Assert that the correct set of commands were generated - assert: - that: - - "{{ deleted['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that the after dicts were correctly generated - assert: - that: - - "{{ deleted['after'] == result['after']}}" - - - name: Delete attributes of given interfaces (IDEMPOTENT) - vyos_lldp_global: *deleted - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result.changed == false" - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ deleted['after'] == result['before'] }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_lldp_global/tests/cli/empty_config.yaml b/test/integration/targets/vyos_lldp_global/tests/cli/empty_config.yaml deleted file mode 100644 index 46f3b96e45..0000000000 --- a/test/integration/targets/vyos_lldp_global/tests/cli/empty_config.yaml +++ /dev/null @@ -1,25 +0,0 @@ ---- -- debug: - msg: "START vyos_lldp_global empty_config integration tests on connection={{ ansible_connection }}" - -- name: Merged with empty config should give appropriate error message - vyos_lldp_global: - config: - state: merged - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state merged' - -- name: Replaced with empty config should give appropriate error message - vyos_lldp_global: - config: - state: replaced - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state replaced' diff --git a/test/integration/targets/vyos_lldp_global/tests/cli/merged.yaml b/test/integration/targets/vyos_lldp_global/tests/cli/merged.yaml deleted file mode 100644 index 9b8e448bd1..0000000000 --- a/test/integration/targets/vyos_lldp_global/tests/cli/merged.yaml +++ /dev/null @@ -1,49 +0,0 @@ ---- -- debug: - msg: "START vyos_lldp_global merged integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Merge the provided configuration with the exisiting running configuration - vyos_lldp_global: &merged - config: - legacy_protocols: - - 'fdp' - - 'cdp' - address: 192.0.2.11 - state: merged - register: result - - - name: Assert that before dicts were correctly generated - assert: - that: "{{ merged['before'] == result['before'] }}" - - - name: Assert that correct set of commands were generated - assert: - that: - - "{{ merged['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that after dicts was correctly generated - assert: - that: - - "{{ merged['after'] == result['after'] }}" - - - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) - vyos_lldp_global: *merged - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - - - name: Assert that before dicts were correctly generated - assert: - that: - - "{{ merged['after'] == result['before'] }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_lldp_global/tests/cli/replaced.yaml b/test/integration/targets/vyos_lldp_global/tests/cli/replaced.yaml deleted file mode 100644 index f641792461..0000000000 --- a/test/integration/targets/vyos_lldp_global/tests/cli/replaced.yaml +++ /dev/null @@ -1,51 +0,0 @@ ---- -- debug: - msg: "START vyos_lldp_global replaced integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Replace device configurations of LLDP service with provided configurations - vyos_lldp_global: &replaced - config: - legacy_protocols: - - 'edp' - - 'sonmp' - - 'cdp' - address: 192.0.2.14 - state: replaced - register: result - - - name: Assert that correct set of commands were generated - assert: - that: - - "{{ replaced['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that before dicts are correctly generated - assert: - that: - - "{{ populate == result['before'] }}" - - - name: Assert that after dict is correctly generated - assert: - that: - - "{{ replaced['after'] == result['after'] }}" - - - name: Replace device configurations of LLDP service with provided configurarions (IDEMPOTENT) - vyos_lldp_global: *replaced - register: result - - - name: Assert that task was idempotent - assert: - that: - - "result['changed'] == false" - - - name: Assert that before dict is correctly generated - assert: - that: - - "{{ replaced['after'] == result['before'] }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_lldp_global/tests/cli/rtt.yaml b/test/integration/targets/vyos_lldp_global/tests/cli/rtt.yaml deleted file mode 100644 index 1e37cdefeb..0000000000 --- a/test/integration/targets/vyos_lldp_global/tests/cli/rtt.yaml +++ /dev/null @@ -1,51 +0,0 @@ ---- -- debug: - msg: "START vyos_lldp_global round trip integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- block: - - name: Apply the provided configuration (base config) - vyos_lldp_global: - config: - legacy_protocols: - - 'fdp' - - 'cdp' - address: 192.0.2.11 - state: merged - register: base_config - - - name: Gather vyos_lldp_global facts - vyos_facts: - gather_subset: - - default - gather_network_resources: - - lldp_global - - - name: Apply the provided configuration (config to be reverted) - vyos_lldp_global: - config: - legacy_protocols: - - 'edp' - - 'sonmp' - - 'cdp' - address: 192.0.2.14 - state: merged - register: result - - - name: Assert that changes were applied - assert: - that: "{{ round_trip['after'] == result['after'] }}" - - - name: Revert back to base config using facts round trip - vyos_lldp_global: - config: "{{ ansible_facts['network_resources']['lldp_global'] }}" - state: replaced - register: revert - - - name: Assert that config was reverted - assert: - that: "{{ base_config['after'] == revert['after'] }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_lldp_global/vars/main.yaml b/test/integration/targets/vyos_lldp_global/vars/main.yaml deleted file mode 100644 index 420b2b4e8f..0000000000 --- a/test/integration/targets/vyos_lldp_global/vars/main.yaml +++ /dev/null @@ -1,56 +0,0 @@ ---- -merged: - before: - address: '192.0.2.17' - enable: true - legacy_protocols: - - 'cdp' - - commands: - - "set service lldp management-address '192.0.2.11'" - - "set service lldp legacy-protocols 'fdp'" - - after: - address: '192.0.2.11' - enable: true - legacy_protocols: - - 'cdp' - - 'fdp' - -populate: - address: '192.0.2.17' - enable: true - legacy_protocols: - - 'cdp' - -replaced: - commands: - - "set service lldp legacy-protocols 'edp'" - - "set service lldp legacy-protocols 'sonmp'" - - "set service lldp management-address '192.0.2.14'" - - after: - address: '192.0.2.14' - enable: true - legacy_protocols: - - 'cdp' - - 'edp' - - 'sonmp' - -deleted: - commands: - - "delete service lldp management-address" - - "delete service lldp legacy-protocols" - - after: - "enable": true - -round_trip: - after: - address: '192.0.2.14' - enable: true - legacy_protocols: - - 'cdp' - - 'edp' - - 'fdp' - - 'sonmp' diff --git a/test/integration/targets/vyos_lldp_interface/aliases b/test/integration/targets/vyos_lldp_interface/aliases deleted file mode 100644 index 8071e1f75b..0000000000 --- a/test/integration/targets/vyos_lldp_interface/aliases +++ /dev/null @@ -1 +0,0 @@ -shippable/vyos/group1 diff --git a/test/integration/targets/vyos_lldp_interface/defaults/main.yaml b/test/integration/targets/vyos_lldp_interface/defaults/main.yaml deleted file mode 100644 index 9ef5ba5165..0000000000 --- a/test/integration/targets/vyos_lldp_interface/defaults/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -testcase: "*" -test_items: [] diff --git a/test/integration/targets/vyos_lldp_interface/tasks/cli.yaml b/test/integration/targets/vyos_lldp_interface/tasks/cli.yaml deleted file mode 100644 index 890d3acf3e..0000000000 --- a/test/integration/targets/vyos_lldp_interface/tasks/cli.yaml +++ /dev/null @@ -1,22 +0,0 @@ ---- -- name: collect all cli test cases - find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - register: test_cases - delegate_to: localhost - -- name: set test_items - set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - -- name: run test case (connection=network_cli) - include: "{{ test_case_to_run }} ansible_connection=network_cli" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - -- name: run test case (connection=local) - include: "{{ test_case_to_run }} ansible_connection=local" - with_first_found: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run diff --git a/test/integration/targets/vyos_lldp_interface/tasks/main.yaml b/test/integration/targets/vyos_lldp_interface/tasks/main.yaml deleted file mode 100644 index d4cf26fc4a..0000000000 --- a/test/integration/targets/vyos_lldp_interface/tasks/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -- {include: cli.yaml, tags: ['cli']} diff --git a/test/integration/targets/vyos_lldp_interface/tests/cli/basic.yaml b/test/integration/targets/vyos_lldp_interface/tests/cli/basic.yaml deleted file mode 100644 index 8335aeffe7..0000000000 --- a/test/integration/targets/vyos_lldp_interface/tests/cli/basic.yaml +++ /dev/null @@ -1,167 +0,0 @@ ---- -- debug: msg="START cli/basic.yaml on connection={{ ansible_connection }}" - -- name: Make sure LLDP is not running before tests - vyos_config: - lines: delete service lldp - -- name: Create LLDP configuration - vyos_lldp_interface: - name: eth1 - state: present - register: result - -- assert: - that: - - 'result.changed == true' - - '"set service lldp interface eth1" in result.commands' - -- name: Create LLDP configuration again (idempotent) - vyos_lldp_interface: - name: eth1 - state: present - register: result - -- assert: - that: - - 'result.changed == false' - -- name: Disable LLDP configuration - vyos_lldp_interface: - name: eth1 - state: disabled - register: result - -- assert: - that: - - 'result.changed == true' - - '"set service lldp interface eth1 disable" in result.commands' - -- name: Disable LLDP configuration again (idempotent) - vyos_lldp_interface: - name: eth1 - state: disabled - register: result - -- assert: - that: - - 'result.changed == false' - -- name: Enable LLDP configuration - vyos_lldp_interface: - name: eth1 - state: enabled - register: result - -- assert: - that: - - 'result.changed == true' - - '"delete service lldp interface eth1 disable" in result.commands' - -- name: Enable LLDP configuration again (idempotent) - vyos_lldp_interface: - name: eth1 - state: enabled - register: result - -- assert: - that: - - 'result.changed == false' - -- name: Delete LLDP configuration - vyos_lldp_interface: - name: eth1 - state: absent - register: result - -- assert: - that: - - 'result.changed == true' - - '"delete service lldp interface eth1" in result.commands' - -- name: Delete LLDP configuration again (idempotent) - vyos_lldp_interface: - name: eth1 - state: absent - register: result - -- assert: - that: - - 'result.changed == false' - -- name: Create aggregate of LLDP interface configurations - vyos_lldp_interface: - aggregate: - - name: eth1 - - name: eth2 - state: present - register: result - -- assert: - that: - - 'result.changed == true' - - '"set service lldp interface eth1" in result.commands' - - '"set service lldp interface eth2" in result.commands' - -- name: Create aggregate of LLDP interface configurations again (idempotent) - vyos_lldp_interface: - aggregate: - - name: eth1 - - name: eth2 - state: present - register: result - -- assert: - that: - - 'result.changed == false' - -- name: Override LLDP interface configuration on aggregate - vyos_lldp_interface: - aggregate: - - name: eth1 - - {name: eth2, state: disabled} - state: present - register: result - -- assert: - that: - - 'result.changed == true' - - '"set service lldp interface eth2 disable" in result.commands' - -- name: Override LLDP interface configuration on aggregate again (idempotent) - vyos_lldp_interface: - aggregate: - - name: eth1 - - {name: eth2, state: disabled} - state: present - register: result - -- assert: - that: - - 'result.changed == false' - -- name: Delete aggregate of LLDP interface configurations - vyos_lldp_interface: - aggregate: - - name: eth1 - - name: eth2 - state: absent - register: result - -- assert: - that: - - 'result.changed == true' - - '"delete service lldp interface eth1" in result.commands' - - '"delete service lldp interface eth2" in result.commands' - -- name: Delete aggregate of LLDP interface configurations (idempotent) - vyos_lldp_interface: - aggregate: - - name: eth1 - - name: eth2 - state: absent - register: result - -- assert: - that: - - 'result.changed == false' diff --git a/test/integration/targets/vyos_lldp_interface/tests/cli/net_lldp_interface.yaml b/test/integration/targets/vyos_lldp_interface/tests/cli/net_lldp_interface.yaml deleted file mode 100644 index 49cd8b005f..0000000000 --- a/test/integration/targets/vyos_lldp_interface/tests/cli/net_lldp_interface.yaml +++ /dev/null @@ -1,26 +0,0 @@ ---- -- debug: msg="START vyos cli/net_lldp_interface.yaml on connection={{ ansible_connection }}" - -# Add minimal testcase to check args are passed correctly to -# implementation module and module run is successful. - -- name: Make sure LLDP is not running - setup - vyos_config: - lines: delete service lldp - -- name: Create LLDP configuration using platform agnostic module - net_lldp_interface: - name: eth1 - state: present - register: result - -- assert: - that: - - 'result.changed == true' - - '"set service lldp interface eth1" in result.commands' - -- name: Make sure LLDP is not running - teardown - vyos_config: - lines: delete service lldp - -- debug: msg="END vyos cli/net_lldp_interface.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/vyos_lldp_interfaces/aliases b/test/integration/targets/vyos_lldp_interfaces/aliases deleted file mode 100644 index 8071e1f75b..0000000000 --- a/test/integration/targets/vyos_lldp_interfaces/aliases +++ /dev/null @@ -1 +0,0 @@ -shippable/vyos/group1 diff --git a/test/integration/targets/vyos_lldp_interfaces/defaults/main.yaml b/test/integration/targets/vyos_lldp_interfaces/defaults/main.yaml deleted file mode 100644 index 164afead28..0000000000 --- a/test/integration/targets/vyos_lldp_interfaces/defaults/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -testcase: "[^_].*" -test_items: [] diff --git a/test/integration/targets/vyos_lldp_interfaces/meta/main.yaml b/test/integration/targets/vyos_lldp_interfaces/meta/main.yaml deleted file mode 100644 index 7413320e48..0000000000 --- a/test/integration/targets/vyos_lldp_interfaces/meta/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dependencies: - - prepare_vyos_tests diff --git a/test/integration/targets/vyos_lldp_interfaces/tasks/cli.yaml b/test/integration/targets/vyos_lldp_interfaces/tasks/cli.yaml deleted file mode 100644 index 655e51ee63..0000000000 --- a/test/integration/targets/vyos_lldp_interfaces/tasks/cli.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -- name: Collect all cli test cases - find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - use_regex: true - register: test_cases - delegate_to: localhost - -- name: Set test_items - set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test case (connection=network_cli) - include: "{{ test_case_to_run }}" - vars: - ansible_connection: network_cli - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run diff --git a/test/integration/targets/vyos_lldp_interfaces/tasks/main.yaml b/test/integration/targets/vyos_lldp_interfaces/tasks/main.yaml deleted file mode 100644 index d4cf26fc4a..0000000000 --- a/test/integration/targets/vyos_lldp_interfaces/tasks/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -- {include: cli.yaml, tags: ['cli']} diff --git a/test/integration/targets/vyos_lldp_interfaces/tests/cli/_populate.yaml b/test/integration/targets/vyos_lldp_interfaces/tests/cli/_populate.yaml deleted file mode 100644 index eec2039674..0000000000 --- a/test/integration/targets/vyos_lldp_interfaces/tests/cli/_populate.yaml +++ /dev/null @@ -1,14 +0,0 @@ ---- -- name: Setup - cli_config: - config: "{{ lines }}" - vars: - lines: | - set service lldp interface eth1 - set service lldp interface eth1 location civic-based country-code US - set service lldp interface eth1 location civic-based ca-type 0 ca-value ENGLISH - set service lldp interface eth2 - set service lldp interface eth2 location coordinate-based latitude 33.524449N - set service lldp interface eth2 location coordinate-based altitude 2200 - set service lldp interface eth2 location coordinate-based datum WGS84 - set service lldp interface eth2 location coordinate-based longitude 222.267255W diff --git a/test/integration/targets/vyos_lldp_interfaces/tests/cli/_populate_intf.yaml b/test/integration/targets/vyos_lldp_interfaces/tests/cli/_populate_intf.yaml deleted file mode 100644 index f48509eda5..0000000000 --- a/test/integration/targets/vyos_lldp_interfaces/tests/cli/_populate_intf.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- name: Setup - cli_config: - config: "{{ lines }}" - vars: - lines: | - set service lldp interface eth2 - set service lldp interface eth2 location civic-based country-code US - set service lldp interface eth2 location civic-based ca-type 0 ca-value ENGLISH - set service lldp interface eth2 disable diff --git a/test/integration/targets/vyos_lldp_interfaces/tests/cli/_remove_config.yaml b/test/integration/targets/vyos_lldp_interfaces/tests/cli/_remove_config.yaml deleted file mode 100644 index 51b5f25473..0000000000 --- a/test/integration/targets/vyos_lldp_interfaces/tests/cli/_remove_config.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -- name: Remove Config - cli_config: - config: "{{ lines }}" - vars: - lines: | - delete service lldp interface - delete service lldp diff --git a/test/integration/targets/vyos_lldp_interfaces/tests/cli/deleted.yaml b/test/integration/targets/vyos_lldp_interfaces/tests/cli/deleted.yaml deleted file mode 100644 index c1efc1fbeb..0000000000 --- a/test/integration/targets/vyos_lldp_interfaces/tests/cli/deleted.yaml +++ /dev/null @@ -1,46 +0,0 @@ ---- -- debug: - msg: "Start vyos_lldp_interfaces deleted integration tests ansible_connection={{ ansible_connection }}" - -- include_tasks: _populate.yaml - -- block: - - name: Delete attributes of given LLDP interfaces. - vyos_lldp_interfaces: &deleted - config: - - name: 'eth1' - - name: 'eth2' - state: deleted - register: result - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that the correct set of commands were generated - assert: - that: - - "{{ deleted['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that the after dicts were correctly generated - assert: - that: - - "{{ deleted['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Delete attributes of given interfaces (IDEMPOTENT) - vyos_lldp_interfaces: *deleted - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result.changed == false" - - "result.commands|length == 0" - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ deleted['after'] | symmetric_difference(result['before']) |length == 0 }}" - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_lldp_interfaces/tests/cli/empty_config.yaml b/test/integration/targets/vyos_lldp_interfaces/tests/cli/empty_config.yaml deleted file mode 100644 index 6b5596ac28..0000000000 --- a/test/integration/targets/vyos_lldp_interfaces/tests/cli/empty_config.yaml +++ /dev/null @@ -1,36 +0,0 @@ ---- -- debug: - msg: "START vyos_lldp_interfaces empty_config integration tests on connection={{ ansible_connection }}" - -- name: Merged with empty config should give appropriate error message - vyos_lldp_interfaces: - config: - state: merged - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state merged' - -- name: Replaced with empty config should give appropriate error message - vyos_lldp_interfaces: - config: - state: replaced - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state replaced' - -- name: Overridden with empty config should give appropriate error message - vyos_lldp_interfaces: - config: - state: overridden - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state overridden' diff --git a/test/integration/targets/vyos_lldp_interfaces/tests/cli/merged.yaml b/test/integration/targets/vyos_lldp_interfaces/tests/cli/merged.yaml deleted file mode 100644 index a1db60fe54..0000000000 --- a/test/integration/targets/vyos_lldp_interfaces/tests/cli/merged.yaml +++ /dev/null @@ -1,58 +0,0 @@ ---- -- debug: - msg: "START vyos_lldp_interfaces merged integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- block: - - name: Merge the provided configuration with the exisiting running configuration - vyos_lldp_interfaces: &merged - config: - - name: 'eth1' - location: - civic_based: - country_code: 'US' - ca_info: - - ca_type: 0 - ca_value: 'ENGLISH' - - - name: 'eth2' - location: - coordinate_based: - altitude: 2200 - datum: 'WGS84' - longitude: '222.267255W' - latitude: '33.524449N' - state: merged - register: result - - - name: Assert that before dicts were correctly generated - assert: - that: "{{ merged['before'] | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that correct set of commands were generated - assert: - that: - - "{{ merged['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that after dicts was correctly generated - assert: - that: - - "{{ merged['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) - vyos_lldp_interfaces: *merged - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - - - name: Assert that before dicts were correctly generated - assert: - that: - - "{{ merged['after'] | symmetric_difference(result['before']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_lldp_interfaces/tests/cli/overridden.yaml b/test/integration/targets/vyos_lldp_interfaces/tests/cli/overridden.yaml deleted file mode 100644 index 16400126ab..0000000000 --- a/test/integration/targets/vyos_lldp_interfaces/tests/cli/overridden.yaml +++ /dev/null @@ -1,49 +0,0 @@ ---- -- debug: - msg: "START vyos_lldp_interfaces overridden integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _populate_intf.yaml - -- block: - - name: Overrides all device configuration with provided configuration - vyos_lldp_interfaces: &overridden - config: - - name: 'eth2' - location: - elin: '0000000911' - state: overridden - register: result - - - name: Assert that before dicts were correctly generated - assert: - that: - - "{{ populate_intf | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that correct commands were generated - assert: - that: - - "{{ overridden['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that after dicts were correctly generated - assert: - that: - - "{{ overridden['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Overrides all device configuration with provided configurations (IDEMPOTENT) - vyos_lldp_interfaces: *overridden - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - - - name: Assert that before dicts were correctly generated - assert: - that: - - "{{ overridden['after'] | symmetric_difference(result['before']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_lldp_interfaces/tests/cli/replaced.yaml b/test/integration/targets/vyos_lldp_interfaces/tests/cli/replaced.yaml deleted file mode 100644 index 028aa5e37e..0000000000 --- a/test/integration/targets/vyos_lldp_interfaces/tests/cli/replaced.yaml +++ /dev/null @@ -1,63 +0,0 @@ ---- -- debug: - msg: "START vyos_lldp_interfaces replaced integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Replace device configurations of listed LLDP interfaces with provided configurations - vyos_lldp_interfaces: &replaced - config: - - name: 'eth2' - enable: false - location: - civic_based: - country_code: 'US' - ca_info: - - ca_type: 0 - ca_value: 'ENGLISH' - - - name: 'eth1' - enable: false - location: - coordinate_based: - altitude: 2200 - datum: 'WGS84' - longitude: '222.267255W' - latitude: '33.524449N' - state: replaced - register: result - - - name: Assert that correct set of commands were generated - assert: - that: - - "{{ replaced['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that before dicts are correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that after dict is correctly generated - assert: - that: - - "{{ replaced['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Replace device configurations of listed LLDP interfaces with provided configurarions (IDEMPOTENT) - vyos_lldp_interfaces: *replaced - register: result - - - name: Assert that task was idempotent - assert: - that: - - "result['changed'] == false" - - - name: Assert that before dict is correctly generated - assert: - that: - - "{{ replaced['after'] | symmetric_difference(result['before']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_lldp_interfaces/tests/cli/rtt.yaml b/test/integration/targets/vyos_lldp_interfaces/tests/cli/rtt.yaml deleted file mode 100644 index 942e2d0210..0000000000 --- a/test/integration/targets/vyos_lldp_interfaces/tests/cli/rtt.yaml +++ /dev/null @@ -1,57 +0,0 @@ ---- -- debug: - msg: "START vyos_lldp_interfaces round trip integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- block: - - name: Apply the provided configuration (base config) - vyos_lldp_interfaces: - config: - - name: 'eth1' - location: - civic_based: - country_code: 'US' - ca_info: - - ca_type: 0 - ca_value: 'ENGLISH' - - state: merged - register: base_config - - - name: Gather lldp_interfaces facts - vyos_facts: - gather_subset: - - default - gather_network_resources: - - lldp_interfaces - - - name: Apply the provided configuration (config to be reverted) - vyos_lldp_interfaces: - config: - - name: 'eth2' - location: - coordinate_based: - altitude: 2200 - datum: 'WGS84' - longitude: '222.267255W' - latitude: '33.524449N' - state: merged - register: result - - - name: Assert that changes were applied - assert: - that: "{{ round_trip['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Revert back to base config using facts round trip - vyos_lldp_interfaces: - config: "{{ ansible_facts['network_resources']['lldp_interfaces'] }}" - state: overridden - register: revert - - - name: Assert that config was reverted - assert: - that: "{{ base_config['after'] | symmetric_difference(revert['after']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_lldp_interfaces/vars/main.yaml b/test/integration/targets/vyos_lldp_interfaces/vars/main.yaml deleted file mode 100644 index 169b0d5d4a..0000000000 --- a/test/integration/targets/vyos_lldp_interfaces/vars/main.yaml +++ /dev/null @@ -1,130 +0,0 @@ ---- -merged: - before: [] - - - commands: - - "set service lldp interface eth1 location civic-based country-code 'US'" - - "set service lldp interface eth1 location civic-based ca-type 0 ca-value 'ENGLISH'" - - "set service lldp interface eth1" - - "set service lldp interface eth2 location coordinate-based latitude '33.524449N'" - - "set service lldp interface eth2 location coordinate-based altitude '2200'" - - "set service lldp interface eth2 location coordinate-based datum 'WGS84'" - - "set service lldp interface eth2 location coordinate-based longitude '222.267255W'" - - "set service lldp interface eth2 location coordinate-based latitude '33.524449N'" - - "set service lldp interface eth2 location coordinate-based altitude '2200'" - - "set service lldp interface eth2 location coordinate-based datum 'WGS84'" - - "set service lldp interface eth2 location coordinate-based longitude '222.267255W'" - - "set service lldp interface eth2" - - after: - - name: 'eth1' - location: - civic_based: - country_code: 'US' - ca_info: - - ca_type: 0 - ca_value: 'ENGLISH' - - - name: 'eth2' - location: - coordinate_based: - altitude: 2200 - datum: 'WGS84' - longitude: '222.267255W' - latitude: '33.524449N' - -populate: - - name: 'eth1' - location: - civic_based: - country_code: 'US' - ca_info: - - ca_type: 0 - ca_value: 'ENGLISH' - - - name: 'eth2' - location: - coordinate_based: - altitude: 2200 - datum: 'WGS84' - longitude: '222.267255W' - latitude: '33.524449N' - -replaced: - commands: - - "delete service lldp interface eth2 location" - - "set service lldp interface eth2 'disable'" - - "set service lldp interface eth2 location civic-based country-code 'US'" - - "set service lldp interface eth2 location civic-based ca-type 0 ca-value 'ENGLISH'" - - "delete service lldp interface eth1 location" - - "set service lldp interface eth1 'disable'" - - "set service lldp interface eth1 location coordinate-based latitude '33.524449N'" - - "set service lldp interface eth1 location coordinate-based altitude '2200'" - - "set service lldp interface eth1 location coordinate-based datum 'WGS84'" - - "set service lldp interface eth1 location coordinate-based longitude '222.267255W'" - - after: - - name: 'eth2' - enable: false - location: - civic_based: - country_code: 'US' - ca_info: - - ca_type: 0 - ca_value: 'ENGLISH' - - - name: 'eth1' - enable: false - location: - coordinate_based: - altitude: 2200 - datum: 'WGS84' - longitude: '222.267255W' - latitude: '33.524449N' - -populate_intf: - - name: 'eth2' - enable: false - location: - civic_based: - country_code: 'US' - ca_info: - - ca_type: 0 - ca_value: 'ENGLISH' - -overridden: - commands: - - "delete service lldp interface eth2 location" - - "delete service lldp interface eth2 'disable'" - - "set service lldp interface eth2 location elin '0000000911'" - - after: - - name: 'eth2' - location: - elin: 0000000911 - -deleted: - commands: - - "delete service lldp interface eth1" - - "delete service lldp interface eth2" - - after: [] - -round_trip: - after: - - name: 'eth1' - location: - civic_based: - country_code: 'US' - ca_info: - - ca_type: 0 - ca_value: 'ENGLISH' - - - name: 'eth2' - location: - coordinate_based: - altitude: 2200 - datum: 'WGS84' - longitude: '222.267255W' - latitude: '33.524449N' diff --git a/test/integration/targets/vyos_logging/aliases b/test/integration/targets/vyos_logging/aliases deleted file mode 100644 index 8071e1f75b..0000000000 --- a/test/integration/targets/vyos_logging/aliases +++ /dev/null @@ -1 +0,0 @@ -shippable/vyos/group1 diff --git a/test/integration/targets/vyos_logging/defaults/main.yaml b/test/integration/targets/vyos_logging/defaults/main.yaml deleted file mode 100644 index 9ef5ba5165..0000000000 --- a/test/integration/targets/vyos_logging/defaults/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -testcase: "*" -test_items: [] diff --git a/test/integration/targets/vyos_logging/tasks/cli.yaml b/test/integration/targets/vyos_logging/tasks/cli.yaml deleted file mode 100644 index 890d3acf3e..0000000000 --- a/test/integration/targets/vyos_logging/tasks/cli.yaml +++ /dev/null @@ -1,22 +0,0 @@ ---- -- name: collect all cli test cases - find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - register: test_cases - delegate_to: localhost - -- name: set test_items - set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - -- name: run test case (connection=network_cli) - include: "{{ test_case_to_run }} ansible_connection=network_cli" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - -- name: run test case (connection=local) - include: "{{ test_case_to_run }} ansible_connection=local" - with_first_found: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run diff --git a/test/integration/targets/vyos_logging/tasks/main.yaml b/test/integration/targets/vyos_logging/tasks/main.yaml deleted file mode 100644 index d4cf26fc4a..0000000000 --- a/test/integration/targets/vyos_logging/tasks/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -- {include: cli.yaml, tags: ['cli']} diff --git a/test/integration/targets/vyos_logging/tests/cli/basic.yaml b/test/integration/targets/vyos_logging/tests/cli/basic.yaml deleted file mode 100644 index d8a1014b5f..0000000000 --- a/test/integration/targets/vyos_logging/tests/cli/basic.yaml +++ /dev/null @@ -1,126 +0,0 @@ ---- -- debug: msg="START cli/basic.yaml on connection={{ ansible_connection }}" - -- name: set-up logging - vyos_logging: - dest: console - facility: all - level: info - state: present - register: result - -- assert: - that: - - 'result.changed == true' - - '"set system syslog console facility all level info" in result.commands' - -- name: set-up logging again (idempotent) - vyos_logging: - dest: console - facility: all - level: info - state: present - register: result - -- assert: - that: - - 'result.changed == false' - -- name: file logging - vyos_logging: - dest: file - name: test - facility: all - level: notice - state: present - register: result - -- assert: - that: - - 'result.changed == true' - - '"set system syslog file test facility all level notice" in result.commands' - -- name: file logging again (idempotent) - vyos_logging: - dest: file - name: test - facility: all - level: notice - state: present - register: result - -- assert: - that: - - 'result.changed == false' - -- name: delete logging - vyos_logging: - dest: file - name: test - facility: all - level: notice - state: absent - register: result - -- assert: - that: - - 'result.changed == true' - - '"delete system syslog file test facility all level notice" in result.commands' - -- name: delete logging again (idempotent) - vyos_logging: - dest: file - name: test - facility: all - level: notice - state: absent - register: result - -- assert: - that: - - 'result.changed == false' - -- name: Add logging collections - vyos_logging: - aggregate: - - {dest: file, name: test1, facility: all, level: info} - - {dest: file, name: test2, facility: news, level: debug} - state: present - register: result - -- assert: - that: - - 'result.changed == true' - - '"set system syslog file test1 facility all level info" in result.commands' - - '"set system syslog file test2 facility news level debug" in result.commands' - -- name: Add and remove logging collections with overrides - vyos_logging: - aggregate: - - {dest: console, facility: all, level: info} - - {dest: file, name: test1, facility: all, level: info, state: absent} - - {dest: console, facility: daemon, level: warning} - state: present - register: result - -- assert: - that: - - 'result.changed == true' - - '"delete system syslog file test1 facility all level info" in result.commands' - - '"set system syslog console facility daemon level warning" in result.commands' - -- name: Remove logging collections - vyos_logging: - aggregate: - - {dest: console, facility: all, level: info} - - {dest: console, facility: daemon, level: warning} - - {dest: file, name: test2, facility: news, level: debug} - state: absent - register: result - -- assert: - that: - - 'result.changed == true' - - '"delete system syslog console facility all level info" in result.commands' - - '"delete system syslog console facility daemon level warning" in result.commands' - - '"delete system syslog file test2 facility news level debug" in result.commands' diff --git a/test/integration/targets/vyos_logging/tests/cli/net_logging.yaml b/test/integration/targets/vyos_logging/tests/cli/net_logging.yaml deleted file mode 100644 index 7c62d72f23..0000000000 --- a/test/integration/targets/vyos_logging/tests/cli/net_logging.yaml +++ /dev/null @@ -1,39 +0,0 @@ ---- -- debug: msg="START vyos cli/net_logging.yaml on connection={{ ansible_connection }}" - -# Add minimal testcase to check args are passed correctly to -# implementation module and module run is successful. - -- name: delete logging - setup - net_logging: - dest: file - name: test - facility: all - level: notice - state: absent - register: result - -- name: file logging using platform agnostic module - net_logging: - dest: file - name: test - facility: all - level: notice - state: present - register: result - -- assert: - that: - - 'result.changed == true' - - '"set system syslog file test facility all level notice" in result.commands' - -- name: delete logging - teardown - net_logging: - dest: file - name: test - facility: all - level: notice - state: absent - register: result - -- debug: msg="END vyos cli/net_logging.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/vyos_smoke/defaults/main.yaml b/test/integration/targets/vyos_smoke/defaults/main.yaml deleted file mode 100644 index 9ef5ba5165..0000000000 --- a/test/integration/targets/vyos_smoke/defaults/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -testcase: "*" -test_items: [] diff --git a/test/integration/targets/vyos_smoke/tasks/cli.yaml b/test/integration/targets/vyos_smoke/tasks/cli.yaml deleted file mode 100644 index 890d3acf3e..0000000000 --- a/test/integration/targets/vyos_smoke/tasks/cli.yaml +++ /dev/null @@ -1,22 +0,0 @@ ---- -- name: collect all cli test cases - find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - register: test_cases - delegate_to: localhost - -- name: set test_items - set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - -- name: run test case (connection=network_cli) - include: "{{ test_case_to_run }} ansible_connection=network_cli" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - -- name: run test case (connection=local) - include: "{{ test_case_to_run }} ansible_connection=local" - with_first_found: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run diff --git a/test/integration/targets/vyos_smoke/tasks/main.yaml b/test/integration/targets/vyos_smoke/tasks/main.yaml deleted file mode 100644 index d4cf26fc4a..0000000000 --- a/test/integration/targets/vyos_smoke/tasks/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -- {include: cli.yaml, tags: ['cli']} diff --git a/test/integration/targets/vyos_smoke/tests/cli/common_config.yaml b/test/integration/targets/vyos_smoke/tests/cli/common_config.yaml deleted file mode 100644 index 8cbab2daf2..0000000000 --- a/test/integration/targets/vyos_smoke/tests/cli/common_config.yaml +++ /dev/null @@ -1,11 +0,0 @@ ---- -# vyos.py in plugins and module_utils/network covered by these as well -# hit NetworkConfig -- name: configure simple config command - vyos_config: - lines: set system host-name smoke - -- name: return host name to inventory_hostname - vyos_config: - lines: set system host-name {{ inventory_hostname_short }} - match: none diff --git a/test/integration/targets/vyos_smoke/tests/cli/common_utils.yaml b/test/integration/targets/vyos_smoke/tests/cli/common_utils.yaml deleted file mode 100644 index f1fe144ba9..0000000000 --- a/test/integration/targets/vyos_smoke/tests/cli/common_utils.yaml +++ /dev/null @@ -1,50 +0,0 @@ ---- -# vyos.py in plugins and module_utils/network covered by these as well -# remove_default_spec() hit by multiple plays - -# hit ComplexList -- name: get output for single command - vyos_command: - commands: - - show version - register: result - -- assert: - that: - - result.changed == false - - result.stdout is defined - - result.stdout_lines is defined - -# hit conditional() - used for declarative intent -# Note, this can't be run on AWS because fully testing the vyos_interface dependencies -# requires the ability to create and remove interfaces other than eth0 -- name: enable eth1 - vyos_interface: - name: eth1 - enabled: true - state: present - register: result - -- name: Check intent arguments - vyos_interface: - name: eth1 - state: up - register: result - -- name: Check intent arguments (failed condition) - vyos_interface: - name: eth1 - state: down - ignore_errors: true - register: result - -- assert: - that: - - "result.failed == true" - - "'state eq(down)' in result.failed_conditions" - -- name: Config + intent - vyos_interface: - name: eth1 - enabled: false - state: down diff --git a/test/integration/targets/vyos_smoke/tests/cli/misc_tests.yaml b/test/integration/targets/vyos_smoke/tests/cli/misc_tests.yaml deleted file mode 100644 index 4dfa29076a..0000000000 --- a/test/integration/targets/vyos_smoke/tests/cli/misc_tests.yaml +++ /dev/null @@ -1,14 +0,0 @@ ---- -# hit check conditional in module_utils.network.vyos -> load_config() -- name: configure simple config command - vyos_config: - lines: set system host-name check-test - check_mode: true - -- name: get host name - vyos_command: - commands: show host name - register: result - -- assert: - that: '"check-test" not in result.stdout' diff --git a/test/integration/targets/vyos_static_route/aliases b/test/integration/targets/vyos_static_route/aliases deleted file mode 100644 index 8071e1f75b..0000000000 --- a/test/integration/targets/vyos_static_route/aliases +++ /dev/null @@ -1 +0,0 @@ -shippable/vyos/group1 diff --git a/test/integration/targets/vyos_static_route/defaults/main.yaml b/test/integration/targets/vyos_static_route/defaults/main.yaml deleted file mode 100644 index 9ef5ba5165..0000000000 --- a/test/integration/targets/vyos_static_route/defaults/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -testcase: "*" -test_items: [] diff --git a/test/integration/targets/vyos_static_route/tasks/cli.yaml b/test/integration/targets/vyos_static_route/tasks/cli.yaml deleted file mode 100644 index 890d3acf3e..0000000000 --- a/test/integration/targets/vyos_static_route/tasks/cli.yaml +++ /dev/null @@ -1,22 +0,0 @@ ---- -- name: collect all cli test cases - find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - register: test_cases - delegate_to: localhost - -- name: set test_items - set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - -- name: run test case (connection=network_cli) - include: "{{ test_case_to_run }} ansible_connection=network_cli" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - -- name: run test case (connection=local) - include: "{{ test_case_to_run }} ansible_connection=local" - with_first_found: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run diff --git a/test/integration/targets/vyos_static_route/tasks/main.yaml b/test/integration/targets/vyos_static_route/tasks/main.yaml deleted file mode 100644 index d4cf26fc4a..0000000000 --- a/test/integration/targets/vyos_static_route/tasks/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -- {include: cli.yaml, tags: ['cli']} diff --git a/test/integration/targets/vyos_static_route/tests/cli/basic.yaml b/test/integration/targets/vyos_static_route/tests/cli/basic.yaml deleted file mode 100644 index 2aa69a4483..0000000000 --- a/test/integration/targets/vyos_static_route/tests/cli/basic.yaml +++ /dev/null @@ -1,120 +0,0 @@ ---- -- debug: msg="START cli/basic.yaml on connection={{ ansible_connection }}" - -- name: create static route - vyos_static_route: - prefix: 172.24.0.0/24 - next_hop: 192.168.42.64 - state: present - register: result - -- assert: - that: - - 'result.changed == true' - - '"set protocols static route 172.24.0.0/24 next-hop 192.168.42.64" in result.commands' - -- name: create static route again (idempotent) - vyos_static_route: - prefix: 172.24.0.0 - mask: 24 - next_hop: 192.168.42.64 - state: present - register: result - -- assert: - that: - - 'result.changed == false' - -- name: modify admin distance of static route - vyos_static_route: - prefix: 172.24.0.0/24 - next_hop: 192.168.42.64 - admin_distance: 1 - state: present - register: result - -- assert: - that: - - 'result.changed == true' - - '"set protocols static route 172.24.0.0/24 next-hop 192.168.42.64 distance 1" in result.commands' - -- name: modify admin distance of static route again (idempotent) - vyos_static_route: - prefix: 172.24.0.0 - mask: 24 - next_hop: 192.168.42.64 - admin_distance: 1 - state: present - register: result - -- assert: - that: - - 'result.changed == false' - -- name: delete static route - vyos_static_route: - prefix: 172.24.0.0/24 - next_hop: 192.168.42.64 - admin_distance: 1 - state: absent - register: result - -- assert: - that: - - 'result.changed == true' - - '"delete protocols static route 172.24.0.0/24" in result.commands' - -- name: delete static route again (idempotent) - vyos_static_route: - prefix: 172.24.0.0/24 - next_hop: 192.168.42.64 - admin_distance: 1 - state: absent - register: result - -- assert: - that: - - 'result.changed == false' - -- name: Add static route collections - vyos_static_route: - aggregate: - - {prefix: 172.24.1.0/24, next_hop: 192.168.42.64} - - {prefix: 172.24.2.0, mask: 24, next_hop: 192.168.42.64} - state: present - register: result - -- assert: - that: - - 'result.changed == true' - - '"set protocols static route 172.24.1.0/24 next-hop 192.168.42.64" in result.commands' - - '"set protocols static route 172.24.2.0/24 next-hop 192.168.42.64" in result.commands' - -- name: Add and remove static route collections with overrides - vyos_static_route: - aggregate: - - {prefix: 172.24.1.0/24, next_hop: 192.168.42.64} - - {prefix: 172.24.2.0/24, next_hop: 192.168.42.64, state: absent} - - {prefix: 172.24.3.0/24, next_hop: 192.168.42.64} - state: present - register: result - -- assert: - that: - - 'result.changed == true' - - '"delete protocols static route 172.24.2.0/24" in result.commands' - - '"set protocols static route 172.24.3.0/24 next-hop 192.168.42.64" in result.commands' - -- name: Remove static route collections - vyos_static_route: - aggregate: - - {prefix: 172.24.1.0/24, next_hop: 192.168.42.64} - - {prefix: 172.24.3.0/24, next_hop: 192.168.42.64} - state: absent - register: result - -- assert: - that: - - 'result.changed == true' - - '"delete protocols static route 172.24.1.0/24" in result.commands' - - '"delete protocols static route 172.24.3.0/24" in result.commands' diff --git a/test/integration/targets/vyos_static_route/tests/cli/net_static_route.yaml b/test/integration/targets/vyos_static_route/tests/cli/net_static_route.yaml deleted file mode 100644 index e2529ebccd..0000000000 --- a/test/integration/targets/vyos_static_route/tests/cli/net_static_route.yaml +++ /dev/null @@ -1,33 +0,0 @@ ---- -- debug: msg="START vyos cli/net_static_route.yaml on connection={{ ansible_connection }}" - -# Add minimal testcase to check args are passed correctly to -# implementation module and module run is successful. - -- name: delete static route - setup - net_static_route: - prefix: 172.24.0.0/24 - next_hop: 192.168.42.64 - state: absent - register: result - -- name: create static route using platform agnostic module - net_static_route: - prefix: 172.24.0.0/24 - next_hop: 192.168.42.64 - state: present - register: result - -- assert: - that: - - 'result.changed == true' - - '"set protocols static route 172.24.0.0/24 next-hop 192.168.42.64" in result.commands' - -- name: delete static route - teardown - net_static_route: - prefix: 172.24.0.0/24 - next_hop: 192.168.42.64 - state: absent - register: result - -- debug: msg="END vyos cli/net_static_route.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/vyos_static_routes/aliases b/test/integration/targets/vyos_static_routes/aliases deleted file mode 100644 index 8071e1f75b..0000000000 --- a/test/integration/targets/vyos_static_routes/aliases +++ /dev/null @@ -1 +0,0 @@ -shippable/vyos/group1 diff --git a/test/integration/targets/vyos_static_routes/defaults/main.yaml b/test/integration/targets/vyos_static_routes/defaults/main.yaml deleted file mode 100644 index 164afead28..0000000000 --- a/test/integration/targets/vyos_static_routes/defaults/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -testcase: "[^_].*" -test_items: [] diff --git a/test/integration/targets/vyos_static_routes/meta/main.yaml b/test/integration/targets/vyos_static_routes/meta/main.yaml deleted file mode 100644 index e69de29bb2..0000000000 --- a/test/integration/targets/vyos_static_routes/meta/main.yaml +++ /dev/null diff --git a/test/integration/targets/vyos_static_routes/tasks/cli.yaml b/test/integration/targets/vyos_static_routes/tasks/cli.yaml deleted file mode 100644 index 655e51ee63..0000000000 --- a/test/integration/targets/vyos_static_routes/tasks/cli.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -- name: Collect all cli test cases - find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - use_regex: true - register: test_cases - delegate_to: localhost - -- name: Set test_items - set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test case (connection=network_cli) - include: "{{ test_case_to_run }}" - vars: - ansible_connection: network_cli - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run diff --git a/test/integration/targets/vyos_static_routes/tasks/main.yaml b/test/integration/targets/vyos_static_routes/tasks/main.yaml deleted file mode 100644 index 415c99d8b1..0000000000 --- a/test/integration/targets/vyos_static_routes/tasks/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -- { include: cli.yaml, tags: ['cli'] } diff --git a/test/integration/targets/vyos_static_routes/tests/cli/_parsed_config.cfg b/test/integration/targets/vyos_static_routes/tests/cli/_parsed_config.cfg deleted file mode 100644 index b2ecd4e9c0..0000000000 --- a/test/integration/targets/vyos_static_routes/tests/cli/_parsed_config.cfg +++ /dev/null @@ -1,6 +0,0 @@ -set protocols static route 192.0.2.32/28 next-hop '192.0.2.9' -set protocols static route 192.0.2.32/28 next-hop '192.0.2.10' -set protocols static route 192.0.2.32/28 blackhole -set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1' -set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2' -set protocols static route6 2001:db8:1000::/36 blackhole distance '2' diff --git a/test/integration/targets/vyos_static_routes/tests/cli/_populate.yaml b/test/integration/targets/vyos_static_routes/tests/cli/_populate.yaml deleted file mode 100644 index c5b02f73eb..0000000000 --- a/test/integration/targets/vyos_static_routes/tests/cli/_populate.yaml +++ /dev/null @@ -1,14 +0,0 @@ ---- -- name: Setup - cli_config: - config: "{{ lines }}" - vars: - lines: | - set protocols static route 192.0.2.32/28 next-hop '192.0.2.10' - set protocols static route 192.0.2.32/28 next-hop '192.0.2.9' - set protocols static route 192.0.2.32/28 blackhole - set protocols static route 192.0.2.32/28 - set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1' - set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2' - set protocols static route6 2001:db8:1000::/36 blackhole distance '2' - set protocols static route6 2001:db8:1000::/36 diff --git a/test/integration/targets/vyos_static_routes/tests/cli/_remove_config.yaml b/test/integration/targets/vyos_static_routes/tests/cli/_remove_config.yaml deleted file mode 100644 index 026ef4580e..0000000000 --- a/test/integration/targets/vyos_static_routes/tests/cli/_remove_config.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -- name: Remove Config - cli_config: - config: "{{ lines }}" - vars: - lines: | - delete protocols static route - delete protocols static route6 diff --git a/test/integration/targets/vyos_static_routes/tests/cli/deleted.yaml b/test/integration/targets/vyos_static_routes/tests/cli/deleted.yaml deleted file mode 100644 index b4bad0cc7c..0000000000 --- a/test/integration/targets/vyos_static_routes/tests/cli/deleted.yaml +++ /dev/null @@ -1,51 +0,0 @@ ---- -- debug: - msg: "Start vyos_static_routes deleted integration tests ansible_connection={{ ansible_connection }}" - -- include_tasks: _populate.yaml - -- block: - - name: Delete static route based on destiation. - vyos_static_routes: &deleted_dest - config: - - address_families: - - afi: 'ipv4' - routes: - - dest: '192.0.2.32/28' - - afi: 'ipv6' - routes: - - dest: '2001:db8:1000::/36' - state: deleted - register: result - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that the correct set of commands were generated - assert: - that: - - "{{ deleted_dest['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that the after dicts were correctly generated - assert: - that: - - "{{ deleted_dest['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Delete attributes of given interfaces (IDEMPOTENT) - vyos_static_routes: *deleted_dest - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result.changed == false" - - "result.commands|length == 0" - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ deleted_dest['after'] | symmetric_difference(result['before']) |length == 0 }}" - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_static_routes/tests/cli/deleted_afi.yaml b/test/integration/targets/vyos_static_routes/tests/cli/deleted_afi.yaml deleted file mode 100644 index 3b6c7e017f..0000000000 --- a/test/integration/targets/vyos_static_routes/tests/cli/deleted_afi.yaml +++ /dev/null @@ -1,47 +0,0 @@ ---- -- debug: - msg: "Start vyos_static_routes deleted integration tests ansible_connection={{ ansible_connection }}" - -- include_tasks: _populate.yaml - -- block: - - name: Delete static route based on afi. - vyos_static_routes: &deleted_afi - config: - - address_families: - - afi: 'ipv4' - - afi: 'ipv6' - state: deleted - register: result - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that the correct set of commands were generated - assert: - that: - - "{{ deleted_afi_all['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that the after dicts were correctly generated - assert: - that: - - "{{ deleted_afi_all['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Delete attributes of given interfaces (IDEMPOTENT) - vyos_static_routes: *deleted_afi - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result.changed == false" - - "result.commands|length == 0" - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ deleted_afi_all['after'] | symmetric_difference(result['before']) |length == 0 }}" - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_static_routes/tests/cli/deleted_all.yaml b/test/integration/targets/vyos_static_routes/tests/cli/deleted_all.yaml deleted file mode 100644 index 39e3f14413..0000000000 --- a/test/integration/targets/vyos_static_routes/tests/cli/deleted_all.yaml +++ /dev/null @@ -1,44 +0,0 @@ ---- -- debug: - msg: "Start vyos_static_routes deleted integration tests ansible_connection={{ ansible_connection }}" - -- include_tasks: _populate.yaml - -- block: - - name: Delete all the static routes. - vyos_static_routes: &deleted_all - config: - state: deleted - register: result - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that the correct set of commands were generated - assert: - that: - - "{{ deleted_afi_all['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that the after dicts were correctly generated - assert: - that: - - "{{ deleted_afi_all['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Delete attributes of given interfaces (IDEMPOTENT) - vyos_static_routes: *deleted_all - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result.changed == false" - - "result.commands|length == 0" - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ deleted_afi_all['after'] | symmetric_difference(result['before']) |length == 0 }}" - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_static_routes/tests/cli/deleted_nh.yaml b/test/integration/targets/vyos_static_routes/tests/cli/deleted_nh.yaml deleted file mode 100644 index 976b384e79..0000000000 --- a/test/integration/targets/vyos_static_routes/tests/cli/deleted_nh.yaml +++ /dev/null @@ -1,55 +0,0 @@ ---- -- debug: - msg: "Start vyos_static_routes deleted integration tests ansible_connection={{ ansible_connection }}" - -- include_tasks: _populate.yaml - -- block: - - name: Delete static route based on next_hop. - vyos_static_routes: &deleted_nh - config: - - address_families: - - afi: 'ipv4' - routes: - - dest: '192.0.2.32/28' - next_hops: - - forward_router_address: '192.0.2.9' - - afi: 'ipv6' - routes: - - dest: '2001:db8:1000::/36' - next_hops: - - forward_router_address: '2001:db8:2000:2::1' - state: deleted - register: result - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that the correct set of commands were generated - assert: - that: - - "{{ deleted_nh['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that the after dicts were correctly generated - assert: - that: - - "{{ deleted_nh['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Delete attributes of given interfaces (IDEMPOTENT) - vyos_static_routes: *deleted_nh - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result.changed == false" - - "result.commands|length == 0" - - - name: Assert that the before dicts were correctly generated - assert: - that: - - "{{ deleted_nh['after'] | symmetric_difference(result['before']) |length == 0 }}" - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_static_routes/tests/cli/empty_config.yaml b/test/integration/targets/vyos_static_routes/tests/cli/empty_config.yaml deleted file mode 100644 index 96bec582a5..0000000000 --- a/test/integration/targets/vyos_static_routes/tests/cli/empty_config.yaml +++ /dev/null @@ -1,58 +0,0 @@ ---- -- debug: - msg: "START vyos_static_routes empty_config integration tests on connection={{ ansible_connection }}" - -- name: Merged with empty config should give appropriate error message - vyos_static_routes: - config: - state: merged - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state merged' - -- name: Replaced with empty config should give appropriate error message - vyos_static_routes: - config: - state: replaced - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state replaced' - -- name: Overridden with empty config should give appropriate error message - vyos_static_routes: - config: - state: overridden - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state overridden' - -- name: Parsed with empty running_config should give appropriate error message - vyos_static_routes: - running_config: - state: parsed - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of running_config parameter must not be empty for state parsed' - -- name: Rendered with empty config should give appropriate error message - vyos_static_routes: - config: - state: rendered - register: result - ignore_errors: true - -- assert: - that: - - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/test/integration/targets/vyos_static_routes/tests/cli/gathered.yaml b/test/integration/targets/vyos_static_routes/tests/cli/gathered.yaml deleted file mode 100644 index 58a4279ec2..0000000000 --- a/test/integration/targets/vyos_static_routes/tests/cli/gathered.yaml +++ /dev/null @@ -1,31 +0,0 @@ ---- -- debug: - msg: "START vyos_static_routes gathered integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Merge the provided configuration with the exisiting running configuration - vyos_static_routes: &gathered - config: - state: gathered - register: result - - - name: Assert that gathered dicts was correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['gathered']) |length == 0 }}" - - - name: Gather the existing running configuration (IDEMPOTENT) - vyos_static_routes: *gathered - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_static_routes/tests/cli/merged.yaml b/test/integration/targets/vyos_static_routes/tests/cli/merged.yaml deleted file mode 100644 index e9399ad77b..0000000000 --- a/test/integration/targets/vyos_static_routes/tests/cli/merged.yaml +++ /dev/null @@ -1,61 +0,0 @@ ---- -- debug: - msg: "START vyos_static_routes merged integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- block: - - name: Merge the provided configuration with the exisiting running configuration - vyos_static_routes: &merged - config: - - address_families: - - afi: 'ipv4' - routes: - - dest: 192.0.2.32/28 - blackhole_config: - type: 'blackhole' - next_hops: - - forward_router_address: 192.0.2.10 - - forward_router_address: 192.0.2.9 - - address_families: - - afi: 'ipv6' - routes: - - dest: 2001:db8:1000::/36 - blackhole_config: - distance: 2 - next_hops: - - forward_router_address: 2001:db8:2000:2::1 - - forward_router_address: 2001:db8:2000:2::2 - state: merged - register: result - - - name: Assert that before dicts were correctly generated - assert: - that: "{{ merged['before'] | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that correct set of commands were generated - assert: - that: - - "{{ merged['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that after dicts was correctly generated - assert: - that: - - "{{ merged['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) - vyos_static_routes: *merged - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - - - name: Assert that before dicts were correctly generated - assert: - that: - - "{{ merged['after'] | symmetric_difference(result['before']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_static_routes/tests/cli/overridden.yaml b/test/integration/targets/vyos_static_routes/tests/cli/overridden.yaml deleted file mode 100644 index 9e838d7bcf..0000000000 --- a/test/integration/targets/vyos_static_routes/tests/cli/overridden.yaml +++ /dev/null @@ -1,52 +0,0 @@ ---- -- debug: - msg: "START vyos_static_routes overridden integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Overrides all device configuration with provided configuration - vyos_static_routes: &overridden - config: - - address_families: - - afi: 'ipv4' - routes: - - dest: 198.0.2.48/28 - next_hops: - - forward_router_address: 192.0.2.18 - state: overridden - register: result - - - name: Assert that before dicts were correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that correct commands were generated - assert: - that: - - "{{ overridden['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that after dicts were correctly generated - assert: - that: - - "{{ overridden['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Overrides all device configuration with provided configurations (IDEMPOTENT) - vyos_static_routes: *overridden - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - - - name: Assert that before dicts were correctly generated - assert: - that: - - "{{ overridden['after'] | symmetric_difference(result['before']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_static_routes/tests/cli/parsed.yaml b/test/integration/targets/vyos_static_routes/tests/cli/parsed.yaml deleted file mode 100644 index 18e5781e71..0000000000 --- a/test/integration/targets/vyos_static_routes/tests/cli/parsed.yaml +++ /dev/null @@ -1,39 +0,0 @@ ---- -- debug: - msg: "START vyos_static_routes parsed integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Gather static_routes facts - vyos_facts: - gather_subset: - - default - gather_network_resources: - - static_routes - register: static_routes_facts - - - name: Provide the running configuration for parsing (config to be parsed) - vyos_static_routes: &parsed - running_config: - "{{ lookup('file', '_parsed_config.cfg') }}" - state: parsed - register: result - - - name: Assert that correct parsing done - assert: - that: "{{ ansible_facts['network_resources']['static_routes'] | symmetric_difference(result['parsed']) |length == 0 }}" - - - name: Gather the existing running configuration (IDEMPOTENT) - vyos_static_routes: *parsed - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_static_routes/tests/cli/rendered.yaml b/test/integration/targets/vyos_static_routes/tests/cli/rendered.yaml deleted file mode 100644 index 80b90ebe5a..0000000000 --- a/test/integration/targets/vyos_static_routes/tests/cli/rendered.yaml +++ /dev/null @@ -1,49 +0,0 @@ ---- -- debug: - msg: "START vyos_static_routes rendered integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Structure provided configuration into device specific commands - vyos_static_routes: &rendered - config: - - address_families: - - afi: 'ipv4' - routes: - - dest: 192.0.2.32/28 - blackhole_config: - type: 'blackhole' - next_hops: - - forward_router_address: 192.0.2.10 - - forward_router_address: 192.0.2.9 - - address_families: - - afi: 'ipv6' - routes: - - dest: 2001:db8:1000::/36 - blackhole_config: - distance: 2 - next_hops: - - forward_router_address: 2001:db8:2000:2::1 - - forward_router_address: 2001:db8:2000:2::2 - state: rendered - register: result - - - name: Assert that correct set of commands were generated - assert: - that: - - "{{ rendered['commands'] | symmetric_difference(result['rendered']) |length == 0 }}" - - - name: Structure provided configuration into device specific commands (IDEMPOTENT) - vyos_static_routes: *rendered - register: result - - - name: Assert that the previous task was idempotent - assert: - that: - - "result['changed'] == false" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_static_routes/tests/cli/replaced.yaml b/test/integration/targets/vyos_static_routes/tests/cli/replaced.yaml deleted file mode 100644 index 1daf406945..0000000000 --- a/test/integration/targets/vyos_static_routes/tests/cli/replaced.yaml +++ /dev/null @@ -1,56 +0,0 @@ ---- -- debug: - msg: "START vyos_static_routes replaced integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- include_tasks: _populate.yaml - -- block: - - name: Replace device configurations of listed static routes with provided configurations - vyos_static_routes: &replaced - config: - - address_families: - - afi: 'ipv4' - routes: - - dest: 192.0.2.32/28 - blackhole_config: - distance: 2 - next_hops: - - forward_router_address: 192.0.2.7 - - forward_router_address: 192.0.2.8 - - forward_router_address: 192.0.2.9 - state: replaced - register: result - - - name: Assert that correct set of commands were generated - assert: - that: - - "{{ replaced['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - - - name: Assert that before dicts are correctly generated - assert: - that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - - - name: Assert that after dict is correctly generated - assert: - that: - - "{{ replaced['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Replace device configurations of listed static routes with provided configurarions (IDEMPOTENT) - vyos_static_routes: *replaced - register: result - - - name: Assert that task was idempotent - assert: - that: - - "result['changed'] == false" - - - name: Assert that before dict is correctly generated - assert: - that: - - "{{ replaced['after'] | symmetric_difference(result['before']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_static_routes/tests/cli/rtt.yaml b/test/integration/targets/vyos_static_routes/tests/cli/rtt.yaml deleted file mode 100644 index 81ece8b383..0000000000 --- a/test/integration/targets/vyos_static_routes/tests/cli/rtt.yaml +++ /dev/null @@ -1,71 +0,0 @@ ---- -- debug: - msg: "START vyos_static_routes round trip integration tests on connection={{ ansible_connection }}" - -- include_tasks: _remove_config.yaml - -- block: - - name: Apply the provided configuration (base config) - vyos_static_routes: - config: - - address_families: - - afi: 'ipv4' - routes: - - dest: 192.0.2.32/28 - blackhole_config: - type: 'blackhole' - next_hops: - - forward_router_address: 192.0.2.10 - - forward_router_address: 192.0.2.9 - - address_families: - - afi: 'ipv6' - routes: - - dest: 2001:db8:1000::/36 - blackhole_config: - distance: 2 - next_hops: - - forward_router_address: 2001:db8:2000:2::1 - - forward_router_address: 2001:db8:2000:2::2 - - state: merged - register: base_config - - - name: Gather static_routes facts - vyos_facts: - gather_subset: - - default - gather_network_resources: - - static_routes - - - name: Apply the provided configuration (config to be reverted) - vyos_static_routes: - config: - - address_families: - - afi: 'ipv4' - routes: - - dest: 192.0.2.32/28 - blackhole_config: - distance: 2 - next_hops: - - forward_router_address: 192.0.2.7 - - forward_router_address: 192.0.2.8 - - forward_router_address: 192.0.2.9 - state: merged - register: result - - - name: Assert that changes were applied - assert: - that: "{{ round_trip['after'] | symmetric_difference(result['after']) |length == 0 }}" - - - name: Revert back to base config using facts round trip - vyos_static_routes: - config: "{{ ansible_facts['network_resources']['static_routes'] }}" - state: overridden - register: revert - - - name: Assert that config was reverted - assert: - that: "{{ base_config['after'] | symmetric_difference(revert['after']) |length == 0 }}" - - always: - - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_static_routes/vars/main.yaml b/test/integration/targets/vyos_static_routes/vars/main.yaml deleted file mode 100644 index eeed9bbe90..0000000000 --- a/test/integration/targets/vyos_static_routes/vars/main.yaml +++ /dev/null @@ -1,163 +0,0 @@ ---- -merged: - before: [] - - commands: - - "set protocols static route 192.0.2.32/28 next-hop '192.0.2.10'" - - "set protocols static route 192.0.2.32/28 next-hop '192.0.2.9'" - - "set protocols static route 192.0.2.32/28 blackhole" - - "set protocols static route 192.0.2.32/28" - - "set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1'" - - "set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'" - - "set protocols static route6 2001:db8:1000::/36 blackhole distance '2'" - - "set protocols static route6 2001:db8:1000::/36" - - after: - - address_families: - - afi: 'ipv4' - routes: - - dest: '192.0.2.32/28' - blackhole_config: - type: 'blackhole' - next_hops: - - forward_router_address: '192.0.2.9' - - forward_router_address: '192.0.2.10' - - afi: 'ipv6' - routes: - - dest: '2001:db8:1000::/36' - blackhole_config: - distance: 2 - next_hops: - - forward_router_address: '2001:db8:2000:2::1' - - forward_router_address: '2001:db8:2000:2::2' - -populate: - - address_families: - - afi: 'ipv4' - routes: - - dest: '192.0.2.32/28' - blackhole_config: - type: 'blackhole' - next_hops: - - forward_router_address: '192.0.2.9' - - forward_router_address: '192.0.2.10' - - afi: 'ipv6' - routes: - - dest: '2001:db8:1000::/36' - blackhole_config: - distance: 2 - next_hops: - - forward_router_address: '2001:db8:2000:2::1' - - forward_router_address: '2001:db8:2000:2::2' - -replaced: - commands: - - "delete protocols static route 192.0.2.32/28 next-hop '192.0.2.10'" - - "set protocols static route 192.0.2.32/28 next-hop '192.0.2.7'" - - "set protocols static route 192.0.2.32/28 next-hop '192.0.2.8'" - - "set protocols static route 192.0.2.32/28 blackhole distance '2'" - - after: - - address_families: - - afi: 'ipv4' - routes: - - dest: 192.0.2.32/28 - blackhole_config: - distance: 2 - next_hops: - - forward_router_address: 192.0.2.7 - - forward_router_address: 192.0.2.8 - - forward_router_address: 192.0.2.9 - - afi: 'ipv6' - routes: - - dest: '2001:db8:1000::/36' - blackhole_config: - distance: 2 - next_hops: - - forward_router_address: '2001:db8:2000:2::1' - - forward_router_address: '2001:db8:2000:2::2' -overridden: - commands: - - "delete protocols static route 192.0.2.32/28" - - "delete protocols static route6 2001:db8:1000::/36" - - "set protocols static route 198.0.2.48/28 next-hop '192.0.2.18'" - - "set protocols static route 198.0.2.48/28" - - after: - - address_families: - - afi: 'ipv4' - routes: - - dest: 198.0.2.48/28 - next_hops: - - forward_router_address: '192.0.2.18' - -rendered: - commands: - - "set protocols static route 192.0.2.32/28 next-hop '192.0.2.10'" - - "set protocols static route 192.0.2.32/28 next-hop '192.0.2.9'" - - "set protocols static route 192.0.2.32/28 blackhole" - - "set protocols static route 192.0.2.32/28" - - "set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1'" - - "set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'" - - "set protocols static route6 2001:db8:1000::/36 blackhole distance '2'" - - "set protocols static route6 2001:db8:1000::/36" - -deleted_dest: - - commands: - - "delete protocols static route 192.0.2.32/28" - - "delete protocols static route6 2001:db8:1000::/36" - - after: [] - -deleted_nh: - - commands: - - "delete protocols static route 192.0.2.32/28 next-hop '192.0.2.9'" - - "delete protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1'" - - after: - - address_families: - - afi: 'ipv4' - routes: - - dest: '192.0.2.32/28' - blackhole_config: - type: 'blackhole' - next_hops: - - forward_router_address: '192.0.2.10' - - afi: 'ipv6' - routes: - - dest: '2001:db8:1000::/36' - blackhole_config: - distance: 2 - next_hops: - - forward_router_address: '2001:db8:2000:2::2' - -deleted_afi_all: - - commands: - - "delete protocols static route" - - "delete protocols static route6" - after: [] - -round_trip: - after: - - address_families: - - afi: 'ipv4' - routes: - - dest: 192.0.2.32/28 - blackhole_config: - distance: 2 - next_hops: - - forward_router_address: '192.0.2.7' - - forward_router_address: '192.0.2.8' - - forward_router_address: '192.0.2.9' - - forward_router_address: '192.0.2.10' - - afi: 'ipv6' - routes: - - dest: '2001:db8:1000::/36' - blackhole_config: - distance: 2 - next_hops: - - forward_router_address: '2001:db8:2000:2::1' - - forward_router_address: '2001:db8:2000:2::2' diff --git a/test/integration/targets/vyos_system/aliases b/test/integration/targets/vyos_system/aliases deleted file mode 100644 index 8071e1f75b..0000000000 --- a/test/integration/targets/vyos_system/aliases +++ /dev/null @@ -1 +0,0 @@ -shippable/vyos/group1 diff --git a/test/integration/targets/vyos_system/defaults/main.yaml b/test/integration/targets/vyos_system/defaults/main.yaml deleted file mode 100644 index 9ef5ba5165..0000000000 --- a/test/integration/targets/vyos_system/defaults/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -testcase: "*" -test_items: [] diff --git a/test/integration/targets/vyos_system/tasks/cli.yaml b/test/integration/targets/vyos_system/tasks/cli.yaml deleted file mode 100644 index 890d3acf3e..0000000000 --- a/test/integration/targets/vyos_system/tasks/cli.yaml +++ /dev/null @@ -1,22 +0,0 @@ ---- -- name: collect all cli test cases - find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - register: test_cases - delegate_to: localhost - -- name: set test_items - set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - -- name: run test case (connection=network_cli) - include: "{{ test_case_to_run }} ansible_connection=network_cli" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - -- name: run test case (connection=local) - include: "{{ test_case_to_run }} ansible_connection=local" - with_first_found: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run diff --git a/test/integration/targets/vyos_system/tasks/main.yaml b/test/integration/targets/vyos_system/tasks/main.yaml deleted file mode 100644 index d4cf26fc4a..0000000000 --- a/test/integration/targets/vyos_system/tasks/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -- {include: cli.yaml, tags: ['cli']} diff --git a/test/integration/targets/vyos_system/tests/cli/basic.yaml b/test/integration/targets/vyos_system/tests/cli/basic.yaml deleted file mode 100644 index c42eddea84..0000000000 --- a/test/integration/targets/vyos_system/tests/cli/basic.yaml +++ /dev/null @@ -1,61 +0,0 @@ ---- -- debug: msg="START cli/basic.yaml on connection={{ ansible_connection }}" - -- name: setup - vyos_config: - lines: - - delete system name-server 192.0.2.1 - - delete system name-server 192.0.2.2 - - delete system name-server 192.0.2.3 - match: none - -- name: configure name servers - vyos_system: - name_servers: - - 192.0.2.1 - - 192.0.2.2 - - 192.0.2.3 - register: result - -- assert: - that: - - result.changed == true - - result.commands|length == 3 - - result.commands[0] is search("set system name-server '192.0.2.1'") - - result.commands[1] is search("set system name-server '192.0.2.2'") - - result.commands[2] is search("set system name-server '192.0.2.3'") - -- name: verify name_servers - vyos_system: - name_servers: - - 192.0.2.1 - - 192.0.2.2 - - 192.0.2.3 - register: result - -- assert: - that: - - result.changed == false - -- name: remove one - vyos_system: - name_servers: - - 192.0.2.3 - state: absent - register: result - -- assert: - that: - - result.changed == true - - result.commands|length == 1 - - result.commands[0] is search("delete system name-server '192.0.2.3'") - -- name: teardown - vyos_config: - lines: - - delete system name-server name-server 192.0.2.1 - - delete system name-server name-server 192.0.2.2 - - delete system name-server name-server 192.0.2.3 - match: none - -- debug: msg="END cli/basic.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/vyos_system/tests/cli/net_system.yaml b/test/integration/targets/vyos_system/tests/cli/net_system.yaml deleted file mode 100644 index b7813c09f0..0000000000 --- a/test/integration/targets/vyos_system/tests/cli/net_system.yaml +++ /dev/null @@ -1,30 +0,0 @@ ---- -- debug: msg="START vyos cli/net_system.yaml on connection={{ ansible_connection }}" - -# Add minimal testcase to check args are passed correctly to -# implementation module and module run is successful. - -- name: setup - vyos_config: - lines: - - delete system name-server 192.0.2.1 - match: none - -- name: configure name servers using platform agnostic module - net_system: - name_servers: - - 192.0.2.1 - register: result - -- assert: - that: - - result.changed == true - - result.commands[0] is search("set system name-server '192.0.2.1'") - -- name: setup - vyos_config: - lines: - - delete system name-server 192.0.2.1 - match: none - -- debug: msg="END vyos cli/net_system.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/vyos_user/defaults/main.yaml b/test/integration/targets/vyos_user/defaults/main.yaml deleted file mode 100644 index 9ef5ba5165..0000000000 --- a/test/integration/targets/vyos_user/defaults/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -testcase: "*" -test_items: [] diff --git a/test/integration/targets/vyos_user/tasks/cli.yaml b/test/integration/targets/vyos_user/tasks/cli.yaml deleted file mode 100644 index 890d3acf3e..0000000000 --- a/test/integration/targets/vyos_user/tasks/cli.yaml +++ /dev/null @@ -1,22 +0,0 @@ ---- -- name: collect all cli test cases - find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - register: test_cases - delegate_to: localhost - -- name: set test_items - set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - -- name: run test case (connection=network_cli) - include: "{{ test_case_to_run }} ansible_connection=network_cli" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - -- name: run test case (connection=local) - include: "{{ test_case_to_run }} ansible_connection=local" - with_first_found: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run diff --git a/test/integration/targets/vyos_user/tasks/main.yaml b/test/integration/targets/vyos_user/tasks/main.yaml deleted file mode 100644 index d4cf26fc4a..0000000000 --- a/test/integration/targets/vyos_user/tasks/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -- {include: cli.yaml, tags: ['cli']} diff --git a/test/integration/targets/vyos_user/tests/cli/auth.yaml b/test/integration/targets/vyos_user/tests/cli/auth.yaml deleted file mode 100644 index 1f4609ab5d..0000000000 --- a/test/integration/targets/vyos_user/tests/cli/auth.yaml +++ /dev/null @@ -1,34 +0,0 @@ ---- -- block: - - name: Create user with password - vyos_user: - name: auth_user - role: admin - state: present - configured_password: pass123 - - - name: test login via ssh with new user - expect: - command: "ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_port | default(22) }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no '/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper show version'" - responses: - (?i)password: "pass123" - - - name: test login via ssh with invalid password (should fail) - expect: - command: "ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_port | default(22) }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no '/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper show version'" - responses: - (?i)password: "badpass" - ignore_errors: true - register: results - - - name: check that attempt failed - assert: - that: - - results.failed - - always: - - name: delete user - vyos_user: - name: auth_user - state: absent - register: result diff --git a/test/integration/targets/vyos_user/tests/cli/basic.yaml b/test/integration/targets/vyos_user/tests/cli/basic.yaml deleted file mode 100644 index 346ecda33a..0000000000 --- a/test/integration/targets/vyos_user/tests/cli/basic.yaml +++ /dev/null @@ -1,77 +0,0 @@ ---- -- debug: msg="START cli/basic.yaml on connection={{ ansible_connection }}" - -- name: Setup - vyos_config: - lines: - - delete system login user ansibletest1 - - delete system login user ansibletest2 - - delete system login user ansibletest3 - -- name: Create user - vyos_user: - name: ansibletest1 - configured_password: test - state: present - register: result - -- assert: - that: - - 'result.changed == true' - - '"set system login user" in result.commands[0]' - - '"authentication plaintext-password" in result.commands[0]' - -- name: Collection of users (SetUp) - vyos_user: - aggregate: - - name: ansibletest2 - - name: ansibletest3 - level: operator - state: present - register: result - -- assert: - that: - - 'result.changed == true' - - 'result.commands == ["set system login user ansibletest2 level operator", "set system login user ansibletest3 level operator"]' - -- name: Add user again (Idempotent) - vyos_user: - name: ansibletest1 - configured_password: test - state: present - update_password: on_create - register: result - -- assert: - that: - - 'result.changed == false' - - 'result.commands | length == 0' - -- name: Add collection of users (Idempotent) - vyos_user: - aggregate: - - name: ansibletest2 - - name: ansibletest3 - level: operator - state: present - register: result - -- assert: - that: - - 'result.changed == false' - - 'result.commands | length == 0' - -- name: tearDown - vyos_user: - users: - - name: ansibletest1 - - name: ansibletest2 - - name: ansibletest3 - state: absent - register: result - -- assert: - that: - - 'result.changed == true' - - 'result.commands == ["delete system login user ansibletest1", "delete system login user ansibletest2", "delete system login user ansibletest3"]' diff --git a/test/integration/targets/vyos_vlan/defaults/main.yaml b/test/integration/targets/vyos_vlan/defaults/main.yaml deleted file mode 100644 index 9ef5ba5165..0000000000 --- a/test/integration/targets/vyos_vlan/defaults/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -testcase: "*" -test_items: [] diff --git a/test/integration/targets/vyos_vlan/tasks/cli.yaml b/test/integration/targets/vyos_vlan/tasks/cli.yaml deleted file mode 100644 index 890d3acf3e..0000000000 --- a/test/integration/targets/vyos_vlan/tasks/cli.yaml +++ /dev/null @@ -1,22 +0,0 @@ ---- -- name: collect all cli test cases - find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - register: test_cases - delegate_to: localhost - -- name: set test_items - set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - -- name: run test case (connection=network_cli) - include: "{{ test_case_to_run }} ansible_connection=network_cli" - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - -- name: run test case (connection=local) - include: "{{ test_case_to_run }} ansible_connection=local" - with_first_found: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run diff --git a/test/integration/targets/vyos_vlan/tasks/main.yaml b/test/integration/targets/vyos_vlan/tasks/main.yaml deleted file mode 100644 index d4cf26fc4a..0000000000 --- a/test/integration/targets/vyos_vlan/tasks/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -- {include: cli.yaml, tags: ['cli']} diff --git a/test/integration/targets/vyos_vlan/tests/cli/basic.yaml b/test/integration/targets/vyos_vlan/tests/cli/basic.yaml deleted file mode 100644 index 7c63478538..0000000000 --- a/test/integration/targets/vyos_vlan/tests/cli/basic.yaml +++ /dev/null @@ -1,101 +0,0 @@ ---- -- debug: msg="START cli/basic.yaml on connection={{ ansible_connection }}" - -- name: setup - remove vlan used in test - vyos_config: - lines: - - delete interfaces ethernet eth1 vif 100 - - delete interfaces ethernet eth0 vif 5 - - delete interfaces ethernet eth0 vif 100 - - delete interfaces ethernet eth0 vif 101 - - delete interfaces ethernet eth1 vif 201 - -- name: set vlan with name - vyos_vlan: &name - vlan_id: 100 - name: vlan-100 - interfaces: eth1 - register: result - -- assert: - that: - - "result.changed == true" - - "'set interfaces ethernet eth1 vif 100 description vlan-100' in result.commands" - -- name: set vlan with name(idempotence) - vyos_vlan: *name - register: result - -- assert: - that: - - "result.changed == false" - -- name: set vlan with address - vyos_vlan: &address - vlan_id: 5 - address: 192.168.5.12/24 - interfaces: eth0 - register: result - -- assert: - that: - - "result.changed == true" - - "'set interfaces ethernet eth0 vif 5 address 192.168.5.12/24' in result.commands" - -- name: set vlan with address(idempotence) - vyos_vlan: *address - register: result - -- assert: - that: - - "result.changed == false" - -- name: delete - vyos_vlan: &delete - vlan_id: 100 - interfaces: eth1 - state: absent - register: result - -- assert: - that: - - "result.changed == true" - - "'delete interfaces ethernet eth1 vif 100' in result.commands" - -- name: delete(idempotence) - vyos_vlan: *delete - register: result - -- assert: - that: - - "result.changed == false" - -- name: Create VLANs using aggregate - vyos_vlan: &agg_vlan - aggregate: - - {vlan_id: 101, name: voice, interfaces: "eth0"} - - {vlan_id: 201, name: mgm, interfaces: "eth1"} - state: present - register: result - -- assert: - that: - - "result.changed == true" - - "'set interfaces ethernet eth0 vif 101 description voice' in result.commands" - - "'set interfaces ethernet eth1 vif 201 description mgm' in result.commands" - -- name: Create VLANs using aggregate (idempotent) - vyos_vlan: *agg_vlan - register: result - -- assert: - that: - - "result.changed == false" - -- name: teardown - vyos_config: - lines: - - delete interfaces ethernet eth1 vif 100 - - delete interfaces ethernet eth0 vif 5 - - delete interfaces ethernet eth0 vif 101 - - delete interfaces ethernet eth1 vif 201 diff --git a/test/integration/targets/vyos_vlan/tests/cli/intent.yaml b/test/integration/targets/vyos_vlan/tests/cli/intent.yaml deleted file mode 100644 index 16617e9e01..0000000000 --- a/test/integration/targets/vyos_vlan/tests/cli/intent.yaml +++ /dev/null @@ -1,59 +0,0 @@ ---- -- debug: msg="START cli/intent.yaml on connection={{ ansible_connection }}" - -- name: setup - remove vlan used in test - vyos_config: &delete - lines: - - delete interfaces ethernet eth1 vif 100 - - delete interfaces ethernet eth0 vif 100 - -- name: set vlan with name - vyos_vlan: - vlan_id: 100 - name: vlan-100 - interfaces: eth1 - register: result - -- assert: - that: - - "result.changed == true" - - "'set interfaces ethernet eth1 vif 100 description vlan-100' in result.commands" - -- name: check vlan interface intent - vyos_vlan: - vlan_id: 100 - name: vlan-100 - associated_interfaces: eth1 - register: result - -- assert: - that: - - "result.failed == false" - -- name: vlan interface config + intent - vyos_vlan: - vlan_id: 100 - interfaces: eth0 - associated_interfaces: - - eth0 - - eth1 - register: result - -- assert: - that: - - "result.failed == false" - -- name: vlan intent fail - vyos_vlan: - vlan_id: 100 - associated_interfaces: - - eth3 - - eth4 - register: result - ignore_errors: true - -- assert: - that: - - "result.failed == True" - -- debug: msg="End cli/intent.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/vyos_vlan/tests/cli/multiple.yaml b/test/integration/targets/vyos_vlan/tests/cli/multiple.yaml deleted file mode 100644 index 25bc1af095..0000000000 --- a/test/integration/targets/vyos_vlan/tests/cli/multiple.yaml +++ /dev/null @@ -1,60 +0,0 @@ ---- -- debug: msg="START cli/multiple.yaml on connection={{ ansible_connection }}" - -- name: setup - remove vlan used in test - vyos_config: - lines: - - delete interfaces ethernet eth0 vif 5 - - delete interfaces ethernet eth0 vif 100 - - delete interfaces ethernet eth1 vif 100 - -- name: Add multiple interfaces to vlan - vyos_vlan: &multiple - vlan_id: 100 - interfaces: - - eth0 - - eth1 - register: result - -- assert: - that: - - "result.changed == true" - - "'set interfaces ethernet eth0 vif 100' in result.commands" - - "'set interfaces ethernet eth1 vif 100' in result.commands" - -- name: Add multiple interfaces to vlan(idempotence) - vyos_vlan: *multiple - register: result - -- assert: - that: - - "result.changed == false" - -- name: delete vlan with multiple interfaces - vyos_vlan: &delete_multiple - vlan_id: 100 - interfaces: - - eth0 - - eth1 - state: absent - register: result - -- assert: - that: - - "result.changed == true" - - "'delete interfaces ethernet eth0 vif 100' in result.commands" - - "'delete interfaces ethernet eth1 vif 100' in result.commands" - -- name: delete vlan with multiple interfaces(idempotence) - vyos_vlan: *delete_multiple - register: result - -- assert: - that: - - "result.changed == false" - -- name: teardown - vyos_config: - lines: - - delete interfaces ethernet eth0 vif 100 - - delete interfaces ethernet eth1 vif 100 diff --git a/test/sanity/ignore.txt b/test/sanity/ignore.txt index 4220cf3bf6..ade5083a60 100644 --- a/test/sanity/ignore.txt +++ b/test/sanity/ignore.txt @@ -76,8 +76,6 @@ lib/ansible/module_utils/facts/utils.py future-import-boilerplate lib/ansible/module_utils/facts/utils.py metaclass-boilerplate lib/ansible/module_utils/json_utils.py future-import-boilerplate lib/ansible/module_utils/json_utils.py metaclass-boilerplate -lib/ansible/module_utils/network/vyos/vyos.py future-import-boilerplate -lib/ansible/module_utils/network/vyos/vyos.py metaclass-boilerplate lib/ansible/module_utils/parsing/convert_bool.py future-import-boilerplate lib/ansible/module_utils/parsing/convert_bool.py metaclass-boilerplate lib/ansible/module_utils/powershell/Ansible.ModuleUtils.ArgvParser.psm1 pslint:PSUseApprovedVerbs @@ -142,129 +140,6 @@ lib/ansible/modules/net_tools/basics/uri.py pylint:blacklisted-name lib/ansible/modules/net_tools/basics/uri.py validate-modules:doc-required-mismatch lib/ansible/modules/net_tools/basics/uri.py validate-modules:parameter-list-no-elements lib/ansible/modules/net_tools/basics/uri.py validate-modules:parameter-type-not-in-doc -lib/ansible/modules/network/vyos/_vyos_interface.py future-import-boilerplate -lib/ansible/modules/network/vyos/_vyos_interface.py metaclass-boilerplate -lib/ansible/modules/network/vyos/_vyos_interface.py validate-modules:doc-choices-do-not-match-spec -lib/ansible/modules/network/vyos/_vyos_interface.py validate-modules:doc-default-does-not-match-spec -lib/ansible/modules/network/vyos/_vyos_interface.py validate-modules:doc-elements-mismatch -lib/ansible/modules/network/vyos/_vyos_interface.py validate-modules:doc-missing-type -lib/ansible/modules/network/vyos/_vyos_interface.py validate-modules:doc-required-mismatch -lib/ansible/modules/network/vyos/_vyos_interface.py validate-modules:missing-suboption-docs -lib/ansible/modules/network/vyos/_vyos_interface.py validate-modules:parameter-type-not-in-doc -lib/ansible/modules/network/vyos/_vyos_interface.py validate-modules:undocumented-parameter -lib/ansible/modules/network/vyos/_vyos_l3_interface.py future-import-boilerplate -lib/ansible/modules/network/vyos/_vyos_l3_interface.py metaclass-boilerplate -lib/ansible/modules/network/vyos/_vyos_l3_interface.py validate-modules:doc-choices-do-not-match-spec -lib/ansible/modules/network/vyos/_vyos_l3_interface.py validate-modules:doc-default-does-not-match-spec -lib/ansible/modules/network/vyos/_vyos_l3_interface.py validate-modules:doc-elements-mismatch -lib/ansible/modules/network/vyos/_vyos_l3_interface.py validate-modules:doc-missing-type -lib/ansible/modules/network/vyos/_vyos_l3_interface.py validate-modules:doc-required-mismatch -lib/ansible/modules/network/vyos/_vyos_l3_interface.py validate-modules:missing-suboption-docs -lib/ansible/modules/network/vyos/_vyos_l3_interface.py validate-modules:parameter-type-not-in-doc -lib/ansible/modules/network/vyos/_vyos_l3_interface.py validate-modules:undocumented-parameter -lib/ansible/modules/network/vyos/_vyos_linkagg.py future-import-boilerplate -lib/ansible/modules/network/vyos/_vyos_linkagg.py metaclass-boilerplate -lib/ansible/modules/network/vyos/_vyos_linkagg.py validate-modules:doc-choices-do-not-match-spec -lib/ansible/modules/network/vyos/_vyos_linkagg.py validate-modules:doc-default-does-not-match-spec -lib/ansible/modules/network/vyos/_vyos_linkagg.py validate-modules:doc-elements-mismatch -lib/ansible/modules/network/vyos/_vyos_linkagg.py validate-modules:doc-missing-type -lib/ansible/modules/network/vyos/_vyos_linkagg.py validate-modules:doc-required-mismatch -lib/ansible/modules/network/vyos/_vyos_linkagg.py validate-modules:missing-suboption-docs -lib/ansible/modules/network/vyos/_vyos_linkagg.py validate-modules:parameter-list-no-elements -lib/ansible/modules/network/vyos/_vyos_linkagg.py validate-modules:parameter-type-not-in-doc -lib/ansible/modules/network/vyos/_vyos_linkagg.py validate-modules:undocumented-parameter -lib/ansible/modules/network/vyos/_vyos_lldp.py validate-modules:doc-default-does-not-match-spec -lib/ansible/modules/network/vyos/_vyos_lldp.py validate-modules:doc-required-mismatch -lib/ansible/modules/network/vyos/_vyos_lldp.py validate-modules:parameter-list-no-elements -lib/ansible/modules/network/vyos/_vyos_lldp_interface.py future-import-boilerplate -lib/ansible/modules/network/vyos/_vyos_lldp_interface.py metaclass-boilerplate -lib/ansible/modules/network/vyos/_vyos_lldp_interface.py validate-modules:doc-choices-do-not-match-spec -lib/ansible/modules/network/vyos/_vyos_lldp_interface.py validate-modules:doc-default-does-not-match-spec -lib/ansible/modules/network/vyos/_vyos_lldp_interface.py validate-modules:doc-elements-mismatch -lib/ansible/modules/network/vyos/_vyos_lldp_interface.py validate-modules:doc-missing-type -lib/ansible/modules/network/vyos/_vyos_lldp_interface.py validate-modules:doc-required-mismatch -lib/ansible/modules/network/vyos/_vyos_lldp_interface.py validate-modules:missing-suboption-docs -lib/ansible/modules/network/vyos/_vyos_lldp_interface.py validate-modules:undocumented-parameter -lib/ansible/modules/network/vyos/_vyos_static_route.py future-import-boilerplate -lib/ansible/modules/network/vyos/_vyos_static_route.py metaclass-boilerplate -lib/ansible/modules/network/vyos/_vyos_static_route.py validate-modules:doc-choices-do-not-match-spec -lib/ansible/modules/network/vyos/_vyos_static_route.py validate-modules:doc-default-does-not-match-spec -lib/ansible/modules/network/vyos/_vyos_static_route.py validate-modules:doc-elements-mismatch -lib/ansible/modules/network/vyos/_vyos_static_route.py validate-modules:doc-missing-type -lib/ansible/modules/network/vyos/_vyos_static_route.py validate-modules:doc-required-mismatch -lib/ansible/modules/network/vyos/_vyos_static_route.py validate-modules:missing-suboption-docs -lib/ansible/modules/network/vyos/_vyos_static_route.py validate-modules:parameter-type-not-in-doc -lib/ansible/modules/network/vyos/_vyos_static_route.py validate-modules:undocumented-parameter -lib/ansible/modules/network/vyos/vyos_banner.py future-import-boilerplate -lib/ansible/modules/network/vyos/vyos_banner.py metaclass-boilerplate -lib/ansible/modules/network/vyos/vyos_banner.py validate-modules:doc-default-does-not-match-spec -lib/ansible/modules/network/vyos/vyos_banner.py validate-modules:doc-missing-type -lib/ansible/modules/network/vyos/vyos_banner.py validate-modules:doc-required-mismatch -lib/ansible/modules/network/vyos/vyos_command.py future-import-boilerplate -lib/ansible/modules/network/vyos/vyos_command.py metaclass-boilerplate -lib/ansible/modules/network/vyos/vyos_command.py pylint:blacklisted-name -lib/ansible/modules/network/vyos/vyos_command.py validate-modules:doc-default-does-not-match-spec -lib/ansible/modules/network/vyos/vyos_command.py validate-modules:doc-missing-type -lib/ansible/modules/network/vyos/vyos_command.py validate-modules:doc-required-mismatch -lib/ansible/modules/network/vyos/vyos_command.py validate-modules:parameter-list-no-elements -lib/ansible/modules/network/vyos/vyos_command.py validate-modules:parameter-type-not-in-doc -lib/ansible/modules/network/vyos/vyos_config.py future-import-boilerplate -lib/ansible/modules/network/vyos/vyos_config.py metaclass-boilerplate -lib/ansible/modules/network/vyos/vyos_config.py validate-modules:doc-default-does-not-match-spec -lib/ansible/modules/network/vyos/vyos_config.py validate-modules:doc-missing-type -lib/ansible/modules/network/vyos/vyos_config.py validate-modules:doc-required-mismatch -lib/ansible/modules/network/vyos/vyos_config.py validate-modules:parameter-list-no-elements -lib/ansible/modules/network/vyos/vyos_config.py validate-modules:parameter-type-not-in-doc -lib/ansible/modules/network/vyos/vyos_facts.py future-import-boilerplate -lib/ansible/modules/network/vyos/vyos_facts.py metaclass-boilerplate -lib/ansible/modules/network/vyos/vyos_facts.py validate-modules:doc-default-does-not-match-spec -lib/ansible/modules/network/vyos/vyos_facts.py validate-modules:doc-required-mismatch -lib/ansible/modules/network/vyos/vyos_facts.py validate-modules:parameter-list-no-elements -lib/ansible/modules/network/vyos/vyos_facts.py validate-modules:parameter-type-not-in-doc -lib/ansible/modules/network/vyos/vyos_interfaces.py validate-modules:doc-elements-mismatch -lib/ansible/modules/network/vyos/vyos_lag_interfaces.py validate-modules:doc-elements-mismatch -lib/ansible/modules/network/vyos/vyos_lag_interfaces.py validate-modules:parameter-list-no-elements -lib/ansible/modules/network/vyos/vyos_lldp_global.py validate-modules:parameter-list-no-elements -lib/ansible/modules/network/vyos/vyos_lldp_interfaces.py validate-modules:doc-elements-mismatch -lib/ansible/modules/network/vyos/vyos_lldp_interfaces.py validate-modules:doc-required-mismatch -lib/ansible/modules/network/vyos/vyos_logging.py future-import-boilerplate -lib/ansible/modules/network/vyos/vyos_logging.py metaclass-boilerplate -lib/ansible/modules/network/vyos/vyos_logging.py validate-modules:doc-choices-do-not-match-spec -lib/ansible/modules/network/vyos/vyos_logging.py validate-modules:doc-default-does-not-match-spec -lib/ansible/modules/network/vyos/vyos_logging.py validate-modules:doc-elements-mismatch -lib/ansible/modules/network/vyos/vyos_logging.py validate-modules:doc-missing-type -lib/ansible/modules/network/vyos/vyos_logging.py validate-modules:doc-required-mismatch -lib/ansible/modules/network/vyos/vyos_logging.py validate-modules:missing-suboption-docs -lib/ansible/modules/network/vyos/vyos_logging.py validate-modules:parameter-type-not-in-doc -lib/ansible/modules/network/vyos/vyos_logging.py validate-modules:undocumented-parameter -lib/ansible/modules/network/vyos/vyos_ping.py validate-modules:doc-default-does-not-match-spec -lib/ansible/modules/network/vyos/vyos_ping.py validate-modules:doc-required-mismatch -lib/ansible/modules/network/vyos/vyos_ping.py validate-modules:parameter-type-not-in-doc -lib/ansible/modules/network/vyos/vyos_system.py future-import-boilerplate -lib/ansible/modules/network/vyos/vyos_system.py metaclass-boilerplate -lib/ansible/modules/network/vyos/vyos_system.py validate-modules:doc-default-does-not-match-spec -lib/ansible/modules/network/vyos/vyos_system.py validate-modules:doc-required-mismatch -lib/ansible/modules/network/vyos/vyos_system.py validate-modules:parameter-list-no-elements -lib/ansible/modules/network/vyos/vyos_system.py validate-modules:parameter-type-not-in-doc -lib/ansible/modules/network/vyos/vyos_user.py future-import-boilerplate -lib/ansible/modules/network/vyos/vyos_user.py metaclass-boilerplate -lib/ansible/modules/network/vyos/vyos_user.py validate-modules:doc-choices-do-not-match-spec -lib/ansible/modules/network/vyos/vyos_user.py validate-modules:doc-default-does-not-match-spec -lib/ansible/modules/network/vyos/vyos_user.py validate-modules:doc-elements-mismatch -lib/ansible/modules/network/vyos/vyos_user.py validate-modules:doc-missing-type -lib/ansible/modules/network/vyos/vyos_user.py validate-modules:doc-required-mismatch -lib/ansible/modules/network/vyos/vyos_user.py validate-modules:missing-suboption-docs -lib/ansible/modules/network/vyos/vyos_user.py validate-modules:parameter-type-not-in-doc -lib/ansible/modules/network/vyos/vyos_user.py validate-modules:undocumented-parameter -lib/ansible/modules/network/vyos/vyos_vlan.py validate-modules:doc-choices-do-not-match-spec -lib/ansible/modules/network/vyos/vyos_vlan.py validate-modules:doc-default-does-not-match-spec -lib/ansible/modules/network/vyos/vyos_vlan.py validate-modules:doc-elements-mismatch -lib/ansible/modules/network/vyos/vyos_vlan.py validate-modules:doc-missing-type -lib/ansible/modules/network/vyos/vyos_vlan.py validate-modules:doc-required-mismatch -lib/ansible/modules/network/vyos/vyos_vlan.py validate-modules:missing-suboption-docs -lib/ansible/modules/network/vyos/vyos_vlan.py validate-modules:parameter-list-no-elements -lib/ansible/modules/network/vyos/vyos_vlan.py validate-modules:parameter-type-not-in-doc -lib/ansible/modules/network/vyos/vyos_vlan.py validate-modules:undocumented-parameter lib/ansible/modules/packaging/language/pip.py pylint:blacklisted-name lib/ansible/modules/packaging/language/pip.py validate-modules:doc-elements-mismatch lib/ansible/modules/packaging/language/pip.py validate-modules:invalid-ansiblemodule-schema @@ -360,7 +235,6 @@ lib/ansible/playbook/collectionsearch.py required-and-default-attributes # http lib/ansible/playbook/helpers.py pylint:blacklisted-name lib/ansible/playbook/role/__init__.py pylint:blacklisted-name lib/ansible/plugins/action/normal.py action-plugin-docs # default action plugin for modules without a dedicated action plugin -lib/ansible/plugins/action/vyos.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` lib/ansible/plugins/cache/base.py ansible-doc!skip # not a plugin, but a stub for backwards compatibility lib/ansible/plugins/doc_fragments/backup.py future-import-boilerplate lib/ansible/plugins/doc_fragments/backup.py metaclass-boilerplate @@ -384,8 +258,6 @@ lib/ansible/plugins/doc_fragments/url.py future-import-boilerplate lib/ansible/plugins/doc_fragments/url.py metaclass-boilerplate lib/ansible/plugins/doc_fragments/validate.py future-import-boilerplate lib/ansible/plugins/doc_fragments/validate.py metaclass-boilerplate -lib/ansible/plugins/doc_fragments/vyos.py future-import-boilerplate -lib/ansible/plugins/doc_fragments/vyos.py metaclass-boilerplate lib/ansible/plugins/lookup/sequence.py pylint:blacklisted-name lib/ansible/plugins/strategy/__init__.py pylint:blacklisted-name lib/ansible/plugins/strategy/linear.py pylint:blacklisted-name diff --git a/test/units/modules/network/vyos/fixtures/show_host_name b/test/units/modules/network/vyos/fixtures/show_host_name deleted file mode 100644 index e89bc06462..0000000000 --- a/test/units/modules/network/vyos/fixtures/show_host_name +++ /dev/null @@ -1 +0,0 @@ -vyos01 diff --git a/test/units/modules/network/vyos/fixtures/show_version b/test/units/modules/network/vyos/fixtures/show_version deleted file mode 100644 index a015d554eb..0000000000 --- a/test/units/modules/network/vyos/fixtures/show_version +++ /dev/null @@ -1,14 +0,0 @@ -Version: VyOS 1.1.7 -Description: VyOS 1.1.7 (helium) -Copyright: 2016 VyOS maintainers and contributors -Built by: maintainers@vyos.net -Built on: Wed Feb 17 09:57:31 UTC 2016 -Build ID: 1602170957-4459750 -System type: x86 64-bit -Boot via: image -Hypervisor: VMware -HW model: VMware Virtual Platform -HW S/N: VMware-42 3c 26 25 44 c5 0a 91-cf 2c 97 2b fe 9b 25 be -HW UUID: 423C2625-44C5-0A91-CF2C-972BFE9B25BE -Uptime: 01:08:20 up 52 days, 2:13, 1 user, load average: 0.00, 0.01, 0.05 - diff --git a/test/units/modules/network/vyos/fixtures/vyos_config_config.cfg b/test/units/modules/network/vyos/fixtures/vyos_config_config.cfg deleted file mode 100644 index fcef8ebdda..0000000000 --- a/test/units/modules/network/vyos/fixtures/vyos_config_config.cfg +++ /dev/null @@ -1,10 +0,0 @@ -set system host-name 'router' -set system domain-name 'example.com' -set system domain-search domain 'example.com' -set system name-server '8.8.8.8' -set system name-server '8.8.4.4' -set interfaces ethernet eth0 address '1.2.3.4/24' -set interfaces ethernet eth0 description 'test string' -set interfaces ethernet eth1 address '6.7.8.9/24' -set interfaces ethernet eth1 description 'test string' -set interfaces ethernet eth1 disable diff --git a/test/units/modules/network/vyos/fixtures/vyos_config_src.cfg b/test/units/modules/network/vyos/fixtures/vyos_config_src.cfg deleted file mode 100644 index 410f6115fc..0000000000 --- a/test/units/modules/network/vyos/fixtures/vyos_config_src.cfg +++ /dev/null @@ -1,6 +0,0 @@ -set system host-name foo - -delete interfaces ethernet eth0 address -set interfaces ethernet eth1 address '6.7.8.9/24' - set interfaces ethernet eth1 description 'test string' -set interfaces ethernet eth1 disable diff --git a/test/units/modules/network/vyos/fixtures/vyos_config_src_brackets.cfg b/test/units/modules/network/vyos/fixtures/vyos_config_src_brackets.cfg deleted file mode 100644 index 468b32c268..0000000000 --- a/test/units/modules/network/vyos/fixtures/vyos_config_src_brackets.cfg +++ /dev/null @@ -1,13 +0,0 @@ -interfaces { - ethernet eth0 { - address 10.10.10.10/24 - } - ethernet eth1 { - address 6.7.8.9/24 - description test string - disable - } -} -system { - host-name foo -} diff --git a/test/units/modules/network/vyos/fixtures/vyos_firewall_global_config.cfg b/test/units/modules/network/vyos/fixtures/vyos_firewall_global_config.cfg deleted file mode 100644 index 2a2a8e8bd8..0000000000 --- a/test/units/modules/network/vyos/fixtures/vyos_firewall_global_config.cfg +++ /dev/null @@ -1,6 +0,0 @@ -set firewall group address-group RND-HOSTS address 192.0.2.1 -set firewall group address-group RND-HOSTS address 192.0.2.3 -set firewall group address-group RND-HOSTS address 192.0.2.5 -set firewall group address-group RND-HOSTS description 'This group has the Management hosts address lists' -set firewall group network-group RND network 192.0.2.0/24 -set firewall group network-group RND description 'This group has the Management network addresses' diff --git a/test/units/modules/network/vyos/fixtures/vyos_firewall_interfaces_config.cfg b/test/units/modules/network/vyos/fixtures/vyos_firewall_interfaces_config.cfg deleted file mode 100644 index 24704d2ddf..0000000000 --- a/test/units/modules/network/vyos/fixtures/vyos_firewall_interfaces_config.cfg +++ /dev/null @@ -1,8 +0,0 @@ -set interfaces ethernet eth0 firewall in name 'INBOUND' -set interfaces ethernet eth0 firewall local ipv6-name 'V6-LOCAL' -set interfaces ethernet eth0 firewall local name 'LOCAL' -set interfaces ethernet eth0 firewall out name 'OUTBOUND' -set interfaces ethernet eth2 firewall in name 'INBOUND' -set interfaces ethernet eth2 firewall local ipv6-name 'V6-LOCAL' -set interfaces ethernet eth2 firewall local name 'LOCAL' -set interfaces ethernet eth2 firewall out name 'OUTBOUND' diff --git a/test/units/modules/network/vyos/fixtures/vyos_firewall_rules_config.cfg b/test/units/modules/network/vyos/fixtures/vyos_firewall_rules_config.cfg deleted file mode 100644 index f65b386963..0000000000 --- a/test/units/modules/network/vyos/fixtures/vyos_firewall_rules_config.cfg +++ /dev/null @@ -1,13 +0,0 @@ -set firewall name V4-INGRESS default-action 'accept' -set firewall ipv6-name V6-INGRESS default-action 'accept' -set firewall name V4-INGRESS description 'This is IPv4 V4-INGRESS rule set' -set firewall name V4-INGRESS enable-default-log -set firewall name V4-INGRESS rule 101 protocol 'icmp' -set firewall name V4-INGRESS rule 101 description 'Rule 101 is configured by Ansible' -set firewall name V4-INGRESS rule 101 fragment 'match-frag' -set firewall name V4-INGRESS rule 101 -set firewall name V4-INGRESS rule 101 disabled -set firewall name V4-INGRESS rule 101 action 'accept' -set firewall name V4-INGRESS rule 101 ipsec 'match-ipsec' -set firewall name V4-EGRESS default-action 'reject' -set firewall ipv6-name V6-EGRESS default-action 'reject' diff --git a/test/units/modules/network/vyos/fixtures/vyos_ping_ping_10.10.10.10_count_2 b/test/units/modules/network/vyos/fixtures/vyos_ping_ping_10.10.10.10_count_2 deleted file mode 100644 index c28fba1583..0000000000 --- a/test/units/modules/network/vyos/fixtures/vyos_ping_ping_10.10.10.10_count_2 +++ /dev/null @@ -1,7 +0,0 @@ -PING 10.10.10.10 (10.10.10.10) 56(84) bytes of data. -64 bytes from 10.10.10.10: icmp_req=1 ttl=255 time=1.27 ms -64 bytes from 10.10.10.10: icmp_req=2 ttl=255 time=2.28 ms - ---- 10.8.38.66 ping statistics --- -2 packets transmitted, 2 received, 0% packet loss, time 1001ms -rtt min/avg/max/mdev = 12.1222/17.124/22.225/10.143 ms diff --git a/test/units/modules/network/vyos/fixtures/vyos_ping_ping_10.10.10.11_count_10_ttl_128_size_512 b/test/units/modules/network/vyos/fixtures/vyos_ping_ping_10.10.10.11_count_10_ttl_128_size_512 deleted file mode 100644 index 54e026c231..0000000000 --- a/test/units/modules/network/vyos/fixtures/vyos_ping_ping_10.10.10.11_count_10_ttl_128_size_512 +++ /dev/null @@ -1,15 +0,0 @@ -PING 10.10.10.11 (10.8.38.65) 512(540) bytes of data. -520 bytes from 10.10.10.11: icmp_req=1 ttl=255 time=1.17 ms -520 bytes from 10.10.10.11: icmp_req=2 ttl=255 time=1.32 ms -520 bytes from 10.10.10.11: icmp_req=3 ttl=255 time=1.21 ms -520 bytes from 10.10.10.11: icmp_req=4 ttl=255 time=1.46 ms -520 bytes from 10.10.10.11: icmp_req=5 ttl=255 time=1.32 ms -520 bytes from 10.10.10.11: icmp_req=6 ttl=255 time=1.28 ms -520 bytes from 10.10.10.11: icmp_req=7 ttl=255 time=1.25 ms -520 bytes from 10.10.10.11: icmp_req=8 ttl=255 time=1.23 ms -520 bytes from 10.10.10.11: icmp_req=9 ttl=255 time=1.34 ms -520 bytes from 10.10.10.11: icmp_req=10 ttl=255 time=21.0 ms - ---- 10.10.10.11 ping statistics --- -10 packets transmitted, 10 received, 0% packet loss, time 9012ms -rtt min/avg/max/mdev = 1.170/3.262/21.002/5.913 ms diff --git a/test/units/modules/network/vyos/fixtures/vyos_ping_ping_10.10.10.20_count_4 b/test/units/modules/network/vyos/fixtures/vyos_ping_ping_10.10.10.20_count_4 deleted file mode 100644 index 08e6181715..0000000000 --- a/test/units/modules/network/vyos/fixtures/vyos_ping_ping_10.10.10.20_count_4 +++ /dev/null @@ -1,9 +0,0 @@ -PING 10.10.10.20 (10.10.10.20) 56(84) bytes of data. -From 10.10.10.20 icmp_seq=1 Destination Host Unreachable -From 10.10.10.20 icmp_seq=2 Destination Host Unreachable -From 10.10.10.20 icmp_seq=3 Destination Host Unreachable -From 10.10.10.20 icmp_seq=4 Destination Host Unreachable - ---- 10.10.10.20 ping statistics --- -4 packets transmitted, 0 received, +4 errors, 100% packet loss, time 3053ms -pipe 3 diff --git a/test/units/modules/network/vyos/fixtures/vyos_static_routes_config.cfg b/test/units/modules/network/vyos/fixtures/vyos_static_routes_config.cfg deleted file mode 100644 index 0411dc9a8e..0000000000 --- a/test/units/modules/network/vyos/fixtures/vyos_static_routes_config.cfg +++ /dev/null @@ -1,2 +0,0 @@ -'set protocols static route 192.0.2.32/28 next-hop 192.0.2.9' -'set protocols static route 192.0.2.32/28 next-hop 192.0.2.10' diff --git a/test/units/modules/network/vyos/fixtures/vyos_user_config.cfg b/test/units/modules/network/vyos/fixtures/vyos_user_config.cfg deleted file mode 100644 index 81cd1a48a1..0000000000 --- a/test/units/modules/network/vyos/fixtures/vyos_user_config.cfg +++ /dev/null @@ -1,2 +0,0 @@ -set system login user admin level operator authentication encrypted-password '$6$V5oWW3JM9NFAwOG$P2L4raFvIrZjjs3g0qmH4Ns5ti7flRpSs6aEqy4TrGZYXGeBiYzwi2A6jy' -set system login user ansible level operator authentication encrypted-password '$6$ZfvSv6A50W6yNPYX$4HP5eg2sywcXYxTqhApQ7zvUvx0HsQHrI9xuJoFLy2gM/' diff --git a/test/units/modules/network/vyos/test_vyos_banner.py b/test/units/modules/network/vyos/test_vyos_banner.py deleted file mode 100644 index f9a172054c..0000000000 --- a/test/units/modules/network/vyos/test_vyos_banner.py +++ /dev/null @@ -1,54 +0,0 @@ -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. - -# Make coding more python3-ish -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -from units.compat.mock import patch -from ansible.modules.network.vyos import vyos_banner -from units.modules.utils import set_module_args -from .vyos_module import TestVyosModule - - -class TestVyosBannerModule(TestVyosModule): - - module = vyos_banner - - def setUp(self): - super(TestVyosBannerModule, self).setUp() - - self.mock_get_config = patch('ansible.modules.network.vyos.vyos_banner.get_config') - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch('ansible.modules.network.vyos.vyos_banner.load_config') - self.load_config = self.mock_load_config.start() - - def tearDown(self): - super(TestVyosBannerModule, self).tearDown() - self.mock_get_config.stop() - self.mock_load_config.stop() - - def load_fixtures(self, commands=None): - self.load_config.return_value = dict(diff=None, session='session') - - def test_vyos_banner_create(self): - set_module_args(dict(banner='pre-login', text='test\nbanner\nstring')) - commands = ["set system login banner pre-login 'test\\nbanner\\nstring'"] - self.execute_module(changed=True, commands=commands) - - def test_vyos_banner_remove(self): - set_module_args(dict(banner='pre-login', state='absent')) - self.execute_module(changed=False, commands=[]) diff --git a/test/units/modules/network/vyos/test_vyos_command.py b/test/units/modules/network/vyos/test_vyos_command.py deleted file mode 100644 index 02423affd8..0000000000 --- a/test/units/modules/network/vyos/test_vyos_command.py +++ /dev/null @@ -1,103 +0,0 @@ -# (c) 2016 Red Hat Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. - -# Make coding more python3-ish -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -from units.compat.mock import patch -from ansible.modules.network.vyos import vyos_command -from units.modules.utils import set_module_args -from .vyos_module import TestVyosModule, load_fixture - - -class TestVyosCommandModule(TestVyosModule): - - module = vyos_command - - def setUp(self): - super(TestVyosCommandModule, self).setUp() - self.mock_run_commands = patch('ansible.modules.network.vyos.vyos_command.run_commands') - self.run_commands = self.mock_run_commands.start() - - def tearDown(self): - super(TestVyosCommandModule, self).tearDown() - self.mock_run_commands.stop() - - def load_fixtures(self, commands=None): - def load_from_file(*args, **kwargs): - module, commands = args - output = list() - - for item in commands: - try: - command = item['command'] - except ValueError: - command = item - filename = str(command).replace(' ', '_') - output.append(load_fixture(filename)) - return output - - self.run_commands.side_effect = load_from_file - - def test_vyos_command_simple(self): - set_module_args(dict(commands=['show version'])) - result = self.execute_module() - self.assertEqual(len(result['stdout']), 1) - self.assertTrue(result['stdout'][0].startswith('Version: VyOS')) - - def test_vyos_command_multiple(self): - set_module_args(dict(commands=['show version', 'show version'])) - result = self.execute_module() - self.assertEqual(len(result['stdout']), 2) - self.assertTrue(result['stdout'][0].startswith('Version: VyOS')) - - def test_vyos_command_wait_for(self): - wait_for = 'result[0] contains "VyOS maintainers"' - set_module_args(dict(commands=['show version'], wait_for=wait_for)) - self.execute_module() - - def test_vyos_command_wait_for_fails(self): - wait_for = 'result[0] contains "test string"' - set_module_args(dict(commands=['show version'], wait_for=wait_for)) - self.execute_module(failed=True) - self.assertEqual(self.run_commands.call_count, 10) - - def test_vyos_command_retries(self): - wait_for = 'result[0] contains "test string"' - set_module_args(dict(commands=['show version'], wait_for=wait_for, retries=2)) - self.execute_module(failed=True) - self.assertEqual(self.run_commands.call_count, 2) - - def test_vyos_command_match_any(self): - wait_for = ['result[0] contains "VyOS maintainers"', - 'result[0] contains "test string"'] - set_module_args(dict(commands=['show version'], wait_for=wait_for, match='any')) - self.execute_module() - - def test_vyos_command_match_all(self): - wait_for = ['result[0] contains "VyOS maintainers"', - 'result[0] contains "maintainers@vyos.net"'] - set_module_args(dict(commands=['show version'], wait_for=wait_for, match='all')) - self.execute_module() - - def test_vyos_command_match_all_failure(self): - wait_for = ['result[0] contains "VyOS maintainers"', - 'result[0] contains "test string"'] - commands = ['show version', 'show version'] - set_module_args(dict(commands=commands, wait_for=wait_for, match='all')) - self.execute_module(failed=True) diff --git a/test/units/modules/network/vyos/test_vyos_config.py b/test/units/modules/network/vyos/test_vyos_config.py deleted file mode 100644 index 015ec8807f..0000000000 --- a/test/units/modules/network/vyos/test_vyos_config.py +++ /dev/null @@ -1,117 +0,0 @@ -# -# (c) 2016 Red Hat Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. - -# Make coding more python3-ish -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -from units.compat.mock import patch, MagicMock -from ansible.modules.network.vyos import vyos_config -from ansible.plugins.cliconf.vyos import Cliconf -from units.modules.utils import set_module_args -from .vyos_module import TestVyosModule, load_fixture - - -class TestVyosConfigModule(TestVyosModule): - - module = vyos_config - - def setUp(self): - super(TestVyosConfigModule, self).setUp() - - self.mock_get_config = patch('ansible.modules.network.vyos.vyos_config.get_config') - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch('ansible.modules.network.vyos.vyos_config.load_config') - self.load_config = self.mock_load_config.start() - - self.mock_run_commands = patch('ansible.modules.network.vyos.vyos_config.run_commands') - self.run_commands = self.mock_run_commands.start() - - self.mock_get_connection = patch('ansible.modules.network.vyos.vyos_config.get_connection') - self.get_connection = self.mock_get_connection.start() - - self.cliconf_obj = Cliconf(MagicMock()) - self.running_config = load_fixture('vyos_config_config.cfg') - - self.conn = self.get_connection() - self.conn.edit_config = MagicMock() - self.running_config = load_fixture('vyos_config_config.cfg') - - def tearDown(self): - super(TestVyosConfigModule, self).tearDown() - - self.mock_get_config.stop() - self.mock_load_config.stop() - self.mock_run_commands.stop() - self.mock_get_connection.stop() - - def load_fixtures(self, commands=None): - config_file = 'vyos_config_config.cfg' - self.get_config.return_value = load_fixture(config_file) - self.load_config.return_value = None - - def test_vyos_config_unchanged(self): - src = load_fixture('vyos_config_config.cfg') - self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(src, src)) - set_module_args(dict(src=src)) - self.execute_module() - - def test_vyos_config_src(self): - src = load_fixture('vyos_config_src.cfg') - set_module_args(dict(src=src)) - candidate = '\n'.join(self.module.format_commands(src.splitlines())) - commands = ['set system host-name foo', 'delete interfaces ethernet eth0 address'] - self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(candidate, self.running_config)) - self.execute_module(changed=True, commands=commands) - - def test_vyos_config_src_brackets(self): - src = load_fixture('vyos_config_src_brackets.cfg') - set_module_args(dict(src=src)) - candidate = '\n'.join(self.module.format_commands(src.splitlines())) - commands = ['set interfaces ethernet eth0 address 10.10.10.10/24', 'set system host-name foo'] - self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(candidate, self.running_config)) - self.execute_module(changed=True, commands=commands) - - def test_vyos_config_backup(self): - set_module_args(dict(backup=True)) - result = self.execute_module() - self.assertIn('__backup__', result) - - def test_vyos_config_lines(self): - commands = ['set system host-name foo'] - set_module_args(dict(lines=commands)) - candidate = '\n'.join(commands) - self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(candidate, self.running_config)) - self.execute_module(changed=True, commands=commands) - - def test_vyos_config_config(self): - config = 'set system host-name localhost' - new_config = ['set system host-name router'] - set_module_args(dict(lines=new_config, config=config)) - candidate = '\n'.join(new_config) - self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(candidate, config)) - self.execute_module(changed=True, commands=new_config) - - def test_vyos_config_match_none(self): - lines = ['set system interfaces ethernet eth0 address 1.2.3.4/24', - 'set system interfaces ethernet eth0 description test string'] - set_module_args(dict(lines=lines, match='none')) - candidate = '\n'.join(lines) - self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(candidate, None, diff_match='none')) - self.execute_module(changed=True, commands=lines, sort=False) diff --git a/test/units/modules/network/vyos/test_vyos_facts.py b/test/units/modules/network/vyos/test_vyos_facts.py deleted file mode 100644 index e7d525c2fa..0000000000 --- a/test/units/modules/network/vyos/test_vyos_facts.py +++ /dev/null @@ -1,97 +0,0 @@ -# (c) 2016 Red Hat Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. -# Make coding more python3-ish -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type -import json -from units.compat.mock import patch -from ansible.modules.network.vyos import vyos_facts -from units.modules.utils import set_module_args -from .vyos_module import TestVyosModule, load_fixture - - -class TestVyosFactsModule(TestVyosModule): - module = vyos_facts - - def setUp(self): - super(TestVyosFactsModule, self).setUp() - self.mock_run_commands = patch('ansible.module_utils.network.vyos.facts.legacy.base.run_commands') - self.run_commands = self.mock_run_commands.start() - - self.mock_get_resource_connection = patch('ansible.module_utils.network.common.facts.facts.get_resource_connection') - self.get_resource_connection = self.mock_get_resource_connection.start() - - self.mock_get_capabilities = patch('ansible.module_utils.network.vyos.facts.legacy.base.get_capabilities') - self.get_capabilities = self.mock_get_capabilities.start() - self.get_capabilities.return_value = { - 'device_info': { - 'network_os': 'vyos', - 'network_os_hostname': 'vyos01', - 'network_os_model': 'VMware', - 'network_os_version': 'VyOS 1.1.7' - }, - 'network_api': 'cliconf' - } - - def tearDown(self): - super(TestVyosFactsModule, self).tearDown() - self.mock_run_commands.stop() - self.mock_get_capabilities.stop() - self.mock_get_resource_connection.stop() - - def load_fixtures(self, commands=None): - def load_from_file(*args, **kwargs): - module, commands = args - output = list() - for item in commands: - try: - obj = json.loads(item) - command = obj['command'] - except ValueError: - command = item - filename = str(command).replace(' ', '_') - output.append(load_fixture(filename)) - return output - self.run_commands.side_effect = load_from_file - - def test_vyos_facts_default(self): - set_module_args(dict(gather_subset='default')) - result = self.execute_module() - facts = result.get('ansible_facts') - self.assertEqual(len(facts), 10) - self.assertEqual(facts['ansible_net_hostname'].strip(), 'vyos01') - self.assertEqual(facts['ansible_net_version'], 'VyOS 1.1.7') - - def test_vyos_facts_not_all(self): - set_module_args(dict(gather_subset='!all')) - result = self.execute_module() - facts = result.get('ansible_facts') - self.assertEqual(len(facts), 10) - self.assertEqual(facts['ansible_net_hostname'].strip(), 'vyos01') - self.assertEqual(facts['ansible_net_version'], 'VyOS 1.1.7') - - def test_vyos_facts_exclude_most(self): - set_module_args(dict(gather_subset=['!neighbors', '!config'])) - result = self.execute_module() - facts = result.get('ansible_facts') - self.assertEqual(len(facts), 10) - self.assertEqual(facts['ansible_net_hostname'].strip(), 'vyos01') - self.assertEqual(facts['ansible_net_version'], 'VyOS 1.1.7') - - def test_vyos_facts_invalid_subset(self): - set_module_args(dict(gather_subset='cereal')) - self.execute_module(failed=True) diff --git a/test/units/modules/network/vyos/test_vyos_firewall_global.py b/test/units/modules/network/vyos/test_vyos_firewall_global.py deleted file mode 100644 index 36e0ba48b5..0000000000 --- a/test/units/modules/network/vyos/test_vyos_firewall_global.py +++ /dev/null @@ -1,207 +0,0 @@ -# (c) 2016 Red Hat Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. - -# Make coding more python3-ish -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -from units.compat.mock import patch -from ansible.modules.network.vyos import vyos_firewall_global -from units.modules.utils import set_module_args -from .vyos_module import TestVyosModule, load_fixture - - -class TestVyosFirewallRulesModule(TestVyosModule): - - module = vyos_firewall_global - - def setUp(self): - super(TestVyosFirewallRulesModule, self).setUp() - self.mock_get_config = patch( - 'ansible.module_utils.network.common.network.Config.get_config') - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch( - 'ansible.module_utils.network.common.network.Config.load_config') - self.load_config = self.mock_load_config.start() - - self.mock_get_resource_connection_config = patch( - 'ansible.module_utils.network.common.cfg.base.get_resource_connection' - ) - self.get_resource_connection_config = self.mock_get_resource_connection_config.start( - ) - - self.mock_get_resource_connection_facts = patch( - 'ansible.module_utils.network.common.facts.facts.get_resource_connection' - ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start( - ) - - self.mock_execute_show_command = patch( - 'ansible.module_utils.network.vyos.facts.firewall_global.firewall_global.Firewall_globalFacts.get_device_data' - ) - - self.execute_show_command = self.mock_execute_show_command.start() - - def tearDown(self): - super(TestVyosFirewallRulesModule, self).tearDown() - self.mock_get_resource_connection_config.stop() - self.mock_get_resource_connection_facts.stop() - self.mock_get_config.stop() - self.mock_load_config.stop() - self.mock_execute_show_command.stop() - - def load_fixtures(self, commands=None): - def load_from_file(*args, **kwargs): - return load_fixture('vyos_firewall_global_config.cfg') - - self.execute_show_command.side_effect = load_from_file - - def test_vyos_firewall_global_set_01_merged(self): - set_module_args( - dict(config=dict( - validation='strict', - config_trap=True, - log_martians=True, - syn_cookies=True, - twa_hazards_protection=True, - ping=dict(all=True, broadcast=True), - state_policy=[ - dict( - connection_type='established', - action='accept', - log=True, - ), - dict(connection_type='invalid', action='reject') - ], - route_redirects=[ - dict(afi='ipv4', - ip_src_route=True, - icmp_redirects=dict(send=True, receive=False)) - ], - group=dict( - address_group=[ - dict( - name='MGMT-HOSTS', - description='This group has the Management hosts address lists', - members=[ - dict(address='192.0.1.1'), - dict(address='192.0.1.3'), - dict(address='192.0.1.5') - ]) - ], - network_group=[ - dict(name='MGMT', - description='This group has the Management network addresses', - members=[dict(address='192.0.1.0/24')]) - ])), - state="merged")) - commands = [ - "set firewall group address-group MGMT-HOSTS address 192.0.1.1", - "set firewall group address-group MGMT-HOSTS address 192.0.1.3", - "set firewall group address-group MGMT-HOSTS address 192.0.1.5", - "set firewall group address-group MGMT-HOSTS description 'This group has the Management hosts address lists'", - "set firewall group address-group MGMT-HOSTS", - "set firewall group network-group MGMT network 192.0.1.0/24", - "set firewall group network-group MGMT description 'This group has the Management network addresses'", - "set firewall group network-group MGMT", - "set firewall ip-src-route 'enable'", - "set firewall receive-redirects 'disable'", - "set firewall send-redirects 'enable'", - "set firewall config-trap 'enable'", - "set firewall state-policy established action 'accept'", - "set firewall state-policy established log 'enable'", - "set firewall state-policy invalid action 'reject'", - "set firewall broadcast-ping 'enable'", - "set firewall all-ping 'enable'", - "set firewall log-martians 'enable'", - "set firewall twa-hazards-protection 'enable'", - "set firewall syn-cookies 'enable'", - "set firewall source-validation 'strict'" - ] - self.execute_module(changed=True, commands=commands) - - def test_vyos_firewall_global_set_01_merged_idem(self): - set_module_args( - dict(config=dict(group=dict( - address_group=[ - dict(name='RND-HOSTS', - description='This group has the Management hosts address lists', - members=[ - dict(address='192.0.2.1'), - dict(address='192.0.2.3'), - dict(address='192.0.2.5') - ]) - ], - network_group=[ - dict(name='RND', - description='This group has the Management network addresses', - members=[dict(address='192.0.2.0/24')]) - ])), - state="merged")) - self.execute_module(changed=False, commands=[]) - - def test_vyos_firewall_global_set_01_replaced(self): - set_module_args( - dict(config=dict(group=dict( - address_group=[ - dict(name='RND-HOSTS', - description='This group has the Management hosts address lists', - members=[ - dict(address='192.0.2.1'), - dict(address='192.0.2.7'), - dict(address='192.0.2.9') - ]) - ], - network_group=[ - dict(name='RND', - description='This group has the Management network addresses', - members=[dict(address='192.0.2.0/24')]) - ])), - state="replaced")) - commands = [ - "delete firewall group address-group RND-HOSTS address 192.0.2.3", - "delete firewall group address-group RND-HOSTS address 192.0.2.5", - "set firewall group address-group RND-HOSTS address 192.0.2.7", - "set firewall group address-group RND-HOSTS address 192.0.2.9" - ] - self.execute_module(changed=True, commands=commands) - - def test_vyos_firewall_global_set_01_replaced_idem(self): - set_module_args( - dict(config=dict(group=dict( - address_group=[ - dict(name='RND-HOSTS', - description='This group has the Management hosts address lists', - members=[ - dict(address='192.0.2.1'), - dict(address='192.0.2.3'), - dict(address='192.0.2.5') - ]) - ], - network_group=[ - dict(name='RND', - description='This group has the Management network addresses', - members=[dict(address='192.0.2.0/24')]) - ])), - state="replaced")) - self.execute_module(changed=False, commands=[]) - - def test_vyos_firewall_global_set_01_deleted(self): - set_module_args(dict(config=dict(), state="deleted")) - commands = ["delete firewall "] - self.execute_module(changed=True, commands=commands) diff --git a/test/units/modules/network/vyos/test_vyos_firewall_interfaces.py b/test/units/modules/network/vyos/test_vyos_firewall_interfaces.py deleted file mode 100644 index 574263a374..0000000000 --- a/test/units/modules/network/vyos/test_vyos_firewall_interfaces.py +++ /dev/null @@ -1,305 +0,0 @@ -# (c) 2016 Red Hat Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. - -# Make coding more python3-ish -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -from units.compat.mock import patch, MagicMock -from ansible.modules.network.vyos import vyos_firewall_interfaces -from units.modules.utils import set_module_args -from .vyos_module import TestVyosModule, load_fixture - - -class TestVyosFirewallInterfacesModule(TestVyosModule): - - module = vyos_firewall_interfaces - - def setUp(self): - super(TestVyosFirewallInterfacesModule, self).setUp() - self.mock_get_config = patch( - 'ansible.module_utils.network.common.network.Config.get_config') - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch( - 'ansible.module_utils.network.common.network.Config.load_config') - self.load_config = self.mock_load_config.start() - - self.mock_get_resource_connection_config = patch( - 'ansible.module_utils.network.common.cfg.base.get_resource_connection' - ) - self.get_resource_connection_config = self.mock_get_resource_connection_config.start( - ) - - self.mock_get_resource_connection_facts = patch( - 'ansible.module_utils.network.common.facts.facts.get_resource_connection' - ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start( - ) - - self.mock_execute_show_command = patch( - 'ansible.module_utils.network.vyos.facts.firewall_interfaces.firewall_interfaces.Firewall_interfacesFacts.get_device_data' - ) - self.execute_show_command = self.mock_execute_show_command.start() - - def tearDown(self): - super(TestVyosFirewallInterfacesModule, self).tearDown() - self.mock_get_resource_connection_config.stop() - self.mock_get_resource_connection_facts.stop() - self.mock_get_config.stop() - self.mock_load_config.stop() - self.mock_execute_show_command.stop() - - def load_fixtures(self, commands=None): - def load_from_file(*args, **kwargs): - return load_fixture('vyos_firewall_interfaces_config.cfg') - - self.execute_show_command.side_effect = load_from_file - - def test_vyos_firewall_rule_set_01_merged(self): - set_module_args( - dict(config=[ - dict(name='eth1', - access_rules=[ - dict(afi='ipv4', - rules=[ - dict(name='INBOUND', direction='in'), - dict(name='OUTBOUND', direction='out'), - dict(name='LOCAL', direction='local') - ]), - dict(afi='ipv6', - rules=[dict(name='V6-LOCAL', direction='local')]) - ]), - dict(name='eth3', - access_rules=[ - dict(afi='ipv4', - rules=[ - dict(name='INBOUND', direction='in'), - dict(name='OUTBOUND', direction='out'), - dict(name='LOCAL', direction='local') - ]), - dict(afi='ipv6', - rules=[dict(name='V6-LOCAL', direction='local')]) - ]) - ], - state="merged")) - commands = [ - "set interfaces ethernet eth1 firewall in name 'INBOUND'", - "set interfaces ethernet eth1 firewall out name 'OUTBOUND'", - "set interfaces ethernet eth1 firewall local name 'LOCAL'", - "set interfaces ethernet eth1 firewall local ipv6-name 'V6-LOCAL'", - "set interfaces ethernet eth3 firewall in name 'INBOUND'", - "set interfaces ethernet eth3 firewall out name 'OUTBOUND'", - "set interfaces ethernet eth3 firewall local name 'LOCAL'", - "set interfaces ethernet eth3 firewall local ipv6-name 'V6-LOCAL'" - ] - self.execute_module(changed=True, commands=commands) - - def test_vyos_firewall_rule_set_02_merged_idem(self): - set_module_args( - dict(config=[ - dict(name='eth0', - access_rules=[ - dict(afi='ipv4', - rules=[ - dict(name='INBOUND', direction='in'), - dict(name='OUTBOUND', direction='out'), - dict(name='LOCAL', direction='local') - ]), - dict(afi='ipv6', - rules=[dict(name='V6-LOCAL', direction='local')]) - ]), - dict(name='eth2', - access_rules=[ - dict(afi='ipv4', - rules=[ - dict(name='INBOUND', direction='in'), - dict(name='OUTBOUND', direction='out'), - dict(name='LOCAL', direction='local') - ]), - dict(afi='ipv6', - rules=[dict(name='V6-LOCAL', direction='local')]) - ]) - ], - state="merged")) - self.execute_module(changed=False, commands=[]) - - def test_vyos_firewall_rule_set_01_deleted_per_afi(self): - set_module_args( - dict(config=[ - dict(name='eth0', - access_rules=[dict(afi='ipv4'), - dict(afi='ipv6')]) - ], - state="deleted")) - commands = [ - "delete interfaces ethernet eth0 firewall in name", - "delete interfaces ethernet eth0 firewall local name", - "delete interfaces ethernet eth0 firewall out name", - "delete interfaces ethernet eth0 firewall local ipv6-name" - ] - self.execute_module(changed=True, commands=commands) - - def test_vyos_firewall_rule_set_03_deleted_per_interface(self): - set_module_args( - dict(config=[dict(name='eth0'), - dict(name='eth2')], - state="deleted")) - commands = [ - "delete interfaces ethernet eth0 firewall", - "delete interfaces ethernet eth2 firewall" - ] - self.execute_module(changed=True, commands=commands) - - def test_vyos_firewall_rule_set_03_deleted_all(self): - set_module_args(dict(config=[], state="deleted")) - commands = [ - "delete interfaces ethernet eth0 firewall", - "delete interfaces ethernet eth2 firewall" - ] - self.execute_module(changed=True, commands=commands) - - def test_vyos_firewall_rule_set_03_deleted(self): - set_module_args( - dict(config=[dict(name='eth0'), - dict(name='eth2')], - state="deleted")) - commands = [ - "delete interfaces ethernet eth0 firewall", - "delete interfaces ethernet eth2 firewall" - ] - self.execute_module(changed=True, commands=commands) - - def test_vyos_firewall_rule_set_04_deleted_interface_idem(self): - set_module_args( - dict(config=[dict(name='eth1'), - dict(name='eth3')], - state="deleted")) - self.execute_module(changed=False, commands=[]) - - def test_vyos_firewall_rule_set_02_replaced_idem(self): - set_module_args( - dict(config=[ - dict(name='eth0', - access_rules=[ - dict(afi='ipv4', - rules=[ - dict(name='INBOUND', direction='in'), - dict(name='OUTBOUND', direction='out'), - dict(name='LOCAL', direction='local') - ]), - dict(afi='ipv6', - rules=[dict(name='V6-LOCAL', direction='local')]) - ]), - dict(name='eth2', - access_rules=[ - dict(afi='ipv4', - rules=[ - dict(name='INBOUND', direction='in'), - dict(name='OUTBOUND', direction='out'), - dict(name='LOCAL', direction='local') - ]), - dict(afi='ipv6', - rules=[dict(name='V6-LOCAL', direction='local')]) - ]) - ], - state="replaced")) - self.execute_module(changed=False, commands=[]) - - def test_vyos_firewall_rule_set_01_replaced(self): - set_module_args( - dict(config=[ - dict(name='eth0', - access_rules=[ - dict(afi='ipv4', - rules=[ - dict(name='INBOUND', direction='in'), - ]), - dict(afi='ipv6', - rules=[dict(name='V6-LOCAL', direction='local')]) - ]), - dict(name='eth2', - access_rules=[ - dict(afi='ipv4', - rules=[dict(name='LOCAL', direction='local')]), - dict(afi='ipv6', - rules=[dict(name='V6-LOCAL', direction='local')]) - ]), - dict(name='eth3', - access_rules=[ - dict(afi='ipv4', - rules=[dict(name='LOCAL', direction='local')]), - dict(afi='ipv6', - rules=[dict(name='V6-LOCAL', direction='local')]) - ]) - ], - state="replaced")) - commands = [ - "delete interfaces ethernet eth0 firewall out name", - "delete interfaces ethernet eth0 firewall local name", - "delete interfaces ethernet eth2 firewall in name", - "delete interfaces ethernet eth2 firewall out name", - "set interfaces ethernet eth3 firewall local name 'LOCAL'", - "set interfaces ethernet eth3 firewall local ipv6-name 'V6-LOCAL'" - ] - self.execute_module(changed=True, commands=commands) - - def test_vyos_firewall_rule_set_01_overridden(self): - set_module_args( - dict(config=[ - dict(name='eth1', - access_rules=[ - dict(afi='ipv4', - rules=[dict(name='INBOUND', direction='in')]) - ]) - ], - state="overridden")) - commands = [ - "delete interfaces ethernet eth0 firewall", - "delete interfaces ethernet eth2 firewall", - "set interfaces ethernet eth1 firewall in name 'INBOUND'" - ] - self.execute_module(changed=True, commands=commands) - - def test_vyos_firewall_rule_set_02_overridden_idem(self): - set_module_args( - dict(config=[ - dict(name='eth0', - access_rules=[ - dict(afi='ipv4', - rules=[ - dict(name='INBOUND', direction='in'), - dict(name='OUTBOUND', direction='out'), - dict(name='LOCAL', direction='local') - ]), - dict(afi='ipv6', - rules=[dict(name='V6-LOCAL', direction='local')]) - ]), - dict(name='eth2', - access_rules=[ - dict(afi='ipv4', - rules=[ - dict(name='INBOUND', direction='in'), - dict(name='OUTBOUND', direction='out'), - dict(name='LOCAL', direction='local') - ]), - dict(afi='ipv6', - rules=[dict(name='V6-LOCAL', direction='local')]) - ]) - ], - state="overridden")) - self.execute_module(changed=False, commands=[]) diff --git a/test/units/modules/network/vyos/test_vyos_firewall_rules.py b/test/units/modules/network/vyos/test_vyos_firewall_rules.py deleted file mode 100644 index 5dc6eaa474..0000000000 --- a/test/units/modules/network/vyos/test_vyos_firewall_rules.py +++ /dev/null @@ -1,827 +0,0 @@ -# (c) 2016 Red Hat Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. - -# Make coding more python3-ish -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -from units.compat.mock import patch -from ansible.modules.network.vyos import vyos_firewall_rules -from units.modules.utils import set_module_args -from .vyos_module import TestVyosModule, load_fixture - - -class TestVyosFirewallRulesModule(TestVyosModule): - - module = vyos_firewall_rules - - def setUp(self): - super(TestVyosFirewallRulesModule, self).setUp() - self.mock_get_config = patch( - 'ansible.module_utils.network.common.network.Config.get_config') - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch( - 'ansible.module_utils.network.common.network.Config.load_config') - self.load_config = self.mock_load_config.start() - - self.mock_get_resource_connection_config = patch( - 'ansible.module_utils.network.common.cfg.base.get_resource_connection' - ) - self.get_resource_connection_config = self.mock_get_resource_connection_config.start( - ) - - self.mock_get_resource_connection_facts = patch( - 'ansible.module_utils.network.common.facts.facts.get_resource_connection' - ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start( - ) - self.mock_execute_show_command = patch( - 'ansible.module_utils.network.vyos.facts.static_routes.static_routes.Static_routesFacts.get_device_data' - ) - - self.mock_execute_show_command = patch( - 'ansible.module_utils.network.vyos.facts.firewall_rules.firewall_rules.Firewall_rulesFacts.get_device_data' - ) - self.execute_show_command = self.mock_execute_show_command.start() - - def tearDown(self): - super(TestVyosFirewallRulesModule, self).tearDown() - self.mock_get_resource_connection_config.stop() - self.mock_get_resource_connection_facts.stop() - self.mock_get_config.stop() - self.mock_load_config.stop() - self.mock_execute_show_command.stop() - - def load_fixtures(self, commands=None): - def load_from_file(*args, **kwargs): - return load_fixture('vyos_firewall_rules_config.cfg') - - self.execute_show_command.side_effect = load_from_file - - def test_vyos_firewall_rule_set_01_merged(self): - set_module_args( - dict(config=[ - dict(afi='ipv6', - rule_sets=[ - dict(name='V6-INBOUND', - description='This is IPv6 INBOUND rule set', - default_action='reject', - enable_default_log=True, - rules=[]), - dict(name='V6-OUTBOUND', - description='This is IPv6 OUTBOUND rule set', - default_action='accept', - enable_default_log=False, - rules=[]) - ]), - dict(afi='ipv4', - rule_sets=[ - dict(name='V4-INBOUND', - description='This is IPv4 INBOUND rule set', - default_action='reject', - enable_default_log=True, - rules=[]), - dict(name='V4-OUTBOUND', - description='This is IPv4 OUTBOUND rule set', - default_action='accept', - enable_default_log=False, - rules=[]) - ]) - ], - state="merged")) - commands = [ - "set firewall ipv6-name V6-INBOUND default-action 'reject'", - "set firewall ipv6-name V6-INBOUND description 'This is IPv6 INBOUND rule set'", - 'set firewall ipv6-name V6-INBOUND enable-default-log', - "set firewall ipv6-name V6-OUTBOUND default-action 'accept'", - "set firewall ipv6-name V6-OUTBOUND description 'This is IPv6 OUTBOUND rule set'", - "set firewall name V4-INBOUND default-action 'reject'", - "set firewall name V4-INBOUND description 'This is IPv4 INBOUND rule set'", - 'set firewall name V4-INBOUND enable-default-log', - "set firewall name V4-OUTBOUND default-action 'accept'", - "set firewall name V4-OUTBOUND description 'This is IPv4 OUTBOUND rule set'" - ] - self.execute_module(changed=True, commands=commands) - - def test_vyos_firewall_rule_set_02_merged(self): - set_module_args( - dict(config=[ - dict(afi='ipv6', - rule_sets=[ - dict(name='V6-INBOUND', - description='This is IPv6 INBOUND rule set', - default_action='reject', - enable_default_log=True, - rules=[]), - dict(name='V6-OUTBOUND', - description='This is IPv6 OUTBOUND rule set', - default_action='accept', - enable_default_log=False, - rules=[]) - ]), - dict(afi='ipv4', - rule_sets=[ - dict(name='V4-INBOUND', - description='This is IPv4 INBOUND rule set', - default_action='reject', - enable_default_log=True, - rules=[]), - dict(name='V4-OUTBOUND', - description='This is IPv4 OUTBOUND rule set', - default_action='accept', - enable_default_log=False, - rules=[]) - ]) - ], - state="merged")) - commands = [ - "set firewall ipv6-name V6-INBOUND default-action 'reject'", - "set firewall ipv6-name V6-INBOUND description 'This is IPv6 INBOUND rule set'", - 'set firewall ipv6-name V6-INBOUND enable-default-log', - "set firewall ipv6-name V6-OUTBOUND default-action 'accept'", - "set firewall ipv6-name V6-OUTBOUND description 'This is IPv6 OUTBOUND rule set'", - "set firewall name V4-INBOUND default-action 'reject'", - "set firewall name V4-INBOUND description 'This is IPv4 INBOUND rule set'", - 'set firewall name V4-INBOUND enable-default-log', - "set firewall name V4-OUTBOUND default-action 'accept'", - "set firewall name V4-OUTBOUND description 'This is IPv4 OUTBOUND rule set'" - ] - self.execute_module(changed=True, commands=commands) - - def test_vyos_firewall_v4_rule_sets_rule_merged_01(self): - set_module_args( - dict(config=[ - dict(afi='ipv4', - rule_sets=[ - dict(name='INBOUND', - description='This is IPv4 INBOUND rule set', - default_action='accept', - enable_default_log=True, - rules=[ - dict(number='101', - action='accept', - description='Rule 101 is configured by Ansible', - ipsec='match-ipsec', - protocol='icmp', - fragment='match-frag', - disabled=True) - ]), - ]) - ], - state="merged")) - commands = [ - "set firewall name INBOUND default-action 'accept'", - "set firewall name INBOUND description 'This is IPv4 INBOUND rule set'", - 'set firewall name INBOUND enable-default-log', - "set firewall name INBOUND rule 101 protocol 'icmp'", - "set firewall name INBOUND rule 101 description 'Rule 101 is configured by Ansible'", - "set firewall name INBOUND rule 101 fragment 'match-frag'", - 'set firewall name INBOUND rule 101', - 'set firewall name INBOUND rule 101 disabled', - "set firewall name INBOUND rule 101 action 'accept'", - "set firewall name INBOUND rule 101 ipsec 'match-ipsec'" - ] - self.execute_module(changed=True, commands=commands) - - def test_vyos_firewall_v4_rule_sets_rule_merged_02(self): - set_module_args( - dict(config=[ - dict(afi='ipv4', - rule_sets=[ - dict(name='INBOUND', - rules=[ - dict(number='101', - protocol='tcp', - source=dict( - address='192.0.2.0', - mac_address='38:00:25:19:76:0c', - port=2127), - destination=dict(address='192.0.1.0', - port=2124), - limit=dict(burst=10, - rate=dict(number=20, - unit='second')), - recent=dict(count=10, time=20), - state=dict(established=True, - related=True, - invalid=True, - new=True)) - ]), - ]) - ], - state="merged")) - commands = [ - "set firewall name INBOUND rule 101 protocol 'tcp'", - 'set firewall name INBOUND rule 101 destination address 192.0.1.0', - 'set firewall name INBOUND rule 101 destination port 2124', - 'set firewall name INBOUND rule 101', - 'set firewall name INBOUND rule 101 source address 192.0.2.0', - 'set firewall name INBOUND rule 101 source mac-address 38:00:25:19:76:0c', - 'set firewall name INBOUND rule 101 source port 2127', - 'set firewall name INBOUND rule 101 state new enable', - 'set firewall name INBOUND rule 101 state invalid enable', - 'set firewall name INBOUND rule 101 state related enable', - 'set firewall name INBOUND rule 101 state established enable', - 'set firewall name INBOUND rule 101 limit burst 10', - 'set firewall name INBOUND rule 101 limit rate 20/second', - 'set firewall name INBOUND rule 101 recent count 10', - 'set firewall name INBOUND rule 101 recent time 20', - ] - self.execute_module(changed=True, commands=commands) - - def test_vyos_firewall_v4_rule_sets_rule_merged_03(self): - set_module_args( - dict(config=[ - dict(afi='ipv4', - rule_sets=[ - dict(name='INBOUND', - rules=[ - dict(number='101', - destination=dict(group=dict( - address_group='OUT-ADDR-GROUP', - network_group='OUT-NET-GROUP', - port_group='OUT-PORT-GROUP')), - source=dict(group=dict( - address_group='IN-ADDR-GROUP', - network_group='IN-NET-GROUP', - port_group='IN-PORT-GROUP'))) - ]), - ]) - ], - state="merged")) - commands = [ - 'set firewall name INBOUND rule 101 source group address-group IN-ADDR-GROUP', - 'set firewall name INBOUND rule 101 source group network-group IN-NET-GROUP', - 'set firewall name INBOUND rule 101 source group port-group IN-PORT-GROUP', - 'set firewall name INBOUND rule 101 destination group address-group OUT-ADDR-GROUP', - 'set firewall name INBOUND rule 101 destination group network-group OUT-NET-GROUP', - 'set firewall name INBOUND rule 101 destination group port-group OUT-PORT-GROUP', - 'set firewall name INBOUND rule 101' - ] - self.execute_module(changed=True, commands=commands) - - def test_vyos_firewall_v4_rule_sets_rule_merged_04(self): - set_module_args( - dict(config=[ - dict(afi='ipv4', - rule_sets=[ - dict(name='INBOUND', - rules=[ - dict(number='101', - time=dict(monthdays='2', - startdate='2020-01-24', - starttime='13:20:00', - stopdate='2020-01-28', - stoptime='13:30:00', - weekdays='!Sat,Sun', - utc=True), - tcp=dict(flags='ALL')) - ]), - ]) - ], - state="merged")) - commands = [ - 'set firewall name INBOUND rule 101', - 'set firewall name INBOUND rule 101 tcp flags ALL', - 'set firewall name INBOUND rule 101 time utc', - 'set firewall name INBOUND rule 101 time monthdays 2', - 'set firewall name INBOUND rule 101 time startdate 2020-01-24', - 'set firewall name INBOUND rule 101 time stopdate 2020-01-28', - 'set firewall name INBOUND rule 101 time weekdays !Sat,Sun', - 'set firewall name INBOUND rule 101 time stoptime 13:30:00', - 'set firewall name INBOUND rule 101 time starttime 13:20:00', - ] - self.execute_module(changed=True, commands=commands) - - def test_vyos_firewall_v6_rule_sets_rule_merged_01(self): - set_module_args( - dict(config=[ - dict(afi='ipv6', - rule_sets=[ - dict(name='INBOUND', - description='This is IPv6 INBOUND rule set', - default_action='accept', - enable_default_log=True, - rules=[ - dict(number='101', - action='accept', - description='Rule 101 is configured by Ansible', - ipsec='match-ipsec', - protocol='icmp', - disabled=True) - ]), - ]) - ], - state="merged")) - commands = [ - "set firewall ipv6-name INBOUND default-action 'accept'", - "set firewall ipv6-name INBOUND description 'This is IPv6 INBOUND rule set'", - 'set firewall ipv6-name INBOUND enable-default-log', - "set firewall ipv6-name INBOUND rule 101 protocol 'icmp'", - "set firewall ipv6-name INBOUND rule 101 description 'Rule 101 is configured by Ansible'", - 'set firewall ipv6-name INBOUND rule 101', - 'set firewall ipv6-name INBOUND rule 101 disabled', - "set firewall ipv6-name INBOUND rule 101 action 'accept'", - "set firewall ipv6-name INBOUND rule 101 ipsec 'match-ipsec'" - ] - self.execute_module(changed=True, commands=commands) - - def test_vyos_firewall_v6_rule_sets_rule_merged_02(self): - set_module_args( - dict(config=[ - dict(afi='ipv6', - rule_sets=[ - dict(name='INBOUND', - rules=[ - dict(number='101', - protocol='tcp', - source=dict( - address='2001:db8::12', - mac_address='38:00:25:19:76:0c', - port=2127), - destination=dict(address='2001:db8::11', - port=2124), - limit=dict(burst=10, - rate=dict(number=20, - unit='second')), - recent=dict(count=10, time=20), - state=dict(established=True, - related=True, - invalid=True, - new=True)) - ]), - ]) - ], - state="merged")) - commands = [ - "set firewall ipv6-name INBOUND rule 101 protocol 'tcp'", - 'set firewall ipv6-name INBOUND rule 101 destination address 2001:db8::11', - 'set firewall ipv6-name INBOUND rule 101 destination port 2124', - 'set firewall ipv6-name INBOUND rule 101', - 'set firewall ipv6-name INBOUND rule 101 source address 2001:db8::12', - 'set firewall ipv6-name INBOUND rule 101 source mac-address 38:00:25:19:76:0c', - 'set firewall ipv6-name INBOUND rule 101 source port 2127', - 'set firewall ipv6-name INBOUND rule 101 state new enable', - 'set firewall ipv6-name INBOUND rule 101 state invalid enable', - 'set firewall ipv6-name INBOUND rule 101 state related enable', - 'set firewall ipv6-name INBOUND rule 101 state established enable', - 'set firewall ipv6-name INBOUND rule 101 limit burst 10', - 'set firewall ipv6-name INBOUND rule 101 recent count 10', - 'set firewall ipv6-name INBOUND rule 101 recent time 20', - 'set firewall ipv6-name INBOUND rule 101 limit rate 20/second' - ] - self.execute_module(changed=True, commands=commands) - - def test_vyos_firewall_v6_rule_sets_rule_merged_03(self): - set_module_args( - dict(config=[ - dict(afi='ipv6', - rule_sets=[ - dict(name='INBOUND', - rules=[ - dict(number='101', - destination=dict(group=dict( - address_group='OUT-ADDR-GROUP', - network_group='OUT-NET-GROUP', - port_group='OUT-PORT-GROUP')), - source=dict(group=dict( - address_group='IN-ADDR-GROUP', - network_group='IN-NET-GROUP', - port_group='IN-PORT-GROUP'))) - ]), - ]) - ], - state="merged")) - commands = [ - 'set firewall ipv6-name INBOUND rule 101 source group address-group IN-ADDR-GROUP', - 'set firewall ipv6-name INBOUND rule 101 source group network-group IN-NET-GROUP', - 'set firewall ipv6-name INBOUND rule 101 source group port-group IN-PORT-GROUP', - 'set firewall ipv6-name INBOUND rule 101 destination group address-group OUT-ADDR-GROUP', - 'set firewall ipv6-name INBOUND rule 101 destination group network-group OUT-NET-GROUP', - 'set firewall ipv6-name INBOUND rule 101 destination group port-group OUT-PORT-GROUP', - 'set firewall ipv6-name INBOUND rule 101' - ] - self.execute_module(changed=True, commands=commands) - - def test_vyos_firewall_v6_rule_sets_rule_merged_04(self): - set_module_args( - dict(config=[ - dict(afi='ipv6', - rule_sets=[ - dict(name='INBOUND', - rules=[ - dict(number='101', - time=dict(monthdays='2', - startdate='2020-01-24', - starttime='13:20:00', - stopdate='2020-01-28', - stoptime='13:30:00', - weekdays='!Sat,Sun', - utc=True), - tcp=dict(flags='ALL')) - ]), - ]) - ], - state="merged")) - commands = [ - 'set firewall ipv6-name INBOUND rule 101', - 'set firewall ipv6-name INBOUND rule 101 tcp flags ALL', - 'set firewall ipv6-name INBOUND rule 101 time utc', - 'set firewall ipv6-name INBOUND rule 101 time monthdays 2', - 'set firewall ipv6-name INBOUND rule 101 time startdate 2020-01-24', - 'set firewall ipv6-name INBOUND rule 101 time stopdate 2020-01-28', - 'set firewall ipv6-name INBOUND rule 101 time weekdays !Sat,Sun', - 'set firewall ipv6-name INBOUND rule 101 time stoptime 13:30:00', - 'set firewall ipv6-name INBOUND rule 101 time starttime 13:20:00' - ] - self.execute_module(changed=True, commands=commands) - - def test_vyos_firewall_v6_rule_sets_rule_merged_icmp_01(self): - set_module_args( - dict(config=[ - dict(afi='ipv6', - rule_sets=[ - dict(name='INBOUND', - rules=[ - dict(number='101', - protocol='icmp', - icmp=dict(type_name='port-unreachable')) - ]), - ]) - ], - state="merged")) - commands = [ - 'set firewall ipv6-name INBOUND rule 101 icmpv6 type port-unreachable', - "set firewall ipv6-name INBOUND rule 101 protocol 'icmp'", - 'set firewall ipv6-name INBOUND rule 101' - ] - self.execute_module(changed=True, commands=commands) - - def test_vyos_firewall_v4_rule_sets_rule_merged_icmp_01(self): - set_module_args( - dict(config=[ - dict(afi='ipv4', - rule_sets=[ - dict(name='INBOUND', - rules=[ - dict(number='101', - protocol='icmp', - icmp=dict(type=1, code=1)) - ]), - ]) - ], - state="merged")) - commands = [ - 'set firewall name INBOUND rule 101 icmp type 1', - 'set firewall name INBOUND rule 101 icmp code 1', - "set firewall name INBOUND rule 101 protocol 'icmp'", - 'set firewall name INBOUND rule 101' - ] - self.execute_module(changed=True, commands=commands) - - def test_vyos_firewall_v4_rule_sets_rule_merged_icmp_02(self): - set_module_args( - dict(config=[ - dict(afi='ipv4', - rule_sets=[ - dict(name='INBOUND', - rules=[ - dict(number='101', - protocol='icmp', - icmp=dict(type_name='echo-request')) - ]), - ]) - ], - state="merged")) - commands = [ - 'set firewall name INBOUND rule 101 icmp type-name echo-request', - "set firewall name INBOUND rule 101 protocol 'icmp'", - 'set firewall name INBOUND rule 101' - ] - self.execute_module(changed=True, commands=commands) - - def test_vyos_firewall_v4_rule_sets_del_01(self): - set_module_args( - dict(config=[ - dict(afi='ipv4', rule_sets=[ - dict(name='V4-INGRESS'), - ]) - ], - state="deleted")) - commands = ['delete firewall name V4-INGRESS'] - self.execute_module(changed=True, commands=commands) - - def test_vyos_firewall_v4v6_rule_sets_del_02(self): - set_module_args( - dict(config=[ - dict(afi='ipv4', rule_sets=[ - dict(name='V4-INGRESS'), - ]), - dict(afi='ipv6', rule_sets=[ - dict(name='V6-INGRESS'), - ]) - ], - state="deleted")) - commands = [ - 'delete firewall name V4-INGRESS', - 'delete firewall ipv6-name V6-INGRESS' - ] - self.execute_module(changed=True, commands=commands) - - def test_vyos_firewall_v4v6_rule_sets_del_03(self): - set_module_args(dict(config=[], state="deleted")) - commands = ['delete firewall name', 'delete firewall ipv6-name'] - self.execute_module(changed=True, commands=commands) - - def test_vyos_firewall_v4v6_rule_sets_del_04(self): - set_module_args( - dict(config=[ - dict(afi='ipv4', rule_sets=[ - dict(name='V4-ING'), - ]), - dict(afi='ipv6', rule_sets=[ - dict(name='V6-ING'), - ]) - ], - state="deleted")) - self.execute_module(changed=False, commands=[]) - - def test_vyos_firewall_v4v6_rule_sets_rule_rep_01(self): - set_module_args( - dict(config=[ - dict(afi='ipv4', - rule_sets=[ - dict(name='V4-INGRESS', - description='This is IPv4 INGRESS rule set', - default_action='accept', - enable_default_log=True, - rules=[ - dict(number='101', - action='reject', - description='Rule 101 is configured by Ansible RM', - ipsec='match-ipsec', - protocol='tcp', - fragment='match-frag', - disabled=False), - dict(number='102', - action='accept', - description='Rule 102 is configured by Ansible RM', - protocol='icmp', - disabled=True) - ]), - ]), - dict(afi='ipv6', - rule_sets=[ - dict(name='V6-INGRESS', - default_action='accept', - description='This rule-set is configured by Ansible RM'), - dict(name='V6-EGRESS', - default_action='reject', - description='This rule-set is configured by Ansible RM') - ]) - ], - state="replaced")) - commands = [ - 'delete firewall name V4-INGRESS rule 101 disabled', - 'delete firewall name V4-EGRESS default-action', - "set firewall name V4-INGRESS description 'This is IPv4 INGRESS rule set'", - "set firewall name V4-INGRESS rule 101 protocol 'tcp'", - "set firewall name V4-INGRESS rule 101 description 'Rule 101 is configured by Ansible RM'", - "set firewall name V4-INGRESS rule 101 action 'reject'", - 'set firewall name V4-INGRESS rule 102 disabled', - "set firewall name V4-INGRESS rule 102 action 'accept'", - "set firewall name V4-INGRESS rule 102 protocol 'icmp'", - "set firewall name V4-INGRESS rule 102 description 'Rule 102 is configured by Ansible RM'", - 'set firewall name V4-INGRESS rule 102', - "set firewall ipv6-name V6-INGRESS description 'This rule-set is configured by Ansible RM'", - "set firewall ipv6-name V6-EGRESS description 'This rule-set is configured by Ansible RM'" - ] - self.execute_module(changed=True, commands=commands) - - def test_vyos_firewall_v4v6_rule_sets_rule_rep_02(self): - set_module_args( - dict(config=[ - dict(afi='ipv4', - rule_sets=[ - dict(name='V4-INGRESS', - description='This is IPv4 V4-INGRESS rule set', - default_action='accept', - enable_default_log=False, - rules=[ - dict(number='101', - action='accept', - description='Rule 101 is configured by Ansible', - ipsec='match-ipsec', - protocol='icmp', - fragment='match-frag', - disabled=True), - ]), - ]), - dict(afi='ipv6', - rule_sets=[ - dict( - name='V6-INGRESS', - default_action='accept', - ), - dict( - name='V6-EGRESS', - default_action='reject', - ) - ]) - ], - state="replaced")) - commands = [ - 'delete firewall name V4-INGRESS enable-default-log', - 'delete firewall name V4-EGRESS default-action' - ] - self.execute_module(changed=True, commands=commands) - - def test_vyos_firewall_v4v6_rule_sets_rule_rep_idem_01(self): - set_module_args( - dict(config=[ - dict(afi='ipv4', - rule_sets=[ - dict(name='V4-INGRESS', - description='This is IPv4 V4-INGRESS rule set', - default_action='accept', - enable_default_log=True, - rules=[ - dict(number='101', - action='accept', - description='Rule 101 is configured by Ansible', - ipsec='match-ipsec', - protocol='icmp', - fragment='match-frag', - disabled=True) - ]), - dict( - name='V4-EGRESS', - default_action='reject', - ), - ]), - dict(afi='ipv6', - rule_sets=[ - dict( - name='V6-INGRESS', - default_action='accept', - ), - dict( - name='V6-EGRESS', - default_action='reject', - ) - ]) - ], - state="replaced")) - self.execute_module(changed=False, commands=[]) - - def test_vyos_firewall_v4v6_rule_sets_rule_mer_idem_01(self): - set_module_args( - dict(config=[ - dict(afi='ipv4', - rule_sets=[ - dict(name='V4-INGRESS', - description='This is IPv4 V4-INGRESS rule set', - default_action='accept', - enable_default_log=True, - rules=[ - dict(number='101', - action='accept', - description='Rule 101 is configured by Ansible', - ipsec='match-ipsec', - protocol='icmp', - fragment='match-frag', - disabled=True) - ]), - dict( - name='V4-EGRESS', - default_action='reject', - ), - ]), - dict(afi='ipv6', - rule_sets=[ - dict( - name='V6-INGRESS', - default_action='accept', - ), - dict( - name='V6-EGRESS', - default_action='reject', - ) - ]) - ], - state="merged")) - self.execute_module(changed=False, commands=[]) - - def test_vyos_firewall_v4v6_rule_sets_rule_ovr_01(self): - set_module_args( - dict(config=[ - dict(afi='ipv4', - rule_sets=[ - dict(name='V4-IN', - description='This is IPv4 INGRESS rule set', - default_action='accept', - enable_default_log=True, - rules=[ - dict(number='1', - action='reject', - description='Rule 1 is configured by Ansible RM', - ipsec='match-ipsec', - protocol='tcp', - fragment='match-frag', - disabled=False), - dict(number='2', - action='accept', - description='Rule 102 is configured by Ansible RM', - protocol='icmp', - disabled=True) - ]), - ]), - dict(afi='ipv6', - rule_sets=[ - dict(name='V6-IN', - default_action='accept', - description='This rule-set is configured by Ansible RM'), - dict(name='V6-EG', - default_action='reject', - description='This rule-set is configured by Ansible RM') - ]) - ], - state="overridden")) - commands = [ - 'delete firewall ipv6-name V6-INGRESS', - 'delete firewall ipv6-name V6-EGRESS', - 'delete firewall name V4-INGRESS', - 'delete firewall name V4-EGRESS', - "set firewall name V4-IN default-action 'accept'", - "set firewall name V4-IN description 'This is IPv4 INGRESS rule set'", - 'set firewall name V4-IN enable-default-log', - "set firewall name V4-IN rule 1 protocol 'tcp'", - "set firewall name V4-IN rule 1 description 'Rule 1 is configured by Ansible RM'", - "set firewall name V4-IN rule 1 fragment 'match-frag'", - 'set firewall name V4-IN rule 1', - "set firewall name V4-IN rule 1 action 'reject'", - "set firewall name V4-IN rule 1 ipsec 'match-ipsec'", - 'set firewall name V4-IN rule 2 disabled', - "set firewall name V4-IN rule 2 action 'accept'", - "set firewall name V4-IN rule 2 protocol 'icmp'", - "set firewall name V4-IN rule 2 description 'Rule 102 is configured by Ansible RM'", - 'set firewall name V4-IN rule 2', - "set firewall ipv6-name V6-IN default-action 'accept'", - "set firewall ipv6-name V6-IN description 'This rule-set is configured by Ansible RM'", - "set firewall ipv6-name V6-EG default-action 'reject'", - "set firewall ipv6-name V6-EG description 'This rule-set is configured by Ansible RM'" - ] - self.execute_module(changed=True, commands=commands) - - def test_vyos_firewall_v4v6_rule_sets_rule_ovr_idem_01(self): - set_module_args( - dict(config=[ - dict(afi='ipv4', - rule_sets=[ - dict(name='V4-INGRESS', - description='This is IPv4 V4-INGRESS rule set', - default_action='accept', - enable_default_log=True, - rules=[ - dict(number='101', - action='accept', - description='Rule 101 is configured by Ansible', - ipsec='match-ipsec', - protocol='icmp', - fragment='match-frag', - disabled=True) - ]), - dict( - name='V4-EGRESS', - default_action='reject', - ), - ]), - dict(afi='ipv6', - rule_sets=[ - dict( - name='V6-INGRESS', - default_action='accept', - ), - dict( - name='V6-EGRESS', - default_action='reject', - ) - ]) - ], - state="overridden")) - self.execute_module(changed=False, commands=[]) diff --git a/test/units/modules/network/vyos/test_vyos_ping.py b/test/units/modules/network/vyos/test_vyos_ping.py deleted file mode 100644 index e12eb8a694..0000000000 --- a/test/units/modules/network/vyos/test_vyos_ping.py +++ /dev/null @@ -1,102 +0,0 @@ -# (c) 2016 Red Hat Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. - -# Make coding more python3-ish -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -from units.compat.mock import patch -from ansible.modules.network.vyos import vyos_ping -from units.modules.utils import set_module_args -from .vyos_module import TestVyosModule, load_fixture - - -class TestVyosPingModule(TestVyosModule): - - module = vyos_ping - - def setUp(self): - super(TestVyosPingModule, self).setUp() - self.mock_run_commands = patch('ansible.modules.network.vyos.vyos_ping.run_commands') - self.run_commands = self.mock_run_commands.start() - - def tearDown(self): - super(TestVyosPingModule, self).tearDown() - self.mock_run_commands.stop() - - def load_fixtures(self, commands=None): - def load_from_file(*args, **kwargs): - commands = kwargs['commands'] - output = list() - - for command in commands: - filename = str(command).split(' | ')[0].replace(' ', '_') - output.append(load_fixture('vyos_ping_%s' % filename)) - return output - - self.run_commands.side_effect = load_from_file - - def test_vyos_ping_expected_success(self): - ''' Test for successful pings when destination should be reachable ''' - set_module_args(dict(count=2, dest="10.10.10.10")) - self.execute_module() - - def test_vyos_ping_expected_failure(self): - ''' Test for unsuccessful pings when destination should not be reachable ''' - set_module_args(dict(count=4, dest="10.10.10.20", state="absent")) - self.execute_module() - - def test_vyos_ping_unexpected_success(self): - ''' Test for successful pings when destination should not be reachable - FAIL. ''' - set_module_args(dict(count=2, dest="10.10.10.10", state="absent")) - self.execute_module(failed=True) - - def test_vyos_ping_unexpected_failure(self): - ''' Test for unsuccessful pings when destination should be reachable - FAIL. ''' - set_module_args(dict(count=4, dest="10.10.10.20")) - self.execute_module(failed=True) - - def test_vyos_ping_failure_stats(self): - '''Test for asserting stats when ping fails''' - set_module_args(dict(count=4, dest="10.10.10.20")) - result = self.execute_module(failed=True) - self.assertEqual(result['packet_loss'], '100%') - self.assertEqual(result['packets_rx'], 0) - self.assertEqual(result['packets_tx'], 4) - - def test_vyos_ping_success_stats(self): - '''Test for asserting stats when ping passes''' - set_module_args(dict(count=2, dest="10.10.10.10")) - result = self.execute_module() - self.assertEqual(result['packet_loss'], '0%') - self.assertEqual(result['packets_rx'], 2) - self.assertEqual(result['packets_tx'], 2) - self.assertEqual(result['rtt']['min'], 12) - self.assertEqual(result['rtt']['avg'], 17) - self.assertEqual(result['rtt']['max'], 22) - self.assertEqual(result['rtt']['mdev'], 10) - - def test_vyos_ping_success_stats_with_options(self): - set_module_args(dict(count=10, ttl=128, size=512, dest="10.10.10.11")) - result = self.execute_module() - self.assertEqual(result['packet_loss'], '0%') - self.assertEqual(result['packets_rx'], 10) - self.assertEqual(result['packets_tx'], 10) - self.assertEqual(result['rtt']['min'], 1) - self.assertEqual(result['rtt']['avg'], 3) - self.assertEqual(result['rtt']['max'], 21) - self.assertEqual(result['rtt']['mdev'], 5) diff --git a/test/units/modules/network/vyos/test_vyos_static_route.py b/test/units/modules/network/vyos/test_vyos_static_route.py deleted file mode 100644 index 4a592ceaca..0000000000 --- a/test/units/modules/network/vyos/test_vyos_static_route.py +++ /dev/null @@ -1,54 +0,0 @@ -# (c) 2016 Red Hat Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. - -# Make coding more python3-ish -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -from units.compat.mock import patch -from ansible.modules.network.vyos import _vyos_static_route -from units.modules.utils import set_module_args -from .vyos_module import TestVyosModule - - -class TestVyosStaticRouteModule(TestVyosModule): - - module = _vyos_static_route - - def setUp(self): - super(TestVyosStaticRouteModule, self).setUp() - - self.mock_get_config = patch('ansible.modules.network.vyos._vyos_static_route.get_config') - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch('ansible.modules.network.vyos._vyos_static_route.load_config') - self.load_config = self.mock_load_config.start() - - def tearDown(self): - super(TestVyosStaticRouteModule, self).tearDown() - - self.mock_get_config.stop() - self.mock_load_config.stop() - - def load_fixtures(self, commands=None, transport='cli'): - self.load_config.return_value = dict(diff=None, session='session') - - def test_vyos_static_route_present(self): - set_module_args(dict(prefix='172.26.0.0/16', next_hop='172.26.4.1', admin_distance='1')) - result = self.execute_module(changed=True) - self.assertEqual(result['commands'], - ['set protocols static route 172.26.0.0/16 next-hop 172.26.4.1 distance 1']) diff --git a/test/units/modules/network/vyos/test_vyos_static_routes.py b/test/units/modules/network/vyos/test_vyos_static_routes.py deleted file mode 100644 index a2882c32d7..0000000000 --- a/test/units/modules/network/vyos/test_vyos_static_routes.py +++ /dev/null @@ -1,202 +0,0 @@ -# (c) 2016 Red Hat Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. - -# Make coding more python3-ish -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -from units.compat.mock import patch -from ansible.modules.network.vyos import vyos_static_routes -from units.modules.utils import set_module_args -from .vyos_module import TestVyosModule, load_fixture - - -class TestVyosStaticRoutesModule(TestVyosModule): - - module = vyos_static_routes - - def setUp(self): - super(TestVyosStaticRoutesModule, self).setUp() - self.mock_get_config = patch('ansible.module_utils.network.common.network.Config.get_config') - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch('ansible.module_utils.network.common.network.Config.load_config') - self.load_config = self.mock_load_config.start() - - self.mock_get_resource_connection_config = patch('ansible.module_utils.network.common.cfg.base.get_resource_connection') - self.get_resource_connection_config = self.mock_get_resource_connection_config.start() - - self.mock_get_resource_connection_facts = patch('ansible.module_utils.network.common.facts.facts.get_resource_connection') - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() - - self.mock_execute_show_command = patch('ansible.module_utils.network.vyos.facts.static_routes.static_routes.Static_routesFacts.get_device_data') - self.execute_show_command = self.mock_execute_show_command.start() - - def tearDown(self): - super(TestVyosStaticRoutesModule, self).tearDown() - self.mock_get_resource_connection_config.stop() - self.mock_get_resource_connection_facts.stop() - self.mock_get_config.stop() - self.mock_load_config.stop() - self.mock_execute_show_command.stop() - - def load_fixtures(self, commands=None): - def load_from_file(*args, **kwargs): - return load_fixture('vyos_static_routes_config.cfg') - self.execute_show_command.side_effect = load_from_file - - def test_vyos_static_routes_merged(self): - set_module_args( - dict(config=[ - dict(address_families=[ - dict( - afi='ipv4', - routes=[ - dict( - dest='192.0.2.48/28', - next_hops=[ - dict( - forward_router_address='192.0.2.9'), - dict(forward_router_address='192.0.2.10') - ]) - ]) - ]) - ], - state="merged")) - commands = ['set protocols static route 192.0.2.48/28', - "set protocols static route 192.0.2.48/28 next-hop '192.0.2.9'", - "set protocols static route 192.0.2.48/28 next-hop '192.0.2.10'"] - self.execute_module(changed=True, commands=commands) - - def test_vyos_static_routes_merged_idempotent(self): - set_module_args( - dict(config=[ - dict(address_families=[ - dict( - afi='ipv4', - routes=[ - dict( - dest='192.0.2.32/28', - next_hops=[ - dict( - forward_router_address='192.0.2.9'), - dict(forward_router_address='192.0.2.10') - ]) - ]) - ]) - ], - state="merged")) - self.execute_module(changed=False, commands=[]) - - def test_vyos_static_routes_replaced(self): - set_module_args( - dict(config=[ - dict(address_families=[ - dict( - afi='ipv4', - routes=[ - dict( - dest='192.0.2.48/28', - next_hops=[ - dict( - forward_router_address='192.0.2.9'), - dict(forward_router_address='192.0.2.10') - ]) - ]) - ]) - ], - state="replaced")) - commands = ["set protocols static route 192.0.2.48/28", - "set protocols static route 192.0.2.48/28 next-hop '192.0.2.9'", - "set protocols static route 192.0.2.48/28 next-hop '192.0.2.10'"] - self.execute_module(changed=True, commands=commands) - - def test_vyos_static_routes_replaced_idempotent(self): - set_module_args( - dict(config=[ - dict(address_families=[ - dict( - afi='ipv4', - routes=[ - dict( - dest='192.0.2.32/28', - next_hops=[ - dict( - forward_router_address='192.0.2.9'), - dict(forward_router_address='192.0.2.10') - ]) - ]) - ]) - ], - state="replaced")) - - self.execute_module(changed=False, commands=[]) - - def test_vyos_static_routes_overridden(self): - set_module_args( - dict(config=[ - dict(address_families=[ - dict( - afi='ipv4', - routes=[ - dict( - dest='192.0.2.48/28', - next_hops=[ - dict( - forward_router_address='192.0.2.9'), - dict(forward_router_address='192.0.2.10') - ]) - ]) - ]) - ], - state="overridden")) - commands = ['delete protocols static route 192.0.2.32/28', - 'set protocols static route 192.0.2.48/28', - "set protocols static route 192.0.2.48/28 next-hop '192.0.2.9'", - "set protocols static route 192.0.2.48/28 next-hop '192.0.2.10'"] - self.execute_module(changed=True, commands=commands) - - def test_vyos_static_routes_overridden_idempotent(self): - set_module_args( - dict(config=[ - dict(address_families=[ - dict( - afi='ipv4', - routes=[ - dict( - dest='192.0.2.32/28', - next_hops=[ - dict( - forward_router_address='192.0.2.9'), - dict(forward_router_address='192.0.2.10') - ]) - ]) - ]) - ], - state="overridden")) - self.execute_module(changed=False, commands=[]) - - def test_vyos_static_routes_deleted(self): - set_module_args( - dict(config=[ - dict(address_families=[ - dict(afi='ipv4', routes=[dict(dest='192.0.2.32/28')]) - ]) - ], - state="deleted")) - commands = ['delete protocols static route 192.0.2.32/28'] - self.execute_module(changed=True, commands=commands) diff --git a/test/units/modules/network/vyos/test_vyos_system.py b/test/units/modules/network/vyos/test_vyos_system.py deleted file mode 100644 index 1720735a3e..0000000000 --- a/test/units/modules/network/vyos/test_vyos_system.py +++ /dev/null @@ -1,97 +0,0 @@ -# (c) 2016 Red Hat Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. - -# Make coding more python3-ish -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -from units.compat.mock import patch -from ansible.modules.network.vyos import vyos_system -from units.modules.utils import set_module_args -from .vyos_module import TestVyosModule, load_fixture - - -class TestVyosSystemModule(TestVyosModule): - - module = vyos_system - - def setUp(self): - super(TestVyosSystemModule, self).setUp() - - self.mock_get_config = patch('ansible.modules.network.vyos.vyos_system.get_config') - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch('ansible.modules.network.vyos.vyos_system.load_config') - self.load_config = self.mock_load_config.start() - - def tearDown(self): - super(TestVyosSystemModule, self).tearDown() - - self.mock_get_config.stop() - self.mock_load_config.stop() - - def load_fixtures(self, commands=None): - self.get_config.return_value = load_fixture('vyos_config_config.cfg') - - def test_vyos_system_hostname(self): - set_module_args(dict(host_name='foo')) - commands = ["set system host-name 'foo'"] - self.execute_module(changed=True, commands=commands) - - def test_vyos_system_clear_hostname(self): - set_module_args(dict(host_name='foo', state='absent')) - commands = ["delete system host-name"] - self.execute_module(changed=True, commands=commands) - - def test_vyos_remove_single_name_server(self): - set_module_args(dict(name_server=['8.8.4.4'], state='absent')) - commands = ["delete system name-server '8.8.4.4'"] - self.execute_module(changed=True, commands=commands) - - def test_vyos_system_domain_name(self): - set_module_args(dict(domain_name='example2.com')) - commands = ["set system domain-name 'example2.com'"] - self.execute_module(changed=True, commands=commands) - - def test_vyos_system_clear_domain_name(self): - set_module_args(dict(domain_name='example.com', state='absent')) - commands = ['delete system domain-name'] - self.execute_module(changed=True, commands=commands) - - def test_vyos_system_domain_search(self): - set_module_args(dict(domain_search=['foo.example.com', 'bar.example.com'])) - commands = ["set system domain-search domain 'foo.example.com'", - "set system domain-search domain 'bar.example.com'"] - self.execute_module(changed=True, commands=commands) - - def test_vyos_system_clear_domain_search(self): - set_module_args(dict(domain_search=[])) - commands = ['delete system domain-search domain'] - self.execute_module(changed=True, commands=commands) - - def test_vyos_system_no_change(self): - set_module_args(dict(host_name='router', domain_name='example.com', name_server=['8.8.8.8', '8.8.4.4'])) - result = self.execute_module() - self.assertEqual([], result['commands']) - - def test_vyos_system_clear_all(self): - set_module_args(dict(state='absent')) - commands = ['delete system host-name', - 'delete system domain-search domain', - 'delete system domain-name', - 'delete system name-server'] - self.execute_module(changed=True, commands=commands) diff --git a/test/units/modules/network/vyos/test_vyos_user.py b/test/units/modules/network/vyos/test_vyos_user.py deleted file mode 100644 index 784721c98f..0000000000 --- a/test/units/modules/network/vyos/test_vyos_user.py +++ /dev/null @@ -1,87 +0,0 @@ -# (c) 2016 Red Hat Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. - -# Make coding more python3-ish -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -from units.compat.mock import patch -from ansible.modules.network.vyos import vyos_user -from units.modules.utils import set_module_args -from .vyos_module import TestVyosModule, load_fixture - - -class TestVyosUserModule(TestVyosModule): - - module = vyos_user - - def setUp(self): - super(TestVyosUserModule, self).setUp() - - self.mock_get_config = patch('ansible.modules.network.vyos.vyos_user.get_config') - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch('ansible.modules.network.vyos.vyos_user.load_config') - self.load_config = self.mock_load_config.start() - - def tearDown(self): - super(TestVyosUserModule, self).tearDown() - self.mock_get_config.stop() - self.mock_load_config.stop() - - def load_fixtures(self, commands=None, transport='cli'): - self.get_config.return_value = load_fixture('vyos_user_config.cfg') - self.load_config.return_value = dict(diff=None, session='session') - - def test_vyos_user_password(self): - set_module_args(dict(name='ansible', configured_password='test')) - result = self.execute_module(changed=True) - self.assertEqual(result['commands'], ['set system login user ansible authentication plaintext-password test']) - - def test_vyos_user_delete(self): - set_module_args(dict(name='ansible', state='absent')) - result = self.execute_module(changed=True) - self.assertEqual(result['commands'], ['delete system login user ansible']) - - def test_vyos_user_level(self): - set_module_args(dict(name='ansible', level='operator')) - result = self.execute_module(changed=True) - self.assertEqual(result['commands'], ['set system login user ansible level operator']) - - def test_vyos_user_level_invalid(self): - set_module_args(dict(name='ansible', level='sysadmin')) - self.execute_module(failed=True) - - def test_vyos_user_purge(self): - set_module_args(dict(purge=True)) - result = self.execute_module(changed=True) - self.assertEqual(sorted(result['commands']), sorted(['delete system login user ansible', - 'delete system login user admin'])) - - def test_vyos_user_update_password_changed(self): - set_module_args(dict(name='test', configured_password='test', update_password='on_create')) - result = self.execute_module(changed=True) - self.assertEqual(result['commands'], ['set system login user test authentication plaintext-password test']) - - def test_vyos_user_update_password_on_create_ok(self): - set_module_args(dict(name='ansible', configured_password='test', update_password='on_create')) - self.execute_module() - - def test_vyos_user_update_password_always(self): - set_module_args(dict(name='ansible', configured_password='test', update_password='always')) - result = self.execute_module(changed=True) - self.assertEqual(result['commands'], ['set system login user ansible authentication plaintext-password test']) diff --git a/test/units/modules/network/vyos/vyos_module.py b/test/units/modules/network/vyos/vyos_module.py deleted file mode 100644 index 138c684e88..0000000000 --- a/test/units/modules/network/vyos/vyos_module.py +++ /dev/null @@ -1,87 +0,0 @@ -# (c) 2016 Red Hat Inc. -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see <http://www.gnu.org/licenses/>. - -# Make coding more python3-ish -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -import os -import json - -from units.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase - - -fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures') -fixture_data = {} - - -def load_fixture(name): - path = os.path.join(fixture_path, name) - - if path in fixture_data: - return fixture_data[path] - - with open(path) as f: - data = f.read() - - try: - data = json.loads(data) - except Exception: - pass - - fixture_data[path] = data - return data - - -class TestVyosModule(ModuleTestCase): - - def execute_module(self, failed=False, changed=False, commands=None, sort=True, defaults=False): - self.load_fixtures(commands) - - if failed: - result = self.failed() - self.assertTrue(result['failed'], result) - else: - result = self.changed(changed) - self.assertEqual(result['changed'], changed, result) - - if commands is not None: - if sort: - self.assertEqual(sorted(commands), sorted(result['commands']), result['commands']) - else: - self.assertEqual(commands, result['commands'], result['commands']) - - return result - - def failed(self): - with self.assertRaises(AnsibleFailJson) as exc: - self.module.main() - - result = exc.exception.args[0] - self.assertTrue(result['failed'], result) - return result - - def changed(self, changed=False): - with self.assertRaises(AnsibleExitJson) as exc: - self.module.main() - - result = exc.exception.args[0] - self.assertEqual(result['changed'], changed, result) - return result - - def load_fixtures(self, commands=None): - pass |