Genie Configuration Libraries (genie-libs-conf)
Genie libs Conf is a Python library within the pyATS/Genie framework, designed to configure network device topologies through Python object attributes. It provides a programmatic way to define and apply configurations, often used in network automation and testing. Version 26.3 is current, and releases typically align with the broader pyATS/Genie framework, which has a regular, frequent release cycle.
Common errors
-
AttributeError: 'NoneType' object has no attribute 'build_config'
cause The `Device` object was not properly initialized or added to the `Genie` instance, making its internal state incomplete.fixEnsure your `Device` instance is created with `Device(name='...', os='...')` and added to the `Genie` instance using `gen.add_device(device)`. -
KeyError: 'Cannot set attribute ip_address, it does not exist in the schema.'
cause You are trying to set an attribute on a `genie.libs.conf` object that does not exist in its defined schema or is misspelled. The attribute might be valid in a different context or spelled differently (e.g. `ipv4_address`).fixCheck the `genie.libs.conf` documentation or the source code for the specific object (e.g., `Interface`) to verify the correct attribute name and its expected type. -
ModuleNotFoundError: No module named 'genie.conf'
cause The `genie.conf` package (which provides the top-level `Genie` object) is not installed. `genie-libs-conf` itself doesn't include it.fixInstall the core `genie` package using `pip install genie` (or `pip install pyats[full]` for the entire framework).
Warnings
- breaking API Changes in PyATS/Genie Major Versions: Older `pyATS`/`Genie` versions (e.g., pre-20.x) might use different API patterns for configuration objects or methods (e.g., `config_builder` instead of `build_config` directly on device objects). Migration is needed.
- gotcha Incorrect Hierarchical Assignment: Attempting to assign configuration objects (e.g., an `Interface` object) directly to a `Device` object's attribute without using proper constructors or `add_feature` can lead to unexpected behavior or no configuration generation.
- gotcha Schema Attribute Naming Mismatches: Incorrect attribute names (e.g., `ip_address` vs `ipv4_address`) or data types when setting configuration values on `genie.libs.conf` objects can silently fail to generate the desired configuration or raise schema validation errors during `build_config`.
Install
-
pip install genie-libs-conf -
pip install genie
Imports
- Device
from genie.libs.conf.base import Device
- Interface
from genie.libs.conf.interface import Interface
- Genie
from genie.libs.conf import Genie
from genie.conf import Genie
Quickstart
from genie.conf import Genie
from genie.libs.conf.base import Device
from genie.libs.conf.interface import Interface
# Create a new Genie configuration object
gen = Genie()
# Create a device and add it to Genie
device = Device(name='my_router', os='iosxe')
gen.add_device(device)
# Configure an interface on the device
intf = Interface(name='GigabitEthernet1', device=device)
intf.description = 'Management Interface'
intf.ip_address = '192.168.1.1/24'
intf.shutdown = False
# Build and print the configuration string
config_string = device.build_config()
print(f"Generated Configuration for {device.name}:\n{config_string}")
# Expected output might look like:
# interface GigabitEthernet1
# description Management Interface
# ip address 192.168.1.1 255.255.255.0
# no shutdown