Which two Netmiko methods are used to configure a device? (Choose two.)
Click on the arrows to vote for the correct answer
A. B. C. D. E.CE.
https://pynet.twb-tech.com/blog/automation/netmiko.htmlNetmiko 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:
pythonfrom 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.
pythonfrom 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.