Insert elem on a list

Hello, i have a list with 5 elements and I want to insert an empty element somewhere on my list and shift the other elem on my list.
Is it possible to do that ?

example:
list 1 4 5 6
shift 1
list 2 5 6 7

You can’t insert empty instances in a list.

But we support ordering of list instances if you use the “ordered-by user;” under your list node model.

Take a look as the example: examples.confd/cli/ordered

This allows you to insert instances before or after some existing instance.

maapi_insert works well for one element but i didn’t found any solution to shift every node on a list.

By “shift” you meant to change the key value for each existing instance?
Here we are not taking about inserting a new instance then.

I am afraid it’s not possible to achieve what you want automatically.

maapi_insert() only works for “indexed-view” lists.

Note that “tailf:indexed-view” was only meant for backward compatibility with Confspec modules, back when YANG wasn’t supported yet.

A snippet from the user guide talks about this:

" This statement is mainly provided for backwards compatibility with confspecs. New data models should consider using YANG’s ordered-by user statement instead."

If you want to make this change, it would have to be made programmatically by reading from, deleting then writing new data to CDB…

I am interested in the use case for this, that can’t be covered by “ordered-by user” YANG statement.
Can you provide a valid use case scenario?

If you just want to keep an index for each instance, you can either keep this index outside of CDB, for example by updating your index each time a list instance if inserted or deleted, or store the index in CDB, but it wouldn’t be a key, and you would have to walk the list to modify its value for the instances following the inserted one, the key should be something else, like a string name for example, that is not bound by index requirements. an Index integer has no meaning to northbound users, and especially if it’s a “moving target”.

You can also explore the “tailf:secondary-index” statement which is useful for SNMP, and sorting of data.