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.
This commit is contained in:
parent
fe3d5560ab
commit
5ab6f4de21
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue