Skip to content

shahedfardous/jdup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Jdup - Juniper Configuration Duplication Tool

Jdup Banner

Jdup is a command-line tool designed to simplify and automate the process of finding and replacing configuration lines across a fleet of Juniper devices running Junos OS. It leverages multi-threading to perform changes in parallel, ensuring efficiency, and incorporates critical safety features like commit check and automatic rollback to prevent faulty configurations from being activated.

Key Features

  • ⚡ Parallel Execution: Uses a thread pool to apply configurations to multiple devices simultaneously, drastically reducing the time required for large-scale changes.
  • 🛡️ Safe & Reliable: Performs a commit check before every commit. If the check fails, the script automatically rolls back the changes, leaving the device in its original state.
  • 💾 Automated Backups: Before making any changes, the script finds and saves the specific configuration lines that will be modified.
  • 📝 Detailed Logging: Creates comprehensive logs for each run, including a main script log, individual device session logs, and detailed error logs for failed commits.
  • 🔄 Smart Duplicate: Intelligently handles deactivate statements by creating a corresponding set statement for the new configuration while preserving the deactivation.
  • 🎨 User-Friendly Interface: Provides a clean, colored output for easy tracking of successes and failures, with a final summary of the entire operation.

How It Works

  1. Load Devices: Reads device connection details (IP, credentials) from a CSV file.
  2. Connect: Establishes SSH connections to the devices.
  3. Find & Backup: Searches for configuration lines matching the specified string and saves them to a backup file in the logs directory.
  4. Generate New Config: Creates the new configuration by replacing the match string with the duplicate string.
  5. Apply & Verify: Loads the new configuration, runs commit check to validate it.
  6. Commit or Rollback:
    • If validation is successful, it commits the changes.
    • If validation fails, it runs rollback 0 and logs the error.
  7. Report: Displays a summary of which devices were updated successfully and which failed.

Screenshots

Execution Example:

Script Execution

Installation

If using jdup.exe then skip this part

  1. Clone the repository:

    git clone https://github.com/shahedfardous/jdup.git
    cd jdup
  2. Create a virtual environment (recommended):

    python -m venv .dup
    source .dup/bin/activate  # On Windows, use: .dup\Scripts\activate
  3. Install dependencies: A requirements.txt file is included for easy installation.

    pip install -r requirements.txt

Usage

  1. Create a devices.csv file in the same directory with the following columns: hostname, ip, port, username, password.

    devices.csv example:

    hostname,ip,port,username,password
    juniper-srx1,10.0.0.1,22,admin,your_password_123
    juniper-mx1,10.0.0.2,22,admin,your_password_123
  2. Run the script with the string to find, the string to replace it with, and the input file.

    Syntax:

    python jdup.py <"match_string"> <"duplicate_string"> -i <input_file.csv>

    For the executable (jdup.exe): Syntax:

    jdup.exe <"match_string"> <"duplicate_string"> -i <input_file.csv>

    Examples:

    • Duplicate an IP configuration:
      python jdup.py "10.1.1.0/24" "10.2.2.0/24" -i devices.csv
      or
      python jdup.py "10.1.1.0/24" "10.2.2.0/24" -i devices.csv -l custom_logs
    • Duplicate an IP configuration using the executable:
      jdup.exe "10.1.1.0/24" "10.2.2.0/24" -i devices.csv
      or
      jdup.exe "10.1.1.0/24" "10.2.2.0/24" -i devices.csv -l custom_logs

Logging

All operational logs are stored in the logs/ directory (or a custom directory specified with -l).

  • script_log_...log: Main log for the script's execution.
  • <hostname>_session.log: Full session log for each device.
  • <hostname>_error_...log: Detailed error output if a commit check or commit fails.
  • <hostname>_<match_string>_...conf: A backup of the configuration lines before changes were made.
  • <hostname>_<duplicate_string>_...conf: The new configuration lines that were applied.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Juniper Configuration Duplication Tool

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages