Genie

26.3 · active · verified Thu Apr 16

Genie is the standard Python Library System built on top of the pyATS framework, providing a rich set of parsers (Genie Ops) and configuration builders (Genie Conf) for network devices, primarily Cisco platforms. It enables network engineers and developers to automate network operations, testing, and configuration management. The current version is 26.3, and it follows the pyATS release cadence, with major updates typically aligning with major pyATS releases.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up a basic testbed YAML, load it using `pyats.topology.Testbed`, and access a device object. It uses environment variables for credentials to keep the example runnable without exposing sensitive data. Note that methods like `device.connect()` and `device.parse()` require an actual network device connection to function, which is omitted for a fully runnable, non-network-dependent example.

import os
from pyats.topology import Testbed

# Create a dummy testbed YAML file for the example
testbed_content = """
devices:
  router1:
    os: iosxe
    type: router
    connections:
      cli:
        protocol: ssh
        ip: 127.0.0.1
        port: 22
    credentials:
      default:
        username: {}
        password: {}
""".format(os.environ.get('GENIE_DEVICE_USERNAME', 'cisco'),
           os.environ.get('GENIE_DEVICE_PASSWORD', 'cisco'))

testbed_path = "temp_genie_testbed.yaml"
with open(testbed_path, "w") as f:
    f.write(testbed_content)

try:
    # Load the testbed using pyATS
    testbed = Testbed(testbed_path)
    print(f"Successfully loaded testbed from {testbed_path}")

    # Access a device defined in the testbed
    device = testbed.devices['router1']
    print(f"Accessed device: {device.name}")
    print(f"Device OS: {device.os}")
    print(f"Device Type: {device.type}")

    # To perform actual operations (like device.parse() or device.connect()),
    # a live connection to a network device is required.
    # Example (will fail without connection, for demonstration only):
    # try:
    #     device.connect()
    #     output = device.parse('show version')
    #     print(f"Parsed 'show version': {output.keys()}")
    # finally:
    #     if device.is_connected():
    #         device.disconnect()

except Exception as e:
    print(f"An error occurred: {e}")
finally:
    # Clean up the dummy testbed file
    if os.path.exists(testbed_path):
        os.remove(testbed_path)

view raw JSON →