ETExamTower
Q18Device-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. <DragDrop items={["xml","open","routing-instance","connect","routing-state","json"]} slots={[{"answer":"routing-state","id":"root"},{"answer":"connect","id":"connection"},{"answer":"xml","id":"filter"},{"answer":"routing-instance","id":"instance"}]} template={"data = '''\n<{{root}} xmlns=\"urn:ietf:params:xml:ns:yang:ietf-routing\">\n <routing-instance>\n <name>default</name>\n <ribs>\n <rib>\n <name>ipv4-default</name>\n <routes>\n </routes>\n </rib>\n </ribs>\n </routing-instance>\n</routing-state>\n'''\nwith manager.{{connection}}(host=HOST, password=PASSWORD, port=PORT,\n username=USERNAME,hostkey_verify=False,\n device_params={'name':'iosxe'}) as m:\n c = m.get(filter=(\"subtree\", {{filter}}))\n routing = xmltodict.parse(c)[\"rpc-reply\"][\"data\"]\n routes =\nrouting[\"routing-state\"][\"{{instance}}\"][\"ribs\"][\"rib\"][\"routes\"][\"route\"]\n for route in routes:\n print(\"\\n destination: {}\".format(route[\"destination-prefix\"]))\n print(\" nexthop int: {}\".format(route[\"next-hop\"][\"outgoing-interface\"]))\n 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.\n\n**Learn more:** [Cisco ncclient Code Exchange](https://developer.cisco.com/codeexchange/github/repo/ncclient/ncclient/)"} reuse={false} />

← → navigate · a answer
Community votes
Discussion · 2
@ 1
Selected Answer: D I'm stuck between D and [Option X]. Can someone explain why D is the better option?
1
Given answer is right.