summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/module_utils/network/vyos/argspec/interfaces/interfaces.py11
-rw-r--r--plugins/module_utils/network/vyos/argspec/l3_interfaces/l3_interfaces.py12
-rw-r--r--plugins/module_utils/network/vyos/argspec/lag_interfaces/lag_interfaces.py12
-rw-r--r--plugins/module_utils/network/vyos/argspec/lldp_global/lldp_global.py11
-rw-r--r--plugins/module_utils/network/vyos/argspec/lldp_interfaces/lldp_interfaces.py11
-rw-r--r--plugins/module_utils/network/vyos/argspec/ospfv2/__init__.py0
-rw-r--r--plugins/module_utils/network/vyos/argspec/ospfv2/ospfv2.py269
-rw-r--r--plugins/module_utils/network/vyos/argspec/ospfv3/__init__.py0
-rw-r--r--plugins/module_utils/network/vyos/argspec/ospfv3/ospfv3.py94
-rw-r--r--plugins/module_utils/network/vyos/config/firewall_rules/firewall_rules.py25
-rw-r--r--plugins/module_utils/network/vyos/config/interfaces/interfaces.py70
-rw-r--r--plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py60
-rw-r--r--plugins/module_utils/network/vyos/config/lag_interfaces/lag_interfaces.py72
-rw-r--r--plugins/module_utils/network/vyos/config/lldp_global/lldp_global.py58
-rw-r--r--plugins/module_utils/network/vyos/config/lldp_interfaces/lldp_interfaces.py75
-rw-r--r--plugins/module_utils/network/vyos/config/ospfv2/__init__.py0
-rw-r--r--plugins/module_utils/network/vyos/config/ospfv2/ospfv2.py949
-rw-r--r--plugins/module_utils/network/vyos/config/ospfv3/__init__.py0
-rw-r--r--plugins/module_utils/network/vyos/config/ospfv3/ospfv3.py464
-rw-r--r--plugins/module_utils/network/vyos/config/static_routes/static_routes.py8
-rw-r--r--plugins/module_utils/network/vyos/facts/facts.py8
-rw-r--r--plugins/module_utils/network/vyos/facts/l3_interfaces/l3_interfaces.py7
-rw-r--r--plugins/module_utils/network/vyos/facts/lag_interfaces/lag_interfaces.py26
-rw-r--r--plugins/module_utils/network/vyos/facts/ospfv2/__init__.py0
-rw-r--r--plugins/module_utils/network/vyos/facts/ospfv2/ospfv2.py499
-rw-r--r--plugins/module_utils/network/vyos/facts/ospfv3/__init__.py0
-rw-r--r--plugins/module_utils/network/vyos/facts/ospfv3/ospfv3.py213
-rw-r--r--plugins/module_utils/network/vyos/utils/utils.py37
-rw-r--r--plugins/modules/vyos_facts.py2
-rw-r--r--plugins/modules/vyos_firewall_rules.py164
-rw-r--r--plugins/modules/vyos_interfaces.py264
-rw-r--r--plugins/modules/vyos_l3_interfaces.py215
-rw-r--r--plugins/modules/vyos_lag_interfaces.py230
-rw-r--r--plugins/modules/vyos_lldp_global.py191
-rw-r--r--plugins/modules/vyos_lldp_interfaces.py187
-rw-r--r--plugins/modules/vyos_ospfv2.py1814
-rw-r--r--plugins/modules/vyos_ospfv3.py667
-rw-r--r--plugins/modules/vyos_static_routes.py257
-rw-r--r--plugins/modules/vyos_vlan.py4
-rw-r--r--tests/integration/targets/vyos_firewall_rules/tests/cli/deleted.yaml4
-rw-r--r--tests/integration/targets/vyos_firewall_rules/tests/cli/gathered.yaml12
-rw-r--r--tests/integration/targets/vyos_firewall_rules/tests/cli/parsed.yaml47
-rw-r--r--tests/integration/targets/vyos_firewall_rules/tests/cli/rendered.yaml17
-rw-r--r--tests/integration/targets/vyos_firewall_rules/vars/main.yaml74
-rw-r--r--tests/integration/targets/vyos_interfaces/tests/cli/_parsed_config.cfg12
-rw-r--r--tests/integration/targets/vyos_interfaces/tests/cli/empty_config.yaml27
-rw-r--r--tests/integration/targets/vyos_interfaces/tests/cli/gathered.yaml26
-rw-r--r--tests/integration/targets/vyos_interfaces/tests/cli/parsed.yaml16
-rw-r--r--tests/integration/targets/vyos_interfaces/tests/cli/rendered.yaml47
-rw-r--r--tests/integration/targets/vyos_interfaces/vars/main.yaml37
-rw-r--r--tests/integration/targets/vyos_l3_interfaces/tests/cli/_parsed_config.cfg9
-rw-r--r--tests/integration/targets/vyos_l3_interfaces/tests/cli/empty_config.yaml23
-rw-r--r--tests/integration/targets/vyos_l3_interfaces/tests/cli/gathered.yaml34
-rw-r--r--tests/integration/targets/vyos_l3_interfaces/tests/cli/parsed.yaml16
-rw-r--r--tests/integration/targets/vyos_l3_interfaces/tests/cli/rendered.yaml44
-rw-r--r--tests/integration/targets/vyos_l3_interfaces/vars/main.yaml24
-rw-r--r--tests/integration/targets/vyos_lag_interfaces/tests/cli/_parsed_config.cfg8
-rw-r--r--tests/integration/targets/vyos_lag_interfaces/tests/cli/empty_config.yaml23
-rw-r--r--tests/integration/targets/vyos_lag_interfaces/tests/cli/gathered.yaml26
-rw-r--r--tests/integration/targets/vyos_lag_interfaces/tests/cli/parsed.yaml33
-rw-r--r--tests/integration/targets/vyos_lag_interfaces/tests/cli/rendered.yaml38
-rw-r--r--tests/integration/targets/vyos_lag_interfaces/vars/main.yaml10
-rw-r--r--tests/integration/targets/vyos_lldp_global/tests/cli/_parsed_config.cfg3
-rw-r--r--tests/integration/targets/vyos_lldp_global/tests/cli/empty_config.yaml23
-rw-r--r--tests/integration/targets/vyos_lldp_global/tests/cli/gathered.yaml25
-rw-r--r--tests/integration/targets/vyos_lldp_global/tests/cli/parsed.yaml15
-rw-r--r--tests/integration/targets/vyos_lldp_global/tests/cli/rendered.yaml28
-rw-r--r--tests/integration/targets/vyos_lldp_global/vars/main.yaml12
-rw-r--r--tests/integration/targets/vyos_lldp_interfaces/tests/cli/_parsed_config.cfg6
-rw-r--r--tests/integration/targets/vyos_lldp_interfaces/tests/cli/empty_config.yaml23
-rw-r--r--tests/integration/targets/vyos_lldp_interfaces/tests/cli/gathered.yaml25
-rw-r--r--tests/integration/targets/vyos_lldp_interfaces/tests/cli/parsed.yaml16
-rw-r--r--tests/integration/targets/vyos_lldp_interfaces/tests/cli/rendered.yaml37
-rw-r--r--tests/integration/targets/vyos_lldp_interfaces/vars/main.yaml30
-rw-r--r--tests/integration/targets/vyos_ospfv2/defaults/main.yaml3
-rw-r--r--tests/integration/targets/vyos_ospfv2/meta/main.yaml3
-rw-r--r--tests/integration/targets/vyos_ospfv2/tasks/cli.yaml19
-rw-r--r--tests/integration/targets/vyos_ospfv2/tasks/main.yaml4
-rw-r--r--tests/integration/targets/vyos_ospfv2/tests/cli/_parsed_config.cfg29
-rw-r--r--tests/integration/targets/vyos_ospfv2/tests/cli/_populate.yaml35
-rw-r--r--tests/integration/targets/vyos_ospfv2/tests/cli/_remove_config.yaml6
-rw-r--r--tests/integration/targets/vyos_ospfv2/tests/cli/deleted.yaml (renamed from tests/integration/targets/vyos_firewall_rules/tests/cli/deleted_rule.yaml)28
-rw-r--r--tests/integration/targets/vyos_ospfv2/tests/cli/empty_config.yaml49
-rw-r--r--tests/integration/targets/vyos_ospfv2/tests/cli/gathered.yaml24
-rw-r--r--tests/integration/targets/vyos_ospfv2/tests/cli/merged.yaml101
-rw-r--r--tests/integration/targets/vyos_ospfv2/tests/cli/merged_update.yaml70
-rw-r--r--tests/integration/targets/vyos_ospfv2/tests/cli/parsed.yaml15
-rw-r--r--tests/integration/targets/vyos_ospfv2/tests/cli/rendered.yaml76
-rw-r--r--tests/integration/targets/vyos_ospfv2/tests/cli/replaced.yaml100
-rw-r--r--tests/integration/targets/vyos_ospfv2/tests/cli/rtt.yaml149
-rw-r--r--tests/integration/targets/vyos_ospfv2/vars/main.yaml485
-rw-r--r--tests/integration/targets/vyos_ospfv3/defaults/main.yaml3
-rw-r--r--tests/integration/targets/vyos_ospfv3/meta/main.yaml3
-rw-r--r--tests/integration/targets/vyos_ospfv3/tasks/cli.yaml19
-rw-r--r--tests/integration/targets/vyos_ospfv3/tasks/main.yaml4
-rw-r--r--tests/integration/targets/vyos_ospfv3/tests/cli/_parsed_config.cfg8
-rw-r--r--tests/integration/targets/vyos_ospfv3/tests/cli/_populate.yaml13
-rw-r--r--tests/integration/targets/vyos_ospfv3/tests/cli/_remove_config.yaml6
-rw-r--r--tests/integration/targets/vyos_ospfv3/tests/cli/deleted.yaml48
-rw-r--r--tests/integration/targets/vyos_ospfv3/tests/cli/empty_config.yaml49
-rw-r--r--tests/integration/targets/vyos_ospfv3/tests/cli/gathered.yaml25
-rw-r--r--tests/integration/targets/vyos_ospfv3/tests/cli/merged.yaml62
-rw-r--r--tests/integration/targets/vyos_ospfv3/tests/cli/merged_update.yaml61
-rw-r--r--tests/integration/targets/vyos_ospfv3/tests/cli/parsed.yaml15
-rw-r--r--tests/integration/targets/vyos_ospfv3/tests/cli/rendered.yaml38
-rw-r--r--tests/integration/targets/vyos_ospfv3/tests/cli/replaced.yaml66
-rw-r--r--tests/integration/targets/vyos_ospfv3/tests/cli/rtt.yaml75
-rw-r--r--tests/integration/targets/vyos_ospfv3/vars/main.yaml142
-rw-r--r--tests/integration/targets/vyos_static_routes/tests/cli/deleted.yaml62
-rw-r--r--tests/integration/targets/vyos_static_routes/tests/cli/deleted_nh.yaml68
-rw-r--r--tests/integration/targets/vyos_static_routes/vars/main.yaml26
-rw-r--r--tests/unit/modules/network/vyos/fixtures/vyos_ospfv2_config.cfg9
-rw-r--r--tests/unit/modules/network/vyos/fixtures/vyos_ospfv3_config.cfg6
-rw-r--r--tests/unit/modules/network/vyos/test_vyos_ospfv2.py435
-rw-r--r--tests/unit/modules/network/vyos/test_vyos_ospfv3.py348
-rw-r--r--tests/unit/modules/network/vyos/test_vyos_static_routes.py12
-rw-r--r--tests/unit/modules/network/vyos/vyos_module.py1
117 files changed, 9779 insertions, 857 deletions
diff --git a/plugins/module_utils/network/vyos/argspec/interfaces/interfaces.py b/plugins/module_utils/network/vyos/argspec/interfaces/interfaces.py
index 3542cb19..fd8b6123 100644
--- a/plugins/module_utils/network/vyos/argspec/interfaces/interfaces.py
+++ b/plugins/module_utils/network/vyos/argspec/interfaces/interfaces.py
@@ -61,8 +61,17 @@ class InterfacesArgs(object): # pylint: disable=R0903
},
"type": "list",
},
+ "running_config": {"type": "str"},
"state": {
- "choices": ["merged", "replaced", "overridden", "deleted"],
+ "choices": [
+ "merged",
+ "replaced",
+ "overridden",
+ "deleted",
+ "rendered",
+ "parsed",
+ "gathered",
+ ],
"default": "merged",
"type": "str",
},
diff --git a/plugins/module_utils/network/vyos/argspec/l3_interfaces/l3_interfaces.py b/plugins/module_utils/network/vyos/argspec/l3_interfaces/l3_interfaces.py
index 91434e4b..2f1dfe45 100644
--- a/plugins/module_utils/network/vyos/argspec/l3_interfaces/l3_interfaces.py
+++ b/plugins/module_utils/network/vyos/argspec/l3_interfaces/l3_interfaces.py
@@ -25,7 +25,6 @@
The arg spec for the vyos_l3_interfaces module
"""
-
from __future__ import absolute_import, division, print_function
__metaclass__ = type
@@ -73,8 +72,17 @@ class L3_interfacesArgs(object): # pylint: disable=R0903
},
"type": "list",
},
+ "running_config": {"type": "str"},
"state": {
- "choices": ["merged", "replaced", "overridden", "deleted"],
+ "choices": [
+ "merged",
+ "replaced",
+ "overridden",
+ "deleted",
+ "rendered",
+ "gathered",
+ "parsed",
+ ],
"default": "merged",
"type": "str",
},
diff --git a/plugins/module_utils/network/vyos/argspec/lag_interfaces/lag_interfaces.py b/plugins/module_utils/network/vyos/argspec/lag_interfaces/lag_interfaces.py
index 97c5d5a2..6cfdabf1 100644
--- a/plugins/module_utils/network/vyos/argspec/lag_interfaces/lag_interfaces.py
+++ b/plugins/module_utils/network/vyos/argspec/lag_interfaces/lag_interfaces.py
@@ -19,7 +19,6 @@
# builder template.
#
#############################################
-
"""
The arg spec for the vyos_lag_interfaces module
"""
@@ -72,8 +71,17 @@ class Lag_interfacesArgs(object): # pylint: disable=R0903
},
"type": "list",
},
+ "running_config": {"type": "str"},
"state": {
- "choices": ["merged", "replaced", "overridden", "deleted"],
+ "choices": [
+ "merged",
+ "replaced",
+ "overridden",
+ "deleted",
+ "rendered",
+ "gathered",
+ "parsed",
+ ],
"default": "merged",
"type": "str",
},
diff --git a/plugins/module_utils/network/vyos/argspec/lldp_global/lldp_global.py b/plugins/module_utils/network/vyos/argspec/lldp_global/lldp_global.py
index 84bbc00c..6205fd77 100644
--- a/plugins/module_utils/network/vyos/argspec/lldp_global/lldp_global.py
+++ b/plugins/module_utils/network/vyos/argspec/lldp_global/lldp_global.py
@@ -19,7 +19,6 @@
# builder template.
#
#############################################
-
"""
The arg spec for the vyos_lldp_global module
"""
@@ -48,8 +47,16 @@ class Lldp_globalArgs(object): # pylint: disable=R0903
},
"type": "dict",
},
+ "running_config": {"type": "str"},
"state": {
- "choices": ["merged", "replaced", "deleted"],
+ "choices": [
+ "merged",
+ "replaced",
+ "deleted",
+ "rendered",
+ "parsed",
+ "gathered",
+ ],
"default": "merged",
"type": "str",
},
diff --git a/plugins/module_utils/network/vyos/argspec/lldp_interfaces/lldp_interfaces.py b/plugins/module_utils/network/vyos/argspec/lldp_interfaces/lldp_interfaces.py
index 2976fc09..109ea430 100644
--- a/plugins/module_utils/network/vyos/argspec/lldp_interfaces/lldp_interfaces.py
+++ b/plugins/module_utils/network/vyos/argspec/lldp_interfaces/lldp_interfaces.py
@@ -81,8 +81,17 @@ class Lldp_interfacesArgs(object): # pylint: disable=R0903
},
"type": "list",
},
+ "running_config": {"type": "str"},
"state": {
- "choices": ["merged", "replaced", "overridden", "deleted"],
+ "choices": [
+ "merged",
+ "replaced",
+ "overridden",
+ "deleted",
+ "rendered",
+ "gathered",
+ "parsed",
+ ],
"default": "merged",
"type": "str",
},
diff --git a/plugins/module_utils/network/vyos/argspec/ospfv2/__init__.py b/plugins/module_utils/network/vyos/argspec/ospfv2/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/plugins/module_utils/network/vyos/argspec/ospfv2/__init__.py
diff --git a/plugins/module_utils/network/vyos/argspec/ospfv2/ospfv2.py b/plugins/module_utils/network/vyos/argspec/ospfv2/ospfv2.py
new file mode 100644
index 00000000..275aaf36
--- /dev/null
+++ b/plugins/module_utils/network/vyos/argspec/ospfv2/ospfv2.py
@@ -0,0 +1,269 @@
+#
+# -*- 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_ospfv2 module
+"""
+
+
+class Ospfv2Args(object): # pylint: disable=R0903
+ """The arg spec for the vyos_ospfv2 module
+ """
+
+ def __init__(self, **kwargs):
+ pass
+
+ argument_spec = {
+ "config": {
+ "options": {
+ "auto_cost": {
+ "options": {"reference_bandwidth": {"type": "int"}},
+ "type": "dict",
+ },
+ "default_information": {
+ "options": {
+ "originate": {
+ "options": {
+ "always": {"type": "bool"},
+ "metric": {"type": "int"},
+ "metric_type": {"type": "int"},
+ "route_map": {"type": "str"},
+ },
+ "type": "dict",
+ }
+ },
+ "type": "dict",
+ },
+ "default_metric": {"type": "int"},
+ "distance": {
+ "options": {
+ "global": {"type": "int"},
+ "ospf": {
+ "options": {
+ "external": {"type": "int"},
+ "inter_area": {"type": "int"},
+ "intra_area": {"type": "int"},
+ },
+ "type": "dict",
+ },
+ },
+ "type": "dict",
+ },
+ "log_adjacency_changes": {
+ "choices": ["detail"],
+ "type": "str",
+ },
+ "max_metric": {
+ "options": {
+ "router_lsa": {
+ "options": {
+ "administrative": {"type": "bool"},
+ "on_shutdown": {"type": "int"},
+ "on_startup": {"type": "int"},
+ },
+ "type": "dict",
+ }
+ },
+ "type": "dict",
+ },
+ "mpls_te": {
+ "options": {
+ "enabled": {"type": "bool"},
+ "router_address": {"type": "str"},
+ },
+ "type": "dict",
+ },
+ "neighbor": {
+ "elements": "dict",
+ "options": {
+ "neighbor_id": {"type": "str"},
+ "poll_interval": {"type": "int"},
+ "priority": {"type": "int"},
+ },
+ "type": "list",
+ },
+ "areas": {
+ "elements": "dict",
+ "options": {
+ "area_id": {"type": "str"},
+ "area_type": {
+ "options": {
+ "normal": {"type": "bool"},
+ "nssa": {
+ "options": {
+ "default_cost": {"type": "int"},
+ "no_summary": {"type": "bool"},
+ "set": {"type": "bool"},
+ "translate": {
+ "choices": [
+ "always",
+ "candidate",
+ "never",
+ ],
+ "type": "str",
+ },
+ },
+ "type": "dict",
+ },
+ "stub": {
+ "options": {
+ "default_cost": {"type": "int"},
+ "no_summary": {"type": "bool"},
+ "set": {"type": "bool"},
+ },
+ "type": "dict",
+ },
+ },
+ "type": "dict",
+ },
+ "authentication": {
+ "choices": ["plaintext-password", "md5"],
+ "type": "str",
+ },
+ "network": {
+ "elements": "dict",
+ "options": {
+ "address": {"required": True, "type": "str"}
+ },
+ "type": "list",
+ },
+ "range": {
+ "elements": "dict",
+ "options": {
+ "address": {"type": "str"},
+ "cost": {"type": "int"},
+ "not_advertise": {"type": "bool"},
+ "substitute": {"type": "str"},
+ },
+ "type": "list",
+ },
+ "shortcut": {
+ "choices": ["default", "disable", "enable"],
+ "type": "str",
+ },
+ "virtual_link": {
+ "elements": "dict",
+ "options": {
+ "address": {"type": "str"},
+ "authentication": {
+ "options": {
+ "md5": {
+ "elements": "dict",
+ "options": {
+ "key_id": {"type": "int"},
+ "md5_key": {"type": "str"},
+ },
+ "type": "list",
+ },
+ "plaintext_password": {"type": "str"},
+ },
+ "type": "dict",
+ },
+ "dead_interval": {"type": "int"},
+ "hello_interval": {"type": "int"},
+ "retransmit_interval": {"type": "int"},
+ "transmit_delay": {"type": "int"},
+ },
+ "type": "list",
+ },
+ },
+ "type": "list",
+ },
+ "parameters": {
+ "options": {
+ "abr_type": {
+ "choices": [
+ "cisco",
+ "ibm",
+ "shortcut",
+ "standard",
+ ],
+ "type": "str",
+ },
+ "opaque_lsa": {"type": "bool"},
+ "rfc1583_compatibility": {"type": "bool"},
+ "router_id": {"type": "str"},
+ },
+ "type": "dict",
+ },
+ "passive_interface": {"type": "list"},
+ "passive_interface_exclude": {"type": "list"},
+ "redistribute": {
+ "elements": "dict",
+ "options": {
+ "metric": {"type": "int"},
+ "metric_type": {"type": "int"},
+ "route_map": {"type": "str"},
+ "route_type": {
+ "choices": [
+ "bgp",
+ "connected",
+ "kernel",
+ "rip",
+ "static",
+ ],
+ "type": "str",
+ },
+ },
+ "type": "list",
+ },
+ "route_map": {"type": "list"},
+ "timers": {
+ "options": {
+ "refresh": {
+ "options": {"timers": {"type": "int"}},
+ "type": "dict",
+ },
+ "throttle": {
+ "options": {
+ "spf": {
+ "options": {
+ "delay": {"type": "int"},
+ "initial_holdtime": {"type": "int"},
+ "max_holdtime": {"type": "int"},
+ },
+ "type": "dict",
+ }
+ },
+ "type": "dict",
+ },
+ },
+ "type": "dict",
+ },
+ },
+ "type": "dict",
+ },
+ "running_config": {"type": "str"},
+ "state": {
+ "choices": [
+ "merged",
+ "replaced",
+ "deleted",
+ "parsed",
+ "gathered",
+ "rendered",
+ ],
+ "default": "merged",
+ "type": "str",
+ },
+ } # pylint: disable=C0301
diff --git a/plugins/module_utils/network/vyos/argspec/ospfv3/__init__.py b/plugins/module_utils/network/vyos/argspec/ospfv3/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/plugins/module_utils/network/vyos/argspec/ospfv3/__init__.py
diff --git a/plugins/module_utils/network/vyos/argspec/ospfv3/ospfv3.py b/plugins/module_utils/network/vyos/argspec/ospfv3/ospfv3.py
new file mode 100644
index 00000000..66aaa8c4
--- /dev/null
+++ b/plugins/module_utils/network/vyos/argspec/ospfv3/ospfv3.py
@@ -0,0 +1,94 @@
+#
+# -*- 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_ospfv3 module
+"""
+
+
+class Ospfv3Args(object): # pylint: disable=R0903
+ """The arg spec for the vyos_ospfv3 module
+ """
+
+ def __init__(self, **kwargs):
+ pass
+
+ argument_spec = {
+ "config": {
+ "options": {
+ "areas": {
+ "elements": "dict",
+ "options": {
+ "area_id": {"type": "str"},
+ "export_list": {"type": "str"},
+ "import_list": {"type": "str"},
+ "range": {
+ "elements": "dict",
+ "options": {
+ "address": {"type": "str"},
+ "advertise": {"type": "bool"},
+ "not_advertise": {"type": "bool"},
+ },
+ "type": "list",
+ },
+ },
+ "type": "list",
+ },
+ "parameters": {
+ "options": {"router_id": {"type": "str"}},
+ "type": "dict",
+ },
+ "redistribute": {
+ "elements": "dict",
+ "options": {
+ "route_map": {"type": "str"},
+ "route_type": {
+ "choices": [
+ "bgp",
+ "connected",
+ "kernel",
+ "ripng",
+ "static",
+ ],
+ "type": "str",
+ },
+ },
+ "type": "list",
+ },
+ },
+ "type": "dict",
+ },
+ "running_config": {"type": "str"},
+ "state": {
+ "choices": [
+ "merged",
+ "replaced",
+ "deleted",
+ "parsed",
+ "gathered",
+ "rendered",
+ ],
+ "default": "merged",
+ "type": "str",
+ },
+ } # pylint: disable=C0301
diff --git a/plugins/module_utils/network/vyos/config/firewall_rules/firewall_rules.py b/plugins/module_utils/network/vyos/config/firewall_rules/firewall_rules.py
index e58593f4..5c377410 100644
--- a/plugins/module_utils/network/vyos/config/firewall_rules/firewall_rules.py
+++ b/plugins/module_utils/network/vyos/config/firewall_rules/firewall_rules.py
@@ -235,28 +235,11 @@ class Firewall_rules(ConfigBase):
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
- )
+ commands.append(
+ self._compute_command(
+ w["afi"], h["name"], remove=True
)
+ )
elif have:
for h in have:
if h["afi"] == w["afi"]:
diff --git a/plugins/module_utils/network/vyos/config/interfaces/interfaces.py b/plugins/module_utils/network/vyos/config/interfaces/interfaces.py
index deb504c2..51bf98e3 100644
--- a/plugins/module_utils/network/vyos/config/interfaces/interfaces.py
+++ b/plugins/module_utils/network/vyos/config/interfaces/interfaces.py
@@ -13,7 +13,6 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
from copy import deepcopy
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import (
ConfigBase,
@@ -49,14 +48,14 @@ class Interfaces(ConfigBase):
def __init__(self, module):
super(Interfaces, self).__init__(module)
- def get_interfaces_facts(self):
+ def get_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
+ self.gather_subset, self.gather_network_resources, data=data
)
interfaces_facts = facts["ansible_network_resources"].get("interfaces")
if not interfaces_facts:
@@ -72,25 +71,42 @@ class Interfaces(ConfigBase):
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
+ if self.state in self.ACTION_STATES:
+ existing_interfaces_facts = self.get_interfaces_facts()
+ else:
+ existing_interfaces_facts = []
- result["commands"] = commands
+ if self.state in self.ACTION_STATES or self.state == "rendered":
+ commands.extend(self.set_config(existing_interfaces_facts))
- if self._module._diff:
- result["diff"] = resp["diff"] if result["changed"] else None
+ if commands and self.state in self.ACTION_STATES:
+ if not self._module.check_mode:
+ self._connection.edit_config(commands)
+ result["changed"] = True
- changed_interfaces_facts = self.get_interfaces_facts()
+ if self.state in self.ACTION_STATES:
+ result["commands"] = commands
+
+ if self.state in self.ACTION_STATES or self.state == "gathered":
+ changed_interfaces_facts = self.get_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_interfaces_facts(data=running_config)
+ else:
+ changed_interfaces_facts = []
- result["before"] = existing_interfaces_facts
- if result["changed"]:
- result["after"] = changed_interfaces_facts
+ if self.state in self.ACTION_STATES:
+ result["before"] = existing_interfaces_facts
+ if result["changed"]:
+ result["after"] = changed_interfaces_facts
+ elif self.state == "gathered":
+ result["gathered"] = changed_interfaces_facts
result["warnings"] = warnings
return result
@@ -118,19 +134,21 @@ class Interfaces(ConfigBase):
to the desired configuration
"""
commands = []
- state = self._module.params["state"]
- if state in ("merged", "replaced", "overridden") and not want:
+ 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(
- state
+ self.state
)
)
- if state == "overridden":
+ if self.state == "overridden":
commands.extend(self._state_overridden(want=want, have=have))
- elif state == "deleted":
+ elif self.state == "deleted":
if not want:
for intf in have:
commands.extend(
@@ -146,12 +164,12 @@ class Interfaces(ConfigBase):
obj_in_have = search_obj_in_list(name, have)
if not obj_in_have:
- obj_in_have = {"name": item["name"]}
+ obj_in_have = {"name": name}
- elif state == "merged":
+ if self.state in ("merged", "rendered"):
commands.extend(self._state_merged(item, obj_in_have))
- elif state == "replaced":
+ elif self.state == "replaced":
commands.extend(self._state_replaced(item, obj_in_have))
return commands
diff --git a/plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py b/plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py
index a23e417f..122cc1eb 100644
--- a/plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py
+++ b/plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py
@@ -52,14 +52,14 @@ class L3_interfaces(ConfigBase):
def __init__(self, module):
super(L3_interfaces, self).__init__(module)
- def get_l3_interfaces_facts(self):
+ def get_l3_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
+ self.gather_subset, self.gather_network_resources, data=data
)
l3_interfaces_facts = facts["ansible_network_resources"].get(
"l3_interfaces"
@@ -78,25 +78,44 @@ class L3_interfaces(ConfigBase):
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
+ if self.state in self.ACTION_STATES:
+ existing_l3_interfaces_facts = self.get_l3_interfaces_facts()
+ else:
+ existing_l3_interfaces_facts = []
- result["commands"] = commands
+ if self.state in self.ACTION_STATES or self.state == "rendered":
+ commands.extend(self.set_config(existing_l3_interfaces_facts))
- if self._module._diff:
- result["diff"] = resp["diff"] if result["changed"] else None
+ if commands and self.state in self.ACTION_STATES:
+ if not self._module.check_mode:
+ self._connection.edit_config(commands)
+ result["changed"] = True
- changed_l3_interfaces_facts = self.get_l3_interfaces_facts()
+ if self.state in self.ACTION_STATES:
+ result["commands"] = commands
+
+ if self.state in self.ACTION_STATES or self.state == "gathered":
+ changed_l3_interfaces_facts = self.get_l3_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_l3_interfaces_facts(
+ data=running_config
+ )
+ else:
+ changed_l3_interfaces_facts = []
- result["before"] = existing_l3_interfaces_facts
- if result["changed"]:
- result["after"] = changed_l3_interfaces_facts
+ if self.state in self.ACTION_STATES:
+ result["before"] = existing_l3_interfaces_facts
+ if result["changed"]:
+ result["after"] = changed_l3_interfaces_facts
+ elif self.state == "gathered":
+ result["gathered"] = changed_l3_interfaces_facts
result["warnings"] = warnings
return result
@@ -126,7 +145,10 @@ class L3_interfaces(ConfigBase):
commands = []
state = self._module.params["state"]
- if state in ("merged", "replaced", "overridden") and not want:
+ if (
+ 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(
state
@@ -154,7 +176,7 @@ class L3_interfaces(ConfigBase):
if not obj_in_have:
obj_in_have = {"name": item["name"]}
- if state == "merged":
+ if state in ("merged", "rendered"):
commands.extend(self._state_merged(item, obj_in_have))
elif state == "replaced":
diff --git a/plugins/module_utils/network/vyos/config/lag_interfaces/lag_interfaces.py b/plugins/module_utils/network/vyos/config/lag_interfaces/lag_interfaces.py
index 2a9efd99..452670f1 100644
--- a/plugins/module_utils/network/vyos/config/lag_interfaces/lag_interfaces.py
+++ b/plugins/module_utils/network/vyos/config/lag_interfaces/lag_interfaces.py
@@ -56,14 +56,14 @@ class Lag_interfaces(ConfigBase):
def __init__(self, module):
super(Lag_interfaces, self).__init__(module)
- def get_lag_interfaces_facts(self):
+ def get_lag_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
+ self.gather_subset, self.gather_network_resources, data=data
)
lag_interfaces_facts = facts["ansible_network_resources"].get(
"lag_interfaces"
@@ -79,27 +79,47 @@ class Lag_interfaces(ConfigBase):
: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
+ commands = list()
+
+ if self.state in self.ACTION_STATES:
+ existing_lag_interfaces_facts = self.get_lag_interfaces_facts()
+ else:
+ existing_lag_interfaces_facts = []
- result["commands"] = commands
+ if self.state in self.ACTION_STATES or self.state == "rendered":
+ commands.extend(self.set_config(existing_lag_interfaces_facts))
- if self._module._diff:
- result["diff"] = resp["diff"] if result["changed"] else None
+ if commands and self.state in self.ACTION_STATES:
+ if not self._module.check_mode:
+ self._connection.edit_config(commands)
+ result["changed"] = True
- changed_lag_interfaces_facts = self.get_lag_interfaces_facts()
+ if self.state in self.ACTION_STATES:
+ result["commands"] = commands
+
+ if self.state in self.ACTION_STATES or self.state == "gathered":
+ changed_lag_interfaces_facts = self.get_lag_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_lag_interfaces_facts(
+ data=running_config
+ )
+ else:
+ changed_lag_interfaces_facts = []
- result["before"] = existing_lag_interfaces_facts
- if result["changed"]:
- result["after"] = changed_lag_interfaces_facts
+ if self.state in self.ACTION_STATES:
+ result["before"] = existing_lag_interfaces_facts
+ if result["changed"]:
+ result["after"] = changed_lag_interfaces_facts
+ elif self.state == "gathered":
+ result["gathered"] = changed_lag_interfaces_facts
result["warnings"] = warnings
return result
@@ -127,16 +147,18 @@ class Lag_interfaces(ConfigBase):
to the desired configuration
"""
commands = []
- state = self._module.params["state"]
- if state in ("merged", "replaced", "overridden") and not want:
+ 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(
- state
+ self.state
)
)
- if state == "overridden":
+ if self.state == "overridden":
commands.extend(self._state_overridden(want, have))
- elif state == "deleted":
+ elif self.state == "deleted":
if want:
for want_item in want:
name = want_item["name"]
@@ -149,9 +171,9 @@ class Lag_interfaces(ConfigBase):
for want_item in want:
name = want_item["name"]
obj_in_have = search_obj_in_list(name, have)
- if state == "merged":
+ if self.state in ("merged", "rendered"):
commands.extend(self._state_merged(want_item, obj_in_have))
- elif state == "replaced":
+ elif self.state == "replaced":
commands.extend(
self._state_replaced(want_item, obj_in_have)
)
diff --git a/plugins/module_utils/network/vyos/config/lldp_global/lldp_global.py b/plugins/module_utils/network/vyos/config/lldp_global/lldp_global.py
index 010e96dd..c70d27ff 100644
--- a/plugins/module_utils/network/vyos/config/lldp_global/lldp_global.py
+++ b/plugins/module_utils/network/vyos/config/lldp_global/lldp_global.py
@@ -47,20 +47,20 @@ class Lldp_global(ConfigBase):
def __init__(self, module):
super(Lldp_global, self).__init__(module)
- def get_lldp_global_facts(self):
+ def get_lldp_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
+ self.gather_subset, self.gather_network_resources, data=data
)
lldp_global_facts = facts["ansible_network_resources"].get(
"lldp_global"
)
if not lldp_global_facts:
- return {}
+ return []
return lldp_global_facts
def execute_module(self):
@@ -70,22 +70,45 @@ class Lldp_global(ConfigBase):
:returns: The result from module execution
"""
result = {"changed": False}
- commands = list()
warnings = list()
+ commands = list()
+
+ if self.state in self.ACTION_STATES:
+ existing_lldp_global_facts = self.get_lldp_global_facts()
+ else:
+ existing_lldp_global_facts = []
- existing_lldp_global_facts = self.get_lldp_global_facts()
- commands.extend(self.set_config(existing_lldp_global_facts))
- if commands:
+ if self.state in self.ACTION_STATES or self.state == "rendered":
+ commands.extend(self.set_config(existing_lldp_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
- result["commands"] = commands
- changed_lldp_global_facts = self.get_lldp_global_facts()
+ if self.state in self.ACTION_STATES:
+ result["commands"] = commands
+
+ if self.state in self.ACTION_STATES or self.state == "gathered":
+ changed_lldp_global_facts = self.get_lldp_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_lldp_global_facts(data=running_config)
+ else:
+ changed_lldp_global_facts = []
- result["before"] = existing_lldp_global_facts
- if result["changed"]:
- result["after"] = changed_lldp_global_facts
+ if self.state in self.ACTION_STATES:
+ result["before"] = existing_lldp_global_facts
+ if result["changed"]:
+ result["after"] = changed_lldp_global_facts
+ elif self.state == "gathered":
+ result["gathered"] = changed_lldp_global_facts
result["warnings"] = warnings
return result
@@ -113,18 +136,17 @@ class Lldp_global(ConfigBase):
to the desired configuration
"""
commands = []
- state = self._module.params["state"]
- if state in ("merged", "replaced") and not want:
+ if self.state in ("merged", "replaced", "rendered") and not want:
self._module.fail_json(
msg="value of config parameter must not be empty for state {0}".format(
- state
+ self.state
)
)
- if state == "deleted":
+ if self.state == "deleted":
commands.extend(self._state_deleted(want=None, have=have))
- elif state == "merged":
+ elif self.state in ("merged", "rendered"):
commands.extend(self._state_merged(want=want, have=have))
- elif state == "replaced":
+ elif self.state == "replaced":
commands.extend(self._state_replaced(want=want, have=have))
return commands
diff --git a/plugins/module_utils/network/vyos/config/lldp_interfaces/lldp_interfaces.py b/plugins/module_utils/network/vyos/config/lldp_interfaces/lldp_interfaces.py
index 377fec9a..94e39c35 100644
--- a/plugins/module_utils/network/vyos/config/lldp_interfaces/lldp_interfaces.py
+++ b/plugins/module_utils/network/vyos/config/lldp_interfaces/lldp_interfaces.py
@@ -15,7 +15,6 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import (
ConfigBase,
)
@@ -54,14 +53,14 @@ class Lldp_interfaces(ConfigBase):
def __init__(self, module):
super(Lldp_interfaces, self).__init__(module)
- def get_lldp_interfaces_facts(self):
+ def get_lldp_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
+ self.gather_subset, self.gather_network_resources, data=data
)
lldp_interfaces_facts = facts["ansible_network_resources"].get(
"lldp_interfaces"
@@ -77,26 +76,47 @@ class Lldp_interfaces(ConfigBase):
: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
+ commands = list()
+
+ if self.state in self.ACTION_STATES:
+ existing_lldp_interfaces_facts = self.get_lldp_interfaces_facts()
+ else:
+ existing_lldp_interfaces_facts = []
- result["commands"] = commands
+ if self.state in self.ACTION_STATES or self.state == "rendered":
+ commands.extend(self.set_config(existing_lldp_interfaces_facts))
- if self._module._diff:
- result["diff"] = resp["diff"] if result["changed"] else None
+ if commands and self.state in self.ACTION_STATES:
+ if not self._module.check_mode:
+ self._connection.edit_config(commands)
+ result["changed"] = True
- changed_lldp_interfaces_facts = self.get_lldp_interfaces_facts()
- result["before"] = existing_lldp_interfaces_facts
- if result["changed"]:
- result["after"] = changed_lldp_interfaces_facts
+ if self.state in self.ACTION_STATES:
+ result["commands"] = commands
+
+ if self.state in self.ACTION_STATES or self.state == "gathered":
+ changed_lldp_interfaces_facts = self.get_lldp_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_lldp_interfaces_facts(
+ data=running_config
+ )
+ else:
+ changed_lldp_interfaces_facts = []
+
+ if self.state in self.ACTION_STATES:
+ result["before"] = existing_lldp_interfaces_facts
+ if result["changed"]:
+ result["after"] = changed_lldp_interfaces_facts
+ elif self.state == "gathered":
+ result["gathered"] = changed_lldp_interfaces_facts
result["warnings"] = warnings
return result
@@ -124,16 +144,18 @@ class Lldp_interfaces(ConfigBase):
to the desired configuration
"""
commands = []
- state = self._module.params["state"]
- if state in ("merged", "replaced", "overridden") and not want:
+ 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(
- state
+ self.state
)
)
- if state == "overridden":
+ if self.state == "overridden":
commands.extend(self._state_overridden(want=want, have=have))
- elif state == "deleted":
+ elif self.state == "deleted":
if want:
for item in want:
name = item["name"]
@@ -150,11 +172,11 @@ class Lldp_interfaces(ConfigBase):
for want_item in want:
name = want_item["name"]
have_item = search_obj_in_list(name, have)
- if state == "merged":
+ if self.state in ("merged", "rendered"):
commands.extend(
self._state_merged(want=want_item, have=have_item)
)
- else:
+ if self.state == "replaced":
commands.extend(
self._state_replaced(want=want_item, have=have_item)
)
@@ -243,7 +265,6 @@ class Lldp_interfaces(ConfigBase):
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:
diff --git a/plugins/module_utils/network/vyos/config/ospfv2/__init__.py b/plugins/module_utils/network/vyos/config/ospfv2/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/plugins/module_utils/network/vyos/config/ospfv2/__init__.py
diff --git a/plugins/module_utils/network/vyos/config/ospfv2/ospfv2.py b/plugins/module_utils/network/vyos/config/ospfv2/ospfv2.py
new file mode 100644
index 00000000..fd25c178
--- /dev/null
+++ b/plugins/module_utils/network/vyos/config/ospfv2/ospfv2.py
@@ -0,0 +1,949 @@
+#
+# -*- 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_ospfv2 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_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import (
+ ConfigBase,
+)
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
+ to_list,
+ remove_empties,
+)
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import (
+ Facts,
+)
+from ansible.module_utils.six import iteritems
+
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import (
+ list_diff_want_only,
+ _in_target,
+ _is_w_same,
+ _bool_to_str,
+)
+
+
+class Ospfv2(ConfigBase):
+
+ """
+ The vyos_ospfv2 class
+ """
+
+ gather_subset = ["!all", "!min"]
+
+ gather_network_resources = ["ospfv2"]
+
+ def __init__(self, module):
+ super(Ospfv2, self).__init__(module)
+
+ def get_ospfv2_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
+ )
+ ospfv2_facts = facts["ansible_network_resources"].get("ospfv2", {})
+ return ospfv2_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_ospfv2_facts = self.get_ospfv2_facts()
+ else:
+ existing_ospfv2_facts = {}
+
+ if self.state in self.ACTION_STATES or self.state == "rendered":
+ commands.extend(self.set_config(existing_ospfv2_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_ospfv2_facts = self.get_ospfv2_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_ospfv2_facts(data=running_config)
+ else:
+ changed_ospfv2_facts = {}
+
+ if self.state in self.ACTION_STATES:
+ result["before"] = existing_ospfv2_facts
+ if result["changed"]:
+ result["after"] = changed_ospfv2_facts
+ elif self.state == "gathered":
+ result["gathered"] = changed_ospfv2_facts
+
+ result["warnings"] = warnings
+ return result
+
+ def set_config(self, existing_ospfv2_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_ospfv2_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 == "deleted":
+ commands.extend(self._state_deleted(h))
+ elif self.state in ("merged", "rendered"):
+ commands.extend(self._state_merged(w, h))
+ elif self.state == "replaced":
+ commands.extend(self._state_replaced(w, h))
+ return commands
+
+ def search_obj_in_have(self, have, w_name, key):
+ """
+ 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:
+ for item in have:
+ if item[key] == w_name[key]:
+ return item
+ 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:
+ commands.extend(self._render_ospf_param(have, want, opr=False))
+ commands.extend(self._render_ospf_param(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_ospf_param(want, have))
+ 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.append("delete protocols ospf")
+ return commands
+
+ def _render_ospf_param(self, want, have, opr=True):
+ """
+ This function forms the set/delete commands for ospf leaf attributes
+ and triggers the process for other child attributes.
+ for firewall_global attributes.
+ :param w: the desired config.
+ :param h: the target config.
+ :param opr: True/False.
+ :return: generated commands list.
+ """
+
+ commands = []
+ w = deepcopy(remove_empties(want))
+ leaf = ("default_metric", "log_adjacency_changes")
+ if w:
+ for (key, val) in iteritems(w):
+ if opr and key in leaf and not _is_w_same(w, have, key):
+ commands.append(
+ self._form_attr_cmd(
+ attr=key, val=_bool_to_str(val), opr=opr
+ )
+ )
+ elif not opr and key in leaf and not _in_target(have, key):
+ commands.append(
+ self._form_attr_cmd(
+ attr=key, val=_bool_to_str(val), opr=opr
+ )
+ )
+ else:
+ commands.extend(
+ self._render_child_param(w, have, key, opr)
+ )
+ return commands
+
+ def _render_child_param(self, w, h, key, opr=True):
+ """
+ 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 in ("neighbor", "redistribute"):
+ commands.extend(self._render_list_dict_param(key, w, h, opr=opr))
+ elif key in ("default_information", "max_metric"):
+ commands.extend(self._render_nested_dict_param(key, w, h, opr=opr))
+ elif key in ("mpls_te", "auto_cost", "parameters", "auto_cost"):
+ commands.extend(self._render_dict_param(key, w, h, opr=opr))
+ elif key in (
+ "route_map",
+ "passive_interface",
+ "passive_interface_exclude",
+ ):
+ commands.extend(self._render_list_param(key, w, h, opr=opr))
+ elif key == "areas":
+ commands.extend(self._render_areas(key, w, h, opr=opr))
+ elif key == "timers":
+ commands.extend(self._render_timers(key, w, h, opr=opr))
+ elif key == "distance":
+ commands.extend(self._render_distance(key, w, h, opr=opr))
+ return commands
+
+ def _render_dict_param(self, attr, want, have, opr=True):
+ """
+ This function generate the commands for dictionary elements.
+ :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 = {}
+ if have:
+ h = have.get(attr) or {}
+ if not opr and not h:
+ commands.append(self._form_attr_cmd(attr=attr, opr=opr))
+ elif want[attr]:
+ leaf_dict = {
+ "auto_cost": "reference_bandwidth",
+ "mpls_te": ("enabled", "router_address"),
+ "parameters": (
+ "router_id",
+ "abr_type",
+ "opaque_lsa",
+ "rfc1583_compatibility",
+ ),
+ }
+ leaf = leaf_dict[attr]
+ for (item, value) in iteritems(want[attr]):
+ if (
+ opr
+ and item in leaf
+ and not _is_w_same(want[attr], h, item)
+ ):
+ if item == "enabled":
+ item = "enable"
+ if item in (
+ "opaque_lsa",
+ "enable",
+ "rfc1583_compatibility",
+ ):
+ commands.append(
+ self._form_attr_cmd(key=attr, attr=item, opr=opr)
+ )
+ else:
+ commands.append(
+ self._form_attr_cmd(
+ key=attr, attr=item, val=value, opr=opr
+ )
+ )
+ elif not opr and item in leaf and not _in_target(h, item):
+ if item == "enabled":
+ commands.append(
+ self._form_attr_cmd(
+ key=attr, attr="enable", opr=opr
+ )
+ )
+ else:
+ commands.append(
+ self._form_attr_cmd(key=attr, attr=item, opr=opr)
+ )
+ return commands
+
+ def _render_list_param(self, attr, want, have, cmd=None, opr=True):
+ """
+ This function forms the commands for passed target list attributes'.
+ :param attr: attribute name.
+ :param w: the desired config.
+ :param h: the target config.
+ :param cmd: commands to be prepend.
+ :param opr: True/False.
+ :return: generated list of commands.
+ """
+
+ commands = []
+ h = []
+ if want:
+ w = want.get(attr) or []
+ if have:
+ h = have.get(attr) or []
+ if not cmd:
+ cmd = self._compute_command(opr=opr)
+ if w:
+ if opr:
+ members = list_diff_want_only(w, h)
+ for member in members:
+ command = cmd + attr.replace("_", "-") + " "
+ if attr == "network":
+ command += member["address"]
+ else:
+ command += member
+ commands.append(command)
+ elif not opr:
+ if h:
+ for member in w:
+ if attr == "network":
+ if not self.search_obj_in_have(
+ h, member, "address"
+ ):
+ commands.append(
+ cmd
+ + attr.replace("_", "-")
+ + " "
+ + member["address"]
+ )
+ elif member not in h:
+ commands.append(
+ cmd + attr.replace("_", "-") + " " + member
+ )
+ else:
+ commands.append(cmd + " " + attr.replace("_", "-"))
+ return commands
+
+ def _render_vlink(self, attr, want, have, cmd=None, opr=True):
+ """
+ This function forms the set/delete commands based on the 'opr' type
+ for attributes with in desired list of dictionary.
+ :param attr: attribute name.
+ :param w: the desired config.
+ :param h: the target config.
+ :param cmd: commands to be prepend.
+ :param opr: True/False.
+ :return: generated commands list.
+ """
+
+ commands = []
+ h = []
+ name = {"virtual_link": "address"}
+ leaf_dict = {
+ "virtual_link": (
+ "address",
+ "dead_interval",
+ "transmit_delay",
+ "hello_interval",
+ "retransmit_interval",
+ )
+ }
+ leaf = leaf_dict[attr]
+ w = want.get(attr) or []
+ if have:
+ h = have.get(attr) or []
+ if not opr and not h:
+ commands.append(cmd + attr.replace("_", "-"))
+ elif w:
+ for w_item in w:
+ for (key, val) in iteritems(w_item):
+ if not cmd:
+ cmd = self._compute_command(opr=opr)
+ h_item = self.search_obj_in_have(h, w_item, name[attr])
+ if (
+ opr
+ and key in leaf
+ and not _is_w_same(w_item, h_item, key)
+ ):
+ if key in "address":
+ commands.append(
+ cmd + attr.replace("_", "-") + " " + str(val)
+ )
+ else:
+ commands.append(
+ cmd
+ + attr.replace("_", "-")
+ + " "
+ + w_item[name[attr]]
+ + " "
+ + key.replace("_", "-")
+ + " "
+ + str(val)
+ )
+ elif (
+ not opr and key in leaf and not _in_target(h_item, key)
+ ):
+ if key in "address":
+ commands.append(
+ cmd + attr.replace("_", "-") + " " + str(val)
+ )
+ else:
+ commands.append(
+ cmd
+ + attr.replace("_", "-")
+ + " "
+ + w_item[name[attr]]
+ + " "
+ + key
+ )
+ elif key == "authentication":
+ commands.extend(
+ self._render_vlink_auth(
+ attr,
+ key,
+ w_item,
+ h_item,
+ w_item["address"],
+ cmd,
+ opr,
+ )
+ )
+ return commands
+
+ def _render_vlink_auth(
+ self, attr, key, want, have, address, cmd=None, opr=True
+ ):
+ """
+ This function forms the set/delete commands based on the 'opr' type
+ for attributes with in desired list of dictionary.
+ :param attr: attribute name.
+ :param w: the desired config.
+ :param h: the target config.
+ :param cmd: commands to be prepend.
+ :param opr: True/False.
+ :return: generated commands list.
+ """
+
+ commands = []
+ h = []
+
+ w = want.get(key) or {}
+ if have:
+ h = have.get(key) or {}
+ cmd += attr.replace("_", "-") + " " + address + " " + key + " "
+ commands.extend(self._render_list_dict_param("md5", w, h, cmd, opr))
+ return commands
+
+ def _render_list_dict_param(self, attr, want, have, cmd=None, opr=True):
+ """
+ This function forms the set/delete commands based on the 'opr' type
+ for attributes with in desired list of dictionary.
+ :param attr: attribute name.
+ :param w: the desired config.
+ :param h: the target config.
+ :param cmd: commands to be prepend.
+ :param opr: True/False.
+ :return: generated commands list.
+ """
+
+ commands = []
+ h = []
+ name = {
+ "redistribute": "route_type",
+ "neighbor": "neighbor_id",
+ "range": "address",
+ "md5": "key_id",
+ "vlink": "address",
+ }
+ leaf_dict = {
+ "md5": "md5_key",
+ "redistribute": (
+ "metric",
+ "route_map",
+ "route_type",
+ "metric_type",
+ ),
+ "neighbor": ("priority", "poll_interval", "neighbor_id"),
+ "range": ("cost", "address", "substitute", "not_advertise"),
+ "vlink": (
+ "address",
+ "dead_interval",
+ "transmit_delay",
+ "hello_interval",
+ "retransmit_interval",
+ ),
+ }
+ leaf = leaf_dict[attr]
+ w = want.get(attr) or []
+ if have:
+ h = have.get(attr) or []
+ if not opr and not h:
+ commands.append(self._compute_command(attr=attr, opr=opr))
+ elif w:
+ for w_item in w:
+ for (key, val) in iteritems(w_item):
+ if not cmd:
+ cmd = self._compute_command(opr=opr)
+ h_item = self.search_obj_in_have(h, w_item, name[attr])
+ if (
+ opr
+ and key in leaf
+ and not _is_w_same(w_item, h_item, key)
+ ):
+ if key in (
+ "route_type",
+ "neighbor_id",
+ "address",
+ "key_id",
+ ):
+ commands.append(cmd + attr + " " + str(val))
+ elif key == "cost":
+ commands.append(
+ cmd
+ + attr
+ + " "
+ + w_item[name[attr]]
+ + " "
+ + key
+ + " "
+ + str(val)
+ )
+ elif key == "not_advertise":
+ commands.append(
+ cmd
+ + attr
+ + " "
+ + w_item[name[attr]]
+ + " "
+ + key.replace("_", "-")
+ )
+ elif key == "md5_key":
+ commands.append(
+ cmd
+ + attr
+ + " "
+ + "key-id"
+ + " "
+ + str(w_item[name[attr]])
+ + " "
+ + key.replace("_", "-")
+ + " "
+ + w_item[key]
+ )
+ else:
+ commands.append(
+ cmd
+ + attr
+ + " "
+ + w_item[name[attr]]
+ + " "
+ + key.replace("_", "-")
+ + " "
+ + str(val)
+ )
+ elif (
+ not opr and key in leaf and not _in_target(h_item, key)
+ ):
+ if key in (
+ "route_type",
+ "neighbor_id",
+ "address",
+ "key_id",
+ ):
+ commands.append(cmd + attr + " " + str(val))
+ else:
+ commands.append(
+ cmd
+ + attr
+ + " "
+ + w_item[name[attr]]
+ + " "
+ + key
+ )
+ return commands
+
+ def _render_nested_dict_param(self, attr, want, have, opr=True):
+ """
+ This function forms the set/delete commands based on the 'opr' type
+ for attributes with in desired nested dicts.
+ :param attr: attribute name.
+ :param w: the desired config.
+ :param h: the target config.
+ :param cmd: commands to be prepend.
+ :param opr: True/False.
+ :return: generated commands list.
+ """
+
+ commands = []
+ attr_dict = {
+ "default_information": "originate",
+ "max_metric": "router_lsa",
+ }
+ leaf_dict = {
+ "default_information": (
+ "always",
+ "metric",
+ "metric_type",
+ "route_map",
+ ),
+ "max_metric": ("administrative", "on_startup", "on_shutdown"),
+ }
+ h = {}
+ w = want.get(attr) or {}
+ if have:
+ h = have.get(attr) or {}
+ if not opr and not h:
+ commands.append(self._form_attr_cmd(attr=attr, opr=opr))
+ elif w:
+ key = attr_dict[attr]
+ w_attrib = want[attr].get(key) or {}
+ cmd = self._compute_command(opr=opr)
+ h_attrib = {}
+ if w_attrib:
+ leaf = leaf_dict[attr]
+ if h and key in h.keys():
+ h_attrib = h.get(key) or {}
+ for (item, val) in iteritems(w[key]):
+ if (
+ opr
+ and item in leaf
+ and not _is_w_same(w[key], h_attrib, item)
+ ):
+ if item in ("administrative", "always") and val:
+ commands.append(
+ cmd
+ + attr.replace("_", "-")
+ + " "
+ + key.replace("_", "-")
+ + " "
+ + item.replace("_", "-")
+ )
+ elif item not in ("administrative", "always"):
+ commands.append(
+ cmd
+ + attr.replace("_", "-")
+ + " "
+ + key.replace("_", "-")
+ + " "
+ + item.replace("_", "-")
+ + " "
+ + str(val)
+ )
+ elif (
+ not opr
+ and item in leaf
+ and not _in_target(h_attrib, item)
+ ):
+
+ commands.append(cmd + attr + " " + item)
+ return commands
+
+ def _render_areas(self, attr, want, have, opr=True):
+ """
+ This function forms the set/delete commands based on the 'opr' type
+ for ospf area attributes.
+ :param attr: attribute name.
+ :param w: the desired config.
+ :param h: the target config.
+ :param opr: True/False.
+ :return: generated commands list.
+ """
+
+ commands = []
+ h_lst = {}
+ w_lst = want.get(attr) or []
+ l_set = ("area_id", "shortcut", "authentication")
+ if have:
+ h_lst = have.get(attr) or []
+ if not opr and not h_lst:
+ commands.append(self._form_attr_cmd(attr="area", opr=opr))
+ elif w_lst:
+ for w_area in w_lst:
+ cmd = (
+ self._compute_command(
+ key="area",
+ attr=_bool_to_str(w_area["area_id"]),
+ opr=opr,
+ )
+ + " "
+ )
+ h_area = self.search_obj_in_have(h_lst, w_area, "area_id")
+ if not opr and not h_area:
+ commands.append(
+ self._form_attr_cmd(
+ key="area", attr=w_area["area_id"], opr=opr
+ )
+ )
+ else:
+ for (key, val) in iteritems(w_area):
+ if (
+ opr
+ and key in l_set
+ and not _is_w_same(w_area, h_area, key)
+ ):
+ if key == "area_id":
+ commands.append(
+ self._form_attr_cmd(
+ attr="area",
+ val=_bool_to_str(val),
+ opr=opr,
+ )
+ )
+ else:
+ commands.append(
+ cmd
+ + key
+ + " "
+ + _bool_to_str(val).replace("_", "-")
+ )
+ elif not opr and key in l_set:
+ if key == "area_id" and not _in_target(
+ h_area, key
+ ):
+ commands.append(cmd)
+ continue
+ elif key != "area_id" and not _in_target(
+ h_area, key
+ ):
+ commands.append(cmd + val + " " + key)
+ elif key == "area_type":
+ commands.extend(
+ self._render_area_type(
+ w_area, h_area, key, cmd, opr
+ )
+ )
+ elif key == "network":
+ commands.extend(
+ self._render_list_param(
+ key, w_area, h_area, cmd, opr
+ )
+ )
+ elif key == "range":
+ commands.extend(
+ self._render_list_dict_param(
+ key, w_area, h_area, cmd, opr
+ )
+ )
+ elif key == "virtual_link":
+ commands.extend(
+ self._render_vlink(
+ key, w_area, h_area, cmd, opr
+ )
+ )
+ return commands
+
+ def _render_area_type(self, want, have, attr, cmd, opr=True):
+ """
+ This function forms the set/delete commands based on the 'opr' type
+ for area_types attributes.
+ :param attr: attribute name.
+ :param w: the desired config.
+ :param h: the target config.
+ :param cmd: command to prepend.
+ :param opr: True/False.
+ :return: generated commands list.
+ """
+
+ commands = []
+ h_type = {}
+ w_type = want.get(attr) or []
+ if have:
+ h_type = have.get(attr) or {}
+ if not opr and not h_type:
+ commands.append(cmd + attr.replace("_", "-"))
+ elif w_type:
+ key = "normal"
+ if (
+ opr
+ and key in w_type.keys()
+ and not _is_w_same(w_type, h_type, key)
+ ):
+ if not w_type[key] and h_type and h_type[key]:
+ commands.append(
+ cmd.replace("set", "delete")
+ + attr.replace("_", "-")
+ + " "
+ + key
+ )
+ elif w_type[key]:
+ commands.append(cmd + attr.replace("_", "-") + " " + key)
+ elif (
+ not opr
+ and key in w_type.keys()
+ and not (h_type and key in h_type.keys())
+ ):
+ commands.append(
+ cmd + want["area"] + " " + attr.replace("_", "-")
+ )
+
+ a_type = {
+ "nssa": ("set", "default_cost", "no_summary", "translate"),
+ "stub": ("set", "default_cost", "no_summary"),
+ }
+ for key in a_type:
+ w_area = want[attr].get(key) or {}
+ h_area = {}
+ if w_area:
+ if h_type and key in h_type.keys():
+ h_area = h_type.get(key) or {}
+ for (item, val) in iteritems(w_type[key]):
+ if (
+ opr
+ and item in a_type[key]
+ and not _is_w_same(w_type[key], h_area, item)
+ ):
+ if item == "set" and val:
+ commands.append(
+ cmd + attr.replace("_", "-") + " " + key
+ )
+ elif not val and h_area and h_area[item]:
+ commands.append(
+ cmd.replace("set", "delete")
+ + attr.replace("_", "-")
+ + " "
+ + key
+ )
+ elif item != "set":
+ commands.append(
+ cmd
+ + attr.replace("_", "-")
+ + " "
+ + key
+ + " "
+ + item.replace("_", "-")
+ + " "
+ + str(val)
+ )
+ elif (
+ not opr
+ and item in a_type[key]
+ and not (h_type and key in h_type)
+ ):
+ if item == "set":
+ commands.append(
+ cmd + attr.replace("_", "-") + " " + key
+ )
+ else:
+ commands.append(
+ cmd
+ + want["area"]
+ + " "
+ + attr.replace("_", "-")
+ + " "
+ + key
+ + " "
+ + item.replace("_", "-")
+ )
+ return commands
+
+ 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.
+ """
+
+ return self._compute_command(
+ key, attr=self._map_attrib(attr), val=val, opr=opr
+ )
+
+ 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 opr: True/False.
+ :return: generated command.
+ """
+
+ if remove or not opr:
+ cmd = "delete protocols ospf "
+ else:
+ cmd = "set protocols ospf "
+ if key:
+ cmd += key.replace("_", "-") + " "
+ if attr:
+ cmd += attr.replace("_", "-")
+ if val:
+ cmd += " '" + str(val) + "'"
+ return cmd
+
+ def _map_attrib(self, attrib):
+ """
+ - This function construct the regex string.
+ - replace the underscore with hyphen.
+ :param attrib: attribute
+ :return: regex string
+ """
+
+ return "disable" if attrib == "disabled" else attrib.replace("_", "-")
diff --git a/plugins/module_utils/network/vyos/config/ospfv3/__init__.py b/plugins/module_utils/network/vyos/config/ospfv3/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/plugins/module_utils/network/vyos/config/ospfv3/__init__.py
diff --git a/plugins/module_utils/network/vyos/config/ospfv3/ospfv3.py b/plugins/module_utils/network/vyos/config/ospfv3/ospfv3.py
new file mode 100644
index 00000000..acda3801
--- /dev/null
+++ b/plugins/module_utils/network/vyos/config/ospfv3/ospfv3.py
@@ -0,0 +1,464 @@
+#
+# -*- 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_ospfv3 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_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import (
+ ConfigBase,
+)
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
+ to_list,
+ remove_empties,
+ search_obj_in_list,
+)
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import (
+ Facts,
+)
+from ansible.module_utils.six import iteritems
+
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import (
+ _in_target,
+ _is_w_same,
+ _bool_to_str,
+)
+
+
+class Ospfv3(ConfigBase):
+ """
+ The vyos_ospfv3 class
+ """
+
+ gather_subset = [
+ "!all",
+ "!min",
+ ]
+
+ gather_network_resources = [
+ "ospfv3",
+ ]
+
+ def __init__(self, module):
+ super(Ospfv3, self).__init__(module)
+
+ def get_ospfv3_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
+ )
+ ospfv3_facts = facts["ansible_network_resources"].get("ospfv3", {})
+ return ospfv3_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_ospfv3_facts = self.get_ospfv3_facts()
+ else:
+ existing_ospfv3_facts = {}
+
+ if self.state in self.ACTION_STATES or self.state == "rendered":
+ commands.extend(self.set_config(existing_ospfv3_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_ospfv3_facts = self.get_ospfv3_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_ospfv3_facts(data=running_config)
+ else:
+ changed_ospfv3_facts = {}
+
+ if self.state in self.ACTION_STATES:
+ result["before"] = existing_ospfv3_facts
+ if result["changed"]:
+ result["after"] = changed_ospfv3_facts
+ elif self.state == "gathered":
+ result["gathered"] = changed_ospfv3_facts
+
+ result["warnings"] = warnings
+ return result
+
+ def set_config(self, existing_ospfv3_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_ospfv3_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 == "deleted":
+ commands.extend(self._state_deleted(w, h))
+ elif self.state in ("merged", "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._render_ospf_param(have, want, opr=False))
+ commands.extend(self._render_ospf_param(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_ospf_param(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 have:
+ commands.append("delete protocols ospfv3")
+ return commands
+
+ def _render_ospf_param(self, want, have, opr=True):
+ """
+ This function forms the set/delete commands for ospf leaf attributes
+ and triggers the process for other child attributes.
+ for firewall_global attributes.
+ :param w: the desired config.
+ :param h: the target config.
+ :param opr: True/False.
+ :return: generated commands list.
+ """
+ commands = []
+ w = deepcopy(remove_empties(want))
+ if w:
+ for key, val in iteritems(w):
+ commands.extend(self._render_child_param(w, have, key, opr))
+ return commands
+
+ def _render_child_param(self, w, h, key, opr=True):
+ """
+ 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 == "areas":
+ commands.extend(self._render_areas(key, w, h, opr=opr))
+ elif key == "parameters":
+ commands.extend(self._render_dict_param(key, w, h, opr=opr))
+ elif key == "redistribute":
+ commands.extend(self._render_list_dict_param(key, w, h, opr=opr))
+ return commands
+
+ def _render_dict_param(self, attr, want, have, opr=True):
+ """
+ This function generate the commands for dictionary elements.
+ :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 = {}
+ if have:
+ h = have.get(attr) or {}
+ if not opr and not h:
+ commands.append(self._form_attr_cmd(attr=attr, opr=opr))
+ elif want[attr]:
+ leaf_dict = {"parameters": "router_id"}
+ leaf = leaf_dict[attr]
+ for item, value in iteritems(want[attr]):
+ if (
+ opr
+ and item in leaf
+ and not _is_w_same(want[attr], h, item)
+ ):
+ commands.append(
+ self._form_attr_cmd(
+ key=attr, attr=item, val=value, opr=opr
+ )
+ )
+ elif not opr and item in leaf and not _in_target(h, item):
+ commands.append(
+ self._form_attr_cmd(key=attr, attr=item, opr=opr)
+ )
+ return commands
+
+ def _render_list_dict_param(self, attr, want, have, cmd=None, opr=True):
+ """
+ This function forms the set/delete commands based on the 'opr' type
+ for attributes with in desired list of dictionary.
+ :param attr: attribute name.
+ :param w: the desired config.
+ :param h: the target config.
+ :param cmd: commands to be prepend.
+ :param opr: True/False.
+ :return: generated commands list.
+ """
+ commands = []
+ h = []
+ name = {
+ "redistribute": "route_type",
+ "range": "address",
+ }
+ leaf_dict = {
+ "redistribute": ("route_map", "route_type"),
+ "range": ("address", "advertise", "not_advertise"),
+ }
+ leaf = leaf_dict[attr]
+ w = want.get(attr) or []
+ if have:
+ h = have.get(attr) or []
+ if not opr and not h:
+ commands.append(self._compute_command(attr=attr, opr=opr))
+ elif w:
+ for w_item in w:
+ for key, val in iteritems(w_item):
+ if not cmd:
+ cmd = self._compute_command(opr=opr)
+ h_item = search_obj_in_list(
+ w_item[name[attr]], h, name[attr]
+ )
+ if (
+ opr
+ and key in leaf
+ and not _is_w_same(w_item, h_item, key)
+ ):
+ if key == "route_type" or (
+ key == "address"
+ and "advertise" not in w_item
+ and "not-advertise" not in w_item
+ ):
+ if not val:
+ cmd = cmd.replace("set", "delete")
+ commands.append(cmd + attr + " " + str(val))
+ elif key in leaf_dict["range"] and key != "address":
+ commands.append(
+ cmd
+ + attr
+ + " "
+ + w_item[name[attr]]
+ + " "
+ + key.replace("_", "-")
+ )
+ elif key == "route_map":
+ commands.append(
+ cmd
+ + attr
+ + " "
+ + w_item[name[attr]]
+ + " "
+ + key.replace("_", "-")
+ + " "
+ + str(val)
+ )
+ elif (
+ not opr and key in leaf and not _in_target(h_item, key)
+ ):
+ if key in ("route_type", "address"):
+ commands.append(cmd + attr + " " + str(val))
+ else:
+ commands.append(
+ cmd
+ + (attr + " " + w_item[name[attr]] + " " + key)
+ )
+ return commands
+
+ def _render_areas(self, attr, want, have, opr=True):
+ """
+ This function forms the set/delete commands based on the 'opr' type
+ for ospf area attributes.
+ :param attr: attribute name.
+ :param w: the desired config.
+ :param h: the target config.
+ :param opr: True/False.
+ :return: generated commands list.
+ """
+ commands = []
+ h_lst = {}
+ w_lst = want.get(attr) or []
+ l_set = ("area_id", "export_list", "import_list")
+ if have:
+ h_lst = have.get(attr) or []
+ if not opr and not h_lst:
+ commands.append(self._form_attr_cmd(attr="area", opr=opr))
+ elif w_lst:
+ for w_area in w_lst:
+ cmd = (
+ self._compute_command(
+ key="area",
+ attr=_bool_to_str(w_area["area_id"]),
+ opr=opr,
+ )
+ + " "
+ )
+ h_area = search_obj_in_list(
+ w_area["area_id"], h_lst, "area_id"
+ )
+ if not opr and not h_area:
+ commands.append(
+ self._form_attr_cmd(
+ key="area", attr=w_area["area_id"], opr=opr
+ )
+ )
+ else:
+ for key, val in iteritems(w_area):
+ if (
+ opr
+ and key in l_set
+ and not _is_w_same(w_area, h_area, key)
+ ):
+ if key == "area_id":
+ commands.append(
+ self._form_attr_cmd(
+ attr="area",
+ val=_bool_to_str(val),
+ opr=opr,
+ )
+ )
+ else:
+ commands.append(
+ cmd
+ + key.replace("_", "-")
+ + " "
+ + _bool_to_str(val).replace("_", "-")
+ )
+ elif not opr and key in l_set:
+ if key == "area_id" and not _in_target(
+ h_area, key
+ ):
+ commands.append(cmd)
+ continue
+ elif key != "area_id" and not _in_target(
+ h_area, key
+ ):
+ commands.append(cmd + val + " " + key)
+ elif key == "range":
+ commands.extend(
+ self._render_list_dict_param(
+ key, w_area, h_area, cmd, opr
+ )
+ )
+ return commands
+
+ 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.
+ """
+ return self._compute_command(
+ key, attr=self._map_attrib(attr), val=val, opr=opr
+ )
+
+ 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 opr: True/False.
+ :return: generated command.
+ """
+ if remove or not opr:
+ cmd = "delete protocols ospfv3 "
+ else:
+ cmd = "set protocols ospfv3 "
+ if key:
+ cmd += key.replace("_", "-") + " "
+ if attr:
+ cmd += attr.replace("_", "-")
+ if val and opr:
+ cmd += " '" + str(val) + "'"
+ return cmd
+
+ def _map_attrib(self, attrib):
+ """
+ - This function construct the regex string.
+ - replace the underscore with hyphen.
+ :param attrib: attribute
+ :return: regex string
+ """
+ return "disable" if attrib == "disabled" else attrib.replace("_", "-")
diff --git a/plugins/module_utils/network/vyos/config/static_routes/static_routes.py b/plugins/module_utils/network/vyos/config/static_routes/static_routes.py
index e93d4ee3..b359dbba 100644
--- a/plugins/module_utils/network/vyos/config/static_routes/static_routes.py
+++ b/plugins/module_utils/network/vyos/config/static_routes/static_routes.py
@@ -160,7 +160,7 @@ class Static_routes(ConfigBase):
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":
+ if self.state in ("merged", "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))
@@ -253,12 +253,6 @@ class Static_routes(ConfigBase):
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):
diff --git a/plugins/module_utils/network/vyos/facts/facts.py b/plugins/module_utils/network/vyos/facts/facts.py
index ff3d0988..4c7b340d 100644
--- a/plugins/module_utils/network/vyos/facts/facts.py
+++ b/plugins/module_utils/network/vyos/facts/facts.py
@@ -40,6 +40,12 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.firew
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.firewall_interfaces.firewall_interfaces import (
Firewall_interfacesFacts,
)
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospfv3.ospfv3 import (
+ Ospfv3Facts,
+)
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospfv2.ospfv2 import (
+ Ospfv2Facts,
+)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.legacy.base import (
Default,
Neighbors,
@@ -58,6 +64,8 @@ FACT_RESOURCE_SUBSETS = dict(
firewall_rules=Firewall_rulesFacts,
firewall_global=Firewall_globalFacts,
firewall_interfaces=Firewall_interfacesFacts,
+ ospfv3=Ospfv3Facts,
+ ospfv2=Ospfv2Facts,
)
diff --git a/plugins/module_utils/network/vyos/facts/l3_interfaces/l3_interfaces.py b/plugins/module_utils/network/vyos/facts/l3_interfaces/l3_interfaces.py
index d1d62c23..3b99d347 100644
--- a/plugins/module_utils/network/vyos/facts/l3_interfaces/l3_interfaces.py
+++ b/plugins/module_utils/network/vyos/facts/l3_interfaces/l3_interfaces.py
@@ -10,7 +10,12 @@ for a given resource, parsed, and the facts tree is populated
based on the configuration.
"""
-from __future__ import absolute_import, division, print_function
+from __future__ import (
+ absolute_import,
+ division,
+ print_function,
+ unicode_literals,
+)
__metaclass__ = type
diff --git a/plugins/module_utils/network/vyos/facts/lag_interfaces/lag_interfaces.py b/plugins/module_utils/network/vyos/facts/lag_interfaces/lag_interfaces.py
index 9201e5c6..90562947 100644
--- a/plugins/module_utils/network/vyos/facts/lag_interfaces/lag_interfaces.py
+++ b/plugins/module_utils/network/vyos/facts/lag_interfaces/lag_interfaces.py
@@ -12,6 +12,7 @@ based on the configuration.
from __future__ import absolute_import, division, print_function
__metaclass__ = type
+
from re import findall, search, M
from copy import deepcopy
@@ -59,30 +60,21 @@ class Lag_interfacesFacts(object):
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 = {}
+
+ group_regex = r".*eth.* '%s'" % lag
+ g_cfg = findall(group_regex, data, M)
+ for item in g_cfg:
+ output = search("^set interfaces ethernet (\\S+)", item, M)
+ if output:
+ member["member"] = output.group(1).strip("'")
+ members.append(member)
obj["name"] = lag.strip("'")
if members:
obj["members"] = members
-
if obj:
objs.append(obj)
-
facts = {}
if objs:
facts["lag_interfaces"] = []
diff --git a/plugins/module_utils/network/vyos/facts/ospfv2/__init__.py b/plugins/module_utils/network/vyos/facts/ospfv2/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/plugins/module_utils/network/vyos/facts/ospfv2/__init__.py
diff --git a/plugins/module_utils/network/vyos/facts/ospfv2/ospfv2.py b/plugins/module_utils/network/vyos/facts/ospfv2/ospfv2.py
new file mode 100644
index 00000000..d62fa9ab
--- /dev/null
+++ b/plugins/module_utils/network/vyos/facts/ospfv2/ospfv2.py
@@ -0,0 +1,499 @@
+#
+# -*- 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 ospfv2 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_collections.ansible.netcommon.plugins.module_utils.network.common import (
+ utils,
+)
+
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ospfv2.ospfv2 import (
+ Ospfv2Args,
+)
+
+
+class Ospfv2Facts(object):
+
+ """ The vyos ospfv2 fact class
+ """
+
+ def __init__(
+ self, module, subspec="config", options="options",
+ ):
+
+ self._module = module
+ self.argument_spec = Ospfv2Args.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 ospfv2
+ :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 = {}
+ ospfv2 = findall(r"^set protocols ospf (.+)", data, M)
+ if ospfv2:
+ objs = self.render_config(ospfv2)
+ facts = {}
+ params = utils.validate_config(self.argument_spec, {"config": objs})
+ facts["ospfv2"] = 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
+
+ :param conf: The configuration
+ :returns: The generated config
+ """
+
+ conf = "\n".join(filter(lambda x: x, conf))
+ a_lst = ["default_metric", "log_adjacency_changes"]
+ config = self.parse_attr(conf, a_lst)
+
+ if not config:
+ config = {}
+ config["timers"] = self.parse_timers(conf)
+ config["auto_cost"] = self.parse_auto_cost(conf)
+ config["distance"] = self.parse_distance(conf)
+ config["max_metric"] = self.parse_max_metric(conf)
+ config["default_information"] = self.parse_def_info(conf)
+ config["route_map"] = self.parse_leaf_list(conf, "route-map")
+ config["mpls_te"] = self.parse_attrib(conf, "mpls_te", "mpls-te")
+ config["areas"] = self.parse_attrib_list(conf, "area", "area_id")
+ config["parameters"] = self.parse_attrib(
+ conf, "parameters", "parameters"
+ )
+ config["neighbor"] = self.parse_attrib_list(
+ conf, "neighbor", "neighbor_id"
+ )
+ config["passive_interface"] = self.parse_leaf_list(
+ conf, "passive-interface"
+ )
+ config["redistribute"] = self.parse_attrib_list(
+ conf, "redistribute", "route_type"
+ )
+ config["passive_interface_exclude"] = self.parse_leaf_list(
+ conf, "passive-interface-exclude"
+ )
+ return config
+
+ def parse_timers(self, conf):
+ """
+ This function triggers the parsing of 'timers' attributes
+ :param conf: configuration
+ :return: generated config dictionary
+ """
+
+ cfg_dict = {}
+ cfg_dict["refresh"] = self.parse_refresh(conf, "refresh")
+ cfg_dict["throttle"] = self.parse_throttle(conf, "spf")
+ return cfg_dict
+
+ def parse_throttle(self, conf, attrib=None):
+ """
+ This function triggers the parsing of 'throttle' attributes
+ :param conf: configuration
+ :param attrib: 'spf'
+ :return: generated config dictionary
+ """
+
+ cfg_dict = {}
+ cfg_dict[attrib] = self.parse_attrib(conf, attrib, match=attrib)
+ return cfg_dict
+
+ def parse_refresh(self, conf, attrib=None):
+ """
+ This function triggers the parsing of 'refresh' attributes
+ :param conf: configuration
+ :param attrib: 'refresh'
+ :return: generated config dictionary
+ """
+
+ cfg_dict = self.parse_attr(conf, ["timers"], match=attrib)
+ return cfg_dict
+
+ def parse_leaf_list(self, conf, attrib):
+ """
+ This function forms the regex to fetch the listed attributes
+ from the configuration data
+ :param conf: configuration data
+ :param attrib: attribute name
+ :return: generated rule list configuration
+ """
+
+ lst = []
+ items = findall(r"^" + attrib + " (?:'*)(\\S+)(?:'*)", conf, M)
+ if items:
+ for i in set(items):
+ lst.append(i.strip("'"))
+ lst.sort()
+ return lst
+
+ def parse_distance(self, conf, attrib=None):
+ """
+ This function triggers the parsing of 'distance' attributes
+ :param conf: configuration
+ :param attrib: attribute name
+ :return: generated config dictionary
+ """
+
+ cfg_dict = self.parse_attr(conf, ["global"], match=attrib)
+ cfg_dict["ospf"] = self.parse_ospf(conf, "ospf")
+ return cfg_dict
+
+ def parse_ospf(self, conf, attrib=None):
+ """
+ This function triggers the parsing of 'distance ospf' attributes
+ :param conf: configuration
+ :param attrib: 'ospf'
+ :return: generated config dictionary
+ """
+
+ cfg_dict = self.parse_attrib(conf, "ospf", match=attrib)
+ return cfg_dict
+
+ def parse_max_metric(self, conf):
+ """
+ This function triggers the parsing of 'max_metric' attributes
+ :param conf: configuration
+ :return: generated config dictionary
+ """
+
+ cfg_dict = {}
+ cfg_dict["router_lsa"] = self.parse_attrib(
+ conf, "router_lsa", match="router-lsa"
+ )
+ return cfg_dict
+
+ def parse_auto_cost(self, conf, attrib=None):
+ """
+ This function triggers the parsing of 'auto_cost' attributes
+ :param conf: configuration
+ :param attrib: attribute name
+ :return: generated config dictionary
+ """
+
+ cfg_dict = self.parse_attr(conf, ["reference_bandwidth"], match=attrib)
+ return cfg_dict
+
+ def parse_def_info(self, conf):
+ """
+ This function triggers the parsing of 'default_information' attributes
+ :param conf: configuration
+ :return: generated config dictionary
+ """
+
+ cfg_dict = {}
+ cfg_dict["originate"] = self.parse_attrib(
+ conf, "originate", "originate"
+ )
+ return cfg_dict
+
+ def parse_area(self, conf, area_id):
+ """
+ This function triggers the parsing of 'area' attributes.
+ :param conf: configuration data
+ :param area_id: area identity
+ :return: generated rule configuration dictionary.
+ """
+
+ rule = self.parse_attrib(conf, "area_id", match=area_id)
+ r_sub = {
+ "area_type": self.parse_area_type(conf, "area-type"),
+ "network": self.parse_network(conf),
+ "range": self.parse_attrib_list(conf, "range", "address"),
+ "virtual_link": self.parse_attrib_list(
+ conf, "virtual-link", "address"
+ ),
+ }
+ rule.update(r_sub)
+ return rule
+
+ def parse_key(self, conf, key_id):
+ """
+ This function triggers the parsing of 'area' attributes.
+ :param conf: configuration data
+ :param area_id: area identity
+ :return: generated rule configuration dictionary.
+ """
+
+ rule = self.parse_attrib(conf, "key_id", match=key_id)
+ return rule
+
+ def parse_area_type(self, conf, attrib=None):
+ """
+ This function triggers the parsing of 'area_type' attributes
+ :param conf: configuration
+ :param attrib: 'area-type'
+ :return: generated config dictionary
+ """
+
+ cfg_dict = self.parse_attr(conf, ["normal"], match=attrib)
+ cfg_dict["nssa"] = self.parse_attrib(conf, "nssa", match="nssa")
+ cfg_dict["stub"] = self.parse_attrib(conf, "stub", match="stub")
+ return cfg_dict
+
+ def parse_network(self, conf):
+ """
+ This function forms the regex to fetch the 'network'
+ :param conf: configuration data
+ :return: generated rule list configuration
+ """
+
+ a_lst = []
+ applications = findall(r"network (.+)", conf, M)
+ if applications:
+ app_lst = []
+ for r in set(applications):
+ obj = {"address": r.strip("'")}
+ app_lst.append(obj)
+ a_lst = sorted(app_lst, key=lambda i: i["address"])
+ return a_lst
+
+ def parse_vlink(self, conf):
+ """
+ This function triggers the parsing of 'virtual_link' attributes
+ :param conf: configuration data
+ :return: generated rule configuration dictionary
+ """
+
+ rule = self.parse_attrib(conf, "vlink")
+ r_sub = {
+ "authentication": self.parse_authentication(conf, "authentication")
+ }
+ rule.update(r_sub)
+ return rule
+
+ def parse_authentication(self, conf, attrib=None):
+ """
+ This function triggers the parsing of 'authentication' attributes.
+ :param conf: configuration
+ :param attrib: 'authentication'
+ :return: generated config dictionary
+ """
+
+ cfg_dict = self.parse_attr(conf, ["plaintext_password"], match=attrib)
+ cfg_dict["md5"] = self.parse_attrib_list(conf, "key-id", "key_id")
+ return cfg_dict
+
+ def parse_attrib_list(self, conf, attrib, param):
+ """
+ This function forms the regex to fetch the listed attributes
+ from config
+ :param conf: configuration data
+ :param attrib: attribute name
+ :param param: parameter data
+ :return: generated rule list configuration
+ """
+
+ r_lst = []
+ if attrib == "area":
+ items = findall(
+ r"^" + attrib.replace("_", "-") + " (?:'*)(\\S+)(?:'*)",
+ conf,
+ M,
+ )
+ elif attrib == "key-id":
+ items = findall(
+ r"^.*" + attrib.replace("_", "-") + " (?:'*)(\\S+)(?:'*)",
+ conf,
+ M,
+ )
+ else:
+ items = findall(r"" + attrib + " (?:'*)(\\S+)(?:'*)", conf, M)
+ if items:
+ a_lst = []
+ for item in set(items):
+ i_regex = r" %s .+$" % item
+ cfg = "\n".join(findall(i_regex, conf, M))
+ if attrib == "area":
+ obj = self.parse_area(cfg, item)
+ elif attrib == "virtual-link":
+ obj = self.parse_vlink(cfg)
+ elif attrib == "key-id":
+ obj = self.parse_key(cfg, item)
+ else:
+ obj = self.parse_attrib(cfg, attrib)
+ obj[param] = item.strip("'")
+ if obj:
+ a_lst.append(obj)
+ r_lst = sorted(a_lst, key=lambda i: i[param])
+ return r_lst
+
+ def parse_attrib(self, conf, param, match=None):
+ """
+ This function triggers the parsing of 'ospf' attributes
+ :param conf: configuration data
+ :return: generated configuration dictionary
+ """
+
+ param_lst = {
+ "key_id": ["md5_key"],
+ "mpls_te": ["enabled", "router_address"],
+ "area_id": ["shortcut", "authentication"],
+ "neighbor": ["priority", "poll_interval"],
+ "stub": ["set", "default_cost", "no_summary"],
+ "range": ["cost", "substitute", "not_advertise"],
+ "ospf": ["external", "inter_area", "intra_area"],
+ "spf": ["delay", "max_holdtime", "initial_holdtime"],
+ "redistribute": ["metric", "metric_type", "route_map"],
+ "nssa": ["set", "translate", "default_cost", "no_summary"],
+ "config_routes": ["default_metric", "log_adjacency_changes"],
+ "originate": ["always", "metric", "metric_type", "route_map"],
+ "router_lsa": ["administrative", "on_shutdown", "on_startup"],
+ "parameters": [
+ "abr_type",
+ "opaque_lsa",
+ "router_id",
+ "rfc1583_compatibility",
+ ],
+ "vlink": [
+ "dead_interval",
+ "hello_interval",
+ "transmit_delay",
+ "retransmit_interval",
+ ],
+ }
+ cfg_dict = self.parse_attr(conf, param_lst[param], match)
+ 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.replace("_", "-") + " " + regex
+ if conf:
+ if self.is_bool(attrib):
+ out = conf.find(attrib.replace("_", "-"))
+ dis = conf.find(attrib.replace("_", "-") + " 'disable'")
+ if match:
+ if attrib == "set" and conf.find(match) >= 1:
+ config[attrib] = True
+ en = conf.find(match + " 'enable'")
+ if out >= 1:
+ if dis >= 1:
+ config[attrib] = False
+ else:
+ config[attrib] = True
+ elif match and en >= 1:
+ 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
+ """
+
+ return (
+ "disable"
+ if attrib == "disabled"
+ else (
+ "enable"
+ if attrib == "enabled"
+ else (
+ "area" if attrib == "area_id" else attrib.replace("_", "-")
+ )
+ )
+ )
+
+ def is_bool(self, attrib):
+ """
+ This function looks for the attribute in predefined bool type set.
+ :param attrib: attribute.
+ :return: True/False
+ """
+
+ bool_set = (
+ "set",
+ "always",
+ "normal",
+ "enabled",
+ "opaque_lsa",
+ "not_advertise",
+ "administrative",
+ "rfc1583_compatibility",
+ )
+ 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 = (
+ "ospf",
+ "delay",
+ "metric",
+ "inter_area",
+ "intra_area",
+ "on_startup",
+ "metric_type",
+ "on_shutdown",
+ "max_holdtime",
+ "poll_interval",
+ "default_metric",
+ "initial_holdtime",
+ "key_id",
+ )
+ return True if attrib in num_set else False
diff --git a/plugins/module_utils/network/vyos/facts/ospfv3/__init__.py b/plugins/module_utils/network/vyos/facts/ospfv3/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/plugins/module_utils/network/vyos/facts/ospfv3/__init__.py
diff --git a/plugins/module_utils/network/vyos/facts/ospfv3/ospfv3.py b/plugins/module_utils/network/vyos/facts/ospfv3/ospfv3.py
new file mode 100644
index 00000000..457a9636
--- /dev/null
+++ b/plugins/module_utils/network/vyos/facts/ospfv3/ospfv3.py
@@ -0,0 +1,213 @@
+#
+# -*- 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 ospfv3 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_collections.ansible.netcommon.plugins.module_utils.network.common import (
+ utils,
+)
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ospfv3.ospfv3 import (
+ Ospfv3Args,
+)
+
+
+class Ospfv3Facts(object):
+ """ The vyos ospfv3 fact class
+ """
+
+ def __init__(self, module, subspec="config", options="options"):
+ self._module = module
+ self.argument_spec = Ospfv3Args.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 ospfv3
+ :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 = {}
+ ospfv3 = findall(r"^set protocols ospfv3 (.+)", data, M)
+ if ospfv3:
+ objs = self.render_config(ospfv3)
+ facts = {}
+ params = utils.validate_config(self.argument_spec, {"config": objs})
+ facts["ospfv3"] = 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
+
+ :param conf: The configuration
+ :returns: The generated config
+ """
+ conf = "\n".join(filter(lambda x: x, conf))
+ config = {}
+ config["parameters"] = self.parse_attrib(
+ conf, "parameters", "parameters"
+ )
+ config["areas"] = self.parse_attrib_list(conf, "area", "area_id")
+ config["redistribute"] = self.parse_attrib_list(
+ conf, "redistribute", "route_type"
+ )
+ return config
+
+ def parse_attrib_list(self, conf, attrib, param):
+ """
+ This function forms the regex to fetch the listed attributes
+ from config
+ :param conf: configuration data
+ :param attrib: attribute name
+ :param param: parameter data
+ :return: generated rule list configuration
+ """
+ r_lst = []
+ if attrib == "area":
+ items = findall(r"^" + attrib + " (?:'*)(\\S+)(?:'*)", conf, M)
+ else:
+ items = findall(r"" + attrib + " (?:'*)(\\S+)(?:'*)", conf, M)
+ if items:
+ a_lst = []
+ for item in set(items):
+ i_regex = r" %s .+$" % item
+ cfg = "\n".join(findall(i_regex, conf, M))
+ if attrib == "area":
+ obj = self.parse_area(cfg, item)
+ else:
+ obj = self.parse_attrib(cfg, attrib)
+ obj[param] = item.strip("'")
+ if obj:
+ a_lst.append(obj)
+ r_lst = sorted(a_lst, key=lambda i: i[param])
+ return r_lst
+
+ def parse_area(self, conf, area_id):
+ """
+ This function triggers the parsing of 'area' attributes.
+ :param conf: configuration data
+ :param area_id: area identity
+ :return: generated rule configuration dictionary.
+ """
+
+ rule = self.parse_attrib(conf, "area_id", match=area_id)
+ r_sub = {"range": self.parse_attrib_list(conf, "range", "address")}
+ rule.update(r_sub)
+ return rule
+
+ def parse_attrib(self, conf, param, match=None):
+ """
+ This function triggers the parsing of 'ospf' attributes
+ :param conf: configuration data
+ :return: generated configuration dictionary
+ """
+ param_lst = {
+ "area_id": ["export_list", "import_list"],
+ "redistribute": ["route_map"],
+ "range": ["advertise", "not_advertise"],
+ "parameters": ["router_id"],
+ }
+ cfg_dict = self.parse_attr(conf, param_lst[param], match)
+ 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.replace("_", "-") + " " + regex
+ if conf:
+ if self.is_bool(attrib):
+ out = conf.find(attrib.replace("_", "-"))
+ dis = conf.find(attrib.replace("_", "-") + " 'disable'")
+ if match:
+ en = conf.find(match + " 'enable'")
+ if out >= 1:
+ if dis >= 1:
+ config[attrib] = False
+ else:
+ config[attrib] = True
+ elif match and en >= 1:
+ 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
+ """
+ return (
+ "disable"
+ if attrib == "disabled"
+ else "enable"
+ if attrib == "enabled"
+ else attrib.replace("_", "-")
+ )
+
+ def is_bool(self, attrib):
+ """
+ This function looks for the attribute in predefined bool type set.
+ :param attrib: attribute.
+ :return: True/False
+ """
+ bool_set = ("enabled", "advertise", "not_advertise")
+ 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 = "ospf"
+ return True if attrib in num_set else False
diff --git a/plugins/module_utils/network/vyos/utils/utils.py b/plugins/module_utils/network/vyos/utils/utils.py
index 4635234c..7e0f3cc3 100644
--- a/plugins/module_utils/network/vyos/utils/utils.py
+++ b/plugins/module_utils/network/vyos/utils/utils.py
@@ -230,3 +230,40 @@ def get_route_type(address):
return "route6"
elif version == 4:
return "route"
+
+
+def _bool_to_str(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 _is_w_same(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(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
diff --git a/plugins/modules/vyos_facts.py b/plugins/modules/vyos_facts.py
index 4a640663..72b191c4 100644
--- a/plugins/modules/vyos_facts.py
+++ b/plugins/modules/vyos_facts.py
@@ -48,7 +48,7 @@ options:
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'.
+ 'firewall_interfaces', 'ospfv3', 'ospfv2'.
required: false
"""
diff --git a/plugins/modules/vyos_firewall_rules.py b/plugins/modules/vyos_firewall_rules.py
index a9e676b6..9c2e832d 100644
--- a/plugins/modules/vyos_firewall_rules.py
+++ b/plugins/modules/vyos_firewall_rules.py
@@ -37,8 +37,9 @@ ANSIBLE_METADATA = {
}
DOCUMENTATION = """module: vyos_firewall_rules
-short_description: Manage firewall rule-set attributes on VyOS devices
+short_description: Firewall rules resource module
description: This module manages firewall rule-set attributes on VyOS devices
+version_added: "1.0.0"
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).
@@ -397,13 +398,12 @@ options:
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'
+ - This option is used only with state I(parsed).
+ - The value of this option should be the output received from the VyOS device by executing
+ the command B(show configuration commands | grep firewall).
+ - The state I(parsed) reads the configuration from C(running_config) option and transforms
+ it into Ansible structured data as per the resource module's argspec and the value is then
+ returned in the I(parsed) key within the result.
type: str
state:
description:
@@ -437,7 +437,7 @@ EXAMPLES = """
# set firewall name Downlink rule 502 ipsec 'match-ipsec'
#
- name: Delete attributes of given firewall rules.
- vyos_firewall_rules:
+ vyos.vyos.vyos_firewall_rules:
config:
- afi: ipv4
rule_sets:
@@ -486,12 +486,22 @@ EXAMPLES = """
# set firewall group address-group 'inbound'
-# Using deleted to delete all the the firewall rules when provided config is empty
+# Using deleted to delete firewall rules based on afi
#
# Before state
# -------------
#
# vyos@vyos:~$ show configuration commands| grep firewall
+# 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 group address-group 'inbound'
# set firewall name Downlink default-action 'accept'
# set firewall name Downlink description 'IPv4 INBOUND rule set'
@@ -501,10 +511,12 @@ EXAMPLES = """
# 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:
+ vyos.vyos.vyos_firewall_rules:
config:
+ - afi: ipv4
state: deleted
#
#
@@ -514,69 +526,29 @@ EXAMPLES = """
#
# "before": [
# {
-# "afi": "ipv4",
+# "afi": "ipv6",
# "rule_sets": [
# {
# "default_action": "accept",
-# "description": "IPv4 INBOUND rule set",
-# "name": "Downlink",
+# "description": "This is ipv6 specific rule-set",
+# "name": "UPLINK",
# "rules": [
# {
# "action": "accept",
-# "description": "Rule 501 is configured by Ansible",
+# "description": "Fwipv6-Rule 1 is configured by Ansible",
# "ipsec": "match-ipsec",
-# "number": 501
+# "number": 1
# },
# {
-# "action": "reject",
-# "description": "Rule 502 is configured by Ansible",
+# "action": "accept",
+# "description": "Fwipv6-Rule 2 is configured by Ansible",
# "ipsec": "match-ipsec",
-# "number": 502
+# "number": 2
# }
# ]
-# }
+# }
# ]
-# }
-# ]
-# "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": [
@@ -603,18 +575,26 @@ EXAMPLES = """
# }
# ]
# "commands": [
-# "delete firewall name",
+# "delete firewall name"
# ]
#
# "after": []
# After state
# ------------
-# vyos@vyos# run show configuration commands | grep firewall
-# set firewall group address-group 'inbound'
-
+# vyos@vyos:~$ show configuration commands| grep firewall
+# 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'
-# Using deleted to delete the the firewall rules based on rule number/id
+# Using deleted to delete all the the firewall rules when provided config is empty
#
# Before state
# -------------
@@ -631,13 +611,8 @@ EXAMPLES = """
# set firewall name Downlink rule 502 ipsec 'match-ipsec'
#
- name: Delete attributes of given firewall rules.
- vyos_firewall_rules:
+ vyos.vyos.vyos_firewall_rules:
config:
- - afi: ipv4
- rule_sets:
- - name: 'Downlink'
- rules:
- - number: 501
state: deleted
#
#
@@ -672,38 +647,14 @@ EXAMPLES = """
# }
# ]
# "commands": [
-# "delete firewall ipv6-name Downlink rule 501"
+# "delete firewall name"
# ]
#
-# "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": []
# After state
# ------------
-# vyos@vyos:~$ show configuration commands| grep firewall
+# vyos@vyos# run 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
@@ -715,7 +666,7 @@ EXAMPLES = """
# set firewall group address-group 'inbound'
#
- name: Merge the provided configuration with the exisiting running configuration
- vyos_firewall_rules:
+ vyos.vyos.vyos_firewall_rules:
config:
- afi: 'ipv6'
rule_sets:
@@ -934,7 +885,7 @@ EXAMPLES = """
# set firewall name INBOUND rule 103 state related 'enable'
#
- name: Replace device configurations of listed firewall rules with provided configurations
- vyos_firewall_rules:
+ vyos.vyos.vyos_firewall_rules:
config:
- afi: 'ipv6'
rule_sets:
@@ -1116,7 +1067,7 @@ EXAMPLES = """
# set firewall name INBOUND rule 104 ipsec 'match-none'
#
- name: Overrides all device configuration with provided configuration
- vyos_firewall_rules:
+ vyos.vyos.vyos_firewall_rules:
config:
- afi: 'ipv4'
rule_sets:
@@ -1267,7 +1218,7 @@ EXAMPLES = """
# set firewall name INBOUND rule 103 state related 'enable'
#
- name: Gather listed firewall rules with provided configurations
- vyos_firewall_rules:
+ vyos.vyos.vyos_firewall_rules:
config:
state: gathered
#
@@ -1382,7 +1333,7 @@ EXAMPLES = """
#
#
- name: Render the commands for provided configuration
- vyos_firewall_rules:
+ vyos.vyos.vyos_firewall_rules:
config:
- afi: 'ipv6'
rule_sets:
@@ -1452,8 +1403,8 @@ EXAMPLES = """
# Using parsed
#
#
-- name: Render the commands for provided configuration
- vyos_firewall_rules:
+- name: Parsed the provided input commands.
+ vyos.vyos.vyos_firewall_rules:
running_config:
"set firewall group address-group 'inbound'
set firewall name Downlink default-action 'accept'
@@ -1546,6 +1497,7 @@ def main():
required_if = [
("state", "merged", ("config",)),
("state", "replaced", ("config",)),
+ ("state", "rendered", ("config",)),
("state", "overridden", ("config",)),
("state", "parsed", ("running_config",)),
]
diff --git a/plugins/modules/vyos_interfaces.py b/plugins/modules/vyos_interfaces.py
index 93df4e46..6730e306 100644
--- a/plugins/modules/vyos_interfaces.py
+++ b/plugins/modules/vyos_interfaces.py
@@ -30,14 +30,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-ANSIBLE_METADATA = {
- "metadata_version": "1.1",
- "status": ["preview"],
- "supported_by": "network",
-}
+ANSIBLE_METADATA = {"metadata_version": "1.1", "supported_by": "Ansible"}
DOCUMENTATION = """module: vyos_interfaces
-short_description: Manages interface attributes of VyOS network devices.
+short_description: Interfaces resource module
description:
- This module manages the interface attributes on VyOS network devices.
- This module supports managing base attributes of Ethernet, Bonding, VXLAN, Loopback
@@ -45,7 +41,10 @@ description:
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)
+version_added: "1.0.0"
+author:
+- Nilashish Chakraborty (@nilashishc)
+- Rohit Thakur (@rohitthakur2590)
options:
config:
description: The provided interfaces configuration.
@@ -119,6 +118,15 @@ options:
- MTU for the virtual sub-interface.
- Refer to vendor documentation for valid values.
type: int
+ running_config:
+ description:
+ - This option is used only with state I(parsed).
+ - The value of this option should be the output received from the VyOS device by executing
+ the command B(show configuration commands | grep interfaces).
+ - The state I(parsed) reads the configuration from C(running_config) option and transforms
+ it into Ansible structured data as per the resource module's argspec and the value is then
+ returned in the I(parsed) key within the result.
+ type: str
state:
description:
- The state of the configuration after module completion.
@@ -128,6 +136,9 @@ options:
- replaced
- overridden
- deleted
+ - rendered
+ - gathered
+ - parsed
default: merged
"""
EXAMPLES = """
@@ -152,7 +163,7 @@ EXAMPLES = """
# set interfaces loopback lo
- name: Merge provided configuration with device configuration
- vyos_interfaces:
+ vyos.vyos.vyos_interfaces:
config:
- name: eth2
description: 'Configured by Ansible'
@@ -330,7 +341,7 @@ EXAMPLES = """
#
#
- name: Replace device configurations of listed interfaces with provided configurations
- vyos_interfaces:
+ vyos.vyos.vyos_interfaces:
config:
- name: eth2
description: "Replaced by Ansible"
@@ -515,7 +526,7 @@ EXAMPLES = """
#
#
- name: Overrides all device configuration with provided configuration
- vyos_interfaces:
+ vyos.vyos.vyos_interfaces:
config:
- name: eth0
description: Outbound Interface For The Appliance
@@ -700,7 +711,7 @@ EXAMPLES = """
#
#
- name: Delete attributes of given interfaces (Note - This won't delete the interfaces themselves)
- vyos_interfaces:
+ vyos.vyos.vyos_interfaces:
config:
- name: bond1
@@ -838,6 +849,224 @@ EXAMPLES = """
# set interfaces loopback lo
#
#
+
+
+# Using gathered
+#
+# Before state:
+# -------------
+#
+# vyos@192# run show configuration commands | grep interfaces
+# set interfaces ethernet eth0 address 'dhcp'
+# set interfaces ethernet eth0 duplex 'auto'
+# set interfaces ethernet eth0 hw-id '08:00:27:50:5e:19'
+# set interfaces ethernet eth0 smp_affinity 'auto'
+# set interfaces ethernet eth0 speed 'auto'
+# set interfaces ethernet eth1 description 'Configured by Ansible'
+# set interfaces ethernet eth1 duplex 'auto'
+# set interfaces ethernet eth1 mtu '1500'
+# set interfaces ethernet eth1 speed 'auto'
+# set interfaces ethernet eth1 vif 200 description 'VIF - 200'
+# set interfaces ethernet eth2 description 'Configured by Ansible'
+# set interfaces ethernet eth2 duplex 'auto'
+# set interfaces ethernet eth2 mtu '1500'
+# set interfaces ethernet eth2 speed 'auto'
+# set interfaces ethernet eth2 vif 200 description 'VIF - 200'
+#
+- name: Gather listed interfaces with provided configurations
+ vyos.vyos.vyos_interfaces:
+ config:
+ state: gathered
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+# "gathered": [
+# {
+# "description": "Configured by Ansible",
+# "duplex": "auto",
+# "enabled": true,
+# "mtu": 1500,
+# "name": "eth2",
+# "speed": "auto",
+# "vifs": [
+# {
+# "description": "VIF - 200",
+# "enabled": true,
+# "vlan_id": 200
+# }
+# ]
+# },
+# {
+# "description": "Configured by Ansible",
+# "duplex": "auto",
+# "enabled": true,
+# "mtu": 1500,
+# "name": "eth1",
+# "speed": "auto",
+# "vifs": [
+# {
+# "description": "VIF - 200",
+# "enabled": true,
+# "vlan_id": 200
+# }
+# ]
+# },
+# {
+# "duplex": "auto",
+# "enabled": true,
+# "name": "eth0",
+# "speed": "auto"
+# }
+# ]
+#
+#
+# After state:
+# -------------
+#
+# vyos@192# run show configuration commands | grep interfaces
+# set interfaces ethernet eth0 address 'dhcp'
+# set interfaces ethernet eth0 duplex 'auto'
+# set interfaces ethernet eth0 hw-id '08:00:27:50:5e:19'
+# set interfaces ethernet eth0 smp_affinity 'auto'
+# set interfaces ethernet eth0 speed 'auto'
+# set interfaces ethernet eth1 description 'Configured by Ansible'
+# set interfaces ethernet eth1 duplex 'auto'
+# set interfaces ethernet eth1 mtu '1500'
+# set interfaces ethernet eth1 speed 'auto'
+# set interfaces ethernet eth1 vif 200 description 'VIF - 200'
+# set interfaces ethernet eth2 description 'Configured by Ansible'
+# set interfaces ethernet eth2 duplex 'auto'
+# set interfaces ethernet eth2 mtu '1500'
+# set interfaces ethernet eth2 speed 'auto'
+# set interfaces ethernet eth2 vif 200 description 'VIF - 200'
+
+
+# Using rendered
+#
+#
+- name: Render the commands for provided configuration
+ vyos.vyos.vyos_interfaces:
+ config:
+ - 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
+ state: rendered
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+#
+# "rendered": [
+# "set interfaces ethernet eth0 duplex 'auto'",
+# "set interfaces ethernet eth0 speed 'auto'",
+# "delete interfaces ethernet eth0 disable",
+# "set interfaces ethernet eth1 duplex 'auto'",
+# "delete interfaces ethernet eth1 disable",
+# "set interfaces ethernet eth1 speed 'auto'",
+# "set interfaces ethernet eth1 description 'Configured by Ansible - Interface 1'",
+# "set interfaces ethernet eth1 mtu '1500'",
+# "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 disable",
+# "set interfaces ethernet eth2 description 'Configured by Ansible - Interface 2 (ADMIN DOWN)'",
+# "set interfaces ethernet eth2 mtu '600'"
+# ]
+
+
+# Using parsed
+#
+#
+- name: Parse the configuration.
+ vyos.vyos.vyos_interfaces:
+ running_config:
+ "set interfaces ethernet eth0 address 'dhcp'
+ set interfaces ethernet eth0 duplex 'auto'
+ set interfaces ethernet eth0 hw-id '08:00:27:50:5e:19'
+ set interfaces ethernet eth0 smp_affinity 'auto'
+ set interfaces ethernet eth0 speed 'auto'
+ set interfaces ethernet eth1 description 'Configured by Ansible'
+ set interfaces ethernet eth1 duplex 'auto'
+ set interfaces ethernet eth1 mtu '1500'
+ set interfaces ethernet eth1 speed 'auto'
+ set interfaces ethernet eth1 vif 200 description 'VIF - 200'
+ set interfaces ethernet eth2 description 'Configured by Ansible'
+ set interfaces ethernet eth2 duplex 'auto'
+ set interfaces ethernet eth2 mtu '1500'
+ set interfaces ethernet eth2 speed 'auto'
+ set interfaces ethernet eth2 vif 200 description 'VIF - 200'"
+ state: parsed
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+#
+# "parsed": [
+# {
+# "description": "Configured by Ansible",
+# "duplex": "auto",
+# "enabled": true,
+# "mtu": 1500,
+# "name": "eth2",
+# "speed": "auto",
+# "vifs": [
+# {
+# "description": "VIF - 200",
+# "enabled": true,
+# "vlan_id": 200
+# }
+# ]
+# },
+# {
+# "description": "Configured by Ansible",
+# "duplex": "auto",
+# "enabled": true,
+# "mtu": 1500,
+# "name": "eth1",
+# "speed": "auto",
+# "vifs": [
+# {
+# "description": "VIF - 200",
+# "enabled": true,
+# "vlan_id": 200
+# }
+# ]
+# },
+# {
+# "duplex": "auto",
+# "enabled": true,
+# "name": "eth0",
+# "speed": "auto"
+# }
+# ]
+
+
"""
RETURN = """
before:
@@ -879,8 +1108,19 @@ def main():
:returns: the result form module invocation
"""
+ required_if = [
+ ("state", "merged", ("config",)),
+ ("state", "replaced", ("config",)),
+ ("state", "rendered", ("config",)),
+ ("state", "overridden", ("config",)),
+ ("state", "parsed", ("running_config",)),
+ ]
+ mutually_exclusive = [("config", "running_config")]
module = AnsibleModule(
- argument_spec=InterfacesArgs.argument_spec, supports_check_mode=True
+ argument_spec=InterfacesArgs.argument_spec,
+ required_if=required_if,
+ supports_check_mode=True,
+ mutually_exclusive=mutually_exclusive,
)
result = Interfaces(module).execute_module()
diff --git a/plugins/modules/vyos_l3_interfaces.py b/plugins/modules/vyos_l3_interfaces.py
index a77ecaf7..47242405 100644
--- a/plugins/modules/vyos_l3_interfaces.py
+++ b/plugins/modules/vyos_l3_interfaces.py
@@ -37,12 +37,14 @@ ANSIBLE_METADATA = {
}
DOCUMENTATION = """module: vyos_l3_interfaces
-short_description: Manages L3 interface attributes of VyOS network devices.
+short_description: L3 interfaces resource module
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)
+author:
+- Nilashish Chakraborty (@NilashishC)
+- Rohit Thakur (@rohitthakur2590)
options:
config:
description: The provided L3 interfaces configuration.
@@ -104,6 +106,16 @@ options:
description:
- IPv6 address of the virtual interface.
type: str
+ running_config:
+ description:
+ - This option is used only with state I(parsed).
+ - The value of this option should be the output received from the VyOS device by executing
+ the command B(show configuration commands | grep -e eth[2,3]).
+ - The state I(parsed) reads the configuration from C(running_config) option and transforms
+ it into Ansible structured data as per the resource module's argspec and the value is then
+ returned in the I(parsed) key within the result.
+ type: str
+ version_added: "1.0.0"
state:
description:
- The state of the configuration after module completion.
@@ -113,6 +125,9 @@ options:
- replaced
- overridden
- deleted
+ - parsed
+ - gathered
+ - rendered
default: merged
"""
EXAMPLES = """
@@ -128,7 +143,7 @@ EXAMPLES = """
# set interfaces ethernet eth3 vif 102
- name: Merge provided configuration with device configuration
- vyos_l3_interfaces:
+ vyos.vyos.vyos_l3_interfaces:
config:
- name: eth2
ipv4:
@@ -196,7 +211,7 @@ EXAMPLES = """
# 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:
+ vyos.vyos.vyos_l3_interfaces:
config:
- name: eth2
ipv4:
@@ -252,7 +267,7 @@ EXAMPLES = """
# set interfaces ethernet eth3 vif 102 address '2001:db8:4000::2/34'
- name: Overrides all device configuration with provided configuration
- vyos_l3_interfaces:
+ vyos.vyos.vyos_l3_interfaces:
config:
- name: eth0
ipv4:
@@ -303,7 +318,7 @@ EXAMPLES = """
# 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:
+ vyos.vyos.vyos_l3_interfaces:
config:
- name: eth1
- name: eth2
@@ -326,6 +341,180 @@ EXAMPLES = """
# set interfaces ethernet eth3 smp_affinity 'auto'
+# Using gathered
+#
+# Before state:
+# -------------
+#
+# vyos:~$ show configuration commands | grep -e eth[2,3,0]
+# set interfaces ethernet eth0 address 'dhcp'
+# set interfaces ethernet eth0 duplex 'auto'
+# set interfaces ethernet eth0 hw-id '08:00:27:50:5e:19'
+# set interfaces ethernet eth0 smp_affinity 'auto'
+# set interfaces ethernet eth0 speed 'auto'
+# set interfaces ethernet eth1 address '192.0.2.14/24'
+# set interfaces ethernet eth2 address '192.0.2.11/24'
+# set interfaces ethernet eth2 address '192.0.2.10/24'
+# set interfaces ethernet eth2 address '2001:db8::10/32'
+# set interfaces ethernet eth2 address '2001:db8::12/32'
+#
+- name: Gather listed l3 interfaces with provided configurations
+ vyos.vyos.vyos_l3_interfaces:
+ config:
+ state: gathered
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+# "gathered": [
+# {
+# "ipv4": [
+# {
+# "address": "192.0.2.11/24"
+# },
+# {
+# "address": "192.0.2.10/24"
+# }
+# ],
+# "ipv6": [
+# {
+# "address": "2001:db8::10/32"
+# },
+# {
+# "address": "2001:db8::12/32"
+# }
+# ],
+# "name": "eth2"
+# },
+# {
+# "ipv4": [
+# {
+# "address": "192.0.2.14/24"
+# }
+# ],
+# "name": "eth1"
+# },
+# {
+# "ipv4": [
+# {
+# "address": "dhcp"
+# }
+# ],
+# "name": "eth0"
+# }
+# ]
+#
+#
+# After state:
+# -------------
+#
+# vyos:~$ show configuration commands | grep -e eth[2,3]
+# set interfaces ethernet eth0 address 'dhcp'
+# set interfaces ethernet eth0 duplex 'auto'
+# set interfaces ethernet eth0 hw-id '08:00:27:50:5e:19'
+# set interfaces ethernet eth0 smp_affinity 'auto'
+# set interfaces ethernet eth0 speed 'auto'
+# set interfaces ethernet eth1 address '192.0.2.14/24'
+# set interfaces ethernet eth2 address '192.0.2.11/24'
+# set interfaces ethernet eth2 address '192.0.2.10/24'
+# set interfaces ethernet eth2 address '2001:db8::10/32'
+# set interfaces ethernet eth2 address '2001:db8::12/32'
+
+
+# Using rendered
+#
+#
+- name: Render the commands for provided configuration
+ vyos.vyos.vyos_l3_interfaces:
+ config:
+ - 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
+ state: rendered
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+#
+# "rendered": [
+# "set interfaces ethernet eth1 address '192.0.2.14/24'",
+# "set interfaces ethernet eth2 address '192.0.2.11/24'",
+# "set interfaces ethernet eth2 address '192.0.2.10/24'",
+# "set interfaces ethernet eth2 address '2001:db8::10/32'",
+# "set interfaces ethernet eth2 address '2001:db8::12/32'"
+# ]
+
+
+# Using parsed
+#
+#
+- name: parse the provided running configuration
+ vyos.vyos.vyos_l3_interfaces:
+ running_config:
+ "set interfaces ethernet eth0 address 'dhcp'
+ 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'"
+ state: parsed
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+#
+# "parsed": [
+# {
+# "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": "eth2"
+# },
+# {
+# "ipv4": [
+# {
+# "address": "192.0.2.14/24"
+# }
+# ],
+# "name": "eth1"
+# },
+# {
+# "ipv4": [
+# {
+# "address": "dhcp"
+# }
+# ],
+# "name": "eth0"
+# }
+# ]
+
+
"""
RETURN = """
before:
@@ -365,8 +554,20 @@ def main():
:returns: the result form module invocation
"""
+ required_if = [
+ ("state", "merged", ("config",)),
+ ("state", "replaced", ("config",)),
+ ("state", "rendered", ("config",)),
+ ("state", "overridden", ("config",)),
+ ("state", "parsed", ("running_config",)),
+ ]
+ mutually_exclusive = [("config", "running_config")]
+
module = AnsibleModule(
- argument_spec=L3_interfacesArgs.argument_spec, supports_check_mode=True
+ argument_spec=L3_interfacesArgs.argument_spec,
+ required_if=required_if,
+ supports_check_mode=True,
+ mutually_exclusive=mutually_exclusive,
)
result = L3_interfaces(module).execute_module()
diff --git a/plugins/modules/vyos_lag_interfaces.py b/plugins/modules/vyos_lag_interfaces.py
index 84f3d018..1ba511c9 100644
--- a/plugins/modules/vyos_lag_interfaces.py
+++ b/plugins/modules/vyos_lag_interfaces.py
@@ -30,16 +30,13 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-ANSIBLE_METADATA = {
- "metadata_version": "1.1",
- "status": ["preview"],
- "supported_by": "network",
-}
+ANSIBLE_METADATA = {"metadata_version": "1.1", "supported_by": "Ansible"}
DOCUMENTATION = """module: vyos_lag_interfaces
-short_description: Manages attributes of link aggregation groups on VyOS network devices.
+short_description: LAG interfaces resource module
description: This module manages attributes of link aggregation groups on VyOS network
devices.
+version_added: "1.0.0"
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).
@@ -100,6 +97,15 @@ options:
description:
- IP address to use for ARP monitoring.
type: list
+ running_config:
+ description:
+ - This option is used only with state I(parsed).
+ - The value of this option should be the output received from the VyOS device by executing
+ the command B(show configuration commands | grep bond).
+ - The state I(parsed) reads the configuration from C(running_config) option and transforms
+ it into Ansible structured data as per the resource module's argspec and the value is then
+ returned in the I(parsed) key within the result.
+ type: str
state:
description:
- The state of the configuration after module completion.
@@ -109,6 +115,9 @@ options:
- replaced
- overridden
- deleted
+ - parsed
+ - gathered
+ - rendered
default: merged
"""
EXAMPLES = """
@@ -122,7 +131,7 @@ EXAMPLES = """
# set interfaces bonding bond3
#
- name: Merge provided configuration with device configuration
- vyos_lag_interfaces:
+ vyos.vyos.vyos_lag_interfaces:
config:
- name: bond2
mode: active-backup
@@ -226,7 +235,7 @@ EXAMPLES = """
# set interfaces ethernet eth3 bond-group 'bond3'
#
- name: Replace device configurations of listed LAGs with provided configurations
- vyos_lag_interfaces:
+ vyos.vyos.vyos_lag_interfaces:
config:
- name: bond3
mode: '802.3ad'
@@ -331,7 +340,7 @@ EXAMPLES = """
# set interfaces ethernet eth3 bond-group 'bond3'
#
- name: Overrides all device configuration with provided configuration
- vyos_lag_interfaces:
+ vyos.vyos.vyos_lag_interfaces:
config:
- name: bond3
mode: active-backup
@@ -441,7 +450,7 @@ EXAMPLES = """
# 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:
+ vyos.vyos.vyos_lag_interfaces:
config:
- name: bond2
- name: bond3
@@ -507,6 +516,202 @@ EXAMPLES = """
# set interfaces bonding bond3
+# Using gathered
+#
+# Before state:
+# -------------
+#
+# vyos@192# run show configuration commands | grep bond
+# set interfaces bonding bond0 hash-policy 'layer2'
+# set interfaces bonding bond0 mode 'active-backup'
+# set interfaces bonding bond0 primary 'eth1'
+# set interfaces bonding bond1 hash-policy 'layer2+3'
+# set interfaces bonding bond1 mode 'active-backup'
+# set interfaces bonding bond1 primary 'eth2'
+# set interfaces ethernet eth1 bond-group 'bond0'
+# set interfaces ethernet eth2 bond-group 'bond1'
+#
+- name: Gather listed lag interfaces with provided configurations
+ vyos.vyos.vyos_lag_interfaces:
+ 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@192# run show configuration commands | grep bond
+# set interfaces bonding bond0 hash-policy 'layer2'
+# set interfaces bonding bond0 mode 'active-backup'
+# set interfaces bonding bond0 primary 'eth1'
+# set interfaces bonding bond1 hash-policy 'layer2+3'
+# set interfaces bonding bond1 mode 'active-backup'
+# set interfaces bonding bond1 primary 'eth2'
+# set interfaces ethernet eth1 bond-group 'bond0'
+# set interfaces ethernet eth2 bond-group 'bond1'
+
+
+# Using rendered
+#
+#
+- name: Render the commands for provided configuration
+ vyos.vyos.vyos_lag_interfaces:
+ config:
+ - 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
+ state: rendered
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+#
+# "rendered": [
+# "set interfaces bonding bond0 hash-policy 'layer2'",
+# "set interfaces ethernet eth1 bond-group 'bond0'",
+# "set interfaces bonding bond0 mode 'active-backup'",
+# "set interfaces bonding bond0 primary 'eth1'",
+# "set interfaces bonding bond1 hash-policy 'layer2+3'",
+# "set interfaces ethernet eth2 bond-group 'bond1'",
+# "set interfaces bonding bond1 mode 'active-backup'",
+# "set interfaces bonding bond1 primary 'eth2'"
+# ]
+
+
+# Using parsed
+#
+#
+- name: Parsed the commands for provided configuration
+ vyos.vyos.vyos_l3_interfaces:
+ running_config:
+ "set interfaces bonding bond0 hash-policy 'layer2'
+ set interfaces bonding bond0 mode 'active-backup'
+ set interfaces bonding bond0 primary 'eth1'
+ set interfaces bonding bond1 hash-policy 'layer2+3'
+ set interfaces bonding bond1 mode 'active-backup'
+ set interfaces bonding bond1 primary 'eth2'
+ set interfaces ethernet eth1 bond-group 'bond0'
+ set interfaces ethernet eth2 bond-group 'bond1'"
+ state: parsed
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+#
+# "parsed": [
+# {
+# "hash_policy": "layer2",
+# "members": [
+# {
+# "member": "eth1"
+# }
+# ],
+# "mode": "active-backup",
+# "name": "bond0",
+# "primary": "eth1"
+# },
+# {
+# "hash_policy": "layer2+3",
+# "members": [
+# {
+# "member": "eth2"
+# }
+# ],
+# "mode": "active-backup",
+# "name": "bond1",
+# "primary": "eth2"
+# }
+# ]
+
+
"""
RETURN = """
before:
@@ -551,12 +756,17 @@ def main():
required_if = [
("state", "merged", ("config",)),
("state", "replaced", ("config",)),
+ ("state", "rendered", ("config",)),
("state", "overridden", ("config",)),
+ ("state", "parsed", ("running_config",)),
]
+ mutually_exclusive = [("config", "running_config")]
+
module = AnsibleModule(
argument_spec=Lag_interfacesArgs.argument_spec,
required_if=required_if,
supports_check_mode=True,
+ mutually_exclusive=mutually_exclusive,
)
result = Lag_interfaces(module).execute_module()
diff --git a/plugins/modules/vyos_lldp_global.py b/plugins/modules/vyos_lldp_global.py
index 08eb1133..3a93c955 100644
--- a/plugins/modules/vyos_lldp_global.py
+++ b/plugins/modules/vyos_lldp_global.py
@@ -30,17 +30,13 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-ANSIBLE_METADATA = {
- "metadata_version": "1.1",
- "status": ["preview"],
- "supported_by": "network",
-}
+ANSIBLE_METADATA = {"metadata_version": "1.1", "supported_by": "Ansible"}
DOCUMENTATION = """module: vyos_lldp_global
-short_description: Manage link layer discovery protocol (LLDP) attributes on VyOS
- devices..
+short_description: LLDP global resource module
description: This module manages link layer discovery protocol (LLDP) attributes on
VyOS devices.
+version_added: "1.0.0"
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).
@@ -72,6 +68,15 @@ options:
- edp
- fdp
- sonmp
+ running_config:
+ description:
+ - This option is used only with state I(parsed).
+ - The value of this option should be the output received from the VyOS device by executing
+ the command B(show configuration commands | grep lldp).
+ - The state I(parsed) reads the configuration from C(running_config) option and transforms
+ it into Ansible structured data as per the resource module's argspec and the value is then
+ returned in the I(parsed) key within the result.
+ type: str
state:
description:
- The state of the configuration after module completion.
@@ -80,6 +85,9 @@ options:
- merged
- replaced
- deleted
+ - gathered
+ - rendered
+ - parsed
default: merged
"""
EXAMPLES = """
@@ -89,10 +97,9 @@ EXAMPLES = """
# -------------
#
# vyos@vyos:~$ show configuration commands|grep lldp
-# vyos@vyos:~$
#
- name: Merge provided configuration with device configuration
- vyos_lldp_global:
+ vyos.vyos.vyos_lldp_global:
config:
legacy_protocols:
- 'fdp'
@@ -154,7 +161,7 @@ EXAMPLES = """
# set service lldp snmp enable
#
- name: Replace device configurations with provided configurations
- vyos_lldp_global:
+ vyos.vyos.vyos_lldp_global:
config:
legacy_protocols:
- 'edp'
@@ -231,7 +238,7 @@ EXAMPLES = """
# 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:
+ vyos.vyos.vyos_lldp_global:
config:
state: deleted
#
@@ -273,6 +280,163 @@ EXAMPLES = """
# set service lldp
+# Using gathered
+#
+# Before state:
+# -------------
+#
+# vyos@192# run show configuration commands | grep lldp
+# set service lldp legacy-protocols 'cdp'
+# set service lldp management-address '192.0.2.17'
+#
+- name: Gather lldp global config with provided configurations
+ vyos.vyos.vyos_lldp_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 lldp
+# set service lldp legacy-protocols 'cdp'
+# set service lldp management-address '192.0.2.17'
+
+
+# Using rendered
+#
+#
+- name: Render the commands for provided configuration
+ vyos.vyos.vyos_lldp_global:
+ config:
+ address: 192.0.2.17
+ enable: true
+ legacy_protocols:
+ - cdp
+ state: rendered
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+#
+# "rendered": [
+# "set service lldp legacy-protocols 'cdp'",
+# "set service lldp",
+# "set service lldp management-address '192.0.2.17'"
+# ]
+#
+
+
+# Using parsed
+#
+#
+- name: Parse the provided commands to provide structured configuration
+ vyos.vyos.vyos_lldp_global:
+ running_config:
+ "set service lldp legacy-protocols 'cdp'
+ set service lldp legacy-protocols 'fdp'
+ set service lldp management-address '192.0.2.11'"
+ state: parsed
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+#
+# "parsed": {
+# "address": "192.0.2.11",
+# "enable": true,
+# "legacy_protocols": [
+# "cdp",
+# "fdp"
+# ]
+# }
+#
+
+
"""
RETURN = """
before:
@@ -317,13 +481,16 @@ def main():
required_if = [
("state", "merged", ("config",)),
("state", "replaced", ("config",)),
+ ("state", "rendered", ("config",)),
+ ("state", "parsed", ("running_config",)),
]
+ mutually_exclusive = [("config", "running_config")]
module = AnsibleModule(
argument_spec=Lldp_globalArgs.argument_spec,
required_if=required_if,
supports_check_mode=True,
+ mutually_exclusive=mutually_exclusive,
)
-
result = Lldp_global(module).execute_module()
module.exit_json(**result)
diff --git a/plugins/modules/vyos_lldp_interfaces.py b/plugins/modules/vyos_lldp_interfaces.py
index 8fe572b0..b26da49e 100644
--- a/plugins/modules/vyos_lldp_interfaces.py
+++ b/plugins/modules/vyos_lldp_interfaces.py
@@ -30,18 +30,15 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-ANSIBLE_METADATA = {
- "metadata_version": "1.1",
- "status": ["preview"],
- "supported_by": "network",
-}
+ANSIBLE_METADATA = {"metadata_version": "1.1", "supported_by": "Ansible"}
DOCUMENTATION = """module: vyos_lldp_interfaces
-short_description: Manages attributes of lldp interfaces on VyOS devices.
+short_description: LLDP interfaces resource module
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).
+version_added: "1.0.0"
author:
- Rohit Thakur (@rohitthakur2590)
options:
@@ -111,6 +108,15 @@ options:
elin:
description: Emergency Call Service ELIN number (between 10-25 numbers).
type: str
+ running_config:
+ description:
+ - This option is used only with state I(parsed).
+ - The value of this option should be the output received from the VyOS device by executing
+ the command B(show configuration commands | grep lldp).
+ - The state I(parsed) reads the configuration from C(running_config) option and transforms
+ it into Ansible structured data as per the resource module's argspec and the value is then
+ returned in the I(parsed) key within the result.
+ type: str
state:
description:
- The state of the configuration after module completion.
@@ -120,6 +126,9 @@ options:
- replaced
- overridden
- deleted
+ - rendered
+ - parsed
+ - gathered
default: merged
"""
EXAMPLES = """
@@ -131,7 +140,7 @@ EXAMPLES = """
# vyos@vyos:~$ show configuration commands | grep lldp
#
- name: Merge provided configuration with device configuration
- vyos_lldp_interfaces:
+ vyos.vyos.vyos_lldp_interfaces:
config:
- name: 'eth1'
location:
@@ -225,7 +234,7 @@ EXAMPLES = """
# 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:
+ vyos.vyos.vyos_lldp_interfaces:
config:
- name: 'eth2'
location:
@@ -348,7 +357,7 @@ EXAMPLES = """
# set service lldp interface eth2 location civic-based country-code 'US'
#
- name: Overrides all device configuration with provided configuration
- vyos_lag_interfaces:
+ vyos.vyos.vyos_lldp_interfaces:
config:
- name: 'eth2'
location:
@@ -423,7 +432,7 @@ EXAMPLES = """
# set service lldp interface eth2 location elin '0000000911'
#
- name: Delete lldp interface attributes of given interfaces.
- vyos_lag_interfaces:
+ vyos.vyos.vyos_lldp_interfaces:
config:
- name: 'eth2'
state: deleted
@@ -453,6 +462,159 @@ EXAMPLES = """
# set service 'lldp'
+# Using gathered
+#
+# Before state:
+# -------------
+#
+# vyos@192# run 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: Gather listed lldp interfaces from running configuration
+ vyos.vyos.vyos_lldp_interfaces:
+ config:
+ state: gathered
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+# "gathered": [
+# {
+# "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@192# run 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 rendered
+#
+#
+- name: Render the commands for provided configuration
+ vyos.vyos.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: rendered
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+#
+# "rendered": [
+# "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"
+# ]
+
+
+# Using parsed
+#
+#
+- name: Parsed the commands to provide structured configuration.
+ vyos.vyos.vyos_lldp_interfaces:
+ running_config:
+ "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'"
+ state: parsed
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+#
+# "parsed": [
+# {
+# "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"
+# }
+# ]
+
+
"""
RETURN = """
before:
@@ -497,12 +659,17 @@ def main():
required_if = [
("state", "merged", ("config",)),
("state", "replaced", ("config",)),
+ ("state", "rendered", ("config",)),
("state", "overridden", ("config",)),
+ ("state", "parsed", ("running_config",)),
]
+ mutually_exclusive = [("config", "running_config")]
+
module = AnsibleModule(
argument_spec=Lldp_interfacesArgs.argument_spec,
required_if=required_if,
supports_check_mode=True,
+ mutually_exclusive=mutually_exclusive,
)
result = Lldp_interfaces(module).execute_module()
diff --git a/plugins/modules/vyos_ospfv2.py b/plugins/modules/vyos_ospfv2.py
new file mode 100644
index 00000000..9c40d9c2
--- /dev/null
+++ b/plugins/modules/vyos_ospfv2.py
@@ -0,0 +1,1814 @@
+#!/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_ospfv2
+"""
+
+from __future__ import absolute_import, division, print_function
+
+__metaclass__ = type
+
+ANSIBLE_METADATA = {"metadata_version": "1.1", "supported_by": "Ansible"}
+
+DOCUMENTATION = """
+---
+module: vyos_ospfv2
+version_added: 2.10
+short_description: OSPFV2 resource module
+description: This resource module configures and manages attributes of OSPFv2 routes on VyOS network devices.
+version_added: "1.0.0"
+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 OSPFv2 route configuration.
+ type: dict
+ suboptions:
+ areas:
+ description: OSPFv2 area.
+ type: list
+ elements: dict
+ suboptions:
+ area_id:
+ description: OSPFv2 area identity.
+ type: str
+ area_type:
+ description: Area type.
+ type: dict
+ suboptions:
+ normal:
+ description: Normal OSPFv2 area.
+ type: bool
+ nssa:
+ description: NSSA OSPFv2 area.
+ type: dict
+ suboptions:
+ set:
+ description: Enabling NSSA.
+ type: bool
+ default_cost:
+ description: Summary-default cost of NSSA area.
+ type: int
+ no_summary:
+ description: Do not inject inter-area routes into stub.
+ type: bool
+ translate:
+ description: NSSA-ABR.
+ type: str
+ choices: ['always', 'candidate', 'never']
+ stub:
+ description: Stub OSPFv2 area.
+ type: dict
+ suboptions:
+ set:
+ description: Enabling stub.
+ type: bool
+ default_cost:
+ description: Summary-default cost of stub area.
+ type: int
+ no_summary:
+ description: Do not inject inter-area routes into stub.
+ type: bool
+ authentication:
+ description: OSPFv2 area authentication type.
+ type: str
+ choices: ['plaintext-password', 'md5']
+ network:
+ description: OSPFv2 network.
+ type: list
+ elements: dict
+ suboptions:
+ address:
+ required: True
+ description: OSPFv2 IPv4 network address.
+ type: str
+ range:
+ description: Summarize routes matching prefix (border routers only).
+ type: list
+ elements: dict
+ suboptions:
+ address:
+ description: border router IPv4 address.
+ type: str
+ cost:
+ description: Metric for this range.
+ type: int
+ not_advertise:
+ description: Don't advertise this range.
+ type: bool
+ substitute:
+ description: Announce area range (IPv4 address) as another prefix.
+ type: str
+ shortcut:
+ description: Area's shortcut mode.
+ type: str
+ choices: ['default', 'disable', 'enable']
+ virtual_link:
+ description: Virtual link address.
+ type: list
+ elements: dict
+ suboptions:
+ address:
+ description: virtual link address.
+ type: str
+ authentication:
+ description: OSPFv2 area authentication type.
+ type: dict
+ suboptions:
+ md5:
+ description: MD5 key id based authentication.
+ type: list
+ elements: dict
+ suboptions:
+ key_id:
+ description: MD5 key id.
+ type: int
+ md5_key:
+ description: MD5 key.
+ type: str
+ plaintext_password:
+ description: Plain text password.
+ type: str
+ dead_interval:
+ description: Interval after which a neighbor is declared dead.
+ type: int
+ hello_interval:
+ description: Interval between hello packets.
+ type: int
+ retransmit_interval:
+ description: Interval between retransmitting lost link state advertisements.
+ type: int
+ transmit_delay:
+ description: Link state transmit delay.
+ type: int
+ log_adjacency_changes:
+ description: Log changes in adjacency state.
+ type: str
+ choices: ['detail']
+ max_metric:
+ description: OSPFv2 maximum/infinite-distance metric.
+ type: dict
+ suboptions:
+ router_lsa:
+ description: Advertise own Router-LSA with infinite distance (stub router).
+ type: dict
+ suboptions:
+ administrative:
+ description: Administratively apply, for an indefinite period.
+ type: bool
+ on_shutdown:
+ description: Time to advertise self as stub-router.
+ type: int
+ on_startup:
+ description: Time to advertise self as stub-router
+ type: int
+ auto_cost:
+ description: Calculate OSPFv2 interface cost according to bandwidth.
+ type: dict
+ suboptions:
+ reference_bandwidth:
+ description: Reference bandwidth cost in Mbits/sec.
+ type: int
+ default_information:
+ description: Control distribution of default information.
+ type: dict
+ suboptions:
+ originate:
+ description: Distribute a default route.
+ type: dict
+ suboptions:
+ always:
+ description: Always advertise default route.
+ type: bool
+ metric:
+ description: OSPFv2 default metric.
+ type: int
+ metric_type:
+ description: OSPFv2 Metric types for default routes.
+ type: int
+ route_map:
+ description: Route map references.
+ type: str
+ default_metric:
+ description: Metric of redistributed routes
+ type: int
+ distance:
+ description: Administrative distance.
+ type: dict
+ suboptions:
+ global:
+ description: Global OSPFv2 administrative distance.
+ type: int
+ ospf:
+ description: OSPFv2 administrative distance.
+ type: dict
+ suboptions:
+ external:
+ description: Distance for external routes.
+ type: int
+ inter_area:
+ description: Distance for inter-area routes.
+ type: int
+ intra_area:
+ description: Distance for intra-area routes.
+ type: int
+ mpls_te:
+ description: MultiProtocol Label Switching-Traffic Engineering (MPLS-TE) parameters.
+ type: dict
+ suboptions:
+ enabled:
+ description: Enable MPLS-TE functionality.
+ type: bool
+ router_address:
+ description: Stable IP address of the advertising router.
+ type: str
+
+ neighbor:
+ description: Neighbor IP address.
+ type: list
+ elements: dict
+ suboptions:
+ neighbor_id:
+ description: Identity (number/IP address) of neighbor.
+ type: str
+ poll_interval:
+ description: Seconds between dead neighbor polling interval.
+ type: int
+ priority:
+ description: Neighbor priority.
+ type: int
+ parameters:
+ descriptions: OSPFv2 specific parameters.
+ type: dict
+ suboptions:
+ abr_type:
+ description: OSPFv2 ABR Type.
+ type: str
+ choices: ['cisco', 'ibm', 'shortcut', 'standard']
+ opaque_lsa:
+ description: Enable the Opaque-LSA capability (rfc2370).
+ type: bool
+ rfc1583_compatibility:
+ description: Enable rfc1583 criteria for handling AS external routes.
+ type: bool
+ router_id:
+ description: Override the default router identifier.
+ type: str
+ passive_interface:
+ description: Suppress routing updates on an interface.
+ type: list
+ passive_interface_exclude:
+ description: Interface to exclude when using passive-interface default.
+ type: list
+ redistribute:
+ description: Redistribute information from another routing protocol.
+ type: list
+ elements: dict
+ suboptions:
+ route_type:
+ description: Route type to redistribute.
+ type: str
+ choices: ['bgp', 'connected', 'kernel', 'rip', 'static']
+ metric:
+ description: Metric for redistribution routes.
+ type: int
+ metric_type:
+ description: OSPFv2 Metric types.
+ type: int
+ route_map:
+ description: Route map references.
+ type: str
+ route_map:
+ description: Filter routes installed in local route map.
+ type: list
+ timers:
+ description: Adjust routing timers.
+ type: dict
+ suboptions:
+ refresh:
+ description: Adjust refresh parameters.
+ type: dict
+ suboptions:
+ timers:
+ description: refresh timer.
+ type: int
+ throttle:
+ description: Throttling adaptive timers.
+ type: dict
+ suboptions:
+ spf:
+ description: OSPFv2 SPF timers.
+ type: dict
+ suboptions:
+ delay:
+ description: Delay (msec) from first change received till SPF calculation.
+ type: int
+ initial_holdtime:
+ description: Initial hold time(msec) between consecutive SPF calculations.
+ type: int
+ max_holdtime:
+ description: maximum hold time (sec).
+ type: int
+ running_config:
+ description:
+ - This option is used only with state I(parsed).
+ - The value of this option should be the output received from the VyOS device by executing
+ the command B(show configuration commands | grep ospf).
+ - The state I(parsed) reads the configuration from C(running_config) option and transforms
+ it into Ansible structured data as per the resource module's argspec and the value is then
+ returned in the I(parsed) key within the result.
+ type: str
+ state:
+ description:
+ - The state the configuration should be left in.
+ type: str
+ choices:
+ - merged
+ - replaced
+ - deleted
+ - parsed
+ - gathered
+ - rendered
+ default: merged
+"""
+EXAMPLES = """
+# Using merged
+#
+# Before state:
+# -------------
+#
+# vyos@vyos# run show configuration commands | grep ospf
+#
+#
+- name: Merge the provided configuration with the existing running configuration
+ vyos.vyos.vyos_ospfv2:
+ config:
+ log_adjacency_changes: 'detail'
+ max_metric:
+ router_lsa:
+ administrative: true
+ on_shutdown: 10
+ on_startup: 10
+ default_information:
+ originate:
+ always: true
+ metric: 10
+ metric_type: 2
+ route_map: 'ingress'
+ mpls_te:
+ enabled: true
+ router_address: '192.0.11.11'
+ auto_cost:
+ reference_bandwidth: 2
+ neighbor:
+ - neighbor_id: '192.0.11.12'
+ poll_interval: 10
+ priority: 2
+ redistribute:
+ - route_type: 'bgp'
+ metric: 10
+ metric_type: 2
+ passive_interface:
+ - 'eth1'
+ - 'eth2'
+ parameters:
+ router_id: '192.0.1.1'
+ opaque_lsa: true
+ rfc1583_compatibility: true
+ abr_type: 'cisco'
+ areas:
+ - area_id: '2'
+ area_type:
+ normal: true
+ authentication: "plaintext-password"
+ shortcut: 'enable'
+ - area_id: '3'
+ area_type:
+ nssa:
+ set: true
+ - area_id: '4'
+ area_type:
+ stub:
+ default_cost: 20
+ network:
+ - address: '192.0.2.0/24'
+ range:
+ - address: '192.0.3.0/24'
+ cost: 10
+ - address: '192.0.4.0/24'
+ cost: 12
+ state: merged
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+# before": {}
+#
+# "commands": [
+# "set protocols ospf mpls-te enable",
+# "set protocols ospf mpls-te router-address '192.0.11.11'",
+# "set protocols ospf redistribute bgp",
+# "set protocols ospf redistribute bgp metric-type 2",
+# "set protocols ospf redistribute bgp metric 10",
+# "set protocols ospf default-information originate metric-type 2",
+# "set protocols ospf default-information originate always",
+# "set protocols ospf default-information originate metric 10",
+# "set protocols ospf default-information originate route-map ingress",
+# "set protocols ospf auto-cost reference-bandwidth '2'",
+# "set protocols ospf parameters router-id '192.0.1.1'",
+# "set protocols ospf parameters opaque-lsa",
+# "set protocols ospf parameters abr-type 'cisco'",
+# "set protocols ospf parameters rfc1583-compatibility",
+# "set protocols ospf passive-interface eth1",
+# "set protocols ospf passive-interface eth2",
+# "set protocols ospf max-metric router-lsa on-shutdown 10",
+# "set protocols ospf max-metric router-lsa administrative",
+# "set protocols ospf max-metric router-lsa on-startup 10",
+# "set protocols ospf log-adjacency-changes 'detail'",
+# "set protocols ospf neighbor 192.0.11.12 priority 2",
+# "set protocols ospf neighbor 192.0.11.12 poll-interval 10",
+# "set protocols ospf neighbor 192.0.11.12",
+# "set protocols ospf area '2'",
+# "set protocols ospf area 2 authentication plaintext-password",
+# "set protocols ospf area 2 shortcut enable",
+# "set protocols ospf area 2 area-type normal",
+# "set protocols ospf area '3'",
+# "set protocols ospf area 3 area-type nssa",
+# "set protocols ospf area 4 range 192.0.3.0/24 cost 10",
+# "set protocols ospf area 4 range 192.0.3.0/24",
+# "set protocols ospf area 4 range 192.0.4.0/24 cost 12",
+# "set protocols ospf area 4 range 192.0.4.0/24",
+# "set protocols ospf area 4 area-type stub default-cost 20",
+# "set protocols ospf area '4'",
+# "set protocols ospf area 4 network 192.0.2.0/24"
+# ]
+#
+# "after": {
+# "areas": [
+# {
+# "area_id": "2",
+# "area_type": {
+# "normal": true
+# },
+# "authentication": "plaintext-password",
+# "shortcut": "enable"
+# },
+# {
+# "area_id": "3",
+# "area_type": {
+# "nssa": {
+# "set": true
+# }
+# }
+# },
+# {
+# "area_id": "4",
+# "area_type": {
+# "stub": {
+# "default_cost": 20,
+# "set": true
+# }
+# },
+# "network": [
+# {
+# "address": "192.0.2.0/24"
+# }
+# ],
+# "range": [
+# {
+# "address": "192.0.3.0/24",
+# "cost": 10
+# },
+# {
+# "address": "192.0.4.0/24",
+# "cost": 12
+# }
+# ]
+# }
+# ],
+# "auto_cost": {
+# "reference_bandwidth": 2
+# },
+# "default_information": {
+# "originate": {
+# "always": true,
+# "metric": 10,
+# "metric_type": 2,
+# "route_map": "ingress"
+# }
+# },
+# "log_adjacency_changes": "detail",
+# "max_metric": {
+# "router_lsa": {
+# "administrative": true,
+# "on_shutdown": 10,
+# "on_startup": 10
+# }
+# },
+# "mpls_te": {
+# "enabled": true,
+# "router_address": "192.0.11.11"
+# },
+# "neighbor": [
+# {
+# "neighbor_id": "192.0.11.12",
+# "poll_interval": 10,
+# "priority": 2
+# }
+# ],
+# "parameters": {
+# "abr_type": "cisco",
+# "opaque_lsa": true,
+# "rfc1583_compatibility": true,
+# "router_id": "192.0.1.1"
+# },
+# "passive_interface": [
+# "eth2",
+# "eth1"
+# ],
+# "redistribute": [
+# {
+# "metric": 10,
+# "metric_type": 2,
+# "route_type": "bgp"
+# }
+# ]
+# }
+#
+# After state:
+# -------------
+#
+# vyos@192# run show configuration commands | grep ospf
+# set protocols ospf area 2 area-type 'normal'
+# set protocols ospf area 2 authentication 'plaintext-password'
+# set protocols ospf area 2 shortcut 'enable'
+# set protocols ospf area 3 area-type 'nssa'
+# set protocols ospf area 4 area-type stub default-cost '20'
+# set protocols ospf area 4 network '192.0.2.0/24'
+# set protocols ospf area 4 range 192.0.3.0/24 cost '10'
+# set protocols ospf area 4 range 192.0.4.0/24 cost '12'
+# set protocols ospf auto-cost reference-bandwidth '2'
+# set protocols ospf default-information originate 'always'
+# set protocols ospf default-information originate metric '10'
+# set protocols ospf default-information originate metric-type '2'
+# set protocols ospf default-information originate route-map 'ingress'
+# set protocols ospf log-adjacency-changes 'detail'
+# set protocols ospf max-metric router-lsa 'administrative'
+# set protocols ospf max-metric router-lsa on-shutdown '10'
+# set protocols ospf max-metric router-lsa on-startup '10'
+# set protocols ospf mpls-te 'enable'
+# set protocols ospf mpls-te router-address '192.0.11.11'
+# set protocols ospf neighbor 192.0.11.12 poll-interval '10'
+# set protocols ospf neighbor 192.0.11.12 priority '2'
+# set protocols ospf parameters abr-type 'cisco'
+# set protocols ospf parameters 'opaque-lsa'
+# set protocols ospf parameters 'rfc1583-compatibility'
+# set protocols ospf parameters router-id '192.0.1.1'
+# set protocols ospf passive-interface 'eth1'
+# set protocols ospf passive-interface 'eth2'
+# set protocols ospf redistribute bgp metric '10'
+# set protocols ospf redistribute bgp metric-type '2'
+
+
+# Using merged
+#
+# Before state:
+# -------------
+#
+# vyos@vyos# run show configuration commands | grep ospf
+#
+#
+- name: Merge the provided configuration to update existing running configuration
+ vyos.vyos.vyos_ospfv2:
+ config:
+ areas:
+ - area_id: '2'
+ area_type:
+ normal: true
+ authentication: "plaintext-password"
+ shortcut: 'enable'
+ - area_id: '3'
+ area_type:
+ nssa:
+ set: false
+ - area_id: '4'
+ area_type:
+ stub:
+ default_cost: 20
+ network:
+ - address: '192.0.2.0/24'
+ - address: '192.0.22.0/24'
+ - address: '192.0.32.0/24'
+ state: merged
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+# "before": {
+# "areas": [
+# {
+# "area_id": "2",
+# "area_type": {
+# "normal": true
+# },
+# "authentication": "plaintext-password",
+# "shortcut": "enable"
+# },
+# {
+# "area_id": "3",
+# "area_type": {
+# "nssa": {
+# "set": true
+# }
+# }
+# },
+# {
+# "area_id": "4",
+# "area_type": {
+# "stub": {
+# "default_cost": 20,
+# "set": true
+# }
+# },
+# "network": [
+# {
+# "address": "192.0.2.0/24"
+# }
+# ],
+# "range": [
+# {
+# "address": "192.0.3.0/24",
+# "cost": 10
+# },
+# {
+# "address": "192.0.4.0/24",
+# "cost": 12
+# }
+# ]
+# }
+# ],
+# "auto_cost": {
+# "reference_bandwidth": 2
+# },
+# "default_information": {
+# "originate": {
+# "always": true,
+# "metric": 10,
+# "metric_type": 2,
+# "route_map": "ingress"
+# }
+# },
+# "log_adjacency_changes": "detail",
+# "max_metric": {
+# "router_lsa": {
+# "administrative": true,
+# "on_shutdown": 10,
+# "on_startup": 10
+# }
+# },
+# "mpls_te": {
+# "enabled": true,
+# "router_address": "192.0.11.11"
+# },
+# "neighbor": [
+# {
+# "neighbor_id": "192.0.11.12",
+# "poll_interval": 10,
+# "priority": 2
+# }
+# ],
+# "parameters": {
+# "abr_type": "cisco",
+# "opaque_lsa": true,
+# "rfc1583_compatibility": true,
+# "router_id": "192.0.1.1"
+# },
+# "passive_interface": [
+# "eth2",
+# "eth1"
+# ],
+# "redistribute": [
+# {
+# "metric": 10,
+# "metric_type": 2,
+# "route_type": "bgp"
+# }
+# ]
+# }
+#
+# "commands": [
+# "delete protocols ospf area 4 area-type stub",
+# "set protocols ospf area 4 network 192.0.22.0/24"
+# "set protocols ospf area 4 network 192.0.32.0/24"
+# ]
+#
+# "after": {
+# "areas": [
+# {
+# "area_id": "2",
+# "area_type": {
+# "normal": true
+# },
+# "authentication": "plaintext-password",
+# "shortcut": "enable"
+# },
+# {
+# "area_id": "3",
+# "area_type": {
+# "nssa": {
+# "set": true
+# }
+# }
+# },
+# {
+# "area_id": "4",
+# },
+# "network": [
+# {
+# "address": "192.0.2.0/24"
+# },
+# {
+# "address": "192.0.22.0/24"
+# },
+# {
+# "address": "192.0.32.0/24"
+# }
+# ],
+# "range": [
+# {
+# "address": "192.0.3.0/24",
+# "cost": 10
+# },
+# {
+# "address": "192.0.4.0/24",
+# "cost": 12
+# }
+# ]
+# }
+# ],
+# "auto_cost": {
+# "reference_bandwidth": 2
+# },
+# "default_information": {
+# "originate": {
+# "always": true,
+# "metric": 10,
+# "metric_type": 2,
+# "route_map": "ingress"
+# }
+# },
+# "log_adjacency_changes": "detail",
+# "max_metric": {
+# "router_lsa": {
+# "administrative": true,
+# "on_shutdown": 10,
+# "on_startup": 10
+# }
+# },
+# "mpls_te": {
+# "enabled": true,
+# "router_address": "192.0.11.11"
+# },
+# "neighbor": [
+# {
+# "neighbor_id": "192.0.11.12",
+# "poll_interval": 10,
+# "priority": 2
+# }
+# ],
+# "parameters": {
+# "abr_type": "cisco",
+# "opaque_lsa": true,
+# "rfc1583_compatibility": true,
+# "router_id": "192.0.1.1"
+# },
+# "passive_interface": [
+# "eth2",
+# "eth1"
+# ],
+# "redistribute": [
+# {
+# "metric": 10,
+# "metric_type": 2,
+# "route_type": "bgp"
+# }
+# ]
+# }
+#
+# After state:
+# -------------
+#
+# vyos@192# run show configuration commands | grep ospf
+# set protocols ospf area 2 area-type 'normal'
+# set protocols ospf area 2 authentication 'plaintext-password'
+# set protocols ospf area 2 shortcut 'enable'
+# set protocols ospf area 3 area-type 'nssa'
+# set protocols ospf area 4 network '192.0.2.0/24'
+# set protocols ospf area 4 network '192.0.22.0/24'
+# set protocols ospf area 4 network '192.0.32.0/24'
+# set protocols ospf area 4 range 192.0.3.0/24 cost '10'
+# set protocols ospf area 4 range 192.0.4.0/24 cost '12'
+# set protocols ospf auto-cost reference-bandwidth '2'
+# set protocols ospf default-information originate 'always'
+# set protocols ospf default-information originate metric '10'
+# set protocols ospf default-information originate metric-type '2'
+# set protocols ospf default-information originate route-map 'ingress'
+# set protocols ospf log-adjacency-changes 'detail'
+# set protocols ospf max-metric router-lsa 'administrative'
+# set protocols ospf max-metric router-lsa on-shutdown '10'
+# set protocols ospf max-metric router-lsa on-startup '10'
+# set protocols ospf mpls-te 'enable'
+# set protocols ospf mpls-te router-address '192.0.11.11'
+# set protocols ospf neighbor 192.0.11.12 poll-interval '10'
+# set protocols ospf neighbor 192.0.11.12 priority '2'
+# set protocols ospf parameters abr-type 'cisco'
+# set protocols ospf parameters 'opaque-lsa'
+# set protocols ospf parameters 'rfc1583-compatibility'
+# set protocols ospf parameters router-id '192.0.1.1'
+# set protocols ospf passive-interface 'eth1'
+# set protocols ospf passive-interface 'eth2'
+# set protocols ospf redistribute bgp metric '10'
+# set protocols ospf redistribute bgp metric-type '2'
+
+
+# Using replaced
+#
+# Before state:
+# -------------
+#
+# vyos@192# run show configuration commands | grep ospf
+# set protocols ospf area 2 area-type 'normal'
+# set protocols ospf area 2 authentication 'plaintext-password'
+# set protocols ospf area 2 shortcut 'enable'
+# set protocols ospf area 3 area-type 'nssa'
+# set protocols ospf area 4 area-type stub default-cost '20'
+# set protocols ospf area 4 network '192.0.2.0/24'
+# set protocols ospf area 4 range 192.0.3.0/24 cost '10'
+# set protocols ospf area 4 range 192.0.4.0/24 cost '12'
+# set protocols ospf auto-cost reference-bandwidth '2'
+# set protocols ospf default-information originate 'always'
+# set protocols ospf default-information originate metric '10'
+# set protocols ospf default-information originate metric-type '2'
+# set protocols ospf default-information originate route-map 'ingress'
+# set protocols ospf log-adjacency-changes 'detail'
+# set protocols ospf max-metric router-lsa 'administrative'
+# set protocols ospf max-metric router-lsa on-shutdown '10'
+# set protocols ospf max-metric router-lsa on-startup '10'
+# set protocols ospf mpls-te 'enable'
+# set protocols ospf mpls-te router-address '192.0.11.11'
+# set protocols ospf neighbor 192.0.11.12 poll-interval '10'
+# set protocols ospf neighbor 192.0.11.12 priority '2'
+# set protocols ospf parameters abr-type 'cisco'
+# set protocols ospf parameters 'opaque-lsa'
+# set protocols ospf parameters 'rfc1583-compatibility'
+# set protocols ospf parameters router-id '192.0.1.1'
+# set protocols ospf passive-interface 'eth1'
+# set protocols ospf passive-interface 'eth2'
+# set protocols ospf redistribute bgp metric '10'
+# set protocols ospf redistribute bgp metric-type '2'
+#
+- name: Replace ospfv2 routes attributes configuration.
+ vyos.vyos.vyos_ospfv2:
+ config:
+ log_adjacency_changes: 'detail'
+ max_metric:
+ router_lsa:
+ administrative: true
+ on_shutdown: 10
+ on_startup: 10
+ default_information:
+ originate:
+ always: true
+ metric: 10
+ metric_type: 2
+ route_map: 'ingress'
+ mpls_te:
+ enabled: true
+ router_address: '192.0.22.22'
+ auto_cost:
+ reference_bandwidth: 2
+ neighbor:
+ - neighbor_id: '192.0.11.12'
+ poll_interval: 10
+ priority: 2
+ redistribute:
+ - route_type: 'bgp'
+ metric: 10
+ metric_type: 2
+ passive_interface:
+ - 'eth1'
+ parameters:
+ router_id: '192.0.1.1'
+ opaque_lsa: true
+ rfc1583_compatibility: true
+ abr_type: 'cisco'
+ areas:
+ - area_id: '2'
+ area_type:
+ normal: true
+ authentication: "plaintext-password"
+ shortcut: 'enable'
+ - area_id: '4'
+ area_type:
+ stub:
+ default_cost: 20
+ network:
+ - address: '192.0.2.0/24'
+ - address: '192.0.12.0/24'
+ - address: '192.0.22.0/24'
+ - address: '192.0.32.0/24'
+ range:
+ - address: '192.0.42.0/24'
+ cost: 10
+ state: replaced
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+# "before": {
+# "areas": [
+# {
+# "area_id": "2",
+# "area_type": {
+# "normal": true
+# },
+# "authentication": "plaintext-password",
+# "shortcut": "enable"
+# },
+# {
+# "area_id": "3",
+# "area_type": {
+# "nssa": {
+# "set": true
+# }
+# }
+# },
+# {
+# "area_id": "4",
+# "area_type": {
+# "stub": {
+# "default_cost": 20,
+# "set": true
+# }
+# },
+# "network": [
+# {
+# "address": "192.0.2.0/24"
+# }
+# ],
+# "range": [
+# {
+# "address": "192.0.3.0/24",
+# "cost": 10
+# },
+# {
+# "address": "192.0.4.0/24",
+# "cost": 12
+# }
+# ]
+# }
+# ],
+# "auto_cost": {
+# "reference_bandwidth": 2
+# },
+# "default_information": {
+# "originate": {
+# "always": true,
+# "metric": 10,
+# "metric_type": 2,
+# "route_map": "ingress"
+# }
+# },
+# "log_adjacency_changes": "detail",
+# "max_metric": {
+# "router_lsa": {
+# "administrative": true,
+# "on_shutdown": 10,
+# "on_startup": 10
+# }
+# },
+# "mpls_te": {
+# "enabled": true,
+# "router_address": "192.0.11.11"
+# },
+# "neighbor": [
+# {
+# "neighbor_id": "192.0.11.12",
+# "poll_interval": 10,
+# "priority": 2
+# }
+# ],
+# "parameters": {
+# "abr_type": "cisco",
+# "opaque_lsa": true,
+# "rfc1583_compatibility": true,
+# "router_id": "192.0.1.1"
+# },
+# "passive_interface": [
+# "eth2",
+# "eth1"
+# ],
+# "redistribute": [
+# {
+# "metric": 10,
+# "metric_type": 2,
+# "route_type": "bgp"
+# }
+# ]
+# }
+#
+# "commands": [
+# "delete protocols ospf passive-interface eth2",
+# "delete protocols ospf area 3",
+# "delete protocols ospf area 4 range 192.0.3.0/24 cost",
+# "delete protocols ospf area 4 range 192.0.3.0/24",
+# "delete protocols ospf area 4 range 192.0.4.0/24 cost",
+# "delete protocols ospf area 4 range 192.0.4.0/24",
+# "set protocols ospf mpls-te router-address '192.0.22.22'",
+# "set protocols ospf area 4 range 192.0.42.0/24 cost 10",
+# "set protocols ospf area 4 range 192.0.42.0/24",
+# "set protocols ospf area 4 network 192.0.12.0/24",
+# "set protocols ospf area 4 network 192.0.22.0/24",
+# "set protocols ospf area 4 network 192.0.32.0/24"
+# ]
+#
+# "after": {
+# "areas": [
+# {
+# "area_id": "2",
+# "area_type": {
+# "normal": true
+# },
+# "authentication": "plaintext-password",
+# "shortcut": "enable"
+# },
+# {
+# "area_id": "4",
+# "area_type": {
+# "stub": {
+# "default_cost": 20,
+# "set": true
+# }
+# },
+# "network": [
+# {
+# "address": "192.0.12.0/24"
+# },
+# {
+# "address": "192.0.2.0/24"
+# },
+# {
+# "address": "192.0.22.0/24"
+# },
+# {
+# "address": "192.0.32.0/24"
+# }
+# ],
+# "range": [
+# {
+# "address": "192.0.42.0/24",
+# "cost": 10
+# }
+# ]
+# }
+# ],
+# "auto_cost": {
+# "reference_bandwidth": 2
+# },
+# "default_information": {
+# "originate": {
+# "always": true,
+# "metric": 10,
+# "metric_type": 2,
+# "route_map": "ingress"
+# }
+# },
+# "log_adjacency_changes": "detail",
+# "max_metric": {
+# "router_lsa": {
+# "administrative": true,
+# "on_shutdown": 10,
+# "on_startup": 10
+# }
+# },
+# "mpls_te": {
+# "enabled": true,
+# "router_address": "192.0.22.22"
+# },
+# "neighbor": [
+# {
+# "neighbor_id": "192.0.11.12",
+# "poll_interval": 10,
+# "priority": 2
+# }
+# ],
+# "parameters": {
+# "abr_type": "cisco",
+# "opaque_lsa": true,
+# "rfc1583_compatibility": true,
+# "router_id": "192.0.1.1"
+# },
+# "passive_interface": [
+# "eth1"
+# ],
+# "redistribute": [
+# {
+# "metric": 10,
+# "metric_type": 2,
+# "route_type": "bgp"
+# }
+# ]
+# }
+#
+# After state:
+# -------------
+#
+# vyos@192# run show configuration commands | grep ospf
+# set protocols ospf area 2 area-type 'normal'
+# set protocols ospf area 2 authentication 'plaintext-password'
+# set protocols ospf area 2 shortcut 'enable'
+# set protocols ospf area 4 area-type stub default-cost '20'
+# set protocols ospf area 4 network '192.0.2.0/24'
+# set protocols ospf area 4 network '192.0.12.0/24'
+# set protocols ospf area 4 network '192.0.22.0/24'
+# set protocols ospf area 4 network '192.0.32.0/24'
+# set protocols ospf area 4 range 192.0.42.0/24 cost '10'
+# set protocols ospf auto-cost reference-bandwidth '2'
+# set protocols ospf default-information originate 'always'
+# set protocols ospf default-information originate metric '10'
+# set protocols ospf default-information originate metric-type '2'
+# set protocols ospf default-information originate route-map 'ingress'
+# set protocols ospf log-adjacency-changes 'detail'
+# set protocols ospf max-metric router-lsa 'administrative'
+# set protocols ospf max-metric router-lsa on-shutdown '10'
+# set protocols ospf max-metric router-lsa on-startup '10'
+# set protocols ospf mpls-te 'enable'
+# set protocols ospf mpls-te router-address '192.0.22.22'
+# set protocols ospf neighbor 192.0.11.12 poll-interval '10'
+# set protocols ospf neighbor 192.0.11.12 priority '2'
+# set protocols ospf parameters abr-type 'cisco'
+# set protocols ospf parameters 'opaque-lsa'
+# set protocols ospf parameters 'rfc1583-compatibility'
+# set protocols ospf parameters router-id '192.0.1.1'
+# set protocols ospf passive-interface 'eth1'
+# set protocols ospf redistribute bgp metric '10'
+# set protocols ospf redistribute bgp metric-type '2'
+
+
+# Using rendered
+#
+#
+- name: Render the commands for provided configuration
+ vyos.vyos.vyos_ospfv2:
+ config:
+ log_adjacency_changes: 'detail'
+ max_metric:
+ router_lsa:
+ administrative: true
+ on_shutdown: 10
+ on_startup: 10
+ default_information:
+ originate:
+ always: true
+ metric: 10
+ metric_type: 2
+ route_map: 'ingress'
+ mpls_te:
+ enabled: true
+ router_address: '192.0.11.11'
+ auto_cost:
+ reference_bandwidth: 2
+ neighbor:
+ - neighbor_id: '192.0.11.12'
+ poll_interval: 10
+ priority: 2
+ redistribute:
+ - route_type: 'bgp'
+ metric: 10
+ metric_type: 2
+ passive_interface:
+ - 'eth1'
+ - 'eth2'
+ parameters:
+ router_id: '192.0.1.1'
+ opaque_lsa: true
+ rfc1583_compatibility: true
+ abr_type: 'cisco'
+ areas:
+ - area_id: '2'
+ area_type:
+ normal: true
+ authentication: "plaintext-password"
+ shortcut: 'enable'
+ - area_id: '3'
+ area_type:
+ nssa:
+ set: true
+ - area_id: '4'
+ area_type:
+ stub:
+ default_cost: 20
+ network:
+ - address: '192.0.2.0/24'
+ range:
+ - address: '192.0.3.0/24'
+ cost: 10
+ - address: '192.0.4.0/24'
+ cost: 12
+ state: rendered
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+#
+# "rendered": [
+# [
+# "set protocols ospf mpls-te enable",
+# "set protocols ospf mpls-te router-address '192.0.11.11'",
+# "set protocols ospf redistribute bgp",
+# "set protocols ospf redistribute bgp metric-type 2",
+# "set protocols ospf redistribute bgp metric 10",
+# "set protocols ospf default-information originate metric-type 2",
+# "set protocols ospf default-information originate always",
+# "set protocols ospf default-information originate metric 10",
+# "set protocols ospf default-information originate route-map ingress",
+# "set protocols ospf auto-cost reference-bandwidth '2'",
+# "set protocols ospf parameters router-id '192.0.1.1'",
+# "set protocols ospf parameters opaque-lsa",
+# "set protocols ospf parameters abr-type 'cisco'",
+# "set protocols ospf parameters rfc1583-compatibility",
+# "set protocols ospf passive-interface eth1",
+# "set protocols ospf passive-interface eth2",
+# "set protocols ospf max-metric router-lsa on-shutdown 10",
+# "set protocols ospf max-metric router-lsa administrative",
+# "set protocols ospf max-metric router-lsa on-startup 10",
+# "set protocols ospf log-adjacency-changes 'detail'",
+# "set protocols ospf neighbor 192.0.11.12 priority 2",
+# "set protocols ospf neighbor 192.0.11.12 poll-interval 10",
+# "set protocols ospf neighbor 192.0.11.12",
+# "set protocols ospf area '2'",
+# "set protocols ospf area 2 authentication plaintext-password",
+# "set protocols ospf area 2 shortcut enable",
+# "set protocols ospf area 2 area-type normal",
+# "set protocols ospf area '3'",
+# "set protocols ospf area 3 area-type nssa",
+# "set protocols ospf area 4 range 192.0.3.0/24 cost 10",
+# "set protocols ospf area 4 range 192.0.3.0/24",
+# "set protocols ospf area 4 range 192.0.4.0/24 cost 12",
+# "set protocols ospf area 4 range 192.0.4.0/24",
+# "set protocols ospf area 4 area-type stub default-cost 20",
+# "set protocols ospf area '4'",
+# "set protocols ospf area 4 network 192.0.2.0/24"
+# ]
+
+
+# Using parsed
+#
+#
+- name: Parse the commands for provided structured configuration
+ vyos.vyos.vyos_ospfv2:
+ running_config:
+ "set protocols ospf area 2 area-type 'normal'
+ set protocols ospf area 2 authentication 'plaintext-password'
+ set protocols ospf area 2 shortcut 'enable'
+ set protocols ospf area 3 area-type 'nssa'
+ set protocols ospf area 4 area-type stub default-cost '20'
+ set protocols ospf area 4 network '192.0.2.0/24'
+ set protocols ospf area 4 range 192.0.3.0/24 cost '10'
+ set protocols ospf area 4 range 192.0.4.0/24 cost '12'
+ set protocols ospf auto-cost reference-bandwidth '2'
+ set protocols ospf default-information originate 'always'
+ set protocols ospf default-information originate metric '10'
+ set protocols ospf default-information originate metric-type '2'
+ set protocols ospf default-information originate route-map 'ingress'
+ set protocols ospf log-adjacency-changes 'detail'
+ set protocols ospf max-metric router-lsa 'administrative'
+ set protocols ospf max-metric router-lsa on-shutdown '10'
+ set protocols ospf max-metric router-lsa on-startup '10'
+ set protocols ospf mpls-te 'enable'
+ set protocols ospf mpls-te router-address '192.0.11.11'
+ set protocols ospf neighbor 192.0.11.12 poll-interval '10'
+ set protocols ospf neighbor 192.0.11.12 priority '2'
+ set protocols ospf parameters abr-type 'cisco'
+ set protocols ospf parameters 'opaque-lsa'
+ set protocols ospf parameters 'rfc1583-compatibility'
+ set protocols ospf parameters router-id '192.0.1.1'
+ set protocols ospf passive-interface 'eth1'
+ set protocols ospf passive-interface 'eth2'
+ set protocols ospf redistribute bgp metric '10'
+ set protocols ospf redistribute bgp metric-type '2'"
+ state: parsed
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+#
+# "parsed": {
+# "areas": [
+# {
+# "area_id": "2",
+# "area_type": {
+# "normal": true
+# },
+# "authentication": "plaintext-password",
+# "shortcut": "enable"
+# },
+# {
+# "area_id": "3",
+# "area_type": {
+# "nssa": {
+# "set": true
+# }
+# }
+# },
+# {
+# "area_id": "4",
+# "area_type": {
+# "stub": {
+# "default_cost": 20,
+# "set": true
+# }
+# },
+# "network": [
+# {
+# "address": "192.0.2.0/24"
+# }
+# ],
+# "range": [
+# {
+# "address": "192.0.3.0/24",
+# "cost": 10
+# },
+# {
+# "address": "192.0.4.0/24",
+# "cost": 12
+# }
+# ]
+# }
+# ],
+# "auto_cost": {
+# "reference_bandwidth": 2
+# },
+# "default_information": {
+# "originate": {
+# "always": true,
+# "metric": 10,
+# "metric_type": 2,
+# "route_map": "ingress"
+# }
+# },
+# "log_adjacency_changes": "detail",
+# "max_metric": {
+# "router_lsa": {
+# "administrative": true,
+# "on_shutdown": 10,
+# "on_startup": 10
+# }
+# },
+# "mpls_te": {
+# "enabled": true,
+# "router_address": "192.0.11.11"
+# },
+# "neighbor": [
+# {
+# "neighbor_id": "192.0.11.12",
+# "poll_interval": 10,
+# "priority": 2
+# }
+# ],
+# "parameters": {
+# "abr_type": "cisco",
+# "opaque_lsa": true,
+# "rfc1583_compatibility": true,
+# "router_id": "192.0.1.1"
+# },
+# "passive_interface": [
+# "eth2",
+# "eth1"
+# ],
+# "redistribute": [
+# {
+# "metric": 10,
+# "metric_type": 2,
+# "route_type": "bgp"
+# }
+# ]
+# }
+# }
+
+
+# Using gathered
+#
+# Before state:
+# -------------
+#
+# vyos@192# run show configuration commands | grep ospf
+# set protocols ospf area 2 area-type 'normal'
+# set protocols ospf area 2 authentication 'plaintext-password'
+# set protocols ospf area 2 shortcut 'enable'
+# set protocols ospf area 3 area-type 'nssa'
+# set protocols ospf area 4 area-type stub default-cost '20'
+# set protocols ospf area 4 network '192.0.2.0/24'
+# set protocols ospf area 4 range 192.0.3.0/24 cost '10'
+# set protocols ospf area 4 range 192.0.4.0/24 cost '12'
+# set protocols ospf auto-cost reference-bandwidth '2'
+# set protocols ospf default-information originate 'always'
+# set protocols ospf default-information originate metric '10'
+# set protocols ospf default-information originate metric-type '2'
+# set protocols ospf default-information originate route-map 'ingress'
+# set protocols ospf log-adjacency-changes 'detail'
+# set protocols ospf max-metric router-lsa 'administrative'
+# set protocols ospf max-metric router-lsa on-shutdown '10'
+# set protocols ospf max-metric router-lsa on-startup '10'
+# set protocols ospf mpls-te 'enable'
+# set protocols ospf mpls-te router-address '192.0.11.11'
+# set protocols ospf neighbor 192.0.11.12 poll-interval '10'
+# set protocols ospf neighbor 192.0.11.12 priority '2'
+# set protocols ospf parameters abr-type 'cisco'
+# set protocols ospf parameters 'opaque-lsa'
+# set protocols ospf parameters 'rfc1583-compatibility'
+# set protocols ospf parameters router-id '192.0.1.1'
+# set protocols ospf passive-interface 'eth1'
+# set protocols ospf passive-interface 'eth2'
+# set protocols ospf redistribute bgp metric '10'
+# set protocols ospf redistribute bgp metric-type '2'
+#
+- name: Gather ospfv2 routes config with provided configurations
+ vyos.vyos.vyos_ospfv2:
+ config:
+ state: gathered
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+# "gathered": {
+# "areas": [
+# {
+# "area_id": "2",
+# "area_type": {
+# "normal": true
+# },
+# "authentication": "plaintext-password",
+# "shortcut": "enable"
+# },
+# {
+# "area_id": "3",
+# "area_type": {
+# "nssa": {
+# "set": true
+# }
+# }
+# },
+# {
+# "area_id": "4",
+# "area_type": {
+# "stub": {
+# "default_cost": 20,
+# "set": true
+# }
+# },
+# "network": [
+# {
+# "address": "192.0.2.0/24"
+# }
+# ],
+# "range": [
+# {
+# "address": "192.0.3.0/24",
+# "cost": 10
+# },
+# {
+# "address": "192.0.4.0/24",
+# "cost": 12
+# }
+# ]
+# }
+# ],
+# "auto_cost": {
+# "reference_bandwidth": 2
+# },
+# "default_information": {
+# "originate": {
+# "always": true,
+# "metric": 10,
+# "metric_type": 2,
+# "route_map": "ingress"
+# }
+# },
+# "log_adjacency_changes": "detail",
+# "max_metric": {
+# "router_lsa": {
+# "administrative": true,
+# "on_shutdown": 10,
+# "on_startup": 10
+# }
+# },
+# "mpls_te": {
+# "enabled": true,
+# "router_address": "192.0.11.11"
+# },
+# "neighbor": [
+# {
+# "neighbor_id": "192.0.11.12",
+# "poll_interval": 10,
+# "priority": 2
+# }
+# ],
+# "parameters": {
+# "abr_type": "cisco",
+# "opaque_lsa": true,
+# "rfc1583_compatibility": true,
+# "router_id": "192.0.1.1"
+# },
+# "passive_interface": [
+# "eth2",
+# "eth1"
+# ],
+# "redistribute": [
+# {
+# "metric": 10,
+# "metric_type": 2,
+# "route_type": "bgp"
+# }
+# ]
+# }
+#
+# After state:
+# -------------
+#
+# vyos@192# run show configuration commands | grep ospf
+# set protocols ospf area 2 area-type 'normal'
+# set protocols ospf area 2 authentication 'plaintext-password'
+# set protocols ospf area 2 shortcut 'enable'
+# set protocols ospf area 3 area-type 'nssa'
+# set protocols ospf area 4 area-type stub default-cost '20'
+# set protocols ospf area 4 network '192.0.2.0/24'
+# set protocols ospf area 4 range 192.0.3.0/24 cost '10'
+# set protocols ospf area 4 range 192.0.4.0/24 cost '12'
+# set protocols ospf auto-cost reference-bandwidth '2'
+# set protocols ospf default-information originate 'always'
+# set protocols ospf default-information originate metric '10'
+# set protocols ospf default-information originate metric-type '2'
+# set protocols ospf default-information originate route-map 'ingress'
+# set protocols ospf log-adjacency-changes 'detail'
+# set protocols ospf max-metric router-lsa 'administrative'
+# set protocols ospf max-metric router-lsa on-shutdown '10'
+# set protocols ospf max-metric router-lsa on-startup '10'
+# set protocols ospf mpls-te 'enable'
+# set protocols ospf mpls-te router-address '192.0.11.11'
+# set protocols ospf neighbor 192.0.11.12 poll-interval '10'
+# set protocols ospf neighbor 192.0.11.12 priority '2'
+# set protocols ospf parameters abr-type 'cisco'
+# set protocols ospf parameters 'opaque-lsa'
+# set protocols ospf parameters 'rfc1583-compatibility'
+# set protocols ospf parameters router-id '192.0.1.1'
+# set protocols ospf passive-interface 'eth1'
+# set protocols ospf passive-interface 'eth2'
+# set protocols ospf redistribute bgp metric '10'
+# set protocols ospf redistribute bgp metric-type '2'
+
+
+# Using deleted
+#
+# Before state
+# -------------
+#
+# vyos@192# run show configuration commands | grep ospf
+# set protocols ospf area 2 area-type 'normal'
+# set protocols ospf area 2 authentication 'plaintext-password'
+# set protocols ospf area 2 shortcut 'enable'
+# set protocols ospf area 3 area-type 'nssa'
+# set protocols ospf area 4 area-type stub default-cost '20'
+# set protocols ospf area 4 network '192.0.2.0/24'
+# set protocols ospf area 4 range 192.0.3.0/24 cost '10'
+# set protocols ospf area 4 range 192.0.4.0/24 cost '12'
+# set protocols ospf auto-cost reference-bandwidth '2'
+# set protocols ospf default-information originate 'always'
+# set protocols ospf default-information originate metric '10'
+# set protocols ospf default-information originate metric-type '2'
+# set protocols ospf default-information originate route-map 'ingress'
+# set protocols ospf log-adjacency-changes 'detail'
+# set protocols ospf max-metric router-lsa 'administrative'
+# set protocols ospf max-metric router-lsa on-shutdown '10'
+# set protocols ospf max-metric router-lsa on-startup '10'
+# set protocols ospf mpls-te 'enable'
+# set protocols ospf mpls-te router-address '192.0.11.11'
+# set protocols ospf neighbor 192.0.11.12 poll-interval '10'
+# set protocols ospf neighbor 192.0.11.12 priority '2'
+# set protocols ospf parameters abr-type 'cisco'
+# set protocols ospf parameters 'opaque-lsa'
+# set protocols ospf parameters 'rfc1583-compatibility'
+# set protocols ospf parameters router-id '192.0.1.1'
+# set protocols ospf passive-interface 'eth1'
+# set protocols ospf passive-interface 'eth2'
+# set protocols ospf redistribute bgp metric '10'
+# set protocols ospf redistribute bgp metric-type '2'
+#
+- name: Delete attributes of ospfv2 routes.
+ vyos.vyos.vyos_ospfv2:
+ config:
+ state: deleted
+#
+#
+# ------------------------
+# Module Execution Results
+# ------------------------
+#
+# "before": {
+# "areas": [
+# {
+# "area_id": "2",
+# "area_type": {
+# "normal": true
+# },
+# "authentication": "plaintext-password",
+# "shortcut": "enable"
+# },
+# {
+# "area_id": "3",
+# "area_type": {
+# "nssa": {
+# "set": true
+# }
+# }
+# },
+# {
+# "area_id": "4",
+# "area_type": {
+# "stub": {
+# "default_cost": 20,
+# "set": true
+# }
+# },
+# "network": [
+# {
+# "address": "192.0.2.0/24"
+# }
+# ],
+# "range": [
+# {
+# "address": "192.0.3.0/24",
+# "cost": 10
+# },
+# {
+# "address": "192.0.4.0/24",
+# "cost": 12
+# }
+# ]
+# }
+# ],
+# "auto_cost": {
+# "reference_bandwidth": 2
+# },
+# "default_information": {
+# "originate": {
+# "always": true,
+# "metric": 10,
+# "metric_type": 2,
+# "route_map": "ingress"
+# }
+# },
+# "log_adjacency_changes": "detail",
+# "max_metric": {
+# "router_lsa": {
+# "administrative": true,
+# "on_shutdown": 10,
+# "on_startup": 10
+# }
+# },
+# "mpls_te": {
+# "enabled": true,
+# "router_address": "192.0.11.11"
+# },
+# "neighbor": [
+# {
+# "neighbor_id": "192.0.11.12",
+# "poll_interval": 10,
+# "priority": 2
+# }
+# ],
+# "parameters": {
+# "abr_type": "cisco",
+# "opaque_lsa": true,
+# "rfc1583_compatibility": true,
+# "router_id": "192.0.1.1"
+# },
+# "passive_interface": [
+# "eth2",
+# "eth1"
+# ],
+# "redistribute": [
+# {
+# "metric": 10,
+# "metric_type": 2,
+# "route_type": "bgp"
+# }
+# ]
+# }
+# "commands": [
+# "delete protocols ospf"
+# ]
+#
+# "after": {}
+# After state
+# ------------
+# vyos@192# run show configuration commands | grep ospf
+#
+
+"""
+RETURN = """
+before:
+ description: The configuration prior to the model invocation.
+ returned: always
+ type: dict
+ 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: dict
+ 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 ospf parameters router-id 192.0.1.1',
+ 'set protocols ospf passive-interface 'eth1']
+"""
+
+
+from ansible.module_utils.basic import AnsibleModule
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ospfv2.ospfv2 import (
+ Ospfv2Args,
+)
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.ospfv2.ospfv2 import (
+ Ospfv2,
+)
+
+
+def main():
+ """
+ Main entry point for module execution
+
+ :returns: the result form module invocation
+ """
+ required_if = [
+ ("state", "merged", ("config",)),
+ ("state", "replaced", ("config",)),
+ ("state", "rendered", ("config",)),
+ ("state", "parsed", ("running_config",)),
+ ]
+ mutually_exclusive = [("config", "running_config")]
+ module = AnsibleModule(
+ argument_spec=Ospfv2Args.argument_spec,
+ required_if=required_if,
+ supports_check_mode=True,
+ mutually_exclusive=mutually_exclusive,
+ )
+
+ result = Ospfv2(module).execute_module()
+ module.exit_json(**result)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/plugins/modules/vyos_ospfv3.py b/plugins/modules/vyos_ospfv3.py
new file mode 100644
index 00000000..e2d3ff7f
--- /dev/null
+++ b/plugins/modules/vyos_ospfv3.py
@@ -0,0 +1,667 @@
+#!/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_ospfv3
+"""
+
+from __future__ import absolute_import, division, print_function
+
+__metaclass__ = type
+
+ANSIBLE_METADATA = {"metadata_version": "1.1", "supported_by": "Ansible"}
+
+DOCUMENTATION = """
+---
+module: vyos_ospfv3
+version_added: 2.10
+short_description: OSPFV3 resource module.
+description: This resource module configures and manages attributes of OSPFv3 routes on VyOS network devices.
+version_added: "1.0.0"
+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 OSPFv3 route configuration.
+ type: dict
+ suboptions:
+ areas:
+ description: OSPFv3 area.
+ type: list
+ elements: dict
+ suboptions:
+ area_id:
+ description: OSPFv3 Area name/identity.
+ type: str
+ export_list:
+ description: Name of export-list.
+ type: str
+ import_list:
+ description: Name of import-list.
+ type: str
+ range:
+ description: Summarize routes matching prefix (border routers only).
+ type: list
+ elements: dict
+ suboptions:
+ address:
+ description: border router IPv4 address.
+ type: str
+ advertise:
+ description: Advertise this range.
+ type: bool
+ not_advertise:
+ description: Don't advertise this range.
+ type: bool
+ parameters:
+ descriptions: OSPFv3 specific parameters.
+ type: dict
+ suboptions:
+ router_id:
+ description: Override the default router identifier.
+ type: str
+ redistribute:
+ description: Redistribute information from another routing protocol.
+ type: list
+ elements: dict
+ suboptions:
+ route_type:
+ description: Route type to redistribute.
+ type: str
+ choices: ['bgp', 'connected', 'kernel', 'ripng', 'static']
+ route_map:
+ description: Route map references.
+ type: str
+ running_config:
+ description:
+ - This option is used only with state I(parsed).
+ - The value of this option should be the output received from the VyOS device by executing
+ the command B(show configuration commands | grep ospfv3).
+ - The state I(parsed) reads the configuration from C(running_config) option and transforms
+ it into Ansible structured data as per the resource module's argspec and the value is then
+ returned in the I(parsed) key within the result.
+ type: str
+ state:
+ description:
+ - The state the configuration should be left in.
+ type: str
+ choices:
+ - merged
+ - replaced
+ - deleted
+ - parsed
+ - gathered
+ - rendered
+ default: merged
+"""
+EXAMPLES = """
+# Using merged
+#
+# Before state:
+# -------------
+#
+# vyos@vyos# run show configuration commands | grep ospfv3
+#
+#
+- name: Merge the provided configuration with the exisiting running configuration
+ vyos.vyos.vyos_ospfv3:
+ config:
+ redistribute:
+ - route_type: 'bgp'
+ parameters:
+ router_id: '192.0.2.10'
+ areas:
+ - area_id: '2'
+ export_list: 'export1'
+ import_list: 'import1'
+ range:
+ - address: '2001:db10::/32'
+ - address: '2001:db20::/32'
+ - address: '2001:db30::/32'
+ - area_id: '3'
+ range:
+ - address: '2001:db40::/32'
+ state: merged
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+# before": {}
+#
+# "commands": [
+# "set protocols ospfv3 redistribute bgp",
+# "set protocols ospfv3 parameters router-id '192.0.2.10'",
+# "set protocols ospfv3 area 2 range 2001:db10::/32",
+# "set protocols ospfv3 area 2 range 2001:db20::/32",
+# "set protocols ospfv3 area 2 range 2001:db30::/32",
+# "set protocols ospfv3 area '2'",
+# "set protocols ospfv3 area 2 export-list export1",
+# "set protocols ospfv3 area 2 import-list import1",
+# "set protocols ospfv3 area '3'",
+# "set protocols ospfv3 area 3 range 2001:db40::/32"
+# ]
+#
+# "after": {
+# "areas": [
+# {
+# "area_id": "2",
+# "export_list": "export1",
+# "import_list": "import1",
+# "range": [
+# {
+# "address": "2001:db10::/32"
+# },
+# {
+# "address": "2001:db20::/32"
+# },
+# {
+# "address": "2001:db30::/32"
+# }
+# ]
+# },
+# {
+# "area_id": "3",
+# "range": [
+# {
+# "address": "2001:db40::/32"
+# }
+# ]
+# }
+# ],
+# "parameters": {
+# "router_id": "192.0.2.10"
+# },
+# "redistribute": [
+# {
+# "route_type": "bgp"
+# }
+# ]
+# }
+#
+# After state:
+# -------------
+#
+# vyos@192# run show configuration commands | grep ospfv3
+# set protocols ospfv3 area 2 export-list 'export1'
+# set protocols ospfv3 area 2 import-list 'import1'
+# set protocols ospfv3 area 2 range '2001:db10::/32'
+# set protocols ospfv3 area 2 range '2001:db20::/32'
+# set protocols ospfv3 area 2 range '2001:db30::/32'
+# set protocols ospfv3 area 3 range '2001:db40::/32'
+# set protocols ospfv3 parameters router-id '192.0.2.10'
+# set protocols ospfv3 redistribute 'bgp'
+
+
+# Using replaced
+#
+# Before state:
+# -------------
+#
+# vyos@192# run show configuration commands | grep ospfv3
+# set protocols ospfv3 area 2 export-list 'export1'
+# set protocols ospfv3 area 2 import-list 'import1'
+# set protocols ospfv3 area 2 range '2001:db10::/32'
+# set protocols ospfv3 area 2 range '2001:db20::/32'
+# set protocols ospfv3 area 2 range '2001:db30::/32'
+# set protocols ospfv3 area 3 range '2001:db40::/32'
+# set protocols ospfv3 parameters router-id '192.0.2.10'
+# set protocols ospfv3 redistribute 'bgp'
+#
+- name: Replace ospfv3 routes attributes configuration.
+ vyos.vyos.vyos_ospfv3:
+ config:
+ redistribute:
+ - route_type: 'bgp'
+ parameters:
+ router_id: '192.0.2.10'
+ areas:
+ - area_id: '2'
+ export_list: 'export1'
+ import_list: 'import1'
+ range:
+ - address: '2001:db10::/32'
+ - address: '2001:db30::/32'
+ - address: '2001:db50::/32'
+ - area_id: '4'
+ range:
+ - address: '2001:db60::/32'
+ state: replaced
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+# "before": {
+# "areas": [
+# {
+# "area_id": "2",
+# "export_list": "export1",
+# "import_list": "import1",
+# "range": [
+# {
+# "address": "2001:db10::/32"
+# },
+# {
+# "address": "2001:db20::/32"
+# },
+# {
+# "address": "2001:db30::/32"
+# }
+# ]
+# },
+# {
+# "area_id": "3",
+# "range": [
+# {
+# "address": "2001:db40::/32"
+# }
+# ]
+# }
+# ],
+# "parameters": {
+# "router_id": "192.0.2.10"
+# },
+# "redistribute": [
+# {
+# "route_type": "bgp"
+# }
+# ]
+# }
+#
+# "commands": [
+# "delete protocols ospfv3 area 2 range 2001:db20::/32",
+# "delete protocols ospfv3 area 3",
+# "set protocols ospfv3 area 2 range 2001:db50::/32",
+# "set protocols ospfv3 area '4'",
+# "set protocols ospfv3 area 4 range 2001:db60::/32"
+# ]
+#
+# "after": {
+# "areas": [
+# {
+# "area_id": "2",
+# "export_list": "export1",
+# "import_list": "import1",
+# "range": [
+# {
+# "address": "2001:db10::/32"
+# },
+# {
+# "address": "2001:db30::/32"
+# },
+# {
+# "address": "2001:db50::/32"
+# }
+# ]
+# },
+# {
+# "area_id": "4",
+# "range": [
+# {
+# "address": "2001:db60::/32"
+# }
+# ]
+# }
+# ],
+# "parameters": {
+# "router_id": "192.0.2.10"
+# },
+# "redistribute": [
+# {
+# "route_type": "bgp"
+# }
+# ]
+# }
+#
+# After state:
+# -------------
+#
+# vyos@192# run show configuration commands | grep ospfv3
+# set protocols ospfv3 area 2 export-list 'export1'
+# set protocols ospfv3 area 2 import-list 'import1'
+# set protocols ospfv3 area 2 range '2001:db10::/32'
+# set protocols ospfv3 area 2 range '2001:db30::/32'
+# set protocols ospfv3 area 2 range '2001:db50::/32'
+# set protocols ospfv3 area 4 range '2001:db60::/32'
+# set protocols ospfv3 parameters router-id '192.0.2.10'
+# set protocols ospfv3 redistribute 'bgp'
+
+
+# Using rendered
+#
+#
+- name: Render the commands for provided configuration
+ vyos.vyos.vyos_ospfv3:
+ config:
+ redistribute:
+ - route_type: 'bgp'
+ parameters:
+ router_id: '192.0.2.10'
+ areas:
+ - area_id: '2'
+ export_list: 'export1'
+ import_list: 'import1'
+ range:
+ - address: '2001:db10::/32'
+ - address: '2001:db20::/32'
+ - address: '2001:db30::/32'
+ - area_id: '3'
+ range:
+ - address: '2001:db40::/32'
+ state: rendered
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+#
+# "rendered": [
+# [
+# "set protocols ospfv3 redistribute bgp",
+# "set protocols ospfv3 parameters router-id '192.0.2.10'",
+# "set protocols ospfv3 area 2 range 2001:db10::/32",
+# "set protocols ospfv3 area 2 range 2001:db20::/32",
+# "set protocols ospfv3 area 2 range 2001:db30::/32",
+# "set protocols ospfv3 area '2'",
+# "set protocols ospfv3 area 2 export-list export1",
+# "set protocols ospfv3 area 2 import-list import1",
+# "set protocols ospfv3 area '3'",
+# "set protocols ospfv3 area 3 range 2001:db40::/32"
+# ]
+
+
+# Using parsed
+#
+#
+- name: Parse the commands to provide structured configuration.
+ vyos.vyos.vyos_ospfv3:
+ running_config:
+ "set protocols ospfv3 area 2 export-list 'export1'
+set protocols ospfv3 area 2 import-list 'import1'
+set protocols ospfv3 area 2 range '2001:db10::/32'
+set protocols ospfv3 area 2 range '2001:db20::/32'
+set protocols ospfv3 area 2 range '2001:db30::/32'
+set protocols ospfv3 area 3 range '2001:db40::/32'
+set protocols ospfv3 parameters router-id '192.0.2.10'
+set protocols ospfv3 redistribute 'bgp'"
+ state: parsed
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+#
+# "parsed": {
+# "areas": [
+# {
+# "area_id": "2",
+# "export_list": "export1",
+# "import_list": "import1",
+# "range": [
+# {
+# "address": "2001:db10::/32"
+# },
+# {
+# "address": "2001:db20::/32"
+# },
+# {
+# "address": "2001:db30::/32"
+# }
+# ]
+# },
+# {
+# "area_id": "3",
+# "range": [
+# {
+# "address": "2001:db40::/32"
+# }
+# ]
+# }
+# ],
+# "parameters": {
+# "router_id": "192.0.2.10"
+# },
+# "redistribute": [
+# {
+# "route_type": "bgp"
+# }
+# ]
+# }
+
+
+# Using gathered
+#
+# Before state:
+# -------------
+#
+# vyos@192# run show configuration commands | grep ospfv3
+# set protocols ospfv3 area 2 export-list 'export1'
+# set protocols ospfv3 area 2 import-list 'import1'
+# set protocols ospfv3 area 2 range '2001:db10::/32'
+# set protocols ospfv3 area 2 range '2001:db20::/32'
+# set protocols ospfv3 area 2 range '2001:db30::/32'
+# set protocols ospfv3 area 3 range '2001:db40::/32'
+# set protocols ospfv3 parameters router-id '192.0.2.10'
+# set protocols ospfv3 redistribute 'bgp'
+#
+- name: Gather ospfv3 routes config with provided configurations
+ vyos.vyos.vyos_ospfv3:
+ config:
+ state: gathered
+#
+#
+# -------------------------
+# Module Execution Result
+# -------------------------
+#
+# "gathered": {
+# "areas": [
+# {
+# "area_id": "2",
+# "export_list": "export1",
+# "import_list": "import1",
+# "range": [
+# {
+# "address": "2001:db10::/32"
+# },
+# {
+# "address": "2001:db20::/32"
+# },
+# {
+# "address": "2001:db30::/32"
+# }
+# ]
+# },
+# {
+# "area_id": "3",
+# "range": [
+# {
+# "address": "2001:db40::/32"
+# }
+# ]
+# }
+# ],
+# "parameters": {
+# "router_id": "192.0.2.10"
+# },
+# "redistribute": [
+# {
+# "route_type": "bgp"
+# }
+# ]
+# }
+#
+# After state:
+# -------------
+#
+# vyos@192# run show configuration commands | grep ospfv3
+# set protocols ospfv3 area 2 export-list 'export1'
+# set protocols ospfv3 area 2 import-list 'import1'
+# set protocols ospfv3 area 2 range '2001:db10::/32'
+# set protocols ospfv3 area 2 range '2001:db20::/32'
+# set protocols ospfv3 area 2 range '2001:db30::/32'
+# set protocols ospfv3 area 3 range '2001:db40::/32'
+# set protocols ospfv3 parameters router-id '192.0.2.10'
+# set protocols ospfv3 redistribute 'bgp'
+
+
+# Using deleted
+#
+# Before state
+# -------------
+#
+# vyos@192# run show configuration commands | grep ospfv3
+# set protocols ospfv3 area 2 export-list 'export1'
+# set protocols ospfv3 area 2 import-list 'import1'
+# set protocols ospfv3 area 2 range '2001:db10::/32'
+# set protocols ospfv3 area 2 range '2001:db20::/32'
+# set protocols ospfv3 area 2 range '2001:db30::/32'
+# set protocols ospfv3 area 3 range '2001:db40::/32'
+# set protocols ospfv3 parameters router-id '192.0.2.10'
+# set protocols ospfv3 redistribute 'bgp'
+#
+- name: Delete attributes of ospfv3 routes.
+ vyos.vyos.vyos_ospfv3:
+ config:
+ state: deleted
+#
+#
+# ------------------------
+# Module Execution Results
+# ------------------------
+#
+# "before": {
+# "areas": [
+# {
+# "area_id": "2",
+# "export_list": "export1",
+# "import_list": "import1",
+# "range": [
+# {
+# "address": "2001:db10::/32"
+# },
+# {
+# "address": "2001:db20::/32"
+# },
+# {
+# "address": "2001:db30::/32"
+# }
+# ]
+# },
+# {
+# "area_id": "3",
+# "range": [
+# {
+# "address": "2001:db40::/32"
+# }
+# ]
+# }
+# ],
+# "parameters": {
+# "router_id": "192.0.2.10"
+# },
+# "redistribute": [
+# {
+# "route_type": "bgp"
+# }
+# ]
+# }
+# "commands": [
+# "delete protocols ospfv3"
+# ]
+#
+# "after": {}
+# After state
+# ------------
+# vyos@192# run show configuration commands | grep ospfv3
+
+
+"""
+RETURN = """
+before:
+ description: The configuration prior to the model invocation.
+ returned: always
+ type: dict
+ 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: dict
+ 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 ospf parameters router-id 192.0.1.1',
+ 'set protocols ospfv3 area 2 range '2001:db10::/32']
+"""
+
+
+from ansible.module_utils.basic import AnsibleModule
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ospfv3.ospfv3 import (
+ Ospfv3Args,
+)
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.ospfv3.ospfv3 import (
+ Ospfv3,
+)
+
+
+def main():
+ """
+ Main entry point for module execution
+
+ :returns: the result form module invocation
+ """
+ required_if = [
+ ("state", "merged", ("config",)),
+ ("state", "replaced", ("config",)),
+ ("state", "rendered", ("config",)),
+ ("state", "parsed", ("running_config",)),
+ ]
+ mutually_exclusive = [("config", "running_config")]
+ module = AnsibleModule(
+ argument_spec=Ospfv3Args.argument_spec,
+ required_if=required_if,
+ supports_check_mode=True,
+ mutually_exclusive=mutually_exclusive,
+ )
+
+ result = Ospfv3(module).execute_module()
+ module.exit_json(**result)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/plugins/modules/vyos_static_routes.py b/plugins/modules/vyos_static_routes.py
index 6e502037..e71114a1 100644
--- a/plugins/modules/vyos_static_routes.py
+++ b/plugins/modules/vyos_static_routes.py
@@ -30,16 +30,13 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-ANSIBLE_METADATA = {
- "metadata_version": "1.1",
- "status": ["preview"],
- "supported_by": "network",
-}
+ANSIBLE_METADATA = {"metadata_version": "1.1", "supported_by": "Ansible"}
DOCUMENTATION = """module: vyos_static_routes
-short_description: Manages attributes of static routes on VyOS network devices.
+short_description: Static routes resource module
description: This module manages attributes of static routes on VyOS network devices.
notes:
+version_added: "1.0.0"
- 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:
@@ -114,13 +111,12 @@ options:
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')
+ - This option is used only with state I(parsed).
+ - The value of this option should be the output received from the VyOS device by executing
+ the command B(show configuration commands | grep static route).
+ - The state I(parsed) reads the configuration from C(running_config) option and transforms
+ it into Ansible structured data as per the resource module's argspec and the value is then
+ returned in the I(parsed) key within the result.
type: str
state:
description:
@@ -145,7 +141,7 @@ EXAMPLES = """
# vyos@vyos:~$ show configuration commands | grep static
#
- name: Merge the provided configuration with the exisiting running configuration
- vyos_static_routes:
+ vyos.vyos.vyos_static_routes:
config:
- address_families:
- afi: 'ipv4'
@@ -259,7 +255,7 @@ EXAMPLES = """
# 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:
+ vyos.vyos.vyos_static_routes:
config:
- address_families:
- afi: 'ipv4'
@@ -435,7 +431,7 @@ EXAMPLES = """
# 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:
+ vyos.vyos.vyos_static_routes:
config:
- address_families:
- afi: 'ipv4'
@@ -531,92 +527,6 @@ EXAMPLES = """
# 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
@@ -631,7 +541,7 @@ EXAMPLES = """
# 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:
+ vyos.vyos.vyos_static_routes:
config:
- address_families:
- afi: 'ipv4'
@@ -713,7 +623,7 @@ EXAMPLES = """
# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'
#
- name: Delete all the static routes.
- vyos_static_routes:
+ vyos.vyos.vyos_static_routes:
config:
state: deleted
#
@@ -778,141 +688,11 @@ EXAMPLES = """
# 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:
+ vyos.vyos.vyos_static_routes:
config:
- address_families:
- afi: 'ipv4'
@@ -955,8 +735,8 @@ EXAMPLES = """
# Using parsed
#
#
-- name: Render the commands for provided configuration
- vyos_static_routes:
+- name: Parse the provided running configuration
+ vyos.vyos.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'
@@ -1026,7 +806,7 @@ EXAMPLES = """
# 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:
+ vyos.vyos.vyos_static_routes:
config:
state: gathered
#
@@ -1137,6 +917,7 @@ def main():
required_if = [
("state", "merged", ("config",)),
("state", "replaced", ("config",)),
+ ("state", "rendered", ("config",)),
("state", "overridden", ("config",)),
("state", "parsed", ("running_config",)),
]
diff --git a/plugins/modules/vyos_vlan.py b/plugins/modules/vyos_vlan.py
index a0aafb57..04f5856a 100644
--- a/plugins/modules/vyos_vlan.py
+++ b/plugins/modules/vyos_vlan.py
@@ -240,8 +240,8 @@ def map_config_to_obj(module):
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())
+ for line in lines:
+ splitted_line = re.split(r"\s{2,}", line.strip())
obj = {}
eth = splitted_line[0].strip("'")
diff --git a/tests/integration/targets/vyos_firewall_rules/tests/cli/deleted.yaml b/tests/integration/targets/vyos_firewall_rules/tests/cli/deleted.yaml
index 7acfe653..67bfd3c1 100644
--- a/tests/integration/targets/vyos_firewall_rules/tests/cli/deleted.yaml
+++ b/tests/integration/targets/vyos_firewall_rules/tests/cli/deleted.yaml
@@ -11,15 +11,11 @@
register: result
vyos.vyos.vyos_firewall_rules: &id001
config:
-
- afi: ipv6
rule_sets:
-
- name: UPLINK
-
- afi: ipv4
rule_sets:
-
- name: INBOUND
state: deleted
diff --git a/tests/integration/targets/vyos_firewall_rules/tests/cli/gathered.yaml b/tests/integration/targets/vyos_firewall_rules/tests/cli/gathered.yaml
index cdc8e51c..59c81aad 100644
--- a/tests/integration/targets/vyos_firewall_rules/tests/cli/gathered.yaml
+++ b/tests/integration/targets/vyos_firewall_rules/tests/cli/gathered.yaml
@@ -9,9 +9,9 @@
- block:
- - name: Merge the provided configuration with the exisiting running configuration
+ - name: Gather the provided configuration with the exisiting running configuration
register: result
- vyos.vyos.vyos_firewall_rules: &id001
+ vyos.vyos.vyos_firewall_rules:
config:
state: gathered
@@ -21,14 +21,6 @@
- "{{ populate | symmetric_difference(result['gathered']) |length == 0\
\ }}"
- - name: Gather the existing running configuration (IDEMPOTENT)
- register: result
- vyos.vyos.vyos_firewall_rules: *id001
-
- - name: Assert that the previous task was idempotent
- assert:
- that:
- - result['changed'] == false
always:
- include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_firewall_rules/tests/cli/parsed.yaml b/tests/integration/targets/vyos_firewall_rules/tests/cli/parsed.yaml
index a793ac58..bc955249 100644
--- a/tests/integration/targets/vyos_firewall_rules/tests/cli/parsed.yaml
+++ b/tests/integration/targets/vyos_firewall_rules/tests/cli/parsed.yaml
@@ -3,39 +3,14 @@
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
- register: firewall_rules_facts
- vyos.vyos.vyos_facts:
- gather_subset:
- - default
- gather_network_resources:
- - firewall_rules
-
- - name: Provide the running configuration for parsing (config to be parsed)
- register: result
- vyos.vyos.vyos_firewall_rules: &id001
- running_config: "{{ lookup('file', '_parsed_config.cfg') }}"
- state: parsed
-
- - 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)
- register: result
- vyos.vyos.vyos_firewall_rules: *id001
-
- - name: Assert that the previous task was idempotent
- assert:
- that:
- - result['changed'] == false
- always:
-
- - include_tasks: _remove_config.yaml
+- name: Parse externally provided Firewall rules config to agnostic model
+ register: result
+ vyos.vyos.vyos_firewall_rules:
+ running_config: "{{ lookup('file', '_parsed_config.cfg') }}"
+ state: parsed
+
+- name: Assert that config was correctly parsed
+ assert:
+ that:
+ - "{{ parsed['after'] | symmetric_difference(result['parsed']) |length ==\
+ \ 0 }}"
diff --git a/tests/integration/targets/vyos_firewall_rules/tests/cli/rendered.yaml b/tests/integration/targets/vyos_firewall_rules/tests/cli/rendered.yaml
index f000998e..6670fd7b 100644
--- a/tests/integration/targets/vyos_firewall_rules/tests/cli/rendered.yaml
+++ b/tests/integration/targets/vyos_firewall_rules/tests/cli/rendered.yaml
@@ -5,13 +5,11 @@
- include_tasks: _remove_config.yaml
-- include_tasks: _populate.yaml
-
- block:
- name: Structure provided configuration into device specific commands
register: result
- vyos.vyos.vyos_firewall_rules: &id001
+ vyos.vyos.vyos_firewall_rules:
config:
- afi: ipv6
@@ -60,14 +58,5 @@
- "{{ rendered['commands'] | symmetric_difference(result['rendered'])\
\ |length == 0 }}"
- - name: Structure provided configuration into device specific commands (IDEMPOTENT)
- register: result
- vyos.vyos.vyos_firewall_rules: *id001
-
- - name: Assert that the previous task was idempotent
- assert:
- that:
- - result['changed'] == false
- always:
-
- - include_tasks: _remove_config.yaml
+- debug:
+ msg: END vyos_firewall_rules rendered integration tests on connection={{ ansible_connection }}
diff --git a/tests/integration/targets/vyos_firewall_rules/vars/main.yaml b/tests/integration/targets/vyos_firewall_rules/vars/main.yaml
index c15a101a..88323bae 100644
--- a/tests/integration/targets/vyos_firewall_rules/vars/main.yaml
+++ b/tests/integration/targets/vyos_firewall_rules/vars/main.yaml
@@ -196,42 +196,7 @@ overridden:
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
+parsed:
after:
- afi: ipv6
rule_sets:
@@ -239,6 +204,10 @@ deleted_r:
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
@@ -270,6 +239,39 @@ deleted_r:
new: false
invalid: false
related: true
+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: []
round_trip:
after:
- afi: ipv6
diff --git a/tests/integration/targets/vyos_interfaces/tests/cli/_parsed_config.cfg b/tests/integration/targets/vyos_interfaces/tests/cli/_parsed_config.cfg
new file mode 100644
index 00000000..e5c3fc78
--- /dev/null
+++ b/tests/integration/targets/vyos_interfaces/tests/cli/_parsed_config.cfg
@@ -0,0 +1,12 @@
+set interfaces ethernet eth1 description 'Configured by Ansible - Interface 1'
+set interfaces ethernet eth1 duplex 'auto'
+set interfaces ethernet eth1 hw-id '08:00:27:da:67:43'
+set interfaces ethernet eth1 mtu '1500'
+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 'disable'
+set interfaces ethernet eth2 hw-id '08:00:27:d8:70:b0'
+set interfaces ethernet eth2 mtu '600'
diff --git a/tests/integration/targets/vyos_interfaces/tests/cli/empty_config.yaml b/tests/integration/targets/vyos_interfaces/tests/cli/empty_config.yaml
index e1e154dc..652f1589 100644
--- a/tests/integration/targets/vyos_interfaces/tests/cli/empty_config.yaml
+++ b/tests/integration/targets/vyos_interfaces/tests/cli/empty_config.yaml
@@ -1,7 +1,7 @@
---
- debug:
- msg: START vyos_interfaces empty_config integration tests on connection={{ ansible_connection
- }}
+ msg: START vyos_interfaces empty_config integration tests on connection={{
+ ansible_connection }}
- name: Merged with empty config should give appropriate error message
register: result
@@ -35,3 +35,26 @@
- 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
+ register: result
+ ignore_errors: true
+ vyos.vyos.vyos_interfaces:
+ running_config:
+ state: parsed
+
+- 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
+ register: result
+ ignore_errors: true
+ vyos.vyos.vyos_interfaces:
+ config:
+ state: rendered
+
+- assert:
+ that:
+ - result.msg == 'value of config parameter must not be empty for state rendered'
diff --git a/tests/integration/targets/vyos_interfaces/tests/cli/gathered.yaml b/tests/integration/targets/vyos_interfaces/tests/cli/gathered.yaml
new file mode 100644
index 00000000..ac9892cb
--- /dev/null
+++ b/tests/integration/targets/vyos_interfaces/tests/cli/gathered.yaml
@@ -0,0 +1,26 @@
+---
+- debug:
+ msg: START vyos_interfaces gathered integration tests on connection={{ ansible_connection
+ }}
+
+- include_tasks: _remove_config.yaml
+
+- include_tasks: _populate.yaml
+
+- block:
+
+ - name: Gather the provided configuration with the exisiting running configuration
+ register: result
+ vyos.vyos.vyos_interfaces:
+ config:
+ state: gathered
+
+ - name: Assert that gathered dicts was correctly generated
+ assert:
+ that:
+ - "{{ populate | symmetric_difference(result['gathered']) |length == 0\
+ \ }}"
+
+ always:
+
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_interfaces/tests/cli/parsed.yaml b/tests/integration/targets/vyos_interfaces/tests/cli/parsed.yaml
new file mode 100644
index 00000000..a44fc2f3
--- /dev/null
+++ b/tests/integration/targets/vyos_interfaces/tests/cli/parsed.yaml
@@ -0,0 +1,16 @@
+---
+- debug:
+ msg: START vyos_interfaces parsed integration tests on connection={{ ansible_connection
+ }}
+
+- name: Parse externally provided interfaces config to agnostic model
+ register: result
+ vyos.vyos.vyos_interfaces:
+ running_config: "{{ lookup('file', '_parsed_config.cfg') }}"
+ state: parsed
+
+- name: Assert that config was correctly parsed
+ assert:
+ that:
+ - "{{ parsed['after'] | symmetric_difference(result['parsed']) |length ==\
+ \ 0 }}"
diff --git a/tests/integration/targets/vyos_interfaces/tests/cli/rendered.yaml b/tests/integration/targets/vyos_interfaces/tests/cli/rendered.yaml
new file mode 100644
index 00000000..5030d718
--- /dev/null
+++ b/tests/integration/targets/vyos_interfaces/tests/cli/rendered.yaml
@@ -0,0 +1,47 @@
+---
+- debug:
+ msg: START vyos_interfaces 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
+ register: result
+ vyos.vyos.vyos_interfaces:
+ config:
+ - 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
+ state: rendered
+
+ - name: Assert that correct set of commands were generated
+ assert:
+ that:
+ - "{{ rendered['commands'] | symmetric_difference(result['rendered'])\
+ \ |length == 0 }}"
+ always:
+
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_interfaces/vars/main.yaml b/tests/integration/targets/vyos_interfaces/vars/main.yaml
index b7300800..84a8bf05 100644
--- a/tests/integration/targets/vyos_interfaces/vars/main.yaml
+++ b/tests/integration/targets/vyos_interfaces/vars/main.yaml
@@ -104,6 +104,26 @@ replaced:
enabled: true
duplex: auto
speed: auto
+parsed:
+ after:
+ - 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
overridden:
commands:
- delete interfaces ethernet eth1 description
@@ -133,6 +153,23 @@ overridden:
vifs:
- vlan_id: 200
enabled: true
+rendered:
+ commands:
+ - set interfaces ethernet eth0 duplex 'auto'
+ - set interfaces ethernet eth0 speed 'auto'
+ - delete interfaces ethernet eth0 disable
+ - set interfaces ethernet eth1 duplex 'auto'
+ - delete interfaces ethernet eth1 disable
+ - set interfaces ethernet eth1 speed 'auto'
+ - set interfaces ethernet eth1 description 'Configured by Ansible - Interface 1'
+ - set interfaces ethernet eth1 mtu '1500'
+ - 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 disable
+ - set interfaces ethernet eth2 description 'Configured by Ansible - Interface 2 (ADMIN DOWN)'
+ - set interfaces ethernet eth2 mtu '600'
+
deleted:
commands:
- delete interfaces ethernet eth1 description
diff --git a/tests/integration/targets/vyos_l3_interfaces/tests/cli/_parsed_config.cfg b/tests/integration/targets/vyos_l3_interfaces/tests/cli/_parsed_config.cfg
new file mode 100644
index 00000000..ef070a72
--- /dev/null
+++ b/tests/integration/targets/vyos_l3_interfaces/tests/cli/_parsed_config.cfg
@@ -0,0 +1,9 @@
+set interfaces ethernet eth1 address '192.0.2.10/24'
+set interfaces ethernet eth1 address '2001:db8::10/32'
+set interfaces ethernet eth1 hw-id '08:00:27:da:67:43'
+set interfaces ethernet eth2 address '198.51.100.10/24'
+set interfaces ethernet eth2 hw-id '08:00:27:d8:70:b0'
+set interfaces ethernet eth2 vif 101 address '198.51.100.130/25'
+set interfaces ethernet eth2 vif 101 address '2001:db8::20/32'
+
+
diff --git a/tests/integration/targets/vyos_l3_interfaces/tests/cli/empty_config.yaml b/tests/integration/targets/vyos_l3_interfaces/tests/cli/empty_config.yaml
index 96d4cda9..9929dd7f 100644
--- a/tests/integration/targets/vyos_l3_interfaces/tests/cli/empty_config.yaml
+++ b/tests/integration/targets/vyos_l3_interfaces/tests/cli/empty_config.yaml
@@ -35,3 +35,26 @@
- 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
+ register: result
+ ignore_errors: true
+ vyos.vyos.vyos_l3_interfaces:
+ running_config:
+ state: parsed
+
+- 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
+ register: result
+ ignore_errors: true
+ vyos.vyos.vyos_l3_interfaces:
+ config:
+ state: rendered
+
+- assert:
+ that:
+ - result.msg == 'value of config parameter must not be empty for state rendered'
diff --git a/tests/integration/targets/vyos_l3_interfaces/tests/cli/gathered.yaml b/tests/integration/targets/vyos_l3_interfaces/tests/cli/gathered.yaml
new file mode 100644
index 00000000..625047bb
--- /dev/null
+++ b/tests/integration/targets/vyos_l3_interfaces/tests/cli/gathered.yaml
@@ -0,0 +1,34 @@
+---
+- debug:
+ msg: START vyos_l3_interfaces 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
+ register: result
+ vyos.vyos.vyos_l3_interfaces: &id001
+ config:
+ state: gathered
+
+ - name: Assert that gathered dicts was correctly generated
+ assert:
+ that:
+ - "{{ populate | symmetric_difference(result['gathered']) |length == 0\
+ \ }}"
+
+ - name: Gather the existing running configuration (IDEMPOTENT)
+ register: result
+ vyos.vyos.vyos_l3_interfaces: *id001
+
+ - name: Assert that the previous task was idempotent
+ assert:
+ that:
+ - result['changed'] == false
+ always:
+
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_l3_interfaces/tests/cli/parsed.yaml b/tests/integration/targets/vyos_l3_interfaces/tests/cli/parsed.yaml
new file mode 100644
index 00000000..d5ff2056
--- /dev/null
+++ b/tests/integration/targets/vyos_l3_interfaces/tests/cli/parsed.yaml
@@ -0,0 +1,16 @@
+---
+- debug:
+ msg: START vyos_l3_nterfaces parsed integration tests on connection={{ ansible_connection
+ }}
+
+- name: Parse externally provided interfaces config to agnostic model
+ register: result
+ vyos.vyos.vyos_l3_interfaces:
+ running_config: "{{ lookup('file', '_parsed_config.cfg') }}"
+ state: parsed
+
+- name: Assert that config was correctly parsed
+ assert:
+ that:
+ - "{{ parsed['after'] | symmetric_difference(result['parsed']) |length ==\
+ \ 0 }}"
diff --git a/tests/integration/targets/vyos_l3_interfaces/tests/cli/rendered.yaml b/tests/integration/targets/vyos_l3_interfaces/tests/cli/rendered.yaml
new file mode 100644
index 00000000..02a28655
--- /dev/null
+++ b/tests/integration/targets/vyos_l3_interfaces/tests/cli/rendered.yaml
@@ -0,0 +1,44 @@
+---
+- debug:
+ msg: START vyos_l3_interfaces 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
+ register: result
+ vyos.vyos.vyos_l3_interfaces: &id001
+ config:
+ - 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
+ state: rendered
+
+ - 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)
+ register: result
+ vyos.vyos.vyos_l3_interfaces: *id001
+
+ - name: Assert that the previous task was idempotent
+ assert:
+ that:
+ - result['changed'] == false
+ always:
+
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_l3_interfaces/vars/main.yaml b/tests/integration/targets/vyos_l3_interfaces/vars/main.yaml
index ee329d30..e9781e6a 100644
--- a/tests/integration/targets/vyos_l3_interfaces/vars/main.yaml
+++ b/tests/integration/targets/vyos_l3_interfaces/vars/main.yaml
@@ -79,6 +79,30 @@ overridden:
ipv4:
- address: 192.0.2.15/24
- name: eth2
+parsed:
+ after:
+ - 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
+rendered:
+ commands:
+ - set interfaces ethernet eth1 address '192.0.2.14/24'
+ - set interfaces ethernet eth2 address '192.0.2.11/24'
+ - set interfaces ethernet eth2 address '192.0.2.10/24'
+ - set interfaces ethernet eth2 address '2001:db8::10/32'
+ - set interfaces ethernet eth2 address '2001:db8::12/32'
+
deleted:
commands:
- delete interfaces ethernet eth1 address '192.0.2.14/24'
diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/cli/_parsed_config.cfg b/tests/integration/targets/vyos_lag_interfaces/tests/cli/_parsed_config.cfg
new file mode 100644
index 00000000..ea3bfce6
--- /dev/null
+++ b/tests/integration/targets/vyos_lag_interfaces/tests/cli/_parsed_config.cfg
@@ -0,0 +1,8 @@
+set interfaces bonding bond0 hash-policy 'layer2'
+set interfaces bonding bond0 mode 'active-backup'
+set interfaces bonding bond0 primary 'eth1'
+set interfaces bonding bond1 hash-policy 'layer2+3'
+set interfaces bonding bond1 mode 'active-backup'
+set interfaces bonding bond1 primary 'eth2'
+set interfaces ethernet eth1 bond-group 'bond0'
+set interfaces ethernet eth2 bond-group 'bond1' \ No newline at end of file
diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/cli/empty_config.yaml b/tests/integration/targets/vyos_lag_interfaces/tests/cli/empty_config.yaml
index 3894fb59..6e89eaed 100644
--- a/tests/integration/targets/vyos_lag_interfaces/tests/cli/empty_config.yaml
+++ b/tests/integration/targets/vyos_lag_interfaces/tests/cli/empty_config.yaml
@@ -35,3 +35,26 @@
- 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
+ register: result
+ ignore_errors: true
+ vyos.vyos.vyos_lag_interfaces:
+ running_config:
+ state: parsed
+
+- 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
+ register: result
+ ignore_errors: true
+ vyos.vyos.vyos_lag_interfaces:
+ config:
+ state: rendered
+
+- assert:
+ that:
+ - result.msg == 'value of config parameter must not be empty for state rendered'
diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/cli/gathered.yaml b/tests/integration/targets/vyos_lag_interfaces/tests/cli/gathered.yaml
new file mode 100644
index 00000000..aca168dd
--- /dev/null
+++ b/tests/integration/targets/vyos_lag_interfaces/tests/cli/gathered.yaml
@@ -0,0 +1,26 @@
+---
+- debug:
+ msg: START vyos_lag_interfaces gathered integration tests on connection={{ ansible_connection
+ }}
+
+- include_tasks: _remove_config.yaml
+
+- include_tasks: _populate.yaml
+
+- block:
+
+ - name: Gather the provided configuration with the exisiting running configuration
+ register: result
+ vyos.vyos.vyos_lag_interfaces: &id001
+ config:
+ state: gathered
+
+ - name: Assert that gathered dicts was correctly generated
+ assert:
+ that:
+ - "{{ populate | symmetric_difference(result['gathered']) |length == 0\
+ \ }}"
+
+ always:
+
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/cli/parsed.yaml b/tests/integration/targets/vyos_lag_interfaces/tests/cli/parsed.yaml
new file mode 100644
index 00000000..ed7bc612
--- /dev/null
+++ b/tests/integration/targets/vyos_lag_interfaces/tests/cli/parsed.yaml
@@ -0,0 +1,33 @@
+---
+- debug:
+ msg: START vyos_lag_interfaces parsed integration tests on connection={{ ansible_connection
+ }}
+
+- include_tasks: _remove_config.yaml
+
+- include_tasks: _populate.yaml
+
+- block:
+
+ - name: Gather lag_interfaces facts
+ register: lag_interfaces_facts
+ vyos.vyos.vyos_facts:
+ gather_subset:
+ - default
+ gather_network_resources:
+ - lag_interfaces
+
+ - name: Provide the running configuration for parsing (config to be parsed)
+ register: result
+ vyos.vyos.vyos_lag_interfaces:
+ running_config: "{{ lookup('file', '_parsed_config.cfg') }}"
+ state: parsed
+
+ - name: Assert that correct parsing done
+ assert:
+ that: "{{ ansible_facts['network_resources']['lag_interfaces'] | symmetric_difference(result['parsed'])\
+ \ |length == 0 }}"
+
+ always:
+
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/cli/rendered.yaml b/tests/integration/targets/vyos_lag_interfaces/tests/cli/rendered.yaml
new file mode 100644
index 00000000..e6d7928c
--- /dev/null
+++ b/tests/integration/targets/vyos_lag_interfaces/tests/cli/rendered.yaml
@@ -0,0 +1,38 @@
+---
+- debug:
+ msg: START vyos_lag_interfaces 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
+ register: result
+ vyos.vyos.vyos_lag_interfaces:
+ config:
+ - 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
+ state: rendered
+
+ - name: Assert that correct set of commands were generated
+ assert:
+ that:
+ - "{{ rendered['commands'] | symmetric_difference(result['rendered'])\
+ \ |length == 0 }}"
+
+ always:
+
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_lag_interfaces/vars/main.yaml b/tests/integration/targets/vyos_lag_interfaces/vars/main.yaml
index 57836936..9784fb97 100644
--- a/tests/integration/targets/vyos_lag_interfaces/vars/main.yaml
+++ b/tests/integration/targets/vyos_lag_interfaces/vars/main.yaml
@@ -83,6 +83,16 @@ deleted:
after:
- name: bond0
- name: bond1
+rendered:
+ commands:
+ - set interfaces bonding bond0 hash-policy 'layer2'
+ - set interfaces ethernet eth1 bond-group 'bond0'
+ - set interfaces bonding bond0 mode 'active-backup'
+ - set interfaces bonding bond0 primary 'eth1'
+ - set interfaces bonding bond1 hash-policy 'layer2+3'
+ - set interfaces ethernet eth2 bond-group 'bond1'
+ - set interfaces bonding bond1 mode 'active-backup'
+ - set interfaces bonding bond1 primary 'eth2'
round_trip:
after:
- name: bond0
diff --git a/tests/integration/targets/vyos_lldp_global/tests/cli/_parsed_config.cfg b/tests/integration/targets/vyos_lldp_global/tests/cli/_parsed_config.cfg
new file mode 100644
index 00000000..9c9f66c5
--- /dev/null
+++ b/tests/integration/targets/vyos_lldp_global/tests/cli/_parsed_config.cfg
@@ -0,0 +1,3 @@
+set service lldp legacy-protocols 'fdp'
+set service lldp legacy-protocols 'cdp'
+set service lldp management-address '192.0.2.17'
diff --git a/tests/integration/targets/vyos_lldp_global/tests/cli/empty_config.yaml b/tests/integration/targets/vyos_lldp_global/tests/cli/empty_config.yaml
index a197c454..0333fa41 100644
--- a/tests/integration/targets/vyos_lldp_global/tests/cli/empty_config.yaml
+++ b/tests/integration/targets/vyos_lldp_global/tests/cli/empty_config.yaml
@@ -24,3 +24,26 @@
- 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
+ register: result
+ ignore_errors: true
+ vyos.vyos.vyos_lldp_global:
+ running_config:
+ state: parsed
+
+- 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
+ register: result
+ ignore_errors: true
+ vyos.vyos.vyos_lldp_global:
+ config:
+ state: rendered
+
+- assert:
+ that:
+ - result.msg == 'value of config parameter must not be empty for state rendered'
diff --git a/tests/integration/targets/vyos_lldp_global/tests/cli/gathered.yaml b/tests/integration/targets/vyos_lldp_global/tests/cli/gathered.yaml
new file mode 100644
index 00000000..95e01de6
--- /dev/null
+++ b/tests/integration/targets/vyos_lldp_global/tests/cli/gathered.yaml
@@ -0,0 +1,25 @@
+---
+- debug:
+ msg: START vyos_lldp_global gathered integration tests on connection={{
+ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+
+- include_tasks: _populate.yaml
+
+- block:
+
+ - name: Gather the provided configuration with the exisiting running configuration
+ register: result
+ vyos.vyos.vyos_lldp_global:
+ config:
+ state: gathered
+
+ - name: Assert that gathered dicts was correctly generated
+ assert:
+ that:
+ - "{{ populate == result['gathered'] }}"
+
+ always:
+
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_lldp_global/tests/cli/parsed.yaml b/tests/integration/targets/vyos_lldp_global/tests/cli/parsed.yaml
new file mode 100644
index 00000000..b9c3abf0
--- /dev/null
+++ b/tests/integration/targets/vyos_lldp_global/tests/cli/parsed.yaml
@@ -0,0 +1,15 @@
+---
+- debug:
+ msg: START vyos_lldp_global parsed integration tests on connection={{ ansible_connection
+ }}
+
+- name: Parse externally provided LLDP global config to agnostic model
+ register: result
+ vyos.vyos.vyos_lldp_global:
+ running_config: "{{ lookup('file', '_parsed_config.cfg') }}"
+ state: parsed
+
+- name: Assert that config was correctly parsed
+ assert:
+ that:
+ - "{{ parsed['after'] == result['parsed'] }}"
diff --git a/tests/integration/targets/vyos_lldp_global/tests/cli/rendered.yaml b/tests/integration/targets/vyos_lldp_global/tests/cli/rendered.yaml
new file mode 100644
index 00000000..5e9f4c5a
--- /dev/null
+++ b/tests/integration/targets/vyos_lldp_global/tests/cli/rendered.yaml
@@ -0,0 +1,28 @@
+---
+- debug:
+ msg: START vyos_lldp_global rendered integration tests on connection={{
+ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+
+- block:
+
+ - name: Structure provided configuration into device specific commands
+ register: result
+ vyos.vyos.vyos_lldp_global:
+ config:
+ address: 192.0.2.17
+ enable: true
+ legacy_protocols:
+ - cdp
+ state: rendered
+
+ - name: Assert that correct set of commands were generated
+ assert:
+ that:
+ - "{{ rendered['commands'] | symmetric_difference(result['rendered'])\
+ \ |length == 0 }}"
+
+ always:
+
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_lldp_global/vars/main.yaml b/tests/integration/targets/vyos_lldp_global/vars/main.yaml
index 81e71bed..622b8e4d 100644
--- a/tests/integration/targets/vyos_lldp_global/vars/main.yaml
+++ b/tests/integration/targets/vyos_lldp_global/vars/main.yaml
@@ -31,6 +31,18 @@ replaced:
- cdp
- edp
- sonmp
+parsed:
+ after:
+ address: 192.0.2.17
+ enable: true
+ legacy_protocols:
+ - fdp
+ - cdp
+rendered:
+ commands:
+ - set service lldp legacy-protocols 'cdp'
+ - set service lldp
+ - set service lldp management-address '192.0.2.17'
deleted:
commands:
- delete service lldp management-address
diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_parsed_config.cfg b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_parsed_config.cfg
new file mode 100644
index 00000000..40c96c40
--- /dev/null
+++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_parsed_config.cfg
@@ -0,0 +1,6 @@
+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' \ No newline at end of file
diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/empty_config.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/empty_config.yaml
index a5ff0a8e..4ef40c9e 100644
--- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/empty_config.yaml
+++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/empty_config.yaml
@@ -35,3 +35,26 @@
- 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
+ register: result
+ ignore_errors: true
+ vyos.vyos.vyos_lldp_interfaces:
+ running_config:
+ state: parsed
+
+- 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
+ register: result
+ ignore_errors: true
+ vyos.vyos.vyos_lldp_interfaces:
+ config:
+ state: rendered
+
+- assert:
+ that:
+ - result.msg == 'value of config parameter must not be empty for state rendered'
diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/gathered.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/gathered.yaml
new file mode 100644
index 00000000..180b62f8
--- /dev/null
+++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/gathered.yaml
@@ -0,0 +1,25 @@
+---
+- debug:
+ msg: START vyos_lldp_interfaces gathered integration tests on connection={{ ansible_connection
+ }}
+
+- include_tasks: _remove_config.yaml
+
+- include_tasks: _populate.yaml
+
+- block:
+
+ - name: Gather the provided configuration with the exisiting running configuration
+ register: result
+ vyos.vyos.vyos_lldp_interfaces:
+ config:
+ state: gathered
+
+ - name: Assert that gathered dicts was correctly generated
+ assert:
+ that:
+ - "{{ populate | symmetric_difference(result['gathered']) |length == 0\
+ \ }}"
+ always:
+
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/parsed.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/parsed.yaml
new file mode 100644
index 00000000..0ca52bed
--- /dev/null
+++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/parsed.yaml
@@ -0,0 +1,16 @@
+---
+- debug:
+ msg: START vyos_lldp_nterfaces parsed integration tests on connection={{ ansible_connection
+ }}
+
+- name: Parse externally provided interfaces config to agnostic model
+ register: result
+ vyos.vyos.vyos_lldp_interfaces:
+ running_config: "{{ lookup('file', '_parsed_config.cfg') }}"
+ state: parsed
+
+- name: Assert that config was correctly parsed
+ assert:
+ that:
+ - "{{ parsed['after'] | symmetric_difference(result['parsed']) |length ==\
+ \ 0 }}"
diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rendered.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rendered.yaml
new file mode 100644
index 00000000..342e64b9
--- /dev/null
+++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rendered.yaml
@@ -0,0 +1,37 @@
+---
+- debug:
+ msg: START vyos_lldp_interfaces rendered integration tests on connection={{ ansible_connection
+ }}
+
+- include_tasks: _remove_config.yaml
+
+- block:
+
+ - name: Structure provided configuration into device specific commands
+ register: result
+ vyos.vyos.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: rendered
+
+ - name: Assert that correct set of commands were generated
+ assert:
+ that:
+ - "{{ rendered['commands'] | symmetric_difference(result['rendered'])\
+ \ |length == 0 }}"
+ always:
+
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_lldp_interfaces/vars/main.yaml b/tests/integration/targets/vyos_lldp_interfaces/vars/main.yaml
index 3cb684ea..092f653c 100644
--- a/tests/integration/targets/vyos_lldp_interfaces/vars/main.yaml
+++ b/tests/integration/targets/vyos_lldp_interfaces/vars/main.yaml
@@ -9,10 +9,6 @@ merged:
- 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
@@ -44,6 +40,16 @@ populate:
datum: WGS84
longitude: 222.267255W
latitude: 33.524449N
+rendered:
+ 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
replaced:
commands:
- delete service lldp interface eth2 location
@@ -91,6 +97,22 @@ overridden:
- name: eth2
location:
elin: 0000000911
+parsed:
+ 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
deleted:
commands:
- delete service lldp interface eth1
diff --git a/tests/integration/targets/vyos_ospfv2/defaults/main.yaml b/tests/integration/targets/vyos_ospfv2/defaults/main.yaml
new file mode 100644
index 00000000..852a6bee
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv2/defaults/main.yaml
@@ -0,0 +1,3 @@
+---
+testcase: '[^_].*'
+test_items: []
diff --git a/tests/integration/targets/vyos_ospfv2/meta/main.yaml b/tests/integration/targets/vyos_ospfv2/meta/main.yaml
new file mode 100644
index 00000000..7413320e
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv2/meta/main.yaml
@@ -0,0 +1,3 @@
+---
+dependencies:
+ - prepare_vyos_tests
diff --git a/tests/integration/targets/vyos_ospfv2/tasks/cli.yaml b/tests/integration/targets/vyos_ospfv2/tasks/cli.yaml
new file mode 100644
index 00000000..93eb2fe4
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv2/tasks/cli.yaml
@@ -0,0 +1,19 @@
+---
+- 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=ansible.netcommon.network_cli)
+ include: '{{ test_case_to_run }}'
+ vars:
+ ansible_connection: ansible.netcommon.network_cli
+ with_items: '{{ test_items }}'
+ loop_control:
+ loop_var: test_case_to_run
diff --git a/tests/integration/targets/vyos_ospfv2/tasks/main.yaml b/tests/integration/targets/vyos_ospfv2/tasks/main.yaml
new file mode 100644
index 00000000..a3db933e
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv2/tasks/main.yaml
@@ -0,0 +1,4 @@
+---
+- include: cli.yaml
+ tags:
+ - cli
diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/_parsed_config.cfg b/tests/integration/targets/vyos_ospfv2/tests/cli/_parsed_config.cfg
new file mode 100644
index 00000000..9cc720b4
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv2/tests/cli/_parsed_config.cfg
@@ -0,0 +1,29 @@
+set protocols ospf area 2 area-type 'normal'
+set protocols ospf area 2 authentication 'plaintext-password'
+set protocols ospf area 2 shortcut 'enable'
+set protocols ospf area 3 area-type 'nssa'
+set protocols ospf area 4 area-type stub default-cost '20'
+set protocols ospf area 4 network '192.0.2.0/24'
+set protocols ospf area 4 range 192.0.3.0/24 cost '10'
+set protocols ospf area 4 range 192.0.4.0/24 cost '12'
+set protocols ospf auto-cost reference-bandwidth '2'
+set protocols ospf default-information originate 'always'
+set protocols ospf default-information originate metric '10'
+set protocols ospf default-information originate metric-type '2'
+set protocols ospf default-information originate route-map 'ingress'
+set protocols ospf log-adjacency-changes 'detail'
+set protocols ospf max-metric router-lsa 'administrative'
+set protocols ospf max-metric router-lsa on-shutdown '10'
+set protocols ospf max-metric router-lsa on-startup '10'
+set protocols ospf mpls-te 'enable'
+set protocols ospf mpls-te router-address '192.0.11.11'
+set protocols ospf neighbor 192.0.11.12 poll-interval '10'
+set protocols ospf neighbor 192.0.11.12 priority '2'
+set protocols ospf parameters abr-type 'cisco'
+set protocols ospf parameters 'opaque-lsa'
+set protocols ospf parameters 'rfc1583-compatibility'
+set protocols ospf parameters router-id '192.0.1.1'
+set protocols ospf passive-interface 'eth1'
+set protocols ospf passive-interface 'eth2'
+set protocols ospf redistribute bgp metric '10'
+set protocols ospf redistribute bgp metric-type '2'
diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/_populate.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/_populate.yaml
new file mode 100644
index 00000000..9f358d5e
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv2/tests/cli/_populate.yaml
@@ -0,0 +1,35 @@
+---
+- name: Setup
+ vars:
+ lines: "set protocols ospf mpls-te 'enable' \n
+ set protocols ospf mpls-te router-address '192.0.11.11' \n
+ set protocols ospf redistribute bgp metric-type '2' \n
+ set protocols ospf redistribute bgp metric '10'\n
+ set protocols ospf default-information originate metric-type '2' \n
+ set protocols ospf default-information originate 'always' \n
+ set protocols ospf default-information originate metric '10' \n
+ set protocols ospf default-information originate route-map 'ingress' \n
+ set protocols ospf auto-cost reference-bandwidth '2' \n
+ set protocols ospf parameters router-id '192.0.1.1' \n
+ set protocols ospf parameters 'opaque-lsa' \n
+ set protocols ospf parameters abr-type 'cisco' \n
+ set protocols ospf parameters 'rfc1583-compatibility' \n
+ set protocols ospf passive-interface 'eth1' \n
+ set protocols ospf passive-interface 'eth2' \n
+ set protocols ospf max-metric router-lsa on-shutdown '10' \n
+ set protocols ospf max-metric router-lsa 'administrative' \n
+ set protocols ospf max-metric router-lsa on-startup '10' \n
+ set protocols ospf log-adjacency-changes 'detail' \n
+ set protocols ospf neighbor 192.0.11.12 priority '2' \n
+ set protocols ospf neighbor 192.0.11.12 poll-interval '10' \n
+ set protocols ospf area 2 authentication 'plaintext-password' \n
+ set protocols ospf area 2 shortcut 'enable' \n
+ set protocols ospf area 2 area-type 'normal' \n
+ set protocols ospf area 3 area-type 'nssa' \n
+ set protocols ospf area 4 range 192.0.3.0/24 cost '10' \n
+ set protocols ospf area 4 range 192.0.4.0/24 cost '12' \n
+ set protocols ospf area 4 area-type stub default-cost '20' \n
+ set protocols ospf area 4 network '192.0.2.0/24'"
+
+ ansible.netcommon.cli_config:
+ config: '{{ lines }}'
diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/_remove_config.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/_remove_config.yaml
new file mode 100644
index 00000000..73608705
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv2/tests/cli/_remove_config.yaml
@@ -0,0 +1,6 @@
+---
+- name: Remove Config
+ vars:
+ lines: "delete protocols ospf\n"
+ ansible.netcommon.cli_config:
+ config: '{{ lines }}'
diff --git a/tests/integration/targets/vyos_firewall_rules/tests/cli/deleted_rule.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/deleted.yaml
index d77e2a9c..a61f5a7c 100644
--- a/tests/integration/targets/vyos_firewall_rules/tests/cli/deleted_rule.yaml
+++ b/tests/integration/targets/vyos_ospfv2/tests/cli/deleted.yaml
@@ -1,46 +1,37 @@
---
- debug:
- msg: Start vyos_firewall_rules deleted integration tests ansible_connection={{
+ msg: Start vyos_ospfv2 deleted integration tests ansible_connection={{
ansible_connection }}
- include_tasks: _populate.yaml
- block:
- - name: Delete firewall rule.
+ - name: Delete attributes of ospfv2.
register: result
- vyos.vyos.vyos_firewall_rules: &id001
+ vyos.vyos.vyos_ospfv2: &id001
config:
-
- - afi: ipv6
- rule_sets:
-
- - name: UPLINK
- rules:
-
- - number: 1
state: deleted
- name: Assert that the before dicts were correctly generated
assert:
that:
- - "{{ populate | symmetric_difference(result['before']) |length == 0 }}"
+ - "{{ populate == result['before'] }}"
- name: Assert that the correct set of commands were generated
assert:
that:
- - "{{ deleted_r['commands'] | symmetric_difference(result['commands'])\
- \ |length == 0 }}"
+ - "{{ deleted['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 }}"
+ - "{{ deleted['after'] == result['after'] }}"
- name: Delete attributes of given interfaces (IDEMPOTENT)
register: result
- vyos.vyos.vyos_firewall_rules: *id001
+ vyos.vyos.vyos_ospfv2: *id001
- name: Assert that the previous task was idempotent
assert:
@@ -51,8 +42,7 @@
- name: Assert that the before dicts were correctly generated
assert:
that:
- - "{{ deleted_r['after'] | symmetric_difference(result['before']) |length\
- \ == 0 }}"
+ - "{{ deleted['after'] == result['before'] }}"
always:
- include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/empty_config.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/empty_config.yaml
new file mode 100644
index 00000000..4566bf47
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv2/tests/cli/empty_config.yaml
@@ -0,0 +1,49 @@
+---
+- debug:
+ msg: START vyos_ospfv2 empty_config integration tests on connection={{
+ ansible_connection }}
+
+- name: Merged with empty config should give appropriate error message
+ register: result
+ ignore_errors: true
+ vyos.vyos.vyos_ospfv2:
+ config:
+ state: merged
+
+- 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
+ register: result
+ ignore_errors: true
+ vyos.vyos.vyos_ospfv2:
+ config:
+ state: replaced
+
+- 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
+ register: result
+ ignore_errors: true
+ vyos.vyos.vyos_ospfv2:
+ running_config:
+ state: parsed
+
+- 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
+ register: result
+ ignore_errors: true
+ vyos.vyos.vyos_ospfv2:
+ config:
+ state: rendered
+
+- assert:
+ that:
+ - result.msg == 'value of config parameter must not be empty for state rendered'
diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/gathered.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/gathered.yaml
new file mode 100644
index 00000000..bc5e1e27
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv2/tests/cli/gathered.yaml
@@ -0,0 +1,24 @@
+---
+- debug:
+ msg: START vyos_ospfv2 gathered integration tests on connection={{
+ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+
+- include_tasks: _populate.yaml
+
+- block:
+
+ - name: Gather the provided configuration with the exisiting running configuration
+ register: result
+ vyos.vyos.vyos_ospfv2:
+ config:
+ state: gathered
+
+ - name: Assert that gathered dicts was correctly generated
+ assert:
+ that:
+ - "{{ populate == result['gathered'] }}"
+ always:
+
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/merged.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/merged.yaml
new file mode 100644
index 00000000..6a58bb57
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv2/tests/cli/merged.yaml
@@ -0,0 +1,101 @@
+---
+- debug:
+ msg: START vyos_ospfv2 merged integration tests on connection={{ ansible_connection
+ }}
+
+- include_tasks: _remove_config.yaml
+
+- block:
+
+ - name: Merge the provided configuration with the exisiting running configuration
+ register: result
+ vyos.vyos.vyos_ospfv2: &id001
+ config:
+ log_adjacency_changes: 'detail'
+ max_metric:
+ router_lsa:
+ administrative: true
+ on_shutdown: 10
+ on_startup: 10
+ default_information:
+ originate:
+ always: true
+ metric: 10
+ metric_type: 2
+ route_map: 'ingress'
+ mpls_te:
+ enabled: true
+ router_address: '192.0.11.11'
+ auto_cost:
+ reference_bandwidth: 2
+ neighbor:
+ - neighbor_id: '192.0.11.12'
+ poll_interval: 10
+ priority: 2
+ redistribute:
+ - route_type: 'bgp'
+ metric: 10
+ metric_type: 2
+ passive_interface:
+ - 'eth1'
+ - 'eth2'
+ parameters:
+ router_id: '192.0.1.1'
+ opaque_lsa: true
+ rfc1583_compatibility: true
+ abr_type: 'cisco'
+ areas:
+ - area_id: '2'
+ area_type:
+ normal: true
+ authentication: "plaintext-password"
+ shortcut: 'enable'
+ - area_id: '3'
+ area_type:
+ nssa:
+ set: true
+ - area_id: '4'
+ area_type:
+ stub:
+ default_cost: 20
+ network:
+ - address: '192.0.2.0/24'
+ range:
+ - address: '192.0.3.0/24'
+ cost: 10
+ - address: '192.0.4.0/24'
+ cost: 12
+ state: merged
+
+ - 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)
+ register: result
+ vyos.vyos.vyos_ospfv2: *id001
+
+ - 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/tests/integration/targets/vyos_ospfv2/tests/cli/merged_update.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/merged_update.yaml
new file mode 100644
index 00000000..9b6823c9
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv2/tests/cli/merged_update.yaml
@@ -0,0 +1,70 @@
+---
+- debug:
+ msg: START vyos_ospfv2 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
+ register: result
+ vyos.vyos.vyos_ospfv2: &id001
+ config:
+ log_adjacency_changes: 'detail'
+ max_metric:
+ router_lsa:
+ administrative: true
+ on_shutdown: 10
+ on_startup: 10
+ passive_interface:
+ - 'eth1'
+ areas:
+ - area_id: '3'
+ area_type:
+ nssa:
+ set: true
+ - area_id: '4'
+ area_type:
+ stub:
+ set: false
+ network:
+ - address: '192.0.2.0/24'
+ - address: '192.0.22.0/24'
+ - address: '192.0.32.0/24'
+ state: merged
+
+ - name: Assert that before dicts were correctly generated
+ assert:
+ that: "{{ merged_update['before'] == result['before'] }}"
+
+ - name: Assert that correct set of commands were generated
+ assert:
+ that:
+ - "{{ merged_update['commands'] | symmetric_difference(result['commands']) |length\
+ \ == 0 }}"
+
+ - name: Assert that after dicts was correctly generated
+ assert:
+ that:
+ - "{{ merged_update['after'] == result['after'] }}"
+
+ - name: Merge the provided configuration with the existing running configuration
+ (IDEMPOTENT)
+ register: result
+ vyos.vyos.vyos_ospfv2: *id001
+
+ - name: Assert that the previous task was idempotent
+ assert:
+ that:
+ - result['changed'] == false
+
+ - name: Assert that before dicts were correctly generated
+ assert:
+ that:
+ - "{{ merged_update['after'] == result['before'] }}"
+ always:
+
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/parsed.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/parsed.yaml
new file mode 100644
index 00000000..cfa29f99
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv2/tests/cli/parsed.yaml
@@ -0,0 +1,15 @@
+---
+- debug:
+ msg: START vyos_ospfv2 parsed integration tests on connection={{ ansible_connection
+ }}
+
+- name: Parse externally provided ospfv2 config to agnostic model
+ register: result
+ vyos.vyos.vyos_ospfv2:
+ running_config: "{{ lookup('file', '_parsed_config.cfg') }}"
+ state: parsed
+
+- name: Assert that config was correctly parsed
+ assert:
+ that:
+ - "{{ parsed['after'] == result['parsed'] }}"
diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/rendered.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/rendered.yaml
new file mode 100644
index 00000000..8a805a6a
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv2/tests/cli/rendered.yaml
@@ -0,0 +1,76 @@
+---
+- debug:
+ msg: START vyos_ospfv2 rendered integration tests on connection={{
+ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+
+- block:
+
+ - name: Structure provided configuration into device specific commands
+ register: result
+ vyos.vyos.vyos_ospfv2:
+ config:
+ log_adjacency_changes: 'detail'
+ max_metric:
+ router_lsa:
+ administrative: true
+ on_shutdown: 10
+ on_startup: 10
+ default_information:
+ originate:
+ always: true
+ metric: 10
+ metric_type: 2
+ route_map: 'ingress'
+ mpls_te:
+ enabled: true
+ router_address: '192.0.11.11'
+ auto_cost:
+ reference_bandwidth: 2
+ neighbor:
+ - neighbor_id: '192.0.11.12'
+ poll_interval: 10
+ priority: 2
+ redistribute:
+ - route_type: 'bgp'
+ metric: 10
+ metric_type: 2
+ passive_interface:
+ - 'eth1'
+ - 'eth2'
+ parameters:
+ router_id: '192.0.1.1'
+ opaque_lsa: true
+ rfc1583_compatibility: true
+ abr_type: 'cisco'
+ areas:
+ - area_id: '2'
+ area_type:
+ normal: true
+ authentication: "plaintext-password"
+ shortcut: 'enable'
+ - area_id: '3'
+ area_type:
+ nssa:
+ set: true
+ - area_id: '4'
+ area_type:
+ stub:
+ default_cost: 20
+ network:
+ - address: '192.0.2.0/24'
+ range:
+ - address: '192.0.3.0/24'
+ cost: 10
+ - address: '192.0.4.0/24'
+ cost: 12
+ state: rendered
+
+ - name: Assert that correct set of commands were generated
+ assert:
+ that:
+ - "{{ rendered['commands'] | symmetric_difference(result['rendered'])\
+ \ |length == 0 }}"
+- debug:
+ msg: END vyos_ospfv2 rendered integration tests on connection={{ ansible_connection }}
diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/replaced.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/replaced.yaml
new file mode 100644
index 00000000..07606f94
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv2/tests/cli/replaced.yaml
@@ -0,0 +1,100 @@
+---
+- debug:
+ msg: START vyos_ospfv2 replaced integration tests on connection={{
+ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+
+- include_tasks: _populate.yaml
+
+- block:
+
+ - name: Replace device configurations of listed ospfv2 routes with provided configurations
+ register: result
+ vyos.vyos.vyos_ospfv2: &id001
+ config:
+ log_adjacency_changes: 'detail'
+ max_metric:
+ router_lsa:
+ administrative: true
+ on_shutdown: 10
+ on_startup: 10
+ default_information:
+ originate:
+ always: true
+ metric: 10
+ metric_type: 2
+ route_map: 'ingress'
+ mpls_te:
+ enabled: true
+ router_address: '192.0.22.22'
+ auto_cost:
+ reference_bandwidth: 2
+ neighbor:
+ - neighbor_id: '192.0.11.12'
+ poll_interval: 10
+ priority: 2
+ redistribute:
+ - route_type: 'bgp'
+ metric: 10
+ metric_type: 2
+ passive_interface:
+ - 'eth1'
+ parameters:
+ router_id: '192.0.1.1'
+ opaque_lsa: true
+ rfc1583_compatibility: true
+ abr_type: 'cisco'
+ areas:
+ - area_id: '2'
+ area_type:
+ normal: true
+ authentication: "plaintext-password"
+ shortcut: 'enable'
+ - area_id: '4'
+ area_type:
+ stub:
+ default_cost: 20
+ network:
+ - address: '192.0.2.0/24'
+ - address: '192.0.12.0/24'
+ - address: '192.0.22.0/24'
+ - address: '192.0.32.0/24'
+ range:
+ - address: '1.1.2.0/24'
+ cost: 10
+ state: replaced
+
+ - 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 ospfv2 routes with provided configurarions
+ (IDEMPOTENT)
+ register: result
+ vyos.vyos.vyos_ospfv2: *id001
+
+ - 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/tests/integration/targets/vyos_ospfv2/tests/cli/rtt.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/rtt.yaml
new file mode 100644
index 00000000..7efc2a7b
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv2/tests/cli/rtt.yaml
@@ -0,0 +1,149 @@
+---
+- debug:
+ msg: START vyos_ospfv2 round trip integration tests on connection={{
+ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+
+- block:
+
+ - name: Apply the provided configuration (base config)
+ register: base_config
+ vyos.vyos.vyos_ospfv2:
+ config:
+ log_adjacency_changes: 'detail'
+ max_metric:
+ router_lsa:
+ administrative: true
+ on_shutdown: 10
+ on_startup: 10
+ default_information:
+ originate:
+ always: true
+ metric: 10
+ metric_type: 2
+ route_map: 'ingress'
+ mpls_te:
+ enabled: true
+ router_address: '192.0.11.11'
+ auto_cost:
+ reference_bandwidth: 2
+ neighbor:
+ - neighbor_id: '192.0.11.12'
+ poll_interval: 10
+ priority: 2
+ redistribute:
+ - route_type: 'bgp'
+ metric: 10
+ metric_type: 2
+ passive_interface:
+ - 'eth1'
+ - 'eth2'
+ parameters:
+ router_id: '192.0.1.1'
+ opaque_lsa: true
+ rfc1583_compatibility: true
+ abr_type: 'cisco'
+ areas:
+ - area_id: '2'
+ area_type:
+ normal: true
+ authentication: "plaintext-password"
+ shortcut: 'enable'
+ - area_id: '3'
+ area_type:
+ nssa:
+ set: true
+ - area_id: '4'
+ area_type:
+ stub:
+ default_cost: 20
+ network:
+ - address: '192.0.2.0/24'
+ range:
+ - address: '192.0.3.0/24'
+ cost: 10
+ - address: '192.0.4.0/24'
+ cost: 12
+ state: merged
+
+ - name: Gather ospfv2 facts
+ vyos.vyos.vyos_facts:
+ gather_subset:
+ - default
+ gather_network_resources:
+ - ospfv2
+
+ - name: Apply the provided configuration (config to be reverted)
+ register: result
+ vyos.vyos.vyos_ospfv2:
+ config:
+ areas:
+ - area_id: '2'
+ area_type:
+ normal: true
+ authentication: "plaintext-password"
+ shortcut: 'enable'
+ - area_id: '4'
+ area_type:
+ stub:
+ default_cost: 20
+ set: true
+ network:
+ - address: '192.0.12.0/24'
+ - address: '192.0.2.0/24'
+ - address: '192.0.22.0/24'
+ - address: '192.0.32.0/24'
+ range:
+ - address: '1.1.2.0/24'
+ cost: 10
+ auto_cost:
+ reference_bandwidth: 2
+ default_information:
+ originate:
+ always: true
+ metric: 10
+ metric_type: 2
+ route_map: 'ingress'
+ log_adjacency_changes: 'detail'
+ max_metric:
+ router_lsa:
+ administrative: true
+ on_shutdown: 10
+ on_startup: 10
+ mpls_te:
+ enabled: true
+ router_address: '192.0.22.22'
+ neighbor:
+ - neighbor_id: '192.0.11.12'
+ poll_interval: 10
+ priority: 2
+ parameters:
+ abr_type: 'cisco'
+ opaque_lsa: true
+ rfc1583_compatibility: true
+ router_id: '192.0.1.1'
+ passive_interface:
+ - 'eth1'
+ redistribute:
+ - metric: 10
+ metric_type: 2
+ route_type: 'bgp'
+ state: replaced
+
+ - name: Assert that changes were applied
+ assert:
+ that: "{{ round_trip['after'] == result['after'] }}"
+
+ - name: Revert back to base config using facts round trip
+ register: revert
+ vyos.vyos.vyos_ospfv2:
+ config: "{{ ansible_facts['network_resources']['ospfv2'] }}"
+ state: replaced
+
+ - name: Assert that config was reverted
+ assert:
+ that: "{{ base_config['after'] == revert['after']}}"
+ always:
+
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_ospfv2/vars/main.yaml b/tests/integration/targets/vyos_ospfv2/vars/main.yaml
new file mode 100644
index 00000000..e55da20f
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv2/vars/main.yaml
@@ -0,0 +1,485 @@
+---
+merged:
+ before: {}
+ commands:
+ - set protocols ospf mpls-te enable
+ - set protocols ospf mpls-te router-address '192.0.11.11'
+ - set protocols ospf redistribute bgp
+ - set protocols ospf redistribute bgp metric-type 2
+ - set protocols ospf redistribute bgp metric 10
+ - set protocols ospf default-information originate metric-type 2
+ - set protocols ospf default-information originate always
+ - set protocols ospf default-information originate metric 10
+ - set protocols ospf default-information originate route-map ingress
+ - set protocols ospf auto-cost reference-bandwidth '2'
+ - set protocols ospf parameters router-id '192.0.1.1'
+ - set protocols ospf parameters opaque-lsa
+ - set protocols ospf parameters abr-type 'cisco'
+ - set protocols ospf parameters rfc1583-compatibility
+ - set protocols ospf passive-interface eth1
+ - set protocols ospf passive-interface eth2
+ - set protocols ospf max-metric router-lsa on-shutdown 10
+ - set protocols ospf max-metric router-lsa administrative
+ - set protocols ospf max-metric router-lsa on-startup 10
+ - set protocols ospf log-adjacency-changes 'detail'
+ - set protocols ospf neighbor 192.0.11.12 priority 2
+ - set protocols ospf neighbor 192.0.11.12 poll-interval 10
+ - set protocols ospf neighbor 192.0.11.12
+ - set protocols ospf area '2'
+ - set protocols ospf area 2 authentication plaintext-password
+ - set protocols ospf area 2 shortcut enable
+ - set protocols ospf area 2 area-type normal
+ - set protocols ospf area '3'
+ - set protocols ospf area 3 area-type nssa
+ - set protocols ospf area 4 range 192.0.3.0/24 cost 10
+ - set protocols ospf area 4 range 192.0.3.0/24
+ - set protocols ospf area 4 range 192.0.4.0/24 cost 12
+ - set protocols ospf area 4 range 192.0.4.0/24
+ - set protocols ospf area 4 area-type stub default-cost 20
+ - set protocols ospf area '4'
+ - set protocols ospf area 4 network 192.0.2.0/24
+ after:
+ areas:
+ - area_id: '2'
+ area_type:
+ normal: true
+ authentication: "plaintext-password"
+ shortcut: 'enable'
+ - area_id: '3'
+ area_type:
+ nssa:
+ set: true
+ - area_id: '4'
+ area_type:
+ stub:
+ default_cost: 20
+ set: true
+ network:
+ - address: '192.0.2.0/24'
+ range:
+ - address: '192.0.3.0/24'
+ cost: 10
+ - address: '192.0.4.0/24'
+ cost: 12
+ auto_cost:
+ reference_bandwidth: 2
+ default_information:
+ originate:
+ always: true
+ metric: 10
+ metric_type: 2
+ route_map: 'ingress'
+ log_adjacency_changes: 'detail'
+ max_metric:
+ router_lsa:
+ administrative: true
+ on_shutdown: 10
+ on_startup: 10
+ mpls_te:
+ enabled: true
+ router_address: '192.0.11.11'
+ neighbor:
+ - neighbor_id: '192.0.11.12'
+ poll_interval: 10
+ priority: 2
+ parameters:
+ abr_type: 'cisco'
+ opaque_lsa: true
+ rfc1583_compatibility: true
+ router_id: '192.0.1.1'
+ passive_interface:
+ - 'eth1'
+ - 'eth2'
+ redistribute:
+ - metric: 10
+ metric_type: 2
+ route_type: 'bgp'
+merged_update:
+ before:
+ areas:
+ - area_id: '2'
+ area_type:
+ normal: true
+ authentication: "plaintext-password"
+ shortcut: 'enable'
+ - area_id: '3'
+ area_type:
+ nssa:
+ set: true
+ - area_id: '4'
+ area_type:
+ stub:
+ default_cost: 20
+ set: true
+ network:
+ - address: '192.0.2.0/24'
+ range:
+ - address: '192.0.3.0/24'
+ cost: 10
+ - address: '192.0.4.0/24'
+ cost: 12
+ auto_cost:
+ reference_bandwidth: 2
+ default_information:
+ originate:
+ always: true
+ metric: 10
+ metric_type: 2
+ route_map: 'ingress'
+ log_adjacency_changes: 'detail'
+ max_metric:
+ router_lsa:
+ administrative: true
+ on_shutdown: 10
+ on_startup: 10
+ mpls_te:
+ enabled: true
+ router_address: '192.0.11.11'
+ neighbor:
+ - neighbor_id: '192.0.11.12'
+ poll_interval: 10
+ priority: 2
+ parameters:
+ abr_type: 'cisco'
+ opaque_lsa: true
+ rfc1583_compatibility: true
+ router_id: '192.0.1.1'
+ passive_interface:
+ - 'eth1'
+ - 'eth2'
+ redistribute:
+ - metric: 10
+ metric_type: 2
+ route_type: 'bgp'
+ after:
+ areas:
+ - area_id: '2'
+ area_type:
+ normal: true
+ authentication: "plaintext-password"
+ shortcut: 'enable'
+ - area_id: '3'
+ area_type:
+ nssa:
+ set: true
+ - area_id: '4'
+ network:
+ - address: '192.0.2.0/24'
+ - address: '192.0.22.0/24'
+ - address: '192.0.32.0/24'
+ range:
+ - address: '192.0.3.0/24'
+ cost: 10
+ - address: '192.0.4.0/24'
+ cost: 12
+ auto_cost:
+ reference_bandwidth: 2
+ default_information:
+ originate:
+ always: true
+ metric: 10
+ metric_type: 2
+ route_map: 'ingress'
+ log_adjacency_changes: 'detail'
+ max_metric:
+ router_lsa:
+ administrative: true
+ on_shutdown: 10
+ on_startup: 10
+ mpls_te:
+ enabled: true
+ router_address: '192.0.11.11'
+ neighbor:
+ - neighbor_id: '192.0.11.12'
+ poll_interval: 10
+ priority: 2
+ parameters:
+ abr_type: 'cisco'
+ opaque_lsa: true
+ rfc1583_compatibility: true
+ router_id: '192.0.1.1'
+ passive_interface:
+ - 'eth1'
+ - 'eth2'
+ redistribute:
+ - metric: 10
+ metric_type: 2
+ route_type: 'bgp'
+ commands:
+ - delete protocols ospf area 4 area-type stub
+ - set protocols ospf area 4 network 192.0.22.0/24
+ - set protocols ospf area 4 network 192.0.32.0/24
+populate:
+ areas:
+ - area_id: '2'
+ area_type:
+ normal: true
+ authentication: "plaintext-password"
+ shortcut: 'enable'
+ - area_id: '3'
+ area_type:
+ nssa:
+ set: true
+ - area_id: '4'
+ area_type:
+ stub:
+ default_cost: 20
+ set: true
+ network:
+ - address: '192.0.2.0/24'
+ range:
+ - address: '192.0.3.0/24'
+ cost: 10
+ - address: '192.0.4.0/24'
+ cost: 12
+ auto_cost:
+ reference_bandwidth: 2
+ default_information:
+ originate:
+ always: true
+ metric: 10
+ metric_type: 2
+ route_map: 'ingress'
+ log_adjacency_changes: 'detail'
+ max_metric:
+ router_lsa:
+ administrative: true
+ on_shutdown: 10
+ on_startup: 10
+ mpls_te:
+ enabled: true
+ router_address: '192.0.11.11'
+ neighbor:
+ - neighbor_id: '192.0.11.12'
+ poll_interval: 10
+ priority: 2
+ parameters:
+ abr_type: 'cisco'
+ opaque_lsa: true
+ rfc1583_compatibility: true
+ router_id: '192.0.1.1'
+ passive_interface:
+ - 'eth1'
+ - 'eth2'
+ redistribute:
+ - metric: 10
+ metric_type: 2
+ route_type: 'bgp'
+replaced:
+ commands:
+ - delete protocols ospf passive-interface eth2
+ - delete protocols ospf area 3
+ - delete protocols ospf area 4 range 192.0.3.0/24 cost
+ - delete protocols ospf area 4 range 192.0.3.0/24
+ - delete protocols ospf area 4 range 192.0.4.0/24 cost
+ - delete protocols ospf area 4 range 192.0.4.0/24
+ - set protocols ospf mpls-te router-address '192.0.22.22'
+ - set protocols ospf area 4 range 1.1.2.0/24 cost 10
+ - set protocols ospf area 4 range 1.1.2.0/24
+ - set protocols ospf area 4 network 192.0.12.0/24
+ - set protocols ospf area 4 network 192.0.22.0/24
+ - set protocols ospf area 4 network 192.0.32.0/24
+ after:
+ areas:
+ - area_id: '2'
+ area_type:
+ normal: true
+ authentication: "plaintext-password"
+ shortcut: 'enable'
+ - area_id: '4'
+ area_type:
+ stub:
+ default_cost: 20
+ set: true
+ network:
+ - address: '192.0.12.0/24'
+ - address: '192.0.2.0/24'
+ - address: '192.0.22.0/24'
+ - address: '192.0.32.0/24'
+ range:
+ - address: '1.1.2.0/24'
+ cost: 10
+ auto_cost:
+ reference_bandwidth: 2
+ default_information:
+ originate:
+ always: true
+ metric: 10
+ metric_type: 2
+ route_map: 'ingress'
+ log_adjacency_changes: 'detail'
+ max_metric:
+ router_lsa:
+ administrative: true
+ on_shutdown: 10
+ on_startup: 10
+ mpls_te:
+ enabled: true
+ router_address: '192.0.22.22'
+ neighbor:
+ - neighbor_id: '192.0.11.12'
+ poll_interval: 10
+ priority: 2
+ parameters:
+ abr_type: 'cisco'
+ opaque_lsa: true
+ rfc1583_compatibility: true
+ router_id: '192.0.1.1'
+ passive_interface:
+ - 'eth1'
+ redistribute:
+ - metric: 10
+ metric_type: 2
+ route_type: 'bgp'
+rendered:
+ commands:
+ - set protocols ospf mpls-te enable
+ - set protocols ospf mpls-te router-address '192.0.11.11'
+ - set protocols ospf redistribute bgp
+ - set protocols ospf redistribute bgp metric-type 2
+ - set protocols ospf redistribute bgp metric 10
+ - set protocols ospf default-information originate metric-type 2
+ - set protocols ospf default-information originate always
+ - set protocols ospf default-information originate metric 10
+ - set protocols ospf default-information originate route-map ingress
+ - set protocols ospf auto-cost reference-bandwidth '2'
+ - set protocols ospf parameters router-id '192.0.1.1'
+ - set protocols ospf parameters opaque-lsa
+ - set protocols ospf parameters abr-type 'cisco'
+ - set protocols ospf parameters rfc1583-compatibility
+ - set protocols ospf passive-interface eth1
+ - set protocols ospf passive-interface eth2
+ - set protocols ospf max-metric router-lsa on-shutdown 10
+ - set protocols ospf max-metric router-lsa administrative
+ - set protocols ospf max-metric router-lsa on-startup 10
+ - set protocols ospf log-adjacency-changes 'detail'
+ - set protocols ospf neighbor 192.0.11.12 priority 2
+ - set protocols ospf neighbor 192.0.11.12 poll-interval 10
+ - set protocols ospf neighbor 192.0.11.12
+ - set protocols ospf area '2'
+ - set protocols ospf area 2 authentication plaintext-password
+ - set protocols ospf area 2 shortcut enable
+ - set protocols ospf area 2 area-type normal
+ - set protocols ospf area '3'
+ - set protocols ospf area 3 area-type nssa
+ - set protocols ospf area 4 range 192.0.3.0/24 cost 10
+ - set protocols ospf area 4 range 192.0.3.0/24
+ - set protocols ospf area 4 range 192.0.4.0/24 cost 12
+ - set protocols ospf area 4 range 192.0.4.0/24
+ - set protocols ospf area 4 area-type stub default-cost 20
+ - set protocols ospf area '4'
+ - set protocols ospf area 4 network 192.0.2.0/24
+parsed:
+ after:
+ areas:
+ - area_id: '2'
+ area_type:
+ normal: true
+ authentication: "plaintext-password"
+ shortcut: 'enable'
+ - area_id: '3'
+ area_type:
+ nssa:
+ set: true
+ - area_id: '4'
+ area_type:
+ stub:
+ default_cost: 20
+ set: true
+ network:
+ - address: '192.0.2.0/24'
+ range:
+ - address: '192.0.3.0/24'
+ cost: 10
+ - address: '192.0.4.0/24'
+ cost: 12
+ auto_cost:
+ reference_bandwidth: 2
+ default_information:
+ originate:
+ always: true
+ metric: 10
+ metric_type: 2
+ route_map: 'ingress'
+ log_adjacency_changes: 'detail'
+ max_metric:
+ router_lsa:
+ administrative: true
+ on_shutdown: 10
+ on_startup: 10
+ mpls_te:
+ enabled: true
+ router_address: '192.0.11.11'
+ neighbor:
+ - neighbor_id: '192.0.11.12'
+ poll_interval: 10
+ priority: 2
+ parameters:
+ abr_type: 'cisco'
+ opaque_lsa: true
+ rfc1583_compatibility: true
+ router_id: '192.0.1.1'
+ passive_interface:
+ - 'eth1'
+ - 'eth2'
+ redistribute:
+ - metric: 10
+ metric_type: 2
+ route_type: 'bgp'
+deleted:
+ commands:
+ - 'delete protocols ospf'
+ after: {}
+round_trip:
+ after:
+ areas:
+ - area_id: '2'
+ area_type:
+ normal: true
+ authentication: "plaintext-password"
+ shortcut: 'enable'
+ - area_id: '4'
+ area_type:
+ stub:
+ default_cost: 20
+ set: true
+ network:
+ - address: '192.0.12.0/24'
+ - address: '192.0.2.0/24'
+ - address: '192.0.22.0/24'
+ - address: '192.0.32.0/24'
+ range:
+ - address: '1.1.2.0/24'
+ cost: 10
+ auto_cost:
+ reference_bandwidth: 2
+ default_information:
+ originate:
+ always: true
+ metric: 10
+ metric_type: 2
+ route_map: 'ingress'
+ log_adjacency_changes: 'detail'
+ max_metric:
+ router_lsa:
+ administrative: true
+ on_shutdown: 10
+ on_startup: 10
+ mpls_te:
+ enabled: true
+ router_address: '192.0.22.22'
+ neighbor:
+ - neighbor_id: '192.0.11.12'
+ poll_interval: 10
+ priority: 2
+ parameters:
+ abr_type: 'cisco'
+ opaque_lsa: true
+ rfc1583_compatibility: true
+ router_id: '192.0.1.1'
+ passive_interface:
+ - 'eth1'
+ redistribute:
+ - metric: 10
+ metric_type: 2
+ route_type: 'bgp'
diff --git a/tests/integration/targets/vyos_ospfv3/defaults/main.yaml b/tests/integration/targets/vyos_ospfv3/defaults/main.yaml
new file mode 100644
index 00000000..852a6bee
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv3/defaults/main.yaml
@@ -0,0 +1,3 @@
+---
+testcase: '[^_].*'
+test_items: []
diff --git a/tests/integration/targets/vyos_ospfv3/meta/main.yaml b/tests/integration/targets/vyos_ospfv3/meta/main.yaml
new file mode 100644
index 00000000..7413320e
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv3/meta/main.yaml
@@ -0,0 +1,3 @@
+---
+dependencies:
+ - prepare_vyos_tests
diff --git a/tests/integration/targets/vyos_ospfv3/tasks/cli.yaml b/tests/integration/targets/vyos_ospfv3/tasks/cli.yaml
new file mode 100644
index 00000000..93eb2fe4
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv3/tasks/cli.yaml
@@ -0,0 +1,19 @@
+---
+- 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=ansible.netcommon.network_cli)
+ include: '{{ test_case_to_run }}'
+ vars:
+ ansible_connection: ansible.netcommon.network_cli
+ with_items: '{{ test_items }}'
+ loop_control:
+ loop_var: test_case_to_run
diff --git a/tests/integration/targets/vyos_ospfv3/tasks/main.yaml b/tests/integration/targets/vyos_ospfv3/tasks/main.yaml
new file mode 100644
index 00000000..a3db933e
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv3/tasks/main.yaml
@@ -0,0 +1,4 @@
+---
+- include: cli.yaml
+ tags:
+ - cli
diff --git a/tests/integration/targets/vyos_ospfv3/tests/cli/_parsed_config.cfg b/tests/integration/targets/vyos_ospfv3/tests/cli/_parsed_config.cfg
new file mode 100644
index 00000000..5e012d5a
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv3/tests/cli/_parsed_config.cfg
@@ -0,0 +1,8 @@
+set protocols ospfv3 area 2 export-list 'export1'
+set protocols ospfv3 area 2 import-list 'import1'
+set protocols ospfv3 area 2 range '2001:db10::/32'
+set protocols ospfv3 area 2 range '2001:db20::/32'
+set protocols ospfv3 area 2 range '2001:db30::/32'
+set protocols ospfv3 area 3 range '2001:db40::/32'
+set protocols ospfv3 parameters router-id '192.0.2.10'
+set protocols ospfv3 redistribute 'bgp'
diff --git a/tests/integration/targets/vyos_ospfv3/tests/cli/_populate.yaml b/tests/integration/targets/vyos_ospfv3/tests/cli/_populate.yaml
new file mode 100644
index 00000000..fb66d0a5
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv3/tests/cli/_populate.yaml
@@ -0,0 +1,13 @@
+---
+- name: Setup
+ vars:
+ lines: "set protocols ospfv3 area 2 export-list 'export1' \n
+ set protocols ospfv3 area 2 import-list 'import1' \n
+ set protocols ospfv3 area 2 range '2001:db10::/32' \n
+ set protocols ospfv3 area 2 range '2001:db20::/32' \n
+ set protocols ospfv3 area 2 range '2001:db30::/32' \n
+ set protocols ospfv3 area 3 range '2001:db40::/32' \n
+ set protocols ospfv3 parameters router-id '192.0.2.10' \n
+ set protocols ospfv3 redistribute 'bgp'"
+ ansible.netcommon.cli_config:
+ config: '{{ lines }}'
diff --git a/tests/integration/targets/vyos_ospfv3/tests/cli/_remove_config.yaml b/tests/integration/targets/vyos_ospfv3/tests/cli/_remove_config.yaml
new file mode 100644
index 00000000..2a475050
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv3/tests/cli/_remove_config.yaml
@@ -0,0 +1,6 @@
+---
+- name: Remove Config
+ vars:
+ lines: "delete protocols ospfv3\n"
+ ansible.netcommon.cli_config:
+ config: '{{ lines }}'
diff --git a/tests/integration/targets/vyos_ospfv3/tests/cli/deleted.yaml b/tests/integration/targets/vyos_ospfv3/tests/cli/deleted.yaml
new file mode 100644
index 00000000..55bec184
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv3/tests/cli/deleted.yaml
@@ -0,0 +1,48 @@
+---
+- debug:
+ msg: Start vyos_ospfv3 deleted integration tests ansible_connection={{
+ ansible_connection }}
+
+- include_tasks: _populate.yaml
+
+- block:
+
+ - name: Delete ospfv3 routes
+ register: result
+ vyos.vyos.vyos_ospfv3: &id001
+ config:
+ state: deleted
+
+ - 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 ospfv3 routes (IDEMPOTENT)
+ register: result
+ vyos.vyos.vyos_ospfv3: *id001
+
+ - 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/tests/integration/targets/vyos_ospfv3/tests/cli/empty_config.yaml b/tests/integration/targets/vyos_ospfv3/tests/cli/empty_config.yaml
new file mode 100644
index 00000000..fec61abf
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv3/tests/cli/empty_config.yaml
@@ -0,0 +1,49 @@
+---
+- debug:
+ msg: START vyos_ospfv3 empty_config integration tests on connection={{
+ ansible_connection }}
+
+- name: Merged with empty config should give appropriate error message
+ register: result
+ ignore_errors: true
+ vyos.vyos.vyos_ospfv3:
+ config:
+ state: merged
+
+- 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
+ register: result
+ ignore_errors: true
+ vyos.vyos.vyos_ospfv3:
+ config:
+ state: replaced
+
+- 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
+ register: result
+ ignore_errors: true
+ vyos.vyos.vyos_ospfv3:
+ running_config:
+ state: parsed
+
+- 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
+ register: result
+ ignore_errors: true
+ vyos.vyos.vyos_ospfv3:
+ config:
+ state: rendered
+
+- assert:
+ that:
+ - result.msg == 'value of config parameter must not be empty for state rendered'
diff --git a/tests/integration/targets/vyos_ospfv3/tests/cli/gathered.yaml b/tests/integration/targets/vyos_ospfv3/tests/cli/gathered.yaml
new file mode 100644
index 00000000..6645b99f
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv3/tests/cli/gathered.yaml
@@ -0,0 +1,25 @@
+---
+- debug:
+ msg: START vyos_ospfv3 gathered integration tests on connection={{
+ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+
+- include_tasks: _populate.yaml
+
+- block:
+
+ - name: Gather the provided configuration with the exisiting running configuration
+ register: result
+ vyos.vyos.vyos_ospfv3:
+ config:
+ state: gathered
+
+ - name: Assert that gathered dicts was correctly generated
+ assert:
+ that:
+ - "{{ populate == result['gathered'] }}"
+
+ always:
+
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_ospfv3/tests/cli/merged.yaml b/tests/integration/targets/vyos_ospfv3/tests/cli/merged.yaml
new file mode 100644
index 00000000..93095009
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv3/tests/cli/merged.yaml
@@ -0,0 +1,62 @@
+---
+- debug:
+ msg: START vyos_ospfv3 merged integration tests on connection={{ ansible_connection
+ }}
+
+- include_tasks: _remove_config.yaml
+
+- block:
+
+ - name: Merge the provided configuration with the exisiting running configuration
+ register: result
+ vyos.vyos.vyos_ospfv3: &id001
+ config:
+ areas:
+ - area_id: '2'
+ export_list: 'export1'
+ import_list: 'import1'
+ range:
+ - address: '2001:db10::/32'
+ - address: '2001:db20::/32'
+ - address: '2001:db30::/32'
+ - area_id: '3'
+ range:
+ - address: '2001:db40::/32'
+ parameters:
+ router_id: '192.0.2.10'
+ redistribute:
+ - route_type: 'bgp'
+ state: merged
+
+ - 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)
+ register: result
+ vyos.vyos.vyos_ospfv3: *id001
+
+ - 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/tests/integration/targets/vyos_ospfv3/tests/cli/merged_update.yaml b/tests/integration/targets/vyos_ospfv3/tests/cli/merged_update.yaml
new file mode 100644
index 00000000..0d506b37
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv3/tests/cli/merged_update.yaml
@@ -0,0 +1,61 @@
+---
+- debug:
+ msg: START vyos_ospfv3 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
+ register: result
+ vyos.vyos.vyos_ospfv3: &id001
+ config:
+ areas:
+ - area_id: '2'
+ range:
+ - address: '2001:db10::/32'
+ - area_id: '3'
+ range:
+ - address: '2001:db40::/32'
+ - address: '2001:db70::/32'
+ parameters:
+ router_id: '192.0.2.10'
+ redistribute:
+ - route_type: 'bgp'
+ state: merged
+
+ - name: Assert that before dicts were correctly generated
+ assert:
+ that: "{{ populate == result['before'] }}"
+
+ - name: Assert that correct set of commands were generated
+ assert:
+ that:
+ - "{{ merged_update['commands'] | symmetric_difference(result['commands']) |length\
+ \ == 0 }}"
+
+ - name: Assert that after dicts was correctly generated
+ assert:
+ that:
+ - "{{ merged_update['after'] == result['after'] }}"
+
+ - name: Merge the provided configuration with the existing running configuration
+ (IDEMPOTENT)
+ register: result
+ vyos.vyos.vyos_ospfv3: *id001
+
+ - name: Assert that the previous task was idempotent
+ assert:
+ that:
+ - result['changed'] == false
+
+ - name: Assert that before dicts were correctly generated
+ assert:
+ that:
+ - "{{ merged_update['after'] == result['before'] }}"
+ always:
+
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_ospfv3/tests/cli/parsed.yaml b/tests/integration/targets/vyos_ospfv3/tests/cli/parsed.yaml
new file mode 100644
index 00000000..62870831
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv3/tests/cli/parsed.yaml
@@ -0,0 +1,15 @@
+---
+- debug:
+ msg: START vyos_ospfv3 parsed integration tests on connection={{ ansible_connection
+ }}
+
+- name: Parse externally provided ospfv3 config to agnostic model
+ register: result
+ vyos.vyos.vyos_ospfv3:
+ running_config: "{{ lookup('file', '_parsed_config.cfg') }}"
+ state: parsed
+
+- name: Assert that config was correctly parsed
+ assert:
+ that:
+ - "{{ parsed['after'] == result['parsed'] }}"
diff --git a/tests/integration/targets/vyos_ospfv3/tests/cli/rendered.yaml b/tests/integration/targets/vyos_ospfv3/tests/cli/rendered.yaml
new file mode 100644
index 00000000..3f714ced
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv3/tests/cli/rendered.yaml
@@ -0,0 +1,38 @@
+---
+- debug:
+ msg: START vyos_ospfv3 rendered integration tests on connection={{
+ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+
+- block:
+
+ - name: Structure provided configuration into device specific commands
+ register: result
+ vyos.vyos.vyos_ospfv3:
+ config:
+ redistribute:
+ - route_type: 'bgp'
+ parameters:
+ router_id: '192.0.2.10'
+ areas:
+ - area_id: '2'
+ export_list: 'export1'
+ import_list: 'import1'
+ range:
+ - address: '2001:db10::/32'
+ - address: '2001:db20::/32'
+ - address: '2001:db30::/32'
+ - area_id: '3'
+ range:
+ - address: '2001:db40::/32'
+ state: rendered
+
+ - name: Assert that correct set of commands were generated
+ assert:
+ that:
+ - "{{ rendered['commands'] | symmetric_difference(result['rendered'])\
+ \ |length == 0 }}"
+
+- debug:
+ msg: END vyos_ospfv3 rendered integration tests on connection={{ ansible_connection }}
diff --git a/tests/integration/targets/vyos_ospfv3/tests/cli/replaced.yaml b/tests/integration/targets/vyos_ospfv3/tests/cli/replaced.yaml
new file mode 100644
index 00000000..74d25dbf
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv3/tests/cli/replaced.yaml
@@ -0,0 +1,66 @@
+---
+- debug:
+ msg: START vyos_ospfv3 replaced integration tests on connection={{
+ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+
+- include_tasks: _populate.yaml
+
+- block:
+
+ - name: Replace device configurations of listed ospfv3 routes with provided configurations
+ register: result
+ vyos.vyos.vyos_ospfv3: &id001
+ config:
+ redistribute:
+ - route_type: 'bgp'
+ parameters:
+ router_id: '192.0.2.10'
+ areas:
+ - area_id: '2'
+ export_list: 'export1'
+ import_list: 'import1'
+
+ range:
+ - address: '2001:db10::/32'
+ - address: '2001:db30::/32'
+ - address: '2001:db50::/32'
+ - area_id: '4'
+ range:
+ - address: '2001:db60::/32'
+ state: replaced
+
+ - 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 ospfv3 routes with provided configurarions
+ (IDEMPOTENT)
+ register: result
+ vyos.vyos.vyos_ospfv3: *id001
+
+ - 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/tests/integration/targets/vyos_ospfv3/tests/cli/rtt.yaml b/tests/integration/targets/vyos_ospfv3/tests/cli/rtt.yaml
new file mode 100644
index 00000000..d8175540
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv3/tests/cli/rtt.yaml
@@ -0,0 +1,75 @@
+---
+- debug:
+ msg: START vyos_ospfv3 round trip integration tests on connection={{
+ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+
+- block:
+
+ - name: Apply the provided configuration (base config)
+ register: base_config
+ vyos.vyos.vyos_ospfv3:
+ config:
+ areas:
+ - area_id: '2'
+ export_list: 'export1'
+ import_list: 'import1'
+ range:
+ - address: '2001:db10::/32'
+ - address: '2001:db20::/32'
+ - address: '2001:db30::/32'
+ - area_id: '3'
+ range:
+ - address: '2001:db40::/32'
+ parameters:
+ router_id: '192.0.2.10'
+ redistribute:
+ - route_type: 'bgp'
+ state: merged
+
+ - name: Gather ospfv3 facts
+ vyos.vyos.vyos_facts:
+ gather_subset:
+ - default
+ gather_network_resources:
+ - ospfv3
+
+ - name: Apply the provided configuration (config to be reverted)
+ register: result
+ vyos.vyos.vyos_ospfv3:
+ config:
+ redistribute:
+ - route_type: 'bgp'
+ parameters:
+ router_id: '192.0.2.10'
+ areas:
+ - area_id: '2'
+ export_list: 'export1'
+ import_list: 'import1'
+
+ range:
+ - address: '2001:db10::/32'
+ - address: '2001:db30::/32'
+ - address: '2001:db50::/32'
+ - area_id: '4'
+ range:
+ - address: '2001:db60::/32'
+ state: replaced
+
+ - name: Assert that changes were applied
+ assert:
+ that: "{{ round_trip['after'] == result['after'] }}"
+
+ - name: Revert back to base config using facts round trip
+ register: revert
+ vyos.vyos.vyos_ospfv3:
+ config: "{{ ansible_facts['network_resources']['ospfv3'] }}"
+ state: replaced
+
+ - name: Assert that config was reverted
+ assert:
+ that: "{{ base_config['after'] == revert['after']}}"
+ always:
+
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_ospfv3/vars/main.yaml b/tests/integration/targets/vyos_ospfv3/vars/main.yaml
new file mode 100644
index 00000000..6ded89a8
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv3/vars/main.yaml
@@ -0,0 +1,142 @@
+---
+merged:
+ before: {}
+ commands:
+ - set protocols ospfv3 redistribute bgp
+ - set protocols ospfv3 parameters router-id '192.0.2.10'
+ - set protocols ospfv3 area 2 range 2001:db10::/32
+ - set protocols ospfv3 area 2 range 2001:db20::/32
+ - set protocols ospfv3 area 2 range 2001:db30::/32
+ - set protocols ospfv3 area '2'
+ - set protocols ospfv3 area 2 export-list export1
+ - set protocols ospfv3 area 2 import-list import1
+ - set protocols ospfv3 area '3'
+ - set protocols ospfv3 area 3 range 2001:db40::/32
+ after:
+ areas:
+ - area_id: '2'
+ export_list: 'export1'
+ import_list: 'import1'
+ range:
+ - address: '2001:db10::/32'
+ - address: '2001:db20::/32'
+ - address: '2001:db30::/32'
+ - area_id: '3'
+ range:
+ - address: '2001:db40::/32'
+ parameters:
+ router_id: '192.0.2.10'
+ redistribute:
+ - route_type: 'bgp'
+
+
+merged_update:
+ commands:
+ - set protocols ospfv3 area 3 range 2001:db70::/32
+ after:
+ areas:
+ - area_id: '2'
+ export_list: 'export1'
+ import_list: 'import1'
+ range:
+ - address: '2001:db10::/32'
+ - address: '2001:db20::/32'
+ - address: '2001:db30::/32'
+ - area_id: '3'
+ range:
+ - address: '2001:db40::/32'
+ - address: '2001:db70::/32'
+ parameters:
+ router_id: '192.0.2.10'
+ redistribute:
+ - route_type: 'bgp'
+
+populate:
+ areas:
+ - area_id: '2'
+ export_list: 'export1'
+ import_list: 'import1'
+ range:
+ - address: '2001:db10::/32'
+ - address: '2001:db20::/32'
+ - address: '2001:db30::/32'
+ - area_id: '3'
+ range:
+ - address: '2001:db40::/32'
+ parameters:
+ router_id: '192.0.2.10'
+ redistribute:
+ - route_type: 'bgp'
+replaced:
+ commands:
+ - delete protocols ospfv3 area 2 range 2001:db20::/32
+ - delete protocols ospfv3 area 3
+ - set protocols ospfv3 area 2 range 2001:db50::/32
+ - set protocols ospfv3 area '4'
+ - set protocols ospfv3 area 4 range 2001:db60::/32
+ after:
+ areas:
+ - area_id: '2'
+ export_list: 'export1'
+ import_list: 'import1'
+ range:
+ - address: '2001:db10::/32'
+ - address: '2001:db30::/32'
+ - address: '2001:db50::/32'
+ - area_id: '4'
+ range:
+ - address: '2001:db60::/32'
+ parameters:
+ router_id: '192.0.2.10'
+ redistribute:
+ - route_type: 'bgp'
+rendered:
+ commands:
+ - set protocols ospfv3 redistribute bgp
+ - set protocols ospfv3 parameters router-id '192.0.2.10'
+ - set protocols ospfv3 area 2 range 2001:db10::/32
+ - set protocols ospfv3 area 2 range 2001:db20::/32
+ - set protocols ospfv3 area 2 range 2001:db30::/32
+ - set protocols ospfv3 area '2'
+ - set protocols ospfv3 area 2 export-list export1
+ - set protocols ospfv3 area 2 import-list import1
+ - set protocols ospfv3 area '3'
+ - set protocols ospfv3 area 3 range 2001:db40::/32
+parsed:
+ after:
+ areas:
+ - area_id: '2'
+ export_list: 'export1'
+ import_list: 'import1'
+ range:
+ - address: '2001:db10::/32'
+ - address: '2001:db20::/32'
+ - address: '2001:db30::/32'
+ - area_id: '3'
+ range:
+ - address: '2001:db40::/32'
+ parameters:
+ router_id: '192.0.2.10'
+ redistribute:
+ - route_type: 'bgp'
+deleted:
+ commands:
+ - 'delete protocols ospfv3'
+ after: {}
+round_trip:
+ after:
+ areas:
+ - area_id: '2'
+ export_list: 'export1'
+ import_list: 'import1'
+ range:
+ - address: '2001:db10::/32'
+ - address: '2001:db30::/32'
+ - address: '2001:db50::/32'
+ - area_id: '4'
+ range:
+ - address: '2001:db60::/32'
+ parameters:
+ router_id: '192.0.2.10'
+ redistribute:
+ - route_type: 'bgp'
diff --git a/tests/integration/targets/vyos_static_routes/tests/cli/deleted.yaml b/tests/integration/targets/vyos_static_routes/tests/cli/deleted.yaml
deleted file mode 100644
index 7f098f52..00000000
--- a/tests/integration/targets/vyos_static_routes/tests/cli/deleted.yaml
+++ /dev/null
@@ -1,62 +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.
- register: result
- vyos.vyos.vyos_static_routes: &id001
- config:
-
- - address_families:
-
- - afi: ipv4
- routes:
-
- - dest: 192.0.2.32/28
-
- - afi: ipv6
- routes:
-
- - dest: 2001:db8:1000::/36
- state: deleted
-
- - 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)
- register: result
- vyos.vyos.vyos_static_routes: *id001
-
- - 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/tests/integration/targets/vyos_static_routes/tests/cli/deleted_nh.yaml b/tests/integration/targets/vyos_static_routes/tests/cli/deleted_nh.yaml
deleted file mode 100644
index f6075d26..00000000
--- a/tests/integration/targets/vyos_static_routes/tests/cli/deleted_nh.yaml
+++ /dev/null
@@ -1,68 +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.
- register: result
- vyos.vyos.vyos_static_routes: &id001
- 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
-
- - 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)
- register: result
- vyos.vyos.vyos_static_routes: *id001
-
- - 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/tests/integration/targets/vyos_static_routes/vars/main.yaml b/tests/integration/targets/vyos_static_routes/vars/main.yaml
index 93b875f2..6ce4cea6 100644
--- a/tests/integration/targets/vyos_static_routes/vars/main.yaml
+++ b/tests/integration/targets/vyos_static_routes/vars/main.yaml
@@ -94,31 +94,7 @@ rendered:
- 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
diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_ospfv2_config.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_ospfv2_config.cfg
new file mode 100644
index 00000000..297671b2
--- /dev/null
+++ b/tests/unit/modules/network/vyos/fixtures/vyos_ospfv2_config.cfg
@@ -0,0 +1,9 @@
+set protocols ospf area 12 area-type normal
+set protocols ospf area 12 authentication plaintext-password
+set protocols ospf area 12 shortcut enable
+set protocols ospf area 14 range 192.0.13.0/24 cost 10
+set protocols ospf area 14 range 192.0.13.0/24
+set protocols ospf area 14 range 192.0.14.0/24 cost 12
+set protocols ospf area 14 range 192.0.14.0/24
+set protocols ospf area 14 area-type stub default-cost 20
+set protocols ospf area 14 network 192.0.12.0/24
diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_ospfv3_config.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_ospfv3_config.cfg
new file mode 100644
index 00000000..060b9b33
--- /dev/null
+++ b/tests/unit/modules/network/vyos/fixtures/vyos_ospfv3_config.cfg
@@ -0,0 +1,6 @@
+set protocols ospfv3 area 12 export-list 'export1'
+set protocols ospfv3 area 12 import-list 'import1'
+set protocols ospfv3 area 12 range '2001:db11::/32'
+set protocols ospfv3 area 12 range '2001:db22::/32'
+set protocols ospfv3 area 12 range '2001:db33::/32'
+set protocols ospfv3 area 13 range '2001:db44::/32' \ No newline at end of file
diff --git a/tests/unit/modules/network/vyos/test_vyos_ospfv2.py b/tests/unit/modules/network/vyos/test_vyos_ospfv2.py
new file mode 100644
index 00000000..b825066d
--- /dev/null
+++ b/tests/unit/modules/network/vyos/test_vyos_ospfv2.py
@@ -0,0 +1,435 @@
+# (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 ansible_collections.vyos.vyos.tests.unit.compat.mock import patch
+from ansible_collections.vyos.vyos.plugins.modules import vyos_ospfv2
+from ansible_collections.vyos.vyos.tests.unit.modules.utils import (
+ set_module_args,
+)
+from .vyos_module import TestVyosModule, load_fixture
+
+
+class TestVyosFirewallRulesModule(TestVyosModule):
+
+ module = vyos_ospfv2
+
+ def setUp(self):
+ super(TestVyosFirewallRulesModule, self).setUp()
+ self.mock_get_config = patch(
+ "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config"
+ )
+ self.get_config = self.mock_get_config.start()
+
+ self.mock_load_config = patch(
+ "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config"
+ )
+ self.load_config = self.mock_load_config.start()
+
+ self.mock_get_resource_connection_config = patch(
+ "ansible_collections.ansible.netcommon.plugins.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_collections.ansible.netcommon.plugins.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_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospfv2.ospfv2.Ospfv2Facts.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, transport="cli", filename=None):
+ if filename is None:
+ filename = "vyos_ospfv2_config.cfg"
+
+ def load_from_file(*args, **kwargs):
+ output = load_fixture(filename)
+ return output
+
+ self.execute_show_command.side_effect = load_from_file
+
+ def test_vyos_ospfv2_merged_new_config(self):
+ set_module_args(
+ dict(
+ config=dict(
+ log_adjacency_changes="detail",
+ mpls_te=dict(enabled=True, router_address="192.0.11.11"),
+ auto_cost=dict(reference_bandwidth=2),
+ areas=[
+ dict(
+ area_id="2",
+ area_type=dict(normal=True),
+ authentication="plaintext-password",
+ shortcut="enable",
+ ),
+ dict(
+ area_id="4",
+ area_type=dict(stub=dict(default_cost=10)),
+ network=[dict(address="192.0.2.0/24"),],
+ range=[
+ dict(address="192.0.3.0/24", cost=10),
+ dict(address="192.0.4.0/24", cost=12),
+ ],
+ ),
+ ],
+ ),
+ state="merged",
+ )
+ )
+ commands = [
+ "set protocols ospf mpls-te enable",
+ "set protocols ospf mpls-te router-address '192.0.11.11'",
+ "set protocols ospf auto-cost reference-bandwidth '2'",
+ "set protocols ospf log-adjacency-changes 'detail'",
+ "set protocols ospf area '2'",
+ "set protocols ospf area 2 authentication plaintext-password",
+ "set protocols ospf area 2 shortcut enable",
+ "set protocols ospf area 2 area-type normal",
+ "set protocols ospf area 4 range 192.0.3.0/24 cost 10",
+ "set protocols ospf area 4 range 192.0.3.0/24",
+ "set protocols ospf area 4 range 192.0.4.0/24 cost 12",
+ "set protocols ospf area 4 range 192.0.4.0/24",
+ "set protocols ospf area 4 area-type stub default-cost 10",
+ "set protocols ospf area '4'",
+ "set protocols ospf area 4 network 192.0.2.0/24",
+ ]
+ self.execute_module(changed=True, commands=commands)
+
+ def test_vyos_ospfv2_merged_idem(self):
+ set_module_args(
+ dict(
+ config=dict(
+ areas=[
+ dict(
+ area_id="12",
+ area_type=dict(normal=True),
+ authentication="plaintext-password",
+ shortcut="enable",
+ ),
+ dict(
+ area_id="14",
+ area_type=dict(stub=dict(default_cost=20)),
+ network=[dict(address="192.0.12.0/24"),],
+ range=[
+ dict(address="192.0.13.0/24", cost=10),
+ dict(address="192.0.14.0/24", cost=12),
+ ],
+ ),
+ ],
+ ),
+ state="merged",
+ )
+ )
+ self.execute_module(changed=False, commands=[])
+
+ def test_vyos_ospfv2_merged_update_existing(self):
+ set_module_args(
+ dict(
+ config=dict(
+ areas=[
+ dict(
+ area_id="12",
+ area_type=dict(normal=True),
+ authentication="plaintext-password",
+ shortcut="enable",
+ ),
+ dict(
+ area_id="14",
+ area_type=dict(stub=dict(set=False)),
+ network=[
+ dict(address="192.0.12.0/24"),
+ dict(address="192.0.22.0/24"),
+ ],
+ range=[
+ dict(address="192.0.13.0/24", cost=10),
+ dict(address="192.0.14.0/24", cost=12),
+ ],
+ ),
+ ],
+ ),
+ state="merged",
+ )
+ )
+ commands = [
+ "delete protocols ospf area 14 area-type stub",
+ "set protocols ospf area 14 network 192.0.22.0/24",
+ ]
+ self.execute_module(changed=True, commands=commands)
+
+ def test_vyos_ospfv2_replaced(self):
+ set_module_args(
+ dict(
+ config=dict(
+ log_adjacency_changes="detail",
+ mpls_te=dict(enabled=True, router_address="192.0.11.11"),
+ auto_cost=dict(reference_bandwidth=2),
+ areas=[
+ dict(
+ area_id="12",
+ area_type=dict(normal=True),
+ authentication="plaintext-password",
+ shortcut="enable",
+ ),
+ dict(
+ area_id="15",
+ area_type=dict(stub=dict(default_cost=10)),
+ network=[dict(address="192.0.12.0/24"),],
+ range=[
+ dict(address="192.0.13.0/24", cost=10),
+ dict(address="192.0.14.0/24", cost=12),
+ dict(address="192.0.15.0/24", cost=14),
+ ],
+ ),
+ ],
+ ),
+ state="replaced",
+ )
+ )
+ commands = [
+ "set protocols ospf mpls-te enable",
+ "set protocols ospf mpls-te router-address '192.0.11.11'",
+ "set protocols ospf auto-cost reference-bandwidth '2'",
+ "set protocols ospf log-adjacency-changes 'detail'",
+ "delete protocols ospf area 14",
+ "set protocols ospf area 15 range 192.0.13.0/24 cost 10",
+ "set protocols ospf area 15 range 192.0.13.0/24",
+ "set protocols ospf area 15 range 192.0.14.0/24 cost 12",
+ "set protocols ospf area 15 range 192.0.14.0/24",
+ "set protocols ospf area 15 range 192.0.15.0/24 cost 14",
+ "set protocols ospf area 15 range 192.0.15.0/24",
+ "set protocols ospf area 15 area-type stub default-cost 10",
+ "set protocols ospf area '15'",
+ "set protocols ospf area 15 network 192.0.12.0/24",
+ ]
+ self.execute_module(changed=True, commands=commands)
+
+ def test_vyos_ospfv2_replaced_idem(self):
+ set_module_args(
+ dict(
+ config=dict(
+ areas=[
+ dict(
+ area_id="12",
+ area_type=dict(normal=True),
+ authentication="plaintext-password",
+ shortcut="enable",
+ ),
+ dict(
+ area_id="14",
+ area_type=dict(stub=dict(default_cost=20)),
+ network=[dict(address="192.0.12.0/24"),],
+ range=[
+ dict(address="192.0.13.0/24", cost=10),
+ dict(address="192.0.14.0/24", cost=12),
+ ],
+ ),
+ ],
+ ),
+ state="replaced",
+ )
+ )
+ self.execute_module(changed=False, commands=[])
+
+ def test_vyos_ospfv2_deleted_no_config(self):
+ set_module_args(dict(config=None, state="deleted"))
+ commands = ["delete protocols ospf"]
+ self.execute_module(changed=True, commands=commands)
+
+ def test_vyos_ospfv2_gathered(self):
+ set_module_args(dict(state="gathered"))
+ result = self.execute_module(
+ changed=False, filename="vyos_ospfv2_config.cfg"
+ )
+ gather_dict = {
+ "areas": [
+ {
+ "area_id": "2",
+ "area_type": {"normal": True},
+ "authentication": "plaintext-password",
+ "shortcut": "enable",
+ },
+ {
+ "area_id": "14",
+ "area_type": {"stub": {"default_cost": 20, "set": True}},
+ "network": [{"address": "192.0.12.0/24"}],
+ "range": [
+ {"address": "192.0.13.0/24", "cost": 10},
+ {"address": "192.0.14.0/24", "cost": 12},
+ ],
+ },
+ ],
+ }
+ self.assertEqual(sorted(gather_dict), sorted(result["gathered"]))
+
+ def test_vyos_ospfv2_parsed(self):
+ parsed_str = """set protocols ospf area 2 area-type 'normal'
+ set protocols ospf area 2 authentication 'plaintext-password'
+ set protocols ospf area 2 shortcut 'enable'
+ set protocols ospf area 3 area-type 'nssa'
+ set protocols ospf area 4 area-type stub default-cost '20'
+ set protocols ospf area 4 network '192.0.2.0/24'
+ set protocols ospf area 4 range 192.0.3.0/24 cost '10'
+ set protocols ospf area 4 range 192.0.4.0/24 cost '12'
+ set protocols ospf default-information originate 'always'
+ set protocols ospf default-information originate metric '10'
+ set protocols ospf default-information originate metric-type '2'
+set protocols ospf auto-cost reference-bandwidth '2'
+set protocols ospf default-information originate route-map 'ingress'
+set protocols ospf log-adjacency-changes 'detail'
+set protocols ospf max-metric router-lsa 'administrative'
+set protocols ospf max-metric router-lsa on-shutdown '10'
+set protocols ospf max-metric router-lsa on-startup '10'
+set protocols ospf mpls-te 'enable'
+set protocols ospf mpls-te router-address '192.0.11.11'
+set protocols ospf neighbor 192.0.11.12 poll-interval '10'
+set protocols ospf neighbor 192.0.11.12 priority '2'
+set protocols ospf parameters abr-type 'cisco'
+set protocols ospf parameters 'opaque-lsa'
+set protocols ospf parameters 'rfc1583-compatibility'
+set protocols ospf parameters router-id '192.0.1.1'
+set protocols ospf passive-interface 'eth1'
+set protocols ospf passive-interface 'eth2'
+set protocols ospf redistribute bgp metric '10'
+set protocols ospf redistribute bgp metric-type '2'"""
+ set_module_args(dict(running_config=parsed_str, state="parsed"))
+ result = self.execute_module(changed=False)
+ parsed_list = {
+ "areas": [
+ {
+ "area_id": "2",
+ "area_type": {"normal": True},
+ "authentication": "plaintext-password",
+ "shortcut": "enable",
+ },
+ {"area_id": "3", "area_type": {"nssa": {"set": True}}},
+ {
+ "area_id": "4",
+ "area_type": {"stub": {"default_cost": 20, "set": True}},
+ "network": [{"address": "192.0.2.0/24"}],
+ "range": [
+ {"address": "192.0.3.0/24", "cost": 10},
+ {"address": "192.0.4.0/24", "cost": 12},
+ ],
+ },
+ ],
+ "auto_cost": {"reference_bandwidth": 2},
+ "default_information": {
+ "originate": {
+ "always": True,
+ "metric": 10,
+ "metric_type": 2,
+ "route_map": "ingress",
+ }
+ },
+ "log_adjacency_changes": "detail",
+ "max_metric": {
+ "router_lsa": {
+ "administrative": True,
+ "on_shutdown": 10,
+ "on_startup": 10,
+ }
+ },
+ "mpls_te": {"enabled": True, "router_address": "192.0.11.11"},
+ "neighbor": [
+ {
+ "neighbor_id": "192.0.11.12",
+ "poll_interval": 10,
+ "priority": 2,
+ }
+ ],
+ "parameters": {
+ "abr_type": "cisco",
+ "opaque_lsa": True,
+ "rfc1583_compatibility": True,
+ "router_id": "192.0.1.1",
+ },
+ "passive_interface": ["eth2", "eth1"],
+ "redistribute": [
+ {"metric": 10, "metric_type": 2, "route_type": "bgp"}
+ ],
+ }
+ self.assertEqual(sorted(parsed_list), sorted(result["parsed"]))
+
+ def test_vyos_ospfv2_rendered(self):
+ set_module_args(
+ dict(
+ config=dict(
+ log_adjacency_changes="detail",
+ mpls_te=dict(enabled=True, router_address="192.0.11.11"),
+ auto_cost=dict(reference_bandwidth=2),
+ areas=[
+ dict(
+ area_id="2",
+ area_type=dict(normal=True),
+ authentication="plaintext-password",
+ shortcut="enable",
+ ),
+ dict(
+ area_id="4",
+ area_type=dict(stub=dict(default_cost=10)),
+ network=[dict(address="192.0.2.0/24"),],
+ range=[
+ dict(address="192.0.3.0/24", cost=10),
+ dict(address="192.0.4.0/24", cost=12),
+ ],
+ ),
+ ],
+ ),
+ state="rendered",
+ )
+ )
+ commands = [
+ "set protocols ospf mpls-te enable",
+ "set protocols ospf mpls-te router-address '192.0.11.11'",
+ "set protocols ospf auto-cost reference-bandwidth '2'",
+ "set protocols ospf log-adjacency-changes 'detail'",
+ "set protocols ospf area '2'",
+ "set protocols ospf area 2 authentication plaintext-password",
+ "set protocols ospf area 2 shortcut enable",
+ "set protocols ospf area 2 area-type normal",
+ "set protocols ospf area 4 range 192.0.3.0/24 cost 10",
+ "set protocols ospf area 4 range 192.0.3.0/24",
+ "set protocols ospf area 4 range 192.0.4.0/24 cost 12",
+ "set protocols ospf area 4 range 192.0.4.0/24",
+ "set protocols ospf area 4 area-type stub default-cost 10",
+ "set protocols ospf area '4'",
+ "set protocols ospf area 4 network 192.0.2.0/24",
+ ]
+ result = self.execute_module(changed=False)
+ self.assertEqual(
+ sorted(result["rendered"]), sorted(commands), result["rendered"]
+ )
diff --git a/tests/unit/modules/network/vyos/test_vyos_ospfv3.py b/tests/unit/modules/network/vyos/test_vyos_ospfv3.py
new file mode 100644
index 00000000..1d9cb3ab
--- /dev/null
+++ b/tests/unit/modules/network/vyos/test_vyos_ospfv3.py
@@ -0,0 +1,348 @@
+# (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 ansible_collections.vyos.vyos.tests.unit.compat.mock import patch
+from ansible_collections.vyos.vyos.plugins.modules import vyos_ospfv3
+from ansible_collections.vyos.vyos.tests.unit.modules.utils import (
+ set_module_args,
+)
+from .vyos_module import TestVyosModule, load_fixture
+
+
+class TestVyosFirewallRulesModule(TestVyosModule):
+
+ module = vyos_ospfv3
+
+ def setUp(self):
+ super(TestVyosFirewallRulesModule, self).setUp()
+ self.mock_get_config = patch(
+ "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config"
+ )
+ self.get_config = self.mock_get_config.start()
+
+ self.mock_load_config = patch(
+ "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config"
+ )
+ self.load_config = self.mock_load_config.start()
+
+ self.mock_get_resource_connection_config = patch(
+ "ansible_collections.ansible.netcommon.plugins.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_collections.ansible.netcommon.plugins.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_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospfv3.ospfv3.Ospfv3Facts.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, transport="cli", filename=None):
+ if filename is None:
+ filename = "vyos_ospfv3_config.cfg"
+
+ def load_from_file(*args, **kwargs):
+ output = load_fixture(filename)
+ return output
+
+ self.execute_show_command.side_effect = load_from_file
+
+ def test_vyos_ospfv3_merged_new_config(self):
+ set_module_args(
+ dict(
+ config=dict(
+ redistribute=[dict(route_type="bgp")],
+ parameters=dict(router_id="192.0.2.10"),
+ areas=[
+ dict(
+ area_id="2",
+ export_list="export1",
+ import_list="import1",
+ range=[
+ dict(address="2001:db10::/32"),
+ dict(address="2001:db20::/32"),
+ dict(address="2001:db30::/32"),
+ ],
+ ),
+ dict(
+ area_id="3",
+ range=[dict(address="2001:db40::/32"),],
+ ),
+ ],
+ ),
+ state="merged",
+ )
+ )
+ commands = [
+ "set protocols ospfv3 redistribute bgp",
+ "set protocols ospfv3 parameters router-id '192.0.2.10'",
+ "set protocols ospfv3 area 2 range 2001:db10::/32",
+ "set protocols ospfv3 area 2 range 2001:db20::/32",
+ "set protocols ospfv3 area 2 range 2001:db30::/32",
+ "set protocols ospfv3 area '2'",
+ "set protocols ospfv3 area 2 export-list export1",
+ "set protocols ospfv3 area 2 import-list import1",
+ "set protocols ospfv3 area '3'",
+ "set protocols ospfv3 area 3 range 2001:db40::/32",
+ ]
+ self.execute_module(changed=True, commands=commands)
+
+ def test_vyos_ospfv3_merged_idem(self):
+ set_module_args(
+ dict(
+ config=dict(
+ areas=[
+ dict(
+ area_id="12",
+ export_list="export1",
+ import_list="import1",
+ range=[
+ dict(address="2001:db11::/32"),
+ dict(address="2001:db22::/32"),
+ dict(address="2001:db33::/32"),
+ ],
+ ),
+ dict(
+ area_id="13",
+ range=[dict(address="2001:db44::/32"),],
+ ),
+ ],
+ ),
+ state="merged",
+ )
+ )
+ self.execute_module(changed=False, commands=[])
+
+ def test_vyos_ospfv3_merged_update_existing(self):
+ set_module_args(
+ dict(
+ config=dict(
+ redistribute=[dict(route_type="bgp")],
+ parameters=dict(router_id="192.0.2.10"),
+ areas=[
+ dict(
+ area_id="12",
+ export_list="export1",
+ import_list="import1",
+ range=[
+ dict(address="2001:db11::/32"),
+ dict(address="2001:db22::/32"),
+ dict(address="2001:db33::/32"),
+ ],
+ ),
+ dict(
+ area_id="13",
+ range=[
+ dict(address="2001:db44::/32"),
+ dict(address="2001:db55::/32"),
+ ],
+ ),
+ ],
+ ),
+ state="merged",
+ )
+ )
+ commands = [
+ "set protocols ospfv3 redistribute bgp",
+ "set protocols ospfv3 parameters router-id '192.0.2.10'",
+ "set protocols ospfv3 area 13 range 2001:db55::/32",
+ ]
+ self.execute_module(changed=True, commands=commands)
+
+ def test_vyos_ospfv3_replaced(self):
+ set_module_args(
+ dict(
+ config=dict(
+ redistribute=[dict(route_type="bgp")],
+ parameters=dict(router_id="192.0.2.10"),
+ areas=[
+ dict(
+ area_id="12",
+ export_list="export1",
+ import_list="import1",
+ range=[
+ dict(address="2001:db10::/32"),
+ dict(address="2001:db22::/32"),
+ dict(address="2001:db33::/32"),
+ ],
+ ),
+ dict(
+ area_id="14",
+ range=[dict(address="2001:db40::/32"),],
+ ),
+ ],
+ ),
+ state="replaced",
+ )
+ )
+ commands = [
+ "set protocols ospfv3 redistribute bgp",
+ "set protocols ospfv3 parameters router-id '192.0.2.10'",
+ "delete protocols ospfv3 area 12 range 2001:db11::/32",
+ "set protocols ospfv3 area 12 range 2001:db10::/32",
+ "delete protocols ospfv3 area 13",
+ "set protocols ospfv3 area '14'",
+ "set protocols ospfv3 area 14 range 2001:db40::/32",
+ ]
+ self.execute_module(changed=True, commands=commands)
+
+ def test_vyos_ospfv3_replaced_idem(self):
+ set_module_args(
+ dict(
+ config=dict(
+ areas=[
+ dict(
+ area_id="12",
+ export_list="export1",
+ import_list="import1",
+ range=[
+ dict(address="2001:db11::/32"),
+ dict(address="2001:db22::/32"),
+ dict(address="2001:db33::/32"),
+ ],
+ ),
+ dict(
+ area_id="13",
+ range=[dict(address="2001:db44::/32"),],
+ ),
+ ],
+ ),
+ state="replaced",
+ )
+ )
+ self.execute_module(changed=False, commands=[])
+
+ def test_vyos_ospfv3_deleted_no_config(self):
+ set_module_args(dict(config=None, state="deleted"))
+ commands = ["delete protocols ospfv3"]
+ self.execute_module(changed=True, commands=commands)
+
+ def test_vyos_ospfv3_gathered(self):
+ set_module_args(dict(state="gathered"))
+ result = self.execute_module(
+ changed=False, filename="vyos_ospfv3_config.cfg"
+ )
+ gather_dict = {
+ "areas": [
+ {
+ "area_id": "12",
+ "export_list": "export1",
+ "import_list": "import1",
+ "range": [
+ {"address": "2001:db11::/32"},
+ {"address": "2001:db22::/32"},
+ {"address": "2001:db33::/32"},
+ ],
+ },
+ {"area_id": "13", "range": [{"address": "2001:db44::/32"}]},
+ ],
+ }
+ self.assertEqual(sorted(gather_dict), sorted(result["gathered"]))
+
+ def test_vyos_ospfv3_parsed(self):
+ parsed_str = """set protocols ospfv3 area 2 export-list 'export1'
+set protocols ospfv3 area 2 import-list 'import1'
+set protocols ospfv3 area 2 range '2001:db10::/32'
+set protocols ospfv3 area 2 range '2001:db20::/32'
+set protocols ospfv3 area 2 range '2001:db30::/32'
+set protocols ospfv3 area 3 range '2001:db40::/32'
+set protocols ospfv3 parameters router-id '192.0.2.10'
+set protocols ospfv3 redistribute 'bgp'"""
+ set_module_args(dict(running_config=parsed_str, state="parsed"))
+ result = self.execute_module(changed=False)
+ parsed_dict = {
+ "areas": [
+ {
+ "area_id": "2",
+ "export_list": "export1",
+ "import_list": "import1",
+ "range": [
+ {"address": "2001:db10::/32"},
+ {"address": "2001:db20::/32"},
+ {"address": "2001:db30::/32"},
+ ],
+ },
+ {"area_id": "3", "range": [{"address": "2001:db40::/32"}]},
+ ],
+ "parameters": {"router_id": "192.0.2.10"},
+ "redistribute": [{"route_type": "bgp"}],
+ }
+ self.assertEqual(sorted(parsed_dict), sorted(result["parsed"]))
+
+ def test_vyos_ospfv3_rendered(self):
+ set_module_args(
+ dict(
+ config=dict(
+ redistribute=[dict(route_type="bgp")],
+ parameters=dict(router_id="192.0.2.10"),
+ areas=[
+ dict(
+ area_id="2",
+ export_list="export1",
+ import_list="import1",
+ range=[
+ dict(address="2001:db10::/32"),
+ dict(address="2001:db20::/32"),
+ dict(address="2001:db30::/32"),
+ ],
+ ),
+ dict(
+ area_id="3",
+ range=[dict(address="2001:db40::/32"),],
+ ),
+ ],
+ ),
+ state="rendered",
+ )
+ )
+ commands = [
+ "set protocols ospfv3 redistribute bgp",
+ "set protocols ospfv3 parameters router-id '192.0.2.10'",
+ "set protocols ospfv3 area 2 range 2001:db10::/32",
+ "set protocols ospfv3 area 2 range 2001:db20::/32",
+ "set protocols ospfv3 area 2 range 2001:db30::/32",
+ "set protocols ospfv3 area '2'",
+ "set protocols ospfv3 area 2 export-list export1",
+ "set protocols ospfv3 area 2 import-list import1",
+ "set protocols ospfv3 area '3'",
+ "set protocols ospfv3 area 3 range 2001:db40::/32",
+ ]
+ result = self.execute_module(changed=False)
+ self.assertEqual(
+ sorted(result["rendered"]), sorted(commands), result["rendered"]
+ )
diff --git a/tests/unit/modules/network/vyos/test_vyos_static_routes.py b/tests/unit/modules/network/vyos/test_vyos_static_routes.py
index 3646d610..85c08422 100644
--- a/tests/unit/modules/network/vyos/test_vyos_static_routes.py
+++ b/tests/unit/modules/network/vyos/test_vyos_static_routes.py
@@ -277,17 +277,9 @@ class TestVyosStaticRoutesModule(TestVyosModule):
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")]
- )
- ]
- )
- ],
+ config=[dict(address_families=[dict(afi="ipv4")])],
state="deleted",
)
)
- commands = ["delete protocols static route 192.0.2.32/28"]
+ commands = ["delete protocols static route"]
self.execute_module(changed=True, commands=commands)
diff --git a/tests/unit/modules/network/vyos/vyos_module.py b/tests/unit/modules/network/vyos/vyos_module.py
index fb15c715..49d46522 100644
--- a/tests/unit/modules/network/vyos/vyos_module.py
+++ b/tests/unit/modules/network/vyos/vyos_module.py
@@ -60,6 +60,7 @@ class TestVyosModule(ModuleTestCase):
commands=None,
sort=True,
defaults=False,
+ filename=None,
):
self.load_fixtures(commands)