Can I build a data model for the following config list?
prefix network [nexthop] [ifname]
10.10.10.0 255.255.255.0 12.12.12.1
10.10.10.0 255.255.255.0 13.13.13.1
10.10.10.0 255.255.255.0 eth1
10.10.10.0 255.255.255.0 eth2
10.10.10.0 255.255.255.0 12.12.12.1 eth1
10.10.10.0 255.255.255.0 12.12.12.1 eth2
10.10.10.0 255.255.255.0 13.13.13.1 eth1
10.10.10.0 255.255.255.0 13.13.13.1 eth2
I’ved tried this model:
list demo {
key "prefix network";
leaf prefix {type string;}
leaf network {type string;}
list next-if {
key "next-hop if-name";
leaf next-hop {type string;}
leaf if-name {type string;}
}
}
There are 8 items in the commands, each item is identical, actually all of the commands are referred to the same one item of list demo by keys ‘prefix and network’. This item of demo has many sub items in list next-if, the next-hop and if-name are one-one correspondence, and they are unique, although they are keys, both of them should be optional. We can only config next-hop, or only if-name, or both of them. I mean the following config are different, and could be configured at the same time.
10.10.10.0 255.255.255.0 12.12.12.1
10.10.10.0 255.255.255.0 eth1
10.10.10.0 255.255.255.0 12.12.12.1 eth1
Actually, I can’t configure like
10.10.10.0 255.255.255.0 12.12.12.1
10.10.10.0 255.255.255.0 eth1
Because the key leaf must be given, it should be
10.10.10.0 255.255.255.0 12.12.12.1 default-ifname
10.10.10.0 255.255.255.0 default-nexthop eth1
Another way to meet my demands is write the model as follows. But I have to config the extra key id.
list model
{
key id;
leaf id {type int32;}
leaf prefix;
leaf netmask;
leaf nexthop;
leaf ifname;
}
1 10.10.10.0 255.255.255.0 12.12.12.1
2 10.10.10.0 255.255.255.0 13.13.13.1
3 10.10.10.0 255.255.255.0 eth1
4 10.10.10.0 255.255.255.0 eth2
5 10.10.10.0 255.255.255.0 12.12.12.1 eth1
6 10.10.10.0 255.255.255.0 12.12.12.1 eth2
7 10.10.10.0 255.255.255.0 13.13.13.1 eth1
8 10.10.10.0 255.255.255.0 13.13.13.1 eth2
How can I write a list like the following, with all of them are key leafs, and any of them is optional?
list model
{
key "id prefix netmask nexthop ifname";
leaf prefix;
leaf netmask;
leaf nexthop;
leaf ifname;
}
if we omit ifname:
10.10.10.0 255.255.255.0 12.12.12.1
10.10.10.0 255.255.255.0 13.13.13.1
if we omit next-hop:
10.10.10.0 255.255.255.0 eth1
10.10.10.0 255.255.255.0 eth2
if we config both:
10.10.10.0 255.255.255.0 12.12.12.1 eth1
10.10.10.0 255.255.255.0 12.12.12.1 eth2
if we config none:
10.10.10.0 255.255.255.0