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

with Scrapli(**device) as conn:
    # Send config command to device
    response = conn.send_config("ip route null0")

Send Configs

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)
Ready to Master Network Automation? Start Your Journey Today!
Our membership provides:
  • Full deep-dive course library (inc. Batfish, pyATS, Netmiko)
  • Code repositories inc. full course code, scripts and examples
  • 24x7 multi-vendor labs (Arista, Cisco, Juniper)
  • Private online community
  • Live monthly tech sessions
  • Access to tech session library

Join Now ➜
Close You've successfully subscribed to Packet Coders.
Close Success! Your account is fully activated, you now have access to all content.
Close Welcome back! You've successfully signed in.
Close Nearly there! To activate your account, please click the link in the email we just sent you.