12-06-2017 11:08 AM - edited 03-01-2019 04:03 AM
I have the following two models: network-topology is a list of sites and associate devices; vpn-service is a list of vpns and associated sites. How can I constrain the switch list in "vpn-service" to just the list of switches in "network-topology" associated with the current site? I am struggling with the proper syntax. Thanks in advance.
//* Module network-topology
- network-topology (list)
|
+- router-name (key)
|
+- switch (list)
|
+- switch-name (key)
//* Module vpn-service
- vpn-service (list)
|
+- vpn-name (key)
|
+- site (list)
|
+- router-name (key)
|
+- switch (list)
|
+- switch-name (key)
module network-topology {
list network-topology {
key "router-name"
tailf:info "Topology of Routers and Switches";
leaf router-name {
tailf:info "Site router name";
type leafref {
path "/ncs:devices/ncs:device/ncs:name";
}
}
list switch {
key switch-name;
tailf:info "The list of switches for a given router";
leaf switch-name {
tailf:info "The name of the router";
type leafref {
path "/ncs:devices/ncs:device/ncs:name";
}
}
}
}
}
///////////////////////////////////////////////////////////////////////////////
module vpn-service {
import network-topology {
prefix nettop;
}
list vpn-service {
key vpn-name;
leaf vpn-name {
type string;
}
list site {
key router-name;
leaf router-name {
tailf:info "Name of the Site Router";
// list of site routers identified in network-topology
type leafref {
path "/nettop:network-topology/nettop:router-name";
}
}
list switch {
key switch-name;
leaf switch-name {
tailf:info "Name of a Site Switch";
type leafref {
path "/nettop:network-topology/nettop:switch/nettop:switch-name";
}
//TBD need to constrain this to just the switches associated with the current site in network-topology
//must "/nettop:network-topology[network-topology:router-name = current()]"; // NOT RIGHT
}
}
}
}
}
Solved! Go to Solution.
12-06-2017 11:09 PM
Hi,
I think your must statement could look something of this sort:
current() = deref(current()/../../router-name)/../switch/switch-name
putting it in words, the right-hand side of the equation says:
current()/../../router-name - go two levels up from here and get the router-name of this site list entry.
deref this reference you have now, to get to the actual router-name on the list in topology.
From there, one level up, to get from topo/router-name to the list itself.
Then go to the list of switches and to the switch-name.
We then equate that to the current node, which should leave us only with the relevant leafs for selection.
I haven't tested it, but you can use the xpath.trace log to debug, in case I missed something.
Hope that helps!
Yftach
12-06-2017 11:09 PM
Hi,
I think your must statement could look something of this sort:
current() = deref(current()/../../router-name)/../switch/switch-name
putting it in words, the right-hand side of the equation says:
current()/../../router-name - go two levels up from here and get the router-name of this site list entry.
deref this reference you have now, to get to the actual router-name on the list in topology.
From there, one level up, to get from topo/router-name to the list itself.
Then go to the list of switches and to the switch-name.
We then equate that to the current node, which should leave us only with the relevant leafs for selection.
I haven't tested it, but you can use the xpath.trace log to debug, in case I missed something.
Hope that helps!
Yftach
12-08-2017 05:50 AM
Thanks Yftach! I had to add the prefix to network-topology, but your explanation was the key. This works:
must "current()=deref(current()/../../router-name/../nettop:switch/nettop:switch-name";
I still find xpath confusing, but am making progress.
12-09-2017 11:08 PM
Glad to hear you got it to work!
(I tend to agree those must statement tend to be confusing)
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide