List without key (or auto generate key)

list multi-items {
    key id;
    uniq "name size";
    leaf id {type uint32;} // auto increase and not be displayed. 
    leaf name {type string;}
    leaf size {type uint32;}
    leaf others {type string;}
}

# config
# mulit-items name xxx size 1 others xxx
# mulit-items name xxx-2 size 2
# mulit-items name xxx-3 size 3


# show full-configuration mulit-items
multi-items 1
    name xxx
    size 2
   ohters xxx
multi-items 2
    name xxx-2
    size 2
multi-items 3
    name xxx-2
    size 2

is it possible to define an auto generate key for list? we don’t need user provide the key, we want the key could be auto generate by confd server internal or use some api to implement?

What is the reason for having the key to be an id instead of having the pair (name, size) to be the key?

In a configuration list, keys have to be user provisioned and can’t be system generated. Otherwise Northbound managers will have a hard time managing a system like this using NETCONF.

If the id in your YANG model needs to be system generated and used for other purposes, then it can either be modeled as operational data or as a non key configuration data. You can generate this key during the creation of a record using a hook callback, which will allow you to write this value to CDB in the same NB user initiated transaction.

if we use the name and size to be the key, couldn’t control the order of items when the items are delivered to MOs, because they are sorted by keys, not the order we create them, if we use the hidden key, we could control the priority of items by the auto-generate id.

Do you means this?
Add config false to id.

list multi-items {
    key id;
    uniq "name size";
    leaf id {config false; type uint32;} // auto increase and not be displayed. 
    leaf name {type string;}
    leaf size {type uint32;}
    leaf others {type string;}
}

It doesn’t work, the id sitll need to be configured.

Last paragraph of Chapter 3.10

At least one leaf must
be an instance key - we cannot have lists without a key.
List entries are ordered and indexed according to the value of the key(s).

@nabil
What do you mean by non key configuration data ?

I meant to make id another configuration leaf that is not a key.

Example:

list multi-items {
key “name size”;
leaf name {type string;}
leaf size {type uint32;}
leaf others {type string;}
leaf id {
tailf:hidden debug;
type uint32;
} // auto increase and not be displayed.
}

You can achieve the “auto increase and not be displayed” requirement for id using hook callbacks as explained before. You can also hide the id from users and make it only accessible to confdlib applications using hide groups. Take a look at section 3.9 of the ConfD user guide: It explains how to hide data in YANG using Tail-f extensions.

Take a look at 10.6. Hooks for how to work with hooks.

You can use YANG’s “ordered-by user” statement in order to have entries in your list be sorted according to an order as defined by the user. This will remove the need from having to use an unnecessary id key.

An example of your YANG list will then look as follows:

list multi-items {
  key "name size";
  ordered-by user;
  leaf name {type string;}
  leaf size {type uint32;}
  leaf others {type string;}
}