cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2049
Views
0
Helpful
1
Replies

removing configuration with ncclient

Ugur Ersoy
Level 1
Level 1

hello guys,

 

somehow I couldn't figure out the way to remove existing configuration with netconf. I created xml template based on yang file static for xr 6.5.3 as follows:

 

sr_config  = '''
<config>
  <router-static xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ip-static-cfg">
    <default-vrf>
      <address-family>
        <vrfipv4>
          <vrf-unicast>
            <vrf-prefixes>
              <vrf-prefix>
                <prefix>13.13.13.13</prefix>
                <prefix-length>32</prefix-length>
                <vrf-route>
                  <vrf-next-hop-table>
                    <vrf-next-hop-interface-name>
                      <interface-name>Null0</interface-name>
                      <tag>710</tag>
                      <description>test_netconf</description>
                    </vrf-next-hop-interface-name>
                  </vrf-next-hop-table>
                </vrf-route>
	      </vrf-prefix>
	     </vrf-prefixes>
          </vrf-unicast>
        </vrfipv4>
      </address-family>
    </default-vrf>
  </router-static>
 </config>
 '''

device_h.edit_config(target="candidate", config=sr_config)

I can filter it out too, but how I am supposed to delete this config? 

1 Reply 1

Hi Ugur,

 

Basically all you need is to add the XML namespace to the config tag and a delete operation on the 'vrf-prefix' element in addition to leafs identifying the particular route object to be deleted:

 

sr_config = '''<config xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
<router-static xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ip-static-cfg">
<default-vrf>
<address-family>
<vrfipv4>
<vrf-unicast>
<vrf-prefixes>
<vrf-prefix nc:operation="delete">
<prefix>13.13.13.13</prefix>
<prefix-length>32</prefix-length>
</vrf-prefix>
</vrf-prefixes>
</vrf-unicast>
</vrfipv4>
</address-family>
</default-vrf>
</router-static>
</config>'''
resp = device_h.edit_config(target="candidate", config=sr_config)
print(resp)
device_h.commit()

 

- Johnny