ConfD User Community

XPath negation?

Is it possible to specify a when XPath statement that is a negation in a ‘when’ clause? IE, I want a particular leaf node to appear ONLY if another particular leaf does NOT exist. Really I want three fields, A, B, and C. A must always exist. If B exists, then C cannot (and vice versa - if C is instantiated first, then B cannot exist). I know I can enforce this at validation time, just wondering if I can enforce it directly in the yang model as well with a “when” (I couldn’t figure out any sort of negation…I can get existence, but not !existence.

You need something like this I believe:

container ABC {
    description "A must always exist. If B exists, then C cannot (and vice versa - if C is instantiated first, then B cannot exist)";
    leaf A {
      type string;
    }
    leaf B {
      type string;
      when "not(../C)";
    }
    leaf C {
      type string;
      when "not(../B)";
    }
  }

You can find more XPath variants here for example:
http://www.w3.org/TR/xpath/#function-boolean

Ah, I had tried without the parens and that doesn’t work…with the parens is the solution, thanks!

@cohult Could this be done with tailf:action input. e.g

    tailf:action test-action
    {
         tailf:exec "/root/test.sh"
        {
            tailf:args '-u $(user) -g $(groups) -c $(context)';
        }
        input
        {
            container in
            {
                tailf:cli-drop-node-name;
                leaf A {
                    type empty;
                }
                leaf B {
                   type string;
                   when "not(../C)";
               }
               leaf C {
                 type string;
                 when "not(../B)";
              }
            } // container in
        } // input
        output
        {
            leaf result
            {
                tailf:cli-drop-node-name;
                type string;
            }
        }
    }

For action input, “when” has no effect. Below is the CLI output
CLI# test-action
Possible completions:
A B C |
CLI# test-action
Possible completions:
A B C |
CLI# test-action A
Possible completions:
B C |
CLI# test-action A B b C c
CLI#
CLI# test-action B b
Possible completions:
A C |
CLI# test-action B b A C c
CLI#

Hi Manish,

Since the tailf:action extension is deprecated in favor of the YANG 1.1 action statement, let’s have a look in the YANG 1.1 RFC 7950, here “the manual”.
https://tools.ietf.org/html/rfc7950#page-200
…and no, when statements are not listed as allowed in action input statements.

Makes sense to me if you look at it from for example a NETCONF perspective. Action input parameters are not “committed” and they are not stored in CDB. The input parameters are just passed on to the application that handles the action. And when the action has been performed, the result is presented in the output parameters.

If you want to implement a CLI command that does something like that, use the clispec, not YANG.

Thank you @cohult. Appreciate your quick response.