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

Yang, xpath, deref a second order object in a list?

anderslindback
Level 1
Level 1

So, working on an inventory style package where I want to set what interfaces can be used for a specific device and ned combination, so below is a compacted version of the Yang model so far.

 

module inventory {
  yang-version 1.1;
  namespace "http://example.com/inventory";
  prefix inventory;
  container inventory {
    list device {
      tailf:info "device hostname";
      key "hostname";
      leaf hostname {type string;}

      list network-interface {
        key 'type id';

        leaf type {
          type leafref {
            path "/inventory/device-model-information/manufacturer[manufacturer = current()/../../manufacturer]/interface-types[ned-id = deref(current()../../device-model)/ned-id]/name/interface-type";
          }
        }

        leaf id {
          type string {
            pattern "[0-9/]+";
          }
        }
      }

      leaf manufacturer {
        type leafref {
          path "/inventory/device-model-information/manufacturer/manufacturer";
        }
      }

      leaf device-model {
        type leafref {
          path "/inventory/device-model-information/manufacturer[manufacturer = current()/../manufacturer]/model/model";
        }
      }
    }
    //end device list


    container device-model-information {
      description "Contains model/manufacturer specific device information";
      tailf:info "Contains model/manufacturer specific device information";

      list manufacturer {
        key manufacturer;
        leaf manufacturer {type string;}
        list model {
          key model;
          leaf model {type string;}
          leaf ned-id {
            type leafref {
              path "/inventory/device-model-information/ned-mappings/ned-name";
            }
          }
        }
        list interface-types {
          key "ned-id";
          leaf ned-id {
            type leafref {
              path "/inventory/device-model-information/ned-mappings/ned-name";
            }
          }
          list name {
            key "interface-type";
            description "Interface types avialable";
            leaf interface-type {
              type string;
            }
          }
        }
      }
    }
  }
}

So based on what device model a specific device is, it gets a ned assigned, there are some other settings in the full module, and that controls what interfaces are available in the list, so populated it looks something like this:

 

 

manufacturer Cisco {
    model ASR9k {
        ned-id cisco-ios-xr;
    }
    model Cat4900 {
        ned-id cisco-ios;
    }
    model NCS5500 {
        ned-id cisco-ios-xr;
    }
    interface-types cisco-ios-xr {
        name Bundle-Ether;
        name FiftyGigE;
        name FortyGigE;
        name FourHundredGigE;
        name HundredGigE;
        name Port-channel;
        name TenGigE;
        name TwentyFiveGigE;
        name TwoHundredGigE;
    }
    interface-types cisco-ios {
        name BVI;
        name Bundle;
        name FastEthernet;
        name GigabitEthernet;
        name Port-channel;
        name TenGigabitEthernet;
    }
}

Now the problem is the type leafs leafref at line 16:

        leaf type {
          type leafref {
            path "/inventory/device-model-information/manufacturer[manufacturer = current()/../../manufacturer]/interface-types[ned-id = deref(current()../../device-model)/ned-id]/name/interface-type";
          }
        }

Just looking up what manufacturer it is with current works, but from that I need to deref the object to get what ned-id is assigned to it, to lookup in the list, but I cant figure out the nested lookup?

 

0 Replies 0