200-901 Question 57
Single answerYou are tasked with writing a Python script to retrieve a list of devices connected to a Cisco network using the Cisco DNA Center SDK. According to the SDK documentation, the method devices.get_device_list() from the dnacentersdk library can be used. Which of the following snippets correctly uses the SDK to retrieve the list of devices?
- A
from dnacentersdk import api sdk = api.DNACenterAPI(base_url='https://dnacenter.example.com', username='admin', password='password', verify=False) response = sdk.devices.get_device_list() print(response)
- B
import dnacentersdk sdk = dnacentersdk.DNACenter(base_url='https://dnacenter.example.com', username='admin', password='password') response = sdk.devices.list_devices() print(response)
- C
from dnacentersdk import api sdk = api.DNACenterAPI(base_url='https://dnacenter.example.com', username='admin', password='password', verify=True) devices = sdk.network.get_all_devices() print(devices)
- D
from dnacentersdk import api sdk = api.DNACenterAPI(base_url='https://dnacenter.example.com', username='admin', password='password', verify=False) response = sdk.devices.get_device_list() print(response.json())
Show answer and explanation
Correct answer: A
Explanation
The correct script follows the SDK documentation by importing the dnacentersdk library, initializing the DNACenterAPI object with the correct parameters, and using the method get_device_list() to retrieve the list of devices. The response is then printed directly without unnecessary modifications.
- A. Correct.
This is the correct script. It correctly imports the
dnacentersdklibrary, initializes theDNACenterAPIobject with the required parameters, and calls the appropriateget_device_list()method to retrieve the list of devices. Theprint(response)outputs the response correctly. - B. Incorrect.
This script has an incorrect import and initialization. The class
DNACenteris not a valid class in thednacentersdklibrary, and the methodlist_devices()does not exist. - C. Incorrect.
This script incorrectly calls a non-existent method
get_all_devices()under thenetworkobject of the SDK. Thenetworkobject does not provide functionality for retrieving devices. - D. Incorrect.
This script contains an incorrect usage of the
.json()method on the response object. Theget_device_list()method in thednacentersdklibrary already returns a Python dictionary, so calling.json()is unnecessary and will cause an error.