How to use the pyeapi.api.EntityCollection function in pyeapi

To help you get started, we’ve selected a few pyeapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github arista-eosplus / pyeapi / pyeapi / api / acl.py View on Github external
cmds = ['ip access-list standard %s' % name]
        entry = '%s %s/%s' % (action, addr, prefixlen)
        if seqno is not None:
            entry = '%s %s' % (seqno, entry)
        if log:
            entry += ' log'
        cmds.append(entry)
        cmds.append('exit')
        return self.configure(cmds)

    def remove_entry(self, name, seqno):
        cmds = ['ip access-list standard %s' % name, 'no %s' % seqno, 'exit']
        return self.configure(cmds)


class ExtendedAcls(EntityCollection):

    entry_re = re.compile(r'(\d+)'
                          r'(?: ([p|d]\w+))'
                          r'(?: (\w+|\d+))'
                          r'(?: ([a|h]\w+))?'
                          r'(?: ([0-9]+(?:\.[0-9]+){3}))?'
                          r'(?:/([0-9]{1,2}))?'
                          r'(?: ((?:eq|gt|lt|neq|range) [\w-]+))?'
                          r'(?: ([a|h]\w+))?'
                          r'(?: ([0-9]+(?:\.[0-9]+){3}))?'
                          r'(?:/([0-9]{1,2}))?'
                          r'(?: ([0-9]+(?:\.[0-9]+){3}))?'
                          r'(?: ((?:eq|gt|lt|neq|range) [\w-]+))?'
                          r'(?: (.+))?')

    def get(self, name):
github arista-eosplus / pyeapi / pyeapi / api / routemaps.py View on Github external
resources on an EOS node. It provides the following class implementations:

    * Routemaps - Configures routemaps in EOS

Notes:
    The set and match attributes produce a list of strings with The
    corresponding configuration. These strings will omit the preceeding
    set or match words, respectively.
"""

import re

from pyeapi.api import EntityCollection


class Routemaps(EntityCollection):
    """The Routemaps class provides management of the routemaps configuration

    The Routemaps class is derived from Entity and provides an API for working
    with the nodes routemaps configuraiton.
    """

    def get(self, name):
        """Provides a method to retrieve all routemap configuration
        related to the name attribute.

        Args:
            name (string): The name of the routemap.

        Returns:
            None if the specified routemap does not exists. If the routermap
            exists a dictionary will be provided as follows::
github arista-eosplus / pyeapi / pyeapi / api / interfaces.py View on Github external
self._instances[cls] = instance
        return instance

    def marshall(self, name, *args, **kwargs):
        interface = args[0]
        if not isvalidinterface(interface):
            raise ValueError('invalid interface {}'.format(interface))

        instance = self.get_instance(interface)
        if not hasattr(instance, name):
            raise AttributeError("'%s' object has no attribute '%s'" %
                                 (instance, name))
        method = getattr(instance, name)
        return method(*args, **kwargs)

class BaseInterface(EntityCollection):

    def __str__(self):
        return 'Interface'

    def get(self, name):
        """Returns a generic interface as a set of key/value pairs

        This class is should normally serve as a  base class for building more
        specific interface resources.  The attributes of this resource are
        common to all interfaces regardless of type in EOS.

        The generic interface resource returns the following:

            * name (str): The name of the interface
            * type (str): Always returns 'generic'
            * shutdown (bool): True if the interface is shutdown
github arista-eosplus / pyeapi / pyeapi / api / switchports.py View on Github external
#
"""Module for working with logical layer 2 switchports in EOS

This module provides an API for working with logical layer 2 interfaces
(switchports) in EOS.  Switchports are interfaces built on top of
physical Ethernet and bundled Port-Channel interfaces.

"""

import re

from pyeapi.api import EntityCollection
from pyeapi.utils import make_iterable


class Switchports(EntityCollection):
    """The Switchports class provides a configuration resource for swichports

    Logical layer 2 interfaces built on top of physical Ethernet and bundled
    Port-Channel interfaces can be configured and managed with an instance
    of Switchports.   The Switchports class is a resource collection and
    supports get and getall methods.  The Switchports class is derived from
    the BaseResource class

    """

    def get(self, name):
        """Returns a dictionary object that represents a switchport

        The Switchport resource returns the following:

            * name (str): The name of the interface
github arista-eosplus / pyeapi / pyeapi / api / interfaces.py View on Github external
VALID_INTERFACES = frozenset([
    'Ethernet',
    'Management',
    'Loopback',
    'Port-Channel',
    'Vlan',
    'Vxlan',
])

def isvalidinterface(value):
    match = re.match(r'([EPVLM][a-z-C]+)', value)
    return match and match.group() in VALID_INTERFACES


