Skip to content

Commit

Permalink
Bump black to 24.3.0 and format files
Browse files Browse the repository at this point in the history
  • Loading branch information
mirceaulinic committed Mar 21, 2024
1 parent f432be6 commit 97e47fb
Show file tree
Hide file tree
Showing 38 changed files with 155 additions and 119 deletions.
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""conf.py."""

# -*- coding: utf-8 -*-
#
# napalm documentation build configuration file, created by
Expand Down
1 change: 1 addition & 0 deletions napalm/base/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Helper functions for the NAPALM base."""

import ipaddress
import itertools
import logging
Expand Down
1 change: 1 addition & 0 deletions napalm/base/test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test fixtures."""

import ast
import json
import os
Expand Down
1 change: 1 addition & 0 deletions napalm/base/test/double.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Base class for Test doubles."""

import json
import re
import os
Expand Down
1 change: 1 addition & 0 deletions napalm/base/test/getters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Testing framework."""

import functools
from itertools import zip_longest
import inspect
Expand Down
1 change: 1 addition & 0 deletions napalm/base/utils/jinja_filters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Some common jinja filters."""

from typing import Dict, Any


Expand Down
1 change: 1 addition & 0 deletions napalm/base/utils/string_parsers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" Common methods to normalize a string """

import re
import struct
from typing import Union, List, Iterable, Dict, Optional, Tuple
Expand Down
1 change: 1 addition & 0 deletions napalm/base/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
See: https://napalm.readthedocs.io/en/latest/validate.html
"""

import yaml
import copy
import re
Expand Down
2 changes: 1 addition & 1 deletion napalm/eos/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,7 @@ def get_interfaces_ip(self):
interface_details.get("linkLocal", {})
.get("subnet", "::/0")
.split("/")[-1]
)
),
# when no link-local set, address will be None and maslken 0
}
)
Expand Down
1 change: 1 addition & 0 deletions napalm/eos/utils/versions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Some functions to work with EOS version numbers"""

import re


