The 'insert' command is used to insert or move YANG list or leaf-list data into a NETCONF database. It is a high level command that utilizes the YANG 'insert' extensions to the NETCONF <edit-config> operation.
Note that, the “system_sorted” parameter is ignored. NETCONF does not require entries to be sorted by index. It only requires the order to be maintained if “ordered-by user” is configured in the YANG module. It will maintain YANG schema order so the objects will be returned in the correct order according to the YANG module.
Use the YANG 'insert' operation to add data rules in some order other than 'last'. By default 'insert' operation add a new data in the last position.
Usage
YANG Data model
list test2 { key name; ordered-by user; unique b2; leaf a1 { type int8; default 4; } leaf name { type string { length 1..6 { error-app-tag leaf-a2-error; error-message 'leaf a2 is invalid'; } } } leaf b2 { type uint32; default 5; } } list test3 { ordered-by user; key "string.1 uint32.1"; leaf string.1 { type string; } leaf uint32.1 { type uint32; } }
1) Insert using Yangcli-Pro:
Single key list insertion: user@myserver> insert /test2[name='entry2'] \ order=after \ edit-target=”[name='entry3']” Multiple keys list insertion: user@myserver> insert /test3[string.1='entry2'][uint32.1='2'] \ order=before \ edit-target=”[string.1='entry1'][uint32.1='1']”
2) Insert using the <edit-config> RPC:
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:yang="urn:ietf:params:xml:ns:yang:1"> <edit-config> <target> <candidate/> </target> <config> <test2 xmlns="http://netconfcentral.org/ns/test" xmlns:ncx="http://netconfcentral.org/ns/yuma-ncx" nc:operation="insert" yang:insert="before" yang:key="[name='entry3']"> <name>entry2</name> <a1>20</a1> <b2>20</b2> <foo>pusan</foo> </test2> <test3 xmlns="http://netconfcentral.org/ns/test" xmlns:ncx="http://netconfcentral.org/ns/yuma-ncx" nc:operation="insert" yang:insert="before" yang:key="[string.1='entry3'][uint32.1='3']"> <string.1>entry4</string.1> <uint32.1>4</uint32.1> </test3> </config> </edit-config> </rpc>
3) Insert using RESTCONF YANG-PATCH edit:
PATCH http://localhost/restconf/data Accept: application/yang-data+json Content-Type: application/yang-patch+json { "ietf-yang-patch:yang-patch" : { "patch-id" : "move-entry-patch", "edit" : [ { "edit-id" : "edit1", "operation" : "move", "target" : "/test2=key1", "where" : "after", "point" : "/test2=key2" }, { "edit-id" : "edit2", "operation" : "insert", "target" : "/test3", "where" : "before", "point" : "/test3=key1,1", "value" : { "test3": { "string.1":"key6", "uint32.1": 6 } } } ] } }
4) Insert using RESTCONF POST edit:
POST http://localhost/restconf/data?insert=after&point=/test2=test1 Accept: application/yang-data+json Content-Type: application/yang-data+json { "test2": { "a2":"t1.1", "b2": 4, "foo": "mandatory" } } POST http://localhost/restconf/data?insert=after&point=/test3=key1,1 Accept: application/yang-data+json Content-Type: application/yang-data+json { "test3": { "string.1":"key2", "uint32.1": 2 } }
5) Insert using DB-API edit:
Single key list insertion:
.... /* insert list */ const xmlChar *path_str = (const xmlChar *)"/test2/key02"; const xmlChar *operation_str = (const xmlChar *)"insert"; const xmlChar *value_str = (const xmlChar *) "<test2 xmlns='http://netconfcentral.org/ns/test''>" "<a2>key02</a2>" "<b2>6</b2>" "<foo>mandatory-node</foo>" "</test2>"; insert_point = (const xmlChar *)"/test2/key2"; insert_where = (const xmlChar *)"after"; const xmlChar *patch_id_str = NULL; boolean system_edit = FALSE; /* * edit_target == target resource (YANG-API path expression) * edit_operation == edit operation (create merge replace delete remove insert) * edit_xml_value == XML payload in string form, whitespace allowed * MAY BE NULL if no value required (delete remove)) * patch_id_str == string to use as the patch ID * == NULL to use the default patch-id field * system_edit == TRUE if this edit is from the system and should * bypass access control enforcement * == FALSE if this edit is from a user and should not * bypass access control enforcement * insert_point is a string like the target except a different instance * of the same list of leaf-list; only for before, after * insert_where == <insert enum string> * "before" * "after" * "first" * "last" */ status_t res = db_api_send_edit_full(path_str, operation_str, value_str, patch_id_str, system_edit, insert_point, insert_where); if (res != NO_ERR) { log_error("\nSend test edit failed %s %s = %s (%s)\n", operation_str, path_str, value_str, get_error_string(res)); } else if (LOGDEBUG) { log_debug("\nSend test edit OK %s %s = %s\n", } ....
Multiple keys list insertion:
.... /* insert list */ const xmlChar *path_str = (const xmlChar *)"/test3/key2/2"; const xmlChar *operation_str = (const xmlChar *)"insert"; const xmlChar *value_str = (const xmlChar *) "<test3 xmlns='http://netconfcentral.org/ns/test'>" " <string.1>key2</string.1>" " <uint32.1>2</uint32.1>" "</test3>"; insert_point = (const xmlChar *)"/test3/key1/1"; insert_where = (const xmlChar *)"before"; const xmlChar *patch_id_str = NULL; boolean system_edit = FALSE; /* * edit_target == target resource (YANG-API path expression) * edit_operation == edit operation (create merge replace delete remove insert) * edit_xml_value == XML payload in string form, whitespace allowed * MAY BE NULL if no value required (delete remove)) * patch_id_str == string to use as the patch ID * == NULL to use the default patch-id field * system_edit == TRUE if this edit is from the system and should * bypass access control enforcement * == FALSE if this edit is from a user and should not * bypass access control enforcement * insert_point is a string like the target except a different instance * of the same list of leaf-list; only for before, after * insert_where == <insert enum string> * "before" * "after" * "first" * "last" */ status_t res = db_api_send_edit_full(path_str, operation_str, value_str, patch_id_str, system_edit, insert_point, insert_where); if (res != NO_ERR) { log_error("\nSend test edit failed %s %s = %s (%s)\n", operation_str, path_str, value_str, get_error_string(res)); } else if (LOGDEBUG) { log_debug("\nSend test edit OK %s %s = %s\n", } ....