Skip to content

Commit

Permalink
added option to run show run all
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrosop committed Aug 3, 2019
1 parent 55dffe0 commit d875710
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 16 deletions.
3 changes: 2 additions & 1 deletion napalm/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1512,13 +1512,14 @@ def get_optics(self):
"""
raise NotImplementedError

def get_config(self, retrieve="all"):
def get_config(self, retrieve="all", full=False):
"""
Return the configuration of a device.
Args:
retrieve(string): Which configuration type you want to populate, default is all of them.
The rest will be set to "".
full(bool): Retrieve all the configuration. For instance, on ios, "sh run all".
Returns:
The object returned is a dictionary with a key for each configuration store:
Expand Down
19 changes: 14 additions & 5 deletions napalm/eos/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1692,20 +1692,27 @@ def get_optics(self):

return optics_detail

def get_config(self, retrieve="all"):
def get_config(self, retrieve="all", full=False):
"""get_config implementation for EOS."""
get_startup = retrieve == "all" or retrieve == "startup"
get_running = retrieve == "all" or retrieve == "running"
get_candidate = (
retrieve == "all" or retrieve == "candidate"
) and self.config_session

run_full = " all" if full else ""

if retrieve == "all":
commands = ["show startup-config", "show running-config"]
commands = [
"show startup-config{}".format(run_full),
"show running-config{}".format(run_full),
]

if self.config_session:
commands.append(
"show session-config named {}".format(self.config_session)
"show session-config named {} {}".format(
self.config_session, run_full
)
)

output = self.device.run_commands(commands, encoding="text")
Expand All @@ -1721,7 +1728,7 @@ def get_config(self, retrieve="all"):
else "",
}
elif get_startup or get_running:
commands = ["show {}-config".format(retrieve)]
commands = ["show {}-config{}".format(retrieve, run_full)]
output = self.device.run_commands(commands, encoding="text")
return {
"startup": py23_compat.text_type(output[0]["output"])
Expand All @@ -1733,7 +1740,9 @@ def get_config(self, retrieve="all"):
"candidate": "",
}
elif get_candidate:
commands = ["show session-config named {}".format(self.config_session)]
commands = [
"show session-config named {}{}".format(self.config_session, run_full)
]
output = self.device.run_commands(commands, encoding="text")
return {
"startup": "",
Expand Down
7 changes: 4 additions & 3 deletions napalm/ios/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -2958,7 +2958,7 @@ def get_network_instances(self, name=""):
}
return instances if not name else instances[name]

def get_config(self, retrieve="all"):
def get_config(self, retrieve="all", full=False):
"""Implementation of get_config for IOS.
Returns the startup or/and running configuration as dictionary.
Expand All @@ -2968,14 +2968,15 @@ def get_config(self, retrieve="all"):
"""

configs = {"startup": "", "running": "", "candidate": ""}
run_full = " all" if full else ""

if retrieve in ("startup", "all"):
command = "show startup-config"
command = "show startup-config{}".format(run_full)
output = self._send_command(command)
configs["startup"] = output

if retrieve in ("running", "all"):
command = "show running-config"
command = "show running-config{}".format(run_full)
output = self._send_command(command)
configs["running"] = output

Expand Down
11 changes: 8 additions & 3 deletions napalm/iosxr/iosxr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2224,17 +2224,22 @@ def get_users(self):

return users

def get_config(self, retrieve="all"):
def get_config(self, retrieve="all", full=False):

config = {"startup": "", "running": "", "candidate": ""} # default values
run_full = " all" if full else ""

if retrieve.lower() in ["running", "all"]:
config["running"] = py23_compat.text_type(
self.device._execute_config_show("show running-config")
self.device._execute_config_show(
"show running-config{}".format(run_full)
)
)
if retrieve.lower() in ["candidate", "all"]:
config["candidate"] = py23_compat.text_type(
self.device._execute_config_show("show configuration merge")
self.device._execute_config_show(
"show configuration merge{}".format(run_full)
)
)

return config
2 changes: 1 addition & 1 deletion napalm/junos/junos.py
Original file line number Diff line number Diff line change
Expand Up @@ -2231,7 +2231,7 @@ def get_optics(self):

return optics_detail

def get_config(self, retrieve="all"):
def get_config(self, retrieve="all", full=False):
rv = {"startup": "", "running": "", "candidate": ""}

options = {"format": "text", "database": "candidate"}
Expand Down
7 changes: 4 additions & 3 deletions napalm/nxos/nxos.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,16 +524,17 @@ def _create_tmp_file(config):
def _disable_confirmation(self):
self._send_command_list(["terminal dont-ask"])

def get_config(self, retrieve="all"):
def get_config(self, retrieve="all", full=False):
config = {"startup": "", "running": "", "candidate": ""} # default values
run_full = " all" if full else ""

if retrieve.lower() in ("running", "all"):
command = "show running-config"
command = "show running-config{}".format(run_full)
config["running"] = py23_compat.text_type(
self._send_command(command, raw_text=True)
)
if retrieve.lower() in ("startup", "all"):
command = "show startup-config"
command = "show startup-config{}".format(run_full)
config["startup"] = py23_compat.text_type(
self._send_command(command, raw_text=True)
)
Expand Down

0 comments on commit d875710

Please sign in to comment.