NSO Yang + XML 기반 패키지 예시

ncs:when

  • 값을 비교하는 것이기 때문에 비교할 값을 지정해줘야 함

Yang

module test {
  namespace "http://example.com/test";
  prefix test;

  import ietf-inet-types {
    prefix inet;
  }
  import tailf-ncs {
    prefix ncs;
  }

  list test {
    key name;
    uses ncs:service-data;
    ncs:servicepoint "test";

    leaf name {
      type string;
      mandatory true;
    }
    
    leaf device {
      type leafref {
        path "/ncs:devices/ncs:device/ncs:name";
      }
      mandatory true;
    }

    leaf interface-type {
      type enumeration {
        enum GigabitEthernet;
        enum TenGigE;
        enum Loopback;
        enum MgmtEth;
      }
      mandatory true;
      description "Type of the interface.";
    }

    leaf interface-id {
      type string;
      mandatory true;
      description "e.g., 0/0/0/1";
    }

    leaf ip-address {
      type inet:ipv4-address;
      mandatory true;
    }

    leaf subnet-mask {
      type inet:ipv4-address;
      mandatory true;
    }
  }
}

Template

<config-template xmlns="http://tail-f.com/ns/config/1.0"
                 xmlns:ncs="http://tail-f.com/ns/ncs"
                 servicepoint="test">
  <devices xmlns="http://tail-f.com/ns/ncs">
    <device>
      <name>{/device}</name>
      <config>
        <interface xmlns="http://tail-f.com/ned/cisco-ios-xr">
          <GigabitEthernet ncs:when="{/interface-type = 'GigabitEthernet'}">
            <id>{/interface-id}</id>
            <ipv4>
              <address>
                <ip>{/ip-address}</ip>
                <mask>{/subnet-mask}</mask>
              </address>
            </ipv4>
          </GigabitEthernet>
        </interface>
      </config>
    </device>
  </devices>
</config-template>