Skip to content
Snippets Groups Projects
Commit aac1c82d authored by Erik Reid's avatar Erik Reid
Browse files

pep8

parent 1d7e641b
No related branches found
No related tags found
No related merge requests found
......@@ -31,6 +31,7 @@ def cursor(cnx):
if csr:
csr.close()
def _db_test(db, router):
database_logger = logging.getLogger(DATABASE_LOGGER_NAME)
with cursor(db) as crs:
......
......@@ -55,7 +55,10 @@ def _load_routers(config_file):
:return:
"""
for line in config_file:
m = re.match(r'^([a-z\d]+\.[a-z\d]{3,4}\.[a-z\d]{2}\.(geant|eumedconnect)\d*\.net)\s*=([^,]+)\s*,(.*)\s*$', line)
m = re.match(
r'^([a-z\d]+\.[a-z\d]{3,4}\.[a-z\d]{2}'
r'\.(geant|eumedconnect)\d*\.net)\s*=([^,]+)\s*,(.*)\s*$',
line)
if not m:
logging.warning("malformed config file line: '%s'" % line.strip())
continue
......@@ -66,7 +69,6 @@ def _load_routers(config_file):
}
def load(f):
"""
loads, validates and returns configuration parameters
......@@ -81,4 +83,3 @@ def load(f):
with open(config["routers_community.conf"]) as f:
config["routers"] = list(_load_routers(f))
return config
......@@ -22,7 +22,9 @@ def neighbors(
for bgp in prot.get("bgp", []):
for g in bgp.get("group", []):
if group_expression and not \
re.match(group_expression, g["name"]["data"]):
re.match(
group_expression,
g["name"]["data"]):
continue
for n in g["neighbor"]:
yield n
......@@ -44,9 +46,14 @@ def interfaces(parsed_json_output):
@contextlib.contextmanager
def ssh_connection(hostname, ssh_params):
# TODO: remove this relative path logic!!
import os
key_filename = os.path.join(os.path.dirname(__file__), ssh_params["private-key"])
known_hosts = os.path.join(os.path.dirname(__file__), ssh_params["known-hosts"])
key_filename = os.path.join(
os.path.dirname(__file__),
ssh_params["private-key"])
known_hosts = os.path.join(
os.path.dirname(__file__),
ssh_params["known-hosts"])
k = paramiko.DSSKey.from_private_key_file(key_filename)
with paramiko.SSHClient() as ssh:
......@@ -109,13 +116,15 @@ def shell_commands():
return {}
yield {
"command": 'show configuration routing-instances IAS protocols bgp | display json',
"command": ('show configuration routing-instances'
' IAS protocols bgp | display json'),
"key": "bgp",
"parser": _parse_bgp_output
}
yield {
"command": 'show configuration logical-systems VRR protocols bgp | display json',
"command": ('show configuration logical-systems '
'VRR protocols bgp | display json'),
"key": "vrr",
"parser": lambda txt: _loads(txt) if txt else {}
}
......
......@@ -52,10 +52,6 @@ def get_router_details(router, params, q):
command_output = commands_proc_queue.get()
assert len(command_output) == len(commands)
# for c, o in zip(commands, command_output):
# with open("/tmp/%s-%s.output" % (router["hostname"], c["key"]), "w") as f:
# f.write(o)
result = {}
for c, o in zip(commands, command_output):
if c["key"]:
......@@ -87,10 +83,12 @@ def load_network_details(params):
result = {}
for p in processes:
threading_logger.debug("waiting for get_router_details result: %r" % p["router"])
threading_logger.debug(
"waiting for get_router_details result: %r" % p["router"])
result[p["router"]["hostname"]] = p["queue"].get()
p["process"].join()
threading_logger.debug("got result and joined get_router_details proc: %r" % p["router"])
threading_logger.debug(
"got result and joined get_router_details proc: %r" % p["router"])
return result
......@@ -102,7 +100,7 @@ def _validate_config(ctx, param, value):
@click.command()
@click.option(
"--params",
# required=True,
# required=True,
type=click.File(),
help="Configuration filename",
default=open("config.json"),
......@@ -122,4 +120,3 @@ if __name__ == "__main__":
logging.getLogger(constants.JUNIPER_LOGGER_NAME).setLevel(logging.DEBUG)
logging.getLogger(constants.DATABASE_LOGGER_NAME).setLevel(logging.DEBUG)
cli()
......@@ -3,7 +3,8 @@ import re
from pysnmp.hlapi import nextCmd, SnmpEngine, CommunityData, \
UdpTransportTarget, ContextData, ObjectType, ObjectIdentity
from pysnmp.smi import builder, view, compiler, rfc1902
from pysnmp.smi import builder, compiler
# from pysnmp.smi import view, rfc1902
from inventory_provider.constants import SNMP_LOGGER_NAME
......@@ -32,10 +33,15 @@ def walk(agent_hostname, community, base_oid):
snmp_logger = logging.getLogger(SNMP_LOGGER_NAME)
mibBuilder = builder.MibBuilder()
mibViewController = view.MibViewController(mibBuilder)
compiler.addMibCompiler(mibBuilder, sources=['http://mibs.snmplabs.com/asn1/@mib@'])
# mibViewController = view.MibViewController(mibBuilder)
compiler.addMibCompiler(
mibBuilder,
sources=['http://mibs.snmplabs.com/asn1/@mib@'])
# Pre-load MIB modules we expect to work with
mibBuilder.loadModules('SNMPv2-MIB', 'SNMP-COMMUNITY-MIB', 'RFC1213-MIB')
mibBuilder.loadModules(
'SNMPv2-MIB',
'SNMP-COMMUNITY-MIB',
'RFC1213-MIB')
snmp_logger.debug("walking %s: %s" % (agent_hostname, base_oid))
......@@ -76,7 +82,6 @@ def get_router_interfaces(router, config):
assert m, "sanity failure parsing oid: " + v4IfcName["oid"]
v4IfcNames[m.group(1)] = v4IfcName["value"]
interfaces = []
for v4Address, v4Mask, v4InterfaceOID in zip(
details["v4Address"],
details["v4Mask"],
......
......@@ -28,12 +28,18 @@ for c in juniper.shell_commands():
SHELL_COMMANDS.append({
"key": "bgpv4",
"command": r'show configuration routing-instances IAS protocols bgp | display set | match neighbor | match description | match "GEANT-IX | GEANT-IX-"'
"command": (r'show configuration routing-instances IAS '
r'protocols bgp | display set | match neighbor'
r' | match description'
r' | match "GEANT-IX | GEANT-IX-"')
})
SHELL_COMMANDS.append({
"key": "bgpv6",
"command": r'show configuration routing-instances IAS protocols bgp | display set | match neighbor | match description | match "GEANT-IXv6 | GEANT-IXv6-"'
"command": (r'show configuration routing-instances IAS'
r' protocols bgp | display set | match neighbor'
r' | match description'
r' | match "GEANT-IXv6 | GEANT-IXv6-"')
})
......@@ -109,4 +115,4 @@ def main():
if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG)
main()
\ No newline at end of file
main()
......@@ -77,7 +77,6 @@ CACHE_SCHEMA = {
}
@pytest.fixture
def cached_test_data():
with open("router-info.json") as f:
......@@ -98,7 +97,7 @@ def _parsed_old_style_output_data(s):
r'neighbor\s+([a-f\d\.:]+)\s+'
r'description\s+"?([^"]+)"?\s*$'), l)
assert m
yield {
"routing-instances": m.group(1),
"protocols": m.group(2),
......@@ -130,7 +129,7 @@ def test_ipv4_neighbors(router_output):
parsers = dict([(c["key"], c["parser"]) for c in juniper.shell_commands()])
neighbors = parsers["bgp"](
router_output["bgp"],
group_expression = r'^GEANT-IX[\s-].*$')
group_expression=r'^GEANT-IX[\s-].*$')
assert len(neighbors) == len(old_v4_data)
for n in neighbors:
......@@ -149,7 +148,7 @@ def test_ipv6_neighbors(router_output):
parsers = dict([(c["key"], c["parser"]) for c in juniper.shell_commands()])
neighbors = parsers["bgp"](
router_output["bgp"],
group_expression = r'^GEANT-IXv6[\s-].*$')
group_expression=r'^GEANT-IXv6[\s-].*$')
assert len(neighbors) == len(old_v6_data)
for n in neighbors:
......@@ -171,4 +170,3 @@ def test_juniper_shell_output_parsing(router_output):
if c["key"] is None:
continue
c["parser"](router_output[c["key"]])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment