How to Perform a Diff within Cisco Genie PyATS

How to Perform a Diff within Cisco Genie PyATS

pyATS Tip:
Use Genie Diff to compare structured data and easily identify differences. It works with dictionaries, including structured output from Genie Parse and Genie Learn.

Below is an example of using Genie Diff to compare the results of a Genie Parse command:

from genie.utils.diff import Diff
from genie.testbed import load

testbed = load("testbed.yaml")
device = testbed.devices["router1"]
device.connect()

before = device.parse("show ip interface brief")
after = device.parse("show ip interface brief")

diff = Diff(before, after)
diff.findDiff()

if diff:
    print(diff)

# Output:
# +interface:
# +    GigabitEthernet2:
# +        status: up
# +        protocol: up
# -    GigabitEthernet3:
# -        status: down
# -        protocol: down

Subscribe to our newsletter and stay updated.

Don't miss anything. Get all the latest posts delivered straight to your inbox.
Great! Check your inbox and click the link to confirm your subscription.
Error! Please enter a valid email address!