300-435 Question 76
Single answerYou are automating a network device configuration using Python and the ncclient library. The goal is to retrieve the current hostname of a device using NETCONF. Which of the following Python script snippets correctly accomplish this task?
- A
from ncclient import manager with manager.connect(host='10.10.10.1', port=830, username='admin', password='admin', hostkey_verify=False) as m: filter = '
' result = m.get(filter=filter) print(result.xml) - B
from ncclient import manager with manager.connect(host='10.10.10.1', port=830, username='admin', password='admin', hostkey_verify=False) as m: filter = '
' result = m.get_config(source='running', filter=('subtree', filter)) print(result.xml) - C
from ncclient import manager with manager.connect(host='10.10.10.1', port=830, username='admin', password='admin', hostkey_verify=False) as m: query = '
' result = m.get(filter=query) print(result) - D
from ncclient import manager with manager.connect(host='10.10.10.1', port=830, username='admin', password='admin', hostkey_verify=False) as m: filter = '
' result = m.get_config(source='running', filter=('subtree', filter)) print(result.xml)
Show answer and explanation
Correct answer: A
Explanation
The correct answer uses the ncclient 'get' method with a proper XML filter '
- A. Correct.
This is the correct option. It uses ncclient's 'get' method with a valid XML filter to retrieve the 'hostname' from the device using NETCONF, and the result is printed in XML format.
- B. Incorrect.
This is incorrect because the XML filter '
' is not valid, and the script incorrectly uses 'get_config' instead of 'get' for retrieving the hostname. - C. Incorrect.
This is incorrect because the variable 'query' is passed to the 'get' method, but its XML structure '
' is invalid for fetching the hostname. - D. Incorrect.
This is incorrect because while the XML filter used is valid, the script uses 'get_config' instead of 'get', which is unnecessary for retrieving non-configuration data such as the hostname.