Skip to content

Commit

Permalink
Use aply-groups inheritance on get-configuration RPC calls
Browse files Browse the repository at this point in the history
The behaviour for get-configuration RPC calls has been changed in
2af90cc, in order to ensure we're gathering from the right database.

The way junos-eznc works is that if there aren't any specific options
passed in, it uses apply-groups by default. But when there are options
passed in, as we do starting with 2af90cc, it doesn't default the
values of `inherit` and `groups`, and therefore when gathering the
config it won't expand the apply-groups, see
https://github.com/Juniper/py-junos-eznc/blob/ab0e8603eac56fa1d049695c7ef86eb64582ab8f/lib/jnpr/junos/factory/cfgtable.py#L517-L520.

Changing this now, by adding a few new optional arguments, which allow
the user to select the desired behaviour.
  • Loading branch information
mirceaulinic committed Jan 19, 2021
1 parent 036ddc3 commit e4955be
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions napalm/junos/junos.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ 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 @@ -1130,10 +1144,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 +1160,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 +1498,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 +1510,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 +1785,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 +1822,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 @@ -2109,7 +2123,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 +2154,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 +2302,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

0 comments on commit e4955be

Please sign in to comment.