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

[config_facts] Add port list member to PORTCHANNEL #7668

Merged
merged 1 commit into from
Mar 7, 2023
Merged
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
14 changes: 14 additions & 0 deletions ansible/library/config_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ def get_facts(config, namespace):

return results


def _add_member_list_to_portchannel(config_facts):
"""Add `member` field to PORTCHANNEL table."""
if "PORTCHANNEL" in config_facts and "PORTCHANNEL_MEMBER" in config_facts:
for pc, pc_config in config_facts["PORTCHANNEL"].items():
if pc in config_facts["PORTCHANNEL_MEMBER"]:
member_ports = list(config_facts["PORTCHANNEL_MEMBER"][pc].keys())
pc_config["members"] = member_ports


def main():
module = AnsibleModule(
argument_spec=dict(
Expand Down Expand Up @@ -163,6 +173,10 @@ def main():
elif m_args["source"] == "running":
config = get_running_config(module, namespace)
results = get_facts(config, namespace)

# NOTE: This is a workaround to allow getting port channel members from
# PORTCHANNEL table.
_add_member_list_to_portchannel(results)
module.exit_json(ansible_facts=results)
except Exception as e:
tb = traceback.format_exc()
Expand Down