sysrepo  3.0.0
YANG-based system repository for all-around configuration management.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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. More...
 
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. More...
 
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. More...
 
int sr_discard_changes (sr_session_ctx_t *session)
 Discard prepared changes made in the current session. More...
 
int sr_discard_items (sr_session_ctx_t *session, const char *xpath)
 Prepare to discard nodes matching the specified xpath (or all if not set) previously set by the session connection. Usable only for SR_DS_OPERATIONAL datastore. These changes are applied only after calling sr_apply_changes(). More...
 
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. More...
 
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(). More...
 
struct lyd_node * sr_get_changes (sr_session_ctx_t *session)
 Retrieve stored changes (prepared, not yet applied). More...
 
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. More...
 
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. More...
 
int sr_has_changes (sr_session_ctx_t *session)
 Learn whether there are any prepared non-applied changes in the session. More...
 
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(). More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 

Detailed Description

Typedef Documentation

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 356 of file sysrepo_types.h.

Enumeration Type Documentation

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 339 of file sysrepo_types.h.

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 361 of file sysrepo_types.h.

Function Documentation

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]sessionSession (DS-specific) to apply changes of.
[in]timeout_msChange 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).
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]sessionSession (DS-specific - target datastore) to use.
[in]module_nameOptional module name that limits the copy operation only to this module.
[in]src_datastoreSource datastore.
[in]timeout_msConfiguration callback timeout in milliseconds. If 0, default is used.
Returns
Error code (SR_ERR_OK on success).
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.

Not supported for SR_DS_OPERATIONAL, use sr_discard_items() or sr_discard_oper_changes() instead.

Parameters
[in]sessionSession (DS-specific) to use.
[in]pathPath identifier of the data element to be deleted.
[in]optsOptions overriding default behavior of this call.
Returns
Error code (SR_ERR_OK on success, SR_ERR_OPERATION_FAILED if the whole edit was discarded).
int sr_discard_changes ( sr_session_ctx_t session)

Discard prepared changes made in the current session.

Parameters
[in]sessionSession (DS-specific) to discard changes from.
Returns
Error code (SR_ERR_OK on success).
int sr_discard_items ( sr_session_ctx_t session,
const char *  xpath 
)

Prepare to discard nodes matching the specified xpath (or all if not set) previously set by the session connection. 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.

Parameters
[in]sessionSession (DS-specific) to use.
[in]xpathXPath expression filtering the nodes to discard, all if NULL.
Returns
Error code (SR_ERR_OK on success).
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]connUnused.
[in]sessionSession (not DS-specific) to use.
[in]module_nameOptional module name that limits the operation only to this module.
[in]timeout_msModule change callback timeout in millisecond. If 0, default is used.
Returns
Error code (SR_ERR_OK on success).
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]sessionSession (DS-specific) to use.
[in]editEdit content, similar semantics to NETCONF <edit-config> content. Uses edit and all of its following siblings.
[in]default_operationDefault 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).
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]sessionSession (DS-specific) to retrieve changes from.
Returns
The stored changes, or NULL, if there are none.
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]sessionSession (not DS-specific) to use.
[in]module_nameOptional module name that limits the operation only to this module.
[out]dataSR data with the stored push oper changes. NULL if none found.
Returns
Error code (SR_ERR_OK on success).
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]sessionSession (not DS-specific) to use.
[in]module_nameName of the module to use.
[out]orderNon-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).
int sr_has_changes ( sr_session_ctx_t session)

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

Parameters
[in]sessionSession (DS-specific) to check changes in.
Returns
non-zero if there are some changes, 0 if there are none.
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]sessionSession (DS-specific) to use
[in]pathPath identifier of the data element to be moved.
[in]positionRequested move direction.
[in]list_keysPredicate identifying the relative list instance (example input [key1="val1"][key2="val2"]...).
[in]leaflist_valueValue 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]originOrigin of the value, used only for SR_DS_OPERATIONAL edits. Module ietf-origin is assumed if no prefix used.
[in]optsOptions overriding default behavior of this call.
Returns
Error code (SR_ERR_OK on success, SR_ERR_OPERATION_FAILED if the whole edit was discarded).
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.

Required WRITE access.

Parameters
[in]sessionSession (DS-specific - target datastore) to use.
[in]module_nameIf specified, limits the replace operation only to this module.
[in]src_configSource data to replace the datastore in session connection libyang context. Is ALWAYS spent and cannot be further used by the application!
[in]timeout_msConfiguration callback timeout in milliseconds. If 0, default is used.
Returns
Error code (SR_ERR_OK on success).
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]sessionSession (DS-specific) to use.
[in]pathPath identifier of the data element to be set.
[in]valueValue to be set. xpath member of the sr_val_t structure can be NULL.
[in]optsOptions overriding default behavior of this call.
Returns
Error code (SR_ERR_OK on success, SR_ERR_OPERATION_FAILED if the whole edit was discarded).
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]sessionSession (DS-specific) to use.
[in]pathPath identifier of the data element to be set.
[in]valueString representation of the value to be set.
[in]originOrigin of the value, used only for SR_DS_OPERATIONAL edits. Module 'ietf-origin' is assumed if no prefix used.
[in]optsOptions overriding default behavior of this call.
Returns
Error code (SR_ERR_OK on success, SR_ERR_OPERATION_FAILED if the whole edit was discarded).
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.

Parameters
[in]sessionSession (not DS-specific) to use.
[in]module_nameName of the module to change. Set to NULL to change the order for all the modules.
[in]orderNon-zero order to set, must be unique.
Returns
Error code (SR_ERR_OK on success).
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]sessionSession (DS-specific) to use.
[in]module_nameIf specified, limits the validate operation only to this module and its dependencies.
[in]timeout_msOperational callback timeout in milliseconds. If 0, default is used.
Returns
Error code (SR_ERR_OK on success).