Skip to content
Snippets Groups Projects
jobs.py 2.92 KiB
import logging

from flask import Blueprint, Response, current_app

from inventory_provider.tasks.app import app
from inventory_provider.constants import TASK_LOGGER_NAME

routes = Blueprint("inventory-data-job-routes", __name__)


@routes.route("/update", methods=['GET', 'POST'])
def update():

    task_logger = logging.getLogger(TASK_LOGGER_NAME)
    config = current_app.config["INVENTORY_PROVIDER_CONFIG"]

    for r in config["routers"]:

        task_logger.info("fetching details for: %r" % r)

        task_logger.debug(
            'launching task: '
            'inventory_provider.tasks.worker.netconf_refresh_config'
            '(%s)' % r['hostname'])
        app.send_task(
            'inventory_provider.tasks.worker.netconf_refresh_config',
            args=[r["hostname"]])

        task_logger.debug(
            'launching task: '
            'inventory_provider.tasks.worker.snmp_refresh_interfaces'
            '(%s)' % r['hostname'])
        app.send_task(
            'inventory_provider.tasks.worker.snmp_refresh_interfaces',
            args=[r["hostname"], r["community"]])

    return Response("OK")


@routes.route("/update-startup", methods=['GET', 'POST'])
def startup_update():
    task_logger = logging.getLogger(TASK_LOGGER_NAME)
    task_logger.debug(
            'launching task: '
            'inventory_provider.tasks.worker.update_alarmsdb_cache')
    app.send_task(
        'inventory_provider.tasks.worker.update_alarmsdb_cache')
    return Response("OK")


@routes.route("update-services-to-monitor", methods=['GET'])
def update_services_to_monitor():
    app.send_task(
        'inventory_provider.tasks.worker.update_service_to_monitor')
    return Response("OK")


@routes.route("update-interfaces-to-services", methods=['GET'])
def update_interfaces_to_services():
    app.send_task(
        'inventory_provider.tasks.worker.update_interfaces_to_services')
    return Response("OK")


@routes.route("update-service-hierarchy", methods=['GET'])
def update_service_hierarchy():
    app.send_task('inventory_provider.tasks.worker.update_circuit_hierarchy')
    return Response("OK")


@routes.route("update-equipment-locations", methods=['GET'])
def update_equipment_locations():
    app.send_task('inventory_provider.tasks.worker.update_equipment_locations')
    return Response("OK")


@routes.route("update-from-inventory-system", methods=['GET'])
def update_from_inventory_system():
    app.send_task(
        'inventory_provider.tasks.worker.update_service_to_monitor')
    app.send_task(
        'inventory_provider.tasks.worker.update_interfaces_to_services')
    app.send_task('inventory_provider.tasks.worker.update_circuit_hierarchy')
    app.send_task('inventory_provider.tasks.worker.update_equipment_locations')
    return Response("OK")


@routes.route("update-interface-statuses")
def update_interface_statuses():
    app.send_task(
        'inventory_provider.tasks.worker.update_interface_statuses')
    return Response("OK")