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.
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.
Node – The node instance this resource will perform operations against for configuration
Config – Returns an instance of Config with the nodes current running configuration
CommandError – Holds the latest CommandError exception instance if raised
Parameters: node (Node) – An instance of Node
command_builder(string, value=None, default=None, disable=None)¶
Builds a command with keywords
- 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’
- 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.
A command string that can be used to configure the node
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.
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
Configures the specified interface with the commands
- name (str) – The interface name to configure
- commands – The commands to configure in the interface
True if the commands completed successfully
Scans the config and returns a block of code
- 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.
A string object that represents the block from the config. If the parent string is not found, then this method will return None.
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
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