Question on handling Dependent leafs

Hi,
I have requirement where if node “A” is configured node “B” should not be allowed with error message and vice-versa.
I have created below model it is working as expected but only issue issue Error message triggered always from node B.
Please help me how i can achieve to get correct error message in each case.

Written model:

container confgA {
    leaf-list A {
        type inet:ipv6-address;
        tailf:cli-list-syntax;
        must "not(../../confgB/confgB1/B)" {
             error-message "B is already configured";
        }
    }
}
container confgB {
   container confgB1 {
        leaf B {
            type empty;
            must "not(../../../confgA/A)" {
                error-message "A is already configured";
            }
        }
   }
}

Configuration point is working good i.e. If node A is configured node B is not allowed and if node B is configured node A is not allowed. But in both the cases am getting error message “A is already configured”. Please help how can i fix this.

Thanks in advance
Anil

First - I made a small edit in your model, the container name was confB but was referred to as confgB, I assume this was just a typo.

Regarding the must statements: I think this is a misunderstanding of what must statements do. They help you to make sure that the configuration is “consistent”, not that the way how the operator created given configuration is correct. In other words, both must statements essentially do the same - make sure that A and B are not both configured at the same time. So when a new configuration contains both A and B, ConfD in the validation phase takes one of the statements and reports its violation.

Your other options are:

  • you can remove one of the two must statements (since, again, they require the same thing) and change the message for the other so that it would say something like “A and B cannot be configured at the same time”;
  • you can implement validation callbacks for the two nodes - I believe it is possible to write them such that you can really detect situations like "B has been already configured and the user is trying to create A in the current transaction";
  • if the above is not possible, you can use a two-phase subscriber and validate in the prepare phase; but that is becoming a bit too complicated, I think.
1 Like

An alternative would be to use a couple of “when” statements.
(if the model actually would look like this you would obviously move the when statements up to the container confgA/confgB level)

container confgA {
    leaf-list A {
        type inet:ipv6-address;
        tailf:cli-list-syntax;
        when "not(../../confgB/confgB1/B)"
    }
}
container confgB {
   container confgB1 {
        leaf B {
            type empty;
            when "not(../../../confgA/A)";
        }
   }
}

If you want to customize the error message of the when statement:

1 Like

Thanks a lot for both the replies.