Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support configuring area interfaces for OSPFv3 #217

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/ospfv3_area_interface.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- Support configuring area interfaces for OSPFv3.
38 changes: 38 additions & 0 deletions docs/vyos.vyos.vyos_ospfv3_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,44 @@ Parameters
<div>Name of import-list.</div>
</td>
</tr>
<tr>
<td class="elbow-placeholder"></td>
<td class="elbow-placeholder"></td>
<td colspan="2">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>interface</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">list</span>
/ <span style="color: purple">elements=dictionary</span>
</div>
</td>
<td>
</td>
<td>
<div>OSPFV3 interfaces.</div>
<div style="font-size: small; color: darkgreen"><br/>aliases: interfaces</div>
</td>
</tr>
<tr>
<td class="elbow-placeholder"></td>
<td class="elbow-placeholder"></td>
<td class="elbow-placeholder"></td>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>name</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">string</span>
</div>
</td>
<td>
</td>
<td>
<div>Interface name.</div>
</td>
</tr>

<tr>
<td class="elbow-placeholder"></td>
<td class="elbow-placeholder"></td>
Expand Down
6 changes: 6 additions & 0 deletions plugins/module_utils/network/vyos/argspec/ospfv3/ospfv3.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ def __init__(self, **kwargs):
"area_id": {"type": "str"},
"export_list": {"type": "str"},
"import_list": {"type": "str"},
"interface": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a new key, the alias is not required? The key can just be interfaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module is developed in a way that the key name is used to form the cli command. Changing it to interfaces leads to a lot of existing code/key name changes. I am planning to take it up as a separate PR, in which I want to work on changing all the key names, into plural forms, whose values are of type list.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GomathiselviS Does it have interface in the facts or the plural one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is interface and so is range and other list elements.

"aliases": ["interfaces"],
"type": "list",
"elements": "dict",
"options": {"name": {"type": "str"}},
},
"range": {
"elements": "dict",
"options": {
Expand Down
21 changes: 12 additions & 9 deletions plugins/module_utils/network/vyos/config/ospfv3/ospfv3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 []
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 5 additions & 0 deletions plugins/module_utils/network/vyos/facts/ospfv3/ospfv3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions plugins/modules/vyos_ospfv3.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@
import_list:
description: Name of import-list.
type: str
interface:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

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
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/modules/network/vyos/test_vyos_ospfv3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
),
],
),
Expand All @@ -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'",
Expand All @@ -141,7 +142,7 @@ def test_vyos_ospfv3_merged_idem(self):
area_id="13",
range=[dict(address="2001:db44::/32")],
),
],
]
),
state="merged",
)
Expand Down Expand Up @@ -240,7 +241,7 @@ def test_vyos_ospfv3_replaced_idem(self):
area_id="13",
range=[dict(address="2001:db44::/32")],
),
],
]
),
state="replaced",
)
Expand Down Expand Up @@ -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"]))

Expand Down Expand Up @@ -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")]
),
],
),
Expand Down