Browse Source

Implement commit check command

Serj Kalichev 1 year ago
parent
commit
363c02102f
4 changed files with 40 additions and 2 deletions
  1. 1 0
      src/plugin.c
  2. 1 0
      src/private.h
  3. 29 2
      src/syms.c
  4. 9 0
      xml/sysrepo.xml

+ 1 - 0
src/plugin.c

@@ -74,6 +74,7 @@ int kplugin_sysrepo_init(kcontext_t *context)
 	kplugin_add_syms(plugin, ksym_new_ext("srp_up", srp_up,
 		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
 	kplugin_add_syms(plugin, ksym_new("srp_insert", srp_insert));
+	kplugin_add_syms(plugin, ksym_new("srp_verify", srp_verify));
 	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));

+ 1 - 0
src/private.h

@@ -52,6 +52,7 @@ int srp_edit(kcontext_t *context);
 int srp_top(kcontext_t *context);
 int srp_up(kcontext_t *context);
 int srp_insert(kcontext_t *context);
+int srp_verify(kcontext_t *context);
 int srp_commit(kcontext_t *context);
 int srp_rollback(kcontext_t *context);
 int srp_show(kcontext_t *context);

+ 29 - 2
src/syms.c

@@ -676,7 +676,7 @@ err:
 }
 
 
-int srp_commit(kcontext_t *context)
+int srp_verify(kcontext_t *context)
 {
 	int ret = -1;
 	sr_conn_ctx_t *conn = NULL;
@@ -689,16 +689,43 @@ int srp_commit(kcontext_t *context)
 		return -1;
 	}
 
-	// Validate candidate config
 	if (sr_session_start(conn, SRP_REPO_EDIT, &sess)) {
 		fprintf(stderr, "Can't connect to candidate data store\n");
 		goto err;
 	}
+
+	// Validate candidate config
 	if (sr_validate(sess, NULL, 0) != SR_ERR_OK) {
 		fprintf(stderr, "Invalid candidate configuration\n");
 		goto err;
 	}
 
+	ret = 0;
+err:
+	sr_disconnect(conn);
+
+	return ret;
+}
+
+
+int srp_commit(kcontext_t *context)
+{
+	int ret = -1;
+	sr_conn_ctx_t *conn = NULL;
+	sr_session_ctx_t *sess = NULL;
+
+	assert(context);
+
+	if (sr_connect(SR_CONN_DEFAULT, &conn)) {
+		fprintf(stderr, "Can't connect to data repository\n");
+		return -1;
+	}
+
+	if (sr_session_start(conn, SRP_REPO_EDIT, &sess)) {
+		fprintf(stderr, "Can't connect to candidate data store\n");
+		goto err;
+	}
+
 	// Copy candidate to running-config
 	if (sr_session_switch_ds(sess, SR_DS_RUNNING)) {
 		fprintf(stderr, "Can't connect to running-config data store\n");

+ 9 - 0
xml/sysrepo.xml

@@ -169,8 +169,17 @@
 		<ACTION sym="srp_insert@sysrepo"/>
 	</ENTRY>
 
+	<ENTRY name="verify" help="Commit data to running-config" mode="sequence">
+		<ENTRY name="COMMAND" purpose="ptype" ref="/COMMAND"/>
+		<ACTION sym="srp_commit@sysrepo"/>
+	</ENTRY>
+
 	<ENTRY name="commit" help="Commit data to running-config" mode="sequence">
 		<ENTRY name="COMMAND" purpose="ptype" ref="/COMMAND"/>
+		<ENTRY name="check" help="Verify the candidate configuration" mode="sequence" min="0">
+			<ENTRY name="COMMAND" purpose="ptype" ref="/COMMAND"/>
+			<ACTION sym="srp_verify@sysrepo"/>
+		</ENTRY>
 		<ACTION sym="srp_commit@sysrepo"/>
 	</ENTRY>