Expand Down
113 changes: 65 additions & 48 deletions napalm/ios/ios.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""NAPALM Cisco IOS Handler."""

# Copyright 2015 Spotify AB. All rights reserved.
#
# The contents of this file are licensed under the Apache License, Version 2.0
Expand Down Expand Up @@ -2100,46 +2101,54 @@ def get_bgp_neighbors_detail(self, neighbor_address=""):
"up": neigh["up"] != "never",
"local_as": napalm.base.helpers.as_number(neigh["local_as"]),
"remote_as": napalm.base.helpers.as_number(neigh["remote_as"]),
"router_id": napalm.base.helpers.ip(bgp_neigh["router_id"])
if bgp_neigh["router_id"]
else "",
"local_address": napalm.base.helpers.ip(bgp_neigh["local_address"])
if bgp_neigh["local_address"]
else "",
"router_id": (
napalm.base.helpers.ip(bgp_neigh["router_id"])
if bgp_neigh["router_id"]
else ""
),
"local_address": (
napalm.base.helpers.ip(bgp_neigh["local_address"])
if bgp_neigh["local_address"]
else ""
),
"local_address_configured": False,
"local_port": napalm.base.helpers.as_number(bgp_neigh["local_port"])
if bgp_neigh["local_port"]
else 0,
"local_port": (
napalm.base.helpers.as_number(bgp_neigh["local_port"])
if bgp_neigh["local_port"]
else 0
),
"routing_table": bgp_neigh["vrf"] if bgp_neigh["vrf"] else "global",
"remote_address": napalm.base.helpers.ip(bgp_neigh["neighbor"]),
"remote_port": napalm.base.helpers.as_number(bgp_neigh["remote_port"])
if bgp_neigh["remote_port"]
else 0,
"remote_port": (
napalm.base.helpers.as_number(bgp_neigh["remote_port"])
if bgp_neigh["remote_port"]
else 0
),
"multihop": False,
"multipath": False,
"remove_private_as": False,
"import_policy": "",
"export_policy": "",
"input_messages": napalm.base.helpers.as_number(
bgp_neigh["msg_total_in"]
)
if bgp_neigh["msg_total_in"]
else 0,
"output_messages": napalm.base.helpers.as_number(
bgp_neigh["msg_total_out"]
)
if bgp_neigh["msg_total_out"]
else 0,
"input_updates": napalm.base.helpers.as_number(
bgp_neigh["msg_update_in"]
)
if bgp_neigh["msg_update_in"]
else 0,
"output_updates": napalm.base.helpers.as_number(
bgp_neigh["msg_update_out"]
)
if bgp_neigh["msg_update_out"]
else 0,
"input_messages": (
napalm.base.helpers.as_number(bgp_neigh["msg_total_in"])
if bgp_neigh["msg_total_in"]
else 0
),
"output_messages": (
napalm.base.helpers.as_number(bgp_neigh["msg_total_out"])
if bgp_neigh["msg_total_out"]
else 0
),
"input_updates": (
napalm.base.helpers.as_number(bgp_neigh["msg_update_in"])
if bgp_neigh["msg_update_in"]
else 0
),
"output_updates": (
napalm.base.helpers.as_number(bgp_neigh["msg_update_out"])
if bgp_neigh["msg_update_out"]
else 0
),
"messages_queued_out": napalm.base.helpers.as_number(neigh["out_q"]),
"connection_state": bgp_neigh["bgp_state"],
"previous_connection_state": "",
Expand All @@ -2150,13 +2159,17 @@ def get_bgp_neighbors_detail(self, neighbor_address=""):
else False
),
"local_as_prepend": False,
"holdtime": napalm.base.helpers.as_number(bgp_neigh["holdtime"])
if bgp_neigh["holdtime"]
else 0,
"holdtime": (
napalm.base.helpers.as_number(bgp_neigh["holdtime"])
if bgp_neigh["holdtime"]
else 0
),
"configured_holdtime": 0,
"keepalive": napalm.base.helpers.as_number(bgp_neigh["keepalive"])
if bgp_neigh["keepalive"]
else 0,
"keepalive": (
napalm.base.helpers.as_number(bgp_neigh["keepalive"])
if bgp_neigh["keepalive"]
else 0
),
"configured_keepalive": 0,
"active_prefix_count": 0,
"received_prefix_count": 0,
Expand Down Expand Up @@ -3209,10 +3222,10 @@ def get_route_to(self, destination="", protocol="", longer=False):
# was not specified
if protocol == "" or protocol == route_entry["protocol"]:
if route_proto == "bgp":
route_entry[
"protocol_attributes"
] = self._get_bgp_route_attr(
destination, _vrf, nh, ip_version
route_entry["protocol_attributes"] = (
self._get_bgp_route_attr(
destination, _vrf, nh, ip_version
)
)
nh_line_found = (
False # for next RT entry processing ...
Expand Down Expand Up @@ -3305,12 +3318,16 @@ def get_users(self):
output = self._send_command(command)
for match in re.finditer(username_regex, output, re.M):
users[match.groupdict()["username"]] = {
"level": int(match.groupdict()["priv_level"])
if match.groupdict()["priv_level"]
else 1,
"password": match.groupdict()["pwd_hash"]
if match.groupdict()["pwd_hash"]
else "",
"level": (
int(match.groupdict()["priv_level"])
if match.groupdict()["priv_level"]
else 1
),
"password": (
match.groupdict()["pwd_hash"]
if match.groupdict()["pwd_hash"]
else ""
),
"sshkeys": [],
}
for match in re.finditer(pub_keychain_regex, output, re.M):
Expand Down
52 changes: 26 additions & 26 deletions napalm/iosxr/iosxr.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ def get_interfaces(self):
"is_enabled": enabled,
"mac_address": mac_address,
"description": description,
"last_flapped": last_flapped / 1e9
if last_flapped != -1.0
else -1.0,
"last_flapped": (
last_flapped / 1e9 if last_flapped != -1.0 else -1.0
),
}
)

Expand Down Expand Up @@ -587,23 +587,23 @@ def generate_vrf_query(vrf_name):
),
0,
)
this_neighbor["address_family"][this_afi][
"accepted_prefixes"
] = napalm.base.helpers.convert(
int,
napalm.base.helpers.find_txt(
neighbor, "AFData/Entry/PrefixesAccepted"
),
0,
this_neighbor["address_family"][this_afi]["accepted_prefixes"] = (
napalm.base.helpers.convert(
int,
napalm.base.helpers.find_txt(
neighbor, "AFData/Entry/PrefixesAccepted"
),
0,
)
)
this_neighbor["address_family"][this_afi][
"sent_prefixes"
] = napalm.base.helpers.convert(
int,
napalm.base.helpers.find_txt(
neighbor, "AFData/Entry/PrefixesAdvertised"
),
0,
this_neighbor["address_family"][this_afi]["sent_prefixes"] = (
napalm.base.helpers.convert(
int,
napalm.base.helpers.find_txt(
neighbor, "AFData/Entry/PrefixesAdvertised"
),
0,
)
)
except AttributeError:
this_neighbor["address_family"][this_afi]["received_prefixes"] = -1
Expand Down Expand Up @@ -947,11 +947,11 @@ def cli(self, commands, encoding="text"):
try:
cli_output[str(command)] = str(self.device._execute_show(command))
except TimeoutError:
cli_output[
str(command)
] = 'Execution of command \
cli_output[str(command)] = (
'Execution of command \
"{command}" took too long! Please adjust your params!'.format(
command=command
command=command
)
)
logger.error(str(cli_output))
raise CommandTimeoutException(str(cli_output))
Expand Down Expand Up @@ -2288,9 +2288,9 @@ def traceroute(
last_probe_host_name = tag_value
continue
if tag_name == "DeltaTime":
last_hop_dict["probes"][last_probe_index][
"rtt"
] = napalm.base.helpers.convert(float, tag_value, 0.0)
last_hop_dict["probes"][last_probe_index]["rtt"] = (
napalm.base.helpers.convert(float, tag_value, 0.0)
)
continue

if last_hop_index:
Expand Down
44 changes: 22 additions & 22 deletions napalm/iosxr_netconf/iosxr_netconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,30 +801,30 @@ def get_vrf_neighbors(rpc_reply_etree, xpath):
),
0,
)
this_neighbor["address_family"][this_afi][
"accepted_prefixes"
] = napalm.base.helpers.convert(
int,
self._find_txt(
neighbor,
"./bgp:af-data/bgp:prefixes-accepted",
default="",
namespaces=C.NS,
),
0,
this_neighbor["address_family"][this_afi]["accepted_prefixes"] = (
napalm.base.helpers.convert(
int,
self._find_txt(
neighbor,
"./bgp:af-data/bgp:prefixes-accepted",
default="",
namespaces=C.NS,
),
0,
)
)
this_neighbor["address_family"][this_afi][
"sent_prefixes"
] = napalm.base.helpers.convert(
int,
self._find_txt(
neighbor,
"./bgp:af-data/\
this_neighbor["address_family"][this_afi]["sent_prefixes"] = (
napalm.base.helpers.convert(
int,
self._find_txt(
neighbor,
"./bgp:af-data/\
bgp:prefixes-advertised",
default="",
namespaces=C.NS,
),
0,
default="",
namespaces=C.NS,
),
0,
)
)
except AttributeError:
this_neighbor["address_family"][this_afi]["received_prefixes"] = -1
Expand Down
4 changes: 2 additions & 2 deletions napalm/junos/junos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,7 @@ def get_bgp_neighbors_detail(self, neighbor_address=""):
"RemovePrivateAS": "remove_private_as",
"Multipath": "multipath",
"Multihop": "multihop",
"AddressFamily": "local_address_configured"
"AddressFamily": "local_address_configured",
# 'AuthKey' : 'authentication_key_set'
# but other vendors do not specify if auth key is set
# other options:
Expand Down Expand Up @@ -1728,7 +1728,7 @@ def get_interfaces_ip(self):

_FAMILY_VMAP_ = {
"inet": "ipv4",
"inet6": "ipv6"
"inet6": "ipv6",
# can add more mappings
}
_FAMILY_MAX_PREFIXLEN = {"inet": 32, "inet6": 128}
Expand Down
1 change: 1 addition & 0 deletions napalm/junos/utils/junos_views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Load tables/views
"""

import yaml
import re
from jnpr.junos.factory import FactoryLoader
Expand Down
1 change: 1 addition & 0 deletions napalm/nxapi_plumbing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Re-implemented by ktbyers to support XML-RPC in addition to JSON-RPC
"""

from napalm.nxapi_plumbing.device import Device
from napalm.nxapi_plumbing.api_client import RPCClient, XMLClient
from napalm.nxapi_plumbing.errors import (
Expand Down
1 change: 1 addition & 0 deletions napalm/nxapi_plumbing/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Reimplemented by ktbyers to support XML-RPC in addition to JSON-RPC
"""

from __future__ import print_function, unicode_literals

from builtins import super
Expand Down
Loading

0 comments on commit 97e47fb

Please sign in to comment.