200-901 · Question #557
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 by using the Cisco SDK. Not all options are…
The correct answer is api_key_id; api_instance; filter; args. The question requires completing a Python script using the Cisco Intersight SDK by dragging and dropping the correct code snippets into the appropriate blanks to properly initialize the API client, create an API handler, and construct a query filter.
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 by using the Cisco SDK. Not all options are used. Answer:
Exhibit
Answer Area
Drag items
Correct arrangement
- api_key_id
- api_instance
- filter
- args
Explanation
The question requires completing a Python script using the Cisco Intersight SDK by dragging and dropping the correct code snippets into the appropriate blanks to properly initialize the API client, create an API handler, and construct a query filter.
Approach. To correctly complete the Python script, each blank must be filled based on the context of the surrounding code and common practices when using the Cisco Intersight SDK:
-
Blank 1 (Line 13):
api_key_id = intersight_api_params['[BLANK 1]']- This line is part of the
IntersightApiClientinitialization, specifically for providing the API key ID. Theintersight_api_paramsdictionary is being accessed to retrieve this value. Given the variable nameapi_key_idon the left side of the assignment, the most logical key to access in theintersight_api_paramsdictionary for this value is'api_key_id'. Therefore, 'api_key_id' is the correct snippet.
- This line is part of the
-
Blank 2 (Line 14):
api_handle = asset_device_registration_api.AssetDeviceRegistrationApi([BLANK 2])- This line instantiates an API handler object (
AssetDeviceRegistrationApi). In the Cisco Intersight SDK (and many other Python SDKs), API handlers require an instantiated API client object (likeIntersightApiClient) to be passed to them during initialization. This client object manages the actual HTTP communication. Theapi_instancevariable, defined just above, holds theIntersightApiClientobject. Therefore, 'api_instance' is the correct snippet.
- This line instantiates an API handler object (
-
Blank 3 (Line 15):
kwargs = dict([BLANK 3]="ConnectionStatus eq 'Connected'")- This line constructs a dictionary
kwargsthat is later passed toapi_handle.asset_device_registrations_get(**kwargs). The value"ConnectionStatus eq 'Connected'"is an OData filter string used to narrow down the results of an API query. In many REST APIs, including Intersight, OData filter strings are passed using a parameter typically named 'filter'. Therefore, 'filter' is the correct snippet.
- This line constructs a dictionary
Common mistakes.
-
common_mistake. Common mistakes arise from misunderstanding the purpose of each blank or the standard usage of the Cisco Intersight SDK. Here's why the other options are incorrect for the specific blanks:
-
'args': This variable is used later in the script as
args.hostnameto access command-line arguments. It is not a dictionary key for API parameters or anApiClientinstance. -
'device': This variable is used within the loop (
for device in api_result.results:) to iterate over individual device objects. It is not a dictionary key for API parameters or anApiClientinstance. -
'api_base_uri': This string is already used as a dictionary key for the
hostparameter duringIntersightApiClientinitialization (host = intersight_api_params['api_base_uri']). It is not the key forapi_key_id, nor is it anApiClientinstance or a filter parameter name.
Concept tested. The core concepts tested include: understanding of Python programming fundamentals (dictionary access, object instantiation), familiarity with the Cisco Intersight Python SDK (API client initialization, API handler creation), common patterns for interacting with REST APIs (passing authentication credentials, constructing query parameters like filters), and interpreting code context to complete a script.
Topics
Community Discussion
No community discussion yet for this question.
