How to get default value for the specific leaf?

Hi,

Is there any ConfD APIs that I can use to get the default value for one specific leaf node?

I write the model as below. I want to set the leaf “restart-time” to its default value (by hooking) when the container ‘server’ is deleted, so I want to get the default value of the leaf “restart-time”. Is there API I can use to get the default value defined in model? Thanks.

container server {
presence “”;
description
“server”;
tailf:callpoint server-hook {
tailf:set-hook subtree;
}
leaf restart-time {
type uint16 {
range “10…4095”;
}
default “120”;
description
“maximim restart timer for the server”;
}
}

Yes, if you have loaded schema information into the library by using e.g. confd_load_schemas(), you can get it from there, e.g. as

struct confd_cs_node *csp = confd_cs_node_cd(NULL, "/server/restart-time");
confd_value_t *default = csp->info.defval;

I’m not sure how this is actually relevant to your intended usage though:

Sorry, this doesn’t make sense - since the ‘restart-time’ leaf is a child of the ‘server’ container, there is no way to access that leaf if the ‘server’ container doesn’t exist, whether for setting a value or anything else.

If the ‘server’ container is not deleted, but the ‘restart-time’ leaf is deleted - or the ‘server’ container is created without setting a value for the ‘restart-time’ leaf, which will have the same result - the default value of the leaf is by definition “in effect”, and there is no reason to set it.

In fact setting a leaf to its default value has a result that is significantly different from having the default value be “in effect” - it is no longer a default, but an explicitly set value that just “happens” to be the same as the default value, and this affects e.g. the rendering in NB interfaces.

I think it would help if you explained what you are trying to achieve, rather than what you want to do…

Minor correction/clarification: your set-hook will actually be invoked before the deletion of the container has been carried out, and at that point the hook can set a value for the leaf - but it still doesn’t make sense, since the leaf will be deleted along with the container, and the value that you set will be lost.

Thanks for the clarification.

Yes, you are right that in common case it does not make sense to explicitly set the leaf to its default value when its parent container is deleted. While my case is little special. I want to use the confd_dyncfg to allow operator change CLI/Netconf maximum session number. I met the issue as described in Confd dyncfg default value. So I have to write a model
container session-limits {
presence “”;
container session-limit{
presence “”;
leaf max-cli-sessions {
type int;
default 100;
}
leaf max-netconf-sessions {
type int;
default 100;
}
}

and set the “/dyncfg:confdConfig/sessionLimits/sessionLimit[context=‘cli’]/maxSessions” to its default value when the container "session-limits " in my model is deleted, else I will loss the control for the max CLI/Netconf session.

Aha, so your initial description was a bit off, claiming that you wanted to use a hook to set the leaf that is a child of the presence container. What you actually want to do, i.e. set the leaf in the confd_dyncfg tree to the default value in your “front-end” data model makes perfect sense, and you can use the method I described to get hold of that default value. And while the method described in the referenced post, with the leafs pointed to confd_dyncfg via tailf:link plus a hook to set the default when the front-end container is deleted should work, it would perhaps be “cleaner” and more straightforward to use a transform instead, mapping all changes in the front-end model to your desired result in confd_dyncfg. I.e. the transform would replace both the tailf:link statements (which are effectively “single-leaf transforms”) and the hook.

Thanks a lot Per for the suggestion on transform.
I have read the transform section, and yes, it’s the more appropriate in my case.