Skip to content

🚀A Python-based framework showcasing expertise in network automation, configuration management, and GitOps for Cisco/Juniper devices.

Notifications You must be signed in to change notification settings

careed23/network-automation-framework

Repository files navigation

🚀 Network Automation Framework

Python Version License: MIT Code style: black Maintenance

A Python-based network automation framework for managing and configuring network devices at scale. Automate backups, deployments, and provisioning across multi-vendor environments.

Cisco IOS Juniper Arista

🆕 New Features!

Check out our latest additions:

See NEW_FEATURES.md for complete setup instructions!

Use Cases

📋 Table of Contents


✨ Features

Feature Description
🔄 Automated Backups Schedule and execute configuration backups with timestamps
📝 Template Engine Jinja2-powered configuration templates for standardized deployments
🔌 Multi-Vendor Support for Cisco, Juniper, Arista, HP, and 50+ vendors via Netmiko
📊 Comprehensive Logging Detailed audit trails for compliance and troubleshooting
⏮️ Rollback Support One-command rollback to previous configurations
🎯 Batch Operations Execute commands across multiple devices simultaneously
🔐 Secure by Design Credential management best practices built-in
🛠️ Easy Configuration Simple YAML-based device inventory

🏗️ Architecture

The framework follows a modular architecture for flexibility and maintainability:

graph TB
    subgraph User["👤 Network Engineer"]
        CLI[Command Line Interface]
    end
    
    subgraph Framework["🐍 Network Automation Framework"]
        subgraph Core["Core Modules"]
            DM[Device Manager<br/>Connection Handler]
        end
        
        subgraph Features["Features"]
            Backup[Config Backup<br/>Module]
            Deploy[Config Deploy<br/>Module]
        end
        
        subgraph Storage["Storage & Templates"]
            Templates[Jinja2 Templates<br/>config/templates/]
            BackupDir[Backup Storage<br/>backups/]
            Logs[Logs<br/>logs/]
        end
    end
    
    subgraph Devices["🌐 Network Infrastructure"]
        R1[Router 1<br/>Cisco IOS]
        R2[Router 2<br/>Cisco IOS]
        SW1[Switch 1<br/>Arista EOS]
        SW2[Switch 2<br/>Juniper]
        FW[Firewall<br/>Palo Alto]
    end
    
    subgraph Config["⚙️ Configuration"]
        YAML[devices.yaml<br/>Device Inventory]
    end
    
    CLI -->|Run Scripts| Backup
    CLI -->|Run Scripts| Deploy
    
    Backup --> DM
    Deploy --> DM
    
    DM -->|SSH/Netmiko| R1
    DM -->|SSH/Netmiko| R2
    DM -->|SSH/Netmiko| SW1
    DM -->|SSH/Netmiko| SW2
    DM -->|SSH/Netmiko| FW
    
    Backup -->|Save configs| BackupDir
    Deploy -->|Load templates| Templates
    DM -->|Write logs| Logs
    
    YAML -.->|Device Info| DM
    Templates -.->|Config Templates| Deploy
    
    style Framework fill:#e1f5ff
    style Devices fill:#fff4e1
    style Config fill:#f0f0f0
    style User fill:#e8f5e9
Loading

Key Components:

  • Device Manager: Handles SSH connections via Netmiko
  • Backup Module: Automated configuration backups with timestamps
  • Deploy Module: Template-based configuration deployment
  • Storage Layer: Organized backup storage and Jinja2 templates

🎬 Demo

# Backup all devices
$ python scripts/config_backup.py

[INFO] Connecting to 192.168.1.1
[INFO] Successfully connected to 192.168.1.1
[INFO] Backup saved: backups/192.168.1.1_20240115_143022.txt
[INFO] ✓ 5 devices backed up successfully

# Deploy configuration template
$ python scripts/config_deploy.py --template interface_config.j2 \
  --vars '{"interface_name": "GigabitEthernet0/1", "vlan": 10}'

[INFO] Configuration deployed to 192.168.1.1
[INFO] ✓ Deployment successful

🚀 Installation

Prerequisites

  • Python 3.7 or higher
  • SSH access to network devices
  • Valid device credentials

Setup

# Clone the repository
git clone https://github.com/yourusername/network-automation-framework.git
cd network-automation-framework

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Create required directories
mkdir -p backups logs config/templates

⚡ Quick Start

  1. Configure your devices in config/devices.yaml:
devices:
  - device_type: cisco_ios
    host: 192.168.1.1
    username: admin
    password: your_password
    port: 22
  1. Run your first backup:
python scripts/config_backup.py
  1. Deploy a configuration:
python scripts/config_deploy.py --host 192.168.1.1 \
  --commands "ntp server 10.0.0.1"

📖 See QUICKSTART.md for detailed instructions.


💻 Usage

Configuration Backup

# Backup all devices
python scripts/config_backup.py

# Custom backup directory
python scripts/config_backup.py --backup-dir /path/to/backups

# Specific devices file
python scripts/config_backup.py --devices config/prod_devices.yaml

