Skip to content
LinkState
Go back

Why Python and Netmiko Beat Heavy Orchestrators

Introduction to Deterministic Routing Rollback

Ephemeral lab topologies are temporary network environments used for testing, validation, and development. These environments are characterized by their dynamic nature, where network configurations and topologies change frequently.

Characteristics of Ephemeral Environments

Dynamic Network Configuration

Network configurations are constantly changing in ephemeral lab topologies, requiring a high degree of flexibility and adaptability in the tools used to manage these environments.

Frequent Topology Changes

Frequent topology changes are common in ephemeral lab topologies, including changes to network devices, links, and routing configurations.

Advantages of Raw Python and Netmiko

Flexibility and Customization

Raw Python and Netmiko offer a high degree of flexibility and customization, making them ideal for managing ephemeral lab topologies.

Python Code Snippets for Custom Routing Scripts

import netmiko

def configure_routing(device, route):
    conn = netmiko.ConnectHandler(**device)
    config_commands = [f"ip route {route['destination']} {route['mask']} {route['next_hop']}"]
    conn.send_config_set(config_commands)
    conn.disconnect()

device = {
    'device_type': 'cisco_ios',
    'ip': '10.0.0.1',
    'username': 'admin',
    'password': 'password'
}
route = {
    'destination': '10.0.0.0',
    'mask': '255.255.255.0',
    'next_hop': '10.0.0.2'
}
configure_routing(device, route)

Netmiko Integration for Device Interaction

Netmiko provides a simple and intuitive API for interacting with network devices, making it easy to automate tasks such as configuring routing, verifying connectivity, and troubleshooting issues.

Example: show ip route Output

Route Table:
10.0.0.0/24 is subnetted, 1 subnets
C       10.0.0.0 is directly connected, GigabitEthernet0/0

Ease of Use and Learning Curve

Raw Python and Netmiko have a relatively low barrier to entry, making them accessible to network engineers and developers who are new to automation.

Simple and Intuitive API

Netmiko’s API is simple and easy to use, with a focus on readability and usability.

Mermaid Topology Diagram: Simple Network Topology

graph LR;
    A[Router 1] -->|10.0.0.1/30|> B[Router 2];
    B -->|10.0.0.5/30|> C[Router 3];

Performance and Scalability

Raw Python and Netmiko are highly performant and scalable, making them suitable for large-scale ephemeral lab topologies.

Fast Execution and Low Overhead

Raw Python and Netmiko have a low overhead compared to other automation tools, making them ideal for environments where speed and efficiency are critical.

Handling Large-Scale Topologies

Raw Python and Netmiko can handle large-scale topologies with ease, making them suitable for complex network environments.

Limitations of Overbuilt Orchestrators

Complexity and Steep Learning Curve

Overbuilt orchestrators such as Ansible have a steep learning curve and are often overly complex, making them difficult to use and master.

Ansible vs Netmiko: Complexity Comparison

Ansible has a much steeper learning curve than Netmiko, with a more complex architecture and a larger number of dependencies.

Example: Ansible Playbook for Routing Configuration

---
- name: Configure routing
  hosts: routers
  become: yes
  tasks:
  - name: Configure route
    ios_config:
      lines:
      - ip route 10.0.0.0 255.255.255.0 10.0.0.2
      before: no ip route 10.0.0.0 255.255.255.0 10.0.0.2

Resource Intensity and Overhead

Overbuilt orchestrators such as Ansible are often resource-intensive and have a high overhead, making them unsuitable for environments where resources are limited.

High Memory and CPU Usage

Ansible requires a significant amount of memory and CPU resources, making it unsuitable for environments where resources are limited.

Top Output: Resource Usage Comparison

PID  USER     PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
1234 user     20   0  123M  45M  12M S  10  2.3   0:01.23 ansible
2345 user     20   0  234M  90M  23M S  20  4.5   0:02.45 netmiko

Inflexibility and Vendor Lock-in

Overbuilt orchestrators such as Ansible often have limited customization options and can lead to vendor lock-in, making it difficult to switch to alternative tools or vendors.

Limited Customization Options

Ansible has limited customization options, making it difficult to tailor the tool to specific use cases or environments.

Mermaid Topology Diagram: Complex Network Topology

graph LR;
    A[Router 1] -->|10.0.0.1/30|> B[Router 2];
    B -->|10.0.0.5/30|> C[Router 3];
    C -->|10.0.0.9/30|> D[Router 4];
    D -->|10.0.0.13/30|> E[Router 5];

Real-World Applications and Use Cases

Ephemeral Lab Topologies for Testing and Validation

Raw Python and Netmiko can be used to automate testing and validation in ephemeral lab topologies.

Python Script for Automated Routing Tests

import netmiko

def test_routing(device, route):
    conn = netmiko.ConnectHandler(**device)
    output = conn.send_command(f"show ip route {route['destination']}")
    conn.disconnect()
    return output

device = {
    'device_type': 'cisco_ios',
    'ip': '10.0.0.1',
    'username': 'admin',
    'password': 'password'
}
route = {
    'destination': '10.0.0.0',
    'mask': '255.255.255.0',
    'next_hop': '10.0.0.2'
}
output = test_routing(device, route)
print(output)

Example: Netmiko Output for Routing Verification

Route Table:
10.0.0.0/24 is subnetted, 1 subnets
C       10.0.0.0 is directly connected, GigabitEthernet0/0

Deterministic Routing Rollback for Production Environments

Raw Python and Netmiko can be used to implement deterministic routing rollback in production environments.

Mermaid Topology Diagram: Production Network Topology

graph LR;
    A[Router 1] -->|10.0.0.1/30|> B[Router 2];
    B -->|10.0.0.5/30|> C[Router 3];
    C -->|10.0.0.9/30|> D[Router 4];

Share this post on:

Previous Post
An AI Test Harness for Broken OSPF Adjacencies
Next Post
OSPF ExStart Loops from MTU Drift