Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use aply-groups inheritance on get-configuration RPC calls #1363

Merged
merged 2 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion napalm/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,7 @@ def traceroute(
{
'error': 'unknown host 8.8.8.8.8'
}
"""
"""
raise NotImplementedError

def get_users(self):
Expand Down
2 changes: 1 addition & 1 deletion napalm/base/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def cisco_conf_parse_objects(cfg_section, config):


def regex_find_txt(pattern, text, default=""):
"""""
""" ""
RegEx search for pattern in text. Will try to match the data type of the "default" value
or return the default value if no match is found.
This is to parse IOS config like below:
Expand Down
12 changes: 7 additions & 5 deletions napalm/eos/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1361,11 +1361,13 @@ def get_route_to(self, destination="", protocol="", longer=False):
)
except CommandError:
# Newer EOS can't mix longer-prefix and detail
command = "show ip{ipv} bgp {dest} {longer} vrf {_vrf}".format(
ipv=ipv,
dest=destination,
longer="longer-prefixes" if longer else "",
_vrf=_vrf,
command = (
"show ip{ipv} bgp {dest} {longer} vrf {_vrf}".format(
ipv=ipv,
dest=destination,
longer="longer-prefixes" if longer else "",
_vrf=_vrf,
)
)
vrf_cache.update(
{
Expand Down
68 changes: 42 additions & 26 deletions napalm/junos/junos.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ def __init__(self, hostname, username, password, timeout=60, optional_args=None)
self.junos_config_database = optional_args.get(
"junos_config_database", "committed"
)
self.junos_config_inheritance = optional_args.get(
"junos_config_inherit", "inherit"
)
self.junos_config_groups = optional_args.get("junos_config_groups", "groups")
self.junos_config_options = {
"database": self.junos_config_database,
"inherit": self.junos_config_inheritance,
"groups": self.junos_config_groups,
}
self.junos_config_options = optional_args.get(
"junos_config_options", self.junos_config_options
)

if self.key_file:
self.device = Device(
Expand Down Expand Up @@ -405,8 +417,8 @@ def get_environment(self):
routing_engine = junos_views.junos_routing_engine_table_srx_cluster(
self.device
)
temperature_thresholds = junos_views.junos_temperature_thresholds_srx_cluster(
self.device
temperature_thresholds = (
junos_views.junos_temperature_thresholds_srx_cluster(self.device)
)
else:
environment = junos_views.junos_environment_table(self.device)
Expand Down Expand Up @@ -1130,10 +1142,10 @@ def build_prefix_limit(**args):

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

Expand All @@ -1146,7 +1158,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(options={"database": self.junos_config_database})
policy.get(options=self.junos_config_options)
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 @@ -1484,7 +1496,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(options={"database": self.junos_config_database})
ntp_table.get(options=self.junos_config_options)

ntp_peers = ntp_table.items()

Expand All @@ -1496,7 +1508,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(options={"database": self.junos_config_database})
ntp_table.get(options=self.junos_config_options)

ntp_servers = ntp_table.items()

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

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

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

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

for probe_test in probes_table_items:
Expand Down Expand Up @@ -1898,12 +1910,14 @@ def traceroute(
if vrf:
vrf_str = " routing-instance {vrf}".format(vrf=vrf)

traceroute_command = "traceroute {destination}{source}{maxttl}{wait}{vrf}".format(
destination=destination,
source=source_str,
maxttl=maxttl_str,
wait=wait_str,
vrf=vrf_str,
traceroute_command = (
"traceroute {destination}{source}{maxttl}{wait}{vrf}".format(
destination=destination,
source=source_str,
maxttl=maxttl_str,
wait=wait_str,
vrf=vrf_str,
)
)

traceroute_rpc = E("command", traceroute_command)
Expand Down Expand Up @@ -1985,14 +1999,16 @@ def ping(
if vrf:
vrf_str = " routing-instance {vrf}".format(vrf=vrf)

ping_command = "ping {destination}{source}{ttl}{timeout}{size}{count}{vrf}".format(
destination=destination,
source=source_str,
ttl=maxttl_str,
timeout=timeout_str,
size=size_str,
count=count_str,
vrf=vrf_str,
ping_command = (
"ping {destination}{source}{ttl}{timeout}{size}{count}{vrf}".format(
destination=destination,
source=source_str,
ttl=maxttl_str,
timeout=timeout_str,
size=size_str,
count=count_str,
vrf=vrf_str,
)
)

ping_rpc = E("command", ping_command)
Expand Down Expand Up @@ -2109,7 +2125,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(options={"database": self.junos_config_database})
root_table.get(options=self.junos_config_options)
root_items = root_table.items()
for user_entry in root_items:
username = "root"
Expand Down Expand Up @@ -2140,7 +2156,7 @@ def get_users(self):
_DEFAULT_USER_DETAILS = {"level": 0, "password": "", "sshkeys": []}

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

Expand Down Expand Up @@ -2288,7 +2304,7 @@ def get_network_instances(self, name=""):
network_instances = {}

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

vrf_interfaces = []
Expand Down
16 changes: 10 additions & 6 deletions napalm/pyIOSXR/iosxr.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,12 @@ def load_candidate_config(self, filename=None, config=None):
with open(filename) as f:
configuration = f.read()

rpc_command = "<CLI><Configuration>{configuration}</Configuration></CLI>".format(
configuration=escape_xml(
configuration
) # need to escape, otherwise will try to load invalid XML
rpc_command = (
"<CLI><Configuration>{configuration}</Configuration></CLI>".format(
configuration=escape_xml(
configuration
) # need to escape, otherwise will try to load invalid XML
)
)

try:
Expand Down Expand Up @@ -710,7 +712,9 @@ def rollback(self, rb_id=1):

:param rb_id: Rollback a specific number of steps. Default: 1
"""
rpc_command = "<Unlock/><Rollback><Previous>{rb_id}</Previous></Rollback><Lock/>".format(
rb_id=rb_id
rpc_command = (
"<Unlock/><Rollback><Previous>{rb_id}</Previous></Rollback><Lock/>".format(
rb_id=rb_id
)
)
self._execute_rpc(rpc_command)