EOS

class pyEOS.eos.EOS(hostname, username, password, use_ssl=True)

Represents a device running EOS.

The object will contain the following interesting attributes:

  • running_config - The configuration retrieved from the device using the method load_running_config
  • candidate_config - The configuration we desire for the device. Can be populated using the method load_candidate_config
Parameters:
  • hostname – IP or FQDN of the device you want to connect to
  • username – Username
  • password – Password
  • use_ssl – If set you True we will connect to the eAPI using https, otherwise http will be used
close()

Dummy, method. Today it does not do anything but it would be interesting to use it to fake closing a connection.

compare_config()
Returns:A string showing the difference between the running_config and the candidate_config. The running_config is loaded automatically just before doing the comparison so there is no neeed for you to do it.
get_config(format='json')
Parameters:format – Either ‘json’ or ‘text’
Returns:The running configuration of the device.
load_candidate_config(filename=None, config=None)

Populates the attribute candidate_config with the desired configuration. You can populate it from a file or from a string. If you send both a filename and a string containing the configuration, the file takes precedence.

Parameters:
  • filename – Path to the file containing the desired configuration. By default is None.
  • config – String containing the desired configuration.
load_running_config()

Populates the attribute running_config with the running configuration of the device.

open()

Opens the connection with the device.

replace_config(config=None)

Applies the configuration changes on the device. You can either commit the changes on the candidate_config attribute or you can send the desired configuration as a string. Note that the current configuration of the device is replaced with the new configuration.

Parameters:config – String containing the desired configuration. If set to None the candidate_config will be used
rollback()

If used after a commit, the configuration will be reverted to the previous state.

run_commands(commands, version=1, auto_format=False, format='json', timestamps=True)

This method will run as many commands as you want. The ‘enable’ command will be prepended automatically so you don’t have to worry about that.

Parameters:
  • commands – List of commands you want to run
  • version – Version of the eAPI you want to connect to. By default is 1.
  • auto_format – If set to True API calls not supporting returning JSON messages will be converted automatically to text. By default is False.
  • format – Format you want to get; ‘json’ or ‘text’. By default is json. This will trigger a CommandUnconverted exception if set to ‘json’ and auto_format is set to False. It will return text if set to ‘json’ but auto_format is set to True.
  • timestamps – This will return some useful information like when was the command executed and how long it took.