ConfD User Community

How to create/delete leaf of type empty

Hi there ,
I have a yang file with the following entry

module lldp {
    leaf enable {
        type empty;
    }
}

I can see this keypath when I do

$ confd --cdb-debug-dump /path/to/confd/cdb-dir
...
/lldp:lldp/enable
...

and I can also read it during runtime, using

$ confd_load -oFc -p /lldp:lldp/enable 
lldp
 enable
exit

But, since the type of the lead lldp contains type empty in the lldp.yang file, we cannot set/change it’s value. According to the https://datatracker.ietf.org/doc/html/rfc6020#section-9.11, where it states “The empty built-in type represents a leaf that does not have any value, it conveys information by its presence or absence.”

I can enable this element through confd_cli using lldp [enable] and disable it using no lldp [enable] (yes the “enable” keyword can be omitted).

But I want to be able to do the same operation through the use of “confd_cmd” and/or “maapi” executables (in linux cli).

I can see that the entry is present using maapi_exists

$ confd_cmd -dd -o -c "maapi_exists /lldp:lldp/enable"
maapi_exists "/lldp:lldp/enable"
TRACE Connected (maapi) to ConfD
TRACE MAAPI_START_USER_SESSION  --> CONFD_OK
TRACE MAAPI_START_TRANS  --> CONFD_OK
TRACE MAAPI_EXISTS /lldp:lldp/enable --> CONFD_OK
yes
TRACE MAAPI_APPLY_TRANS  --> CONFD_OK
TRACE MAAPI_STOP_TRANS  --> CONFD_OK
TRACE MAAPI_END_USER_SESSION  --> CONFD_OK

But when I try to delete the node it fails using “delete” and maapi_delete" subcommands:

$ confd_cmd -dd -o -c "delete /lldp:lldp/enable"
maapi_delete "/lldp:lldp/enable"
TRACE Connected (maapi) to ConfD
TRACE MAAPI_START_USER_SESSION  --> CONFD_OK
TRACE MAAPI_START_TRANS  --> CONFD_OK
TRACE MAAPI_DELETE /lldp:lldp/enableDEBUG item is not writable - 
 --> CONFD_ERR
FAILED: maapi_delete(ms, mtid, argv[0]), Error: item is not writable (4): , in function do_maapi_delete, line 1506
$ confd_cmd -dd -o -c "maapi_delete lldp:lldp/enable"
delete "/lldp:lldp/enable"
TRACE Connected (cdb) to ConfD
TRACE CDB_NEW_SESSION  --> CONFD_OK
TRACE Established new CDB session to ConfD
TRACE CDB_DELETE /lldp:lldp/enableDEBUG badly formatted or nonexistent path - Not a cdb operational data path
 --> CONFD_ERR
FAILED: cdb_delete(cs, argv[0]), Error: badly formatted or nonexistent path (8): Not a cdb operational data path, in function do_cdb_delete, line 536

How can I delete and recreate this node? Can it be done through confd_cmd and/or maapi? Somehow else perhaps ?

Ultimately I want to add a clispec that defines a different convention to enable/disable this feature and call internally (through confd_cmd presumably) the same [no] lldp [enable] confd_cli commands. How can I do that ?

Thank you in advance for your help

Hi,

Is the leaf you are attempting to delete an operational data leaf? If it is configuration data, skip the “-o” flag if you want to access that leaf. The output of maapi_exists indicates that it is a “config true” leaf, but the output of the delete and maapi_delete command show it is a “config false” leaf.

   container lldp {
      config false;
      leaf enable {
         type empty;
      }
   }
$ confd_cmd -h | grep "\-o"
  -o             CDB commands work on CDB operational database
  1. You seem to have switched around the output of the delete and maapi_delete commands.

You can for example use the confd_cmd tool to perform MAAPI create, here “mcreate” or CDB API create commands or use the confd_load tool to create it. Use -o to address config false data, Change the namespace to your YANG models namespace in the below examples.
Create:

confd_cmd -dd -o -c 'mcreate "/lldp/enable"'
confd_cmd -dd -o -c 'create "/lldp/enable"'
confd_load -dd -o -l - <<< '<lldp xmlns="http://example.com/ns/lldp"><enable/></lldp>'

Delete:

confd_cmd -dd -o -c 'maapi_delete "/lldp/enable"'
confd_cmd -dd -o -c 'delete "/lldp/enable"'
1 Like

Hi there I am really not sure either. It probably is configuration data (there is no “config false” within the “container lldp”).If I retry the maapi_exist command without the “-o” I see

TRACE MAAPI_START_TRANS DEBUG item is not writable - Data store is not writable
 --> CONFD_ERR
FAILED: maapi_start_trans(ms, mdb, CONFD_READ_WRITE), Error: item is not writable (4): Data store is not writable, in function do_maapi_new_read_write_trans, line 1261

It appears one needs to do a change in the candidate database in order to this to work:

confd_cmd -e -c "maapi_delete /lldp:lldp/enable" ← delete from candidate db, but still in operational
confd_cmd -o -c "ccommit" <— candidate db committed to the operational.

Another question : why are there multiple patterns the maapi_* subcommands?

there is maapi_delete == mdel , but there is no maapi_create, only mcreate .

The candidate is for config only. When writing config to the candidate and committing it you first commit to the candidate and then the candidate to the running datastore like this:

confd_cmd -e -c "maapi_delete /lldp:lldp/enable; mcommit; ccommit"

Historic reasons. Btw, you have the source code for confd_cmd under $CONFD_DIR/src/confd/tools/confd_cmd.c