How can I properly remove a single element from a list and shift the list.
exemple :
there is my list [1 2 3 5 10 15 20]
remove 10
[1 2 3 5 14 19]
Is it possible to do this with maapi ?
How can I properly remove a single element from a list and shift the list.
exemple :
there is my list [1 2 3 5 10 15 20]
remove 10
[1 2 3 5 14 19]
Is it possible to do this with maapi ?
You can use something like maapi_delete(maapi_socket, thandle, '/path/to/my-list{10}');
It removes only the node 10, but it didn’t shift my list.
I believe you have misunderstood what the values in a leaf-list represent. They are just values sorted in “system” or “user” order. Their index is based on a “pseudo” index. See https://tools.ietf.org/html/rfc7950#section-7.7.1
To “shift” those values you would have to delete value 10, 15, 20 and create 14 19.
Can i move my index with maapi_move_ordered or maapi_move ?
Do you have an exemple of maapi_move_ordered?
See the source code for the confd_cmd tool for a maapi_move_ordered() example;
$CONFD_DIR/src/confd/tools/confd_cmd.c
Quick demo:
$ confd_load -Fo -p /my-leaf-list
{
"data": {
"my-module:my-leaf-list": [1, 2, 3, 4, 5]
}
}
$ confd_cmd -dd -c 'maapi_move "/my-leaf-list" "{1}" last'
maapi_move "/my-leaf-list" "{1}" "last"
TRACE Connected (maapi) to ConfD
TRACE MAAPI_LOAD_ALL_NS
TRACE MAAPI_LOAD_MNS_MAPS
TRACE MAAPI_LOAD_HASH_DB
TRACE Connected (maapi) to ConfD
TRACE MAAPI_START_USER_SESSION --> CONFD_OK
TRACE MAAPI_START_TRANS --> CONFD_OK
TRACE MAAPI_MOVE_ORDERED /my-leaf-list{1} --> CONFD_OK
TRACE MAAPI_APPLY_TRANS --> CONFD_OK
TRACE MAAPI_STOP_TRANS --> CONFD_OK
TRACE MAAPI_END_USER_SESSION --> CONFD_OK
$ confd_load -Fo -p /my-leaf-list
{
"data": {
"my-module:my-leaf-list": [2, 3, 4, 5, 1]
}
}
More details:
So how can I copy my element from my list to another entry?
With maapi_copy or maapi_move ?
Its a list not a leaf-list.
Give us a YANG example please so we don’t have to ask about what type of list etc.