Devnet
pyATS
6 Library Conf Module

pyATS Library Conf Module

In network testing scenarios, configuring devices and reverting changes afterward are common tasks. pyATS offers various methods to accomplish this, one of which is using the pyATS (formerly Genie) Conf module. This module abstracts configuration details, enabling users to focus on specifying values rather than individual configuration commands. Essentially, users define "what" needs to be configured, while pyATS handles the "how."

pyATS Versus Genie

pyATS serves as a versatile framework, with Genie libraries extending its capabilities for network automation and validation. While Cisco rebranded Genie as the pyATS Library, both names are still used interchangeably in documentation and commands. Developed alongside each other, pyATS and Genie offer comprehensive network automation solutions.

Usage Scenarios for pyATS Conf Module

The pyATS (Genie) Conf Module proves beneficial in several scenarios:

  • Configuring multiple devices across diverse platforms and operating systems.
  • Creating reusable scripts adaptable to different platforms.
  • Rapid setup and teardown of test environments.
  • Validating configuration execution.

pyATS Topology Package

The pyATS Topology package offers a straightforward approach to pushing configurations to network devices by sending raw configuration strings directly. While this method lacks the abstraction provided by the pyATS (Genie) Conf module, it requires users to ensure correct syntax for each operating system, potentially limiting script reusability.

Example Usage with pyATS Topology Package

from pyats.topology.loader import load
 
testbed = load('testbed_file.yaml')
csr01 = testbed.devices['csr']
csr01.connect()
csr01.configure('''
interface Gi3
ip addr 100.0.0.1 255.255.255.0
shutdown
''')
csr01.execute('show ip int brief')

pyATS Conf Module Objects

The pyATS Library Conf module offers a higher level of abstraction, allowing users to configure network devices without manually constructing configuration strings. By providing attribute values, users generate multi-line configuration strings, applicable to one or more devices simultaneously. Leveraging Python objects and a consistent key-value pair structure, this module ensures script portability across different devices.

Example Usage with pyATS Conf Module

from pyats.topology.loader import load
from genie.conf.base import Interface
 
testbed = load('testbed_file.yaml')
uut = testbed.devices['uut']
 
uut.connect()
nxos_interface = Interface(device=uut, name='Ethernet4/3')
nxos_interface.ipv4 = '200.1.1.2'
nxos_interface.ipv4.netmask = '255.255.255.0'
nxos_interface.switchport_enable = False
nxos_interface.shutdown = False
 
# Preview generated configuration
print(nxos_interface.build_config(apply=False))
 
# Deploy configuration to the device
nxos_interface.build_config()
 
# Revert configuration changes
nxos_interface.build_unconfig()

Additional Notes