Skip to content

Commit

Permalink
add support for multiple local-preference (#518)
Browse files Browse the repository at this point in the history
* add support for single local-preference

* multiple local-preference supported now and also added unit test

* chore: auto fixes from pre-commit.com hooks

* added changelog

* added support to handling multiple local-preference values

* chore: auto fixes from pre-commit.com hooks

* pushing local changes

* Updated documentation

* chore: auto fixes from pre-commit.com hooks

* Fix argument spec to match documentation requirements

* chore: auto fixes from pre-commit.com hooks

* pep8 sanity correction done

* fix duplicates keys

* added integration tests and change the variable of local_preference_number to metric_number

* chore: auto fixes from pre-commit.com hooks

* Update changelogs/fragments/local_preference.yaml

Co-authored-by: Sagar Paul <[email protected]>

* sanity test fixed

* chore: auto fixes from pre-commit.com hooks

* fixed True to true

* made some changes to integration tests

* Delete tests/integration/inventory.networking

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sagar Paul <[email protected]>
Co-authored-by: Vinay M <[email protected]>
  • Loading branch information
4 people authored Dec 30, 2024
1 parent b6ac704 commit 5070f32
Show file tree
Hide file tree
Showing 12 changed files with 1,109 additions and 94 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/local_preference.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- Adds support for setting local-preference with plus/minus values in route policies
909 changes: 846 additions & 63 deletions docs/cisco.iosxr.iosxr_route_maps_module.rst

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ class Route_mapsArgs(object): # pylint: disable=R0903
"igp_cost": {"type": "bool"},
},
},
"local_preference": {
"type": "list",
"elements": "dict",
"options": {
"multiply": {"type": "bool"},
"increment": {"type": "bool"},
"decrement": {"type": "bool"},
"metric_number": {
"type": "int",
"required": True,
},
},
},
"attribute_set": {"type": "str"},
"c_multicast_routing": {
"type": "dict",
Expand Down Expand Up @@ -322,6 +335,19 @@ class Route_mapsArgs(object): # pylint: disable=R0903
"type": "dict",
"options": {
"administrative_distance": {"type": "int"},
"local_preference": {
"type": "list",
"elements": "dict",
"options": {
"multiply": {"type": "bool"},
"increment": {"type": "bool"},
"decrement": {"type": "bool"},
"metric_number": {
"type": "int",
"required": True,
},
},
},
"aigp_metric": {
"type": "dict",
"options": {
Expand Down Expand Up @@ -556,6 +582,19 @@ class Route_mapsArgs(object): # pylint: disable=R0903
"type": "dict",
"options": {
"administrative_distance": {"type": "int"},
"local_preference": {
"type": "list",
"elements": "dict",
"options": {
"multiply": {"type": "bool"},
"increment": {"type": "bool"},
"decrement": {"type": "bool"},
"metric_number": {
"type": "int",
"required": True,
},
},
},
"aigp_metric": {
"type": "dict",
"options": {
Expand Down Expand Up @@ -795,6 +834,19 @@ class Route_mapsArgs(object): # pylint: disable=R0903
"type": "dict",
"options": {
"administrative_distance": {"type": "int"},
"local_preference": {
"type": "list",
"elements": "dict",
"options": {
"multiply": {"type": "bool"},
"increment": {"type": "bool"},
"decrement": {"type": "bool"},
"metric_number": {
"type": "int",
"required": True,
},
},
},
"aigp_metric": {
"type": "dict",
"options": {
Expand Down Expand Up @@ -1062,6 +1114,19 @@ class Route_mapsArgs(object): # pylint: disable=R0903
"type": "dict",
"options": {
"administrative_distance": {"type": "int"},
"local_preference": {
"type": "list",
"elements": "dict",
"options": {
"multiply": {"type": "bool"},
"increment": {"type": "bool"},
"decrement": {"type": "bool"},
"metric_number": {
"type": "int",
"required": True,
},
},
},
"aigp_metric": {
"type": "dict",
"options": {
Expand Down Expand Up @@ -1330,6 +1395,19 @@ class Route_mapsArgs(object): # pylint: disable=R0903
"type": "dict",
"options": {
"administrative_distance": {"type": "int"},
"local_preference": {
"type": "list",
"elements": "dict",
"options": {
"multiply": {"type": "bool"},
"increment": {"type": "bool"},
"decrement": {"type": "bool"},
"metric_number": {
"type": "int",
"required": True,
},
},
},
"aigp_metric": {
"type": "dict",
"options": {
Expand Down Expand Up @@ -1596,6 +1674,19 @@ class Route_mapsArgs(object): # pylint: disable=R0903
"type": "dict",
"options": {
"administrative_distance": {"type": "int"},
"local_preference": {
"type": "list",
"elements": "dict",
"options": {
"multiply": {"type": "bool"},
"increment": {"type": "bool"},
"decrement": {"type": "bool"},
"metric_number": {
"type": "int",
"required": True,
},
},
},
"aigp_metric": {
"type": "dict",
"options": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def __init__(self, module):
"unsuppress_route",
"remove",
"set.administrative_distance",
"set.local_preference",
"set.aigp_metric",
"set.attribute_set",
"set.c_multicast_routing",
Expand Down Expand Up @@ -122,7 +123,6 @@ def generate_commands(self):
# if state is merged, merge want onto have and then compare
if self.state == "merged":
wantd = dict_merge(haved, wantd)

for k, want in iteritems(wantd):
if self.state == "purged": # for purged state
if haved.pop(k, {}):
Expand Down
32 changes: 32 additions & 0 deletions plugins/module_utils/network/iosxr/rm_templates/route_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,38 @@ def __init__(self, lines=None, module=None):
},
},
},
{
"name": "set.local_preference",
"getval": re.compile(
r"""
\s*set\slocal-preference\s(?P<increment>\+)?
(?P<decrement>\-)?
(?P<multiply>\*)?
(?P<metric_number>\d+)
$""", re.VERBOSE,
),
"setval": "{% for pref in set.local_preference %}"
"set local-preference"
"{{ ' *' if pref.multiply|d(False) else '' }}"
"{{ ' +' if pref.increment|d(False) else '' }}"
"{{ ' -' if pref.decrement|d(False) else '' }}"
"{{ pref.metric_number|string }}\n"
"{% endfor %}",
"result": {
"policies": {
"set": {
"local_preference": [
{
"increment": "{{ not not increment }}",
"metric_number": "{{ metric_number}}",
"decrement": "{{ not not decrement }}",
"multiply": "{{ not not multiply }}",
},
],
},
},
},
},
{
"name": "set.aigp_metric",
"getval": re.compile(
Expand Down
18 changes: 18 additions & 0 deletions plugins/modules/iosxr_route_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,24 @@
administrative_distance:
description: Administrative Distance of the prefix, <1-255> 8 bit decimal numbe
type: int
local_preference:
description: List of local preference configurations
type: list
elements: dict
suboptions:
increment:
type: bool
description: "+ Increment the attribute with specified value"
decrement:
description: "- Decrement the attribute by specified value"
type: bool
metric_number:
description: "<0-4294967295> 32-bit decimal number"
type: int
required: true
multiply:
description: "* multiply the attribute by specified value"
type: bool
aigp_metric:
description: AIGP metric attribute
type: dict
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ route-policy SIMPLE_GLOBAL_ROUTE_POLICY
apply A_NEW_ROUTE_POLICY
set community (11011:1001) additive
set weight 20000
set local-preference +100
set local-preference -200
set local-preference *300
end-policy
!
route-policy SIMPLE_CONDITION_ROUTE_POLICY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
additive: true
community_name: (11011:1001)
weight: 20000
local_preference:
- increment: true
metric_number: 100
- decrement: true
metric_number: 200
- multiply: true
metric_number: 300
name: SIMPLE_GLOBAL_ROUTE_POLICY
- else_section:
global:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
additive: true
community_name: (11011:1001)
weight: 20000
local_preference:
- increment: true
metric_number: 100
- decrement: true
metric_number: 200
- multiply: true
metric_number: 300
name: SIMPLE_GLOBAL_ROUTE_POLICY
- else_section:
global:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
community:
community_name: test_comm_name
weight: 20000
local_preference:
- increment: true
metric_number: 100
- decrement: true
metric_number: 200
- multiply: true
metric_number: 300
name: SIMPLE_GLOBAL_ROUTE_POLICY_overridden
- else_section:
else_section:
Expand Down
Loading

0 comments on commit 5070f32

Please sign in to comment.