Skip to content

Commit

Permalink
Merge branch 'develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mirceaulinic authored Sep 25, 2019
2 parents 116715f + 5bed485 commit 0a53013
Show file tree
Hide file tree
Showing 31 changed files with 19,806 additions and 65 deletions.
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ to see how to properly format your request.
### Did you follow the steps from https://github.com/napalm-automation/napalm#faq
(Place an ``x`` between the square brackets where applicable)

- [ ] Yes
- [ ] No
- [] Yes
- [] No


### Setup
Expand Down
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
48 changes: 39 additions & 9 deletions napalm/eos/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,26 @@ class EOSDriver(NetworkDriver):
)

def __init__(self, hostname, username, password, timeout=60, optional_args=None):
"""Constructor."""
"""
Initialize EOS Driver.
Optional args:
* lock_disable (True/False): force configuration lock to be disabled (for external lock
management).
* enable_password (True/False): Enable password for privilege elevation
* eos_autoComplete (True/False): Allow for shortening of cli commands
* transport (string): pyeapi transport, defaults to eos_transport if set
- socket
- http_local
- http
- https
- https_certs
(from: https://github.com/arista-eosplus/pyeapi/blob/develop/pyeapi/client.py#L115)
transport is the preferred method
* eos_transport (string): pyeapi transport, defaults to https
eos_transport for backwards compatibility
"""
self.device = None
self.hostname = hostname
self.username = username
Expand All @@ -101,6 +120,9 @@ def __init__(self, hostname, username, password, timeout=60, optional_args=None)
self._process_optional_args(optional_args or {})

def _process_optional_args(self, optional_args):
# Define locking method
self.lock_disable = optional_args.get("lock_disable", False)

self.enablepwd = optional_args.pop("enable_password", "")
self.eos_autoComplete = optional_args.pop("eos_autoComplete", None)
# eos_transport is there for backwards compatibility, transport is the preferred method
Expand All @@ -115,7 +137,7 @@ def _process_optional_args(self, optional_args):
init_args.pop(0) # Remove "self"
init_args.append("enforce_verification") # Not an arg for unknown reason

filter_args = ["host", "username", "password", "timeout"]
filter_args = ["host", "username", "password", "timeout", "lock_disable"]

