Confd python package/library

Hi,

I’m very new to python and confd api’s. I want to do some POC to perform certain operations on host device. I’m looking for python package/modules/library, which is similar to confd-api jar, which can be installed into my development system (windows) for code development. Could someone please point to instructions on this.

Thanks,
-Venkat

The Python API can be found under $CONFD_DIR/src/confd/pyapi and the API docs under doc/api/python

Since ConfD doesn’t run under Windows, you need Linux. The easiest way nowadays would be to install Docker on your Windows machine and run ConfD in a Docker container.

Dockerfile for installing ConfD and running the iter_python example:

FROM python:latest

ARG CONFD_VERSION

ENV CONFD_VERSION=${CONFD_VERSION}
ENV DEBIAN_FRONTEND=noninteractive
ENV CONFD_DIR=/confd
ENV PATH=${CONFD_DIR}/bin:$PATH
ENV CONFD=${CONFD_DIR}/bin/confd
ENV LD_LIBRARY_PATH=${CONFD_DIR}/lib

WORKDIR /
RUN pip install --upgrade pip \
    && pip install --no-cache-dir paramiko \
    && apt-get update \
    && apt-get install psmisc libxml2-utils

COPY confd-${CONFD_VERSION}.linux.x86_64.installer.bin /tmp
COPY confd-${CONFD_VERSION}.examples.tar.gz /tmp
RUN ln -s libcrypto.so /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0 \
    && /tmp/confd-${CONFD_VERSION}.linux.x86_64.installer.bin ${CONFD_DIR}

# Add the ConfD cryptography integration and C-library API source
ADD confd-${CONFD_VERSION}.libconfd.tar.gz /tmp

# Rebuild the ConfD crypto integration for libcrypto1.1
WORKDIR /tmp/confd-${CONFD_VERSION}/libconfd
RUN make install_crypto

# Cleanup
RUN rm -rf /tmp/* /var/tmp/* \
    && apt-get autoremove -y \
    && apt-get clean

WORKDIR ${CONFD_DIR}/examples.confd/cdb_subscription/iter_python
# Build and create a startup script for one of the ConfD Python examples
RUN make all \
    && echo "#!/bin/bash" > ./run.sh \
    && echo "confd -c confd.conf --addloadpath $CONFD_DIR/etc/confd; python cdbl.py; tail -F confd.log" >> ./run.sh \
    && chmod +x ./run.sh

# Start one of the ConfD Python examples
EXPOSE 4565 2022
CMD [ "./run.sh" ]

Quick demo:

$ dir
Dockerfile 
confd-7.3.linux.x86_64.installer.bin 
confd-7.3.examples.tar.gz
confd-7.3.libconfd.tar.gz
$ docker build -t confd-docker-demo --build-arg CONFD_VERSION=7.3 -f Dockerfile .
$ docker run --name confd-docker-demo -d --rm -p 2022:2022 -p 4565:4565 confd-docker-demo
$ docker exec -it confd-docker-demo bash -c "netconf-console --edit-config=-<<<'<root xmlns=\"http://tail-f.com/ns/example/root\"><node-b><rf-head><dn>1</dn></rf-head></node-b></root>'"
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
  <ok/>
</rpc-reply>
$ docker exec -it confd-docker-demo netconf-console --get-config -x /root
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
  <data>
    <root xmlns="http://tail-f.com/ns/example/root">
      <node-b>
        <rf-head>
          <dn>1</dn>
        </rf-head>
      </node-b>
    </root>
  </data>
</rpc-reply>

If you just want the Python API I guess you could try to compile the Python API and libconfd for the Windows subsystem for Linux (WSL).

Thank you for your reply.

I’m successfully able to run python-confd application. But while listening to config changes, iter_func returns keypath as kp=/tag<1711485895>/tag<2105663071> /tag<840214230>,. But I’m expecting path as something like this ‘kp=/system:system/settings/xyz,’

Could you please let me know anything I’m missing.

Just load the schema first to get names instead of the hash representation. See maapi.load_schema()