aboutsummaryrefslogtreecommitdiff
path: root/pyenc/enc.py
blob: 7ec3a8e465f27ebee8c22f2a4875ba0f76aab852 (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

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):
    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):
    app.cli.add_command(run_enc)