At the prepare phase, the saved running and candidate configurations do not reflect the status seen on client.
The file examples.confd/cdb_subscription/twophase/twophase.c is modified for the following:
----
switch (type) {
case CDB_SUB_PREPARE:
printf("\nTYPE=CDB_SUB_PREPARE\n");
{
save_config(CONFD_CANDIDATE);
save_config(CONFD_RUNNING);
if (go_check_hardware() == 0) {
printf("send abort\n");
cdb_sub_abort_trans(ss, CONFD_ERRCODE_RESOURCE_DENIED,
0, 0, "HARDWARE IS NOT CONFIGURABLE");
}else {
printf("send CDB_DONE_PRIORITY\n");
cdb_sync_subscription_socket(ss, CDB_DONE_PRIORITY);
}
break;
}
----
void save_config(int db_mode)
{ /* save */
int id, ssock, r;
FILE *f;
char buf[BUFSIZ];
if ((tid = maapi_start_trans(sock, db_mode, CONFD_READ)) >= 0)
printf("GOT tid for config \n");
else
ERR("maapi_start_trans()", 1);
if (db_mode == CONFD_CANDIDATE){
if ((f = fopen("candidate.xml", "w")) == NULL)
fatal(errno, 1, "failed to open file %s", "defnet_c.xml");
}
if (db_mode == CONFD_RUNNING){
if ((f = fopen("running.xml", "w")) == NULL)
fatal(errno, 1, "failed to open file %s", "defnet_r.xml");
}
id = maapi_save_config(sock, tid, MAAPI_CONFIG_XML_PRETTY, "/system");
if (id <= 0)
ERR("maapi_save_config()", 1);
if ((ssock = socket(PF_INET, SOCK_STREAM, 0)) < 0 )
fatal(errno, 1, "failed to open socket");
OK(confd_stream_connect(ssock, (struct sockaddr*)&addr, addrlen, id, 0));
while ((r = read(ssock, buf, sizeof(buf))) > 0) {
if (fwrite(buf, 1, r, f) != r)
fatal(errno, 1, "failed to write output");
}
if (r < 0)
fatal(errno, 1, "failed to read from stream socket");
close(ssock);
OK(maapi_save_config_result(sock, id));
fprintf(f, "\n");
if (f != stdout) {
if (fclose(f) != 0)
fatal(errno, 1, "failed to write output");
}
OK(maapi_finish_trans(sock, tid));
}
----
I tried the abort scenario:
mnair-server# show running-config system
% No entries found.
mnair-server# config
Entering configuration mode terminal
admin(config)# system nodes node1 nodeA 1 nodeB 1 nodeC 2 nodeD 3
admin(config-nodes-node1)# commit
Aborted: resource denied: HARDWARE IS NOT CONFIGURABLE
admin(config)# show configuration
system nodes node1
nodeA 1
nodeB 1
nodeC 2
nodeD 3
!
admin(config)# show configuration running system
% No entries found.
----
Running and candidate Configs are saved in XML.
candidate.xml
::::::::::::::
running.xml
::::::::::::::
node1
1
1
2
3
----
This does not seem to be correct. At the prepare stage, the candidate config should be the same as the running.xml shown above. The running config should be empty, at this point since ‘commit’ has not occurred yet.