cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
396
Views
2
Helpful
3
Replies

constrain list of devices associated with site

ryan-hitch
Level 4
Level 4

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
        }
      }
    }
  }
}

1 Accepted Solution

Accepted Solutions

yfherzog
Cisco Employee
Cisco Employee

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

View solution in original post

3 Replies 3

yfherzog
Cisco Employee
Cisco Employee

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

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.

Glad to hear you got it to work!

(I tend to agree those must statement tend to be confusing)