From fe26b3f1955f30285c9390c70264b9785a336cfb Mon Sep 17 00:00:00 2001 From: Justin Jeffery Date: Thu, 16 Dec 2021 08:32:00 -0500 Subject: [PATCH] fix: Added reverse to intent compare and some more explanations --- examples/intent.py | 8 +++++++- ipfabric/intent.py | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/intent.py b/examples/intent.py index d4bba69..3d55f89 100644 --- a/examples/intent.py +++ b/examples/intent.py @@ -78,9 +78,15 @@ """ print() - compare = ipf.intent.compare_snapshot('$lastLocked') + compare = ipf.intent.compare_snapshot('$lastLocked', reverse=False) print(tabulate(compare, headers="keys")) """ + Current: The snapshot loaded into the intent class: + ipf.intent.load_intent('$last') + Other: The snapshot in the comparison: + ipf.intent.compare_snapshot('$prev', reverse=True) + Reverse (Default: False): Will flip current and other. Use when class is newest date and compare is an older date. + name id check current other diff -------------------------------------------- ---------- ------- --------- ------- ------ CDP/LLDP unidirectional 320633253 total 21 25 4 diff --git a/ipfabric/intent.py b/ipfabric/intent.py index 4f23868..748e99a 100644 --- a/ipfabric/intent.py +++ b/ipfabric/intent.py @@ -86,12 +86,12 @@ def get_results(self, intent: IntentCheck, color: Union[str, int], snapshot_id: return self.client.fetch_all(intent.api_endpoint, snapshot_id=snapshot_id, reports=intent.web_endpoint, filters={intent.column: ['color', 'eq', color]}) - def compare_snapshot(self, snapshot_id: str = None): + def compare_snapshot(self, snapshot_id: str = None, reverse: bool = False): new_intents = {i.name: i for i in self.get_intent_checks(snapshot_id)} comparison = list() for name, intent in new_intents.items(): old = self.intent_by_name[name].result - compare = old.compare(intent.result) + compare = intent.result.compare(old) if reverse else old.compare(intent.result) for desc, value in compare.items(): n = desc if desc != 'count' else 'total' comparison.append({"name": name, "id": intent.intent_id, "check": n, **value})