Reset to default on deletion of config in CDB

Hi,

I have a query related to default values.
I am using openconfig stp configuration with some annotations on top of it.
default values are defined for config leafs.
when i do “no stp”, configuration is getting deleted and config leafs are set to default values.
But looks like leafs does not exist in CDB. when i tried to save configuration, no data related to stp is saved?
Could you let me know if there is a way to retain the leafs in CDB.

~Karthik

Handling default values is a bit tricky topic, but shortly, if you always want default values to be reported, set /confdConfig/defaultHandlingMode to report-all; if you just want then to be saved in your save command, use something like save /my/file stp | details.

See the confd.conf documentation for more details on default handling, also the RFC 6243 may be help you understand how default values work.

Hi @mvf ,

Thanks for the reply.
In my use case, when i do “no stp” and commit , i am expecting few config leafs to be retained, but values set to default values in CDB.

If you do no stp, there is nothing in CDB under the container stp, not even leafs with default value; not unless you set defaultHandlingMode to report-all, in which case it at least behaves as if these leafs were there if their parents were there too.

Hi @mvf ,

When “no stp” is called, in the backend code i see MOP_VALUE_SET is coming and cdb_exists is true.
After that when i try to save config using maapi_save_config, then data is not present. Could you please let me knwo if there any way i can set the value, so that data will be present?

~Karthik

You can use the maapi_save_config() MAAPI_CONFIG_WITH_DEFAULTS flag. See the confd_lib_maapi(5) man page for details.

Use the -W option with the confd_load tool to use the MAAPI_CONFIG_WITH_DEFAULTS flag. See the confd_load(1) man page for details.

Thanks @cohult
Apart from saving config, is there any way that i can do from backend code to set it to CDB?
I have a upgrade scenario where i am expecting values in CDB.

If you have /confdConfig/defaultHandlingMode set to “explicit” or “report-all” in confd.conf, for the leafs that have default values, you can set those leafs to the default value using MAAPI and the values will then be stored in CDB.
Example:

$ pwd
/confd/examples.confd/intro/1-2-3-start-query-model
$ make all start
...
$ confd_load -Fp -p /dhcp
<config xmlns="http://tail-f.com/ns/config/1.0">
</config>
$ confd_load -Fp -W -p /dhcp
<config xmlns="http://tail-f.com/ns/config/1.0">
  <dhcp xmlns="http://tail-f.com/ns/example/dhcpd">
    <default-lease-time>PT600S</default-lease-time>
    <max-lease-time>PT7200S</max-lease-time>
    <log-facility>local7</log-facility>
  </dhcp>
</config>
$ confd_load -Fp -W -p /dhcp > init.xml
$ confd_load -m -l init.xml
$ confd_load -Fp -p /dhcp
<config xmlns="http://tail-f.com/ns/config/1.0">
  <dhcp xmlns="http://tail-f.com/ns/example/dhcpd">
    <default-lease-time>PT600S</default-lease-time>
    <max-lease-time>PT7200S</max-lease-time>
    <log-facility>local7</log-facility>
  </dhcp>
</config>

Thanks @cohult
Will check if I can set from backend code using maapi