diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-06-18 02:31:31 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-06-18 02:31:31 +0200 |
commit | 735510307c915fc272e918ee7967722bd9f41981 (patch) | |
tree | 9476be4b8d0923fd85508db65543d1d1f45d2c0e | |
parent | Fix pycodestyle. (diff) | |
download | puppet-classifier-735510307c915fc272e918ee7967722bd9f41981.tar.gz puppet-classifier-735510307c915fc272e918ee7967722bd9f41981.tar.xz |
Pydocstyle.
-rw-r--r-- | .pydocstyle | 2 | ||||
-rw-r--r-- | pyenc/__init__.py | 9 | ||||
-rw-r--r-- | pyenc/db.py | 13 | ||||
-rw-r--r-- | pyenc/enc.py | 6 | ||||
-rw-r--r-- | pyenc/model.py | 30 |
5 files changed, 44 insertions, 16 deletions
diff --git a/.pydocstyle b/.pydocstyle new file mode 100644 index 0000000..b18701d --- /dev/null +++ b/.pydocstyle @@ -0,0 +1,2 @@ +[pydocstyle] +ignore = D100,D105,D107,D203,D212 diff --git a/pyenc/__init__.py b/pyenc/__init__.py index 08f724b..d5ec4f4 100644 --- a/pyenc/__init__.py +++ b/pyenc/__init__.py @@ -1,6 +1,4 @@ -""" -app object setup for application -""" +"""App object setup for application.""" import flask from flask import ( @@ -21,6 +19,11 @@ import yaml def create_app(): + """ + Create new flask app. + + Should bind everything needed to it. + """ app = Flask(__name__, instance_relative_config=True) app.config.from_pyfile('settings.py') diff --git a/pyenc/db.py b/pyenc/db.py index 3bf2bba..38edda1 100644 --- a/pyenc/db.py +++ b/pyenc/db.py @@ -1,6 +1,4 @@ -""" -Database connection for application -""" +"""Database connection for application.""" import click from flask import current_app, g @@ -8,16 +6,10 @@ from flask.cli import with_appcontext from .model import db -@with_appcontext -def init_db(): - db.create_all() - - @click.command('init-db') @with_appcontext def init_db_command(): - """ - """ + """Create database from command line.""" # init_db() # print(db) print(db) @@ -26,6 +18,7 @@ def init_db_command(): def init_app(app): + """Add database (and click) to given flask app.""" # app.teardown_appcontext(close_db) db.init_app(app) app.cli.add_command(init_db_command) diff --git a/pyenc/enc.py b/pyenc/enc.py index 5df6ecb..24f9fdc 100644 --- a/pyenc/enc.py +++ b/pyenc/enc.py @@ -11,6 +11,11 @@ import yaml @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}") @@ -23,4 +28,5 @@ def run_enc(fqdn): def init_app(app): + """Add puppet enc click to current flask app.""" app.cli.add_command(run_enc) diff --git a/pyenc/model.py b/pyenc/model.py index 0382e96..0a240d9 100644 --- a/pyenc/model.py +++ b/pyenc/model.py @@ -1,6 +1,4 @@ -""" -Database model for application -""" +"""Database model for application.""" from flask_sqlalchemy import SQLAlchemy import requests @@ -21,6 +19,15 @@ host_classes = db.Table( class Host(db.Model): + """ + Single computer. + + A computer has a name (machine.example.com.), an environment + (production) and a list of puppet classes. + + (TODO and direct values?) + """ + __tablename__ = 'host' id = db.Column(db.Integer, primary_key=True) fqdn = db.Column(db.Text, nullable=False) @@ -37,16 +44,33 @@ class Host(db.Model): class PuppetFile(db.Model): + """ + Puppet source code file. + + Keeps track of known puppet files. Each file contains 0 to many + puppet classes. + """ + __tablename__ = 'puppet_file' id = db.Column(db.Integer, primary_key=True) + # Where we found the file path = db.Column(db.Text, nullable=False) + # Output of 'puppet parser dump --format json <filename>' json = db.Column(db.Text, nullable=False) + # When we last read data into json last_parse = db.Column(db.Float) # classes = db.relationship('PuppetClass', back_populates='comes_from') classes = db.relationship('PuppetClass', backref='comes_from') class PuppetClass(db.Model): + """ + A puppet class. + + The class itself only keeps track of its name here, and mostyl + ensures that only existing classes can be added to a given node/host. + """ + __tablename__ = 'puppet_class' id = db.Column(db.Integer, primary_key=True) class_name = db.Column(db.Text, nullable=False) |