Skip to content

Commit

Permalink
updated_deprecation_method
Browse files Browse the repository at this point in the history
  • Loading branch information
Girish5tri committed Oct 18, 2024
1 parent 7aaf9fe commit 844c976
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 17 deletions.
28 changes: 14 additions & 14 deletions plugins/action/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ def run(self, tmp=None, task_vars=None):
% self._play_context.connection,
}

# Handle deprecated 'number' parameter
if "config" in self._task.args and self._task.args["config"] is not None:
config = self._task.args["config"]
if "neighbors" in config:
for neighbor in config["neighbors"]:
if "local_as" in neighbor:
if "number" in neighbor["local_as"]:
display.deprecated(
msg="DEPRECATED: The 'number' option in 'local_as' is deprecated, Use 'asn' instead.",
date="2027-01-01",
collection_name="cisco.ios",
)
neighbor["local_as"]["asn"] = str(neighbor["local_as"]["number"])
del neighbor["local_as"]["number"]
# # Handle deprecated 'number' parameter
# if "config" in self._task.args and self._task.args["config"] is not None:
# config = self._task.args["config"]
# if "neighbors" in config:
# for neighbor in config["neighbors"]:
# if "local_as" in neighbor:
# if "number" in neighbor["local_as"]:
# display.deprecated(
# msg="DEPRECATED: The 'number' option in 'local_as' is deprecated, Use 'asn' instead.",
# date="2027-01-01",
# collection_name="cisco.ios",
# )
# neighbor["local_as"]["asn"] = str(neighbor["local_as"]["number"])
# del neighbor["local_as"]["number"]

result = super(ActionModule, self).run(task_vars=task_vars)
if warnings:
Expand Down
36 changes: 33 additions & 3 deletions plugins/module_utils/network/ios/config/bgp_global/bgp_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ def execute_module(self):
:rtype: A dictionary
:returns: The result from module execution
"""
if self.want:
self.want = self.handle_deprecates(self.want)

if self.state not in ["parsed", "gathered"]:
#self.want = self.handle_deprecates(self.want)
self.generate_commands()
self.run_commands()
return self.result
Expand All @@ -160,8 +164,8 @@ def generate_commands(self):
"configuring new ASN".format(h_asn),
)

if self.want:
self.handle_deprecates(self.want)
self.want = self.handle_deprecates(self.want)
self.have = self.handle_deprecates(self.have)

for each in self.want, self.have:
self._bgp_global_list_to_dict(each)
Expand Down Expand Up @@ -193,6 +197,8 @@ def _compare(self, want, have):
the `want` and `have` data with the `parsers` defined
for the Bgp_global network resource.
"""
want = self.handle_deprecates(want)

self.generic_list_parsers = ["distributes", "aggregate_addresses", "networks"]

if self._has_bgp_inject_maps(want):
Expand Down Expand Up @@ -356,8 +362,10 @@ def _compare_neighbor_lists(self, want, have):
]

for name, w_neighbor in want.items():
w_neighbor = self.handle_deprecates(w_neighbor, is_nbr=True)
handle_shutdown_default = False
have_nbr = have.pop(name, {})
have_nbr = self.handle_deprecates(have_nbr, is_nbr=True)
want_route = w_neighbor.pop("route_maps", {})
have_route = have_nbr.pop("route_maps", {})
if (
Expand Down Expand Up @@ -459,5 +467,27 @@ def handle_deprecates(self, want, is_nbr=False):
else:
if "local_as" in want:
if "number" in want["local_as"]:
want["local_as"]["asn"] = want["local_as"].pop("number")
want["local_as"]["asn"] = str(want["local_as"].pop("number"))
return want


# def handle_deprecates(self, want, is_nbr=False):
# """
# Handles deprecated values post rewrite
# neighbor.route_map [dict] - neighbor.route_maps [list:dict]

# Args:
# want (_type_): Handle want attributes for deprecated values
# is_nbr (bool, optional): activates neighbor part on recursion. Defaults to False.
# """
# if not is_nbr:
# if want.get("neighbors"):
# _want_nbrs = want.get("neighbors", {})
# for nbr in _want_nbrs:
# nbr = self.handle_deprecates(nbr, is_nbr=True)
# else:
# if "local_as" in want:
# if "number" in want["local_as"]:
# want["local_as"]["asn"] = str(want["local_as"]["number"])
# del want["local_as"]["number"]
# return want

0 comments on commit 844c976

Please sign in to comment.