From b4ab32c03c7be4814c367246ec847771a92ab0d7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ale=C5=A1?= Date: Wed, 8 Jul 2020 14:17:32 +0200 Subject: [PATCH] demo: list configuration data --- utils/kresctl/commands.c | 46 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/utils/kresctl/commands.c b/utils/kresctl/commands.c index 60d5295ad..924d98916 100644 --- a/utils/kresctl/commands.c +++ b/utils/kresctl/commands.c @@ -200,8 +200,6 @@ static int cmd_export(cmd_args_t *args) char *yaml_out; yaml_out = to_yaml(data); - printf(yaml_out); - fprintf(file ? file : stdout, yaml_out); lyd_free_withsiblings(data); @@ -431,6 +429,50 @@ static int cmd_container(cmd_args_t *args) static int cmd_list(cmd_args_t *args) { + int ret = CLI_EOK; + + /* get operational data */ + if (!args->argc) { + + struct lyd_node *data = NULL; + sr_session_ctx_t *sr_session = NULL; + + if (!ret) ret = sr_session_start(sysrepo_ctx->connection, SR_DS_RUNNING, &sr_session); + if (!ret) ret = sr_get_data(sr_session, args->desc->xpath, 0, args->timeout, 0, &data); + if (ret) { + printf("get configuration data failed, %s\n", sr_strerror(ret)); + sr_session_stop(sr_session); + return CLI_ECMD; + } + + //lyd_print_file(stdout, data, LYD_JSON, LYP_FORMAT | LYP_WITHSIBLINGS); + + char *yaml; + yaml = to_yaml(data); + printf("\n%s\n", yaml); + + lyd_free_withsiblings(data); + sr_session_stop(sr_session); + free(yaml); + } + else { + /* check if there is an active session */ + if (!sysrepo_ctx->session) { + printf("no active transaction\n"); + return CLI_ECMD; + } + + if (!ret) ret = sr_session_switch_ds(sysrepo_ctx->session,SR_DS_CANDIDATE); + + /* set new configuration */ + + if (!ret) ret = sr_apply_changes(sysrepo_ctx->session, 0, 0); + if (ret) { + printf("set data value failed, %s\n", sr_strerror(ret)); + return CLI_ECMD; + } + } + return CLI_EOK; } -- 2.47.2