diff --git a/ansible/eos_install_config b/ansible/eos_install_config index cb94939..c62a61f 100644 --- a/ansible/eos_install_config +++ b/ansible/eos_install_config @@ -30,11 +30,10 @@ DOCUMENTATION = ''' module: eos_install_config author: David Barroso version_added: "1.0.0" -short_description: Replaces the configuration taken from a file on a device running EOS. -description: - This library will take the configuration from a file and load it into a device running EOS. The old configuration - will be replaced using the feature 'config replace terminal: force'. The use this module you need to enable access - to the device via the eAPI. +short_description: Takes configuration from a file and loads it onto a device running EOS. +description: This library will take the configuration from a file and load it into a device running EOS. The old + configuration will be replaced by using the feature 'config replace terminal: force'. To use this module you + need to enable access to the device via the eAPI. requirements: - pyEOS @@ -50,19 +49,19 @@ options: description: Password required: true use_ssl: - description: If set to True we will connect via https, if False we will use http instead. Default is True. + description: If set to true we will connect via https, if false we will use http instead. Default is true. required: false config_file: - description: Where to load the configuration from. + description: File to load the configuration from. required: true commit_changes: - description: If set to True the configuration will be actually replaced. If the set to False, we will not - apply the changes, just check the differences. - required: true + description: If set to true the commit will be performed. If set to false, we will not apply the changes, + only check the differences. Default: false. + required: false diff_file: - description: A file where to store the "diff" between the running configuration and the new configuration. If - it's not set the diff between configurations is not saved. - required: False + description: A file where to store the "diff" between the running configuration and the new configuration. + If it's not set the diff between configurations is not saved. Default: none. + required: false ''' EXAMPLES = ''' @@ -77,9 +76,9 @@ EXAMPLES = ''' hostname={{ inventory_hostname }} username=admin password=p4ssw0rd - use_ssl=False + use_ssl=false config_file=~/spotify/network-ansible/compiled/{{ inventory_hostname }}/running.conf - commit_changes={{commit_changes}} + commit_changes={{ commit_changes }} diff_file=logs/{{ inventory_hostname }}.log From the CLI we would trigger the playbook like: @@ -131,7 +130,6 @@ def main(): device.open() device.load_candidate_config(filename=config_file) - #content of the diff = device.compare_config() changed = len(diff) > 0 @@ -151,4 +149,4 @@ def main(): from ansible.module_utils.basic import * -main() \ No newline at end of file +main() diff --git a/pyEOS/eos.py b/pyEOS/eos.py index 35de3bc..a22426c 100644 --- a/pyEOS/eos.py +++ b/pyEOS/eos.py @@ -27,7 +27,8 @@ def __init__(self, hostname, username, password, use_ssl=True): 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 + * **candidate_config** - The configuration we desire for the device. Can be populated using the method + load_candidate_config :param hostname: IP or FQDN of the device you want to connect to :param username: Username @@ -71,9 +72,13 @@ def run_commands(self, commands, version=1, auto_format=False, format='json', ti :param commands: List of commands you want to run :param version: Version of the eAPI you want to connect to. By default is 1. - :param auto_format: If set to True API calls not supporting returning JSON messages will be converted automatically to text. By default is False. - :param 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. - :param timestamps: This will return some useful information like when was the command executed and how long it took. + :param auto_format: If set to True API calls not supporting returning JSON messages will be converted + automatically to text. By default it is False. + :param format: Format you want to get; 'json' or 'text'. By default it 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. + :param timestamps: This will return some useful information like when was the command executed and how long + it took. """ @@ -125,7 +130,8 @@ def run_commands(self, commands, version=1, auto_format=False, format='json', ti def close(self): """ - Dummy, method. Today it does not do anything but it would be interesting to use it to fake closing a connection. + Dummy, method. Today it does not do anything but it would be interesting to use it to fake closing a + connection. """ pass @@ -150,9 +156,10 @@ def load_running_config(self): def load_candidate_config(self, 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. + from a string. If you send both a filename and a string containing the configuration, the file takes + precedence. - :param filename: Path to the file containing the desired configuration. By default is None. + :param filename: Path to the file containing the desired configuration. By default it is None. :param config: String containing the desired configuration. """ @@ -164,8 +171,9 @@ def load_candidate_config(self, filename=None, config=None): def compare_config(self): """ - :return: 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. + :return: A string showing the difference between the running_config and the candidate_config, assuming the + entire running conf will be replaced by the candidate. The running_config is loaded automatically just + before doing the comparison so there is no neeed for you to do it. """ # We get the config in text format because you get better printability by parsing and using an OrderedDict diff --git a/test/unit/TestEOS.py b/test/unit/TestEOS.py index 941a0f5..96e50b9 100644 --- a/test/unit/TestEOS.py +++ b/test/unit/TestEOS.py @@ -90,4 +90,4 @@ def test_loading_modified_config_replace_config_and_rollback(self): def test_get_interface_config(self): self.device.load_running_config() interface = self.device.running_config['interface Ethernet2'] - self.assertGreater(len(interface), 0) \ No newline at end of file + self.assertGreater(len(interface), 0)