350-901 · Question #54
Refer to the exhibit. What is the output of this IOS-XE configuration program? ``python import sys, requests USER = 'root' PASS = 'Cisco0123' URI = URL +…
The correct answer is B. interface administrative status in IPv4 addresses. The Python script queries the RESTCONF interfaces endpoint and prints interface admin status alongside IPv4 addresses parsed from the YANG ietf-interfaces model.
Question
import sys, requests
USER = 'root'
PASS = 'Cisco0123'
URI = URL + '/restconf/data/ietf-interfaces:interfaces-state'
headers = {'Content-Type': 'application/yang-data+json', 'Accept': \
'application/yang-data+json'}
try:
result = requests.get(URI, auth=(USER,PASS), headers=headers)
r_json = result.json()
flagdown=0
for record in r_json["ietf-interfaces:interfaces"]["interface"]:
if(print("0<:5>",format(record["name"]," record["name"],"
if(print("0<:5>",format(record["name"],"
if record["ietf-interfaces:interfaces"]["interface"]:
print("0<:5> ", format(record["name"]," "), end="")
if record["ietf-ip:ipv4"]["address"]:
print("0<:15>", format(record["ietf-ip:ipv4"]["address"][0]["ip"], end=""))
else:
print("0<:15>",format("no IPv4"), end="")
print("0<:9>",format(record["ietf-interfaces:interfaces"]["interface"][0]["admin-status"]," "), end="")
print("0<:9>",format(record["ietf-interfaces:interfaces"]["interface"][0]["oper-status"]," "), end="")
print("0<:9>",format(record["ietf-interfaces:interfaces"]["interface"][0]["enabled"]," "), end="")
flagdown=1
if(flagdown):
print("At least one interface is down")
else:
print("All interfaces are up")
except:
print("Exception: " + str(sys.exc_info()[0]) + "\n" + str(sys.exc_info()[1]))
print("Error: " + str(result.status_code), result.text)
Exhibit
Options
- Ainterface operational status in IPv6 addresses
- Binterface administrative status in IPv4 addresses
- Cinterface operational status in IPv4 addresses
- Dinterface administrative status in IPv6 addresses
How the community answered
(46 responses)- A2% (1)
- B80% (37)
- C4% (2)
- D13% (6)
Why each option
The Python script queries the RESTCONF interfaces endpoint and prints interface admin status alongside IPv4 addresses parsed from the YANG ietf-interfaces model.
The script parses ietf-ip:ipv4 address fields, not IPv6 address fields, so the output contains IPv4 data, not IPv6.
The script accesses the ietf-interfaces YANG model data via RESTCONF and iterates over interface records, printing the admin-status field and the associated ietf-ip:ipv4 address entries, producing output that shows administrative status paired with IPv4 addresses.
The script retrieves admin-status (administrative/configured state) from the ietf-interfaces model, not oper-status (operational/runtime state).
The script outputs IPv4 addresses from the ietf-ip:ipv4 container, not IPv6 addresses.
Concept tested: RESTCONF YANG ietf-interfaces admin-status and IPv4 parsing
Source: https://developer.cisco.com/docs/ios-xe/restconf/
Topics
Community Discussion
No community discussion yet for this question.
