Genie Libs Clean

26.3 · active · verified Thu Apr 16

Genie Libs Clean (version 26.3) is a component of the CiscoTestAutomation's Genie framework, providing functionalities for cleaning network devices. It automates tasks such as removing configurations, upgrading/downgrading OS, and reloading devices to prepare them for new test runs or restore them to a known state. It is actively maintained as part of the broader Genie/pyATS ecosystem, with a release cadence tied to the pyATS framework.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate and prepare a `Clean` object with a device and a basic clean YAML process. It shows the correct import and initialization. Note that `clean_obj.go()` is commented out to prevent actual device interaction in a basic runnable example; in a real environment, it would execute the defined clean stages on the device.

import os
import yaml
from pyats.topology import Device
from genie.libs.clean.clean import Clean

# --- This example uses a mock device for demonstration ---
# In a real scenario, `device` would come from a pyATS testbed file
# and `device.connect()` would establish a connection.

device = Device(name="dut1", os="iosxe", connections={'cli': {'protocol': 'ssh'}})
print(f"Created mock device: {device.name}")

# Define a simple clean YAML process. In a real test, this
# would often be loaded from a file or generated dynamically.
clean_yaml_process = """
clean:
    order:
        - stage: clear_logging
        - stage: reload
"""

# Instantiate the Clean object with the device and the clean definition
try:
    clean_obj = Clean(device=device, clean_info=yaml.safe_load(clean_yaml_process))
    print("Clean object instantiated successfully.")

    # Execute the clean process.
    # IMPORTANT: clean_obj.go() would execute actual commands on the device.
    # For this quickstart, we are simulating its call.
    # To run for real, ensure device is connected and testbed setup correctly.
    print("Simulating clean process execution (clean_obj.go() is commented out).")
    # clean_obj.go()

    print("Quickstart demonstration completed.")

except Exception as e:
    print(f"An error occurred during quickstart: {e}")
    print("Ensure all dependencies (pyATS, genie) are installed and versions are compatible.")

view raw JSON →