Cisco Exam 300-435-ENAUTO: Automating and Programming Cisco Enterprise Solutions

Using Python library Requests for Configuring Device with RESTCONF

Question

The automation engineer must replace device configuration using RESTCONF.

How is this configured using the Python library Requests?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

C.

https://www.cisco.com/c/en/us/td/docs/ios-xml/ios/prog/configuration/166/b_166_programmability_cg/restconf_prog_int.html

RESTCONF is a protocol used to manage network devices over HTTP using RESTful APIs. Python Requests is a library that is commonly used to make HTTP requests. To replace the device configuration using RESTCONF, the PUT method should be used.

The PUT method is used to update or replace a resource with a new version. In the context of network devices, this method can be used to replace the configuration of a device with a new one.

Here is an example code using Python Requests to replace the device configuration using RESTCONF with the PUT method:

python
import requests # Define the headers and payload for the PUT request headers = { 'Content-Type': 'application/yang-data+json', 'Accept': 'application/yang-data+json' } payload = { "ietf-interfaces:interface": { "name": "GigabitEthernet1", "description": "New description" } } # Send the PUT request to replace the device configuration response = requests.put('http://example.com/restconf/data/ietf-interfaces:interfaces/interface=GigabitEthernet1', headers=headers, json=payload, auth=('username', 'password')) # Check the response status code if response.status_code == 204: print('Configuration replaced successfully') else: print('Failed to replace configuration')

In this example, the payload contains the new configuration to be applied, and the headers specify the content type and accept type for the request. The URL used in the PUT request is the path to the specific interface to be updated. The auth parameter is used to authenticate the request with the device.

The PUT method is the appropriate choice when replacing a device configuration using RESTCONF because it allows for the full replacement of the resource with a new version. The PATCH method, on the other hand, is used to make partial updates to a resource.