sysrepo  1.4.58
YANG datastore
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Editing Data API

Typedefs

typedef enum sr_edit_flag_e sr_edit_flag_t
 Flags used to override default behavior of data manipulation calls. 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...
 
typedef enum sr_move_position_e sr_move_position_t
 Options for specifying move direction of sr_move_item call. More...
 

Enumerations

enum  sr_edit_flag_e { SR_EDIT_DEFAULT = 0, SR_EDIT_NON_RECURSIVE = 1, SR_EDIT_STRICT = 2, SR_EDIT_ISOLATE = 4 }
 Flags used to override default behavior of data manipulation calls. More...
 
enum  sr_move_position_e { 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...
 

Functions

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_delete_item (sr_session_ctx_t *session, const char *path, const sr_edit_options_t opts)
 Prepare to selete 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_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_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...
 
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...
 
int sr_apply_changes (sr_session_ctx_t *session, uint32_t timeout_ms, int wait)
 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_has_changes (sr_session_ctx_t *session)
 Learn whether there are any prepared non-applied changes in the session. More...
 
int sr_discard_changes (sr_session_ctx_t *session)
 Discard prepared changes made in the current session. More...
 
int sr_replace_config (sr_session_ctx_t *session, const char *module_name, struct lyd_node *src_config, uint32_t timeout_ms, int wait)
 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_copy_config (sr_session_ctx_t *session, const char *module_name, sr_datastore_t src_datastore, uint32_t timeout_ms, int wait)
 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...
 

Detailed Description

Typedef Documentation

Flags used to override default behavior of data manipulation calls.

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 842 of file sysrepo.h.

Options for specifying move direction of sr_move_item call.

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. However, note that it can adversely affect edit performance.

Definition at line 825 of file sysrepo.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 847 of file sysrepo.h.

Function Documentation

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).

To create a list use xpath with key values included and pass NULL as value argument.

Setting of a leaf-list value appends the value at the end of the leaf-list. A value of 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.

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).
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.
[in]optsOptions overriding default behavior of this call.
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 selete 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.

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).
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).

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.
[in]optsOptions overriding default behavior of this call.
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.

Parameters
[in]sessionSession (DS-specific) to use.
[in]editEdit content, similar semantics to NETCONF <edit-config> content.
[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).
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).
int sr_apply_changes ( sr_session_ctx_t session,
uint32_t  timeout_ms,
int  wait 
)

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_msConfiguration 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.
[in]waitWhether to wait until all callbacks on all events are finished (even SR_EV_DONE or SR_EV_ABORT). If not set, these events may not yet be processed after the function returns. Note that all SR_EV_CHANGE events are always waited for.
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_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_replace_config ( sr_session_ctx_t session,
const char *  module_name,
struct lyd_node *  src_config,
uint32_t  timeout_ms,
int  wait 
)

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. Is ALWAYS spent and cannot be further used by the application!
[in]timeout_msConfiguration callback timeout in milliseconds. If 0, default is used.
[in]waitWhether to wait until all callbacks on all events are finished (even SR_EV_DONE or SR_EV_ABORT). If not set, these events may not yet be processed after the function returns. Note that all SR_EV_CHANGE events are always waited for.
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,
int  wait 
)

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.
[in]waitWhether to wait until all callbacks on all events are finished (even SR_EV_DONE or SR_EV_ABORT). If not set, these events may not yet be processed after the function returns. Note that all SR_EV_CHANGE events are always waited for.
Returns
Error code (SR_ERR_OK on success).