Identical element in inner list items

Hi all,

I would like have an unique item among nested lists elements.

Let’s say userprofile 1 can have multiple users, userprofile2 can have multiple users. In my scenario, I would like to restrict different userprofiles can have same user name or id…

I know it can be done at application level but how to achieve this at yang level ? Is there any way?

container user-profile {
	container user-profile-con {
		list user-profile-list {
			    key "uuid";
                unique "user-profile-name";

                leaf uuid {
                    description
                      "Unique identifier of the list.";
                    type common-types:uuid;
                }

                leaf user-profile-name {
                    description
                      "Name of user profile";
                    mandatory true;
                    type string;
                }
                ..
                ..
                ..

            container user-config-con {
            	   list user-list {
                    key "uuid";
                    unique "user-name";
                    

                    leaf uuid {
                        description
                          "Unique identifier of the list.";
                        type common-types:uuid;
                    }

                    leaf id {
                        description
                          "user ID.";
                        config false;
                        type int;
                    }

                    leaf user-name {
                        description
                          "user name.";
                        mandatory true;
                        type string;
                    }
            }
	}
}

}

Thanks in advance,
Regards

You can implement what you need via a must statement, it allows you to express ideas like “username in a user profile different from this one must not be the same as the current username”. But the problem with such approach is that such constraint would be difficult to check, if you have more than few hundreds of users, the performance penalty might be too high.

Looking at your requirements it sounds to me that user is actually a standalone entity; can you change your data model? If you change it so that you have a list of user profiles and as its sibling a list of users where each user instance links to a user profile instance, you have your requirement fulfilled automatically.

One more note - depending on how you manage your system, UUIDs may not be a good candidate for a key leaf, or for a configurable leaf at all. They are great for computers, but if you expect human operators to be working with your system, maybe just use names as keys, you declare them unique anyway. I believe such uniqueness requirement has again the problem that every new user needs to be checked against all other users; if username is the key leaf, such requirement is kind of automatic (and also checked much faster).