Confd_load filter the configuration using the XPath expression

Hi,

I’m trying to use confd_load -P to have one specific instance saved in one XML file as below. But the configuration is not saved correctly.

bash-4.2# /usr/confd/bin/confd_load -F x -P /dhcpd:dhcp/dhcpd:SharedNetworks/dhcpd:sharedNetwork[dhcpd:name=‘test’] -f /usr/confd/test.xml
bash-4.2# cat /usr/confd/test.xml

bash-4.2#

While I tried to save through confd cli and confd netconf, the xml file was saved correctly as below.

So could you let me know how to use confd_load to have the sharedNetwork that has name as “test” saved in XML file, as what I saved via CLI.

bash-4.2# /usr/confd/bin/confd_cli -C

test# config
test(config)# save /usr/confd/test_cli.xml xml dhcp SharedNetworks sharedNetwork test
Saving parts of the configuration.
test(config)# end

bash-4.2# cat /usr/confd/test_cli.xml




test



bash-4.2#

Netconf test:









]]>]]>

test

Repost my test result, as the last post does not show the XML result.

bash-4.2# /usr/confd/bin/confd_load -F x -P /dhcpd:dhcp/dhcpd:SharedNetworks/dhcpd:sharedNetwork[dhcpd:name=‘test’] -f /usr/confd/test.xml
bash-4.2# cat /usr/confd/test.xml
<-config xmlns=“http://tail-f.com/ns/config/1.0”>
bash-4.2#

netconf test:

<-rpc message-id="101"
          xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" >
       <-get-config>
         <-source>
           <-running/>
         <-/source>
         <-!-- get the user named fred -->
         <-filter xmlns:dhcpd="http://tail-f.com/ns/example/dhcpd"
                 type="xpath"
                 select="/dhcpd:dhcp/dhcpd:SharedNetworks/dhcpd:sharedNetwork[dhcpd:name='test']"/>
        <-/get-config>
     <-/rpc>]]>]]>

<-rpc-reply message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
  <-data>
    <-dhcp xmlns="http://tail-f.com/ns/example/dhcpd">
      <-SharedNetworks>
        <-sharedNetwork>
          <-name>test</name>
        <-/sharedNetwork>
      <-/SharedNetworks>
    <-/dhcp>
  <-/data>
<-/rpc-reply>

CLI test

test# config
test(config)# save /usr/confd/test_cli.xml xml dhcp SharedNetworks sharedNetwork test
Saving parts of the configuration.
test(config)# end

bash-4.2# cat /usr/confd/test_cli.xml

<-config xmlns="http://tail-f.com/ns/config/1.0">
  <-dhcp xmlns="http://tail-f.com/ns/example/dhcpd">
  <-SharedNetworks>
  <-sharedNetwork>
    <-name>test</name>
  <-/sharedNetwork>
  <-/SharedNetworks>
  <-/dhcp>

Hi,

You can use the preformatted text button </> to make for example XML readable when posting it.

Try adding "" around your xpath expression. I.e.:
$ /usr/confd/bin/confd_load -d -d -F x -P "/dhcpd:dhcp/dhcpd:SharedNetworks/dhcpd:sharedNetwork[dhcpd:name='test']" -f /usr/confd/test.xml

Hi,

Thanks so much for your help.

Addding “” works.

you can also use triple ``` with language name:

 ```xml
....
xml content
...

In this case you also get syntax highlighting.