cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
843
Views
0
Helpful
4
Replies

Converting data model to valid yang output

denvle
Beginner
Beginner

Hello everyone,

 

I'm quite new to this and I'm wondering how you guys convert your own data model to a valid yang data model that you can send to the device?

 

My problem is that in your own data model "IAC" you have this file to configure an ACL:

acls:[
  {"ip": "10.1.0.190", "mask": ""},
  {"ip": "172.30.176.0", "mask": "0.0.15.255"}
]

Now you want to convert this to a valid YANG/json format.

The thing is the yang/json format doesn't accept empty keys

How do you convert this without writing a lot of code?

You can see that in my example I have an empty string for the mask.
But in the valid yang/json you can't send the key

 

{
    "Cisco-IOS-XE-acl:standard": {
        "name": 61,
        "access-list-seq-rule": [
            {
                "sequence": "10",
                "permit": {
                    "std-ace": {
                        "ipv4-prefix": "10.1.0.190"
                    }
                }
            },
            {
                "sequence": "20",
                "permit": {
                    "std-ace": {
                        "ipv4-prefix": "172.30.176.0",
                        "mask": "0.0.15.255"
                    }
                }
            },

Thanks in advance for setting me in the right direction!

1 Accepted Solution

Accepted Solutions

Hi Dennis

In my opinion you need to add verifications for IP address and mask values, before you are updating the yangacllist. This is critical, because the values must comply with the patterns defined in the YANG model. Obviously, the empty string does not comply with the pattern, so it will never gets into configuration.

Yan Gorelik
YDK Solutions

View solution in original post

4 Replies 4

yangorelik
Rising star
Rising star

Based on the YANG model

  grouping ipv4-std-ace-grouping {
    container std-ace {
      choice source-choice {
        case ipv4-prefix-case {
          leaf ipv4-prefix {
            type ios-types:ipv4-host;
          }
          leaf mask {
            type inet:ipv4-address;
          }
        }

        case any-case {
          leaf any {
            description
              "Any source prefix";
            type empty;
          }
        }

        case host-case {
          leaf host {
            description
              "A single source host";
            type ios-types:ipv4-host;
          }
        }
      }
      uses ace-log-grouping;
    }
  }

The 'mask' is not a mandatory leaf, so it is not necessary to include it to the configuration. But if you include it, you should follow its type format 'inet:ipv4-address':

  typedef ipv4-address {
    type string {
      pattern
        '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}'
      +  '([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'
      + '(%[\p{N}\p{L}]+)?';
    }
}

Based on that definition the mask cannot be an empty string!

Yan Gorelik
YDK Solutions