Utils¶
- class pyeapi.utils.CliVariants(*cli)[source]¶
Bases:
object
Provides an interface for cli variants (typically to handle a transition period for a deprecated cli)
- Instance must be initialized either with 2 or more str variants:
CliVariants( 'new cli', 'legacy cli' )
,- or with 2 or more sequences of cli (or a mix of list and str types), e.g.:
CliVariants( ['new cli1', 'new cli2'], 'alt cli3', 'legacy cli4' )
- static expand(cmds)[source]¶
Expands cmds argument into a list of all CLI variants
The method returns a list of all full variant combinations present in the the cmds arguement
- Parameters:
cmds (list) – a list made of str and CliVariants types
- Returns:
expand( ‘x’, CliVariants( ‘a’, ‘b’), ‘y’ ) will return: [ [‘x’, ‘a’, ‘y’], [‘x’, ‘b’, ‘y’] ]
- Return type:
expanded list, e.g.
- pyeapi.utils.collapse_range(arg, value_delimiter=',', range_delimiter='-')[source]¶
Collapses a list of values into a range set
- Parameters:
arg – The list of values to collapse
value_delimiter – The delimiter that separates values
range_delimiter – The delimiter that separates a value range
- Returns:
An array of collapsed string values
- Return type:
list
- pyeapi.utils.debug(text)[source]¶
Log a message to syslog and stderr
- Parameters:
text (str) – The string object to print
- pyeapi.utils.expand_range(arg, value_delimiter=',', range_delimiter='-')[source]¶
Expands a delimited string of ranged integers into a list of strings
- Parameters:
arg – The string range to expand
value_delimiter – The delimiter that separates values
range_delimiter – The delimiter that signifies a range of values
- Returns:
An array of expanded string values
- Return type:
list
- pyeapi.utils.import_module(name)[source]¶
Imports a module into the current runtime environment
This function emulates the Python import system that allows for importing full path modules. It will break down the module and import each part (or skip if it is already loaded in cache).
- Parameters:
name (str) – The name of the module to import. This should be the full path of the module
- Returns:
The module that was imported
- pyeapi.utils.islocalconnection()[source]¶
Checks if running locally on EOS device or remotely
This function will return a boolean indicating if the current execution environment is running locally on an EOS device (True) or running remotely and communicating over HTTP/S (False)
- Returns:
- A boolean value that indicates whether or not the current
thread is local or remote
- pyeapi.utils.load_module(name)[source]¶
Attempts to load a module into the current environment
This function will load a module specified by name. The module name is first checked to see if it is already loaded and will return the module if it is. If the module hasn’t been previously loaded it will attempt to import it
- Parameters:
name (str) – Specifies the full name of the module. For instance pyeapi.api.vlans
- Returns:
The module that has been imported or retrieved from the sys modules