static read_conf_f read_conf = NULL;
static el_subscription_ctx_t *el_subscription_ctx = NULL;
static const struct lys_node* lys_root = NULL;
+static const struct ly_ctx* ly_context = NULL;
/**
* Change callback getting called by sysrepo. Iterates over changed options and passes
goto cleanup;
/* obtain schema root node, will be used from within Lua */
- const struct ly_ctx* ly_context = sr_get_context(sr_connection);
+ ly_context = sr_get_context(sr_connection);
+ assert(ly_context != NULL);
lys_root = ly_ctx_get_node(ly_context, NULL, XPATH_BASE, 0);
assert(lys_root != NULL);
return lyd_new(parent, module, name);
}
KR_EXPORT const struct lys_module* schema_get_module(const struct lys_node* schema) {
+ assert(schema != NULL);
return schema->module;
}
KR_EXPORT const struct lys_node* schema_child_first(const struct lys_node* parent) {
+ assert(parent != NULL);
assert(
parent->nodetype == LYS_CONTAINER ||
parent->nodetype == LYS_LIST ||
}
KR_EXPORT const struct lys_node* schema_child_next(const struct lys_node* prev_child) {
+ assert(prev_child != NULL);
return prev_child->next;
}
KR_EXPORT const char* schema_get_name(const struct lys_node* node) {
+ assert(node != NULL);
return node->name;
}
assert(lys_root != NULL);
return lys_root;
}
+
+KR_EXPORT int node_validate(struct lyd_node* node) {
+ assert(node != NULL);
+ assert(ly_context != NULL);
+ return lyd_validate(&node, LYD_OPT_DATA | LYD_OPT_STRICT, (void*) ly_context);
+}
+
+KR_EXPORT void node_free(struct lyd_node* node) {
+ lyd_free_withsiblings(node);
+}
KR_EXPORT const char* schema_get_name(const struct lys_node* node);
/** Get schema root */
KR_EXPORT const struct lys_node* schema_root();
+/** Validate data tree */
+KR_EXPORT int node_validate(struct lyd_node* node);
+/** Free data nodes recursively */
+KR_EXPORT void node_free(struct lyd_node* node);
const char* schema_get_name(const struct lys_node* node);
/** Get schema root */
const struct lys_node* schema_root();
+ /** Validate data tree */
+ int node_validate(struct lyd_node* node);
+ /** Free data nodes recursively */
+ void node_free(struct lyd_node* node);
]]
end
local module = {}
function module.serialize_configuration(root_node)
init_schema()
- model:serialize(root_node)
+
+ -- serialize operational data
+ local node = model:serialize(root_node)
+ assert(node ~= nil)
+
+ -- validate the result
+ local validation_result = clib().node_validate(node)
+ if validation_result ~= 0 then
+ clib().node_free(node)
+ print("Tree validation failed, see printed libyang errors")
+ node = nil
+ end
+
+ return node
end
function module.apply_configuration(root_node)