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

initial use of redis

parent ba267a17
Branches
Tags
No related merge requests found
......@@ -3,6 +3,7 @@ import logging
from multiprocessing import Process, Queue
import click
import redis
from inventory_provider import constants
from inventory_provider import snmp
......@@ -81,11 +82,16 @@ def load_network_details(params):
p.start()
processes.append({"router": r, "process": p, "queue": q})
r = redis.StrictRedis(
host=params["redis"]["hostname"],
port=params["redis"]["port"])
result = {}
for p in processes:
threading_logger.debug(
"waiting for get_router_details result: %r" % p["router"])
result[p["router"]["hostname"]] = p["queue"].get()
r.set(p["router"]["hostname"], json.dumps(p["queue"].get()))
p["process"].join()
threading_logger.debug(
"got result and joined get_router_details proc: %r" % p["router"])
......@@ -106,11 +112,17 @@ def _validate_config(ctx, param, value):
default=open("config.json"),
callback=_validate_config)
def cli(params):
network_details = load_network_details(params)
load_network_details(params)
r = redis.StrictRedis(
host=params["redis"]["hostname"],
port=params["redis"]["port"])
result = dict([(k.decode("utf-8"), json.loads(r.get(k))) for k in r.keys()])
filename = "/tmp/router-info.json"
logging.debug("writing output to: " + filename)
with open(filename, "w") as f:
f.write(json.dumps(network_details))
f.write(json.dumps(result))
if __name__ == "__main__":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment