Move an entry after another entry within the list

How to move a list entry after another list entry ?
I’ve following yang model. Where I need to move a entry in “rule” list after another “rule” entry within same sipAdaptor Profile ex:
move
/PROFILES:profiles/signaling/sipAdaptorProfile{smm}/rule{1}
after
/PROFILES:profiles/signaling/sipAdaptorProfile{smm}/rule{3}

module sipAdaptor {	
	augment "/PROFILES:profiles/PROFILES:signaling" {
		list sipAdaptorProfile {
			key name;
			tailf:sort-order snmp;
			leaf name {
				type string;
				tailf:info "
					The name of Adaptor Profile.
				";
			}
			list rule {
				key ruleIndex;
				min-elements 1;
				tailf:sort-order snmp;
				leaf ruleIndex {
					type uint16;
				}
				list criterion {
					key criterionIndex;
					min-elements 1;
					tailf:sort-order snmp;
					leaf criterionIndex {
						type uint16;
					}
					container message {
						leaf messageTypes {
							type string;
						}
					}
				}
				list action {
					key actionIndex;
					min-elements 1;
					leaf actionIndex {
						type uint16;
					}
					leaf operation {
						type string;
					}
				}
			}
		}	
	}
}

Thanks.

Which northbound interface are you referring to? NETCONF? CLI? other?

CLI
I tried “mmove” but It seems I’m providing wrong command string.
Following is the o/p:

$CONFD_CMD -dd -u "admin2" -g "Administrator" -x "system" -e -c 'mmove "/PROFILES:profiles/signaling/sipAdaptorProfile{smm}/rule" "{3}" after "1"';
mmove "/PROFILES:profiles/signaling/sipAdaptorProfile{smm}/rule" "{3}" "after" "1"
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 /PROFILES:profiles/signaling/sipAdaptorProfile{smm}/rule{3}DEBUG item has a bad/wrong type - expected type uint16, got string.
--> CONFD_ERR
FAILED: maapi_move_ordered(ms, mtid, where, tokey, n, "%s%s", argv[0], argv[1]), Error: item has a bad/wrong type (5): expected type uint16, got string., in function do_maapi_move, line 1445

First, in order to be able to move list entries around, you need your list to be user-ordered; and so that you can make the list rule user-ordered, it must not be tailf:sort-order snmp. So let’s suppose the list rule looks like this:

list rule {
  key ruleIndex;
  min-elements 1;
  ordered-by user;
  leaf ruleIndex {
    type uint16;
  }
  ...
}

With this, you can move rule entries around.

As for the actual command, the utility confd_cmd is somewhat limited; you can move entries to first or last positions, but not before X or after X, at least not unless your list has single string-typed key. I’m not sure if this is a bug or a (over)simplification, in either case, if first and last are not enough, you need to use other tools, or take the source of confd_cmd (available in $CONFD_DIR/src/confd/tools) and modify it to satisfy tour needs.

Thanks @mvf , One follow up question, as I looked in the confd-user-guide 7.4 and found the following

In description maapi_move_ordered() is specifically mentioned for ordered-by user statement.
Should I assume maapi_move() can be used for tailf:sort-order snmp;

Thanks.

maapi_move is kind of a misnomer, it should perhaps be named maapi_rename. It does not (directly) change order of entries, it changes key values of an entry, i.e. renames it. So it indeed applies to any kind of list (user-ordered or not), but it does something else than what you asked for.

1 Like