I’m trying to use maapi_roll_config() to read the actual rollback configuration after a commit has been done. I call maapi_roll_config() after have received a commit Notification. However, I tried many things, but I never seem to get anything. Is this API known to work? I’m using Confd version 8.0.16.
The maapi_roll_config() should be working as documented, but it is not exactly clear that you are using it per the documentation. You mention that you are calling it after you receive a commit Notification. When are you setting up the stream relative to your commit? Can you include some basic code that you are trying this with?
Hi Scott, thanks for responding. See below a snipped of the code:
I register for a commit notification using CONFD_NOTIF_COMMIT_DIFF. I call the code below immediately when having received a notification for CONFD_RUNNING.
char *confd_ip = (char *)"127.0.0.1";
int confd_port = CONFD_PORT;
char buf[1024];
int datastore = CONFD_RUNNING;
char *user = (char *)"admin";
const char *groups[] = {"admin"};
char *context = (char *)"system";
maapisock = socket(PF_INET, SOCK_STREAM, 0);
if (maapisock < 0) {
goto config_read_cleanup;
}
addr.sin_addr.s_addr = inet_addr(confd_ip);
addr.sin_family = AF_INET;
addr.sin_port = htons(confd_port);
src_addr.af = AF_INET;
inet_aton(confd_ip, &src_addr.ip.v4);
// Connect to maapi
res = maapi_connect(maapisock, (struct sockaddr *)&addr,
sizeof(struct sockaddr_in));
if (res < 0) {
goto config_read_cleanup;
}
// Start User Session
res = maapi_start_user_session(maapisock, user, context, groups, 1, &src_addr,
CONFD_PROTO_TCP);
if (res != CONFD_OK) {
goto config_read_cleanup;
}
thandle = maapi_start_trans(maapisock, datastore, CONFD_READ);
if (thandle < 0) {
goto config_read_cleanup;
}
id = maapi_roll_config(maapisock, thandle, "/");
streamsock = socket(PF_INET, SOCK_STREAM, 0);
confd_stream_connect(streamsock, (struct sockaddr *)&addr,
sizeof(struct sockaddr_in), id, 0);
while ((r = read(streamsock, buf, sizeof(buf))) > 0) {
printf("Rollback: %s\n", buf);
}
// This functions checks if the entire config was read.
res = maapi_roll_config_result(maapisock, id);
if (res != CONFD_OK) {
printf("Maapi roll config result failed (error %i)\n", res);
}
Let me also explain what my intention is, just in case there are other solutions. Based on a commit notification, I want to pull the rollback configuration diff for that commit. I am able to retrieve the list using maapi_list_rollbacks(). Is there a maapi command where I can retrieve the rollback diff using the fixed_nr? So essentially “show configuration rollback changes ”, but with the actual nr, not the relative number.
I agree it may be best to look for another solution. I was able to get output when I did e.g. a maapi_delete() and then did the maapi_roll_config() on that same socket:
int sock, tid, id, ssock;
char buf[size];
create_maapi_sesssion(addr, &sock, &tid, 0);
OK(maapi_delete(sock, tid, "/server"));
assert((id = maapi_roll_config(sock, tid, "/")) > 0);
if ((ssock = socket(PF_INET, SOCK_STREAM, 0)) < 0)
confd_fatal("Failed to open stream socket\n");
OK(confd_stream_connect(ssock,(struct sockaddr*)addr,
sizeof (struct sockaddr_in), id, 0));
while (read(ssock, buf, sizeof(buf)) > 0)
printf("roll received %s\n", buf);
maapi_roll_config_result(sock, id);
close(sock);
with some data:
roll received server abcdefghijklmnopqrstuvwxyz0 {
roll received opqrstuvwxyz1 {
roll received value abcdefghijklmnopqrstuvwxyz10b;
...
But I also didn’t see any data by attaching to the CONFD_RUNNING or even the ‘current’ transaction.