diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index 15ede0cf..1345414c 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -6,8 +6,8 @@ bin_PROGRAMS = copy erase files copy_SOURCES = copy.c util.c util.h copy_CPPFLAGS = -D_DEFAULT_SOURCE -D_GNU_SOURCE copy_CFLAGS = -W -Wall -Wextra -copy_CFLAGS += $(libite_CFLAGS) $(sysrepo_CFLAGS) -copy_LDADD = $(libite_LIBS) $(sysrepo_LIBS) +copy_CFLAGS += $(libite_CFLAGS) $(libyang_CFLAGS) $(sysrepo_CFLAGS) +copy_LDADD = $(libite_LIBS) $(libyang_LIBS) $(sysrepo_LIBS) erase_SOURCES = erase.c util.c util.h erase_CPPFLAGS = -D_DEFAULT_SOURCE -D_GNU_SOURCE diff --git a/src/bin/configure.ac b/src/bin/configure.ac index 10aaf0a8..8b5c12c8 100644 --- a/src/bin/configure.ac +++ b/src/bin/configure.ac @@ -15,6 +15,7 @@ AC_PROG_INSTALL PKG_PROG_PKG_CONFIG PKG_CHECK_MODULES([libite], [libite >= 2.5.0]) +PKG_CHECK_MODULES([libyang], [libyang >= 3.0.0]) PKG_CHECK_MODULES([sysrepo], [sysrepo >= 2.2.36]) # Misc variable replacements for below Summary @@ -55,8 +56,8 @@ cat <datastore, timeout * 1000); - if (rc) - emsg(sess, ERRMSG "unable to copy configuration, err %d: %s\n", - rc, sr_strerror(rc)); - else - set_owner(dstds->path, user); + + /* + * When copying TO running-config, use sr_replace_config() + * to trigger change callbacks. Otherwise use sr_copy_config() + * for direct datastore copy without callbacks. + */ + if (dstds->datastore == SR_DS_RUNNING && srcds->path) { + rc = replace_running(conn, sess, srcds->path, timeout); + if (!rc) + set_owner(dstds->path, user); + } else { + /* Direct copy for other datastores (no callbacks needed) */ + rc = sr_copy_config(sess, NULL, srcds->datastore, timeout * 1000); + if (rc) + emsg(sess, ERRMSG "unable to copy configuration, err %d: %s\n", rc, sr_strerror(rc)); + else + set_owner(dstds->path, user); + } } rc = sr_disconnect(conn); @@ -320,9 +365,29 @@ static int copy(const char *src, const char *dst, const char *remote_user) if (rc) { fprintf(stderr, ERRMSG "failed downloading %s", src); } else { - rc = systemf("sysrepocfg -d %s -I%s -f json", dstds->sysrepocfg, fn); - if (rc) - fprintf(stderr, ERRMSG "failed loading %s from %s", dst, src); + /* Use replace_config() for running-config (triggers callbacks), sysrepocfg for others */ + if (dstds->datastore == SR_DS_RUNNING) { + if (sr_connect(SR_CONN_DEFAULT, &conn)) { + fprintf(stderr, ERRMSG "connection to datastore failed\n"); + rc = 1; + } else { + sr_log_syslog("klishd", SR_LL_WRN); + if (sr_session_start(conn, SR_DS_RUNNING, &sess)) { + fprintf(stderr, ERRMSG "unable to open transaction to %s\n", dst); + rc = 1; + } else { + sr_nacm_set_user(sess, user); + rc = replace_running(conn, sess, fn, timeout); + if (!rc) + set_owner(dstds->path, user); + } + sr_disconnect(conn); + } + } else { + rc = systemf("sysrepocfg -d %s -I%s -f json", dstds->sysrepocfg, fn); + if (rc) + fprintf(stderr, ERRMSG "failed loading %s from %s", dst, src); + } } } else { if (strstr(src, "://") && strstr(dst, "://")) {