From 1862d9ba0c20831074408471f62d57793af147c6 Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Thu, 14 Oct 2021 12:17:56 -0400 Subject: [PATCH 1/2] Support configuring area interfaces for OSPFv3 Signed-off-by: GomathiselviS --- .../fragments/ospfv3_area_interface.yml | 3 +++ .../network/vyos/argspec/ospfv3/ospfv3.py | 6 ++++++ .../network/vyos/config/ospfv3/ospfv3.py | 21 +++++++++++-------- .../network/vyos/facts/ospfv3/ospfv3.py | 5 +++++ plugins/modules/vyos_ospfv3.py | 9 ++++++++ .../modules/network/vyos/test_vyos_ospfv3.py | 14 ++++++------- 6 files changed, 42 insertions(+), 16 deletions(-) create mode 100644 changelogs/fragments/ospfv3_area_interface.yml diff --git a/changelogs/fragments/ospfv3_area_interface.yml b/changelogs/fragments/ospfv3_area_interface.yml new file mode 100644 index 000000000..f0ee677b2 --- /dev/null +++ b/changelogs/fragments/ospfv3_area_interface.yml @@ -0,0 +1,3 @@ +--- +minor_changes: + - Support configuring area interfaces for OSPFv3. diff --git a/plugins/module_utils/network/vyos/argspec/ospfv3/ospfv3.py b/plugins/module_utils/network/vyos/argspec/ospfv3/ospfv3.py index 7fac36c36..4f9a17a2c 100644 --- a/plugins/module_utils/network/vyos/argspec/ospfv3/ospfv3.py +++ b/plugins/module_utils/network/vyos/argspec/ospfv3/ospfv3.py @@ -45,6 +45,12 @@ def __init__(self, **kwargs): "area_id": {"type": "str"}, "export_list": {"type": "str"}, "import_list": {"type": "str"}, + "interface": { + "aliases": ["interfaces"], + "type": "list", + "elements": "dict", + "options": {"name": {"type": "str"}}, + }, "range": { "elements": "dict", "options": { diff --git a/plugins/module_utils/network/vyos/config/ospfv3/ospfv3.py b/plugins/module_utils/network/vyos/config/ospfv3/ospfv3.py index c43dfe7a7..3c8a04510 100644 --- a/plugins/module_utils/network/vyos/config/ospfv3/ospfv3.py +++ b/plugins/module_utils/network/vyos/config/ospfv3/ospfv3.py @@ -40,14 +40,9 @@ class Ospfv3(ConfigBase): The vyos_ospfv3 class """ - gather_subset = [ - "!all", - "!min", - ] + gather_subset = ["!all", "!min"] - gather_network_resources = [ - "ospfv3", - ] + gather_network_resources = ["ospfv3"] def __init__(self, module): super(Ospfv3, self).__init__(module) @@ -277,10 +272,12 @@ def _render_list_dict_param(self, attr, want, have, cmd=None, opr=True): name = { "redistribute": "route_type", "range": "address", + "interface": "name", } leaf_dict = { "redistribute": ("route_map", "route_type"), "range": ("address", "advertise", "not_advertise"), + "interface": ("name"), } leaf = leaf_dict[attr] w = want.get(attr) or [] @@ -301,7 +298,7 @@ def _render_list_dict_param(self, attr, want, have, cmd=None, opr=True): and key in leaf and not _is_w_same(w_item, h_item, key) ): - if key == "route_type" or ( + if key in ["route_type", "name"] or ( key == "address" and "advertise" not in w_item and "not-advertise" not in w_item @@ -332,7 +329,7 @@ def _render_list_dict_param(self, attr, want, have, cmd=None, opr=True): elif ( not opr and key in leaf and not _in_target(h_item, key) ): - if key in ("route_type", "address"): + if key in ("route_type", "address", "name"): commands.append(cmd + attr + " " + str(val)) else: commands.append( @@ -416,6 +413,12 @@ def _render_areas(self, attr, want, have, opr=True): key, w_area, h_area, cmd, opr ) ) + elif key == "interface": + 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): diff --git a/plugins/module_utils/network/vyos/facts/ospfv3/ospfv3.py b/plugins/module_utils/network/vyos/facts/ospfv3/ospfv3.py index 414c65e9b..616081c7e 100644 --- a/plugins/module_utils/network/vyos/facts/ospfv3/ospfv3.py +++ b/plugins/module_utils/network/vyos/facts/ospfv3/ospfv3.py @@ -124,6 +124,10 @@ def parse_area(self, conf, area_id): rule = self.parse_attrib(conf, "area_id", match=area_id) r_sub = {"range": self.parse_attrib_list(conf, "range", "address")} rule.update(r_sub) + r_int = { + "interface": self.parse_attrib_list(conf, "interface", "name") + } + rule.update(r_int) return rule def parse_attrib(self, conf, param, match=None): @@ -136,6 +140,7 @@ def parse_attrib(self, conf, param, match=None): "area_id": ["export_list", "import_list"], "redistribute": ["route_map"], "range": ["advertise", "not_advertise"], + "interface": ["name"], "parameters": ["router_id"], } cfg_dict = self.parse_attr(conf, param_lst[param], match) diff --git a/plugins/modules/vyos_ospfv3.py b/plugins/modules/vyos_ospfv3.py index 9954ac769..c337d5801 100644 --- a/plugins/modules/vyos_ospfv3.py +++ b/plugins/modules/vyos_ospfv3.py @@ -61,6 +61,15 @@ import_list: description: Name of import-list. type: str + interface: + description: OSPFV3 interfaces. + aliases: ['interfaces'] + type: list + elements: dict + suboptions: + name: + description: Interface name. + type: str range: description: Summarize routes matching prefix (border routers only). type: list diff --git a/tests/unit/modules/network/vyos/test_vyos_ospfv3.py b/tests/unit/modules/network/vyos/test_vyos_ospfv3.py index ab38bf767..807ce920c 100644 --- a/tests/unit/modules/network/vyos/test_vyos_ospfv3.py +++ b/tests/unit/modules/network/vyos/test_vyos_ospfv3.py @@ -98,10 +98,10 @@ def test_vyos_ospfv3_merged_new_config(self): dict(address="2001:db20::/32"), dict(address="2001:db30::/32"), ], + interfaces=[dict(name="eth0")], ), dict( - area_id="3", - range=[dict(address="2001:db40::/32")], + area_id="3", range=[dict(address="2001:db40::/32")] ), ], ), @@ -115,6 +115,7 @@ def test_vyos_ospfv3_merged_new_config(self): "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 interface eth0", "set protocols ospfv3 area 2 export-list export1", "set protocols ospfv3 area 2 import-list import1", "set protocols ospfv3 area '3'", @@ -141,7 +142,7 @@ def test_vyos_ospfv3_merged_idem(self): area_id="13", range=[dict(address="2001:db44::/32")], ), - ], + ] ), state="merged", ) @@ -240,7 +241,7 @@ def test_vyos_ospfv3_replaced_idem(self): area_id="13", range=[dict(address="2001:db44::/32")], ), - ], + ] ), state="replaced", ) @@ -270,7 +271,7 @@ def test_vyos_ospfv3_gathered(self): ], }, {"area_id": "13", "range": [{"address": "2001:db44::/32"}]}, - ], + ] } self.assertEqual(sorted(gather_dict), sorted(result["gathered"])) @@ -322,8 +323,7 @@ def test_vyos_ospfv3_rendered(self): ], ), dict( - area_id="3", - range=[dict(address="2001:db40::/32")], + area_id="3", range=[dict(address="2001:db40::/32")] ), ], ), From 1e8f1b48738b61546f00e057c926b0943c0ff232 Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Thu, 14 Oct 2021 12:20:45 -0400 Subject: [PATCH 2/2] doc changes --- docs/vyos.vyos.vyos_ospfv3_module.rst | 38 +++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/docs/vyos.vyos.vyos_ospfv3_module.rst b/docs/vyos.vyos.vyos_ospfv3_module.rst index 6bad877e5..538de1684 100644 --- a/docs/vyos.vyos.vyos_ospfv3_module.rst +++ b/docs/vyos.vyos.vyos_ospfv3_module.rst @@ -116,6 +116,44 @@ Parameters
Name of import-list.
+ + + + +
+ interface + +
+ list + / elements=dictionary +
+ + + + +
OSPFV3 interfaces.
+

aliases: interfaces
+ + + + + + + +
+ name + +
+ string +
+ + + + +
Interface name.
+ + +