Skip to content

jdiff.utils.jmespath_parsers

jmespath expression parsers and related utilities.

This utility interfaces the custom jdiff jmespath expression with the jmespath library. From one expression defined in jdiff, we will derive two expressions: one expression that traverse the json output and get the evaluated bit of it, the second will target the reference key relative to the value to evaluate. More on README.md

jdiff.utils.jmespath_parsers.associate_key_of_my_value(paths, wanted_value)

Associate extracted field names with the values returned by the parsed JMESPath value path.

jdiff.utils.jmespath_parsers.jmespath_refkey_parser(path)

Get the jmespath reference key path from 'path' argument.

Reference key is define within $$ in 'path' and will be associated to the value/s to be evaluated. More on README.md.

Parameters:

Name Type Description Default
path str

"result[0].vrfs.default.peerList[*].[$peerAddress$,prefixesReceived]"

required

Return: "result[0].vrfs.default.peerList[*].[$peerAddress$]"

jdiff.utils.jmespath_parsers.jmespath_value_parser(path)

Extract the jmespath value path from 'path' argument.

This is required as we use custom anchors ($$) to identify the reference key. So the expression must be parsed and stripped of the reference key anchor. More info on README.md

Two combinations are possible based on where reference key is defined. See example below.

Parameters:

Name Type Description Default
path str

"result[0].vrfs.default.peerList[*].[$peerAddress$,prefixesReceived]"

required
path str

"result[0].$vrfs$.default.peerList[*].[peerAddress, prefixesReceived]"

required
Return

"result[0].vrfs.default.peerList[].[prefixesReceived]" "result[0].vrfs.default.peerList[].[peerAddress, prefixesReceived]"

jdiff.utils.jmespath_parsers.keys_cleaner(wanted_reference_keys)

Get every required reference key from output and build a dictionary from it.

jdiff.utils.jmespath_parsers.keys_values_zipper(list_of_reference_keys, wanted_value_with_key)

Build dictionary zipping keys with relative values.

jdiff.utils.jmespath_parsers.multi_reference_keys(jmspath, data)

Build a list of concatenated reference keys.

Parameters:

Name Type Description Default
jmspath str

"$$.peers.$$.*.ipv4.[accepted_prefixes]"

required
data dict

tests/mock/napalm_get_bgp_neighbors/multi_vrf.json

required

Returns (str): ["global.10.1.0.0", "global.10.2.0.0", "global.10.64.207.255", "global.7.7.7.7", "vpn.10.1.0.0", "vpn.10.2.0.0"]