Browse Source

Oper mode: show configuration command

Serj Kalichev 1 year ago
parent
commit
bef22d627c
4 changed files with 37 additions and 2 deletions
  1. 1 0
      src/plugin.c
  2. 27 2
      src/syms.c
  3. 1 0
      src/syms.h
  4. 8 0
      xml/sysrepo.xml

+ 1 - 0
src/plugin.c

@@ -72,6 +72,7 @@ int kplugin_sysrepo_init(kcontext_t *context)
 	kplugin_add_syms(plugin, ksym_new("srp_commit", srp_commit));
 	kplugin_add_syms(plugin, ksym_new("srp_rollback", srp_rollback));
 	kplugin_add_syms(plugin, ksym_new("srp_show", srp_show));
+	kplugin_add_syms(plugin, ksym_new("srp_show_running", srp_show_running));
 	kplugin_add_syms(plugin, ksym_new("srp_deactivate", srp_deactivate));
 
 	return 0;

+ 27 - 2
src/syms.c

@@ -863,7 +863,7 @@ err:
 }
 
 
-int srp_show(kcontext_t *context)
+static int show(kcontext_t *context, sr_datastore_t ds)
 {
 	int ret = -1;
 	faux_argv_t *args = NULL;
@@ -879,7 +879,7 @@ int srp_show(kcontext_t *context)
 
 	if (sr_connect(SR_CONN_DEFAULT, &conn))
 		return -1;
-	if (sr_session_start(conn, SRP_REPO_EDIT, &sess)) {
+	if (sr_session_start(conn, ds, &sess)) {
 		sr_disconnect(conn);
 		return -1;
 	}
@@ -928,6 +928,31 @@ err:
 }
 
 
+int srp_show(kcontext_t *context)
+{
+	return show(context, SRP_REPO_EDIT);
+}
+
+
+int srp_show_running(kcontext_t *context)
+{
+	sr_conn_ctx_t *conn = NULL;
+	sr_session_ctx_t *sess = NULL;
+
+	if (sr_connect(SR_CONN_DEFAULT, &conn))
+		return -1;
+	if (sr_session_start(conn, SR_DS_RUNNING, &sess)) {
+		sr_disconnect(conn);
+		return -1;
+	}
+
+	show_xpath(sess, NULL, SRP_DEFAULT_PARSE_OPTS);
+	sr_disconnect(conn);
+
+	return 0;
+}
+
+
 int srp_deactivate(kcontext_t *context)
 {
 	int ret = -1;

+ 1 - 0
src/syms.h

@@ -46,6 +46,7 @@ int srp_insert(kcontext_t *context);
 int srp_commit(kcontext_t *context);
 int srp_rollback(kcontext_t *context);
 int srp_show(kcontext_t *context);
+int srp_show_running(kcontext_t *context);
 int srp_deactivate(kcontext_t *context);
 
 C_DECL_END

+ 8 - 0
xml/sysrepo.xml

@@ -65,6 +65,14 @@
 		<ACTION sym="nav">replace sysrepo</ACTION>
 	</ENTRY>
 
+	<ENTRY name="show" help="Show" mode="switch">
+		<ENTRY name="COMMAND" purpose="ptype" ref="/COMMAND"/>
+		<ENTRY name="configuration" help="Show running-config" mode="sequence">
+			<ENTRY name="SUBCOMMAND" purpose="ptype" ref="/SUBCOMMAND"/>
+		</ENTRY>
+		<ACTION sym="srp_show_running@sysrepo"/>
+	</ENTRY>
+
 </ENTRY>