Cdb, cdb api, yang, python

I have inserted the data into the confd cdb database using confd_load. Now i want to retrieve the data as rpc reply using python. if i use cdb.get() function I can get only a single value but i need to get the whole inserted data as rpc reply how can i do it.

//servers.yang
module servers {
  namespace "http://example.com/ns/servers";
  prefix servers;

  import ietf-inet-types {
    prefix inet;
  }

  revision "2006-09-01" {
      description "Initial servers data model";
  }

  /*  A set of server structures  */
  container servers {
    list server {
      key name;
      max-elements 64;
      leaf name {
        type string;
      }
      leaf ip {
        type inet:ip-address;
        mandatory true;
      }
      leaf port {
        type inet:port-number;
        mandatory true;
      }
    }
  }
}
//servers.xml
<config xmlns="http://tail-f.com/ns/config/1.0">
  <servers xmlns="http://example.com/ns/servers">
      <server>
        <name>dns</name>
        <ip>192.168.3.5</ip>
        <port>53</port>
      </server>
      <server>
        <name>www</name>
        <ip>192.168.3.4</ip>
        <port>88</port>
      </server>
      <server>
        <name>www2</name>
        <ip>192.168.3.5</ip>
        <port>80</port>
      </server>
    </servers>
</config>

I am inserting the above xml data as into the cdb database I want to write a python code such that when i run the python code it will get the xml data as rpc reply

You do not mention your use-case → there are various ways to read data, depending on what you need specifically.

E.g.

  • northbound client (reading data in general, e.g. via maapi.save_config() with various formats supported)
  • southbound implementations like data provider, transformation daemon, CDB subscriber app
    (e.g. cdb.get_modifications() for pending commit, cdb.get_objects() for reading “whole” list entries), etc.

There is nothing like scenario i am just inserting the sample data and retrieving it but while retrieving i need to get the whole data as a rpc reply. Now i am get the data one at a time i.e., i am using cdb.get() to get to get the leaf.

<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
  <data>

<servers xmlns="http://example.com/ns/servers">
  <server>
    <name>dns</name>
    <ip>192.168.3.5</ip>
    <port>53</port>
  </server>
  <server>
    <name>www</name>
    <ip>192.168.3.4</ip>
    <port>88</port>
  </server>
  <server>
    <name>www2</name>
    <ip>192.168.3.5</ip>
    <port>80</port>
  </server>
</servers>

i need to get the below as output when i call the python code. is this possible? if yes how?

Screenshot from 2020-09-02 12-56-46

You can use ncclient for NETCONF calls from python.