Configuration Deployment

# Deploy specific commands
python scripts/config_deploy.py --commands \
  "interface GigabitEthernet0/1" \
  "description Uplink to Core"

# Deploy to specific device
python scripts/config_deploy.py --host 192.168.1.1 \
  --file config/my_config.txt

# Use template with variables
python scripts/config_deploy.py --template interface_config.j2 \
  --vars '{"interface_name": "Gi0/1", "vlan": 100}'

Rollback Configuration

python scripts/config_deploy.py --host 192.168.1.1 \
  --file backups/192.168.1.1_20240115_143022.txt

⚙️ Configuration

Device Inventory (config/devices.yaml)

devices:
  - device_type: cisco_ios
    host: 192.168.1.1
    username: admin
    password: secure_password
    secret: enable_password  # Optional
    port: 22
    
  - device_type: juniper_junos
    host: 192.168.1.10
    username: netadmin
    password: secure_password
    port: 22

Supported Device Types

Click to expand supported platforms
  • Cisco: cisco_ios, cisco_nxos, cisco_xr, cisco_asa
  • Juniper: juniper_junos
  • Arista: arista_eos
  • HP: hp_procurve, hp_comware
  • Dell: dell_force10, dell_os10
  • Palo Alto: paloalto_panos
  • And 40+ more via Netmiko

📚 Examples

Example 1: Bulk Interface Configuration

Create config/templates/bulk_interface.j2:

{% for interface in interfaces %}
interface {{ interface.name }}
 description {{ interface.description }}
 switchport access vlan {{ interface.vlan }}
 no shutdown
{% endfor %}

Deploy:

python scripts/config_deploy.py --template bulk_interface.j2 \
  --vars '{"interfaces": [
    {"name": "Gi0/1", "description": "Workstation", "vlan": 10},
    {"name": "Gi0/2", "description": "Printer", "vlan": 20}
  ]}'

Example 2: Python Integration

from scripts.device_manager import DeviceManager
from scripts.config_backup import ConfigBackup

# Backup a device programmatically
device_config = {
    'device_type': 'cisco_ios',
    'host': '192.168.1.1',
    'username': 'admin',
    'password': 'password'
}

backup_manager = ConfigBackup()
backup_manager.backup_device(device_config)

More examples in examples/example_usage.py


📁 Project Structure

network-automation-framework/
├── 📄 README.md                 # This file
├── 📄 QUICKSTART.md             # Quick start guide
├── 📄 requirements.txt          # Python dependencies
├── 📄 .gitignore               # Git ignore rules
│
├── 📂 config/
│   ├── 📄 devices.yaml         # Device inventory
│   └── 📂 templates/           # Jinja2 templates
│       └── 📄 interface_config.j2
│
├── 📂 scripts/
│   ├── 📄 __init__.py
│   ├── 📄 device_manager.py    # Core device connections
│   ├── 📄 config_backup.py     # Backup functionality
│   └── 📄 config_deploy.py     # Deployment functionality
│
├── 📂 examples/
│   └── 📄 example_usage.py     # Usage examples
│
├── 📂 backups/                 # Configuration backups
└── 📂 logs/                    # Application logs

🔐 Security

Best Practices Implemented

  • ✅ Credentials stored in YAML (excluded from Git)
  • ✅ Comprehensive logging for audit trails
  • ✅ SSH-based authentication
  • ✅ No hardcoded passwords in code
  • ✅ File permission recommendations

Security Recommendations

# Restrict permissions on sensitive files
chmod 600 config/devices.yaml

# Use environment variables for credentials
export DEVICE_PASSWORD='your_password'

# Consider using SSH keys instead of passwords

⚠️ Warning: Never commit config/devices.yaml to version control!


🗺️ Roadmap

  • 🌐 Web-based dashboard for monitoring
  • ✅ Configuration compliance checking
  • ⏰ Scheduled backup jobs (cron integration)
  • 🔄 Git integration for version control
  • 📡 REST API for remote operations
  • 🔍 Configuration diff and change tracking
  • ⚡ Multi-threading for faster operations
  • 📊 Reporting and analytics dashboard

🤝 Contributing

Contributions are welcome! Here's how you can help:

  1. 🍴 Fork the repository
  2. 🌟 Create a feature branch (git checkout -b feature/AmazingFeature)
  3. 💾 Commit your changes (git commit -m 'Add some AmazingFeature')
  4. 📤 Push to the branch (git push origin feature/AmazingFeature)
  5. 🎉 Open a Pull Request

Please read CONTRIBUTING.md for details on our code of conduct.


👤 Author

Your Name


🙏 Acknowledgments

  • Netmiko - Network device connectivity
  • Jinja2 - Configuration templating
  • PyYAML - YAML parsing

📊 Project Stats

GitHub stars GitHub forks GitHub issues GitHub pull requests


Made with ❤️ for Network Engineers

⭐ Star this repo if you find it helpful!

About

🚀A Python-based framework showcasing expertise in network automation, configuration management, and GitOps for Cisco/Juniper devices.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published