ConfD User Community

How to generate the string from keypath


#1

I am using an external Database, and need to construct a single string from the netconf query for get.

for example:

<dsa>
         <dsaId>2</dsaId>
         <sbControl>
           <control>sb</control>
            <sbatest>
               <sbaId>mnp</sbaId>
            </sbamnp>
         </sbControl>
       </dsa>
     </filter>

need to construct a string dsaId “2” control “sb” sbaId “mnp”
yang model

 list dsa {
  config false;
       tailf:callpoint appmap{
    }
    key dsaId;
      leaf dsaId {
      type uint32 {
        range "0 .. 2147483647";
      }
      mandatory true;
      description "integer";
    }
................
  list sbControl {
      key control;
      leaf control {
      type enumeration {
        enum sdf {
          tailf:code-name "mnp_0sdf";
          value 0;
        }
.....

as i understand for external Database config:false to be used. get_elem is invoked while querying using get in netconf, can it be worked to construct the string at a single place/or call ?
Please suggest


#2

Hello,

I guess you need to use some tool to convert XML node to XPATH syntax.
Something like https://stackoverflow.com/questions/4746299/generate-get-xpath-from-xml-node-java.


#3

if the cdb is used, the keypath will come nicely as a single string if used, confd_pp_kpath, is there any option available?
Given the above yang model, how can the user know, how many elements are in the tree? if this value is known then probably could use confd_pp_kpath at the last element.


#4

Hello,

If I understood it correctly, what you have is XML string returned by Netconf <get> query.
Your requirement is to print all (or one) keypaths found in the XML.
XML is outside ConfD application. Is this correct?

I do not think there is confd function takin XML and returning keypaths. There is confd_xpath_pp_kpath, but to use it, you would need to convert part6 of XML to confd_hkeypath_t, which is probably more work that directly covert to XPATH (with some tool like mentioned above)
In addition, you would need to do it in some application linking libconfd, which is another work.


#5

get_elem was invoked for each of the element. Queries can be dynamic in nature and given that situation, is there any way to find out did it reach at end of it?
if there is a way to find out, it reached at end of call, confd_pp_kpath could be used to find out the entire path.


#6

In case you have ConfD application processing data provider callbacks, you may gather paths in
get_elem. This will work in most case, but still this approach is probably not advisable.
You have to consider several things.

E.g.:

  • as you mention, it may not be easy to get point, when list traversal is over (usually when you reply to get_next that there are no other keys available - confd_data_reply_next_key(NULL, -1, -1))

  • callbacks may be called in parallel from different sessions

  • if you implement get_object or get_next_object, the get_elem may not be called at all

  • you need to implement some list/lists to store resulting xpath strings from get_elem

  • how you get results to your application/script where you need it (print to file?)