-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
schema/context: restore some backlinks support
In libyang v1 the schema nodes had a backlinks member to be able to look up dependents of the node. SONiC depends on this to provide functionality it uses and it needs to be exposed via the python module. In theory, exposing the 'dfs' functions could make this work, but it would likely be cost prohibitive since walking the tree would be expensive to create a python node for evaluation in native python. Instead this PR depends on the this libyang PR: CESNET/libyang#2352 And adds thin wrappers. This implementation provides 2 python functions: * Context.find_backlinks_paths() - This function can take the path of the base node and find all dependents. If no path is specified, then it will return all nodes that contain a leafref reference. * Context.find_leafref_path_target_paths() - This function takes an xpath, then returns all target nodes the xpath may reference. Typically only one will be returned, but multiples may be in the case of a union. A user can build a cache by combining Context.find_backlinks_paths() with no path set and building a reverse table using Context.find_leafref_path_target_paths() Signed-off-by: Brad House <[email protected]>
- Loading branch information
Showing
5 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module yolo-leafref-search-extmod { | ||
yang-version 1.1; | ||
namespace "urn:yang:yolo:leafref-search-extmod"; | ||
prefix leafref-search-extmod; | ||
|
||
import wtf-types { prefix types; } | ||
|
||
import yolo-leafref-search { | ||
prefix leafref-search; | ||
} | ||
|
||
revision 2025-02-11 { | ||
description | ||
"Initial version."; | ||
} | ||
|
||
list my_extref_list { | ||
key my_leaf_string; | ||
leaf my_leaf_string { | ||
type string; | ||
} | ||
leaf my_extref { | ||
type leafref { | ||
path "/leafref-search:my_list/leafref-search:my_leaf_string"; | ||
} | ||
} | ||
leaf my_extref_union { | ||
type union { | ||
type leafref { | ||
path "/leafref-search:my_list/leafref-search:my_leaf_string"; | ||
} | ||
type leafref { | ||
path "/leafref-search:my_list/leafref-search:my_leaf_number"; | ||
} | ||
type types:number; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module yolo-leafref-search { | ||
yang-version 1.1; | ||
namespace "urn:yang:yolo:leafref-search"; | ||
prefix leafref-search; | ||
|
||
import wtf-types { prefix types; } | ||
|
||
revision 2025-02-11 { | ||
description | ||
"Initial version."; | ||
} | ||
|
||
list my_list { | ||
key my_leaf_string; | ||
leaf my_leaf_string { | ||
type string; | ||
} | ||
leaf my_leaf_number { | ||
description | ||
"A number."; | ||
type types:number; | ||
} | ||
} | ||
|
||
leaf refstr { | ||
type leafref { | ||
path "../my_list/my_leaf_string"; | ||
} | ||
} | ||
|
||
leaf refnum { | ||
type leafref { | ||
path "../my_list/my_leaf_number"; | ||
} | ||
} | ||
} |