Confd API to update cli prompt

Hi,

Is there any confd API using which i can update confd cli prompt.
Currently it is considering hostname to display defined in prompt1 (\u@\h\M \t> ) in confd/scripts/confd.conf file.
I would like to update it dynamically without changing hostname. Could you please let me if that is possible.

Thanks,
Karthik

Hi,

See the examples.confd/confdconf/dyncfg example on how to enable dynamic config of for example the CLI prompt. The initial CLI prompt is set in the confd_dyncfg_init.xml file in that example.

Regards

Hi @cohult

Hope this is what you are referring
>

        <cli>
          <prompt1>\h\M&gt; </prompt1>
          <prompt2>\h\M% </prompt2>
        </cli>
      </confdConfig>

How can i use this to configure on fly. Is there any CDB api to update the same from a process.

Back to basics then, you can’t write configuration data through the CDB API, only read. You need to go through the transaction engine, i.e. you need to use MAAPI. There are plenty of MAAPI set examples in the ConfD example set and in this forum.

Another example that comes with source code is the confd_cmd tool that I mentioned in lots of previous replies. Here the confd_cmd tool use maapi_set_elem2():

$ confd_cmd -dd -c 'mset "/confdConfig/cli/prompt1" ">> "; mset "/confdConfig/cli/prompt2" "%% "'  
mset "/confdConfig/cli/prompt1" ">> " ; mset "/confdConfig/cli/prompt2" "%% "
TRACE Connected (maapi) to ConfD
TRACE MAAPI_START_USER_SESSION  --> CONFD_OK
TRACE MAAPI_START_TRANS  --> CONFD_OK
TRACE MAAPI_SET_ELEM2 /confdConfig/cli/prompt1 --> CONFD_OK
TRACE MAAPI_SET_ELEM2 /confdConfig/cli/prompt2 --> CONFD_OK
TRACE MAAPI_APPLY_TRANS  --> CONFD_OK
TRACE MAAPI_STOP_TRANS  --> CONFD_OK
TRACE MAAPI_END_USER_SESSION  --> CONFD_OK

See the confd_lib_maapi(3) man page for details on maapi_set_elem() and maapi_set_elem2().
Source code:

$ pwd
/Users/tailf/confd-7.5.1/src/confd/tools$ ls
Makefile.confd_cmd	Makefile.xmlset		confd_cmd.c		confd_load.c		xmlset.c

There are multiple examples in the ConfD example set.

