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

parallelize router queries

parent 887ed45c
No related branches found
No related tags found
No related merge requests found
import contextlib import contextlib
import json import json
import re import re
from multiprocessing import Pool
import click import click
import jsonschema import jsonschema
...@@ -217,6 +218,10 @@ def get_router_interfaces(router): ...@@ -217,6 +218,10 @@ def get_router_interfaces(router):
} }
def get_router_interfaces_l(router):
return list(get_router_interfaces(router))
@click.command() @click.command()
@click.option( @click.option(
"--config", "--config",
...@@ -226,15 +231,13 @@ def get_router_interfaces(router): ...@@ -226,15 +231,13 @@ def get_router_interfaces(router):
default=open("config.json"), default=open("config.json"),
callback=_validate_config) callback=_validate_config)
def cli(config): def cli(config):
pool = Pool(20)
with open("routers_community.conf") as f: with open("routers_community.conf") as f:
for r in load_routers(f): routers = list(load_routers(f))
for r, i in zip(routers, pool.map(get_router_interfaces_l, routers)):
with connection(config["alarms-db"]) as c: print(r["hostname"])
_db_test(c, r) for ifc in i:
print("\t%r" % ifc)
print(r["hostname"])
for i in get_router_interfaces(r):
print("\t%r" % i)
if __name__ == "__main__": if __name__ == "__main__":
......
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