ConfD User Community

How to define a YANG list with multiple optional keys

Hi ,
I am new to tailf and I was trying to define YANG model to render a CLI for one of our use cases in which I have a table and there are multiple keys for the table however the user may chose not to provide all the keys and only provide a combination of them.

For example , lets take a simplified use case such as a employee database where each entry of the employee list identifies uniquely an employee . An employee could be a contractor - so there are 2 keys for the entries - employee id and contractor id. A contractor will have both an employee id and a contractor id.

Now from the northbound interface , a user may give either employee id or contractor-id or he may provide both.

The user should be able to show the entries based on either of these keys ( employee id or contractor id ) or a combination.

I have tried using tailf extension of providing default values for keys - but I have faced other issues there ,since the CLI is interactive , it first prompts the user to give values for the first leaf node defined in the key statement - so the order in which the keys are given gets fixed. Is there a way to over-ride this behavior ?

Any response to this query will be much appreciated as this has become a blocker for us.

Thanks and Regards,
Rishi Raj

Have you tried using the wildcard as the employee id key when being prompted by CLI?

I have come up with the following simple example to illustrate how that would look like:

$ make clean all start
rm -rf
*.o *.a *.xso *.fxs *.xsd *.ccl
_proto.h
./confd-cdb .db aaa_cdb.
rollback
/rollback{0…999} rollback{0…999}
host.key host.cert ssh-keydir
.log confderr.log.
etc .access
running.invalid global.data _tmp

rm -rf hrdb.h > /dev/null || true
$CONFD_DIR/confd-6.0.1/ConfD/bin/confdc --fail-on-warnings -c -o hrdb.fxs hrdb.yang
mkdir -p ./confd-cdb 2>/dev/null || true
cp $CONFD_DIR/var/confd/cdb/aaa_init.xml ./confd-cdb
ln -s $CONFD_DIR/etc/confd/ssh ssh-keydir
Build complete
$CONFD_DIR/bin/confd --stop || true
connection refused (stop)
$CONFD_DIR/bin/confd -c confd.conf --addloadpath $CONFD_DIR/etc/confd
$ cat hrdb.yang

module hrdb {
   namespace "urn:hrdb";
   prefix hrdb;

   import tailf-common {
   prefix tailf;
}

  container db {
   list employees {
    key "employee_id contractor_id";
    leaf employee_id { 
      tailf:cli-expose-key-name;
      type uint32;
    }
    leaf contractor_id {
      tailf:cli-expose-key-name;
      type uint32;
    }
    leaf age { type uint16; }
    }
  }
}

$ confd_load -l -m cmd-initialize-db.xml
$ cat cmd-initialize-db.xml

<config xmlns="http://tail-f.com/ns/config/1.0">
  <db xmlns="urn:hrdb">
    <employees>
      <employee_id>1</employee_id>
      <contractor_id>101</contractor_id>
      <age>21</age>
    </employees>
    <employees>
      <employee_id>2</employee_id>
      <contractor_id>102</contractor_id>
      <age>22</age>
    </employees>
  </db>
</config>

$ confd_load -l -m cmd-initialize-db.xml
$ cat cmd-get-id.xml

<?xml version="1.0" encoding="UTF-8"?>
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
  <capabilities>
    <capability>urn:ietf:params:netconf:base:1.0</capability>
  </capabilities>
</hello>
]]>]]>
<?xml version="1.0" encoding="UTF-8"?>
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
  <get>
    <filter xmlns="urn:hrdb">
      <db/>
    </filter>
  </get>
</rpc>
]]>]]>
<?xml version="1.0" encoding="UTF-8"?>
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
  <close-session/>
</rpc>

$ netconf-console cmd-get-id.xml

<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
  <data>
    <db xmlns="urn:hrdb">
      <employees>
        <employee_id>1</employee_id>
        <contractor_id>101</contractor_id>
        <age>21</age>
      </employees>
      <employees>
        <employee_id>2</employee_id>
        <contractor_id>102</contractor_id>
        <age>22</age>
      </employees>
    </db>
  </data>
</rpc-reply>

$ make cli-c
$CONFD_CIR/bin/confd_cli -C --user=admin --groups=admin
–interactive || echo Exit

admin connected from 127.0.0.1 using console on WAITAI-M-K092
WAITAI-M-K092# show running-config
Possible completions:
aaa AAA management
alias Create command alias.
db
nacm Access control
session Global default CLI session parameters
user User specific command aliases and default CLI session parameters
webui Web UI specific configuration
| Output modifiers

WAITAI-M-K092# show running-config db
db employees employee_id 1 contractor_id 101
age 21
!
db employees employee_id 2 contractor_id 102
age 22
!
WAITAI-M-K092# show running-config db employees
Possible completions:
employee_id |
Possible match completions:
age
WAITAI-M-K092# show running-config db employees employee_id 1
db employees employee_id 1 contractor_id 101
age 21
!
WAITAI-M-K092# show running-config db employees employee_id *
Possible completions:
contractor_id |
Possible match completions:
age
WAITAI-M-K092# show running-config db employees employee_id * contractor_id 102
db employees employee_id 2 contractor_id 102
age 22
!
WAITAI-M-K092# show running-config db employees employee_id 1 contractor_id 101
db employees employee_id 1 contractor_id 101
age 21
!