pyeapi

repository·develop·Indexed 41 days ago

https://github.com/arista-eosplus/pyeapi

A Python client library for interacting with Arista EOS devices via the eAPI. It supports both on-box and off-box communication, utilizing INI-style configuration files for connection management. The library provides an extensible object-oriented API for command execution and EOS configuration, including support for atomic Config Sessions with commit and abort capabilities.

Tokens
7.8K
Snippets
32
Records
43
Agent score
99%

What's inside pyeapi

  1. Overview of the pyeapi library

    develop

    The pyeapi library is a native Python wrapper for the Arista EOS eAPI. It provides Python language bindings to configure Arista EOS nodes.

    Key capabilities include:

    • Connectivity: Supports both local (on-box) and remote (off-box) communication with EOS.
    • Configuration: Uses standard INI-style configuration files to define nodes and connection profiles.
    • Object Model: Provides an API layer for interacting with EOS using native Python objects, which is extensible for custom implementations.
  2. Introduction to pyeapi

    develop

    The Python Client for eAPI (pyeapi) is a native Python library wrapper for Arista EOS eAPI. It provides Python language bindings for configuring Arista EOS nodes.

    Key capabilities include:

    • Communication Modes: Supports both local (on-box) and remote (off-box) communication with EOS.
    • Configuration: Uses standard INI-style configuration files to manage multiple nodes and connection profiles.
    • API Layer: Provides an extensible API layer for interacting with EOS using native Python objects, making it easier to manage EOS configurations.
  3. Overview of the Arista eAPI Python Library

    develop

    The pyeapi library is a Python client for interacting with Arista EOS nodes via the eAPI command API. It supports both local (on-box) and remote (off-box) communication.

    Key features include:

    • Connection Management: Uses standard INI-style configuration files to define one or more nodes and their connection properties.
    • Object-Oriented API: Provides an API layer for building native Python objects to interact with EOS configuration, which is extensible for custom implementations.
  4. Determine when an eapi.conf file is required

    develop

    Whether you need an eapi.conf file depends on your transport method and whether you are running the script on-box or off-box.

    Transporteapi.conf RequiredScript run fromAuthentication Required
    httpYesOn/Off-switchYes
    httpsYesOn/Off-switchYes
    https_certsYesOn/Off-switchYes (via certs)
    http_localYesOn-switch onlyNo
    socketNoOn-switch onlyNo
  5. Contact support for Pyeapi

    develop

    Pyeapi is developed by Arista EOS+ CS and supported by the Arista EOS+ community on a best-effort basis.

    • General/Community Support: Contact the development team via email at eosplus-dev@arista.com.
    • Premium Support: Customers requiring premium-level support should contact their local Arista account team or email eosplus@arista.com.
  6. Implement on-box connections using Unix Sockets or HTTP Local

    develop

    For running pyeapi scripts directly on the switch (on-box), you can avoid passing credentials if using specific transport methods.

    Using Unix Sockets (Preferred)

    If EOS 4.14.5+ is used and Unix Sockets are enabled, socket is the default transport and localhost is the default host. No eapi.conf or credentials are required.

    Using HTTP Local

    Requires an eapi.conf file located at /mnt/flash/eapi.conf. You must also configure the switch to allow local HTTP traffic.

    eapi.conf example:

    [connection:localhost]
    transport: http_local

    Switch configuration required:

    switch(config)#management http-server
    switch(config-mgmt-http-server)#protocol http localhost
  7. Configure subinterfaces on Ethernet and Port-Channel interfaces

    develop

    To configure subinterfaces using pyeapi, you must first ensure the primary interface is in routed mode. You can achieve this by calling create on the ipinterfaces API. Once the primary interface is configured, you can create subinterfaces by calling create on the interfaces API using the subinterface name (e.g., Ethernet1.1).

    Workflow:

    1. Set the primary interface to routed mode using node.api('ipinterfaces').create('INTERFACE_NAME').
    2. Create the subinterface using node.api('interfaces').create('INTERFACE_NAME.SUBINTERFACE_ID').
    3. Apply VLAN encapsulation to the subinterface.
    import pyeapi
    
    # Connect to the node
    node = pyeapi.connect_to('veos01')
    
    # 1. Set primary interface to routed mode
    node.api('ipinterfaces').create('Ethernet1')
    
    # 2. Create the subinterface
    node.api('interfaces').create('Ethernet1.1')
    
    # 3. Apply VLAN encapsulation
    node.api('interfaces').set_encapsulation('Ethernet1.1', 4)
  8. Connect to an Arista EOS node with pyeapi

    develop

    To use pyeapi, you must first enable the EOS Command API on your Arista device (supporting HTTP, HTTPS, HTTP Local, or Unix Sockets). Once enabled, you can connect to a node by instantiating a Node object using pyeapi.connect_to(node_name). The node_name must correspond to an entry in your eapi.conf configuration file. If you are running the script on-box with Unix Sockets enabled, you can skip the eapi.conf file creation.

    import pyeapi
    
    # Connect to a node defined in your config file
    node = pyeapi.connect_to('veos01')
  9. Implement off-box connections using HTTP or HTTPS

    develop

    When running scripts from a remote server, you must use an eapi.conf file located in $HOME/.eapi.conf. Authentication via username and password is required.

    Note: Do not use the name localhost in your connection description (e.g., [connection:localhost]) for off-box connections; localhost is reserved for on-box methods.

    Example configuration:

    [connection:veos01]
    transport: http
    username: paul
    password: nottelling
    
    [connection:veos03]
    transport: https
    username: bob
    password: mysecret
    
    [connection:veos04]
    host: 192.168.2.10
    transport: https
    username: admin
    password: admin
  10. Use Config Sessions to apply configuration blocks

    develop

    Config Sessions allow you to group multiple configuration commands into a single operation. This provides atomicity: if an error occurs during the application of the block, you can abort the entire session to prevent partial or invalid configurations from being applied to the device.

    To use Config Sessions with pyeapi:

    1. Initialize a connection using pyeapi.connect_to().
    2. Start a session with node.configure_session().
    3. Apply configurations using the .configure() method on your API objects.
    4. Either node.commit() to apply the changes or node.abort() to discard them.
    import pyeapi
    node = pyeapi.connect_to('veos01')
    
    # Start the session
    node.configure_session()
    
    # Apply configuration via an API object
    vlans = node.api('vlans')
    success = vlans.configure(['vlan 100', 'vlan 200'])
    
    if success:
        node.commit()
    else:
        node.abort()
  11. Submit issues and enhancement requests

    develop

    Bugs and enhancement requests are tracked via GitHub Issues at https://github.com/arista-eosplus/pyeapi/issues.

    For Defect Issues (Bugs)

    To help the development team resolve defects, provide as much relevant data as possible, including:

    • Steps to reproduce the issue.
    • The version of EOS being used.
    • The Python version.
    • Operating System (OS) details.

    For Enhancement Requests

    When requesting new features, provide:

    • A brief description of the requested enhancement.
    • The version of EOS that needs to be supported.