nerdexam
CiscoCisco

200-901 · Question #492

200-901 Question #492: Real Exam Question with Answer & Explanation

The question requires filling in missing Python code segments to retrieve network interface data using RESTCONF, based on a provided solution which contains several technical inaccuracies.

Infrastructure and Automation

Question

Drag and Drop Question Refer to the exhibit. Drag and drop the code from the bottom onto the box where the code is missing to construct a Python script that allows an engineer to retrieve interface data. Not all options are used.Drag and Drop Question Refer to the exhibit. Drag and drop the code from the bottom onto the box where the code is missing to construct a Python script that allows an engineer to retrieve interface data. Not all options are used. Answer:

Explanation

The question requires filling in missing Python code segments to retrieve network interface data using RESTCONF, based on a provided solution which contains several technical inaccuracies.

Approach. Based on the provided solution image (Image 3), the correct interactions are as follows, although some choices are technically incorrect for a functional script:

  1. Line 09 (Headers dictionary key): The solution places Encoding into the first empty box. While Accept is the standard HTTP header for specifying the desired response media type (application/yang-data+json in this case), the provided solution uses Encoding.

  2. Line 15 (URL construction - IP address placeholder): The solution places ipaddress into the empty box within the f-string for the URL. The device dictionary contains the actual IP under the key 'ip'. For an f-string, {{device['ip']}} would correctly embed the IP address. Inserting the literal string ipaddress as shown in the solution would make the URL non-functional (e.g., https://ipaddress:9443/...). However, ipaddress is presented as the chosen option.

  3. Line 22 (JSON parsing - Accessing interfaces): The solution places device['ip'] into the empty box for accessing the JSON response. According to the ietf-interfaces YANG model, the list of interfaces is typically found under the key 'interface' (singular) within the ietf-interfaces:interfaces container (e.g., response['ietf-interfaces:interfaces']['interface']). Using device['ip'] (the device's IP address string) as a key to access the interfaces list is technically incorrect and would likely result in a KeyError at runtime.

  4. Line 24 (For loop iterable): The solution places devices into the empty box for the for loop iterable. The loop is intended to iterate over the interfaces (plural) variable, which should hold the collection of interface objects retrieved from the API. The variable devices is not defined anywhere in the script and is not a valid iterable in this context. The correct choice from the options would be interfaces.

Common mistakes.

  • common_mistake. Several choices in the provided solution are technically incorrect and represent common pitfalls or design flaws in the question itself:
  1. Using Encoding instead of Accept for the header: The standard HTTP header to negotiate the content type that a client expects from a server is Accept. Encoding (or Content-Encoding/Accept-Encoding) relates to data compression, not the data format itself. A common mistake would be confusing these HTTP headers.

  2. Placing ipaddress string literal in the URL f-string instead of device['ip']: The f-string f"https://{{ }}:{{device['port']}}/" expects a Python expression in the {{ }} curly braces to dynamically insert a value. Placing the string literal ipaddress results in a non-functional URL. The correct way to insert the device's IP from the dictionary is device['ip'].

  3. Using device['ip'] as a key for JSON parsing (Line 22): The ietf-interfaces:interfaces YANG model typically structures its response such that the list of individual interfaces is under a key named 'interface' (singular). Using the device's IP address (device['ip']) as a key to extract interface data is fundamentally incorrect and would fail at runtime. The common mistake here is not understanding the standard JSON structure for YANG data models.

  4. Using devices instead of interfaces as the iterable for the loop (Line 24): The for loop is meant to iterate over the collection of interfaces fetched from the API, which should be stored in the interfaces variable (plural) defined in line 22. devices is an undefined variable and would cause a NameError. The common mistake is confusing variable names or not correctly identifying the intended collection for iteration.

Concept tested. The underlying technical concepts being tested include Python dictionary usage, f-string formatting for URL construction, HTTP headers (specifically Accept for RESTCONF API calls), JSON parsing and navigation based on YANG data models (ietf-interfaces), and basic Python loop constructs (for-loop) for data processing. The question also implicitly tests the ability to interact with RESTCONF APIs using the requests library.

Topics

#Python#Network Automation#API Consumption#Operational Data Retrieval

Community Discussion

No community discussion yet for this question.

Full 200-901 PracticeBrowse All 200-901 Questions