import datetime import logging from sqlalchemy.dialects import postgresql from lg.base import get_app log = logging.getLogger(__name__) _, db, _ = get_app() Session = db.sessionmaker() class ASN(db.Model): __tablename__ = 'asn' asn = db.Column(db.Integer, primary_key=True, nullable=False, autoincrement=False) as_name = db.Column(db.String(255), nullable=True) prefixes = db.relationship('Prefix', backref='source_asn') created_at = db.Column(db.DateTime(), default=datetime.datetime.utcnow) updated_at = db.Column(db.DateTime(), default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow) def __repr__(self): return f'<ASN {self.asn} // {self.as_name}>'
####################################### # # Register apps # ####################################### from lg import base from flask import render_template from lg.exceptions import DatabaseConnectionFail import logging import lg.models log = logging.getLogger(__name__) flask, db, migration = base.get_app() @flask.route('/') def index(): return render_template('index.html') log.debug('Checking if BGP Peer Info app is enabled... (ENABLE_PEERAPP)') if base.ENABLE_PEERAPP: log.debug('ENABLE_PEERAPP is True. Initialising BGP Peer Info app') try: from lg.peerapp.views import flask as peer_flask flask.register_blueprint(peer_flask) except DatabaseConnectionFail: log.exception( 'Cannot register "peerapp" - is your CouchDB and Redis running?') log.debug('Checking if Ping/Trace app is enabled... (ENABLE_LG)')
def db(self) -> SQLAlchemy: """Obtain an SQLAlchemy instance from :py:attr:`._db` or init SQLAlchemy if it's `None`""" if not PathLoader._db: _, db, _ = base.get_app() PathLoader._db = db return PathLoader._db