How to validate that only one value can be changed among these in YANG model

70 views Asked by At
leaf value1
{
    tailf:info "value1";
    type integer;
    mandatory true;
}

leaf value2
{
    tailf:info "value2";
    type integer;
    mandatory true;
}

I want to check if someone has updated both values then it should abort the operation.

I tried using must but not able to figure out the condition. Further explanation:

So user will initially set both the values like this: value1 = 2 value2 = 4

Then after that if they want to modify these values only one of them should be allowed to modify at a time, like: value1 modified to 3 value2 kept to 4.

OR--- value1 kept to 2 value2 modified to 3.

Also in separate operations they can modify but not in single one.Like value1 modified to 3 value2 modified to 5 Both in one operation should not be allowed.

1

There are 1 answers

0
predi On

This is a very odd requirement. I doubt you can define something like this without relying on human text in normative YANG "description" statements.

"must" statements do not seem applicable here. They apply on the content of a valid data tree, usually a datastore such as running - when you issue a commit or a direct edit-config/edit-data with this datastore as the target. There's no standardized "state keeping" that would allow you to keep track of what was modified during the modification itself (in order to reference in an XPath expression). Servers probably do keep such state internally one way or another, but a YANG model has no access to such details.

You could probably get away with making those leaf nodes config "false", then creating a specialized RPC or action, intended solely to modify those values. Input parameters would force whatever invokes the RPC/action to make a choice between the two parameters.

leaf value1
{
    tailf:info "value1";
    type integer;
    mandatory true;
    config false; 
}

leaf value2
{
    tailf:info "value2";
    type integer;
    mandatory true;
    config false;
}

// ...

rpc modify-value {
    description "Modifies value1 or value2 in device state.";
    input {
        choice value {
            mandatory true;
            
            leaf value1 {
                type integer;
            }

            leaf value2 {
                type integer;
            }
        }
    }
}

This is probably not the solution that you had hoped for. I don't currently see a way to do this without relying on some dark YANG magic (the kind you should keep clear from).