From 654004b386ab4f40b72449412f967a697a4e0986 Mon Sep 17 00:00:00 2001 From: Simon T Reeser Date: Wed, 5 Jul 2023 22:43:18 -0600 Subject: [PATCH 1/2] Add format optional parameter to core drivers to support JUNOS get_config text option. --- napalm/eos/eos.py | 2 +- napalm/ios/ios.py | 2 +- napalm/iosxr/iosxr.py | 2 +- napalm/iosxr_netconf/iosxr_netconf.py | 2 +- napalm/junos/junos.py | 5 +++-- napalm/nxos/nxos.py | 2 +- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/napalm/eos/eos.py b/napalm/eos/eos.py index 52db5463b..a31e91a71 100644 --- a/napalm/eos/eos.py +++ b/napalm/eos/eos.py @@ -2063,7 +2063,7 @@ def get_optics(self): return optics_detail - def get_config(self, retrieve="all", full=False, sanitized=False): + def get_config(self, retrieve="all", full=False, sanitized=False, format="text"): """get_config implementation for EOS.""" get_startup = retrieve == "all" or retrieve == "startup" get_running = retrieve == "all" or retrieve == "running" diff --git a/napalm/ios/ios.py b/napalm/ios/ios.py index df7a78400..b10b22fe3 100644 --- a/napalm/ios/ios.py +++ b/napalm/ios/ios.py @@ -3613,7 +3613,7 @@ def get_network_instances(self, name=""): except AttributeError: raise ValueError("The vrf %s does not exist" % name) - def get_config(self, retrieve="all", full=False, sanitized=False): + def get_config(self, retrieve="all", full=False, sanitized=False, format="text"): """Implementation of get_config for IOS. Returns the startup or/and running configuration as dictionary. diff --git a/napalm/iosxr/iosxr.py b/napalm/iosxr/iosxr.py index 475ad3484..71f5c31ba 100644 --- a/napalm/iosxr/iosxr.py +++ b/napalm/iosxr/iosxr.py @@ -2318,7 +2318,7 @@ def get_users(self): return users - def get_config(self, retrieve="all", full=False, sanitized=False): + def get_config(self, retrieve="all", full=False, sanitized=False, format="text"): config = {"startup": "", "running": "", "candidate": ""} # default values # IOS-XR only supports "all" on "show run" diff --git a/napalm/iosxr_netconf/iosxr_netconf.py b/napalm/iosxr_netconf/iosxr_netconf.py index 6f224e46a..f8b0a7a0e 100644 --- a/napalm/iosxr_netconf/iosxr_netconf.py +++ b/napalm/iosxr_netconf/iosxr_netconf.py @@ -3111,7 +3111,7 @@ def get_users(self): return users - def get_config(self, retrieve="all", full=False, sanitized=False): + def get_config(self, retrieve="all", full=False, sanitized=False, format="text"): """Return device configuration.""" encoding = self.config_encoding diff --git a/napalm/junos/junos.py b/napalm/junos/junos.py index b12d09774..413b39a17 100644 --- a/napalm/junos/junos.py +++ b/napalm/junos/junos.py @@ -2435,10 +2435,11 @@ def get_optics(self): return optics_detail - def get_config(self, retrieve="all", full=False, sanitized=False): + def get_config(self, retrieve="all", full=False, sanitized=False, format="text"): rv = {"startup": "", "running": "", "candidate": ""} - options = {"format": "text", "database": "candidate"} + self.format = format + options = {"format": self.format, "database": "candidate"} sanitize_strings = { r"^(\s+community\s+)\w+(;.*|\s+{.*)$": r"\1\2", r'^(.*)"\$\d\$\S+"(;.*)$': r"\1\2", diff --git a/napalm/nxos/nxos.py b/napalm/nxos/nxos.py index 09170074d..ef293b77a 100644 --- a/napalm/nxos/nxos.py +++ b/napalm/nxos/nxos.py @@ -583,7 +583,7 @@ def _disable_confirmation(self) -> None: self._send_command_list(["terminal dont-ask"]) def get_config( - self, retrieve: str = "all", full: bool = False, sanitized: bool = False + self, retrieve: str = "all", full: bool = False, sanitized: bool = False, format: str = "text" ) -> models.ConfigDict: # NX-OS adds some extra, unneeded lines that should be filtered. filter_strings = [ From c2aabcaba1a60095e5471f9445657317e8884da0 Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 5 Apr 2024 09:39:01 -0600 Subject: [PATCH 2/2] Added base support for get_config --- napalm/base/base.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/napalm/base/base.py b/napalm/base/base.py index b1b56040d..10448debd 100644 --- a/napalm/base/base.py +++ b/napalm/base/base.py @@ -1599,7 +1599,11 @@ def get_optics(self) -> Dict[str, models.OpticsDict]: raise NotImplementedError def get_config( - self, retrieve: str = "all", full: bool = False, sanitized: bool = False + self, + retrieve: str = "all", + full: bool = False, + sanitized: bool = False, + format: str = "text", ) -> models.ConfigDict: """ Return the configuration of a device. @@ -1609,6 +1613,7 @@ def get_config( The rest will be set to "". full(bool): Retrieve all the configuration. For instance, on ios, "sh run all". sanitized(bool): Remove secret data. Default: ``False``. + format(string): The configuration format style to be retrieved. Returns: The object returned is a dictionary with a key for each configuration store: