Loading...
Searching...
No Matches
Editing Data API

## Functions

int | sr_apply_changes (sr_session_ctx_t *session, uint32_t timeout_ms)
| Apply changes made in the current session. In case the changes could not be applied successfully for any reason, they remain intact in the session.
int | sr_copy_config (sr_session_ctx_t *session, const char *module_name, sr_datastore_t src_datastore, uint32_t timeout_ms)
| Replaces a conventional datastore with the contents of another conventional datastore. If the module is specified, limits the operation only to the specified module. If it is not specified, the operation is performed on all modules.
int | sr_delete_discard_items (sr_session_ctx_t *session, const char *xpath, const sr_edit_options_t opts)
| Remove a 'discard-items' node from a push oper data of a session. Usable only for SR_DS_OPERATIONAL datastore. These changes are applied only after calling sr_apply_changes().
int | sr_delete_item (sr_session_ctx_t *session, const char *path, const sr_edit_options_t opts)
| Prepare to delete the nodes matching the specified xpath. These changes are applied only after calling sr_apply_changes(). The accepted values are the same as for sr_set_item_str.
int | sr_discard_changes (sr_session_ctx_t *session)
| Discard prepared changes made in the current session.
int | sr_discard_changes_xpath (sr_session_ctx_t *session, const char *xpath)
| Discard prepared changes made in the current session matching an XPath expression.
int | sr_discard_items (sr_session_ctx_t *session, const char *xpath)
| Prepare to discard nodes matching the specified xpath in the operational datastore before applying the other push oper data of this session. Usable only for SR_DS_OPERATIONAL datastore. These changes are applied only after calling sr_apply_changes().
int | sr_discard_oper_changes (sr_conn_ctx_t *conn, sr_session_ctx_t *session, const char *module_name, uint32_t timeout_ms)
| Discard push operational changes of a module for a session.
int | sr_edit_batch (sr_session_ctx_t *session, const struct lyd_node *edit, const char *default_operation)
| Provide a prepared edit data tree to be applied. These changes are applied only after calling sr_apply_changes().
const struct lyd_node * | sr_get_changes (sr_session_ctx_t *session)
| Retrieve stored changes (prepared, not yet applied).
int | sr_get_oper_changes (sr_session_ctx_t *session, const char *module_name, sr_data_t **data)
| Get stored push operational changes of a session.
int | sr_get_oper_changes_order (sr_session_ctx_t *session, const char *module_name, uint32_t *order)
| Get push operational changes order determining when they are applied relative to other sessions for the module.
int | sr_has_changes (sr_session_ctx_t *session)
| Learn whether there are any prepared non-applied changes in the session.
int | sr_move_item (sr_session_ctx_t *session, const char *path, const sr_move_position_t position, const char *list_keys, const char *leaflist_value, const char *origin, const sr_edit_options_t opts)
| Prepare to move/create the instance of an user-ordered list or leaf-list to the specified position. These changes are applied only after calling sr_apply_changes().
int | sr_oper_delete_item_str (sr_session_ctx_t *session, const char *path, const char *value, const sr_edit_options_t opts)
| Deprecated, not supported.
int | sr_replace_config (sr_session_ctx_t *session, const char *module_name, struct lyd_node *src_config, uint32_t timeout_ms)
| Replace a datastore with the contents of a data tree. If the module is specified, limit the operation only to the specified module. If it is not specified, the operation is performed on all modules.
int | sr_set_item (sr_session_ctx_t *session, const char *path, const sr_val_t *value, const sr_edit_options_t opts)
| Prepare to set (create) the value of a leaf, leaf-list, list, or presence container. These changes are applied only after calling sr_apply_changes(). Data are represented as sr_val_t structures.
int | sr_set_item_str (sr_session_ctx_t *session, const char *path, const char *value, const char *origin, const sr_edit_options_t opts)
| Prepare to set (create) the value of a leaf, leaf-list, list, or presence container. These changes are applied only after calling sr_apply_changes(). Data are represented as pairs of a path and string value.
int | sr_set_oper_changes_order (sr_session_ctx_t *session, const char *module_name, uint32_t order)
| Set explicit push operational changes order determining when they are applied relative to other sessions for the module.
int | sr_validate (sr_session_ctx_t *session, const char *module_name, uint32_t timeout_ms)
| Perform the validation a datastore and any changes made in the current session, but do not apply nor discard them.
enum | sr_edit_flag_t { SR_EDIT_DEFAULT = 0x0 , SR_EDIT_NON_RECURSIVE = 0x1 , SR_EDIT_STRICT = 0x2 , SR_EDIT_ISOLATE = 0x4 }
| Flags used to override default behavior of data manipulation calls. More...
enum | sr_move_position_t { SR_MOVE_BEFORE = 0 , SR_MOVE_AFTER = 1 , SR_MOVE_FIRST = 2 , SR_MOVE_LAST = 3 }
| Options for specifying move direction of sr_move_item call. More...
typedef uint32_t | sr_edit_options_t
| Options overriding default behavior of data manipulation calls, it is supposed to be bitwise OR-ed value of any sr_edit_flag_t flags.

## Detailed Description

## Typedef Documentation

## sr_edit_options_t

typedef uint32_t sr_edit_options_t

Options overriding default behavior of data manipulation calls, it is supposed to be bitwise OR-ed value of any sr_edit_flag_t flags.

Definition at line 361 of file sysrepo_types.h.

## Enumeration Type Documentation

## sr_edit_flag_t

enum sr_edit_flag_t

Flags used to override default behavior of data manipulation calls.

Enumerator
SR_EDIT_DEFAULT | Default behavior - non-strict.
SR_EDIT_NON_RECURSIVE | Non-recursive behavior: by sr_set_item, all preceding nodes (parents) of the identified element must exist.
SR_EDIT_STRICT | Strict behavior: by sr_set_item the identified element must not exist (similar to NETCONF create operation), by sr_delete_item the identified element must exist (similar to NETCONF delete operation).
SR_EDIT_ISOLATE | Create new operation separately, independent of all the previous operations. Since all the operations are concatenated into one edit tree, it may happen that 2 incompatible operations are set and an error is observed. This flag can in those cases be used. Also, if an error is returned the previous edit is always left untouched.

Definition at line 344 of file sysrepo_types.h.

## sr_move_position_t

enum sr_move_position_t

Options for specifying move direction of sr_move_item call.

Enumerator
SR_MOVE_BEFORE | Move the specified item before the selected sibling.
SR_MOVE_AFTER | Move the specified item after the selected.
SR_MOVE_FIRST | Move the specified item to the position of the first child.
SR_MOVE_LAST | Move the specified item to the position of the last child.

Definition at line 366 of file sysrepo_types.h.

## Function Documentation

## sr_apply_changes()

int sr_apply_changes | ( | sr_session_ctx_t * | session,
|  | uint32_t | timeout_ms )

Apply changes made in the current session. In case the changes could not be applied successfully for any reason, they remain intact in the session.

Note
  Note that in case that you are changing the running datastore, you also need to copy the config to startup to make the changes persistent.

Required WRITE access.

Parameters

  [in] | session | Session (DS-specific) to apply changes of.
  [in] | timeout_ms | Change callback timeout in milliseconds. If 0, default is used. Note that this timeout is measured separately for each callback meaning this whole function call can easily take more time than this timeout if there are changes applied for several subscribers.

Returns
  Error code (SR_ERR_OK on success).

## sr_copy_config()

int sr_copy_config | ( | sr_session_ctx_t * | session,
|  | const char * | module_name,
|  | sr_datastore_t | src_datastore,
|  | uint32_t | timeout_ms )

Replaces a conventional datastore with the contents of another conventional datastore. If the module is specified, limits the operation only to the specified module. If it is not specified, the operation is performed on all modules.

Note
  Note that copying from candidate to running or vice versa causes the candidate datastore to revert to original behavior of mirroring running datastore (datastores).

Required WRITE access.

Parameters

  [in] | session | Session (DS-specific - target datastore) to use.
  [in] | module_name | Optional module name that limits the copy operation only to this module.
  [in] | src_datastore | Source datastore.
  [in] | timeout_ms | Configuration callback timeout in milliseconds. If 0, default is used.

Returns
  Error code (SR_ERR_OK on success).

## sr_delete_discard_items()

int sr_delete_discard_items | ( | sr_session_ctx_t * | session,
|  | const char * | xpath,
|  | const sr_edit_options_t | opts )

Remove a 'discard-items' node from a push oper data of a session. Usable only for SR_DS_OPERATIONAL datastore. These changes are applied only after calling sr_apply_changes().

Removes nodes set by sr_discard_items().

Only SR_EDIT_STRICT flag is allowed and if set, the specified 'discard-items' node must must exist.

Parameters

  [in] | session | Session (DS-specific) to use.
  [in] | xpath | XPath expression set for 'discard-items'.
  [in] | opts | Options overriding the default behavior of this call.

Returns
  Error code (SR_ERR_OK on success).

## sr_delete_item()

int sr_delete_item | ( | sr_session_ctx_t * | session,
|  | const char * | path,
|  | const sr_edit_options_t | opts )

Prepare to delete the nodes matching the specified xpath. These changes are applied only after calling sr_apply_changes(). The accepted values are the same as for sr_set_item_str.

If SR_EDIT_STRICT flag is set the specified node must must exist in the datastore. If the `path` includes the list keys/leaf-list value, the specified instance is deleted. If the `path` of list/leaf-list does not include keys/value, all instances are deleted but there can be no further changes merged into the list, use SR_EDIT_ISOLATE in such a case.

For SR_DS_OPERATIONAL, this function deletes the selected nodes from the session push oper data. To delete the nodes from the final operational datastore, use sr_discard_items() instead. Only SR_EDIT_STRICT option is allowed causing the function to return an error if the deleted nodes do not exist in the session push oper data. If the path is invalid, an error is returned even without SR_EDIT_STRICT option.

Parameters

  [in] | session | Session (DS-specific) to use.
  [in] | path | Path identifier of the data element to be deleted.
  [in] | opts | Options overriding default behavior of this call.

Returns
  Error code (SR_ERR_OK on success, SR_ERR_OPERATION_FAILED if the whole edit was discarded).

## sr_discard_changes()

int sr_discard_changes | ( | sr_session_ctx_t * | session | ) |

Discard prepared changes made in the current session.

Parameters

  [in] | session | Session (DS-specific) to discard changes from.

Returns
  Error code (SR_ERR_OK on success).

## sr_discard_changes_xpath()

int sr_discard_changes_xpath | ( | sr_session_ctx_t * | session,
|  | const char * | xpath )

Discard prepared changes made in the current session matching an XPath expression.

Parameters

  [in] | session | Session (DS-specific) to discard changes from.
  [in] | xpath | XPatch selecting the changes to discard, NULL to discard all the changes.

Returns
  Error code (SR_ERR_OK on success).

## sr_discard_items()

int sr_discard_items | ( | sr_session_ctx_t * | session,
|  | const char * | xpath )

Prepare to discard nodes matching the specified xpath in the operational datastore before applying the other push oper data of this session. Usable only for SR_DS_OPERATIONAL datastore. These changes are applied only after calling sr_apply_changes().

Creates an opaque node discard-items in the sysrepo YANG module namespace with `xpath` used as the value. Such a node can be a part of the edit in sr_edit_batch() and will discard nodes like this function does.

This affects only operational data of lower order. It is recommended that 'order' is explicitly set by calling sr_set_oper_changes_order() from all sessions that push operational data to the module to avoid different behaviour if a process restarts and is automatically assigned a higher order.

Parameters

  [in] | session | Session (DS-specific) to use.
  [in] | xpath | XPath expression filtering the nodes to discard, all if NULL.

Returns
  Error code (SR_ERR_OK on success).

## sr_discard_oper_changes()

int sr_discard_oper_changes | ( | sr_conn_ctx_t * | conn,
|  | sr_session_ctx_t * | session,
|  | const char * | module_name,
|  | uint32_t | timeout_ms )

Discard push operational changes of a module for a session.

Parameters

  [in] | conn | Unused.
  [in] | session | Session (not DS-specific) to use.
  [in] | module_name | Optional module name that limits the operation only to this module.
  [in] | timeout_ms | Module change callback timeout in millisecond. If 0, default is used.

Returns
  Error code (SR_ERR_OK on success).

## sr_edit_batch()

int sr_edit_batch | ( | sr_session_ctx_t * | session,
|  | const struct lyd_node * | edit,
|  | const char * | default_operation )

Provide a prepared edit data tree to be applied. These changes are applied only after calling sr_apply_changes().

Only top-level operations merge and replace are allowed for SR_DS_OPERATIONAL.

Parameters

  [in] | session | Session (DS-specific) to use.
  [in] | edit | Edit content, similar semantics to NETCONF <edit-config> content. Uses `edit` and all of its following siblings.
  [in] | default_operation | Default operation for nodes without operation on themselves or any parent. Possible values are merge, replace, or none (see NETCONF RFC).

Returns
  Error code (SR_ERR_OK on success).

## sr_get_changes()

const struct lyd_node * sr_get_changes | ( | sr_session_ctx_t * | session | ) |

Retrieve stored changes (prepared, not yet applied).

Note: as soon as the changes get applied or discarded, the return value becomes invalid.

Parameters

  [in] | session | Session (DS-specific) to retrieve changes from.

Returns
  The stored changes, or NULL, if there are none.

## sr_get_oper_changes()

int sr_get_oper_changes | ( | sr_session_ctx_t * | session,
|  | const char * | module_name,
|  | sr_data_t ** | data )

Get stored push operational changes of a session.

Parameters

  [in] | session | Session (not DS-specific) to use.
  [in] | module_name | Optional module name that limits the operation only to this module.
  [out] | data | SR data with the stored push oper changes. NULL if none found.

Returns
  Error code (SR_ERR_OK on success).

## sr_get_oper_changes_order()

int sr_get_oper_changes_order | ( | sr_session_ctx_t * | session,
|  | const char * | module_name,
|  | uint32_t * | order )

Get push operational changes order determining when they are applied relative to other sessions for the module.

Parameters

  [in] | session | Session (not DS-specific) to use.
  [in] | module_name | Name of the module to use.
  [out] | order | Non-zero push oper data order. 0 if there are no push oper data of the session for the module.

Returns
  Error code (SR_ERR_OK on success).

## sr_has_changes()

int sr_has_changes | ( | sr_session_ctx_t * | session | ) |

Learn whether there are any prepared non-applied changes in the session.

Parameters

  [in] | session | Session (DS-specific) to check changes in.

Returns
  non-zero if there are some changes, 0 if there are none.

## sr_move_item()

int sr_move_item | ( | sr_session_ctx_t * | session,
|  | const char * | path,
|  | const sr_move_position_t | position,
|  | const char * | list_keys,
|  | const char * | leaflist_value,
|  | const char * | origin,
|  | const sr_edit_options_t | opts )

Prepare to move/create the instance of an user-ordered list or leaf-list to the specified position. These changes are applied only after calling sr_apply_changes().

Item can be moved to the first or last position or positioned relatively to its sibling.

With default options it recursively creates all missing nodes (containers and lists including their key leaves) in the xpath to the specified node (can be turned off with SR_EDIT_NON_RECURSIVE option). If SR_EDIT_STRICT flag is set, the node must not exist (otherwise an error is returned).

Not supported for SR_DS_OPERATIONAL.

Note
  To determine current order, you can issue a sr_get_items() call (without specifying keys of particular list).

Parameters

  [in] | session | Session (DS-specific) to use
  [in] | path | Path identifier of the data element to be moved.
  [in] | position | Requested move direction.
  [in] | list_keys | Predicate identifying the relative list instance (example input [key1="val1"][key2="val2"]...).
  [in] | leaflist_value | Value of the relative leaf-list instance (example input val1) used to determine relative position, needed only if position argument is SR_MOVE_BEFORE or SR_MOVE_AFTER.
  [in] | origin | Unused, deprecated.
  [in] | opts | Options overriding default behavior of this call.

Returns
  Error code (SR_ERR_OK on success, SR_ERR_OPERATION_FAILED if the whole edit was discarded).

## sr_oper_delete_item_str()

int sr_oper_delete_item_str | ( | sr_session_ctx_t * | session,
|  | const char * | path,
|  | const char * | value,
|  | const sr_edit_options_t | opts )

Deprecated, not supported.

## sr_replace_config()

int sr_replace_config | ( | sr_session_ctx_t * | session,
|  | const char * | module_name,
|  | struct lyd_node * | src_config,
|  | uint32_t | timeout_ms )

