From a4b1a860313fe3542fb045101d4277c382e36f49 Mon Sep 17 00:00:00 2001 From: Mikker Gimenez-Peterson Date: Tue, 5 Dec 2017 15:59:55 -0800 Subject: [PATCH] Adding index json document so this can be hit like an API, and used by other apps --- .gitignore | 1 + README.rst | 4 ++++ infinitory/cli.py | 10 ++++++++-- setup.py | 0 4 files changed, 13 insertions(+), 2 deletions(-) mode change 100644 => 100755 setup.py diff --git a/.gitignore b/.gitignore index 9c6978f..0bf0a89 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ __pycache__ /dist/ /*.egg-info /output +bin/ diff --git a/README.rst b/README.rst index c925b51..a12bd9f 100644 --- a/README.rst +++ b/README.rst @@ -3,3 +3,7 @@ SRE Inventory Report Generate a report on SRE inventory, including hosts, roles, and services. +Developing +========== + +Use `python setup.py develop` to install dependencies diff --git a/infinitory/cli.py b/infinitory/cli.py index a5921f6..b80a608 100755 --- a/infinitory/cli.py +++ b/infinitory/cli.py @@ -4,6 +4,7 @@ import click import csv from datetime import datetime import jinja2 +import json import logging import os import markdown2 @@ -90,6 +91,8 @@ def output_html(inventory, directory): for node in nodes: csv_writer.writerow([cell.body_csv(node) for cell in all_columns]) + write_json(nodes, directory, "index") + for node in nodes: path = "{}/nodes/{}.html".format(directory, node["certname"]) with open(path, "w", encoding="utf-8") as html: @@ -127,7 +130,6 @@ def output_html(inventory, directory): generation_time=generation_time, service=service)) - def render_template(template_name, **kwargs): data_path = os.path.dirname(os.path.abspath(__file__)) environment = jinja2.Environment( @@ -174,6 +176,11 @@ def set_up_logging(level=logging.WARNING): logging.getLogger("paramiko").setLevel(logging.FATAL) +def write_json(nodes, directory, filename): + path = "{}/nodes/{}.json".format(directory, filename) + with open(path, "w", encoding="utf-8") as json_out: + json_out.write(json.dumps(nodes)) + @click.command() @click.option("--output", "-o", required=True, metavar="PATH", help="Directory to put report in. WARNING: this directory will be removed if it already exists.") @click.option("--host", "-h", default="localhost", metavar="HOST", help="PuppetDB host to query") @@ -182,7 +189,6 @@ def set_up_logging(level=logging.WARNING): @click.version_option() def main(host, output, verbose, debug): """Generate SRE inventory report""" - if debug: set_up_logging(logging.DEBUG) elif verbose: diff --git a/setup.py b/setup.py old mode 100644 new mode 100755