List of elements within same hierarchy

Hi,

I wanted to create something like below,

routing-instance blue {
    mapping {
        10.0.0.0/24 tag 10;
        10.0.1.0/24 tag 20;
        10.0.2.0/24 tag 30;
    }
}

I have tried the YANG like below,

        container routing-instance {
            container mapping {
                tailf:info "IP TAG Mapping";
                list ip-prefix {
                    key "ip-prefix";
                    leaf ip-prefix {
                        tailf:info "IP Prefix";
                        type inet:ip-prefix;
                    }
                    leaf tag {
                        tailf:info "TAG value";
                        string;
                    }
                }
            }
        }

But it gives me output like below,

cli(config)% show | compare
routing-instances {
    blue {
         mapping {
            ip-prefix 10.0.0.0/24 {
                tag10;
            }
            ip-prefix 10.0.1.0/24 {
                tag 20;
            }
            ip-prefix 11.0.0.0/24 {
                tag 25;
            }
         }
     }
 }
}
[ok][2021-04-12 22:36:07]

Any pointers on how to achieve my desired output style ?

You are using J-style CLI which considerably limits your options (C- and I- style CLIs are more flexible, but this comes at a price). You should be able to get rid of the ip-prefix kewyord by using tailf:cli-no-keyword, but I don’t know of any good way how to remove the block.

If you for some reason insist on doing that, you can “cripple” your data model like this:

    container routing-instance {
      container mapping {
        tailf:info "IP TAG Mapping";
        list ip-prefix {
          key "ip-prefix tag";
          unique ip-prefix;
          tailf:cli-no-keyword;
          leaf ip-prefix {
            tailf:info "IP Prefix";
            type inet:ip-prefix;
          }
          leaf tag {
            tailf:cli-expose-key-name;
            tailf:info "TAG value";
            type string;
          }
        }
      }
    }

This works for show and for load, for some reason not for show | compare. But again - you are modifying your data model so that it works for your CLI while deviating from the original intent.

1 Like