Skip to content

Commit

Permalink
Added option to show run all (#1029)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrosop authored and ktbyers committed Aug 4, 2019
1 parent 55dffe0 commit 7202c01
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 11 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
12 changes: 9 additions & 3 deletions napalm/eos/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1692,16 +1692,19 @@ 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

# EOS only supports "all" on "show run"
run_full = " all" if full else ""

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

if self.config_session:
commands.append(
Expand All @@ -1721,7 +1724,10 @@ def get_config(self, retrieve="all"):
else "",
}
elif get_startup or get_running:
commands = ["show {}-config".format(retrieve)]
if retrieve == "running":
commands = ["show {}-config{}".format(retrieve, run_full)]
elif retrieve == "startup":
commands = ["show {}-config".format(retrieve)]
output = self.device.run_commands(commands, encoding="text")
return {
"startup": py23_compat.text_type(output[0]["output"])
Expand Down
6 changes: 4 additions & 2 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,16 @@ def get_config(self, retrieve="all"):
"""

configs = {"startup": "", "running": "", "candidate": ""}
# IOS only supports "all" on "show run"
run_full = " all" if full else ""

if retrieve in ("startup", "all"):
command = "show startup-config"
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
8 changes: 6 additions & 2 deletions napalm/iosxr/iosxr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2224,13 +2224,17 @@ 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
# IOS-XR only supports "all" on "show run"
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(
Expand Down
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
6 changes: 4 additions & 2 deletions napalm/nxos/nxos.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,13 @@ 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
# NX-OS only supports "all" on "show run"
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)
)
Expand Down

0 comments on commit 7202c01

Please sign in to comment.