Skip to content

Commit

Permalink
Speedup interface parsing for junos (#898)
Browse files Browse the repository at this point in the history
  • Loading branch information
jobec authored and ktbyers committed Jan 6, 2019
1 parent a97d012 commit cf69482
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions napalm/junos/junos.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,30 +310,33 @@ def get_interfaces(self):

# convert all the tuples to our pre-defined dict structure
def _convert_to_dict(interfaces):
for iface in interfaces.keys():
# calling .items() here wont work.
# The dictionary values will end up being tuples instead of dictionaries
interfaces = dict(interfaces)
for iface, iface_data in interfaces.items():
result[iface] = {
"is_up": interfaces[iface]["is_up"],
"is_up": iface_data["is_up"],
# For physical interfaces <admin-status> will always be there, so just
# return the value interfaces[iface]['is_enabled']
# For logical interfaces if <iff-down> is present interface is disabled,
# otherwise interface is enabled
"is_enabled": (
True
if interfaces[iface]["is_enabled"] is None
else interfaces[iface]["is_enabled"]
if iface_data["is_enabled"] is None
else iface_data["is_enabled"]
),
"description": (interfaces[iface]["description"] or ""),
"last_flapped": float((interfaces[iface]["last_flapped"] or -1)),
"description": (iface_data["description"] or ""),
"last_flapped": float((iface_data["last_flapped"] or -1)),
"mac_address": napalm.base.helpers.convert(
napalm.base.helpers.mac,
interfaces[iface]["mac_address"],
py23_compat.text_type(interfaces[iface]["mac_address"]),
iface_data["mac_address"],
py23_compat.text_type(iface_data["mac_address"]),
),
"speed": -1,
}
# result[iface]['last_flapped'] = float(result[iface]['last_flapped'])

match = re.search(r"(\d+)(\w*)", interfaces[iface]["speed"] or "")
match = re.search(r"(\d+)(\w*)", iface_data["speed"] or "")
if match is None:
continue
speed_value = napalm.base.helpers.convert(int, match.group(1), -1)
Expand Down

0 comments on commit cf69482

Please sign in to comment.