cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1024
Views
2
Helpful
7
Replies

How can I use a switch and interface specified from "choice" as list key?

ryan-hitch
Level 4
Level 4

I am trying to define a list of switches with interfaces based this off of Yftach Herzog's example here: Re: How can I reference existing interface types/interfaces/configured IP's in yang service model?

I want the key to include the interface, so that multiple interfaces can be specified, but am unsure how to reference the correct interface leaf. The following key throws an error: the key switch-interface does not reference an existing leaf" - I assume because switch-interface is a choice, not a leaf. What is the correct way to accomplish this?  Thanks!

list switch {

  key "name switch-interface";


  leaf name {

    type leafref {

      path "/ncs:services/ncs:device/ncs:name";

    }

  }


  choice switch-interface {

    case ios-FastEthernet {

      type leafref {

        path "deref(../name)/../ncs:config/ios:interface/ios:FastEthernet/ios:name";

      }

    }

    case ios-GigabitEthernet {

      type leafref {

        path "deref(../name)/../ncs:config/ios:interface/ios:GigabitEthernet/ios:name";

      }

    }

  }

}

7 Replies 7

Jan Lindblad
Cisco Employee
Cisco Employee

Choices are not legal as keys in YANG, so you have to change your model a bit. You could give each instance a string name that has no direct connection to the device name or anything else. Then have leafs pointing to devices, interfaces etc that are not keys.

Bummer. Thanks for the quick reply. I am trying to come up with an intuitive way for end users to select from a list of interfaces. Is there a way to specify a wildcard in a leafref? Something akin to:

"deref(../name)/../ncs:config/ios:interface/ios:*/ios:name"; rather than "deref(../name)/../ncs:config/ios:interface/ios:GigabitEthernet/ios:name";

Nope, afraid not.

If all interfaces were in a single list (like in the ietf-interfaces YANG module), this wouldn't be a problem, but the IOS YANG model is what it is, and you can't change that.

I'd say your options are:

- Live with the fact that interface name won't be part of the service instance key (easiest)

- If this is a modern XE device, you can switch to NETCONF NED management and use the IETF model. There all interfaces are in a single list. (experimental option)

- You can split your service into a two layer design, where the lower level service just normalizes the interface names, and the upper service is your current service, and which consumes a single list of interfaces. Sync-from will not populate interface names with this approach, so this is only really useful if we're in a scenario where sync-froms are rare (for high automation use cases)

- You can build a simple interface name transform in that makes all interfaces appear in a single list. (advanced)

Thanks for your quick responses. Sounds like I will have to go with option (1) for now, until I figure out how to do the split service or transform options that you mention as I am new to NSO/Yang. Unfortunately, from and end user perspecive it will add an extra text field to the model which serves no purpose other than to act as a key when the "switch-name interface-type interface-id" key would be much more elegant.

Our goal is to have NOC staff members use the new NSO 4.5 webui directly to add/remove/modify services (this service is specifically switch interface VLAN assignment - see the screenshot below). The new webui is fantastic and is SO CLOSE to being usable by NOC members directly rather than using NSO as a backend to another UI. The one hurdle we are having trouble overcoming is specifying a device interface as a string type is very limiting when presented directly to NOC staff. They understandably want a drop down of available interfaces to select from rather than a text box which requires them to identify an available interface using another tool and then type it manually into the NSO webui. Preferrably certain attributes would be displayed with each interface (such as interface description, VLAN assignment, or up/down status - similar to how the NSO cli displays interface descriptions using "show devices device <name> config ios:interface ?). All of this information is already in CDB and seemingly should be able to be referenced simply in a yang model. Any guidance is greatly appreciated. Thanks again for your help.

Screenshot (3).png

jcederqu, did you see this?

- You can build a simple interface name transform in that makes all interfaces appear in a single list. (advanced)

>>>

Jan, can this " simple interface name" transform dynamically and real time leafref-erincing when used in CLI or GUI?

Certainly. The question is what you do with all the other leafs, they probably need to be transformed as well, even if it's a 1:1 mapping.