cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1010
Views
5
Helpful
2
Replies

xpath in path with const string

lweddewer
Level 5
Level 5

Hello,

 

want to use device-groups to ease the selection of devices.

For testing I start with a static group name "PE-group".

 

I start trying with YANG-path below and always got this error message:

error: bad argument value "/ncs:devices/ncs:device-group[ncs:name = 'PE-group']/ncs:device-name", should be of type path-arg

 

    leaf device_PE {
      tailf:info "PE Router";
      type leafref {
        path "/ncs:devices/ncs:device-group[ncs:name = 'PE-group']/ncs:device-name";
      }
      mandatory 'true';
    }
	

Doublecheck if anything is wrong with the path in general by replacing the constant value with a current() reference:

    leaf device_PE {
      tailf:info "PE Router";
      type leafref {
        //path "/ncs:devices/ncs:device-group[ncs:name = current()/../group_name]/ncs:device-name";
      }
      mandatory 'true';
    }
	
    leaf group_name {
    	type string;
    	default 'PE-group';
    }

With this yang file anything works as expected.

Any idea want's wrong with the expression with the constant value?

 

Regards

Lothar

1 Accepted Solution

Accepted Solutions

vleijon
Cisco Employee
Cisco Employee

The YANG standard RFC6020 restricts an xpath to a path-arg, defined as:

 

path-arg-str        = < a string that matches the rule
                           path-arg >
path-arg            = absolute-path / relative-path
absolute-path       = 1*("/" (node-identifier *path-predicate))
relative-path       = 1*(".." "/") descendant-path
descendant-path     = node-identifier
                         [*path-predicate absolute-path]
path-predicate      = "[" *WSP path-equality-expr *WSP "]"
path-equality-expr  = node-identifier *WSP "=" *WSP path-key-expr
path-key-expr       = current-function-invocation *WSP "/" *WSP
                         rel-path-keyexpr
rel-path-keyexpr    = 1*(".." *WSP "/" *WSP)
                         *(node-identifier *WSP "/" *WSP)
                         node-identifier

 

Which is a little bit of a mouthful, but the key here is that path-key-expr can only be current() plus a path, or a pure relative path. Which unfortunately means that it cannot be a string.

 

View solution in original post

2 Replies 2

vleijon
Cisco Employee
Cisco Employee

The YANG standard RFC6020 restricts an xpath to a path-arg, defined as:

 

path-arg-str        = < a string that matches the rule
                           path-arg >
path-arg            = absolute-path / relative-path
absolute-path       = 1*("/" (node-identifier *path-predicate))
relative-path       = 1*(".." "/") descendant-path
descendant-path     = node-identifier
                         [*path-predicate absolute-path]
path-predicate      = "[" *WSP path-equality-expr *WSP "]"
path-equality-expr  = node-identifier *WSP "=" *WSP path-key-expr
path-key-expr       = current-function-invocation *WSP "/" *WSP
                         rel-path-keyexpr
rel-path-keyexpr    = 1*(".." *WSP "/" *WSP)
                         *(node-identifier *WSP "/" *WSP)
                         node-identifier

 

Which is a little bit of a mouthful, but the key here is that path-key-expr can only be current() plus a path, or a pure relative path. Which unfortunately means that it cannot be a string.

 

So it's not a bug it's a feature. :( Don't expact that.
The idea looks so simple and natrual.

So I see two ways:
1) Using a additional leaf as filter.
2) Adding a must-statment which filters the wanted group-members.

Thanks for your support!
Regards
Lothar