Skip to content
Snippets Groups Projects
Commit 7efb36eb authored by Karel van Klink's avatar Karel van Klink :smiley_cat:
Browse files

parse Nokia config diff, update requirements.txt

parent ffbccc7f
No related branches found
No related tags found
1 merge request!42less verbose Nokia output
...@@ -8,6 +8,7 @@ import uuid ...@@ -8,6 +8,7 @@ import uuid
import ansible_runner import ansible_runner
import requests import requests
import xmltodict import xmltodict
from dictdiffer import diff
from pydantic import BaseModel, HttpUrl from pydantic import BaseModel, HttpUrl
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -115,15 +116,14 @@ def _run_playbook_proc(job_id: str, playbook_path: str, extra_vars: dict, invent ...@@ -115,15 +116,14 @@ def _run_playbook_proc(job_id: str, playbook_path: str, extra_vars: dict, invent
# Juniper-specific # Juniper-specific
# Prevent the diff from being displayed twice, and only keep the formatted version. # Prevent the diff from being displayed twice, and only keep the formatted version.
task_result.pop("diff", None) task_result.pop("diff", None)
elif "before" in task_result["diff"] and "after" in task_result["diff"]: elif "diff" in task_result and "before" in task_result["diff"] and "after" in task_result["diff"]:
# Nokia-specific # Nokia-specific
# We have a chunk of Nokia config, and we would like to show the actual diff, not a full before and # We have a chunk of Nokia config, and we would like to show the actual diff, not a full before and
# after. This will take some extra steps. # after.
before_parsed = xmltodict.parse(task_result["diff"]["before"]) before_parsed = xmltodict.parse(task_result["diff"]["before"])
after_parsed = xmltodict.parse(task_result["diff"]["after"]) after_parsed = xmltodict.parse(task_result["diff"]["after"])
# Only leave the diff in the resulting output # Only leave the diff in the resulting output
task_result["diff"] = {k: v for k, v in after_parsed.items() if task_result["diff"] = list(diff(before_parsed, after_parsed))[0]
k not in before_parsed or v != before_parsed[k]}
if bool(task_result): if bool(task_result):
# Only add the event if there are any relevant keys left. # Only add the event if there are any relevant keys left.
......
...@@ -30,4 +30,6 @@ junos-eznc ...@@ -30,4 +30,6 @@ junos-eznc
jxmlease jxmlease
ncclient ncclient
ruamel.yaml ruamel.yaml
xmltodict xmltodict~=0.13.0
dictdiffer~=0.9.0
jmespath~=1.0.1
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment