Netmiko Methods for Device Configuration | Exam 300-435-ENAUTO

Netmiko Methods Used to Configure a Device

Question

Which two Netmiko methods are used to configure a device? (Choose two.)

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D. E.

CE.

https://pynet.twb-tech.com/blog/automation/netmiko.html

Netmiko is a Python library used to automate the configuration of network devices, including Cisco devices. The library uses SSH or Telnet to connect to the device and provides a set of methods to execute commands and configuration changes.

The two Netmiko methods that can be used to configure a device are:

  1. send_config_set(): This method is used to send a set of configuration commands to a device. The method takes a list of configuration commands as input and sends them to the device in the order they appear in the list. For example:
python
from netmiko import ConnectHandler device = { 'device_type': 'cisco_ios', 'ip': '192.0.2.1', 'username': 'admin', 'password': 'secret', } config_commands = [ 'interface GigabitEthernet0/1', 'ip address 10.0.0.1 255.255.255.0', 'no shutdown', ] with ConnectHandler(**device) as net_connect: output = net_connect.send_config_set(config_commands) print(output)

This code snippet connects to a Cisco IOS device with the IP address 192.0.2.1 using the provided credentials. The config_commands list contains three configuration commands that are sent to the device using the send_config_set() method. The output of the method is captured in the output variable and printed to the console.

  1. send_config_from_file(): This method is used to send a set of configuration commands from a file to a device. The method takes the filename as input and sends the contents of the file to the device. For example:
python
from netmiko import ConnectHandler device = { 'device_type': 'cisco_ios', 'ip': '192.0.2.1', 'username': 'admin', 'password': 'secret', } filename = 'config.txt' with ConnectHandler(**device) as net_connect: output = net_connect.send_config_from_file(filename) print(output)

This code snippet connects to a Cisco IOS device with the IP address 192.0.2.1 using the provided credentials. The filename variable contains the name of a file that contains a set of configuration commands. The send_config_from_file() method reads the contents of the file and sends them to the device. The output of the method is captured in the output variable and printed to the console.

Note that the other methods listed in the question (send_config(), send_control_from_file(), and send_command()) are also part of the Netmiko library, but they are not used for device configuration. The send_config() method is used to send a single configuration command to a device, while the send_control_from_file() method is used to send special control characters to a device. The send_command() method is used to send a single command to a device and retrieve the output.