300-435 exam dumps

300-435 practice question 87 of 322

Automating Cisco Enterprise Solutions. Professional level, Cisco. Free question with the correct answer and a full explanation.

300-435 Question 87

Single answer

You are tasked with configuring a Cisco device using the RESTCONF API and Python's 'requests' library. You need to send a request to update the hostname of the device. Which of the following code snippets correctly sets the hostname to 'NewDevice' using RESTCONF?

  1. A

    import requests url = 'https://192.168.1.1/restconf/data/Cisco-IOS-XE-native:native/hostname' data = {'Cisco-IOS-XE-native:hostname': 'NewDevice'} headers = {'Content-Type': 'application/json'} response = requests.post(url, json=data, headers=headers, auth=('admin', 'password'))

  2. B

    import requests url = 'https://192.168.1.1/restconf/data/Cisco-IOS-XE-native:native/hostname' data = {'Cisco-IOS-XE-native:hostname': 'NewDevice'} headers = {'Content-Type': 'application/yang-data+json'} response = requests.put(url, json=data, headers=headers, auth=('admin', 'password'))

  3. C

    import requests url = 'https://192.168.1.1/restconf/data/Cisco-IOS-XE-native:native/hostname' data = {'hostname': 'NewDevice'} headers = {'Content-Type': 'application/yang-data+xml'} response = requests.put(url, data=data, headers=headers, auth=('admin', 'password'))

  4. D

    import requests url = 'https://192.168.1.1/restconf/data/Cisco-IOS-XE-native:native/hostname' data = {'Cisco-IOS-XE-native:hostname': 'NewDevice'} headers = {'Content-Type': 'application/yang-data+json'} response = requests.patch(url, json=data, headers=headers, auth=('admin', 'password'))

Show answer and explanation

Correct answer: B

Explanation

The correct answer is the second option because it adheres to the RESTCONF standards for updating resources. It uses the PUT method, which is suitable for replacing or creating the resource at the target URI. The payload structure is accurate, and the 'application/yang-data+json' content type is specified, which is required for RESTCONF API operations. Other options either use the wrong HTTP method, incorrect payload structure, or unsupported content types.

  • A. Incorrect.

    This code snippet incorrectly uses the POST method. RESTCONF typically uses PUT for creating or updating a specific resource like hostname.

  • B. Correct.

    This snippet is correct as it uses the PUT method, the appropriate URL, the correct JSON payload structure, and the proper 'application/yang-data+json' content type header.

  • C. Incorrect.

    This code uses an incorrect payload structure ('hostname' key instead of 'Cisco-IOS-XE-native:hostname') and an unsupported content type ('application/yang-data+xml').

  • D. Incorrect.

    This code snippet uses the PATCH method, which is not the most appropriate choice for updating the hostname. PUT is preferred for this operation.

Timed practice exam

Take a 300-435 practice test under exam conditions

75 questions in 120 minutes, drawn from this bank, with a score report and a per-question review when you finish.

Start timed exam