# Confd API to update cli prompt

**URL:** <https://dmap-community.ductus.global/t/confd-api-to-update-cli-prompt/3555>\
**Category:** CDB and CDB API\
**Created:** [March 16, 2021, 6:28am UTC](https://dmap-community.ductus.global/t/confd-api-to-update-cli-prompt/3555 "2021-03-16T06:28:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![linga.kartheek](https://avatars.discourse-cdn.com/v4/letter/l/e9a140/32.png) [@linga.kartheek](https://dmap-community.ductus.global/u/linga.kartheek)\
**Post date:** [March 16, 2021, 6:28am UTC](https://dmap-community.ductus.global/t/confd-api-to-update-cli-prompt/3555/1 "2021-03-16T06:28:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cohult](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/cohult/32/221_2.png) [@cohult](https://dmap-community.ductus.global/u/cohult)\
**Post date:** [March 16, 2021, 7:13am UTC](https://dmap-community.ductus.global/t/confd-api-to-update-cli-prompt/3555/2 "2021-03-16T07:13:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![linga.kartheek](https://avatars.discourse-cdn.com/v4/letter/l/e9a140/32.png) [@linga.kartheek](https://dmap-community.ductus.global/u/linga.kartheek)\
**Post date:** [March 16, 2021, 7:46am UTC](https://dmap-community.ductus.global/t/confd-api-to-update-cli-prompt/3555/3 "2021-03-16T07:46:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cohult](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/cohult/32/221_2.png) [@cohult](https://dmap-community.ductus.global/u/cohult)\
**Post date:** [March 16, 2021, 9:11am UTC](https://dmap-community.ductus.global/t/confd-api-to-update-cli-prompt/3555/4 "2021-03-16T09:11:44Z")

</div>

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():

```auto
$ 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:

```auto
$ 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.

```auto
$ 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]));

```

---

<div class="post-metadata">

**Author:** ![josephm](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@josephm](https://dmap-community.ductus.global/u/josephm)\
**Post date:** [March 16, 2021, 9:55am UTC](https://dmap-community.ductus.global/t/confd-api-to-update-cli-prompt/3555/5 "2021-03-16T09:55:21Z")

</div>

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

```auto
...
  <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)

---

<div class="post-metadata">

**Author:** ![linga.kartheek](https://avatars.discourse-cdn.com/v4/letter/l/e9a140/32.png) [@linga.kartheek](https://dmap-community.ductus.global/u/linga.kartheek)\
**Post date:** [March 16, 2021, 10:40am UTC](https://dmap-community.ductus.global/t/confd-api-to-update-cli-prompt/3555/6 "2021-03-16T10:40:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![josephm](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@josephm](https://dmap-community.ductus.global/u/josephm)\
**Post date:** [March 16, 2021, 11:58am UTC](https://dmap-community.ductus.global/t/confd-api-to-update-cli-prompt/3555/7 "2021-03-16T11:58:38Z")

</div>

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…
