Maapi function to check uncommited changes on exit

I am using MAAPI to connect to ConfD. I am looking for a function to check if there are uncommited changes before exiting configuration mode. I have read the documentation, but cannot found it. Can anybody show me the function?

It is not clear what you want to achieve. If it is that something checks if there are uncommitted changes when you try to exit, ConfD already does that. If you want be able to run your command that does this check, you can do that: write a custom CLI command that runs maapi_diff_iterate or an equivalent. If you want to have such a command that is run as a hook when you try to exit the config mode, I do not think this is possible.

I do not use confd_cli, but I am using maapi to write a program like confd_cli. In the case of confd_cli, we enter configuration mode, do some configuration changes. Then we type exit, exit, … to return to operation mode. The confd_cli will ask if we want to commit these changes or not. This behavior is what I want when maapi is used instead of confd_cli.

I see. As I wrote, the function maapi_diff_iterate can be used to check if there are changes in the current transaction. The function is actually intended to check what exactly those changes are, but if you are interested only in whether there are some, you can call it with a very simple iter function as an argument.

Regarding maapi_cli_diff_cmd(), maapi_is_running_modified(), and maapi_is_candidate_modified():

  • You can use maapi_is_candidate_modified() to check if the candidate has been modified by a session and not yet committed to running
  • You can only use maapi_is_running_modified() if the startup datastore has been enabled to check if running has been modified by a session and not yet copied to startup.
  • To check if the running datastore has been modified by a transactions private shadow datastore, you can use maapi_diff_iterate() as @mfv suggests
  • Or use maapi_cli_diff_cmd() that return 0 if there are modifications. You can use a buffer of size 0 if you are not interested in the diff