[DAY#2 PyATS Series] Setting up Python Virtual Environments for pyATS (Ping Tests) using pyATS (Vendor-Agnostic) – Cisco, Arista, Palo Alto, Fortigate [Python for Network Engineer]

[DAY#2 PyATS Series] Setting up Python Virtual Environments for pyATS (Ping Tests) using pyATS (Vendor-Agnostic) – Cisco, Arista, Palo Alto, Fortigate [Python for Network Engineer]

Introduction on the Key Points

Welcome back to Day #2 of our 101 Days of pyATS (Vendor-Agnostic) journey. If you’re reading this, you’re serious about transforming how you validate, automate, and troubleshoot networks across Cisco, Arista, Palo Alto, and FortiGate platforms. As a Python for Network Engineer advocate, I want to set a strong foundation—starting with Python Virtual Environments.

Why is this so critical? Because reproducibility, isolation, and modular code development are the backbone of any successful network automation framework. When you’re testing multi-vendor networks, you need a clean, consistent, and replicable Python environment to run tools like pyATS, Genie, and your custom libraries.

In this post, I’ll walk you through:

  • Why Python virtual environments matter
  • How to set up and use them effectively
  • How to structure your pyATS projects with them
  • How to run ping tests post-environment setup across Cisco/Arista/Palo Alto/Fortigate devices

Let’s engineer this the right way from the beginning


Topology Overview

For this lab, we’ll simulate a simple topology:

Each device has reachable management interfaces (via SSH/API), and the goal is to validate ping reachability after setting up our pyATS virtual environment.


Why Vendor-Agnostic Testing Matters

In the real world, networks aren’t single-vendor anymore. Most enterprise and service provider environments are a cocktail of platforms—Cisco at the core, Arista in the DC, Palo Alto at the edge, and FortiGate for segmentation or branch security.

Vendor-specific tooling creates silos.

But pyATS + Python break those barriers by enabling:

  • Unified testing logic across vendors
  • Centralized validation pipelines
  • Easier CI/CD integrations
  • Reduced manual troubleshooting effort

A well-set virtual environment ensures these scripts are portable across systems without the infamous “dependency hell.”


Topology & Communications

We’ll assume the following basic connectivity:

  • Cisco Router → SSH reachable at 10.1.1.1
  • Arista Switch → SSH reachable at 10.1.1.2
  • Palo Alto → API/SSH at 10.1.1.3
  • Fortigate → API/SSH at 10.1.1.4

You’ll be validating ping reachability from a Linux host (Ubuntu) with internet access for package installs.


Workflow Script (Virtual Environment + pyATS + Ping Test)

# Step 1: Install Python3 and venv
sudo apt update
sudo apt install python3 python3-venv -y

# Step 2: Create a project directory
mkdir pyats-vendor-lab && cd pyats-vendor-lab

# Step 3: Create a virtual environment
python3 -m venv venv

# Step 4: Activate the virtual environment
source venv/bin/activate

# Step 5: Install pyATS and Genie
pip install pyats genie

# Step 6: Create testbed and ping script
touch testbed.yml vendor_ping_test.py

Explanation by Line

CommandExplanation
sudo apt updateUpdates package list for latest versions
sudo apt install python3 python3-venvInstalls Python3 and the venv module
mkdir pyats-vendor-lab && cd pyats-vendor-labCreates workspace folder
python3 -m venv venvCreates isolated Python environment
source venv/bin/activateActivates environment so pip installs locally
pip install pyats genieInstalls pyATS and Genie parsing libraries
touch testbed.yml vendor_ping_test.pyPrepares your files for CLI and Python automation

Once done, you’ll run vendor_ping_test.py to validate ping from each vendor device.


testbed.yml Example

devices:
  cisco1:
    os: iosxe
    type: router
    connections:
      cli:
        protocol: ssh
        ip: 10.1.1.1

  arista1:
    os: eos
    type: switch
    connections:
      cli:
        protocol: ssh
        ip: 10.1.1.2

  palo1:
    os: panos
    type: firewall
    connections:
      cli:
        protocol: ssh
        ip: 10.1.1.3

  forti1:
    os: fortinet
    type: firewall
    connections:
      cli:
        protocol: ssh
        ip: 10.1.1.4

Multi‑Vendor CLI Screenshots

Cisco IOS XE

Screenshot 1 – show version

Cisco IOS XE Software, Version 17.03.04
Cisco IOS Software [Amsterdam], ISR Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 17.3.4
...
ROM: IOS-XE ROMMON
System image file is "bootflash:isr4300-universalk9.17.03.04.SPA.bin"

Screenshot 2 – show ip interface brief

Interface              IP-Address      OK? Method Status                Protocol
GigabitEthernet0/0     192.168.1.1     YES NVRAM  up                    up
Loopback0              10.1.1.1        YES manual up                    up

Arista EOS

Screenshot 3 – show version

Arista DCS-7050S-64
Hardware version:    01.00
Serial number:       JPE12345678
Software image version: 4.27.3M
Architecture:           i686

Screenshot 4 – show ip interface brief

Interface              IP Address      Status     Protocol
Ethernet1              10.0.0.1        up         up
Loopback0              10.1.1.2        up         up

Palo Alto (PAN-OS CLI)

Screenshot 5 – show system info

hostname: PA-VM
model: PA-VM
serial: 007000012345
sw-version: 10.2.3

Screenshot 6 – show interface management

Name: Management Interface
IP Address: 192.168.1.10/24
MAC Address: 00:1b:17:aa:bb:cc
Link status: up

FortiGate (FortiOS CLI)

Screenshot 7 – get system status

Version: FortiGate-VM64 v7.2.1,build1234,220901 (GA)
Serial-Number: FGVM02TM21000123
Hostname: FG-VM

Screenshot 8 – get system interface

name                IP address        status
wan1                192.168.0.1/24    up
lan                 10.0.0.1/24       up

Tips for Screenshots:

  • Run these commands directly on each platform in your EVE-NG or lab environment.
  • Ensure IPs and hostnames are consistent with your testbed.yml for traceability.
  • You can anonymize serials or MAC addresses before publishing.
  • Save the screenshots as JPEG or PNG and embed with captions like:
    Figure 1: Cisco IOS XE - show ip interface brief

FAQs

1. Why should I use a virtual environment for pyATS?

Virtual environments isolate dependencies, prevent version conflicts, and ensure your automation scripts work consistently across machines.

2. Can I use the same virtual environment across multiple labs?

Yes, but it’s better practice to create separate virtual environments per project to avoid dependency contamination.

3. Is pyATS supported for Palo Alto and Fortigate?

While Genie doesn’t have native parsers for PAN/FG, you can still run CLI/API commands and use regex or custom parsers to extract info.

4. What if my system doesn’t have python3-venv installed?

Use: sudo apt install python3-venv. On CentOS/RHEL, the package is python3-venv as well, available via EPEL.

5. How do I deactivate the virtual environment?

Just run deactivate in the terminal, and your shell will return to normal.

6. Can I use the same testbed.yml across scripts?

Yes, the testbed is portable. Use loader.load('testbed.yml') in multiple scripts.

7. How do I validate ping from within Python?

Use device.execute('ping x.x.x.x') and parse the response or look for patterns using regex.

8. What version of pyATS is recommended?

Always go for the latest stable release unless your use case requires legacy support.


YouTube Link

Watch the Complete Python for Network Engineer: Setting up Python Virtual Environments for pyATS (Ping Tests) using pyATS (Vendor-Agnostic) – Cisco, Arista, Palo Alto, Fortigate Lab Demo & Explanation on our channel:

Master Python Network Automation, Ansible, REST API & Cisco DevNet
Master Python Network Automation, Ansible, REST API & Cisco DevNet
Master Python Network Automation, Ansible, REST API & Cisco DevNet
Why Robot Framework for Network Automation?

Join Our Training

If you’re enjoying this hands-on series and want to fast-track your journey into network automation, I invite you to join our 3-month instructor-led training:

Course: Python, Ansible, API & Cisco DevNet for Network Engineers
Check Full Curriculum Here

Led personally by Trainer Sagar Dhawan, this course is designed to:

  • Turn you into a confident Python for Network Engineer
  • Teach real-world use of pyATS, Ansible, REST APIs
  • Build real labs across Cisco, Arista, Palo Alto, Fortigate

Enroll Now & Future‑Proof Your Career
Emailinfo@networkjourney.com
WhatsApp / Call: +91 97395 21088

Seats fill fast — start your automation journey today.