From 5ab6f4de211f8f8fcf73c140cc7ede4d00176cc5 Mon Sep 17 00:00:00 2001 From: Marcus Hoff Date: Wed, 21 Oct 2020 16:34:52 +0200 Subject: [PATCH] Add get_config method Supports all retrive options, where 'candidate' is the Napalm candidate. Either gets the boot config as 'startup' or output from 'show' in edit mode for 'running' Supports sanitized only for 'running'. Outputs the 'show' in op mode. --- napalm_vyos/vyos.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/napalm_vyos/vyos.py b/napalm_vyos/vyos.py index ddddf06..100ccb9 100644 --- a/napalm_vyos/vyos.py +++ b/napalm_vyos/vyos.py @@ -914,3 +914,42 @@ class VyOSDriver(NetworkDriver): } return ping_result + + def get_config(self, retrieve="all", full=False, sanitized=False): + """ + Return the configuration of a device. + :param retrieve: String to determine which configuration type you want to retrieve, default is all of them. + The rest will be set to "". + :param full: Boolean to retrieve all the configuration. (Not supported) + :param sanitized: Boolean to remove secret data. (Only supported for 'running') + :return: The object returned is a dictionary with a key for each configuration store: + - running(string) - Representation of the native running configuration + - candidate(string) - Representation of the candidate configuration. + - startup(string) - Representation of the native startup configuration. + """ + if retrieve not in ["running", "candidate", "startup", "all"]: + raise Exception("ERROR: Not a valid option to retrieve.\nPlease select from 'running', 'candidate', " + "'startup', or 'all'") + else: + config_dict = { + "running": "", + "startup": "", + "candidate": "" + } + if retrieve in ["running", "all"]: + config_dict['running'] = self._get_running_config(sanitized) + if retrieve in ["startup", "all"]: + config_dict['startup'] = self.device.send_command(f"cat {self._BOOT_FILENAME}") + if retrieve in ["candidate", "all"]: + config_dict['candidate'] = self._new_config + + return config_dict + + def _get_running_config(self, sanitized): + if sanitized: + return self.device.send_command("show configuration") + self.device.config_mode() + config = self.device.send_command("show") + config = config[:config.rfind('\n')] + self.device.exit_config_mode() + return config