I’ve a requirement to verify the candidate DB is enabled in a running system using Maapi API.
Could you please let me know the API which helps in this case
You can use maapi_exists(). Demo using the confd_cmd tool:
$ confd_cmd -o -dd -c 'maapi_exists "/netconf-state/datastores/datastore{candidate}"'
maapi_exists "/netconf-state/datastores/datastore{candidate}"
TRACE Connected (maapi) to ConfD
TRACE MAAPI_START_USER_SESSION --> CONFD_OK
TRACE MAAPI_START_TRANS --> CONFD_OK
TRACE MAAPI_EXISTS /netconf-state/datastores/datastore{candidate} --> CONFD_OK
yes
TRACE MAAPI_APPLY_TRANS --> CONFD_OK
TRACE MAAPI_STOP_TRANS --> CONFD_OK
TRACE MAAPI_END_USER_SESSION --> CONFD_OK
Yes, but this API requires transaction Identifier right?
if that is true, should I pass db as candidate or running? what if some transaction is going on with lock while I’m startingTransaction to get transaction Identified?
As the “-o” flag I used with the confd_cmd tool above indicates, the transaction is started towards CONFD_OPERATIONAL
Thank you. Let me try with this.
Note that you should start your transaction as a read only transaction if you will only do a maapi_exists().
Again demoing using the confd_cmd tool:
$ confd_cmd -o -dd -c 'mrtrans; maapi_exists "/netconf-state/datastores/datastore{candidate}"'d
mrtrans ; maapi_exists "/netconf-state/datastores/datastore{candidate}" "d"
TRACE Connected (maapi) to ConfD
TRACE MAAPI_START_USER_SESSION --> CONFD_OK
TRACE MAAPI_START_TRANS --> CONFD_OK
TRACE MAAPI_EXISTS /netconf-state/datastores/datastore{candidate} --> CONFD_OK
no
TRACE MAAPI_END_USER_SESSION --> CONFD_OK
Yes, I just need to verify only exists of candidate in first. I’m doing startTransaction and then checking exists. And finally finish transaction.
int th = maapi.startTrans(Conf.DB_OPERATIONAL, Conf.MODE_READ);
boolean exists = maapi.exists(th, “/netconf-state/datastores/datastore{candidate}”)
maapi.finishTrans(th);
Hope these statements should work in this read transaction.