diff --git a/inventory_provider/router_interfaces.py b/inventory_provider/router_interfaces.py index 21d6eb11dd1ffe4514b737ef447312b5d9e5ba3b..4b17f10b0be415eec8b577155e9ecff5bd7ef088 100644 --- a/inventory_provider/router_interfaces.py +++ b/inventory_provider/router_interfaces.py @@ -1,6 +1,7 @@ import contextlib import json import re +from multiprocessing import Pool import click import jsonschema @@ -217,6 +218,10 @@ def get_router_interfaces(router): } +def get_router_interfaces_l(router): + return list(get_router_interfaces(router)) + + @click.command() @click.option( "--config", @@ -226,15 +231,13 @@ def get_router_interfaces(router): default=open("config.json"), callback=_validate_config) def cli(config): + pool = Pool(20) with open("routers_community.conf") as f: - for r in load_routers(f): - - with connection(config["alarms-db"]) as c: - _db_test(c, r) - - print(r["hostname"]) - for i in get_router_interfaces(r): - print("\t%r" % i) + routers = list(load_routers(f)) + for r, i in zip(routers, pool.map(get_router_interfaces_l, routers)): + print(r["hostname"]) + for ifc in i: + print("\t%r" % ifc) if __name__ == "__main__":