self.eapi_kwargs = {
k: v
Expand Down Expand Up @@ -154,8 +176,6 @@ def is_alive(self):
return {"is_alive": True} # always true as eAPI is HTTP-based

def _lock(self):
if self.config_session is None:
self.config_session = "napalm_{}".format(datetime.now().microsecond)
sess = self.device.run_commands(["show configuration sessions"])[0]["sessions"]
if [
k
Expand Down Expand Up @@ -227,9 +247,10 @@ def _mode_comment_convert(commands):
return ret

def _load_config(self, filename=None, config=None, replace=True):
commands = []
if self.config_session is None:
self.config_session = "napalm_{}".format(datetime.now().microsecond)

self._lock()
commands = []
commands.append("configure session {}".format(self.config_session))
if replace:
commands.append("rollback clean-config")
Expand Down Expand Up @@ -293,6 +314,9 @@ def compare_config(self):

def commit_config(self, message=""):
"""Implementation of NAPALM method commit_config."""

if not self.lock_disable:
self._lock()
if message:
raise NotImplementedError(
"Commit message not implemented for this platform"
Expand Down Expand Up @@ -1692,16 +1716,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 +1748,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
27 changes: 16 additions & 11 deletions napalm/junos/junos.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ def __init__(self, hostname, username, password, timeout=60, optional_args=None)
self.lock_disable = optional_args.get("lock_disable", False)
self.session_config_lock = optional_args.get("config_lock", False)

# Junos driver specific options
self.junos_config_database = optional_args.get(
"junos_config_database", "committed"
)

if self.key_file:
self.device = Device(
hostname,
Expand Down Expand Up @@ -1089,10 +1094,10 @@ def build_prefix_limit(**args):

if group:
bgp = junos_views.junos_bgp_config_group_table(self.device)
bgp.get(group=group)
bgp.get(group=group, options={"database": self.junos_config_database})
else:
bgp = junos_views.junos_bgp_config_table(self.device)
bgp.get()
bgp.get(options={"database": self.junos_config_database})
neighbor = "" # if no group is set, no neighbor should be set either
bgp_items = bgp.items()

Expand All @@ -1105,7 +1110,7 @@ def build_prefix_limit(**args):
# The resulting dict (nhs_policies) will be used by _check_nhs to determine if "nhs"
# is configured or not in the policies applied to a BGP neighbor
policy = junos_views.junos_policy_nhs_config_table(self.device)
policy.get()
policy.get(options={"database": self.junos_config_database})
nhs_policies = dict()
for policy_name, is_nhs_list in policy.items():
# is_nhs_list is a list with one element. Ex: [('is_nhs', True)]
Expand Down Expand Up @@ -1443,7 +1448,7 @@ def get_ipv6_neighbors_table(self):
def get_ntp_peers(self):
"""Return the NTP peers configured on the device."""
ntp_table = junos_views.junos_ntp_peers_config_table(self.device)
ntp_table.get()
ntp_table.get(options={"database": self.junos_config_database})

ntp_peers = ntp_table.items()

Expand All @@ -1455,7 +1460,7 @@ def get_ntp_peers(self):
def get_ntp_servers(self):
"""Return the NTP servers configured on the device."""
ntp_table = junos_views.junos_ntp_servers_config_table(self.device)
ntp_table.get()
ntp_table.get(options={"database": self.junos_config_database})

ntp_servers = ntp_table.items()

Expand Down Expand Up @@ -1729,7 +1734,7 @@ def get_snmp_information(self):
snmp_information = {}

snmp_config = junos_views.junos_snmp_config_table(self.device)
snmp_config.get()
snmp_config.get(options={"database": self.junos_config_database})
snmp_items = snmp_config.items()

if not snmp_items:
Expand Down Expand Up @@ -1767,7 +1772,7 @@ def get_probes_config(self):
probes = {}

probes_table = junos_views.junos_rpm_probes_config_table(self.device)
probes_table.get()
probes_table.get(options={"database": self.junos_config_database})
probes_table_items = probes_table.items()

for probe_test in probes_table_items:
Expand Down Expand Up @@ -2072,7 +2077,7 @@ def _get_root(self):
_DEFAULT_USER_DETAILS = {"level": 20, "password": "", "sshkeys": []}
root = {}
root_table = junos_views.junos_root_table(self.device)
root_table.get()
root_table.get(options={"database": self.junos_config_database})
root_items = root_table.items()
for user_entry in root_items:
username = "root"
Expand Down Expand Up @@ -2106,7 +2111,7 @@ def get_users(self):
_DEFAULT_USER_DETAILS = {"level": 0, "password": "", "sshkeys": []}

users_table = junos_views.junos_users_table(self.device)
users_table.get()
users_table.get(options={"database": self.junos_config_database})
users_items = users_table.items()
root_user = self._get_root()

Expand Down Expand Up @@ -2231,7 +2236,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 All @@ -2250,7 +2255,7 @@ def get_network_instances(self, name=""):
network_instances = {}

ri_table = junos_views.junos_nw_instances_table(self.device)
ri_table.get()
ri_table.get(options={"database": self.junos_config_database})
ri_entries = ri_table.items()

vrf_interfaces = []
Expand Down
2 changes: 1 addition & 1 deletion napalm/junos/utils/junos_views.yml
Original file line number Diff line number Diff line change
Expand Up @@ -748,5 +748,5 @@ junos_nw_instances_table:
junos_nw_instances_view:
fields:
instance_type: {instance-type: unicode}
interfaces: {interface/name: unicode}
interfaces: {interface/name | bridge-domains/domain/interface/name: unicode}
route_distinguisher: {route-distinguisher/rd-type: unicode}
Loading

0 comments on commit 0a53013

Please sign in to comment.