class Interfaces(EntityCollection):

    def __init__(self, node, *args, **kwargs):
        super(Interfaces, self).__init__(node, *args, **kwargs)
        self._instances = dict()

    def get(self, name):
        return self.get_instance(name)[name]

    def getall(self):
        """Returns all interfaces in a dict object.

        Returns:
            A Python dictionary object containing all interface
            configuration indexed by interface name::

                {
github arista-eosplus / pyeapi / pyeapi / api / vrfs.py View on Github external
ipv4_routing (bool): Tells whether IPv4 routing is enabled on the VRF
    ipv6_routing (bool): Tells whether IPv6 unicast routing is enabled on the
        VRF

"""

import re

from pyeapi.api import EntityCollection
from pyeapi.utils import make_iterable

RD_RE = re.compile(r'(?:\srd\s)(?P.*)$', re.M)
DESCRIPTION_RE = re.compile(r'(?:description\s)(?P.*)$', re.M)


class Vrfs(EntityCollection):
    """The Vrfs class provides a configuration resource for VRFs

    The Vrfs class is derived from ResourceBase a standard set of methods
    for working with VRF configurations on an EOS node.

    """

    def get(self, value):
        """Returns the VRF configuration as a resource dict.

        Args:
            value (string): The vrf name to retrieve from the
                running configuration.

        Returns:
            A Python dict object containing the VRF attributes as
github arista-eosplus / pyeapi / pyeapi / api / varp.py View on Github external
mac_address):
                    raise ValueError('mac_address must be formatted like:'
                                     'aa:bb:cc:dd:ee:ff')
            else:
                raise ValueError('mac_address must be a properly formatted '
                                 'address string')
        if default or disable and not mac_address:
            current_mac = self._parse_mac_address()
            if current_mac['mac_address']:
                base_command = base_command + ' ' + current_mac['mac_address']
        commands = self.command_builder(base_command, value=mac_address,
                                        default=default, disable=disable)
        return self.configure(commands)


class VarpInterfaces(EntityCollection):
    """The VarpInterfaces class helps manage interfaces with
    virtual-router configuration.
    """
    def get(self, name):
        interface_re = r'interface\s%s' % name
        config = self.get_block(interface_re)

        if not config:
            return None

        resource = dict(addresses=dict())
        resource.update(self._parse_virtual_addresses(config))
        return resource

    def getall(self):
        resources = dict()
github arista-eosplus / pyeapi / pyeapi / api / staticroute.py View on Github external
#   ip_dest
#   next_hop
#   next_hop_ip
#   distance
#   tag
#   name
ROUTES_RE = re.compile(r'(?<=^ip route)'
                       r' (\d+\.\d+\.\d+\.\d+\/\d+)'
                       r' (\d+\.\d+\.\d+\.\d+|\S+)'
                       r'(?: (\d+\.\d+\.\d+\.\d+))?'
                       r' (\d+)'
                       r'(?: tag (\d+))?'
                       r'(?: name (\S+))?', re.M)


class StaticRoute(EntityCollection):
    """The StaticRoute class provides a configuration instance
    for working with static routes

    """

    def __str__(self):
        return 'StaticRoute'

    def get(self, name):
        """Retrieves the ip route information for the destination
        ip address specified.

        Args:
            name (string): The ip address of the destination in the
                form of A.B.C.D/E
github arista-eosplus / pyeapi / pyeapi / api / vlans.py View on Github external
is considered a valid VLAN

    Args:
        value: The value to check if is a valid VLAN

    Returns:
        True if the supplied value is a valid VLAN otherwise False
    """
    try:
        value = int(value)
        return value in range(1, 4095)
    except ValueError:
        return False


class Vlans(EntityCollection):
    """The Vlans class provides a configuration resource for VLANs

    The Vlans class is derived from ResourceBase a standard set of methods
    for working with VLAN configurations on an EOS node.

    """
    def get(self, value):
        """Returns the VLAN configuration as a resource dict.

        Args:
            value (string): The vlan identifier to retrieve from the
                running configuration.  Valid values are in the range
                of 1 to 4095

        Returns:
            A Python dict object containing the VLAN attributes as
github arista-eosplus / pyeapi / pyeapi / api / stp.py View on Github external
cmds = 'spanning-tree mode %s' % value
        return self.configure(cmds)

class StpInstances(EntityCollection):
    """Provides a configuration resource for spanning-tree instances

    This class provides an API for working with spanning-tree instances from
    the global configuration.  Spanning tree instances work with MST
    configuration
    """

    def getall(self):
        # TODO: (privateip, 20150106) stubbed out, needs implementation
        return dict()

class StpInterfaces(EntityCollection):
    """Provides a configuration resource for spanning-tree interfaces

    This class provides an API for working with spanning-tree interface
    configurations.  It provides access to managing specific interface
    spanning-tree configuration options.  Note that spanning-tree interfaces
    cannot be created or deleted.
    """

    def get(self, name):
        """Returns the specified interfaces STP configuration resource

        The STP interface resource contains the following

            * name (str): The interface name
            * portfast (bool): The spanning-tree portfast admin state
            * bpduguard (bool): The spanning-tree bpduguard admin state