I have a yang model with 3 input leaf nodes under a container.
input {
leaf ipv4 {
type inet:ipv4-address;
}
leaf interface {
type uint16;
}
leaf vpn {
type uint16;
}
}
There is another model that has the config of all the configured interfaces and VPNs on the device. I want that while configuring interfaces and vpn in my new model, the possible completions to show the configured values of interfaces/VPNs in the other model. How can I achieve that?
One way is to use YANG leafref statement (see RFC section) to configure leaf value as sort of “pointer” to other model you mention -> this will automatically do the completion for you without any extra coding/work.
Other way, without directly binding data on YANG level, is to implement completion callback as described in ConfD user guide section “Customizing CLI completion”.
Say, I have a master model that has the config of multiple interfaces configured under a specific VPN. There can be multiple such VPNs configured each containing multiple interfaces.
In my new model, I want the possible completions to show only those interfaces that are part of the vpn that I have configured in this new model.
In my new model(as mentioned in the original description) when I configure vpn 0 I want the possible completions for interface to show only ge0/0 and ge0/1.
I tried using something like this but didn’t help:
leaf interface {
type leafref {
path "/vpn/vpn-instance[$(vpn-id)]/interface/if-name";
}
}
where, “/vpn/vpn-instance/vpn-id” is the path in the master model containing the VPN config.
container vpn {
list vpn-instance {
key "vpn-id";
leaf vpn-id {
type uint16;
}
list interface {
key "if-name";
leaf if-name {
type string;
}
}
}
}
I think you need to do specific projection (key-name = value)…
Let’s assume that value of VPN you want to limit to is in leaf my-vpn that is sibling of interface.
Then, you need something like this:
leaf my-vpn {
type uint16;
}
leaf interface {
type leafref {
path "/vpn/vpn-instance[vpn-id = current()/../my-vpn]/interface/if-name";
}
}
For a myvpn, if I enter an if-name that is not part of the vpn-instance[myvpn]/interface/ then the CLI throws “illegal reference” error, which is expected. This confirms that the leafref path is correct.
But I still don’t see the possible completions of interface on ?
Although, if I set the type of myvpn as leafref to the path: “/vpn/vpn-instance/vpn-id” then I do see the possible completions of vpn-id.
I wonder why I don’t see the same behaviour with interface/if-name.