QuestionQ19

Device-Level Network Automation

Drag the code from the bottom into the missing-code boxes to build an ncclient request that captures operational IPv4 routing data from a Cisco IOS XE device. Not every option is used.

Drag & Drop
data = '''
< xmlns="urn:ietf:params:xml:ns:yang:ietf-routing">
  <routing-instance>
    <name>default</name>
    <ribs>
      <rib>
        <name>ipv4-default</name>
        <routes>
        </routes>
      </rib>
    </ribs>
  </routing-instance>
</routing-state>
'''
with manager.(host=HOST, password=PASSWORD, port=PORT,
                     username=USERNAME,hostkey_verify=False,
                     device_params={'name':'iosxe'}) as m:
    c = m.get(filter=("subtree", ))
    routing = xmltodict.parse(c)["rpc-reply"]["data"]
    routes =
routing["routing-state"][""]["ribs"]["rib"]["routes"]["route"]
    for route in routes:
        print("\n  destination: {}".format(route["destination-prefix"]))
        print("  nexthop int: {}".format(route["next-hop"]["outgoing-interface"]))
        print("  nexthop addr: {}".format(route["next-hop"]["next-hop-address"]))
Explanation

routing-state is the IETF routing operational-state container. manager.connect creates the ncclient NETCONF session, and the returned XML reply is parsed into a dictionary whose route hierarchy is routing-state → routing-instance → RIB → routes. Cisco’s ncclient examples use manager.connect with the IOS XE device handler.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!