1

I have a yang model with a leafref, which is pointing to a list inside of a other list. Basically something like this:

list some-names
{
    key "name";
    leaf name
    {
        type string;
    }

    list some-other-names
    {
        key "name";
        leaf name
        {
            type string;
        }
    }  
}

I want to point from outside with a leafref to the some-other-names list but only the ones with upper name equals to foo. Unfortunately the leafref has to have a current() for restriction. So my current solution is the following but requires a extra leaf which is total unnecessary for configuration .

leaf foo
{
    type string;
    deafault "foo";
}
leaf some-leaf-ref
{
    type leafref
    {
        path "/some-names[name = current()/../foo]/some-other-names/name";
    }
}

Is there a simpler way than this, which does not need a additional leaf for restricting the name of some-names to a certain value?

BTW this I already tried but its not a correct path-arg:

leaf some-leaf-ref
{
    type leafref
    {
        path "/some-names[name = 'foo']/some-other-names";
    }
}
phschoen
  • 2,021
  • 16
  • 25

1 Answers1

1

Perhaps something along the lines of:

  leaf some-leafref {
    must "/some-names[name = 'foo']/some-other-names/name = .";
    type leafref {
      path "/some-names/some-other-names/name";
    }
  }

So, no predicate in the path expression, yet with an additional must restriction - the two expressions are essentially ANDed together. YANG specification does mention that a path expression may evaluate to a node set that contains more than one node, and it doesn't say predicates are mandatory per key (unlike for instance-identifiers). Seems like hackery to me, though, or ugly at least.

Perhaps what you really want is a leafref leaf child to your outer list (some-names), that has a when to make it valid only when ../name = 'foo'.

  list some-names {
    key "name";
    leaf name {
      type string;
    }

    list some-other-names {
      key "name";
      leaf name {
        type my-type;
      }
    }  

    leaf some-leafref {
      when "../name = 'foo'";
      type leafref {
        path "../some-other-names/name";
      }
    }
  }
phschoen
  • 2,021
  • 16
  • 25
predi
  • 5,528
  • 32
  • 60