This lesson is part of the Network Configuration with Scrapli Course.
In this lesson, we will cover:
- The available send configuration methods.
- How to use
on_close
to perform configuration commits.
You can find the scripts and code for this lesson within the Scrapli repo under the directory: 002_scrapli_core/005_config/.
Available Methods
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.
Send Config
The full code for this section is located here: scrapli_send_config.py
with Scrapli(**device) as conn:
# Send config command to device
response = conn.send_config("ip route 1.2.3.4/32 null0")
Send Configs
The full code for this section is located here: scrapli_send_configs.py
Below shows you the two different ways that you can use the `send_configs`method.
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)