CiscoDevNet / ydk-gen

Generate model-driven APIs from YANG models
http://ciscodevnet.github.io/ydk-gen/
Apache License 2.0
137 stars 74 forks source link

Issue with crud.delete - please confirm YDK generate the right XML payload #397

Closed marumer closed 7 years ago

marumer commented 7 years ago

Hi All,

I am trying using the crud.delete method to delete a specific static route but the outcome is that all static routes are getting deleted. The YDK originated XML debug seems adding the operation="delete" in the wrong location of the XML payload.

This is the YDK RPC trace, with the operation="delete" added to the router-static xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ip-static-cfg name space that based on my testing delete all static routes in the router:

Apologies for the poor formatting below but the best i can do is to format the RPC as code, you should be able to see a better format when you update the message.

 xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:ed6864cf-4d91-46e9-a761-a9503df85313">
  <edit-config>
    <target>
      <candidate/>
    </target>
    <config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
      <router-static xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ip-static-cfg" xc:operation="delete">
        <default-vrf>
          <address-family>
            <vrfipv4>
              <vrf-unicast>
                <vrf-prefixes>
                  <vrf-prefix>
                    <prefix>2.2.2.0</prefix>
                    <prefix-length>25</prefix-length>
                    <vrf-route>
                      <vrf-next-hop-table>
                        <vrf-next-hop-next-hop-address>
                          <next-hop-address>192.168.10.5</next-hop-address>
                        </vrf-next-hop-next-hop-address>
                      </vrf-next-hop-table>
                    </vrf-route>
                  </vrf-prefix>
                </vrf-prefixes>
              </vrf-unicast>
            </vrfipv4>
          </address-family>
        </default-vrf>
      </router-static>
    </config>
  </edit-config>
</rpc>

This is a separate XML with the xc:operation="delete" added to the vrf-prefix that properly delete only the specified route in the XML payload. If you move the operation="delete" to the "router-static xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ip-static-cfg" you are going to get the same behaviour experienced with YDK. I have tested this pushing the XML with ncclient.

edit_data = '''
<config xmlns:xc="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 xc:operation="delete">
        <prefix>2.2.2.0</prefix>
        <prefix-length>25</prefix-length>
        </vrf-prefix>
    </vrf-prefixes>
    </vrf-unicast>
    </vrfipv4>
    </address-family>
  </default-vrf>
</router-static>
</config>

I am adding here a snip of the configuration used to delete the route in YDK (that generates the RPC described at the beginning of this email).

from ydk.models.cisco_ios_xr import Cisco_IOS_XR_ip_static_cfg as xr_ip_static_cfg
new_route_static = xr_ip_static_cfg.RouterStatic()  # create object static route
vrf_unicast = new_route_static.default_vrf.address_family.vrfipv4.vrf_unicast
vrf_prefix = vrf_unicast.vrf_prefixes.VrfPrefix()
vrf_prefix.prefix = "2.2.2.0"
vrf_prefix.prefix_length = 25
vrf_next_hop_next_hop_address = vrf_prefix.vrf_route.vrf_next_hop_table.VrfNextHopNextHopAddress()
vrf_next_hop_next_hop_address.next_hop_address = "192.168.10.5"
vrf_prefix.vrf_route.vrf_next_hop_table.vrf_next_hop_next_hop_address.append(vrf_next_hop_next_hop_address)
vrf_unicast.vrf_prefixes.vrf_prefix.append(vrf_prefix)

try:
    crud.delete(provider, new_route_static)
except:
    sys.exc_info()[0]

Regards, Marco

psykokwak4 commented 7 years ago

Hi Marco,

Is crud.delete(provider, vrf_prefix) working for you?

ghost commented 7 years ago

Just edited your post, Marco, to better format it

marumer commented 7 years ago

Thank you you your comment Xiaoqin. You are right, I have tested that I need to pass part of the object to achieve selected delete. It is a logical construct to be selective operation="delete" placement but is it any documentation describing it? Apologies if I have missed it but I am sure it would be useful for others.

Thank you again, Regards, Marco

marumer commented 7 years ago

Closing after confirming solution to pass just the prefix object as crud.delete(provider, vrf_prefix).

psykokwak4 commented 7 years ago

Sorry, the documentation seems out-dated, and I think you're right, we should add documentation for this.