Abstract¶
Provides an abstract implementation for building API modules
This module provides a set of classes that are used to build API modules that work with Node objects. Using this module will allow the API modules to be automatically loaded using the Node.api method.
The classes in this module should not be instantiated directly but rather provide parent class for API implementations. All API modules will ultimately derive from BaseEntity which provides some common functions to make building API modules easier.
-
class
pyeapi.api.abstract.
BaseEntity
(node)[source]¶ Bases:
object
Base class for all resources to derive from
This BaseEntity class should not be directly instatiated. It is designed to be implemented by all resource classes to provide common methods.
-
error
¶ Holds the latest CommandError exception instance if raised
Type: CommandError
Parameters: node (Node) – An instance of Node -
command_builder
(string, value=None, default=None, disable=None)[source]¶ Builds a command with keywords
Notes
- Negating a command string by overriding ‘value’ with None or an
- assigned value that evalutates to false has been deprecated. Please use ‘disable’ to negate a command.
Parameters are evaluated in the order ‘default’, ‘disable’, ‘value’
Parameters: - string (str) – The command string
- value (str) – The configuration setting to subsititue into the command string. If value is a boolean and True, just the command string is used
- default (bool) – Specifies the command should use the default keyword argument. Default preempts disable and value.
- disable (bool) – Specifies the command should use the no keyword argument. Disable preempts value.
Returns: A command string that can be used to configure the node
-
config
-
configure
(commands)[source]¶ Sends the commands list to the node in config mode
This method performs configuration the node using the array of commands specified. This method wraps the configuration commands in a try/except block and stores any exceptions in the error property.
Note
If the return from this method is False, use the error property to investigate the exception
Parameters: commands (list) – A list of commands to be sent to the node in config mode Returns: - True if the commands are executed without exception otherwise
- False is returned
-
configure_interface
(name, commands)[source]¶ Configures the specified interface with the commands
Parameters: - name (str) – The interface name to configure
- commands – The commands to configure in the interface
Returns: True if the commands completed successfully
-
error
-
get_block
(parent, config='running_config')[source]¶ Scans the config and returns a block of code
Parameters: - parent (str) – The parent string to search the config for and return the block
- config (str) – A text config string to be searched. Default is to search the running-config of the Node.
Returns: A string object that represents the block from the config. If the parent string is not found, then this method will return None.
-
-
class
pyeapi.api.abstract.
Entity
(node)[source]¶ Bases:
pyeapi.api.abstract.BaseEntity
,collections.abc.Callable
Abstract class for building Entity resources
The Entity class provides an abstract implementation that allows for building an API configuration resource. The Entity class should not be directly instantiated. It is used in instances where a single config entity is appropriate in the configuration.
Examples of Entity candidates include global spanning tree
-
class
pyeapi.api.abstract.
EntityCollection
(node)[source]¶ Bases:
pyeapi.api.abstract.BaseEntity
,collections.abc.Mapping
Abstract class for building EntityCollection resources
The EntityCollection class provides an abstract implementat that allows for building API configuration resources with multiple resources. The EntityCollection class should not be directly instantiated.
Examples of an EntityCollection candidate include VLANs and interfaces