In this lesson, we will cover:
- The available send configuration methods.
- How to use
on_closeto perform configuration commits.
The available Scrapli commands for sending configuration are extremely similar to the send command. For example:
send_config("config_command_1")– send a single command to the device.
send_configs(["config_command_1", "config_command_2"])– send multiple commands to the device.
send_configs_from_file('config_commands.txt')– read commands from a file and send them to the device.
The key difference between these commands and the
send_command commands is that
send_config accepts multiple commands within a single string. Scrapli will automatically split it into separate lines, so only a single
Response will be returned.
We will now see a short example of each of the
send_config commands. Although they are self-explanatory, it provides a good reference should you need them.
with Scrapli(**device) as conn: # Send config command to device response = conn.send_config("ip route 188.8.131.52/32 null0")
The first is by supplying the commands to Scrapli via a
list(). Like so:
# Multiple Commands / Multiple List Elements with Scrapli(**device) as conn: # Send config commands to device commands = ["interface loopback200", "description # Scrapli Demo"] multiresponse = conn.send_configs(commands)