mbj4668 / pyang

An extensible YANG validator and converter in python
ISC License
537 stars 344 forks source link

Annotations not working with leaf-list for json2xml #423

Open ganeshrn opened 6 years ago

ganeshrn commented 6 years ago

Yang model (to add custom annotation):

module nc_operations {
  namespace "http://example.org/nc_operations";
  prefix "nc-op";
  import ietf-yang-metadata {
    prefix "md";
  }
  md:annotation operation {
         type string;
        description
            "annotations for netconf edit-config operation.";
      }
      description "NETCONF 'operation' attribute values";
}

JSON file content with leaf-list annotations added as per RFC https://tools.ietf.org/html/rfc7952

{
    "openconfig-interfaces:interfaces":
     {
        "interface": [{
            "name" : "GigabitEthernet0/0/0/1",
            "config" : {
                "name" : "GigabitEthernet0/0/0/1"
            }
        },
       {
            "name" : "GigabitEthernet0/0/0/2",
            "config" : {
                "name" : "GigabitEthernet0/0/0/2",
                "mtu": 1024
       }
    }],
    "@interface": [{"nc-op:operation": "delete"}, {"nc-op:operation": "replace"}]
  }
}

Actual Output:

<nc:config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" xmlns:ocif=\"http://openconfig.net/yang/interfaces\" xmlns:if=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\" xmlns:md=\"urn:ietf:params:xml:ns:yang:ietf-yang-metadata\" xmlns:nc-op=\"http://example.org/nc_operations\" xmlns:ocext=\"http://openconfig.net/yang/openconfig-ext\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:ietf-yang-types\">
  <ocif:interfaces>
    <ocif:interface>
      <ocif:name>GigabitEthernet0/0/0/1</ocif:name>
      <ocif:config>
        <ocif:name>GigabitEthernet0/0/0/1</ocif:name>
      </ocif:config>
    </ocif:interface>
    <ocif:interface>
       <ocif:name>GigabitEthernet0/0/0/2</ocif:name>
       <ocif:config>
         <ocif:name>GigabitEthernet0/0/0/2</ocif:name>
         <ocif:mtu>1024</ocif:mtu>
      </ocif:config>
    </ocif:interface>
  </ocif:interfaces>
</nc:config>

Expected Output:

<nc:config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" xmlns:ocif=\"http://openconfig.net/yang/interfaces\" xmlns:if=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\" xmlns:md=\"urn:ietf:params:xml:ns:yang:ietf-yang-metadata\" xmlns:nc-op=\"http://example.org/nc_operations\" xmlns:ocext=\"http://openconfig.net/yang/openconfig-ext\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:ietf-yang-types\">
  <ocif:interfaces>
    <ocif:interface operation="delete">
      <ocif:name>GigabitEthernet0/0/0/1</ocif:name>
      <ocif:config>
        <ocif:name>GigabitEthernet0/0/0/1</ocif:name>
      </ocif:config>
    </ocif:interface>
    <ocif:interface operation="replace">
       <ocif:name>GigabitEthernet0/0/0/2</ocif:name>
       <ocif:config>
         <ocif:name>GigabitEthernet0/0/0/2</ocif:name>
         <ocif:mtu>1024</ocif:mtu>
      </ocif:config>
    </ocif:interface>
  </ocif:interfaces>
</nc:config>
iskenderuz commented 5 years ago

I have the same issue. Could someone suggest a workaround for delete operations until there is a fix?