aboutsummaryrefslogtreecommitdiff
path: root/pyenc/enc.py
blob: 24f9fdcb293c95ca5e0654d6fb6670909abab643 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import click
from flask import current_app, g
from flask.cli import with_appcontext
from .db import db
from . import model

import yaml


@click.command('enc')
@click.option('--fqdn', help='Node to get data for')
@with_appcontext
def run_enc(fqdn):
    """
    Run the puppet node classifier.

    Runs the node clasifier for puppet, return the data as yaml.
    """
    host = model.Host.query.where(model.Host.fqdn == fqdn).first()
    if not host:
        print(f"No host with name {fqdn}")
        return 1
    out = {
        'environment': host.environment,
        'classes': [cls.class_name for cls in host.classes],
    }
    print(yaml.dump(out))


def init_app(app):
    """Add puppet enc click to current flask app."""
    app.cli.add_command(run_enc)