$ pwd
/Users/tailf/confd-7.5.1/examples.confd
$ find . -name "*.c" |xargs grep maapi_set_elem
./misc/maapi_command/maapi.c:        if (maapi_set_elem2(sock, tid, valstr, path) != CONFD_OK)
./misc/aaa_transform/users_aaa.c:        OK(maapi_set_elem(maapi_socket, tctx->thandle, &list,
./misc/aaa_transform/users_aaa.c:        OK(maapi_set_elem(maapi_socket, tctx->thandle, &list,
./misc/aaa_transform/users_aaa.c:        if (maapi_set_elem(maapi_socket, tctx->thandle, newval,
./misc/aaa_transform/users_aaa.c:            OK(maapi_set_elem2(maapi_socket, tctx->thandle, "0",
./misc/aaa_transform/users_aaa.c:            OK(maapi_set_elem2(maapi_socket, tctx->thandle, "0",
./misc/aaa_transform/users_aaa.c:            OK(maapi_set_elem2(maapi_socket, tctx->thandle, "20",
./misc/aaa_transform/users_aaa.c:            OK(maapi_set_elem2(maapi_socket, tctx->thandle, "20",
./misc/aaa_transform/users_aaa.c:    OK(maapi_set_elem2(maapi_socket, tctx->thandle, buf,
./misc/aaa_transform/users_aaa.c:    OK(maapi_set_elem2(maapi_socket, tctx->thandle, buf,
./misc/maapi_cli/cliapp.c:            if (maapi_set_elem2(sock,tid,ipstr,"/root/servers/server{%s}/ip",name)
./misc/maapi_cli/cliapp.c:            if (maapi_set_elem2(sock,tid,portstr,"/root/servers/server{%s}/port",
./crypto/crypto2/crypto_keys.c:        if (maapi_set_elem2(msock, th, val, key) != CONFD_OK) {
./intro/11-c_hooks/hooks.c:                    != maapi_set_elem(maapisock, tctx->thandle, &gw, "%s/gw",
./intro/11-c_hooks/hooks.c:        if (CONFD_OK != maapi_set_elem(maapisock, th, &ipv6,
./intro/10-c_transform/src/cb_common.c:    int ret = maapi_set_elem(glob.maapi_socket, tctx->thandle, &val,
./intro/10-c_transform/src/cb_set_elem.c:                ret = maapi_set_elem(sock, th, newval,
./intro/10-c_transform/src/cb_set_elem.c:                ret = maapi_set_elem(sock, th, newval,
./intro/10-c_transform/src/cb_create.c:    OK(maapi_set_elem(glob.maapi_socket, tctx->thandle, username,
./intro/10-c_transform/src/cb_create.c:    OK(maapi_set_elem(glob.maapi_socket, tctx->thandle, &val,
./intro/10-c_transform/src/cb_create.c:    OK(maapi_set_elem(glob.maapi_socket, tctx->thandle, &v_content_bits,
./intro/10-c_transform/src/cb_remove.c:    OK(maapi_set_elem(glob.maapi_socket, tctx->thandle, &v_content_bits,
./cdb_upgrade/moved_servers/server_upgrade.c:        maapi_set_elem(ms, th, &ip, "ip");
./cdb_upgrade/moved_servers/server_upgrade.c:        maapi_set_elem(ms, th, &port, "port");
./cdb_upgrade/moved_servers/server_upgrade.c:        maapi_set_elem(ms, th, &aip, "admin-ip");
./cdb_upgrade/using_maapi/server_upgrade.c:        maapi_set_elem2(ms, th,
./cdb_upgrade/using_maapi/server_upgrade.c:        maapi_set_elem2(ms, th,
./cli/cli_command/add_user.c:    if (maapi_set_elem2(msock,thandle,sshdir,"user{%s}/ssh_keydir",user) !=
./cli/cli_command/add_user.c:    if (maapi_set_elem2(msock,thandle,pwd,"user{%s}/password",user) !=
./cli/cli_command/add_user.c:    if (maapi_set_elem2(msock,thandle,home,"user{%s}/homedir",user) !=
./cli/cli_command/add_user.c:    if (maapi_set_elem2(msock,thandle,gid,"user{%s}/gid",user) !=
./cli/cli_command/add_user.c:    if (maapi_set_elem2(msock,thandle,uid,"user{%s}/uid",user) !=
./snmpa/11-different-keys/hook.c:        OK(maapi_set_elem(msock, tctx->thandle, &v, "/servers/ifmap"));
./snmpa/11-different-keys/hook.c:        OK(maapi_set_elem(msock, tctx->thandle, &v, "%h/index", kp));
./snmpa/11-different-keys/hook.c:    OK(maapi_set_elem(msock, tctx->thandle, &v, "/servers/ifmap"));
./snmpa/11-different-keys/hook.c:     * hook when calling maapi_set_elem in the create set hook, and
./snmpa/11-different-keys/hook.c:        OK(maapi_set_elem(msock, tctx->thandle, &v, "/servers/ifmap"));
./snmpa/11-different-keys/hook.c:        OK(maapi_set_elem(msock, tctx->thandle, &v, "%*h/service-map",
./snmpa/11-different-keys/hook.c:        OK(maapi_set_elem(msock, tctx->thandle, &v, "%h/index", kp));
./snmpa/11-different-keys/hook.c:    OK(maapi_set_elem(msock, tctx->thandle, &v, "%*h/service-map",
./snmpa/11-different-keys/hook.c:     * hook when calling maapi_set_elem in the create set hook, and
./snmpa/11-different-keys/hook.c:        OK(maapi_set_elem(msock, tctx->thandle, &v, "%*h/service-map",
./snmpa/7-transform/transform.c:            OK(maapi_set_elem(msock, thandle, &v,
./snmpa/7-transform/transform.c:            OK(maapi_set_elem(msock, thandle, &v,
./snmpa/7-transform/transform.c:    OK(maapi_set_elem(msock, tctx->thandle, &v,
./snmpa/7-transform/transform.c:        OK(maapi_set_elem(msock, tctx->thandle, &sysUpTime,
./snmpa/7-transform/transform.c:        OK(maapi_set_elem(msock, tctx->thandle, &sysUpTime,
./snmpa/7-transform/transform.c:                OK(maapi_set_elem(msock, tctx->thandle, &ip_address,
./snmpa/7-transform/transform.c:    maapi_set_elem(msock, tctx->thandle, area_id,
./snmpa/7-transform/transform.c:    maapi_set_elem(msock, tctx->thandle, iface_name,
./snmpa/7-transform/transform.c:            return maapi_set_elem(msock, th, newval,
./snmpa/7-transform/transform.c:            return maapi_set_elem(msock, th, newval,
./snmpa/7-transform/transform.c:            return maapi_set_elem(msock, th, newval,
./snmpa/7-transform/transform.c:            return maapi_set_elem(msock, th, newval,
./snmpa/7-transform/transform.c:                OK(maapi_set_elem(msock,th, newval,
./snmpa/7-transform/transform.c:                OK(maapi_set_elem(msock,th, &v,
./snmpa/7-transform/transform.c:                return maapi_set_elem(msock, th, newval,
./snmpa/7-transform/transform.c:            if (maapi_set_elem(msock, tctx->thandle, &v,
./snmpa/7-transform/transform.c:            return maapi_set_elem(
./linuxcfg/ietf_system/ietf_system.c:    result = maapi_set_elem(maapi_socket, tctx->thandle, newval,
./linuxcfg/ietf_system/ietf_system.c:        result = maapi_set_elem(maapi_socket, tctx->thandle, newval,
./in_service_upgrade/with_helper/src/v2/upgrade_helper.c:        OK(maapi_set_elem2(ms, th, "0.0.0.0", "server{%x}/proxy", &mc.keys[0]));
./in_service_upgrade/with_helper/src/v2/upgrade_helper.c:        OK(maapi_set_elem2(ms, th, "true", "server{%x}/enabled", &mc.keys[0]));

to rephrase the previous answers, the section you have identified in confd.conf file:

...
  <cli>
    <prompt1>\h\M&gt; </prompt1>
    <prompt2>\h\M% </prompt2>
  </cli>
</confdConfig>

can help you, but…

If you want to update it dynamically (using northbound APIs like MAAPI/CLI/NETCONF…), you need to enable dynamic configuration in ConfD as @cohult originally referred to.

After you’ve done that - you can edit parts of /confdConfig/... including the ../cli/prompt1 etc. int the same way as any other device configuration…

(plus you may need to update access rights or exporting for specific northbound API for the dynconfig model of course so it’s not accessible to any user)

Hi @cohult & @josephm

Thanks for the reply.

May be i didn’t put my question correctly.
Lets say for example, when i enter confd cli i am getting as “App-1#”, i would like to change it to “App-2#”. Is
it possible to update it dynamically?
Lets say if my prompt looks like \h\M# , so here it refers hostname of the system and displays it when we enter confd cli. I would like to change the cli prompt string with a new hostname without changing the hostname of the system.

Yes of course, just don’t use template variables like \h for hostname, or use other ones that fit your requirement… They are described e.g. in linux manual page of man confd.conf: for node /confdConfig/cli/prompt1.

  1. enable dynamic config,
  2. set prompt1/prompt2 nodes in ConfD daemon configuration to any text you want/like e.g. using cli, or any other northbound api…

edit: there are two separate settings for different CLI styles - prompt1 vs cPrompt1, and same for prompt2…