Replace a datastore with the contents of a data tree. If the module is specified, limit the operation only to the specified module. If it is not specified, the operation is performed on all modules.

Required WRITE access.

Parameters

  [in] | session | Session (DS-specific - target datastore) to use.
  [in] | module_name | If specified, limits the replace operation only to this module.
  [in] | src_config | Source data to replace the datastore in `session` connection libyang context. Is ALWAYS spent and cannot be further used by the application!
  [in] | timeout_ms | Configuration callback timeout in milliseconds. If 0, default is used.

Returns
  Error code (SR_ERR_OK on success).

## sr_set_item()

int sr_set_item | ( | sr_session_ctx_t * | session,
|  | const char * | path,
|  | const sr_val_t * | value,
|  | const sr_edit_options_t | opts )

Prepare to set (create) the value of a leaf, leaf-list, list, or presence container. These changes are applied only after calling sr_apply_changes(). Data are represented as sr_val_t structures.

With default options it recursively creates all missing nodes (containers and lists including their key leaves) in the xpath to the specified node (can be turned off with SR_EDIT_NON_RECURSIVE option). If SR_EDIT_STRICT flag is set, the node must not exist (otherwise an error is returned). Neither option is allowed for SR_DS_OPERATIONAL.

To create a list use `path` with key values included in predicates, `value` will be ignored. When creating key-less lists and state leaf-lists, use positional predicates such as [1] to refer to the instances. Using no predicate means the instance should be created.

The value of a leaf-list can be specified either by predicate in xpath or by value argument. If both are present, value argument is ignored and xpath predicate is used.

Edits preserve their order only if SR_EDIT_ISOLATE is used and in some cases it may affect the result.

Parameters

  [in] | session | Session (DS-specific) to use.
  [in] | path | Path identifier of the data element to be set.
  [in] | value | Value to be set. xpath member of the sr_val_t structure can be NULL.
  [in] | opts | Options overriding default behavior of this call.

Returns
  Error code (SR_ERR_OK on success, SR_ERR_OPERATION_FAILED if the whole edit was discarded).

## sr_set_item_str()

int sr_set_item_str | ( | sr_session_ctx_t * | session,
|  | const char * | path,
|  | const char * | value,
|  | const char * | origin,
|  | const sr_edit_options_t | opts )

Prepare to set (create) the value of a leaf, leaf-list, list, or presence container. These changes are applied only after calling sr_apply_changes(). Data are represented as pairs of a path and string value.

Function provides the same functionality as sr_set_item().

Parameters

  [in] | session | Session (DS-specific) to use.
  [in] | path | Path identifier of the data element to be set.
  [in] | value | String representation of the value to be set.
  [in] | origin | Origin of the value, used only for SR_DS_OPERATIONAL edits. Module 'ietf-origin' is assumed if no prefix used.
  [in] | opts | Options overriding default behavior of this call.

Returns
  Error code (SR_ERR_OK on success, SR_ERR_OPERATION_FAILED if the whole edit was discarded).

## sr_set_oper_changes_order()

int sr_set_oper_changes_order | ( | sr_session_ctx_t * | session,
|  | const char * | module_name,
|  | uint32_t | order )

Set explicit push operational changes order determining when they are applied relative to other sessions for the module.

By default the next highest order (lowest priority) is generated for any new session push oper data of a module. It is not supported to set the order if the session already has push operational data for the specified module. This is because it can result in change of the final view of operational data, which must be notified to subscribers.

Parameters

  [in] | session | Session (not DS-specific) to use.
  [in] | module_name | Name of the module to change, must be a valid installed module.
  [in] | order | Non-zero order to set, must be unique.

Returns
  Error code (SR_ERR_OK on success).

## sr_validate()

int sr_validate | ( | sr_session_ctx_t * | session,
|  | const char * | module_name,
|  | uint32_t | timeout_ms )

Perform the validation a datastore and any changes made in the current session, but do not apply nor discard them.

Provides only YANG validation, apply-changes subscribers will not be notified in this case.

Parameters

  [in] | session | Session (DS-specific) to use.
  [in] | module_name | If specified, limits the validate operation only to this module and its dependencies.
  [in] | timeout_ms | Operational callback timeout in milliseconds. If 0, default is used.

Returns
  Error code (SR_ERR_OK on success).